using MailKit.Search; using Masuit.Tools; using Newtonsoft.Json; using WIDESEA_Common; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Const; using WIDESEA_Core.Helper; using WIDESEA_IOrderRepository; using WIDESEA_IOrderServices; using WIDESEA_IServices; using WIDESEA_IStorageTaskRepository; using WIDESEA_IStorageTaskServices; using WIDESEA_Model.Models; using WIDESEA_Model.Models.Order; using WIDESEA_OrderRepository; namespace WIDESEA_OrderServices { public class Dt_InboundOrderService : ServiceBase, IDt_InboundOrderService { private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly ISys_ConfigService _configService; public Dt_InboundOrderService(IDt_InboundOrderRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, ISys_ConfigService configService) : base(BaseDal) { _unitOfWorkManage = unitOfWorkManage; _configService = configService; } public WebResponseContent GetInboundOrderInfo(string OrderNo) { WebResponseContent content=new WebResponseContent(); try { var InboundOrder = BaseDal.QueryFirst(x => x.OrderNo == OrderNo); if (InboundOrder == null) { return content.Error($"未找到该单号数据请人工确认"); } return content.OK(data: InboundOrder); } catch (Exception ex) { return content.Error(ex.Message); } } public WebResponseContent PrintOrder(int[] keys) { WebResponseContent content = new WebResponseContent(); try { List inboundOrders = new List(); foreach (var item in keys) { var InboundOrder = BaseDal.QueryFirst(x => x.Id == item); if(InboundOrder != null) { inboundOrders.Add(InboundOrder); } } content=PrintInbound(inboundOrders); return content; } catch (Exception ex) { return content.Error("未知错误,请联系管理员"); } } public WebResponseContent PrintPalletCode(int num) { WebResponseContent content = new WebResponseContent(); try { List PalletCodes = new List(); for (int i = 0; i < num; i++) { PalletCodes.Add(GetOrderPintCode("PalletCodes")); } content= PrintPallet(PalletCodes); return content.OK(); } catch (Exception ex) { return content.Error("未知错误,请联系管理员"); } } public string GetOrderPintCode(string printCode) { string PrintCode = ""; var PrintSetting = SqlSugarHelper.DbWMS.Queryable().Where(x => x.PrintCode == printCode).ToList().FirstOrDefault(); if (PrintSetting.Spare1 == DateTime.Now.ToString("yyyyMMdd")) { PrintCode = PrintSetting.Spare1 + PrintSetting.PrintNo.ToString().PadLeft(PrintSetting.Spare2, '0'); PrintSetting.PrintNo = PrintSetting.PrintNo + 1; } else { PrintSetting.Spare1 = DateTime.Now.ToString("yyyyMMdd"); PrintSetting.PrintNo = 2; PrintCode = PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0'); } SqlSugarHelper.DbWMS.Updateable(PrintSetting).ExecuteCommand(); return PrintCode; } public WebResponseContent PrintPallet(List palletCodes) { var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var Base = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintIPAddress)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintPalletCodes)?.ConfigValue; if (Base == null || ipAddress == null) { throw new InvalidOperationException("WMS IP 未配置"); } var IpAddress = Base + ipAddress; var result = HttpsClient.PostAsync(IpAddress, palletCodes.ToJsonString()).Result; return JsonConvert.DeserializeObject(result); } public WebResponseContent PrintInbound(List orders) { WebResponseContent content = new WebResponseContent(); var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var Base = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintIPAddress)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintInboundOrder)?.ConfigValue; if (Base == null || ipAddress == null) { throw new InvalidOperationException("WMS IP 未配置"); } var IpAddress = Base + ipAddress; var result = HttpsClient.PostAsync(IpAddress, orders.ToJsonString()).Result; return JsonConvert.DeserializeObject(result); } } }