using Masuit.Tools; using SharpCompress.Compressors.ADC; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using WIDESEA_Common; using WIDESEA_Core.Const; using WIDESEA_IOrderRepository; using WIDESEA_IServices; using WIDESEA_IStorageBasicServices.Stock; using WIDESEA_Model.Models.ERP; using WIDESEA_Model.Models.Order; using WIDESEA_OrderRepository; namespace WIDESEA_StorageBasicServices { public partial class ERPInboundOrderService : IERPInboundOrderService { private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly ISys_ConfigService _configService; private readonly IDt_InboundOrderRepository _inboundOrderRepository; public ERPInboundOrderService(IUnitOfWorkManage unitOfWorkManage, ISys_ConfigService configService,IDt_InboundOrderRepository inboundOrderRepository) { _unitOfWorkManage = unitOfWorkManage; _configService = configService; _inboundOrderRepository = inboundOrderRepository; } public virtual PageGridData GetPageData(PageDataOptions options) { string wheres = options.ValidatePageOptions(typeof(WMS_采购及成品入库清单_ST).GetProperties()); //获取排序字段 int totalCount = 0; var data = SqlSugarHelper.DBERP.Queryable() .WhereIF(!wheres.IsNullOrEmpty(), wheres) .ToPageList(options.Page, options.Rows, ref totalCount); new PageGridData(totalCount, data); return new PageGridData(totalCount, data); } public WebResponseContent Print(List wMSs) { WebResponseContent content = new WebResponseContent(); try { List orderinbound=new List(); foreach (var wMS in wMSs) { Dt_InboundOrder Print = new Dt_InboundOrder() { OrderNo = GetOrderPintCode("OrderNoIn"), UpperOrderNo = wMS.单号, DemandClassification = wMS.需求分类, OrderType = wMS.单据类型, WarehouseName = wMS.入库仓库名称, Datetime = wMS.日期.ToString(), LineNumber = wMS.行号, ProductDrawingNumber = wMS.产品图号, MaterialNo = wMS.料号, MaterialName = wMS.品名, Weight = wMS.单重, WareHouseId = wMS.入库仓库编码, Specs = wMS.规格, Unit = wMS.单位, Texture = wMS.用友材质, Quantity = wMS.入库数量, OrderStatus = wMS.单据状态 }; orderinbound.Add(Print); } _inboundOrderRepository.AddData(orderinbound); PrintInbound(orderinbound); return content.OK("打印成功"); } catch (Exception ex) { return content.Error(ex.Message); } } public void PrintInbound(List orders) { 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; } 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; } } }