| | |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.webApi; |
| | | using MES.Service.Modes; |
| | | using MES.Service.util; |
| | | using SqlSugar; |
| | | |
| | | namespace MES.Service.service.BasicData; |
| | | |
| | | public class MesRohInManager : Repository<MesRohIn> |
| | | { |
| | | //当前类已经继承了 Repository 增、删、查、改的方法 |
| | | |
| | | private readonly MesRohInDataManager rohInDataManager = new(); |
| | | |
| | | //这里面写的代码不会给覆盖,如果要重新生成请删除 MesRohInManager.cs |
| | | |
| | | // Save 方法用于保存单个 RohIn 记录,根据类型执行不同的操作 |
| | | public bool Save(RohIn rohIn) |
| | | { |
| | | var rohInErpRohIn = rohIn.ErpRohIn; |
| | | var mesRohIn = GetMesRohIn(rohInErpRohIn); |
| | | var mesRohInDatas = |
| | | GetMesRohInDatas(rohIn.ErpRohinDatas, rohInErpRohIn.Type); |
| | | switch (rohInErpRohIn.Type) |
| | | var mesRohInDatas = GetMesRohInDatas(rohIn.ErpRohinDatas, rohInErpRohIn.Type); |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | | case "1": |
| | | switch (rohInErpRohIn.Type) |
| | | { |
| | | // case "2": |
| | | // return InsertData(db, mesRohIn, mesRohInDatas, |
| | | // rohInErpRohIn.FBILLTYPE) |
| | | // ? 1 |
| | | // : 0; |
| | | case "3": |
| | | return UpdateData(db, mesRohIn, mesRohInDatas) ? 1 : 0; |
| | | case "2": |
| | | case "4": |
| | | case "5": |
| | | case "B": |
| | | return SaveOrUpdateData(db, mesRohIn, mesRohInDatas) |
| | | ? 1 |
| | | : 0; |
| | | default: |
| | | throw new NotImplementedException( |
| | | $"type没有{rohInErpRohIn.Type}这个类型"); |
| | | } |
| | | }) > 0; |
| | | } |
| | | |
| | | // 插入数据的方法 |
| | | private bool InsertData(SqlSugarScope db, MesRohIn mesRohIn, |
| | | List<MesRohInData> mesRohInDatas, string FBILLTYPE) |
| | | { |
| | | switch (FBILLTYPE) |
| | | { |
| | | case "A": |
| | | { |
| | | var decimals = mesRohInDatas.Select(s => s.Id).ToArray(); |
| | | |
| | | if (mesRohIn.Id != null) base.DeleteById(mesRohIn.Id); |
| | | |
| | | if (decimals.Length > 0) |
| | | db.Deleteable<MesRohInData>().In(decimals).ExecuteCommand(); |
| | | |
| | | var insert = base.Insert(mesRohIn); |
| | | var insertRange = rohInDataManager.InsertRange(mesRohInDatas); |
| | | var insertRange = |
| | | rohInDataManager.InsertRange(mesRohInDatas); |
| | | |
| | | if (insert && insertRange) return true; |
| | | throw new NotImplementedException("插入失败"); |
| | | case "2": |
| | | var update = base.Update(mesRohIn); |
| | | var insertOrUpdate = |
| | | rohInDataManager.InsertOrUpdate(mesRohInDatas); |
| | | } |
| | | case "B": |
| | | { |
| | | var decimals = mesRohInDatas.Select(s => s.Id).ToArray(); |
| | | if (base.DeleteById(mesRohIn.Id) && db |
| | | .Deleteable<MesRohInData>().In(decimals) |
| | | .ExecuteCommand() > 0) |
| | | { |
| | | var insert = base.Insert(mesRohIn); |
| | | var insertRange = |
| | | rohInDataManager.InsertRange(mesRohInDatas); |
| | | |
| | | if (update && insertOrUpdate) return true; |
| | | throw new NotImplementedException("更新失败"); |
| | | case "4": |
| | | var orUpdate = SaveOrUpdate(mesRohIn); |
| | | var baOrUpdate = |
| | | rohInDataManager.InsertOrUpdate(mesRohInDatas); |
| | | if (orUpdate && baOrUpdate) return true; |
| | | throw new NotImplementedException("插入失败"); |
| | | default: |
| | | throw new NotImplementedException("type没有" + |
| | | rohInErpRohIn.Type + "这个类型"); |
| | | if (insert && insertRange) return true; |
| | | throw new NotImplementedException("插入失败"); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | throw new NotImplementedException("采购订单类型错误"); |
| | | } |
| | | |
| | | private bool SaveOrUpdate(MesRohIn mesRohIn) |
| | | // 更新数据的方法 |
| | | private bool UpdateData(SqlSugarScope db, MesRohIn mesRohIn, |
| | | List<MesRohInData> mesRohInDatas) |
| | | { |
| | | var mesRohIns = base.GetList(it => it.EbelnK3id == mesRohIn.EbelnK3id); |
| | | var decimals = mesRohInDatas.Select(s => s.Id).ToArray(); |
| | | var update = base.DeleteById(mesRohIn.Id); |
| | | var insertOrUpdate = db |
| | | .Deleteable<MesRohInData>().In(decimals) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | if (CollectionUtil.IsNullOrEmpty(mesRohIns)) |
| | | { |
| | | return base.Insert(mesRohIn); |
| | | } |
| | | |
| | | return base.Update(mesRohIn); |
| | | if (update && insertOrUpdate) return true; |
| | | throw new NotImplementedException("更新失败"); |
| | | } |
| | | |
| | | // 插入或更新数据的方法 |
| | | private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn, |
| | | List<MesRohInData> mesRohInDatas) |
| | | { |
| | | if (mesRohIn.Id != null) base.DeleteById(mesRohIn.Id); |
| | | |
| | | if (mesRohInDatas.Count > 0) |
| | | db.Deleteable<MesRohInData>() |
| | | .Where(s => s.ErpId == mesRohIn.EbelnK3id).ExecuteCommand(); |
| | | |
| | | var orUpdate = base.Insert(mesRohIn); |
| | | var baOrUpdate = rohInDataManager.InsertRange(mesRohInDatas); |
| | | if (orUpdate && baOrUpdate) return true; |
| | | throw new NotImplementedException("插入或更新失败"); |
| | | } |
| | | |
| | | // 批量保存记录的方法 |
| | | public bool SaveList(List<RohIn> rohIns) |
| | | { |
| | | var result = new List<bool>(); |
| | | rohIns.ForEach(s => |
| | | { |
| | | var save = Save(s); |
| | | result.Add(save); |
| | | }); |
| | | var result = rohIns.Select(Save).ToList(); |
| | | return result.All(b => b); |
| | | } |
| | | |
| | | // 将 ErpRohIn 对象转换为 MesRohIn 对象的方法 |
| | | public MesRohIn GetMesRohIn(ErpRohIn rohIn) |
| | | { |
| | | var eid = Convert.ToDecimal(rohIn.id); |
| | | var mesRohIn = new MesRohIn(); |
| | | if (!"1".Equals(rohIn.Type)) |
| | | { |
| | | var single = base.GetSingle(it => it.EbelnK3id == eid); |
| | | if (single != null) mesRohIn.Id = single.Id; |
| | | } |
| | | |
| | | var single = base.GetSingle(it => it.EbelnK3id == eid); |
| | | if (single != null) mesRohIn.Id = single.Id; |
| | | |
| | | mesRohIn.EbelnK3id = eid; |
| | | |
| | | mesRohIn.BillNo = rohIn.FBillNo; |
| | | mesRohIn.DocumentStatus = rohIn.FDocumentStatus; |
| | | mesRohIn.DocumentType = rohIn.FBillTypeID; |
| | | mesRohIn.BusinessType = rohIn.FBusinessType; |
| | | |
| | | if (rohIn.FDate != null) |
| | | mesRohIn.PurchaseDate = DateTime.ParseExact( |
| | | rohIn.FDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | mesRohIn.PurchaseDate = DateTime.ParseExact(rohIn.FDate,"yyyy-MM-dd HH:mm:ss", null); |
| | | mesRohIn.Supplier = rohIn.FSupplierId; |
| | | mesRohIn.CloseStatus = rohIn.FCloseStatus; |
| | | mesRohIn.PurchaseOrg = rohIn.FPurchaseOrgId; |
| | | mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId; |
| | | mesRohIn.PurchaseGroup = rohIn.FPurchaserGroupId; |
| | | mesRohIn.QtyAcceptance = rohIn.Facctype; |
| | | mesRohIn.Purchaser = rohIn.FPurchaserId; |
| | | mesRohIn.QualityReq = rohIn.F_UNW_Remarks_zlyq; |
| | | // mesRohIn.SupplierContact = rohIn.F_UNW_GYSLXR; |
| | | // mesRohIn.ContactPhone = rohIn.F_UNW_LXRDH; |
| | | // mesRohIn.Position = rohIn.FProviderJob; |
| | | // mesRohIn.OfficePhone = rohIn.FProviderPhone; |
| | | // mesRohIn.SupplierAddress = rohIn.FProviderAddress; |
| | | mesRohIn.SettlementParty = rohIn.FSettleId; |
| | | mesRohIn.PaymentParty = rohIn.FChargeId; |
| | | mesRohIn.Email = rohIn.FProviderEMail; |
| | | mesRohIn.TransportMethod = rohIn.F_UNW_Text_ysfs; |
| | | mesRohIn.Remarks = rohIn.F_UNW_BZ; |
| | | mesRohIn.FixtureMoldProcurement = rohIn.F_UNW_Combo_zjmj; |
| | | mesRohIn.CancellationStatus = rohIn.FCancelStatus; |
| | | mesRohIn.CancellationPerson = rohIn.FCancellerId; |
| | | |
| | | if (rohIn.FCancelDate != null) |
| | | mesRohIn.CancellationDate = DateTime.ParseExact( |
| | | rohIn.FCancelDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | mesRohIn.CancellationDate = |
| | | DateTime.ParseExact(rohIn.FCancelDate, |
| | | "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | mesRohIn.CreateBy = rohIn.FCreatorId; |
| | | |
| | | if (rohIn.FCreateDate != null) |
| | | mesRohIn.CreateDate = DateTime.ParseExact( |
| | | rohIn.FCreateDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | mesRohIn.LastupdateBy = rohIn.FModifierId; |
| | | |
| | | if (rohIn.FModifyDate != null) |
| | | mesRohIn.LastupdateDate = DateTime.ParseExact( |
| | | rohIn.FModifyDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | mesRohIn.LastupdateDate = DateTime.ParseExact(rohIn.FModifyDate, |
| | | "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | mesRohIn.ErpCheckBy = rohIn.FApproverId; |
| | | mesRohIn.ErpCheckDate = rohIn.FApproveDate; |
| | | |
| | | mesRohIn.Changereason = rohIn.FChangeReason; |
| | | mesRohIn.CreateDate = DateTime.Now; |
| | | mesRohIn.ReceiveOrg = Convert.ToDecimal(rohIn.FReceiveOrgId); |
| | | |
| | | return mesRohIn; |
| | | } |
| | | |
| | | public List<MesRohInData> GetMesRohInDatas(List<ErpRohinData> ErpRohinDatas, |
| | | string type) |
| | | // 将 ErpRohinData 对象转换为 MesRohInData 对象的方法 |
| | | public List<MesRohInData> GetMesRohInDatas( |
| | | List<ErpRohinData> erpRohinDatas, string type) |
| | | { |
| | | var list = new List<MesRohInData>(); |
| | | ErpRohinDatas.ForEach(s => |
| | | return erpRohinDatas.Select(s => |
| | | { |
| | | var entity = new MesRohInData(); |
| | | |
| | | var eid = Convert.ToDecimal(s.id); |
| | | |
| | | if (!"1".Equals(type)) |
| | | var entity = new MesRohInData |
| | | { |
| | | var single = |
| | | rohInDataManager.GetSingle(it => it.EbelnK3id == eid); |
| | | if (single != null) entity.Id = single.Id; |
| | | } |
| | | EbelnK3id = Convert.ToDecimal(s.id), |
| | | ErpId = Convert.ToDecimal(s.Eid), |
| | | BillNo = s.FBillNo, |
| | | OrderLineId=s.FSeq, |
| | | PurchaseOrderLineNumber = s.FSeq, |
| | | SalesOrderId = s.FXSHTH, |
| | | ItemId = s.FMaterialId, |
| | | PurchaseUnit = s.FUnitId, |
| | | PurchaseQty = Convert.ToDecimal(s.FQty), |
| | | InventoryUnit = s.FStockUnitID, |
| | | PricingUnit = s.FPriceUnitId, |
| | | PricingQty = Convert.ToDecimal(s.FPriceUnitQty), |
| | | DeliveryDate = s.FDeliveryDate != null |
| | | ? DateTime.ParseExact(s.FDeliveryDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null, |
| | | EarliestDeliveryDate = s.FDeliveryEarlyDate != null |
| | | ? DateTime.ParseExact(s.FDeliveryEarlyDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null, |
| | | LatestDeliveryDate = s.FDeliveryLastDate != null |
| | | ? DateTime.ParseExact(s.FDeliveryLastDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null, |
| | | IsGift = s.FGiveAway, |
| | | Remarks = s.FNote, |
| | | SupplierItemCode = s.FSupMatId, |
| | | SupplierItemName = s.FSupMatName, |
| | | OutsourcingOrderId = s.FSubreqBillNo, |
| | | BatchNumber = s.FLot, |
| | | BusinessClose = s.FMRPCloseStatus, |
| | | BusinessFreeze = s.FMRPFreezeStatus, |
| | | Freezer = s.FFreezerId, |
| | | FreezeTime = s.FFreezeDate != null |
| | | ? DateTime.ParseExact(s.FFreezeDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null, |
| | | BusinessTerminate = s.FMRPTerminateStatus, |
| | | Terminator = s.FTerminaterId, |
| | | TerminateTime = s.FTerminateDate != null |
| | | ? DateTime.ParseExact(s.FTerminateDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null, |
| | | TotalReceivedQty = Convert.ToDecimal(s.FQty)-Convert.ToDecimal(s.FRemainReceiveQty), |
| | | RemainingReceivedQty = Convert.ToDecimal(s.FRemainReceiveQty), |
| | | TotalStoredQty = Convert.ToDecimal(s.FQty) - Convert.ToDecimal(s.FRemainStockINQty), |
| | | RemainingStoredQty = Convert.ToDecimal(s.FRemainStockINQty), |
| | | TotalReturnedQty = Convert.ToDecimal(s.FMrbQty), |
| | | ReturnableReceivedQty = Convert.ToDecimal(s.FBaseCheckRetQty), |
| | | ReturnableStoredQty = Convert.ToDecimal(s.FBaseStockRetQty), |
| | | SourceDocumentType = s.FSrcBillTypeId, |
| | | SourceDocumentId = s.FSrcBillNo, |
| | | DemandTrackingId = s.FReqTraceNo, |
| | | PlanTrackingId = s.FMtoNo, |
| | | ChangeFlag = s.FChangeFlag, |
| | | DemandSource = s.FDemandType, |
| | | DemandDocumentId = s.FDemandBillNo, |
| | | DemandDocumentLineId = s.FDemandBillEntrySeq, |
| | | Demand = s.FRequireOrgId, |
| | | DemandOrg = s.FRequireOrgId, |
| | | Receiving = s.FReceiveOrgId, |
| | | ReceivingOrg = s.FReceiveOrgId, |
| | | Settlement = s.FEntrySettleOrgId, |
| | | SettlementOrg = s.FEntrySettleOrgId, |
| | | DemandDept = s.FRequireDeptId, |
| | | ReceivingDept = s.FReceiveDeptId |
| | | }; |
| | | |
| | | entity.EbelnK3id = Convert.ToDecimal(s.id); |
| | | entity.ErpId = Convert.ToDecimal(s.Eid); |
| | | var single = rohInDataManager.GetSingle(it => |
| | | it.EbelnK3id == entity.EbelnK3id); |
| | | if (single != null) entity.Id = single.Id; |
| | | |
| | | entity.BillNo = s.FBillNo; |
| | | entity.SalesOrderId = s.F_UNW_Text_xsddh; |
| | | entity.ItemId = s.FMaterialId; |
| | | entity.PurchaseUnit = s.FUnitId; |
| | | entity.PurchaseQty = Convert.ToDecimal(s.FQty); |
| | | entity.InventoryUnit = s.FStockUnitID; |
| | | entity.PricingUnit = s.FPriceUnitId; |
| | | entity.PricingQty = Convert.ToDecimal(s.FPriceUnitQty); |
| | | |
| | | if (s.FDeliveryDate != null) |
| | | entity.DeliveryDate = DateTime.ParseExact( |
| | | s.FDeliveryDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | if (s.FDeliveryEarlyDate != null) |
| | | entity.EarliestDeliveryDate = DateTime.ParseExact( |
| | | s.FDeliveryEarlyDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | if (s.FDeliveryLastDate != null) |
| | | entity.LatestDeliveryDate = DateTime.ParseExact( |
| | | s.FDeliveryLastDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | entity.IsGift = s.FGiveAway; |
| | | entity.Remarks = s.FEntryNote; |
| | | entity.SupplierItemCode = s.FSupMatId; |
| | | entity.SupplierItemName = s.FSupMatName; |
| | | entity.OutsourcingOrderId = s.FSUBREQBILLNO; |
| | | entity.BatchNumber = s.FLot; |
| | | entity.BusinessClose = s.FMRPCloseStatus; |
| | | entity.BusinessFreeze = s.FMRPFreezeStatus; |
| | | entity.Freezer = s.FFreezerId; |
| | | |
| | | if (s.FFreezeDate != null) |
| | | entity.FreezeTime = DateTime.ParseExact( |
| | | s.FFreezeDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | entity.BusinessTerminate = s.FMRPTerminateStatus; |
| | | entity.Terminator = s.FTerminaterId; |
| | | |
| | | if (s.FTerminateDate != null) |
| | | entity.TerminateTime = DateTime.ParseExact( |
| | | s.FTerminateDate, "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | entity.TotalReceivedQty = Convert.ToDecimal(s.FReceiveQty); |
| | | entity.RemainingReceivedQty = |
| | | Convert.ToDecimal(s.FRemainReceiveQty); |
| | | entity.TotalStoredQty = Convert.ToDecimal(s.FStockInQty); |
| | | entity.RemainingStoredQty = Convert.ToDecimal(s.FRemainStockINQty); |
| | | entity.TotalReturnedQty = Convert.ToDecimal(s.FMrbQty); |
| | | entity.ReturnableReceivedQty = Convert.ToDecimal(s.FCHECKRETQTY); |
| | | entity.ReturnableStoredQty = Convert.ToDecimal(s.FSTOCKRETQTY); |
| | | entity.SourceDocumentType = s.FSrcBillTypeId; |
| | | entity.SourceDocumentId = s.FSrcBillNo; |
| | | entity.DemandTrackingId = s.FReqTraceNo; |
| | | entity.PlanTrackingId = s.FMtoNo; |
| | | entity.ChangeFlag = s.FChangeFlag; |
| | | entity.DemandSource = s.FDEMANDTYPE; |
| | | entity.DemandDocumentId = s.FDEMANDBILLNO; |
| | | entity.DemandDocumentLineId = s.FDEMANDBILLENTRYSEQ; |
| | | list.Add(entity); |
| | | }); |
| | | return list; |
| | | return entity; |
| | | }).ToList(); |
| | | } |
| | | |
| | | #region 教学方法 |
| | | |
| | | /// <summary> |
| | | /// 仓储方法满足不了复杂业务需求,业务代码请在这里面定义方法 |
| | | /// </summary> |
| | | public void Study() |
| | | { |
| | | /*********查询*********/ |
| | | |
| | | var data1 = base.GetById(1); //根据ID查询 |
| | | var data2 = base.GetList(); //查询所有 |
| | | var data3 = base.GetList(it => 1 == 1); //根据条件查询 |
| | | //var data4 = base.GetSingle(it => 1 == 1);//根据条件查询一条,如果超过一条会报错 |
| | | |
| | | var p = new PageModel { PageIndex = 1, PageSize = 2 }; // 分页查询 |
| | | var data5 = base.GetPageList(it => 1 == 1, p); |
| | | Console.Write(p.TotalCount); //返回总数 |
| | | |
| | | var data6 = |
| | | base.GetPageList(it => 1 == 1, p, |
| | | it => SqlFunc.GetRandom()); // 分页查询加排序 |
| | | Console.Write(p.TotalCount); //返回总数 |
| | | |
| | | var conModels = new List<IConditionalModel>(); //组装条件查询作为条件实现 分页查询加排序 |
| | | conModels.Add(new ConditionalModel |
| | | { |
| | | FieldName = typeof(MesRohIn).GetProperties()[0].Name, |
| | | ConditionalType = ConditionalType.Equal, FieldValue = "1" |
| | | }); //id=1 |
| | | var data7 = base.GetPageList(conModels, p, it => SqlFunc.GetRandom()); |
| | | |
| | | AsQueryable().Where(x => 1 == 1) |
| | | .ToList(); //支持了转换成queryable,我们可以用queryable实现复杂功能 |
| | | |
| | | |
| | | /*********插入*********/ |
| | | var insertData = new MesRohIn(); //测试参数 |
| | | var insertArray = new[] { insertData }; |
| | | base.Insert(insertData); //插入 |
| | | base.InsertRange(insertArray); //批量插入 |
| | | var id = base.InsertReturnIdentity(insertData); //插入返回自增列 |
| | | AsInsertable(insertData).ExecuteCommand(); //我们可以转成 Insertable实现复杂插入 |
| | | |
| | | |
| | | /*********更新*********/ |
| | | var updateData = new MesRohIn(); //测试参数 |
| | | var updateArray = new[] { updateData }; //测试参数 |
| | | base.Update(updateData); //根据实体更新 |
| | | base.UpdateRange(updateArray); //批量更新 |
| | | //base.Update(it => new MesRohIn() { ClassName = "a", CreateTime = DateTime.Now }, it => it.id==1);// 只更新ClassName列和CreateTime列,其它列不更新,条件id=1 |
| | | AsUpdateable(updateData).ExecuteCommand(); //转成Updateable可以实现复杂的插入 |
| | | |
| | | |
| | | /*********删除*********/ |
| | | var deldata = new MesRohIn(); //测试参数 |
| | | base.Delete(deldata); //根据实体删除 |
| | | base.DeleteById(1); //根据主键删除 |
| | | base.DeleteById(new[] { 1, 2 }); //根据主键数组删除 |
| | | base.Delete(it => 1 == 2); //根据条件删除 |
| | | AsDeleteable().Where(it => 1 == 2) |
| | | .ExecuteCommand(); //转成Deleteable实现复杂的操作 |
| | | } |
| | | |
| | | #endregion |
| | | } |