| | |
| | | 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": |
| | |
| | | |
| | | 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(); |
| | |
| | | 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> |
| | |
| | | // 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("æä½å¤±è´¥"); |
| | | } |
| | | } |