diff --git a/SlnMesnac.RfidUpload.Business/CsbHandleBusiness.cs b/SlnMesnac.RfidUpload.Business/CsbHandleBusiness.cs index f156d09..dca016a 100644 --- a/SlnMesnac.RfidUpload.Business/CsbHandleBusiness.cs +++ b/SlnMesnac.RfidUpload.Business/CsbHandleBusiness.cs @@ -37,6 +37,7 @@ namespace SlnMesnac.RfidUpload.Business { public class CsbHandleBusiness { + private static readonly Lazy _lazy = new Lazy(() => new CsbHandleBusiness()); @@ -90,7 +91,7 @@ namespace SlnMesnac.RfidUpload.Business } }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync(jsonString); + var str = webApiClientApp.UploadAsync(jsonString, "容器指定封发扫描接口"); CsbResult res = JsonConvert.DeserializeObject(str); logHelper.Info($"容器指定封发扫描接口返回信息:{jsonChange.ModeToJson(res)}"); } @@ -106,6 +107,7 @@ namespace SlnMesnac.RfidUpload.Business public CsbResult scanAnyContainerCodeByCsb(string rqtm) { CsbResult res = new CsbResult(); + try { var jsonObject = new JObject @@ -118,10 +120,13 @@ namespace SlnMesnac.RfidUpload.Business ["devicedId"] = appConfig.devicedId, }; + string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("scanAnyContainerCodeByCsb", "batchOpenQuery", jsonString); + + + var str = webApiClientApp.UploadAsync("scanAnyContainerCodeByCsb", + "batchOpenQuery", jsonString, "容器入库"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器入库接口返回信息:{jsonChange.ModeToJson(res)}"); return res; } catch (Exception ex) @@ -153,10 +158,15 @@ namespace SlnMesnac.RfidUpload.Business }, }; + + + string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("containerStorageQueryByCsb", "newContainerStorageQuery", jsonString); + + var str = webApiClientApp.UploadAsync("containerStorageQueryByCsb", "newContainerStorageQuery", + jsonString, "新容器入库-调拨单号验证接口"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"新容器入库-调拨单号验证接口返回信息:{jsonChange.ModeToJson(res)}"); + } catch (Exception ex) { @@ -185,9 +195,10 @@ namespace SlnMesnac.RfidUpload.Business ["rqtmEnd"] = rqtmEnd, }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("containerStorageBatchQueryByCsb", "newContainerStorageBatchQuery", jsonString); + var str = webApiClientApp.UploadAsync("containerStorageBatchQueryByCsb", + "newContainerStorageBatchQuery", jsonString, "新容器入库-按送货单接收容器接口"); CsbResult res = JsonConvert.DeserializeObject(str); - logHelper.Info($"新容器入库-按送货单接收容器接口返回信息:{jsonChange.ModeToJson(res)}"); + } catch (Exception ex) { @@ -209,9 +220,10 @@ namespace SlnMesnac.RfidUpload.Business ["msgType"] = msgType, }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("receContainerStorageByCsb", "newContainerStorageQuery", jsonString); + var str = webApiClientApp.UploadAsync("receContainerStorageByCsb", "newContainerStorageQuery", + jsonString, "新容器入库-按送货单反馈接收结果接口"); CsbResult res = JsonConvert.DeserializeObject(str); - logHelper.Info($"新容器入库-按送货单反馈接收结果接口返回信息:{jsonChange.ModeToJson(res)}"); + } catch (Exception ex) { @@ -236,9 +248,10 @@ namespace SlnMesnac.RfidUpload.Business }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("transferOrderFfjhByCsb", "TdjStockTransferOrderQuery", jsonString); + var str = webApiClientApp.UploadAsync("transferOrderFfjhByCsb", "TdjStockTransferOrderQuery", + jsonString, "容器封发-获取调拨单和封发计划"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器封发-获取调拨单和封发计划接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -267,9 +280,10 @@ namespace SlnMesnac.RfidUpload.Business }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("transferOrderFfjhCheckByCsb", "TdjStockTransferOrderffjhCheckQuery", jsonString); + var str = webApiClientApp.UploadAsync("transferOrderFfjhCheckByCsb", + "TdjStockTransferOrderffjhCheckQuery", jsonString, " 容器封发-验证封发计划"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器封发-验证封发计划接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -304,9 +318,12 @@ namespace SlnMesnac.RfidUpload.Business }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("containerScanSealByCsb", "TdjContainerScanSealQuery", jsonString); + + + var str = webApiClientApp.UploadAsync("containerScanSealByCsb", "TdjContainerScanSealQuery", + jsonString, "容器封发-接收容器条码"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器封发-接收容器条码接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -333,10 +350,14 @@ namespace SlnMesnac.RfidUpload.Business ["opBatch"] = opBatch, }; + + string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("containerScanSealResultByCsb", "TdjContainerScanSealQuery", jsonString); + + var str = webApiClientApp.UploadAsync("containerScanSealResultByCsb", "TdjContainerScanSealQuery", + jsonString, "容器封发-反馈接收结果"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器封发-反馈接收结果接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -366,9 +387,10 @@ namespace SlnMesnac.RfidUpload.Business ["opBatch"] = opBatch, }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("findStationSequenceByCsb", "TdjContainerAllotQuery", jsonString); + var str = webApiClientApp.UploadAsync("findStationSequenceByCsb", "TdjContainerAllotQuery", + jsonString, " 容器直连配发-获取邮路卸交站"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器直连配发-获取邮路卸交站接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -403,9 +425,9 @@ namespace SlnMesnac.RfidUpload.Business }; string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("tranPlanCheckByCsb", "TdjContainerAllotQuery", jsonString); + var str = webApiClientApp.UploadAsync("tranPlanCheckByCsb", "TdjContainerAllotQuery", jsonString, "容器直连配发-校验发运计划"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器直连配发-校验发运计划接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -438,10 +460,14 @@ namespace SlnMesnac.RfidUpload.Business ["groupName"] = iNIFile.IniReadValue("TdjContainerAllotQuery", "groupName"), }; + + string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("containerAllotByCsb", "containerAllotByCsb", jsonString); + + + var str = webApiClientApp.UploadAsync("containerAllotByCsb", "containerAllotByCsb", jsonString, "容器直连配发-开始配发"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器直连配发-开始配发接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) @@ -469,10 +495,13 @@ namespace SlnMesnac.RfidUpload.Business ["opBatch"] = opBatch, }; + string jsonString = jsonObject.ToString(); - var str = webApiClientApp.UploadAsync("containerAllotResultByCsb", "TdjContainerAllotQuery", jsonString); + + var str = webApiClientApp.UploadAsync("containerAllotResultByCsb", "TdjContainerAllotQuery", + jsonString, "容器直连配发-反馈接收结果"); res = JsonConvert.DeserializeObject(str); - logHelper.Info($"容器直连配发-反馈接收结果接口返回信息:{jsonChange.ModeToJson(res)}"); + return res; } catch (Exception ex) diff --git a/SlnMesnac.RfidUpload.Business/HandleBusiness.cs b/SlnMesnac.RfidUpload.Business/HandleBusiness.cs index 1944921..9ef8304 100644 --- a/SlnMesnac.RfidUpload.Business/HandleBusiness.cs +++ b/SlnMesnac.RfidUpload.Business/HandleBusiness.cs @@ -127,7 +127,7 @@ namespace SlnMesnac.RfidUpload.Business public void upload(int code,string paramStr,string msg) { //WebApiClientApp api = new WebApiClientApp(); - string result = _webApiClientApp.UploadAsync(code,paramStr); + string result = _webApiClientApp.UploadAsync(code,paramStr,msg); RefreshLogMessageEvent?.Invoke($"CSB{msg}接口调用结果:{result}"); } diff --git a/SlnMesnac.RfidUpload.Common/EmsLog.cs b/SlnMesnac.RfidUpload.Common/EmsLog.cs new file mode 100644 index 0000000..aa2186f --- /dev/null +++ b/SlnMesnac.RfidUpload.Common/EmsLog.cs @@ -0,0 +1,39 @@ +using SQLite; + +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.RfidUpload.Common +{ + public class EmsLogData + { + + public EmsLogData() + { + Id = SnowflakeFactory.NewId; + CreateTime = DateTime.Now; + } + [PrimaryKey] + public long Id { get; set; } + public string Remark { get; set; } = ""; + public string ApiName { get; set; } = ""; + + public string ParamName { get; set; } = ""; + public string paramStr { get; set; } = ""; + + public string Json { get; set; } = ""; + + public DateTime CreateTime { get; set; } + + + public string ResultJson { get; set; } = ""; + + + public string Message = ""; + + + + + } +} diff --git a/SlnMesnac.RfidUpload.Common/SnowflakeFactory.cs b/SlnMesnac.RfidUpload.Common/SnowflakeFactory.cs new file mode 100644 index 0000000..10142c6 --- /dev/null +++ b/SlnMesnac.RfidUpload.Common/SnowflakeFactory.cs @@ -0,0 +1,15 @@ +using NewLife.Data; + +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.RfidUpload.Common +{ + public class SnowflakeFactory + { + private static readonly Snowflake GetInstance = new Snowflake(); + + public static long NewId => GetInstance.NewId(); + } +} diff --git a/SlnMesnac.RfidUpload.Common/SqLiteHelper.cs b/SlnMesnac.RfidUpload.Common/SqLiteHelper.cs index 2942ef7..e4c6b45 100644 --- a/SlnMesnac.RfidUpload.Common/SqLiteHelper.cs +++ b/SlnMesnac.RfidUpload.Common/SqLiteHelper.cs @@ -1,91 +1,91 @@ -//using SQLite; +using SQLite; -//using System; -//using System.Collections.Generic; -//using System.IO; -//using System.Linq.Expressions; -//using System.Text; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq.Expressions; +using System.Text; -//namespace SlnMesnac.RfidUpload.Common -//{ -// /// -// /// SQLite同步方法帮助类 -// /// 作者:追逐时光者 -// /// 创建时间:2023年11月30日 -// /// -// /// -// public class SqLiteHelper where T : new() -// { -// private readonly string _databasePath = Path.Combine(Environment.CurrentDirectory, "db.db"); -// private readonly SQLiteConnection _connection; // SQLite连接对象 +namespace SlnMesnac.RfidUpload.Common +{ + /// + /// SQLite同步方法帮助类 + /// 作者:追逐时光者 + /// 创建时间:2023年11月30日 + /// + /// + public class SqLiteHelper where T : new() + { + private readonly string _databasePath = Path.Combine(Environment.CurrentDirectory, "db.db"); + private readonly SQLiteConnection _connection; // SQLite连接对象 -// /// -// /// 构造函数 -// /// -// public SqLiteHelper() -// { -// // 创建SQLite连接对象并打开连接 -// _connection = new SQLiteConnection(_databasePath); -// _connection.CreateTable(); // 如果表不存在,则创建该表[不会创建重复的表] -// } + /// + /// 构造函数 + /// + public SqLiteHelper() + { + // 创建SQLite连接对象并打开连接 + _connection = new SQLiteConnection(_databasePath); + _connection.CreateTable(); // 如果表不存在,则创建该表[不会创建重复的表] + } -// /// -// /// 数据插入 -// /// -// /// 要插入的数据项 -// /// -// public int Insert(T item) -// { -// return _connection.Insert(item); -// } + /// + /// 数据插入 + /// + /// 要插入的数据项 + /// + public int Insert(T item) + { + return _connection.Insert(item); + } -// /// -// /// 数据删除 -// /// -// /// 要删除的数据的主键ID -// /// -// public int Delete(int id) -// { -// return _connection.Delete(id); -// } + /// + /// 数据删除 + /// + /// 要删除的数据的主键ID + /// + public int Delete(int id) + { + return _connection.Delete(id); + } -// /// -// /// 数据更新 -// /// -// /// 要更新的数据项 -// /// -// public int Update(T item) -// { -// return _connection.Update(item); -// } + /// + /// 数据更新 + /// + /// 要更新的数据项 + /// + public int Update(T item) + { + return _connection.Update(item); + } -// /// -// /// 根据条件查询记录 -// /// -// /// 查询条件 -// /// -// public List Query(Expression> predExpr) -// { -// return _connection.Table().Where(predExpr).ToList(); -// } + /// + /// 根据条件查询记录 + /// + /// 查询条件 + /// + public List Query(Expression> predExpr) + { + return _connection.Table().Where(predExpr).ToList(); + } -// /// -// /// 查询所有数据 -// /// -// /// -// public List QueryAll() -// { -// return _connection.Table().ToList(); -// } + /// + /// 查询所有数据 + /// + /// + public List QueryAll() + { + return _connection.Table().ToList(); + } -// /// -// /// 根据条件查询单条记录 -// /// -// /// 查询条件 -// /// -// public T QuerySingle(Expression> predExpr) -// { -// return _connection.Table().Where(predExpr).FirstOrDefault(); -// } -// } -//} + /// + /// 根据条件查询单条记录 + /// + /// 查询条件 + /// + public T QuerySingle(Expression> predExpr) + { + return _connection.Table().Where(predExpr).FirstOrDefault(); + } + } +} diff --git a/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs b/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs index 2f29c04..66a80a2 100644 --- a/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs +++ b/SlnMesnac.RfidUpload.TouchSocket/WebApiClientApp.cs @@ -15,6 +15,7 @@ using TouchSocket.Core; using TouchSocket.Rpc; using TouchSocket.Sockets; using TouchSocket.WebApi; +using System.Security.Policy; namespace SlnMesnac.RfidUpload.TouchSocket { @@ -36,9 +37,10 @@ namespace SlnMesnac.RfidUpload.TouchSocket private JsonChange jsonChange = JsonChange.Instance; private AppConfig appConfig = AppConfig.Instance; - - public string UploadAsync(int code,string paramStr) + + public string UploadAsync(int code,string paramStr,string reqName) { + string guid = SnowflakeFactory.NewId.ToString(); string result = string.Empty; try { @@ -52,10 +54,16 @@ namespace SlnMesnac.RfidUpload.TouchSocket sk = appConfig.sk, containerRegisterQuery = paramStr }; + + var str = jsonChange.ModeToJson(param); - logger.Info($"请求CSB接口调用服务,参数:{str}"); - result = Post(appConfig.localUrl, param); - logger.Info($"CSB接口返回信息:{result}"); + logger.Info(" "); + logger.Info($"==========={reqName}==========="); + logger.Info($"Http请求的:[{guid}] => {str}"); + logger.Info($"Http请求ParamStr的:[{guid}] => {paramStr}"); + result = client.PostJson(appConfig.localUrl, param); + logger.Info($"Http返回的:[{guid}] => {result}"); + } catch (Exception e) { @@ -67,11 +75,12 @@ namespace SlnMesnac.RfidUpload.TouchSocket } - public string UploadAsync(string apiName, string paramName, string paramStr) + public string UploadAsync(string apiName, string paramName, string paramStr,string reqName) { string result = string.Empty; try { + string guid = SnowflakeFactory.NewId.ToString(); //logger.Info($"请求CSB接口调用服务,参数:{paramStr}"); ContainerInbound container = new ContainerInbound @@ -86,16 +95,15 @@ namespace SlnMesnac.RfidUpload.TouchSocket paramName = paramName, containerRegisterQuery = paramStr }; + var str = jsonChange.ModeToJson(container); - logger.Info("------------------------------http开始-----------------------------------------"); - logger.Info($"apIName:{apiName}"); - logger.Info($"paramName:{paramName}"); - logger.Info($"paramStr:{paramStr}"); - logger.Info($"请求CSB接口调用服务,参数:{str}"); - result = Post(appConfig.localUrl, container); - logger.Info($"CSB接口返回信息:{result}"); - - logger.Info("------------------------------http结束-----------------------------------------"); + logger.Info(" "); + logger.Info($"==========={reqName}==========="); + logger.Info($"Http请求的:[{reqName}]:[{guid}] => {str}"); + logger.Info($"Http请求ParamStr的:[{reqName}]:[{guid}] => {paramStr}"); + result = client.PostJson(appConfig.localUrl, container); + logger.Info($"Http返回的:[{reqName}]:[{guid}] => {result}"); + } catch (Exception e) { @@ -106,19 +114,23 @@ namespace SlnMesnac.RfidUpload.TouchSocket return result; } - - public string UploadAsync(string paramStr) + /// + /// ok + /// + /// + /// + /// + public string UploadAsync(string paramStr, string reqName) { + string guid = SnowflakeFactory.NewId.ToString(); string result = string.Empty; try { - logger.Info("------------------------------http开始-----------------------------------------"); - - logger.Info($"apIName: paramName:"); - logger.Info($"请求CSB接口调用服务,参数:{paramStr}"); - result = Post(appConfig.localUrl, paramStr); - logger.Info($"CSB接口返回信息:{result}"); - logger.Info("------------------------------http结束-----------------------------------------"); + logger.Info(" "); + logger.Info($"==========={reqName}==========="); + logger.Info($"Http请求的:[{reqName}]:[{guid}] => {paramStr}"); + result = client.PostJson(appConfig.localUrl, paramStr); + logger.Info($"Http返回的:[{reqName}]:[{guid}] => {result}"); } catch (Exception e) { @@ -131,24 +143,6 @@ namespace SlnMesnac.RfidUpload.TouchSocket private HttpClient client = new HttpClient(); - public string Post(string url, object postData) - { - var res = client.PostJson(url,postData); - return res; - //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