You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SlnMesnac.Repository.service.ScanLog;
using TouchSocket.Core;
using TouchSocket.Rpc;
using TouchSocket.WebApi;
namespace SlnMesnac.TouchSocket
{
public class ApiServer : RpcServer
{
private readonly IScanLogService _scanService;
private readonly IBaseCodeService _baseCodeService;
public Action<ScanLogSocket>? ScanLogSocketAction;
public Action<ScanStatusSocket>? ScanStatusSocketAction;
public ApiServer(IScanLogService scanService, IBaseCodeService baseCodeService)
{
_scanService = scanService;
_baseCodeService = baseCodeService;
}
/// <summary>
/// 扫描的状态回传
/// </summary>
/// <param name="messageHeader"></param>
/// <param name="containerRegisterQuery"></param>
/// <returns></returns>
[EnableCors("cors")]
[WebApi(HttpMethodType.POST)]
public Back ScanStatus(ScanStatusSocket scanStatus)
{
if (scanStatus.is_alarm == 1 && scanStatus.device_status != null && scanStatus.device_status.Count > 0)
{
List<string> ls = new List<string>();
var baseCodes = _baseCodeService.QuListCache();
foreach (var baseCode in scanStatus.device_status)
{
var enBaseCode = baseCodes.FirstOrDefault(x=>x.Code==baseCode);
if (enBaseCode != null)
{
ls.Add(enBaseCode.State);
}
}
scanStatus.status_txt = ls;
}
ScanStatusSocketAction?.Invoke(scanStatus);
return new Back();
}
/// <summary>
/// 入库开始
/// </summary>
/// <param name="messageHeader"></param>
/// <param name="containerRegisterQuery"></param>
/// <returns></returns>
[EnableCors("cors")]
[WebApi(HttpMethodType.POST)]
public Back ScanBack(ScanLogSocket scanStatus)
{
ScanLogSocketAction?.Invoke(scanStatus);
_scanService.Insert(new ScanLogModel()
{
CreateTime = scanStatus.CreateTime,
DataType = scanStatus.data_type,
Code = scanStatus.code,
Rfid = scanStatus.rfid,
Ocr = scanStatus.ocr,
Url = scanStatus.url
});
return new Back();
}
}
}