wenjy 15 hours ago
commit 532cd2f5e1

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

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

@ -13,7 +13,7 @@
{ {
"configId": "mes", "configId": "mes",
"dbType": 4, "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": [ "PlcConfig": [

Loading…
Cancel
Save