完善日志

master
nodyang@aliyun.com 1 month ago
parent 5cda604edb
commit 19b4a751f0

@ -37,6 +37,7 @@ namespace SlnMesnac.RfidUpload.Business
{
public class CsbHandleBusiness
{
private static readonly Lazy<CsbHandleBusiness> _lazy = new Lazy<CsbHandleBusiness>(() => 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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(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<CsbResult>(str);
logHelper.Info($"容器直连配发-反馈接收结果接口返回信息:{jsonChange.ModeToJson(res)}");
return res;
}
catch (Exception ex)

@ -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}");
}

@ -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 = "";
}
}

@ -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();
}
}

@ -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
//{
// /// <summary>
// /// SQLite同步方法帮助类
// /// 作者:追逐时光者
// /// 创建时间2023年11月30日
// /// </summary>
// /// <typeparam name="T"></typeparam>
// public class SqLiteHelper<T> where T : new()
// {
// private readonly string _databasePath = Path.Combine(Environment.CurrentDirectory, "db.db");
// private readonly SQLiteConnection _connection; // SQLite连接对象
namespace SlnMesnac.RfidUpload.Common
{
/// <summary>
/// SQLite同步方法帮助类
/// 作者:追逐时光者
/// 创建时间2023年11月30日
/// </summary>
/// <typeparam name="T"></typeparam>
public class SqLiteHelper<T> where T : new()
{
private readonly string _databasePath = Path.Combine(Environment.CurrentDirectory, "db.db");
private readonly SQLiteConnection _connection; // SQLite连接对象
// /// <summary>
// /// 构造函数
// /// </summary>
// public SqLiteHelper()
// {
// // 创建SQLite连接对象并打开连接
// _connection = new SQLiteConnection(_databasePath);
// _connection.CreateTable<T>(); // 如果表不存在,则创建该表[不会创建重复的表]
// }
/// <summary>
/// 构造函数
/// </summary>
public SqLiteHelper()
{
// 创建SQLite连接对象并打开连接
_connection = new SQLiteConnection(_databasePath);
_connection.CreateTable<T>(); // 如果表不存在,则创建该表[不会创建重复的表]
}
// /// <summary>
// /// 数据插入
// /// </summary>
// /// <param name="item">要插入的数据项</param>
// /// <returns></returns>
// public int Insert(T item)
// {
// return _connection.Insert(item);
// }
/// <summary>
/// 数据插入
/// </summary>
/// <param name="item">要插入的数据项</param>
/// <returns></returns>
public int Insert(T item)
{
return _connection.Insert(item);
}
// /// <summary>
// /// 数据删除
// /// </summary>
// /// <param name="id">要删除的数据的主键ID</param>
// /// <returns></returns>
// public int Delete(int id)
// {
// return _connection.Delete<T>(id);
// }
/// <summary>
/// 数据删除
/// </summary>
/// <param name="id">要删除的数据的主键ID</param>
/// <returns></returns>
public int Delete(int id)
{
return _connection.Delete<T>(id);
}
// /// <summary>
// /// 数据更新
// /// </summary>
// /// <param name="item">要更新的数据项</param>
// /// <returns></returns>
// public int Update(T item)
// {
// return _connection.Update(item);
// }
/// <summary>
/// 数据更新
/// </summary>
/// <param name="item">要更新的数据项</param>
/// <returns></returns>
public int Update(T item)
{
return _connection.Update(item);
}
// /// <summary>
// /// 根据条件查询记录
// /// </summary>
// /// <param name="predExpr">查询条件</param>
// /// <returns></returns>
// public List<T> Query(Expression<Func<T, bool>> predExpr)
// {
// return _connection.Table<T>().Where(predExpr).ToList();
// }
/// <summary>
/// 根据条件查询记录
/// </summary>
/// <param name="predExpr">查询条件</param>
/// <returns></returns>
public List<T> Query(Expression<Func<T, bool>> predExpr)
{
return _connection.Table<T>().Where(predExpr).ToList();
}
// /// <summary>
// /// 查询所有数据
// /// </summary>
// /// <returns></returns>
// public List<T> QueryAll()
// {
// return _connection.Table<T>().ToList();
// }
/// <summary>
/// 查询所有数据
/// </summary>
/// <returns></returns>
public List<T> QueryAll()
{
return _connection.Table<T>().ToList();
}
// /// <summary>
// /// 根据条件查询单条记录
// /// </summary>
// /// <param name="predExpr">查询条件</param>
// /// <returns></returns>
// public T QuerySingle(Expression<Func<T, bool>> predExpr)
// {
// return _connection.Table<T>().Where(predExpr).FirstOrDefault();
// }
// }
//}
/// <summary>
/// 根据条件查询单条记录
/// </summary>
/// <param name="predExpr">查询条件</param>
/// <returns></returns>
public T QuerySingle(Expression<Func<T, bool>> predExpr)
{
return _connection.Table<T>().Where(predExpr).FirstOrDefault();
}
}
}

@ -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)
/// <summary>
/// ok
/// </summary>
/// <param name="paramStr"></param>
/// <param name="reqName"></param>
/// <returns></returns>
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();
}
}
}
Loading…
Cancel
Save