diff --git a/SlnMesnac.RfidUpload.Analysis/InstructionAdapter.cs b/SlnMesnac.RfidUpload.Analysis/InstructionAdapter.cs index 167ee9e..bafa69a 100644 --- a/SlnMesnac.RfidUpload.Analysis/InstructionAdapter.cs +++ b/SlnMesnac.RfidUpload.Analysis/InstructionAdapter.cs @@ -1,8 +1,7 @@ -using NLog; using SlnMesnac.RfidUpload.Common; using SlnMesnac.RfidUpload.Model; +using SlnMesnac.RfidUpload.NLog; using System; -using System.Collections.Generic; using System.Text; namespace SlnMesnac.RfidUpload.Analysis @@ -13,7 +12,7 @@ namespace SlnMesnac.RfidUpload.Analysis public class InstructionAdapter { private MsgUtil _msgUtil = MsgUtil.Instance; - private static Logger logger = LogManager.GetCurrentClassLogger(); + private readonly LogHelper logger = LogHelper.Instance; #region 单例实现 private static readonly Lazy _lazy = new Lazy(() => new InstructionAdapter()); diff --git a/SlnMesnac.RfidUpload.Business/HandleBusiness.cs b/SlnMesnac.RfidUpload.Business/HandleBusiness.cs index 6080a20..1944921 100644 --- a/SlnMesnac.RfidUpload.Business/HandleBusiness.cs +++ b/SlnMesnac.RfidUpload.Business/HandleBusiness.cs @@ -124,10 +124,11 @@ namespace SlnMesnac.RfidUpload.Business return packets; } - public void apiTest(string url) + public void upload(int code,string paramStr,string msg) { //WebApiClientApp api = new WebApiClientApp(); - _webApiClientApp.Upload(url); + string result = _webApiClientApp.UploadAsync(code,paramStr); + RefreshLogMessageEvent?.Invoke($"CSB{msg}接口调用结果:{result}"); } /// diff --git a/SlnMesnac.RfidUpload.Business/SerialPortBusiness.cs b/SlnMesnac.RfidUpload.Business/SerialPortBusiness.cs index 67645a8..75d7356 100644 --- a/SlnMesnac.RfidUpload.Business/SerialPortBusiness.cs +++ b/SlnMesnac.RfidUpload.Business/SerialPortBusiness.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.IO.Ports; using System.Linq; using System.Threading; +using TouchSocket.Sockets; namespace SlnMesnac.RfidUpload.Business { @@ -49,15 +51,36 @@ namespace SlnMesnac.RfidUpload.Business /// /// 打开串口 /// - public void Open() + //public void Open() + //{ + // string port = System.IO.Ports.SerialPort.GetPortNames().FirstOrDefault(); + // _serialPort = new SerialPort(port, 115200, Parity.None, 8, StopBits.One); + // _serialPort.DataReceived += SerialPortDataReceived; + + // _serialPort.Open(); + //} + + /// + /// 打开串口 + /// + /// 串口号 + /// 波特率 + /// 校验位None = 0,Odd = 1, Even = 2,Mark = 3,Space = 4, + /// 数据位 + /// 停止位 + public void OpenSerialPort(string serialPort, int baudRate, int parity, int dataBits, int stopBits) { - string port = System.IO.Ports.SerialPort.GetPortNames().FirstOrDefault(); - _serialPort = new SerialPort(port, 115200, Parity.None, 8, StopBits.One); - _serialPort.DataReceived += SerialPortDataReceived; + if (string.IsNullOrEmpty(serialPort)) + { + throw new ArgumentException("串口号不能为空"); + } + _serialPort = new SerialPort(serialPort, baudRate, (System.IO.Ports.Parity)parity, dataBits, (StopBits)stopBits); + _serialPort.DataReceived += SerialPortDataReceived; _serialPort.Open(); } + /// /// 关闭串口 /// @@ -96,7 +119,10 @@ namespace SlnMesnac.RfidUpload.Business } else { - RefreshLogMessageEvent?.Invoke("心跳指令不进行逻辑处理"); + //RefreshLogMessageEvent?.Invoke("心跳指令不进行逻辑处理"); + + //.Send(item.Id, "heartbeat"); + _serialPort.WriteLine("heartbeat"); } } catch (Exception ex) @@ -120,5 +146,15 @@ namespace SlnMesnac.RfidUpload.Business return false; } + + /// + /// 获取系统内的串口 + /// + /// + public void GetSerialPorts(out List serialPorts) + { + serialPorts = SerialPort.GetPortNames().ToList(); + } + } } \ No newline at end of file diff --git a/SlnMesnac.RfidUpload.Business/SlnMesnac.RfidUpload.Business.csproj b/SlnMesnac.RfidUpload.Business/SlnMesnac.RfidUpload.Business.csproj index c86fc79..d3e3651 100644 --- a/SlnMesnac.RfidUpload.Business/SlnMesnac.RfidUpload.Business.csproj +++ b/SlnMesnac.RfidUpload.Business/SlnMesnac.RfidUpload.Business.csproj @@ -13,6 +13,10 @@ + + + + diff --git a/SlnMesnac.RfidUpload.Model/ContainerInbound.cs b/SlnMesnac.RfidUpload.Model/ContainerInbound.cs index a65c893..4e63465 100644 --- a/SlnMesnac.RfidUpload.Model/ContainerInbound.cs +++ b/SlnMesnac.RfidUpload.Model/ContainerInbound.cs @@ -5,39 +5,53 @@ namespace SlnMesnac.RfidUpload.Model /// public class ContainerInbound { - /// - /// 入参1,请求报文到消息头 - /// - public string messageHeader { get; set; } - - /// - /// 入参2,将下列参数封装到batchOpenQuery - /// - public string batchOpenQuery { get; set; } - - /// - /// 机构代码 - /// - public string opOrgCode { get; set; } - - /// - /// 登录人代码 - /// - public string userCode { get; set; } - - /// - /// 登录人名称 - /// - public string userName { get; set; } - - /// - /// 省份代码 - /// - public string province { get; set; } - - /// - /// 容器条码 - /// - public string rqtm { get; set; } + ///// + ///// 入参1,请求报文到消息头 + ///// + //public string messageHeader { get; set; } + + ///// + ///// 入参2,将下列参数封装到batchOpenQuery + ///// + //public string batchOpenQuery { get; set; } + + ///// + ///// 机构代码 + ///// + //public string opOrgCode { get; set; } + + ///// + ///// 登录人代码 + ///// + //public string userCode { get; set; } + + ///// + ///// 登录人名称 + ///// + //public string userName { get; set; } + + ///// + ///// 省份代码 + ///// + //public string province { get; set; } + + ///// + ///// 容器条码 + ///// + //public string rqtm { get; set; } + + public int code { get; set; } + + public string requestURL { get; set; } + + public string containerRegisterQuery { get; set; } + + public string sysCode { get; set; } + + public string password { get; set; } + + public string ak { get; set; } + + public string sk { get; set; } } } \ No newline at end of file diff --git a/SlnMesnac.RfidUpload.Model/apiParam/ApiResult.cs b/SlnMesnac.RfidUpload.Model/apiParam/ApiResult.cs new file mode 100644 index 0000000..5934fcf --- /dev/null +++ b/SlnMesnac.RfidUpload.Model/apiParam/ApiResult.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.Model.apiParam +* 唯一标识:fbf869f5-fcea-44c6-b350-7b243fa26d45 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-07-02 16:00:16 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.Model.apiParam +{ + public class ApiResult + { + public string status { get; set; } + + public string msg { get; set; } + + public static ApiResult Success() + { + return new ApiResult { status = "200",msg = "向客户端发送消息成功!" }; + } + + public static ApiResult Fail() + { + return new ApiResult { status = "101", msg = "向客户端发送消息失败!" }; + } + + public static ApiResult TimeOut() + { + return new ApiResult { status = "201", msg = "向客户端发送消息成功,接收客户端消息超时!" }; + } + + public static ApiResult Error() + { + return new ApiResult { status = "100", msg = "向客户端发送消息失败!" }; + } + } +} diff --git a/SlnMesnac.RfidUpload.Model/apiParam/BatchOpenQuery.cs b/SlnMesnac.RfidUpload.Model/apiParam/BatchOpenQuery.cs new file mode 100644 index 0000000..a91d91c --- /dev/null +++ b/SlnMesnac.RfidUpload.Model/apiParam/BatchOpenQuery.cs @@ -0,0 +1,106 @@ +using SlnMesnac.RfidUpload.Common; +using System; +using System.Collections.Generic; +using System.Text; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.Model.apiParam +* 唯一标识:923d436a-eb53-433b-87f6-f00771f525da +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-10-29 14:57:58 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.Model.apiParam +{ + /// + /// 容器入库接口参数 + /// + public class BatchOpenQuery + { + private static readonly Lazy lazy = new Lazy(() => new BatchOpenQuery()); + + public static BatchOpenQuery Instance + { + get + { + return lazy.Value; + } + } + + private BatchOpenQuery() + { + + } + + private static INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/App.InI"); + + /// + /// 机构代码 + /// + public string opOrgCode + { + get { return iNIFile.IniReadValue("BatchOpenQuery", "opOrgCode"); } + set { iNIFile.IniWriteValue("BatchOpenQuery", "opOrgCode", value.ToString()); } + } + + /// + /// 登录人代码 + /// + public string userCode + { + get { return iNIFile.IniReadValue("BatchOpenQuery", "userCode"); } + set { iNIFile.IniWriteValue("BatchOpenQuery", "userCode", value.ToString()); } + } + + /// + /// 登录人名称 + /// + public string userName + { + get { return iNIFile.IniReadValue("BatchOpenQuery", "userName"); } + set { iNIFile.IniWriteValue("BatchOpenQuery", "userName", value.ToString()); } + } + + /// + /// 省份代码 + /// + public string provice + { + get { return iNIFile.IniReadValue("BatchOpenQuery", "provice"); } + set { iNIFile.IniWriteValue("BatchOpenQuery", "provice", value.ToString()); } + } + + /// + /// 容器条码 + /// + public string rqtm + { + get { return iNIFile.IniReadValue("BatchOpenQuery", "rqtm"); } + set { iNIFile.IniWriteValue("BatchOpenQuery", "rqtm", value.ToString()); } + } + + /// + /// 设备编码 + /// + public string devicedId + { + get { return iNIFile.IniReadValue("BatchOpenQuery", "devicedId"); } + set { iNIFile.IniWriteValue("BatchOpenQuery", "devicedId", value.ToString()); } + } + } +} diff --git a/SlnMesnac.RfidUpload.Model/apiParam/ContainerRegisterQuery.cs b/SlnMesnac.RfidUpload.Model/apiParam/ContainerRegisterQuery.cs new file mode 100644 index 0000000..2600b25 --- /dev/null +++ b/SlnMesnac.RfidUpload.Model/apiParam/ContainerRegisterQuery.cs @@ -0,0 +1,170 @@ +using SlnMesnac.RfidUpload.Common; +using SlnMesnac.RfidUpload.Model.config; +using System; +using System.Collections.Generic; +using System.Text; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.Model.apiParam +* 唯一标识:82cc9323-4b7f-4490-8b0a-6cd7d56f5f84 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-10-29 14:53:32 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.Model.apiParam +{ + /// + /// 容器指定封发扫描接口参数 + /// + public class ContainerRegisterQuery + { + private static readonly Lazy lazy = new Lazy(() => new ContainerRegisterQuery()); + + public static ContainerRegisterQuery Instance + { + get + { + return lazy.Value; + } + } + + private ContainerRegisterQuery() + { + + } + + private static INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/App.InI"); + + /// + /// 机构代码 + /// + public string opOrgCode + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "opOrgCode"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "opOrgCode", value.ToString()); } + } + + /// + /// 省份代码 + /// + public string opOrgName + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "opOrgName"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "opOrgName", value.ToString()); } + } + + /// + /// 登录人代码 + /// + public string userCode + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "userCode"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "userCode", value.ToString()); } + } + + /// + /// 登录人名称 + /// + public string userName + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "userName"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "userName", value.ToString()); } + } + + /// + /// 省份代码 + /// + public string provice + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "provice"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "provice", value.ToString()); } + } + + /// + /// 容器种类名称 + /// + public string rqzlmc + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "rqzlmc"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "rqzlmc", value.ToString()); } + } + + /// + /// 总包id + /// + public string zbid + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "zbid"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "zbid", value.ToString()); } + } + + /// + /// 寄达局名称 + /// + public string destinationOrgName + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "destinationOrgName"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "destinationOrgName", value.ToString()); } + } + + /// + /// 寄达局编号 + /// + public string destinationOrgCode + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "destinationOrgCode"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "destinationOrgCode", value.ToString()); } + } + + /// + /// 容器种类 + /// + public string rqzl + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "rqzl"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "rqzl", value.ToString()); } + } + + /// + /// 容器型号 + /// + public string rqxh + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "rqxh"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "rqxh", value.ToString()); } + } + + /// + /// 容器型号名称 + /// + public string rqxhmc + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "rqxhmc"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "rqxhmc", value.ToString()); } + } + + /// + /// 容器条码 + /// + public string rqtm + { + get { return iNIFile.IniReadValue("ContainerRegisterQuery", "rqtm"); } + set { iNIFile.IniWriteValue("ContainerRegisterQuery", "rqtm", value.ToString()); } + } + } +} diff --git a/SlnMesnac.RfidUpload.Model/apiParam/InStoreParam.cs b/SlnMesnac.RfidUpload.Model/apiParam/InStoreParam.cs new file mode 100644 index 0000000..65f2486 --- /dev/null +++ b/SlnMesnac.RfidUpload.Model/apiParam/InStoreParam.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Text; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.Model.apiParam +* 唯一标识:cd1c0cdd-b51d-425a-91e3-1dd20eddb4e9 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-07-02 15:59:39 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.Model.apiParam +{ + public class InStoreParam + { + /// + /// 机构代码 + /// + public string opOrgCode { get; set; } + + /// + /// 登录人代码 + /// + public string userCode { get; set; } + + /// + /// 登录人名称 + /// + public string userName { get; set; } + + /// + /// 省份代码 + /// + public string province { get; set; } + } +} diff --git a/SlnMesnac.RfidUpload.Model/ContainerSealed.cs b/SlnMesnac.RfidUpload.Model/apiParam/OutStoreParam.cs similarity index 60% rename from SlnMesnac.RfidUpload.Model/ContainerSealed.cs rename to SlnMesnac.RfidUpload.Model/apiParam/OutStoreParam.cs index d786e35..0ae52fc 100644 --- a/SlnMesnac.RfidUpload.Model/ContainerSealed.cs +++ b/SlnMesnac.RfidUpload.Model/apiParam/OutStoreParam.cs @@ -1,30 +1,38 @@ -namespace SlnMesnac.RfidUpload.Model +using System; +using System.Collections.Generic; +using System.Text; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.Model.apiParam +* 唯一标识:43029bd1-d802-45dd-b3a8-c348c9a6f104 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-07-02 15:59:48 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.Model.apiParam { - /// - /// 容器封发扫描 - /// - public class ContainerSealed + public class OutStoreParam { - /// - /// 入参1,请求报文到消息头 - /// - public string messageHeader { get; set; } - - /// - /// 入参2,将下列参数封装到containerRegisterQuery - /// - public string containerRegisterQuery { get; set; } - /// /// 机构代码 /// public string opOrgCode { get; set; } - /// - /// 机构名称 - /// - public string opOrgName { get; set; } - /// /// 登录人代码 /// @@ -46,7 +54,7 @@ namespace SlnMesnac.RfidUpload.Model public string rqzlmc { get; set; } /// - /// 总包Id + /// 总包id /// public string zbid { get; set; } @@ -74,10 +82,5 @@ namespace SlnMesnac.RfidUpload.Model /// 容器型号名称 /// public string rqxhmc { get; set; } - - /// - /// 容器条码 - /// - public string rqtm { get; set; } } -} \ No newline at end of file +} diff --git a/SlnMesnac.RfidUpload.Model/config/AppConfig.cs b/SlnMesnac.RfidUpload.Model/config/AppConfig.cs index 94994e8..d9602e9 100644 --- a/SlnMesnac.RfidUpload.Model/config/AppConfig.cs +++ b/SlnMesnac.RfidUpload.Model/config/AppConfig.cs @@ -1,4 +1,5 @@ using SlnMesnac.RfidUpload.Common; +using SlnMesnac.RfidUpload.Model.apiParam; using System; using System.Collections.Generic; using System.Text; @@ -58,5 +59,47 @@ namespace SlnMesnac.RfidUpload.Model.config get { return iNIFile.IniReadValue("SystemConfig", "FilterInterval"); } set { iNIFile.IniWriteValue("SystemConfig", "FilterInterval", value.ToString()); } } + + /// + /// 工作模式 + /// + public string workModel + { + get { return iNIFile.IniReadValue("SystemConfig", "WorkModel"); } + set { iNIFile.IniWriteValue("SystemConfig", "WorkModel", value.ToString()); } + } + + /// + /// 设备编码 + /// + public string requestURL + { + get { return iNIFile.IniReadValue("SystemConfig", "RequestURL"); } + set { iNIFile.IniWriteValue("SystemConfig", "RequestURL", value.ToString()); } + } + + public string sysCode + { + get { return iNIFile.IniReadValue("SystemConfig", "sysCode"); } + set { iNIFile.IniWriteValue("SystemConfig", "sysCode", value.ToString()); } + } + + public string password + { + get { return iNIFile.IniReadValue("SystemConfig", "password"); } + set { iNIFile.IniWriteValue("SystemConfig", "password", value.ToString()); } + } + + public string ak + { + get { return iNIFile.IniReadValue("SystemConfig", "ak"); } + set { iNIFile.IniWriteValue("SystemConfig", "ak", value.ToString()); } + } + + public string sk + { + get { return iNIFile.IniReadValue("SystemConfig", "sk"); } + set { iNIFile.IniWriteValue("SystemConfig", "sk", value.ToString()); } + } } } diff --git a/SlnMesnac.RfidUpload.NLog/LogHelper.cs b/SlnMesnac.RfidUpload.NLog/LogHelper.cs new file mode 100644 index 0000000..94a7b44 --- /dev/null +++ b/SlnMesnac.RfidUpload.NLog/LogHelper.cs @@ -0,0 +1,158 @@ +using log4net.Config; +using log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.NLog +* 唯一标识:63646c4f-5bfd-4936-a480-7c23460ba2c0 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-11-05 10:34:55 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.NLog +{ + public class LogHelper + { + + private static readonly Lazy _lazy = new Lazy(() => new LogHelper()); + + public static LogHelper Instance + { + get + { + return _lazy.Value; + } + } + private LogHelper() + { + var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); + XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); + } + public readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo"); + public readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror"); + public readonly log4net.ILog logPlc = log4net.LogManager.GetLogger("plclog"); + public readonly log4net.ILog logRfid = log4net.LogManager.GetLogger("rfidlog"); + public readonly log4net.ILog logView = log4net.LogManager.GetLogger("viewlog"); + public readonly log4net.ILog sqllog = log4net.LogManager.GetLogger("sqllog"); + public readonly log4net.ILog semaphorelog = log4net.LogManager.GetLogger("semaphorelog"); + /// + /// 记录Info日志 + /// + /// + /// + public void Info(string msg) + { + if (loginfo.IsInfoEnabled) + { + loginfo.Info(msg); + } + } + + /// + /// 记录PLC日志 + /// + /// + public void PlcLog(string msg) + { + if (logPlc.IsInfoEnabled) + { + logPlc.Info(msg); + } + } + + /// + /// 记录Rfid日志 + /// + /// + public void RfidLog(string msg) + { + if (logRfid.IsInfoEnabled) + { + logRfid.Info(msg); + } + } + + /// + /// 界面日志 + /// + /// + public void ViewLog(string msg) + { + if (logView.IsInfoEnabled) + { + logView.Info(msg); + } + } + + public void SqlLog(string msg) + { + if (sqllog.IsInfoEnabled) + { + sqllog.Info(msg); + } + } + + public void SemaphoreLog(string msg) + { + if (semaphorelog.IsInfoEnabled) + { + semaphorelog.Info(msg); + } + } + + /// + /// 记录Error日志 + /// + /// + /// + public void Error(string info, Exception ex = null) + { + if (!string.IsNullOrEmpty(info) && ex == null) + { + logerror.ErrorFormat("【附加信息】 : {0}
", new object[] { info }); + } + else if (!string.IsNullOrEmpty(info) && ex != null) + { + string errorMsg = BeautyErrorMsg(ex); + logerror.ErrorFormat("【附加信息】 : {0}
{1}", new object[] { info, errorMsg }); + } + else if (string.IsNullOrEmpty(info) && ex != null) + { + string errorMsg = BeautyErrorMsg(ex); + logerror.Error(errorMsg); + } + } + + /// + /// 美化错误信息 + /// + /// 异常 + /// 错误信息 + private string BeautyErrorMsg(Exception ex) + { + string errorMsg = string.Format("【异常类型】:{0}
【异常信息】:{1}
【堆栈调用】:{2}", new object[] { ex.GetType().Name, ex.Message, ex.StackTrace }); + errorMsg = errorMsg.Replace("\r\n", "
"); + errorMsg = errorMsg.Replace("位置", "位置"); + return errorMsg; + } + } +} diff --git a/SlnMesnac.RfidUpload.NLog/SlnMesnac.RfidUpload.NLog.csproj b/SlnMesnac.RfidUpload.NLog/SlnMesnac.RfidUpload.NLog.csproj index c615582..1f2e2c3 100644 --- a/SlnMesnac.RfidUpload.NLog/SlnMesnac.RfidUpload.NLog.csproj +++ b/SlnMesnac.RfidUpload.NLog/SlnMesnac.RfidUpload.NLog.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -10,16 +10,15 @@ - + + ..\packages\log4net.dll + - - - - - - + + PreserveNewest + diff --git a/SlnMesnac.RfidUpload.NLog/log4net.config b/SlnMesnac.RfidUpload.NLog/log4net.config new file mode 100644 index 0000000..33ab07c --- /dev/null +++ b/SlnMesnac.RfidUpload.NLog/log4net.config @@ -0,0 +1,153 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SlnMesnac.RfidUpload.TouchSocket/ApiServer.cs b/SlnMesnac.RfidUpload.TouchSocket/ApiServer.cs new file mode 100644 index 0000000..8695db5 --- /dev/null +++ b/SlnMesnac.RfidUpload.TouchSocket/ApiServer.cs @@ -0,0 +1,133 @@ +using SlnMesnac.RfidUpload.Model; +using SlnMesnac.RfidUpload.Model.apiParam; +using System; +using System.Collections.Generic; +using System.Text; +using TouchSocket.Rpc; +using TouchSocket.WebApi; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.TouchSocket +* 唯一标识:f4ca948d-1fdb-4241-8251-2858f027de04 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-07-02 15:42:57 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.TouchSocket +{ + public partial class ApiServer : RpcServer + { + private static ApiServer instance; + + private ApiServer() { } + + public static ApiServer GetInstance() + { + if (instance == null) + { + lock (typeof(ApiServer)) + { + if (instance == null) + { + instance = new ApiServer(); + } + } + } + return instance; + } + + + public delegate void RefreshScanInfoInCenterStart(); + /// + /// 入库开始事件刷新 + /// + public event RefreshScanInfoInCenterStart RefreshScanInfoInCenterStartEvent; + + public delegate void RefreshScanInfoInCenterStop(); + /// + /// 入库结束事件刷新 + /// + public event RefreshScanInfoInCenterStop RefreshScanInfoInCenterStopEvent; + + public delegate void RefreshScanInfoOutCenterStart(); + /// + /// 出库开始事件刷新 + /// + public event RefreshScanInfoOutCenterStart RefreshScanInfoOutCenterStartEvent; + + public delegate void RefreshScanInfoOutCenterStop(); + /// + /// 出库结束事件刷新 + /// + public event RefreshScanInfoOutCenterStop RefreshScanInfoOutCenterStopEvent; + + /// + /// 入库开始 + /// + /// + /// + /// + [EnableCors("cors")] + [WebApi(HttpMethodType.POST)] + public ApiResult getScanInfoInCenterStart(string messageHeader,InStoreParam containerRegisterQuery) + { + RefreshScanInfoInCenterStartEvent?.Invoke(); + return ApiResult.Success(); + } + + /// + /// 入库结束 + /// + /// + /// + /// + [EnableCors("cors")] + [WebApi(HttpMethodType.POST)] + public ApiResult getScanInfoInCenterStop(string messageHeader, InStoreParam containerRegisterQuery) + { + RefreshScanInfoInCenterStopEvent?.Invoke(); + return ApiResult.Success(); + } + + /// + /// 出库开始 + /// + /// + /// + /// + [WebApi(HttpMethodType.POST)] + public ApiResult getScanInfoOutCenterStart(string messageHeader, OutStoreParam containerRegisterQuery) + { + RefreshScanInfoOutCenterStartEvent?.Invoke(); + return ApiResult.Success(); + } + + /// + /// 出库结束 + /// + /// + /// + /// + [WebApi(HttpMethodType.POST)] + public ApiResult getScanInfoOutCenterStop(string messageHeader, OutStoreParam containerRegisterQuery) + { + RefreshScanInfoOutCenterStopEvent?.Invoke(); + return ApiResult.Success(); + } + } +} diff --git a/SlnMesnac.RfidUpload.TouchSocket/SlnMesnac.RfidUpload.TouchSocket.csproj b/SlnMesnac.RfidUpload.TouchSocket/SlnMesnac.RfidUpload.TouchSocket.csproj index c0915eb..a6fa20c 100644 --- a/SlnMesnac.RfidUpload.TouchSocket/SlnMesnac.RfidUpload.TouchSocket.csproj +++ b/SlnMesnac.RfidUpload.TouchSocket/SlnMesnac.RfidUpload.TouchSocket.csproj @@ -6,11 +6,13 @@ - + + + diff --git a/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs b/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs index c727b69..07b429f 100644 --- a/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs +++ b/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs @@ -1,6 +1,17 @@ -using SlnMesnac.RfidUpload.Model; +using Newtonsoft.Json; +using SlnMesnac.RfidUpload.Common; +using SlnMesnac.RfidUpload.Model; +using SlnMesnac.RfidUpload.Model.config; +using SlnMesnac.RfidUpload.NLog; using System; -using TouchSocket.Rpc.WebApi; +using System.IO; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using TouchSocket.Core; +using TouchSocket.Rpc; +using TouchSocket.Sockets; +using TouchSocket.WebApi; namespace SlnMesnac.RfidUpload.TouchSocket { @@ -18,40 +29,68 @@ namespace SlnMesnac.RfidUpload.TouchSocket } } #endregion + private LogHelper logger = LogHelper.Instance; + private JsonChange jsonChange = JsonChange.Instance; + private AppConfig appConfig = AppConfig.Instance; private WebApiClientApp() { } - private WebApiClient CreateWebApiClient(string url) + private WebApiClientSlim CreateWebApiClient(string url) { - WebApiClient client = new WebApiClient(); - client.Setup(url); - client.Connect(); - Console.WriteLine("连接成功"); + var client = new WebApiClientSlim(new System.Net.Http.HttpClient()); + client.Setup(new TouchSocketConfig() + .SetRemoteIPHost("http://127.0.0.1:9090") + .ConfigurePlugins(a => + { + })); return client; } - public void Upload(string url) + public string UploadAsync(int code,string paramStr) { + string result = string.Empty; try { - var client = CreateWebApiClient(url); - var param = new ContainerInbound() { - messageHeader = Guid.NewGuid().ToString(), - batchOpenQuery = "OK", - opOrgCode = Guid.NewGuid().ToString() + code = code, + requestURL = appConfig.requestURL, + sysCode = appConfig.sysCode, + password = appConfig.password, + ak = appConfig.ak, + sk = appConfig.sk, + containerRegisterQuery = paramStr }; - - var sum2 = client.Invoke("POST:/Server/ContainerInboundApi", null, param); - Console.WriteLine($"Post调用成功,结果:{sum2.Message}"); - + var str = jsonChange.ModeToJson(param); + logger.Info($"请求CSB接口调用服务,参数:{str}"); + result = Post("http://127.0.0.1:9090/api/uploadCsb", param); + logger.Info($"CSB接口返回信息:{result}"); } catch (Exception e) { Console.WriteLine(e.Message); + result = e.Message; + logger.Info($"请求CSB接口调用服务异常:{e.Message}"); } + return result; + } + + public static string Post(string url, object postData) + { + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + req.Method = "POST"; + req.ContentType = "application/json"; + req.Timeout = 5000; + + if (req == null) return string.Empty; + byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(postData)); + using (Stream reqStream = req.GetRequestStream()) + reqStream.Write(data, 0, data.Length); + using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) + using (Stream stream = resp.GetResponseStream()) + using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + return reader.ReadToEnd(); } } } \ No newline at end of file diff --git a/SlnMesnac.RfidUpload.TouchSocket/WebApiServerApp.cs b/SlnMesnac.RfidUpload.TouchSocket/WebApiServerApp.cs new file mode 100644 index 0000000..dfa7893 --- /dev/null +++ b/SlnMesnac.RfidUpload.TouchSocket/WebApiServerApp.cs @@ -0,0 +1,118 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using TouchSocket.Core; +using TouchSocket.Http; +using TouchSocket.Rpc; +using TouchSocket.Sockets; +using TouchSocket.WebApi; +using TouchSocket.WebApi.Swagger; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.RfidUpload.TouchSocket +* 唯一标识:2f39e963-acb9-44d1-9980-27aaa910de29 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-07-02 15:35:25 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.RfidUpload.TouchSocket +{ + public sealed class WebApiServerApp + { + private static readonly Lazy _lazy = new Lazy(() => new WebApiServerApp()); + + public static WebApiServerApp Instance + { + get + { + return _lazy.Value; + } + } + + private WebApiServerApp() { } + + private ApiServer apiServer = ApiServer.GetInstance(); + + public void Init() + { + try + { + var service = new HttpService(); + service.Setup(new TouchSocketConfig() + .SetListenIPHosts(7789) + .ConfigureContainer(a => + { + a.AddRpcStore(store => + { + + store.RegisterServer(apiServer);//注册服务 + }); + + a.AddCors(corsOption => + { + corsOption.Add("cors", corsBuilder => + { + corsBuilder.AllowAnyMethod() + .AllowAnyOrigin(); + }); + }); + + a.AddLogger(logger => + { + logger.AddConsoleLogger(); + logger.AddFileLogger(); + }); + }) + .ConfigurePlugins(a => + { + a.UseCheckClear(); + + a.Add(); + + a.UseWebApi() + .ConfigureConverter(converter => + { + converter.AddJsonSerializerFormatter(new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None }); + }); + + a.UseSwagger();//使用Swagger页面 + //.UseLaunchBrowser(); + + a.UseDefaultHttpServicePlugin(); + })); + service.Start(); + + Console.WriteLine("以下连接用于测试webApi"); + Console.WriteLine($"使用:http://127.0.0.1:7789/swagger/index.html"); + }catch(Exception ex) + { + Console.WriteLine(ex.ToString()); + } + + //Console.ReadLine(); + } + } + + internal class AuthenticationPlugin : PluginBase, IHttpPlugin + { + public async Task OnHttpRequest(IHttpSocketClient client, HttpContextEventArgs e) + { + await e.InvokeNext(); + } + } +} diff --git a/SlnMesnac.RfidUpload.UI/MainWindow.xaml b/SlnMesnac.RfidUpload.UI/MainWindow.xaml index 46a77b9..fde09cd 100644 --- a/SlnMesnac.RfidUpload.UI/MainWindow.xaml +++ b/SlnMesnac.RfidUpload.UI/MainWindow.xaml @@ -3,12 +3,17 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:SlnMesnac.RfidUpload.UI" + xmlns:local="clr-namespace:SlnMesnac.RfidUpload.UI" + xmlns:local1="clr-namespace:SlnMesnac.RfidUpload.UI.converter" mc:Ignorable="d" - Title="海威物联RFID移动盘点系统" Height="766" Width="1268" ResizeMode="NoResize" Topmost="False"> - + Title="海威物联RFID移动盘点系统" Height="766" Width="1268" + WindowState="Maximized" WindowStyle="SingleBorderWindow" > + + + + + + @@ -23,52 +28,77 @@ - - - - - -