From 35bbd277a1963dfbbecf10b8682d6ac210b3a2ec Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期二, 21 一月 2025 17:03:22 +0800 Subject: [PATCH] 供应商 --- StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs | 226 +++++++++++++------------------ StandardPda/MES.Service/Dto/webApi/ErpDetail.cs | 6 StandardPda/MES.Service/service/BasicData/SalesReturnNoticeManager.cs | 67 --------- StandardPda/MES.Service/service/BasicData/MesRohInManager.cs | 46 ------ StandardPda/MES.Service/Dto/webApi/ErpCustomer.cs | 9 - StandardPda/MES.Service/service/BasicData/MesCustomerManager.cs | 7 StandardPda/MES.Service/Dto/webApi/ErpSupplier.cs | 2 7 files changed, 105 insertions(+), 258 deletions(-) diff --git a/StandardPda/MES.Service/Dto/webApi/ErpCustomer.cs b/StandardPda/MES.Service/Dto/webApi/ErpCustomer.cs index cb8cf44..eb4466a 100644 --- a/StandardPda/MES.Service/Dto/webApi/ErpCustomer.cs +++ b/StandardPda/MES.Service/Dto/webApi/ErpCustomer.cs @@ -13,12 +13,5 @@ public string? State { get; set; } public string? FForbidStatus { get; set; } - public List<ErpDetail>? ErpDetails { get; set; } - -} - -public class ErpDetail -{ - public string? FUseOrgId { get; set; } - + public List<ErpDetail>? ErpDetails { get; set; } } \ No newline at end of file diff --git a/StandardPda/MES.Service/Dto/webApi/ErpDetail.cs b/StandardPda/MES.Service/Dto/webApi/ErpDetail.cs new file mode 100644 index 0000000..fef8da4 --- /dev/null +++ b/StandardPda/MES.Service/Dto/webApi/ErpDetail.cs @@ -0,0 +1,6 @@ +锘縩amespace MES.Service.Dto.webApi; + +public class ErpDetail +{ + public string? FUseOrgId { get; set; } +} \ No newline at end of file diff --git a/StandardPda/MES.Service/Dto/webApi/ErpSupplier.cs b/StandardPda/MES.Service/Dto/webApi/ErpSupplier.cs index e0f3248..41f69f3 100644 --- a/StandardPda/MES.Service/Dto/webApi/ErpSupplier.cs +++ b/StandardPda/MES.Service/Dto/webApi/ErpSupplier.cs @@ -26,7 +26,7 @@ // public string? FCreateOrgId { get; set; } //鐢ㄥ弸鐗规畩鐐� - public string[]? FUseOrgId { get; set; } + public List<ErpDetail>? FUseOrgId { get; set; } //public string? FDescription { get; set; } // public string? fremarks { get; set; } public string? PrivateDescSeg { get; set; } diff --git a/StandardPda/MES.Service/service/BasicData/MesCustomerManager.cs b/StandardPda/MES.Service/service/BasicData/MesCustomerManager.cs index 61f49d5..4e78597 100644 --- a/StandardPda/MES.Service/service/BasicData/MesCustomerManager.cs +++ b/StandardPda/MES.Service/service/BasicData/MesCustomerManager.cs @@ -134,8 +134,6 @@ //var id = db.Insertable(insertObj).ExecuteReturnIdentity(); //鏍规嵁搴忓垪鑾峰彇鏂扮殑MES_ID - - List<MesCustomer> customers = new List<MesCustomer>(); foreach (ErpDetail erpDetail in customer.ErpDetails) @@ -181,10 +179,7 @@ customers.Add(mesCustomer); } - - - - + //customers = customer.ErpDetails.Select(ErpDetails => new MesCustomer //{ // Id = GetSeqUtil.GetSeq("U9_MES_ID"), diff --git a/StandardPda/MES.Service/service/BasicData/MesRohInManager.cs b/StandardPda/MES.Service/service/BasicData/MesRohInManager.cs index 873583a..dfe434e 100644 --- a/StandardPda/MES.Service/service/BasicData/MesRohInManager.cs +++ b/StandardPda/MES.Service/service/BasicData/MesRohInManager.cs @@ -31,51 +31,7 @@ }; }) > 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); - - if (insert && insertRange) return true; - throw new NotImplementedException("鎻掑叆澶辫触"); - } - 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 (insert && insertRange) return true; - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - break; - } - } - - throw new NotImplementedException("閲囪喘璁㈠崟绫诲瀷閿欒"); - } - + // 鏇存柊鏁版嵁鐨勬柟娉� private bool UpdateData(SqlSugarScope db, MesRohIn mesRohIn, List<MesRohInData> mesRohInDatas) diff --git a/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs b/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs index 7036520..655f745 100644 --- a/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs +++ b/StandardPda/MES.Service/service/BasicData/MesSupplierManager.cs @@ -16,15 +16,15 @@ switch (unit.Type) { case "0": - if (UpdateSupplierStatus(db, entity.Id, "A")) + if (UpdateSupplierStatus(db, entity, "A")) return 1; break; case "1": - if (UpdateSupplierStatus(db, entity.Id, "B")) + if (UpdateSupplierStatus(db, entity, "B")) return 1; break; case "3": - if (DeleteSupplier(entity.Id)) + if (DeleteSupplier(entity)) return 1; break; case "2": @@ -43,111 +43,16 @@ public bool SaveList(List<ErpSupplier> suppliers) { - var list = suppliers.Select(GetMesSupplier).ToList(); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); - - return UseTransaction(db => - { - foreach (var supplierGroup in groupBy) - switch (supplierGroup.Key) - { - case "0": - if (!UpdateSupplierStatusBatch(db, supplierGroup.Value, - "A")) - throw new NotImplementedException("鍚敤澶辫触"); - break; - case "1": - if (!UpdateSupplierStatusBatch(db, supplierGroup.Value, - "B")) - throw new NotImplementedException("绂佺敤澶辫触"); - break; - - case "3": - if (!DeleteSupplierBatch(db, supplierGroup.Value)) - throw new NotImplementedException("鍒犻櫎澶辫触"); - break; - case "2": - case "4": - if (!InsertOrUpdateBatch(db, supplierGroup.Value)) - throw new NotImplementedException("鍚屾澶辫触"); - break; - default: - throw new ArgumentNullException( - $"type娌℃湁{supplierGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); - } - - return 1; - }) > 0; + var result = suppliers.Select(Save).ToList(); + return result.All(b => b); } - private bool UpdateSupplierStatus(SqlSugarScope db, decimal supplierId, + private bool UpdateSupplierStatus(SqlSugarScope db, + List<MesSupplier> supplierId, string status) { - var result = db.Updateable<MesSupplier>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == supplierId).ExecuteCommand(); + var ids = supplierId.Select(it => it.Id).ToArray(); - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); - } - - private bool InsertSupplier(SqlSugarScope db, MesSupplier entity) - { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - private bool DeleteSupplier(decimal supplierId) - { - if (base.DeleteById(supplierId)) return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - private MesSupplier GetMesSupplier(ErpSupplier supplier) - { - return new MesSupplier - { - Id = Convert.ToDecimal(supplier.Id), - SuppNo = supplier.FNumber, - SuppSname = supplier.FShortName, - SuppName = supplier.FName, - Lxr = supplier.FContact, - Telf1 = supplier.FTel, - Fstaffid = supplier.FStaffId, - /// <summary> - /// 鎺ュ彛瀛楁璋冩暣锛氭爣鍑嗙増鎺ュ彛鏂板 ERP鍗曟嵁鐘舵�� 瀛楁銆� - /// </summary> - /// <remarks> - /// 淇敼浜猴細<姹犲崡楠�> - /// 淇敼鏃ユ湡锛�<2024-12-28> - /// 淇敼璇存槑锛� - /// - 鍘熶唬鐮侊細绌� - /// - 淇敼鍚庯細 - ///FDOCUMENTSTATUS = supplier.FDocumentStatus, - /// </remarks> - DocumentStatus = supplier.FDocumentStatus, - Fforbidstatus = supplier.FForbidStatus, - CreateDate = DateTime.Now, - //CreateOrg= Convert.ToDecimal(supplier.FCreateOrgId), - //UseOrg = supplier.FUseOrgId, - //Remark=supplier.fremarks, - PrivateDescSeg = supplier.PrivateDescSeg, - Company = "1000", - Factory = "1000" - }; - } - - private bool UpdateSupplierStatusBatch(SqlSugarScope db, - List<MesSupplier> supplierList, string status) - { - var ids = supplierList.Select(it => it.Id).ToArray(); var result = db.Updateable<MesSupplier>() .SetColumns(s => s.Fforbidstatus == status) .Where(s => ids.Contains(s.Id)).ExecuteCommand(); @@ -158,25 +63,86 @@ throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); } - private bool InsertSupplierBatch(SqlSugarScope db, - List<MesSupplier> supplierList) + private bool DeleteSupplier(List<MesSupplier> supplierId) { - var insertRange = db.Insertable(supplierList).ExecuteCommand(); - if (insertRange > 0) - return true; + var ids = supplierId.Select(it => it.Id).ToArray(); - throw new NotImplementedException("鎻掑叆澶辫触"); - } + var executeCommand = Db.Deleteable<MesSupplier>() + .Where(s => ids.Contains(s.Id)).ExecuteCommand(); - private bool DeleteSupplierBatch(SqlSugarScope db, - List<MesSupplier> supplierList) - { - var ids = supplierList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<MesSupplier>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; + if (executeCommand > 0) return true; throw new NotImplementedException("鍒犻櫎澶辫触"); + } + + private List<MesSupplier> GetMesSupplier(ErpSupplier supplier) + { + List<MesSupplier> list = new List<MesSupplier>(); + foreach (var se in supplier.FUseOrgId) + { + var exists = Db.Queryable<MesLinkU9>().Any(u => + u.U9Id == supplier.Id && u.OrgId == se.FUseOrgId && + u.TableType == "MES_SUPPLIER"); + + decimal mesId = 0; + if (exists) + { + //鑾峰彇mesid + mesId = Convert.ToDecimal(Db.Queryable<MesLinkU9>() + .Where(u => + u.U9Id == supplier.Id && u.OrgId == se.FUseOrgId && + u.TableType == "MES_SUPPLIER") + .Select(u => u.MesId) // 閫夋嫨 MesId 瀛楁 + .First()); + } + else + { + var entity = new MesLinkU9 + { + CreateDate = DateTime.Now, + MesId = mesId.ToString(), + U9Id = supplier.Id, + OrgId = se.FUseOrgId, + TableType = "MES_SUPPLIER" + }; + mesId = Db.Insertable(entity).ExecuteReturnIdentity(); + } + + var mesSupplier = new MesSupplier + { + Id = mesId, + SuppNo = supplier.FNumber, + SuppSname = supplier.FShortName, + SuppName = supplier.FName, + Lxr = supplier.FContact, + Telf1 = supplier.FTel, + Fstaffid = supplier.FStaffId, + /// <summary> + /// 鎺ュ彛瀛楁璋冩暣锛氭爣鍑嗙増鎺ュ彛鏂板 ERP鍗曟嵁鐘舵�� 瀛楁銆� + /// </summary> + /// <remarks> + /// 淇敼浜猴細<姹犲崡楠�> + /// 淇敼鏃ユ湡锛�<2024-12-28> + /// 淇敼璇存槑锛� + /// - 鍘熶唬鐮侊細绌� + /// - 淇敼鍚庯細 + ///FDOCUMENTSTATUS = supplier.FDocumentStatus, + /// </remarks> + DocumentStatus = supplier.FDocumentStatus, + Fforbidstatus = supplier.FForbidStatus, + CreateDate = DateTime.Now, + //CreateOrg= Convert.ToDecimal(supplier.FCreateOrgId), + UseOrg = se.FUseOrgId, + //Remark=supplier.fremarks, + PrivateDescSeg = supplier.PrivateDescSeg, + Company = "1000", + Factory = "1000" + }; + + list.Add(mesSupplier); + } + + return list; } /// <summary> @@ -208,24 +174,20 @@ // return false; //} ///鏂颁唬鐮� - private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity) + private bool InsertOrUpdate(SqlSugarScope db, List<MesSupplier> entity) { - db.Deleteable<MesSupplier>() - .Where(s => s.Id == entity.Id) + var ids = entity.Select(it => it.Id).ToArray(); + + var executeCommand = db.Deleteable<MesSupplier>() + .Where(s => ids.Contains(s.Id)) .ExecuteCommand(); - var insert = db.Insertable(entity).ExecuteCommand(); - return insert > 0; - } + if (executeCommand > 0) + { + var insert = db.Insertable(entity).ExecuteCommand(); + return insert > 0; + } - - private bool InsertOrUpdateBatch(SqlSugarScope db, - List<MesSupplier> supplierList) - { - foreach (var entity in supplierList) - if (!InsertOrUpdate(db, entity)) - return false; - - return true; + throw new Exception("鎿嶄綔澶辫触"); } } \ No newline at end of file diff --git a/StandardPda/MES.Service/service/BasicData/SalesReturnNoticeManager.cs b/StandardPda/MES.Service/service/BasicData/SalesReturnNoticeManager.cs index 206f0ea..3b0027b 100644 --- a/StandardPda/MES.Service/service/BasicData/SalesReturnNoticeManager.cs +++ b/StandardPda/MES.Service/service/BasicData/SalesReturnNoticeManager.cs @@ -9,70 +9,5 @@ //褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉� //杩欓噷闈㈠啓鐨勪唬鐮佷笉浼氱粰瑕嗙洊,濡傛灉瑕侀噸鏂扮敓鎴愯鍒犻櫎 SalesReturnNoticeManager.cs - - - #region 鏁欏鏂规硶 - - /// <summary> - /// 浠撳偍鏂规硶婊¤冻涓嶄簡澶嶆潅涓氬姟闇�姹傦紝涓氬姟浠g爜璇峰湪杩欓噷闈㈠畾涔夋柟娉� - /// </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(SalesReturnNotice).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,鎴戜滑鍙互鐢╭ueryable瀹炵幇澶嶆潅鍔熻兘 - - - /*********鎻掑叆*********/ - var insertData = new SalesReturnNotice(); //娴嬭瘯鍙傛暟 - var insertArray = new[] { insertData }; - base.Insert(insertData); //鎻掑叆 - base.InsertRange(insertArray); //鎵归噺鎻掑叆 - var id = base.InsertReturnIdentity(insertData); //鎻掑叆杩斿洖鑷鍒� - AsInsertable(insertData).ExecuteCommand(); //鎴戜滑鍙互杞垚 Insertable瀹炵幇澶嶆潅鎻掑叆 - - - /*********鏇存柊*********/ - var updateData = new SalesReturnNotice(); //娴嬭瘯鍙傛暟 - var updateArray = new[] { updateData }; //娴嬭瘯鍙傛暟 - base.Update(updateData); //鏍规嵁瀹炰綋鏇存柊 - base.UpdateRange(updateArray); //鎵归噺鏇存柊 - //base.Update(it => new SalesReturnNotice() { ClassName = "a", CreateTime = DateTime.Now }, it => it.id==1);// 鍙洿鏂癈lassName鍒楀拰CreateTime鍒楋紝鍏跺畠鍒椾笉鏇存柊锛屾潯浠秈d=1 - AsUpdateable(updateData).ExecuteCommand(); //杞垚Updateable鍙互瀹炵幇澶嶆潅鐨勬彃鍏� - - - /*********鍒犻櫎*********/ - var deldata = new SalesReturnNotice(); //娴嬭瘯鍙傛暟 - base.Delete(deldata); //鏍规嵁瀹炰綋鍒犻櫎 - base.DeleteById(1); //鏍规嵁涓婚敭鍒犻櫎 - base.DeleteById(new[] { 1, 2 }); //鏍规嵁涓婚敭鏁扮粍鍒犻櫎 - base.Delete(it => 1 == 2); //鏍规嵁鏉′欢鍒犻櫎 - AsDeleteable().Where(it => 1 == 2) - .ExecuteCommand(); //杞垚Deleteable瀹炵幇澶嶆潅鐨勬搷浣� - } - - #endregion + } \ No newline at end of file -- Gitblit v1.9.3