using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.HkOpenApi; using DS.WMS.Core.OpenApiModule.Dtos; using DS.WMS.Core.OpenApiModule.Entity; using DS.WMS.Core.OpenApiModule.Interface; using Mapster; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using NLog; using SqlSugar; namespace DS.WMS.Core.OpenApiModule.Method; public class PortOpenService : IPortOpenService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly IHttpRequestService _ihkHttpService; /// /// /// /// public PortOpenService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); _ihkHttpService = _serviceProvider.GetRequiredService(); } public async Task> GetTruckInfoAsync(string truckNo) { // List truckList = new List(); // List stockinTruckList = await db.Ado.SqlQueryAsync( // @"select DISTINCT b.TRUCKNO , a.WMSPLANID,a.MBLNO, 1 AS Type,a.PLANTIME as PlanTime from OP_WMS_IN_PLAN a left join OP_WMS_IN_PLAN_GOODS b on a.WMSPLANID = b.WMSPLANID where b.TRUCKNO is not null and b.TRUCKNO<>'' and a.AuditStatus =1 and a.ISEND = 0 "); // // List stockoutTruckList = await db.Ado.SqlQueryAsync( // @"select DISTINCT b.TRUCKNO , a.WMSPLANID,a.MBLNO, 2 AS Type,a.PLANTIME as PlanTime from OP_WMS_OUT_PLAN a left join OP_WMS_OUT_PLAN_DETAIL b on a.WMSPLANID = b.WMSPLANID where b.TRUCKNO is not null and b.TRUCKNO<>'' and a.AuditStatus =1 and a.ISEND = 0 "); // // List clearanceTruckList = await db.Ado.SqlQueryAsync( // @"select DISTINCT b.TRUCKNO , a.WMSPLANID,a.MBLNO, 3 AS Type,a.PLANTIME as PlanTime from OP_WMS_CLEARANCE a left join OP_WMS_CLEARANCE_DETAIL b on a.WMSPLANID = b.WMSPLANID where b.TRUCKNO is not null and b.TRUCKNO<>'' and a.AuditStatus =1 and a.ISEND = 0 "); // // truckList.AddRange(stockinTruckList); // truckList.AddRange(stockoutTruckList); // truckList.AddRange(clearanceTruckList); // var truckInfo = truckList.Where(x => x.TRUCKNO == truckNo.Trim()).OrderBy(x => x.PlanTime).ToList(); var truckList = db.Queryable().Where(x => x.TRUCKNO == truckNo.Trim()).OrderBy(x => x.PlanTime) .Select() .Mapper(it => { it.IsInternalCar = false; }) .ToList(); if (truckList.Count == 0) { return DataResult.Failed("车辆信息不存在!"); } return DataResult.Success("获取数据成功", truckList.First()); } /// /// 记录车辆相关信息 /// /// /// public async Task RecordTruckInfoAsync(TruckRecordInput model) { Logger.Log(LogLevel.Info, DateTime.Now.ToString() + "地磅回推数据" + JsonConvert.SerializeObject(model)); var truckList = db.Queryable() .Where(x => x.TRUCKNO == model.TRUCKNO.Trim() && x.WMSPLANID == model.WMSPLANID).OrderBy(x => x.PlanTime) .ToList(); if (truckList.Count == 0) { return DataResult.Failed("车辆信息不存在!"); } var info = model.Adapt(); var boxNo = string.Empty; var now = DateTime.Now.AddMinutes(-5).ToString("yyyy-MM-dd HH:mm:ss"); var end = DateTime.Now.AddMinutes(5).ToString("yyyy-MM-dd HH:mm:ss"); var parm = new { boxNo = "", plateNo = info.TRUCKNO, pageNo = 1, pageSize = 20, startTime = now, endTime = end, }; var req = new HKPostData() { Url = "/artemis/api/v1/record/query/gate", Data = JsonConvert.SerializeObject(parm), }; var res = _ihkHttpService.HKHttpPost(req); if (res.Code == "0") { Logger.Log(LogLevel.Info, DateTime.Now.ToString() + JsonConvert.SerializeObject(res.Data)); var record = JsonConvert.DeserializeObject(res.Data.ToString()); foreach (var item in record.List) { boxNo += item.ContainerNumOne + ";" + item.ContainerNumTwo; } //info.BoxNo = record.List[0].ContainerNumOne + ";" + record.List[0].ContainerNumTwo; } else { Logger.Log(LogLevel.Error, DateTime.Now.ToString() + JsonConvert.SerializeObject(res)); } info.BoxNo = boxNo; await db.Insertable(info).ExecuteCommandAsync(); return DataResult.Successed("车辆信息纪录成功!"); } }