wenjy 2 months ago
commit 532cd2f5e1

@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using System;
using System.Runtime.Serialization;
using SqlSugar;
namespace SlnMesnac.Model.domain
@ -34,4 +35,34 @@ namespace SlnMesnac.Model.domain
public int Category { get; set; }
}
[SugarTable("BaseLog"), TenantAttribute("mes")]
[DataContract(Name = "BaseLog 基础表")]
public class BaseLog
{
public BaseLog()
{
this.CreateTime = DateTime.Now;
}
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "createtime")]
public DateTime CreateTime { get; set; }
[SugarColumn(ColumnName = "log_level")]
public string LogLevel { get; set; }
[SugarColumn(ColumnName = "content")]
public string Content { get; set; }
[SugarColumn(ColumnName = "err_msg")]
public string ErrMsg { get; set; }
}
}

@ -0,0 +1,36 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using SlnMesnac.Repository.service.ScanLog;
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Repository.service.LogImpl
{
public class BaseLogServiceImpl : BaseServiceImpl<BaseLog>, IBaseLogService
{
public BaseLogServiceImpl(Repository<BaseLog> rep) : base(rep)
{
}
public void CreatTable()
{
_rep.Context.CodeFirst.InitTables<BaseLog>();
}
public Page<BaseLog> QueryPage(int pageIndex, int pageSize)
{
int totalCount = 0;
var list = _rep.Context.Queryable<BaseLog>().OrderByDescending(x => x.CreateTime)
.ToPageList(pageIndex, pageSize, ref totalCount);
Page<BaseLog> page = new Page<BaseLog>();
page.Data = list;
page.PageIndex = pageIndex;
page.PageSize = pageSize;
page.TotalCount = totalCount;
page.TotalPage = (int)Math.Ceiling(totalCount / (double)pageSize);
return page;
}
}
}

@ -0,0 +1,15 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
namespace SlnMesnac.Repository.service.LogImpl
{
public interface IBaseLogService : IBaseService<BaseLog>
{
void CreatTable();
Page<BaseLog> QueryPage(int pageIndex, int pageSize);
}
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SlnMesnac.Repository.service.LogImpl;
using SlnMesnac.Repository.service.ScanLog;
using TouchSocket.Core;
using TouchSocket.Rpc;
@ -17,27 +18,36 @@ namespace SlnMesnac.TouchSocket
private readonly IBaseCodeService _baseCodeService;
public Action<ScanLogModel>? ScanLogSocketAction; //Update By WenJY 2024-09-19将返回值改为ScanLogModel
IBaseLogService _baseLogService;
public Action<ScanLogModel>? ScanLogSocketAction;
public Action<ScanStatusSocket>? ScanStatusSocketAction;
public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService)
public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService, IBaseLogService baseLogService)
{
_scanService = scanService;
_baseCodeService = baseCodeService;
_baseLogService = baseLogService;
}
/// <summary>
/// 扫描的状态回传
/// </summary>
/// <param name="messageHeader"></param>
/// <param name="containerRegisterQuery"></param>
/// <param name="scanStatus"></param>
/// <returns></returns>
[EnableCors("cors")]
[WebApi(HttpMethodType.POST)]
public Back ScanStatus(ScanStatusSocket scanStatus)
{
BaseLog log = new BaseLog
{
LogLevel = "Info",
ErrMsg = "",
Content = scanStatus.ToJsonString()
};
try
{
if (scanStatus.is_alarm == 1 && scanStatus.device_status != null && scanStatus.device_status.Count > 0)
{
List<string> ls = new List<string>();
@ -55,35 +65,58 @@ namespace SlnMesnac.TouchSocket
ScanStatusSocketAction?.Invoke(scanStatus);
}
catch (Exception e)
{
log.LogLevel = "Error";
log.ErrMsg=e.Message;
}
_baseLogService.Insert(log);
return new Back();
}
/// <summary>
/// 入库开始
/// 扫描数据回传接口
/// </summary>
/// <param name="messageHeader"></param>
/// <param name="containerRegisterQuery"></param>
/// <param name="scanLog"></param>
/// <returns></returns>
[EnableCors("cors")]
[WebApi(HttpMethodType.POST)]
public Back ScanBack(ScanLogSocket scanStatus)
public Back ScanBack(ScanLogSocket scanLog)
{
BaseLog log = new BaseLog();
log.LogLevel = "Info";
log.ErrMsg = "";
log.Content = scanLog.ToJsonString();
try
{
var scan = new ScanLogModel()
var model = new ScanLogModel()
{
CreateTime = scanStatus.CreateTime,
DataType = scanStatus.data_type,
Code = scanStatus.code,
Rfid = scanStatus.rfid,
Ocr = scanStatus.ocr,
Url = scanStatus.url
CreateTime = scanLog.CreateTime,
DataType = scanLog.data_type,
Code = scanLog.code,
Rfid = scanLog.rfid,
Ocr = scanLog.ocr,
Url = scanLog.url
};
ScanLogSocketAction?.Invoke(scan); //Update By WenJY 2024-09-19将返回值改为ScanLogModel
_scanService.Insert(scan);
ScanLogSocketAction?.Invoke(model);
_scanService.Insert(model);
}
catch (Exception e)
{
log.LogLevel = "Error";
log.ErrMsg = e.Message;
}
_baseLogService.Insert(log);
return new Back();
}
}
}

@ -8,18 +8,11 @@
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="Templates\image\background.jpg" />
<None Remove="Templates\image\left.png" />
<None Remove="Templates\image\right.png" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Business\SlnMesnac.Business.csproj" />
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />

@ -13,7 +13,7 @@
{
"configId": "mes",
"dbType": 4,
"connStr": "PORT=5433;DATABASE=daxing;HOST=127.0.0.1;PASSWORD=123456;USER ID=postgres"
"connStr": "PORT=5432;DATABASE=daxing;HOST=127.0.0.1;PASSWORD=123456;USER ID=postgres"
}
],
"PlcConfig": [

Loading…
Cancel
Save