From 6761b0ed84fd7a03400b557244d0835f671dad94 Mon Sep 17 00:00:00 2001 From: sjz <1240968267@qq.com> Date: 星期一, 14 七月 2025 18:02:59 +0800 Subject: [PATCH] 修改多组织 --- MES.Service/service/BasicData/MesUnitManager.cs | 120 +-- MES.Service/service/BasicData/MesStaffManager.cs | 106 +-- MES.Service/Modes/MesRohInData.cs | 5 MES.Service/service/BasicData/MesRohInManager.cs | 151 +--- MES.Service/service/BasicData/MesPositionManager.cs | 119 +--- MES.Service/Dto/webApi/ErpDepots.cs | 10 MES.Service/Modes/MesRohIn.cs | 2 MES.Service/service/BasicData/SysDepartmentManager.cs | 158 ++--- MES.Service/Modes/MesPosition.cs | 11 MES.Service/service/BasicData/MesCustomerManager.cs | 152 ++--- MES.Service/service/BasicData/OrganizeManager.cs | 343 ++++------- MES.Service/service/BasicData/MesSupplierManager.cs | 151 ++--- MES.Service/Dto/webApi/ErpRohinData.cs | 10 MES.Service/Dto/webApi/ErpPosition.cs | 17 MES.Service/service/BasicData/MesDepotsManager.cs | 163 ++--- MES.Service/service/BasicData/MesItemsManager.cs | 131 ++-- 16 files changed, 630 insertions(+), 1,019 deletions(-) diff --git a/MES.Service/Dto/webApi/ErpDepots.cs b/MES.Service/Dto/webApi/ErpDepots.cs index ee44fad..d81f376 100644 --- a/MES.Service/Dto/webApi/ErpDepots.cs +++ b/MES.Service/Dto/webApi/ErpDepots.cs @@ -5,22 +5,12 @@ public string Id { get; set; } public string? Type { get; set; } public string? FNumber { get; set; } - public string? FName { get; set; } - - public string? FAllowMinusQty { get; set; } - public string? FPrincipal { get; set; } - public string? FStockProperty { get; set; } - public string? FForbidStatus { get; set; } - public string? FGroup { get; set; } - - public string? FCreateOrgId { get; set; } - public string? FUseOrgId { get; set; } } \ No newline at end of file diff --git a/MES.Service/Dto/webApi/ErpPosition.cs b/MES.Service/Dto/webApi/ErpPosition.cs index 7da84f0..4eece24 100644 --- a/MES.Service/Dto/webApi/ErpPosition.cs +++ b/MES.Service/Dto/webApi/ErpPosition.cs @@ -4,28 +4,15 @@ { public string Id { get; set; } - /// <summary> - /// 0 鍚敤 1绂佺敤 2 瀹℃牳 3鍙嶅鏍� - /// </summary> public string? Type { get; set; } - - public string? FNumber { get; set; } - public string? FName { get; set; } - public string? FDESCRIPTIONS { get; set; } - public string? FDept { get; set; } - public string? FCreateDate { get; set; } - public string? FForbidderId { get; set; } - public string? FForbidDate { get; set; } - - /// <summary> - /// 绂佺敤鐘舵�� A 鍚敤 B绂佺敤 - /// </summary> public string? FForbidStatus { get; set; } + public string? FCreateOrgId { get; set; } + public string? FUseOrgId { get; set; } } \ No newline at end of file diff --git a/MES.Service/Dto/webApi/ErpRohinData.cs b/MES.Service/Dto/webApi/ErpRohinData.cs index 8cbe8bc..c75827f 100644 --- a/MES.Service/Dto/webApi/ErpRohinData.cs +++ b/MES.Service/Dto/webApi/ErpRohinData.cs @@ -21,7 +21,7 @@ public string? FRequireDeptId { get; set; } public string? FReceiveOrgId { get; set; } public string? FReceiveDeptId { get; set; } - public string? FEntrySettleOrgId { get; set; } + public string? Fsettleorgid { get; set; } // end public string? FGiveAway { get; set; } public string? FNote { get; set; } @@ -37,13 +37,13 @@ public string? FMRPTerminateStatus { get; set; } public string? FTerminaterId { get; set; } public string? FTerminateDate { get; set; } - public string? FBaseReceiveQty { get; set; } + public string? FReceiveQty { get; set; } public string? FRemainReceiveQty { get; set; } - public string? FBaseStockInQty { get; set; } + public string? FStockInQty { get; set; } public string? FRemainStockINQty { get; set; } public string? FMrbQty { get; set; } - public string? FBaseCheckRetQty { get; set; } - public string? FBaseStockRetQty { get; set; } + public string? Fcheckretqty { get; set; } + public string? Fstockretqty { get; set; } public string? FSrcBillTypeId { get; set; } public string? FSrcBillNo { get; set; } public string? FReqTraceNo { get; set; } diff --git a/MES.Service/Modes/MesPosition.cs b/MES.Service/Modes/MesPosition.cs index a2f13ce..7d92c34 100644 --- a/MES.Service/Modes/MesPosition.cs +++ b/MES.Service/Modes/MesPosition.cs @@ -86,6 +86,17 @@ [SugarColumn(ColumnName = "REMARK5")] public string? Remark5 { get; set; } + /// <summary> + /// 浣跨敤缁勭粐 + /// </summary> + [SugarColumn(ColumnName = "FUSEORGID")] + public string? FUserOrgId { get; set; } + + /// <summary> + /// 鍒涘缓缁勭粐 + /// </summary> + [SugarColumn(ColumnName = "FCREATEORGID")] + public string? FCreateOrgId { get; set; } [SugarColumn(IsIgnore = true)] public string? Type { get; set; } } \ No newline at end of file diff --git a/MES.Service/Modes/MesRohIn.cs b/MES.Service/Modes/MesRohIn.cs index 2c9fc7a..f0802d7 100644 --- a/MES.Service/Modes/MesRohIn.cs +++ b/MES.Service/Modes/MesRohIn.cs @@ -276,7 +276,7 @@ public DateTime? ArriveDate { get; set; } /// <summary> - /// 閲囪喘鏃ユ湡 + /// 鏀舵枡缁勭粐 /// </summary> [SugarColumn(ColumnName = "RECEIVE_ORG")] public decimal? ReceiveOrg { get; set; } diff --git a/MES.Service/Modes/MesRohInData.cs b/MES.Service/Modes/MesRohInData.cs index 0e7a344..5dddcd9 100644 --- a/MES.Service/Modes/MesRohInData.cs +++ b/MES.Service/Modes/MesRohInData.cs @@ -35,14 +35,12 @@ /// <summary> /// 鐗╂枡鍚嶇О /// </summary> - // [SugarColumn(ColumnName = "ITEM_NAME")] [SugarColumn(IsIgnore = true)] public string? ItemName { get; set; } /// <summary> /// 鐗╂枡瑙勬牸 /// </summary> - // [SugarColumn(ColumnName = "ITEM_SPEC")] [SugarColumn(IsIgnore = true)] public string? ItemSpec { get; set; } @@ -314,8 +312,7 @@ /// <summary> /// SEQ_BASEINFO_ID /// </summary> - [SugarColumn(ColumnName = "ID", OracleSequenceName = "SEQ_BASEINFO_ID", - IsPrimaryKey = true)] + [SugarColumn(ColumnName = "ID", OracleSequenceName = "SEQ_BASEINFO_ID",IsPrimaryKey = true)] public decimal Id { get; set; } /// <summary> diff --git a/MES.Service/service/BasicData/MesCustomerManager.cs b/MES.Service/service/BasicData/MesCustomerManager.cs index 805a5fa..6fef5bc 100644 --- a/MES.Service/service/BasicData/MesCustomerManager.cs +++ b/MES.Service/service/BasicData/MesCustomerManager.cs @@ -9,7 +9,7 @@ { public bool Save(ErpCustomer customer) { - var entity = GetSysDepartment(customer); + var entity = GetMesCustomer(customer); return UseTransaction(db => { @@ -28,7 +28,7 @@ return 1; break; case "3": - if (DeleteCustomer(db, entity.Id)) + if (UpdateCustomerStatus(db, entity.Id, "B")) return 1; break; case "4": @@ -36,8 +36,7 @@ return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{customer.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{customer.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -46,9 +45,9 @@ public bool SaveList(List<ErpCustomer> customers) { - var list = customers.Select(GetSysDepartment).ToList(); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var list = customers.Select(GetMesCustomer).ToList(); + + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { @@ -68,7 +67,7 @@ throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteCustomerBatch(db, customerGroup.Value)) + if (!UpdateCustomerStatusBatch(db, customerGroup.Value, "B")) throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": @@ -76,47 +75,63 @@ throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{customerGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{customerGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; }) > 0; } - private bool UpdateCustomerStatus(SqlSugarScope db, decimal customerId, - string status) + private bool UpdateCustomerStatus(SqlSugarScope db, decimal customerId,string status) { - var result = db.Updateable<MesCustomer>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == customerId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesCustomer>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == customerId).ExecuteCommand(); + return true; } private bool InsertCustomer(SqlSugarScope db, MesCustomer entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) + var exists = db.Queryable<MesCustomer>().Any(e => e.Id == entity.Id); + if (exists) + { + var result = db.Updateable<MesCustomer>().ExecuteCommand(); return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } + } } - - private bool DeleteCustomer(SqlSugarScope db, decimal customerId) + private bool InsertOrUpdate(SqlSugarScope db, MesCustomer entity) { - var deleteById = db.Deleteable<MesCustomer>().In(customerId) - .ExecuteCommand(); - if (deleteById > 0) + var exists = db.Queryable<MesCustomer>().Any(e => e.Id == entity.Id); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } - private MesCustomer GetSysDepartment(ErpCustomer customer) + private MesCustomer GetMesCustomer(ErpCustomer customer) { return new MesCustomer { @@ -136,67 +151,34 @@ }; } - private bool UpdateCustomerStatusBatch(SqlSugarScope db, - List<MesCustomer> customerList, string status) + private bool UpdateCustomerStatusBatch(SqlSugarScope db,List<MesCustomer> customerList, string status) { var ids = customerList.Select(it => it.Id).ToArray(); - var result = db.Updateable<MesCustomer>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => ids.Contains(s.Id)).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesCustomer>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; } - private bool InsertCustomerBatch(SqlSugarScope db, - List<MesCustomer> customerList) - { - var insertRange = db.Insertable(customerList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - private bool DeleteCustomerBatch(SqlSugarScope db, - List<MesCustomer> customerList) - { - var ids = customerList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<MesCustomer>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - private bool InsertOrUpdate(SqlSugarScope db, MesCustomer entity) - { - var exists = db.Queryable<MesCustomer>().Any(e => e.Id == entity.Id); - if (exists) - { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; - } - else - { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - } - - return false; - } - - private bool InsertOrUpdateBatch(SqlSugarScope db, - List<MesCustomer> customerList) + private bool InsertCustomerBatch(SqlSugarScope db,List<MesCustomer> customerList) { foreach (var entity in customerList) - if (!InsertOrUpdate(db, entity)) + { + if (!InsertCustomer(db, entity)) + { return false; + } + } + return true; + } + private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesCustomer> customerList) + { + foreach (var entity in customerList) + { + if (!InsertOrUpdate(db, entity)) + { + return false; + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs index 10c7f9d..3087d0b 100644 --- a/MES.Service/service/BasicData/MesDepotsManager.cs +++ b/MES.Service/service/BasicData/MesDepotsManager.cs @@ -16,28 +16,27 @@ switch (depots.Type) { case "0": - if (UpdateDepotStatus(db, entity.DepotId, "A")) return 1; - + if (UpdateDepotStatus(db, entity.DepotId, "A")) + return 1; break; case "1": - if (UpdateDepotStatus(db, entity.DepotId, "B")) return 1; - + if (UpdateDepotStatus(db, entity.DepotId, "B")) + return 1; break; case "2": - if (InsertDepot(db, entity)) return 1; - + if (InsertDepot(db, entity)) + return 1; break; case "3": - if (DeleteDepot(db, entity.DepotId)) return 1; - + if (UpdateDepotStatus(db, entity.DepotId, "B")) + return 1; break; case "4": - if (InsertOrUpdate(db, entity)) return 1; - + if (InsertOrUpdate(db, entity)) + return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{depots.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{depots.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -45,59 +44,56 @@ } // 鏇存柊浠撳簱鐘舵�佺殑鏂规硶 - private bool UpdateDepotStatus(SqlSugarScope db, decimal depotId, - string status) + private bool UpdateDepotStatus(SqlSugarScope db, decimal depotId,string status) { - var result = db.Updateable<MesDepots>() - .SetColumns(s => s.IsNg == status) - .Where(s => s.DepotId == depotId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesDepots>().SetColumns(s => s.IsNg == status).Where(s => s.DepotId == depotId).ExecuteCommand(); + return true; } // 鎻掑叆鏂颁粨搴撶殑鏂规硶 private bool InsertDepot(SqlSugarScope db, MesDepots entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - - throw new NotImplementedException("瀹℃牳澶辫触"); - } - - // 鍒犻櫎浠撳簱鐨勬柟娉� - private bool DeleteDepot(SqlSugarScope db, decimal depotId) - { - var deleteById = db.Deleteable<MesDepots>().In(depotId) - .ExecuteCommand(); - if (deleteById > 0) - return true; - - throw new NotImplementedException("鍙嶅鏍稿け璐�"); - } - - // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 - private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity) - { - var exists = db.Queryable<MesDepots>() - .Any(e => e.DepotId == entity.DepotId); + var exists = db.Queryable<MesDepots>().Any(e => e.DepotId == entity.DepotId); if (exists) { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; + var result = db.Updateable<MesDepots>().ExecuteCommand(); + return true; } else { var insert = db.Insertable(entity).ExecuteCommand(); if (insert > 0) + { return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } } + } - return false; + // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 + private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity) + { + var exists = db.Queryable<MesDepots>().Any(e => e.DepotId == entity.DepotId); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); + return true; + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } // 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉� @@ -124,49 +120,35 @@ // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜浠撳簱璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔 public bool SaveList(List<ErpDepots> erpDepots) { - var list = new List<MesDepots>(); - erpDepots.ForEach(s => - { - var entity = GetMesDepots(s); // 灏� ErpDepots 杞崲涓� MesDepots - entity.Type = s.Type; - list.Add(entity); - }); - - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var list = erpDepots.Select(GetMesDepots).ToList(); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { foreach (var depotsGroup in groupBy) switch (depotsGroup.Key) { case "0": - if (!UpdateDepotStatusBatch(db, depotsGroup.Value, - "A")) // 鎵归噺鍚敤浠撳簱 + if (!UpdateDepotStatusBatch(db, depotsGroup.Value,"A")) // 鎵归噺鍚敤浠撳簱 throw new NotImplementedException("鍚敤澶辫触"); break; case "1": - if (!UpdateDepotStatusBatch(db, depotsGroup.Value, - "B")) // 鎵归噺绂佺敤浠撳簱 + if (!UpdateDepotStatusBatch(db, depotsGroup.Value,"B")) // 鎵归噺绂佺敤浠撳簱 throw new NotImplementedException("绂佺敤澶辫触"); break; case "2": - if (!InsertDepotBatch(db, - depotsGroup.Value)) // 鎵归噺鎻掑叆浠撳簱 + if (!InsertDepotBatch(db,depotsGroup.Value)) // 鎵归噺鎻掑叆浠撳簱 throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteDepotBatch(db, - depotsGroup.Value)) // 鎵归噺鍒犻櫎浠撳簱 + if (!UpdateDepotStatusBatch(db, depotsGroup.Value, "B")) // 鎵归噺绂佺敤浠撳簱 throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": - if (!InsertOrUpdateBatch(db, - depotsGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴� + if (!InsertOrUpdateBatch(db,depotsGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴� throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{depotsGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{depotsGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; @@ -178,48 +160,27 @@ List<MesDepots> depotList, string status) { var ids = depotList.Select(it => it.DepotId).ToArray(); - var result = db.Updateable<MesDepots>() - .SetColumns(s => s.IsNg == status) - .Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesDepots>().SetColumns(s => s.IsNg == status).Where(s => ids.Contains(s.DepotId)).ExecuteCommand(); + return true; } // 鎵归噺鎻掑叆浠撳簱鐨勬柟娉� - private bool InsertDepotBatch(SqlSugarScope db, - List<MesDepots> depotList) + private bool InsertDepotBatch(SqlSugarScope db,List<MesDepots> depotList) { var insertRange = db.Insertable(depotList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("瀹℃牳澶辫触"); - } - - // 鎵归噺鍒犻櫎浠撳簱鐨勬柟娉� - private bool DeleteDepotBatch(SqlSugarScope db, - List<MesDepots> depotList) - { - var ids = depotList.Select(it => it.DepotId).ToArray(); - var deleteByIds = - db.Deleteable<MesDepots>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍙嶅鏍稿け璐�"); + return true; } // 鎵归噺鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶 - private bool InsertOrUpdateBatch(SqlSugarScope db, - List<MesDepots> depotList) + private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesDepots> depotList) { foreach (var entity in depotList) + { if (!InsertOrUpdate(db, entity)) + { return false; - + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/MesItemsManager.cs b/MES.Service/service/BasicData/MesItemsManager.cs index 7bdb461..f3ab3cf 100644 --- a/MES.Service/service/BasicData/MesItemsManager.cs +++ b/MES.Service/service/BasicData/MesItemsManager.cs @@ -10,10 +10,7 @@ { public MesItems GetItemQcPrint(WarehouseQuery query) { - return Db.Queryable<MesItems>() - .Where(c => c.Factory == query.Factory - && c.Company == query.Company - && c.ItemNo == query.ItemNo).First(); + return Db.Queryable<MesItems>().Where(c => c.Factory == query.Factory && c.Company == query.Company && c.ItemNo == query.ItemNo).First(); } @@ -38,7 +35,7 @@ return 1; break; case "3": - if (DeleteItem(db, entity.Id)) + if (UpdateItemStatus(db, entity.Id, "B")) return 1; break; case "4": @@ -46,8 +43,7 @@ return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{item.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{item.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -57,8 +53,7 @@ public bool SaveList(List<ErpItems> items) { var list = items.Select(GetMesItems).ToList(); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { @@ -78,7 +73,7 @@ throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteItemBatch(db, itemGroup.Value)) + if (!UpdateItemStatusBatch(db, itemGroup.Value, "B")) throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": @@ -86,43 +81,61 @@ throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{itemGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{itemGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; }) > 0; } - private bool UpdateItemStatus(SqlSugarScope db, decimal itemId, - string status) + private bool UpdateItemStatus(SqlSugarScope db, decimal itemId,string status) { - var result = db.Updateable<MesItems>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == itemId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesItems>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == itemId).ExecuteCommand(); + return true; } private bool InsertItem(SqlSugarScope db, MesItems entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) + var exists = db.Queryable<MesItems>().Any(e => e.Id == entity.Id); + if (exists) + { + var result = db.Updateable<MesItems>().ExecuteCommand(); return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } + } } - private bool DeleteItem(SqlSugarScope db, decimal itemId) + private bool InsertOrUpdate(SqlSugarScope db, MesItems entity) { - var deleteById = db.Deleteable<MesItems>().In(itemId).ExecuteCommand(); - if (deleteById > 0) + var exists = db.Queryable<Organize>().Any(e => e.Id == entity.Id); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } private MesItems GetMesItems(ErpItems item) @@ -166,64 +179,34 @@ }; } - private bool UpdateItemStatusBatch(SqlSugarScope db, - List<MesItems> itemList, string status) + private bool UpdateItemStatusBatch(SqlSugarScope db,List<MesItems> itemList, string status) { var ids = itemList.Select(it => it.Id).ToArray(); - var result = db.Updateable<MesItems>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => ids.Contains(s.Id)).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesItems>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; } private bool InsertItemBatch(SqlSugarScope db, List<MesItems> itemList) { - var insertRange = db.Insertable(itemList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - private bool DeleteItemBatch(SqlSugarScope db, List<MesItems> itemList) - { - var ids = itemList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<MesItems>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - private bool InsertOrUpdate(SqlSugarScope db, MesItems entity) - { - var exists = db.Queryable<MesItems>().Any(e => e.Id == entity.Id); - if (exists) + foreach (var entity in itemList) { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; + if (!InsertItem(db, entity)) + { + return false; + } } - else - { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - } - - return false; + return true; } private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesItems> itemList) { foreach (var entity in itemList) + { if (!InsertOrUpdate(db, entity)) + { return false; - + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/MesPositionManager.cs b/MES.Service/service/BasicData/MesPositionManager.cs index 628faf8..3e7b4cb 100644 --- a/MES.Service/service/BasicData/MesPositionManager.cs +++ b/MES.Service/service/BasicData/MesPositionManager.cs @@ -7,9 +7,6 @@ public class MesPositionManager : Repository<MesPosition> { - // 褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉� - - // Save 鏂规硶鐢ㄤ簬淇濆瓨鍗曚釜宀椾綅璁板綍锛屾牴鎹被鍨嬫墽琛屼笉鍚岀殑鎿嶄綔 public bool Save(ErpPosition unit) { var entity = GetMesPosition(unit); // 灏� ErpPosition 杞崲涓� MesPosition @@ -30,7 +27,7 @@ return 1; break; case "3": - if (DeletePosition(db, entity.Id)) // 鍒犻櫎宀椾綅 + if (UpdatePositionStatus(db, entity.Id, "B")) // 鍒犻櫎宀椾綅 return 1; break; case "4": @@ -38,8 +35,7 @@ return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -47,17 +43,10 @@ } // 鏇存柊宀椾綅鐘舵�佺殑鏂规硶 - private bool UpdatePositionStatus(SqlSugarScope db, decimal positionId, - string status) + private bool UpdatePositionStatus(SqlSugarScope db, decimal positionId , string status) { - var result = db.Updateable<MesPosition>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == positionId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesPosition>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == positionId).ExecuteCommand(); + return true; } // 鎻掑叆鎴栨洿鏂板矖浣嶇殑鏂规硶 @@ -67,28 +56,20 @@ if (exists) { var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; + return true; } else { var insert = db.Insertable(entity).ExecuteCommand(); if (insert > 0) + { return true; + } + else + { + return false; + } } - - return false; - } - - // 鍒犻櫎宀椾綅鐨勬柟娉� - private bool DeletePosition(SqlSugarScope db, decimal positionId) - { - var deleteById = db.Deleteable<MesPosition>().In(positionId) - .ExecuteCommand(); - if (deleteById > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); } // 灏� ErpPosition 瀵硅薄杞崲涓� MesPosition 瀵硅薄鐨勬柟娉� @@ -103,8 +84,9 @@ Department = position.FDept, Fforbidstatus = position.FForbidStatus, CreationDate = DateTime.Now, - DisabledBy = position.FForbidderId, - DisabledDate = position.FForbidDate != null? DateTime.ParseExact(position.FForbidDate, "yyyy-MM-dd HH:mm:ss", null) : null + FCreateOrgId = position.FCreateOrgId, + FUserOrgId = position.FUseOrgId + }; } @@ -112,48 +94,34 @@ public bool SaveList(List<ErpPosition> positions) { var list = new List<MesPosition>(); - positions.ForEach(s => - { - var entity = GetMesPosition(s); // 灏� ErpPosition 杞崲涓� MesPosition - entity.Type = s.Type; - list.Add(entity); - }); - - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { foreach (var positionGroup in groupBy) switch (positionGroup.Key) { case "0": - if (!UpdatePositionStatusBatch(db, positionGroup.Value, - "A")) // 鎵归噺鍚敤宀椾綅 + if (!UpdatePositionStatusBatch(db, positionGroup.Value,"A")) // 鎵归噺鍚敤宀椾綅 throw new NotImplementedException("鍚敤澶辫触"); break; case "1": - if (!UpdatePositionStatusBatch(db, positionGroup.Value, - "B")) // 鎵归噺绂佺敤宀椾綅 + if (!UpdatePositionStatusBatch(db, positionGroup.Value,"B")) // 鎵归噺绂佺敤宀椾綅 throw new NotImplementedException("绂佺敤澶辫触"); break; case "2": - if (!InsertPositionBatch(db, - positionGroup.Value)) // 鎵归噺鎻掑叆宀椾綅 + if (!InsertOrUpdatePositionBatch(db, positionGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂板矖浣� throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeletePositionBatch(db, - positionGroup.Value)) // 鎵归噺鍒犻櫎宀椾綅 + if (!UpdatePositionStatusBatch(db, positionGroup.Value, "B")) // 鎵归噺绂佺敤宀椾綅 throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": - if (!InsertOrUpdatePositionBatch(db, - positionGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂板矖浣� + if (!InsertOrUpdatePositionBatch(db,positionGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂板矖浣� throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{positionGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{positionGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; @@ -161,51 +129,24 @@ } // 鎵归噺鏇存柊宀椾綅鐘舵�佺殑鏂规硶 - private bool UpdatePositionStatusBatch(SqlSugarScope db, - List<MesPosition> positionList, string status) + private bool UpdatePositionStatusBatch(SqlSugarScope db,List<MesPosition> positionList, string status) { var ids = positionList.Select(it => it.Id).ToArray(); - var result = db.Updateable<MesPosition>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => ids.Contains(s.Id)).ExecuteCommand(); + var result = db.Updateable<MesPosition>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); - } - - // 鎵归噺鎻掑叆宀椾綅鐨勬柟娉� - private bool InsertPositionBatch(SqlSugarScope db, - List<MesPosition> positionList) - { - var insertRange = db.Insertable(positionList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - // 鎵归噺鍒犻櫎宀椾綅鐨勬柟娉� - private bool DeletePositionBatch(SqlSugarScope db, - List<MesPosition> positionList) - { - var ids = positionList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<MesPosition>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); } // 鎵归噺鎻掑叆鎴栨洿鏂板矖浣嶇殑鏂规硶 - private bool InsertOrUpdatePositionBatch(SqlSugarScope db, - List<MesPosition> positionList) + private bool InsertOrUpdatePositionBatch(SqlSugarScope db,List<MesPosition> positionList) { foreach (var entity in positionList) + { if (!InsertOrUpdatePosition(db, entity)) + { return false; - + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/MesRohInManager.cs b/MES.Service/service/BasicData/MesRohInManager.cs index 2b901f2..9b395ea 100644 --- a/MES.Service/service/BasicData/MesRohInManager.cs +++ b/MES.Service/service/BasicData/MesRohInManager.cs @@ -8,8 +8,6 @@ public class MesRohInManager : Repository<MesRohIn> { private readonly MesRohInDataManager rohInDataManager = new(); - - // Save 鏂规硶鐢ㄤ簬淇濆瓨鍗曚釜 RohIn 璁板綍锛屾牴鎹被鍨嬫墽琛屼笉鍚岀殑鎿嶄綔 public bool Save(RohIn rohIn) { var rohInErpRohIn = rohIn.ErpRohIn; @@ -20,95 +18,46 @@ { 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; + return SaveOrUpdateData(db, mesRohIn, mesRohInDatas) ? 1 : 0; default: - throw new NotImplementedException( - $"type娌℃湁{rohInErpRohIn.Type}杩欎釜绫诲瀷"); + 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); - - 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) + private bool UpdateData(SqlSugarScope db, MesRohIn mesRohIn,List<MesRohInData> mesRohInDatas) { var decimals = mesRohInDatas.Select(s => s.Id).ToArray(); var update = base.DeleteById(mesRohIn.Id); - var insertOrUpdate = db - .Deleteable<MesRohInData>().In(decimals) - .ExecuteCommand() > 0; + var insertOrUpdate = db.Deleteable<MesRohInData>().In(decimals).ExecuteCommand() > 0; - if (update && insertOrUpdate) return true; + if (update && insertOrUpdate) + { + return true; + } throw new NotImplementedException("鏇存柊澶辫触"); } // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶 - private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn, - List<MesRohInData> mesRohInDatas) + private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn,List<MesRohInData> mesRohInDatas) { - if (mesRohIn.Id != null) base.DeleteById(mesRohIn.Id); + if (mesRohIn.Id != null) + { + base.DeleteById(mesRohIn.Id); + } if (mesRohInDatas.Count > 0) - db.Deleteable<MesRohInData>() - .Where(s => s.ErpId == mesRohIn.EbelnK3id).ExecuteCommand(); - + { + 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; @@ -129,7 +78,10 @@ var mesRohIn = new MesRohIn(); var single = base.GetSingle(it => it.EbelnK3id == eid); - if (single != null) mesRohIn.Id = single.Id; + if (single != null) + { + mesRohIn.Id = single.Id; + } mesRohIn.EbelnK3id = eid; mesRohIn.BillNo = rohIn.FBillNo; @@ -137,7 +89,9 @@ 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; @@ -151,17 +105,16 @@ 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; 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; @@ -172,8 +125,7 @@ } // 灏� ErpRohinData 瀵硅薄杞崲涓� MesRohInData 瀵硅薄鐨勬柟娉� - public List<MesRohInData> GetMesRohInDatas( - List<ErpRohinData> erpRohinDatas, string type) + public List<MesRohInData> GetMesRohInDatas(List<ErpRohinData> erpRohinDatas, string type) { return erpRohinDatas.Select(s => { @@ -191,18 +143,9 @@ 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, + 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, @@ -212,23 +155,17 @@ 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, + 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, + 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), + ReturnableReceivedQty = Convert.ToDecimal(s.Fcheckretqty), + ReturnableStoredQty = Convert.ToDecimal(s.Fstockretqty), SourceDocumentType = s.FSrcBillTypeId, SourceDocumentId = s.FSrcBillNo, DemandTrackingId = s.FReqTraceNo, @@ -241,15 +178,17 @@ DemandOrg = s.FRequireOrgId, Receiving = s.FReceiveOrgId, ReceivingOrg = s.FReceiveOrgId, - Settlement = s.FEntrySettleOrgId, - SettlementOrg = s.FEntrySettleOrgId, + Settlement = s.Fsettleorgid, + SettlementOrg = s.Fsettleorgid, DemandDept = s.FRequireDeptId, ReceivingDept = s.FReceiveDeptId }; - var single = rohInDataManager.GetSingle(it => - it.EbelnK3id == entity.EbelnK3id); - if (single != null) entity.Id = single.Id; + var single = rohInDataManager.GetSingle(it =>it.EbelnK3id == entity.EbelnK3id); + if (single != null) + { + entity.Id = single.Id; + } return entity; }).ToList(); diff --git a/MES.Service/service/BasicData/MesStaffManager.cs b/MES.Service/service/BasicData/MesStaffManager.cs index 9f05723..d0eb8b7 100644 --- a/MES.Service/service/BasicData/MesStaffManager.cs +++ b/MES.Service/service/BasicData/MesStaffManager.cs @@ -30,12 +30,11 @@ return 1; break; case "3": - if (DeleteStaff(db, entity.Id)) // 鍒犻櫎鍛樺伐 + if (UpdateStaffStatus(db, entity.Id, "B")) // 绂佺敤鍛樺伐 return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -46,48 +45,30 @@ private bool UpdateStaffStatus(SqlSugarScope db, decimal staffId,string status) { var result = db.Updateable<MesStaff>().SetColumns(s => s.FforbidStatus == status).Where(s => s.Id == staffId).ExecuteCommand(); - - if (result > 0) - { - return true; - } - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + return true; } // 鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶 private bool InsertOrUpdateStaff(SqlSugarScope db,MesStaff entity) { - var exists = db.Queryable<MesStaff>().Any(u => u.StaffNo == entity.StaffNo); + var exists = db.Queryable<MesStaff>().Any(e => e.Id == entity.Id); if (exists) { - var updateStaff = db.Updateable(entity).ExecuteCommand(); - if (updateStaff > 0) - { - return true; - } + var update = db.Updateable(entity).ExecuteCommand(); + return true; } else { - var insertStaff = db.Insertable(entity).ExecuteCommand(); - if (insertStaff > 0) + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) { return true; } + else + { + return false; + } } - - return false; - } - - // 鍒犻櫎鍛樺伐鐨勬柟娉� - private bool DeleteStaff(SqlSugarScope db,decimal staffId) - { - var deleteStaff =db.Deleteable<MesStaff>().In(staffId).ExecuteCommand(); - if (deleteStaff > 0) - { - return true; - } - - throw new NotImplementedException("鍙嶅鏍稿け璐�"); } // 灏� ErpStaff 瀵硅薄杞崲涓� MesStaff 瀵硅薄鐨勬柟娉� @@ -117,18 +98,9 @@ } // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜鍛樺伐璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔 - public bool SaveList(List<ErpStaff> departments) + public bool SaveList(List<ErpStaff> staffs) { - var list = new List<MesStaff>(); - - departments.ForEach(s => - { - var entity = GetMesStaff(s); - entity.Type = s.Type; - list.Add(entity); - - }); - + var list = staffs.Select(GetMesStaff).ToList(); var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { @@ -148,7 +120,7 @@ throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteStaffBatch(db,staffGroup.Value)) // 鎵归噺鍒犻櫎鍛樺伐 + if (!UpdateStaffStatusBatch(db, staffGroup.Value, "B")) // 鎵归噺绂佺敤鍛樺伐 throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": @@ -168,51 +140,33 @@ { var ids = staffList.Select(it => it.Id).ToArray(); var result = db.Updateable<MesStaff>().SetColumns(s => s.FforbidStatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); - - if (result > 0) - { - return true; - } - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + return true; + } // 鎵归噺鎻掑叆鍛樺伐鐨勬柟娉� private bool InsertStaffBatch(SqlSugarScope db,List<MesStaff> staffList) { - var userInsert = staffList.FindAll(s => s.Type == "INSERT"); - var executeCommand = db.Insertable(userInsert).ExecuteCommand(); - if (executeCommand > 0) - if (db.Insertable(staffList).ExecuteCommand() > 0) - return true; - - throw new ArgumentNullException("瀹℃牳澶辫触"); - } - - // 鎵归噺鍒犻櫎鍛樺伐鐨勬柟娉� - private bool DeleteStaffBatch(SqlSugarScope db, List<MesStaff> staffList) - { - var ids = staffList.Select(it => it.Id).ToArray(); - if (db.Deleteable<MesStaff>().In(ids).ExecuteCommand() > 0) + foreach (var entity in staffList) { - return true; - } - - throw new ArgumentNullException("鍙嶅鏍稿け璐�"); - } - - // 鎵归噺鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶 - private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesStaff> staffList) - { - foreach (var staff in staffList) - { - var entity = staffList.First(s => s.StaffNo == staff.StaffNo); if (!InsertOrUpdateStaff(db, entity)) { return false; } } + return true; + } + // 鎵归噺鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶 + private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesStaff> staffList) + { + foreach (var entity in staffList) + { + if (!InsertOrUpdateStaff(db, entity)) + { + return false; + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/MesSupplierManager.cs b/MES.Service/service/BasicData/MesSupplierManager.cs index fb8718f..649b8fd 100644 --- a/MES.Service/service/BasicData/MesSupplierManager.cs +++ b/MES.Service/service/BasicData/MesSupplierManager.cs @@ -2,6 +2,7 @@ using MES.Service.Dto.webApi; using MES.Service.Modes; using SqlSugar; +using System.Collections.Generic; namespace MES.Service.service.BasicData; @@ -28,7 +29,7 @@ return 1; break; case "3": - if (DeleteSupplier(entity.Id)) + if (UpdateSupplierStatus(db, entity.Id, "B")) return 1; break; case "4": @@ -36,10 +37,8 @@ return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } - throw new NotImplementedException("鎿嶄綔澶辫触"); }) > 0; } @@ -47,8 +46,7 @@ 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()); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { @@ -56,13 +54,11 @@ switch (supplierGroup.Key) { case "0": - if (!UpdateSupplierStatusBatch(db, supplierGroup.Value, - "A")) + if (!UpdateSupplierStatusBatch(db, supplierGroup.Value,"A")) throw new NotImplementedException("鍚敤澶辫触"); break; case "1": - if (!UpdateSupplierStatusBatch(db, supplierGroup.Value, - "B")) + if (!UpdateSupplierStatusBatch(db, supplierGroup.Value,"B")) throw new NotImplementedException("绂佺敤澶辫触"); break; case "2": @@ -70,7 +66,7 @@ throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteSupplierBatch(db, supplierGroup.Value)) + if (!UpdateSupplierStatusBatch(db, supplierGroup.Value, "B")) throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": @@ -78,41 +74,61 @@ throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{supplierGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{supplierGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; }) > 0; } - private bool UpdateSupplierStatus(SqlSugarScope db, decimal supplierId, - string status) + private bool UpdateSupplierStatus(SqlSugarScope db, decimal supplierId,string status) { - var result = db.Updateable<MesSupplier>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == supplierId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesSupplier>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == supplierId).ExecuteCommand(); + return true; } private bool InsertSupplier(SqlSugarScope db, MesSupplier entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) + var exists = db.Queryable<MesSupplier>().Any(e => e.Id == entity.Id); + if (exists) + { + var result = db.Updateable<MesSupplier>().ExecuteCommand(); return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } + } } - private bool DeleteSupplier(decimal supplierId) + private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity) { - if (base.DeleteById(supplierId)) return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); + var exists = db.Queryable<MesSupplier>().Any(e => e.Id == entity.Id); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); + return true; + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } private MesSupplier GetMesSupplier(ErpSupplier supplier) @@ -136,67 +152,34 @@ }; } - private bool UpdateSupplierStatusBatch(SqlSugarScope db, - List<MesSupplier> supplierList, string status) + 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(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesSupplier>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; } - private bool InsertSupplierBatch(SqlSugarScope db, - List<MesSupplier> supplierList) - { - var insertRange = db.Insertable(supplierList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - 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; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - private bool InsertOrUpdate(SqlSugarScope db, MesSupplier entity) - { - var exists = db.Queryable<MesSupplier>().Any(e => e.Id == entity.Id); - if (exists) - { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; - } - else - { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - } - - return false; - } - - private bool InsertOrUpdateBatch(SqlSugarScope db, - List<MesSupplier> supplierList) + private bool InsertSupplierBatch(SqlSugarScope db,List<MesSupplier> supplierList) { foreach (var entity in supplierList) - if (!InsertOrUpdate(db, entity)) + { + if (!InsertSupplier(db, entity)) + { return false; + } + } + return true; + } + private bool InsertOrUpdateBatch(SqlSugarScope db,List<MesSupplier> supplierList) + { + foreach (var entity in supplierList) + { + if (!InsertOrUpdate(db, entity)) + { + return false; + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/MesUnitManager.cs b/MES.Service/service/BasicData/MesUnitManager.cs index 4ad9501..e06cbca 100644 --- a/MES.Service/service/BasicData/MesUnitManager.cs +++ b/MES.Service/service/BasicData/MesUnitManager.cs @@ -28,7 +28,7 @@ return 1; break; case "3": - if (DeleteUnit(db, entity.Id)) + if (UpdateUnitStatus(db, entity.Id, "B")) return 1; break; case "4": @@ -36,8 +36,7 @@ return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{unit.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -47,8 +46,7 @@ public bool SaveList(List<ErpUnit> units) { var list = units.Select(GetMesUnit).ToList(); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); return UseTransaction(db => { @@ -68,7 +66,7 @@ throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteUnitBatch(db, unitGroup.Value)) + if (!UpdateUnitStatusBatch(db, unitGroup.Value, "B")) throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": @@ -76,43 +74,61 @@ throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{unitGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{unitGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; }) > 0; } - private bool UpdateUnitStatus(SqlSugarScope db, decimal unitId, - string status) + private bool UpdateUnitStatus(SqlSugarScope db, decimal unitId,string status) { - var result = db.Updateable<MesUnit>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == unitId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesUnit>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == unitId).ExecuteCommand(); + return true; } private bool InsertUnit(SqlSugarScope db, MesUnit entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) + var exists = db.Queryable<MesUnit>().Any(e => e.Id == entity.Id); + if (exists) + { + var result = db.Updateable<MesUnit>().ExecuteCommand(); return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } + } } - private bool DeleteUnit(SqlSugarScope db, decimal unitId) + private bool InsertOrUpdate(SqlSugarScope db, MesUnit entity) { - var deleteById = db.Deleteable<MesUnit>().In(unitId).ExecuteCommand(); - if (deleteById > 0) + var exists = db.Queryable<MesUnit>().Any(e => e.Id == entity.Id); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } private MesUnit GetMesUnit(ErpUnit unit) @@ -141,57 +157,31 @@ string status) { var ids = unitList.Select(it => it.Id).ToArray(); - var result = db.Updateable<MesUnit>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => ids.Contains(s.Id)).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<MesUnit>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; } private bool InsertUnitBatch(SqlSugarScope db, List<MesUnit> unitList) { - var insertRange = db.Insertable(unitList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - private bool DeleteUnitBatch(SqlSugarScope db, List<MesUnit> unitList) - { - var ids = unitList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<MesUnit>().In(ids).ExecuteCommand(); - return deleteByIds > 0; - } - - private bool InsertOrUpdate(SqlSugarScope db, MesUnit entity) - { - var exists = db.Queryable<MesUnit>().Any(e => e.Id == entity.Id); - if (exists) + foreach (var entity in unitList) { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; + if (!InsertUnit(db, entity)) + { + return false; + } } - else - { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - } - - return false; + return true; } private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesUnit> unitList) { foreach (var entity in unitList) + { if (!InsertOrUpdate(db, entity)) + { return false; - + } + } return true; } } \ No newline at end of file diff --git a/MES.Service/service/BasicData/OrganizeManager.cs b/MES.Service/service/BasicData/OrganizeManager.cs index f5f5f31..4af4abe 100644 --- a/MES.Service/service/BasicData/OrganizeManager.cs +++ b/MES.Service/service/BasicData/OrganizeManager.cs @@ -6,254 +6,179 @@ using MES.Service.Dto.webApi; using System.Xml.Linq; -namespace MES.Service.service -{ +namespace MES.Service.service; + public class OrganizeManager : Repository<Organize> { - //褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉� + public bool Save(ErpOrganize item) + { + var entity = GetOrganize(item); - //杩欓噷闈㈠啓鐨勪唬鐮佷笉浼氱粰瑕嗙洊,濡傛灉瑕侀噸鏂扮敓鎴愯鍒犻櫎 OrganizeManager.cs - public bool Save(ErpOrganize item) + return UseTransaction(db => { - var entity = GetOrganize(item); - - return UseTransaction(db => + switch (item.Type) { - switch (item.Type) + case "0": + if (UpdateOrganizetatus(db, entity.Id, "A")) //鈭� + return 1; + break; + case "1": + if (UpdateOrganizetatus(db, entity.Id, "B")) //鈭� + return 1; + break; + case "2": + if (InsertItem(db, entity)) //鈭� + return 1; + break; + case "3": + if (UpdateOrganizetatus(db, entity.Id, "B")) //鈭� + return 1; + break; + case "4": + if (InsertOrUpdate(db, entity)) //鈭� + return 1; + break; + default: + throw new ArgumentNullException($"type娌℃湁{item.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + } + + throw new NotImplementedException("鎿嶄綔澶辫触"); + }) > 0; + } + + public bool SaveList(List<ErpOrganize> Organize) + { + var list = Organize.Select(GetOrganize).ToList(); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); + + return UseTransaction(db => + { + foreach (var itemGroup in groupBy) + switch (itemGroup.Key) { case "0": - if (UpdateOrganizetatus(db, entity.Id, "A")) - return 1; + if (!UpdateOrganizetatusBatch(db, itemGroup.Value, "A")) + throw new NotImplementedException("鍚敤澶辫触"); break; case "1": - if (UpdateOrganizetatus(db, entity.Id, "B")) - return 1; + if (!UpdateOrganizetatusBatch(db, itemGroup.Value, "B")) + throw new NotImplementedException("绂佺敤澶辫触"); break; case "2": - if (InsertItem(db, entity)) - return 1; + if (!InsertItemBatch(db, itemGroup.Value)) + throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (DeleteItem(db, Convert.ToDecimal(entity.Id))) - return 1; + if (!UpdateOrganizetatusBatch(db, itemGroup.Value, "B")) + throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": - if (InsertOrUpdate(db, entity)) - return 1; + if (!InsertOrUpdateBatch(db, itemGroup.Value)) + throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{item.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{itemGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } - throw new NotImplementedException("鎿嶄綔澶辫触"); - }) > 0; - } + return 1; + }) > 0; + } - public bool SaveList(List<ErpOrganize> Organize) + private bool UpdateOrganizetatus(SqlSugarScope db, decimal itemId,string status) + { + var result = db.Updateable<Organize>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == itemId).ExecuteCommand(); + return true; + } + + private bool InsertItem(SqlSugarScope db, Organize entity) + { + var exists = db.Queryable<Organize>().Any(e => e.Id == entity.Id); + if (exists) { - var list = Organize.Select(GetOrganize).ToList(); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); - - return UseTransaction(db => - { - foreach (var itemGroup in groupBy) - switch (itemGroup.Key) - { - case "0": - if (!UpdateOrganizetatusBatch(db, itemGroup.Value, "A")) - throw new NotImplementedException("鍚敤澶辫触"); - break; - case "1": - if (!UpdateOrganizetatusBatch(db, itemGroup.Value, "B")) - throw new NotImplementedException("绂佺敤澶辫触"); - break; - case "2": - if (!InsertItemBatch(db, itemGroup.Value)) - throw new NotImplementedException("鎻掑叆澶辫触"); - break; - case "3": - if (!DeleteItemBatch(db, itemGroup.Value)) - throw new NotImplementedException("鍒犻櫎澶辫触"); - break; - case "4": - if (!InsertOrUpdateBatch(db, itemGroup.Value)) - throw new NotImplementedException("鍚屾澶辫触"); - break; - default: - throw new ArgumentNullException( - $"type娌℃湁{itemGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); - } - - return 1; - }) > 0; + var result = db.Updateable<Organize>().ExecuteCommand(); + return true; } - - private bool UpdateOrganizetatus(SqlSugarScope db, decimal itemId, - string status) - { - var result = db.Updateable<Organize>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => s.Id == itemId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); - } - - private bool InsertItem(SqlSugarScope db, Organize entity) + else { var insert = db.Insertable(entity).ExecuteCommand(); if (insert > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - private bool DeleteItem(SqlSugarScope db, decimal itemId) - { - var deleteById = db.Deleteable<Organize>().In(itemId).ExecuteCommand(); - if (deleteById > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - private Organize GetOrganize(ErpOrganize Organize) - { - return new Organize { - - Id = Convert.ToDecimal(Organize.Id), - Fnumber = Organize.FNumber, - Fname = Organize.FName, - Fforbidstatus = Organize.FForbidStatus, - Type = Organize.Type, - Fparentid=Organize.FParentID, - Fcreatedate=DateTime.Now - }; - } - - private bool UpdateOrganizetatusBatch(SqlSugarScope db, - List<Organize> itemList, string status) - { - var ids = itemList.Select(it => it.Id).ToArray(); - var result = db.Updateable<Organize>() - .SetColumns(s => s.Fforbidstatus == status) - .Where(s => ids.Contains(s.Id)).ExecuteCommand(); - - if (result > 0) return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); - } - - private bool InsertItemBatch(SqlSugarScope db, List<Organize> itemList) - { - var insertRange = db.Insertable(itemList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - private bool DeleteItemBatch(SqlSugarScope db, List<Organize> itemList) - { - var ids = itemList.Select(it => it.Id).ToArray(); - var deleteByIds = db.Deleteable<Organize>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - private bool InsertOrUpdate(SqlSugarScope db, Organize entity) - { - var exists = db.Queryable<Organize>().Any(e => e.Id == entity.Id); - if (exists) - { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; } else { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; + throw new NotImplementedException("鎻掑叆澶辫触"); } - - return false; } + } - private bool InsertOrUpdateBatch(SqlSugarScope db, List<Organize> itemList) + private bool InsertOrUpdate(SqlSugarScope db, Organize entity) + { + var exists = db.Queryable<Organize>().Any(e => e.Id == entity.Id); + if (exists) { - foreach (var entity in itemList) - if (!InsertOrUpdate(db, entity)) - return false; - + var update = db.Updateable(entity).ExecuteCommand(); return true; } - #region 鏁欏鏂规硶 - /// <summary> - /// 浠撳偍鏂规硶婊¤冻涓嶄簡澶嶆潅涓氬姟闇�姹傦紝涓氬姟浠g爜璇峰湪杩欓噷闈㈠畾涔夋柟娉� - /// </summary> - public void Study() + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } + } + + private Organize GetOrganize(ErpOrganize Organize) { - - /*********鏌ヨ*********/ + return new Organize + { - 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(), OrderByType.Asc);// 鍒嗛〉鏌ヨ鍔犳帓搴� - Console.Write(p.TotalCount);//杩斿洖鎬绘暟 - - List<IConditionalModel> conModels = new List<IConditionalModel>(); //缁勮鏉′欢鏌ヨ浣滀负鏉′欢瀹炵幇 鍒嗛〉鏌ヨ鍔犳帓搴� - conModels.Add(new ConditionalModel() { FieldName= typeof(Organize).GetProperties()[0].Name, ConditionalType = ConditionalType.Equal, FieldValue = "1" });//id=1 - var data7 = base.GetPageList(conModels, p, it => SqlFunc.GetRandom(), OrderByType.Asc); - - base.AsQueryable().Where(x => 1 == 1).ToList();//鏀寔浜嗚浆鎹㈡垚queryable,鎴戜滑鍙互鐢╭ueryable瀹炵幇澶嶆潅鍔熻兘 - - - - /*********鎻掑叆*********/ - var insertData = new Organize() { };//娴嬭瘯鍙傛暟 - var insertArray = new Organize[] { insertData }; - base.Insert(insertData);//鎻掑叆 - base.InsertRange(insertArray);//鎵归噺鎻掑叆 - var id = base.InsertReturnIdentity(insertData);//鎻掑叆杩斿洖鑷鍒� - base.AsInsertable(insertData).ExecuteCommand();//鎴戜滑鍙互杞垚 Insertable瀹炵幇澶嶆潅鎻掑叆 - - - - /*********鏇存柊*********/ - var updateData = new Organize() { };//娴嬭瘯鍙傛暟 - var updateArray = new Organize[] { updateData };//娴嬭瘯鍙傛暟 - base.Update(updateData);//鏍规嵁瀹炰綋鏇存柊 - base.UpdateRange(updateArray);//鎵归噺鏇存柊 - //base.Update(it => new Organize() { ClassName = "a", CreateTime = DateTime.Now }, it => it.id==1);// 鍙洿鏂癈lassName鍒楀拰CreateTime鍒楋紝鍏跺畠鍒椾笉鏇存柊锛屾潯浠秈d=1 - base.AsUpdateable(updateData).ExecuteCommand(); //杞垚Updateable鍙互瀹炵幇澶嶆潅鐨勬彃鍏� - - - - /*********鍒犻櫎*********/ - var deldata = new Organize() { };//娴嬭瘯鍙傛暟 - base.Delete(deldata);//鏍规嵁瀹炰綋鍒犻櫎 - base.DeleteById(1);//鏍规嵁涓婚敭鍒犻櫎 - base.DeleteById(new int[] { 1,2});//鏍规嵁涓婚敭鏁扮粍鍒犻櫎 - base.Delete(it=>1==2);//鏍规嵁鏉′欢鍒犻櫎 - base.AsDeleteable().Where(it=>1==2).ExecuteCommand();//杞垚Deleteable瀹炵幇澶嶆潅鐨勬搷浣� + Id = Convert.ToDecimal(Organize.Id), + Fnumber = Organize.FNumber, + Fname = Organize.FName, + Fforbidstatus = Organize.FForbidStatus, + Type = Organize.Type, + Fparentid=Organize.FParentID, + Fcreatedate=DateTime.Now + }; } - #endregion + + private bool UpdateOrganizetatusBatch(SqlSugarScope db,List<Organize> itemList, string status) + { + var ids = itemList.Select(it => it.Id).ToArray(); + var result = db.Updateable<Organize>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; } + + private bool InsertItemBatch(SqlSugarScope db, List<Organize> itemList) + { + foreach (var entity in itemList) + { + if (!InsertItem(db, entity)) + { + return false; + } + } + return true; + } + + private bool InsertOrUpdateBatch(SqlSugarScope db, List<Organize> itemList) + { + foreach (var entity in itemList) + { + if (!InsertOrUpdate(db, entity)) + { + return false; + } + } + return true; + } + } \ No newline at end of file diff --git a/MES.Service/service/BasicData/SysDepartmentManager.cs b/MES.Service/service/BasicData/SysDepartmentManager.cs index f10a7e5..cdab8cf 100644 --- a/MES.Service/service/BasicData/SysDepartmentManager.cs +++ b/MES.Service/service/BasicData/SysDepartmentManager.cs @@ -1,4 +1,5 @@ -锘縰sing MES.Service.DB; +锘縰sing Castle.Core.Resource; +using MES.Service.DB; using MES.Service.Dto.webApi; using MES.Service.Modes; using SqlSugar; @@ -31,7 +32,7 @@ return 1; break; case "3": - if (DeleteDepartment(db, entity.Id)) // 鍒犻櫎閮ㄩ棬 + if (UpdateDepartmentStatus(db, entity.Id, "B")) // 绂佺敤閮ㄩ棬 return 1; break; case "4": @@ -39,8 +40,7 @@ return 1; break; default: - throw new ArgumentNullException( - $"type娌℃湁{department.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{department.Type}杩欎釜绫诲瀷鐨勫弬鏁�"); } throw new NotImplementedException("鎿嶄綔澶辫触"); @@ -48,59 +48,56 @@ } // 鏇存柊閮ㄩ棬鐘舵�佺殑鏂规硶 - private bool UpdateDepartmentStatus(SqlSugarScope db, decimal departmentId, - string status) + private bool UpdateDepartmentStatus(SqlSugarScope db, decimal departmentId,string status) { - var result = db.Updateable<SysDepartment>() - .SetColumns(s => s.Depextr4 == status) - .Where(s => s.Id == departmentId).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<SysDepartment>().SetColumns(s => s.Depextr4 == status).Where(s => s.Id == departmentId).ExecuteCommand(); + return true; } // 鎻掑叆鏂伴儴闂ㄧ殑鏂规硶 private bool InsertDepartment(SqlSugarScope db, SysDepartment entity) { - var insert = db.Insertable(entity).ExecuteCommand(); - if (insert > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - // 鍒犻櫎閮ㄩ棬鐨勬柟娉� - private bool DeleteDepartment(SqlSugarScope db, decimal departmentId) - { - var deleteById = db.Deleteable<SysDepartment>().In(departmentId) - .ExecuteCommand(); - if (deleteById > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); - } - - // 鎻掑叆鎴栨洿鏂伴儴闂ㄧ殑鏂规硶 - private bool InsertOrUpdateDepartment(SqlSugarScope db, - SysDepartment entity) - { var exists = db.Queryable<SysDepartment>().Any(e => e.Id == entity.Id); if (exists) { - var update = db.Updateable(entity).ExecuteCommand(); - if (update > 0) - return true; + var result = db.Updateable<SysDepartment>().ExecuteCommand(); + return true; } else { var insert = db.Insertable(entity).ExecuteCommand(); if (insert > 0) + { return true; + } + else + { + throw new NotImplementedException("鎻掑叆澶辫触"); + } } + } - return false; + // 鎻掑叆鎴栨洿鏂伴儴闂ㄧ殑鏂规硶 + private bool InsertOrUpdateDepartment(SqlSugarScope db,SysDepartment entity) + { + var exists = db.Queryable<SysDepartment>().Any(e => e.Id == entity.Id); + if (exists) + { + var update = db.Updateable(entity).ExecuteCommand(); + return true; + } + else + { + var insert = db.Insertable(entity).ExecuteCommand(); + if (insert > 0) + { + return true; + } + else + { + return false; + } + } } // 灏� ErpDepartment 瀵硅薄杞崲涓� SysDepartment 瀵硅薄鐨勬柟娉� @@ -128,50 +125,37 @@ // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜閮ㄩ棬璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔 public bool SaveList(List<ErpDepartment> departments) { - var list = new List<SysDepartment>(); - departments.ForEach(s => - { - var entity = - GetSysDepartment(s); // 灏� ErpDepartment 杞崲涓� SysDepartment - entity.Type = s.Type; - list.Add(entity); - }); + var list = departments.Select(GetSysDepartment).ToList(); - var groupBy = list.GroupBy(s => s.Type) - .ToDictionary(g => g.Key, g => g.ToList()); + var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); + return UseTransaction(db => { foreach (var departmentGroup in groupBy) switch (departmentGroup.Key) { case "0": - if (!UpdateDepartmentStatusBatch(db, - departmentGroup.Value, "A")) // 鎵归噺鍚敤閮ㄩ棬 + if (!UpdateDepartmentStatusBatch(db,departmentGroup.Value, "A")) // 鎵归噺鍚敤閮ㄩ棬 throw new NotImplementedException("鍚敤澶辫触"); break; case "1": - if (!UpdateDepartmentStatusBatch(db, - departmentGroup.Value, "B")) // 鎵归噺绂佺敤閮ㄩ棬 + if (!UpdateDepartmentStatusBatch(db,departmentGroup.Value, "B")) // 鎵归噺绂佺敤閮ㄩ棬 throw new NotImplementedException("绂佺敤澶辫触"); break; case "2": - if (!InsertDepartmentBatch(db, - departmentGroup.Value)) // 鎵归噺鎻掑叆閮ㄩ棬 + if (!InsertDepartmentBatch(db,departmentGroup.Value)) // 鎵归噺鎻掑叆閮ㄩ棬 throw new NotImplementedException("鎻掑叆澶辫触"); break; case "3": - if (!DeleteDepartmentBatch(db, - departmentGroup.Value)) // 鎵归噺鍒犻櫎閮ㄩ棬 + if (!UpdateDepartmentStatusBatch(db, departmentGroup.Value, "B")) // 鎵归噺绂佺敤閮ㄩ棬 throw new NotImplementedException("鍒犻櫎澶辫触"); break; case "4": - if (!InsertOrUpdateDepartmentBatch(db, - departmentGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂伴儴闂� + if (!InsertOrUpdateDepartmentBatch(db,departmentGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂伴儴闂� throw new NotImplementedException("鍚屾澶辫触"); break; default: - throw new ArgumentNullException( - $"type娌℃湁{departmentGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); + throw new ArgumentNullException($"type娌℃湁{departmentGroup.Key}杩欎釜绫诲瀷鐨勫弬鏁�"); } return 1; @@ -179,52 +163,36 @@ } // 鎵归噺鏇存柊閮ㄩ棬鐘舵�佺殑鏂规硶 - private bool UpdateDepartmentStatusBatch(SqlSugarScope db, - List<SysDepartment> departmentList, string status) + private bool UpdateDepartmentStatusBatch(SqlSugarScope db,List<SysDepartment> departmentList, string status) { var ids = departmentList.Select(it => it.Id).ToArray(); - var result = db.Updateable<SysDepartment>() - .SetColumns(s => s.Depextr4 == status) - .Where(s => ids.Contains(s.Id)).ExecuteCommand(); - - if (result > 0) - return true; - - throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触"); + var result = db.Updateable<SysDepartment>().SetColumns(s => s.Depextr4 == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); + return true; } // 鎵归噺鎻掑叆閮ㄩ棬鐨勬柟娉� - private bool InsertDepartmentBatch(SqlSugarScope db, - List<SysDepartment> departmentList) + private bool InsertDepartmentBatch(SqlSugarScope db,List<SysDepartment> departmentList) { - var insertRange = db.Insertable(departmentList).ExecuteCommand(); - if (insertRange > 0) - return true; - - throw new NotImplementedException("鎻掑叆澶辫触"); - } - - // 鎵归噺鍒犻櫎閮ㄩ棬鐨勬柟娉� - private bool DeleteDepartmentBatch(SqlSugarScope db, - List<SysDepartment> departmentList) - { - var ids = departmentList.Select(it => it.Id).ToArray(); - var deleteByIds = - db.Deleteable<SysDepartment>().In(ids).ExecuteCommand(); - if (deleteByIds > 0) - return true; - - throw new NotImplementedException("鍒犻櫎澶辫触"); + foreach (var entity in departmentList) + { + if (!InsertDepartment(db, entity)) + { + return false; + } + } + return true; } // 鎵归噺鎻掑叆鎴栨洿鏂伴儴闂ㄧ殑鏂规硶 - private bool InsertOrUpdateDepartmentBatch(SqlSugarScope db, - List<SysDepartment> departmentList) + private bool InsertOrUpdateDepartmentBatch(SqlSugarScope db,List<SysDepartment> departmentList) { foreach (var entity in departmentList) + { if (!InsertOrUpdateDepartment(db, entity)) + { return false; - + } + } return true; } } \ No newline at end of file -- Gitblit v1.9.3