using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using ZR.Model; using ZR.Model.Dto; using ZR.Repository; using System.Linq; using ZR.Service.mes.wms.IService; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Collections.Generic; namespace ZR.Service.mes.wms { /// /// 出库货物记录表Service业务层处理 /// [AppService(ServiceType = typeof(IWmGoodsOutProductionService), ServiceLifetime = LifeTime.Transient)] public class WmGoodsOutProductionService : BaseService, IWmGoodsOutProductionService { /// /// 查询出库货物记录表列表 /// /// /// public (List,int) GetList(WmGoodsOutProductionQueryDto parm) { int total = 0; var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.Partnumber), wgo => wgo.Partnumber.Contains(parm.Partnumber)) .AndIF(!string.IsNullOrEmpty(parm.PackageCodeClient), wgo => wgo.PackageCodeClient.Contains(parm.PackageCodeClient)) .AndIF(!string.IsNullOrEmpty(parm.LocationCode), wgo => wgo.LocationCode.Contains(parm.LocationCode)) .AndIF(!string.IsNullOrEmpty(parm.FkOutOrderId), wgo => wgo.FkOutOrderId.Contains(parm.FkOutOrderId)) ; var response = Queryable() .LeftJoin((wgo, wml) => wgo.Partnumber == wml.Partnumber) .Where(predicate.ToExpression()) .Select((wgo, wml) => new WmGoodsOutProductionDto { Description = wml.Description }, true) .MergeTable() .OrderBy(wml => wml.OutTime,OrderByType.Desc) .ToPageList(parm.PageNum, parm.PageSize,ref total); return (response,total); } /// /// 获取详情 /// /// /// public WmGoodsOutRecord GetInfo(string Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加出库货物记录表 /// /// /// public WmGoodsOutRecord AddWmGoodsOutProduction(WmGoodsOutRecord model) { if(string.IsNullOrEmpty(model.PackageCode)) { model.PackageCode = "L" + DateTime.Now.ToString("yyMMddHHmmss"); } if (string.IsNullOrEmpty(model.Id)) { model.Id= SnowFlakeSingle.Instance.NextId().ToString();//也可以在程序中直接获取ID } //2. 根据成品仓库id修改记录 WmGoodsNowProduction updateModel = new WmGoodsNowProduction(); updateModel.Id = model.FkNowProductionId; updateModel.GoodsNumAction = model.GoodsNumLogic - model.GoodsNumAction; if (updateModel.GoodsNumAction <= 0) { updateModel.GoodsNumAction = 0; } if (updateModel.GoodsNumAction == 0) { Context.Deleteable().Where(it => it.Id == updateModel.Id).ExecuteCommand(); } else { Context.Updateable(updateModel).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改出库货物记录表 /// /// /// public int UpdateWmGoodsOutProduction(WmGoodsOutRecord model) { //var response = Update(w => w.Id == model.Id, it => new WmGoodsOutProduction() //{ // PackageCode = model.PackageCode, // PackageCodeClient = model.PackageCodeClient, // PackageCodeOriginal = model.PackageCodeOriginal, // LocationCode = model.LocationCode, // Partnumber = model.Partnumber, // GoodsNumLogic = model.GoodsNumLogic, // GoodsNumAction = model.GoodsNumAction, // EntryWarehouseTime = model.EntryWarehouseTime, // OutTime = model.OutTime, // Remark = model.Remark, // UpdatedBy = model.UpdatedBy, // UpdatedTime = model.UpdatedTime, // CreatedBy = model.CreatedBy, // CreatedTime = model.CreatedTime, //}); //return response; return Update(model, true); } public string DoPatchOutProduction(WmBatchGoodsOutProductionDto parm) { int type = parm.Type; var time = DateTime.Now.ToLocalTime(); if (type == 1) { var list = parm.Ids; for (int i = 0; i < list.Count; i++) { WmGoodsNowProduction nowProduction = Context.Queryable() .Where(it => it.Id == list[i]).First(); if(nowProduction == null) { continue; } WmGoodsOutRecord outRecord = new() { Id = SnowFlakeSingle.Instance.NextId().ToString(), FkNowProductionId = nowProduction.Id, FkOutOrderId = parm.FkOutOrderId, PackageCode = nowProduction.PackageCode, PackageCodeClient = nowProduction.PackageCodeClient, PackageCodeOriginal = nowProduction.PackageCodeOriginal, LocationCode = nowProduction.LocationCode, Partnumber = nowProduction.Partnumber, GoodsNumAction = nowProduction.GoodsNumAction, GoodsNumLogic = nowProduction.GoodsNumAction, EntryWarehouseTime = nowProduction.EntryWarehouseTime, OutTime = time, Remark = "批量出库", CreatedBy = "batch", CreatedTime = time, }; Context.Insertable(outRecord).ExecuteCommand(); Context.Deleteable().Where(it => it.Id == nowProduction.Id).ExecuteCommand(); } } else if(type == 2) { if (parm.PackageCodeClient == "" || parm.PackageCodeClient == null) { return "无批次号参数"; } // 短批次号 string shortPackageCode = parm.PackageCodeClient.Split('_')[0]; if (shortPackageCode.Length<8) { return "请输入至少8位批次号编码,以保证正确批次出库!"; } List nowProductionList = Context.Queryable() .Where(it => it.PackageCodeClient.Contains(shortPackageCode)).ToList(); for (int i = 0; i < nowProductionList.Count; i++) { WmGoodsNowProduction nowProduction = Context.Queryable() .Where(it => it.Id == nowProductionList[i].Id).First(); if (nowProduction == null) { continue; } WmGoodsOutRecord outRecord = new() { Id = SnowFlakeSingle.Instance.NextId().ToString(), FkNowProductionId = nowProduction.Id, FkOutOrderId = parm.FkOutOrderId, PackageCode = nowProduction.PackageCode, PackageCodeClient = nowProduction.PackageCodeClient, PackageCodeOriginal = nowProduction.PackageCodeOriginal, LocationCode = nowProduction.LocationCode, Partnumber = nowProduction.Partnumber, GoodsNumAction = nowProduction.GoodsNumAction, GoodsNumLogic = nowProduction.GoodsNumAction, EntryWarehouseTime = nowProduction.EntryWarehouseTime, OutTime = time, Remark = "批量出库", CreatedBy = "batch", CreatedTime = time, }; Context.Insertable(outRecord).ExecuteCommand(); Context.Deleteable().Where(it => it.Id == nowProduction.Id).ExecuteCommand(); } } return "ok"; } } }