From 1a09e10891586f227bec656d92ad27382f0412a2 Mon Sep 17 00:00:00 2001 From: hao <1836460075@qq.com> Date: 星期一, 18 八月 2025 15:14:12 +0800 Subject: [PATCH] 直接调拨申请单 --- .vs/slnx.sqlite | 0 StandardInterface/MES.Service/Dto/webApi/ERPZJDB.cs | 49 +++++++ StandardInterface/MES.Service/service/DbckaManager.cs | 3 StandardInterface/MES.Service/service/ZjdbManager.cs | 142 ++++++++++++++++++++ StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs | 38 +++++ StandardInterface/MES.Service/service/WomcaaManager.cs | 48 +++--- StandardInterface/MESApplication/Controllers/ZJdbController.cs | 103 ++++++++++++++ 7 files changed, 358 insertions(+), 25 deletions(-) diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 0200bd8..eb885f4 100644 --- a/.vs/slnx.sqlite +++ b/.vs/slnx.sqlite Binary files differ diff --git a/StandardInterface/MES.Service/Dto/webApi/ERPZJDB.cs b/StandardInterface/MES.Service/Dto/webApi/ERPZJDB.cs new file mode 100644 index 0000000..3ecc243 --- /dev/null +++ b/StandardInterface/MES.Service/Dto/webApi/ERPZJDB.cs @@ -0,0 +1,49 @@ +锘縰sing System.Collections.Generic; + +namespace MES.Service.Dto.webApi +{ + public class ERPZJDB + { + + public ERPZJDBA ERPZJDBA { get; set; } = new ERPZJDBA(); + public List<ERPZJDBB> ERPZJDBB { get; set; } = new List<ERPZJDBB>(); + } + + public class ERPZJDBA + { + public string? billno { get; set; } // 鍗曟嵁缂栫爜 + public string? dj_lx { get; set; } // 鍗曟嵁绫诲瀷 + public string? db_lx1 { get; set; } // 璋冩嫧绫诲瀷 + public string? db_fx { get; set; } // 璋冩嫧鏂瑰悜 + public string? db_lx { get; set; } // 璋冩嫧绫诲瀷 + public string? yw_lx { get; set; } // 涓氬姟绫诲瀷 + public string? dj_zt { get; set; } // 鍗曟嵁鐘舵�� + public string? sq_bm { get; set; } // 鐢宠閮ㄩ棬 + public string? dc_kc { get; set; } // 璋冨嚭搴撳瓨缁勭粐 + public string? dr_kc { get; set; } // 璋冨叆搴撳瓨缁勭粐 + public string? dc_hz { get; set; } // 璋冨嚭璐т富 + public string? dr_hz { get; set; } // 璋冨叆璐т富 + public string? dr_ck { get; set; } // 璋冨叆浠撳簱 + public string? dc_bm { get; set; } // 璋冨嚭閮ㄩ棬 + public string? dr_bm { get; set; } // 璋冨叆閮ㄩ棬 + public string? bz { get; set; } // 澶囨敞 + public string type { get; set; } // type + public string? erpid { get; set; } // 璋冩嫧鍑哄簱鍗昳d + } + + public class ERPZJDBB + { + public string? itemid { get; set; } // 鐗╂枡缂栫爜 + public string? unit { get; set; } // 鍗曚綅 + public string? quantity { get; set; } // 鐢宠鏁伴噺 + public string? dc_org { get; set; } // 璋冨嚭缁勭粐 + public string? dc_depot { get; set; } // 璋冨嚭浠撳簱 + public string? dr_org { get; set; } // 璋冨叆缁勭粐 + public string? dr_depot { get; set; } // 璋冨叆浠撳簱 + public string? dc_hz { get; set; } // 璋冨嚭璐т富 + public string? dr_hz { get; set; } // 璋冨叆璐т富 + public string? bz { get; set; } // 澶囨敞 + public string? erpid { get; set; } // 璋冩嫧鍑哄簱琛宨d + public string? eid { get; set; } // 璋冩嫧鍑哄簱澶磇d + } +} diff --git a/StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs b/StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs index fdd5138..0819536 100644 --- a/StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs +++ b/StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs @@ -211,5 +211,43 @@ ///</summary> [SugarColumn(ColumnName = "ERPID")] public string? Erpid { get; set; } + + /// <summary> + /// 璋冨嚭搴撳瓨缁勭粐 + ///</summary> + [SugarColumn(ColumnName = "DC_KC")] + public string? DcKc { get; set; } + /// <summary> + /// 璋冨叆搴撳瓨缁勭粐 + ///</summary> + [SugarColumn(ColumnName = "DR_KC")] + public string? DrKc { get; set; } + + + /// <summary> + /// 璋冨叆璐т富 + ///</summary> + [SugarColumn(ColumnName = "DR_HZ")] + public string? DrHz { get; set; } + /// <summary> + /// 璋冨叆浠撳簱 + ///</summary> + [SugarColumn(ColumnName = "DR_CK")] + public string? DrCk { get; set; } + /// <summary> + /// 璋冨嚭閮ㄩ棬 + ///</summary> + [SugarColumn(ColumnName = "DC_BM")] + public string? DcBm { get; set; } + /// <summary> + /// 璋冨叆閮ㄩ棬 + ///</summary> + [SugarColumn(ColumnName = "DR_BM")] + public string? DrBm { get; set; } + /// <summary> + /// MES绫诲瀷 + ///</summary> + [SugarColumn(ColumnName = "TYPE2")] + public string? Type2 { get; set; } } } diff --git a/StandardInterface/MES.Service/service/DbckaManager.cs b/StandardInterface/MES.Service/service/DbckaManager.cs index 5df6e9b..7bfdc3a 100644 --- a/StandardInterface/MES.Service/service/DbckaManager.cs +++ b/StandardInterface/MES.Service/service/DbckaManager.cs @@ -59,7 +59,8 @@ CreateDate = DateTime.Now, CreateBy = "System", DbStatus="鏈皟鎷�", - Status=1 + Status=1, + Type2 = "鍒嗗竷寮忚皟鎷ㄥ崟", }; // var single = base.GetSingle(it => it.Erpid == entity.Erpid); diff --git a/StandardInterface/MES.Service/service/WomcaaManager.cs b/StandardInterface/MES.Service/service/WomcaaManager.cs index 84b5753..37adb77 100644 --- a/StandardInterface/MES.Service/service/WomcaaManager.cs +++ b/StandardInterface/MES.Service/service/WomcaaManager.cs @@ -98,8 +98,30 @@ List<Womcab> mesWomcabs) { + //瀹氫箟杈撳叆鍙傛暟 + var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001); + // 瀹氫箟杈撳嚭鍙傛暟 + var outParam1 = new SugarParameter("c_Result", null, true); + var outParam2 = new SugarParameter("C_MSG", null, true); + // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼ + Db.Ado.ExecuteCommand( + "BEGIN PRC_UPDATE_DAA2(:P_WORK_NO,:c_Result,:C_MSG); END;", + inputParam1, outParam1, outParam2); + // 鑾峰彇杈撳嚭鍙傛暟鐨勫�� + var result = int.Parse((string)outParam1.Value); + var message = outParam2.Value == DBNull.Value + ? string.Empty + : (string)outParam2.Value; + if (result == 1) + { + //瀛樺偍杩囩▼澶辫触鍒欎簨鍔¤繘琛屽洖婊� + db.Ado.RollbackTran(); + throw new Exception(message); + } - + // 鎻愪氦浜嬪姟 + db.Ado.CommitTran(); + var decimals = mesWomcabs.Select(s => s.Id).ToArray(); @@ -119,29 +141,7 @@ if (update && insertOrUpdate) { - //瀹氫箟杈撳叆鍙傛暟 - var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001); - // 瀹氫箟杈撳嚭鍙傛暟 - var outParam1 = new SugarParameter("c_Result", null, true); - var outParam2 = new SugarParameter("C_MSG", null, true); - // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼ - Db.Ado.ExecuteCommand( - "BEGIN PRC_UPDATE_DAA2(:P_WORK_NO,:c_Result,:C_MSG); END;", - inputParam1, outParam1, outParam2); - // 鑾峰彇杈撳嚭鍙傛暟鐨勫�� - var result = int.Parse((string)outParam1.Value); - var message = outParam2.Value == DBNull.Value - ? string.Empty - : (string)outParam2.Value; - if (result == 1) - { - //瀛樺偍杩囩▼澶辫触鍒欎簨鍔¤繘琛屽洖婊� - db.Ado.RollbackTran(); - throw new Exception(message); - } - - // 鎻愪氦浜嬪姟 - db.Ado.CommitTran(); + return true; } throw new NotImplementedException("鏇存柊澶辫触"); diff --git a/StandardInterface/MES.Service/service/ZjdbManager.cs b/StandardInterface/MES.Service/service/ZjdbManager.cs new file mode 100644 index 0000000..bcf870e --- /dev/null +++ b/StandardInterface/MES.Service/service/ZjdbManager.cs @@ -0,0 +1,142 @@ +锘縰sing SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using MES.Service.DB; +using MES.Service.Dto.webApi; +using MES.Service.Modes; + +namespace MES.Service.service +{ + public class ERPZJDBManager : Repository<MesInvItemDbsq> + { + public bool SaveList(List<ERPZJDB> list) + { + var result = list.Select(Save).ToList(); + return result.All(b => b); + } + + public bool Save(ERPZJDB data) + { + var head = MapErpToMesHead(data.ERPZJDBA); + var details = MapErpDbckbToDbckb(data.ERPZJDBB); + + return UseTransaction(db => + { + switch (data.ERPZJDBA.type) + { + case "3": + return UpdateData(db, head, details) ? 1 : 0; + case "2": + case "4": + case "5": + return SaveOrUpdateData(db, head, details) ? 1 : 0; + default: + throw new NotImplementedException($"type娌℃湁 {data.ERPZJDBA.type} 杩欎釜绫诲瀷"); + } + }) > 0; + } + + private MesInvItemDbsq MapErpToMesHead(ERPZJDBA dto) + { + var entity = new MesInvItemDbsq + { + BillNo = dto.billno,//鍗曟嵁缂栫爜 + Djlx = dto.dj_lx, //鍗曟嵁绫诲瀷 + DbLx1 = dto.db_lx1, //璋冩嫧绫诲瀷 + DbFx = dto.db_fx, //璋冩嫧鏂瑰悜 + DbLx = dto.db_lx, //璋冩嫧绫诲瀷 + YwLx = dto.yw_lx, //涓氬姟绫诲瀷 + DjZt = dto.dj_zt, //鍗曟嵁鐘舵�� + SqBm = dto.sq_bm, //鐢宠閮ㄩ棬 + DcKc = dto.dc_kc, //璋冨嚭搴撳瓨缁勭粐 + DrKc = dto.dr_kc, //璋冨叆搴撳瓨缁勭粐 + DcHz = dto.dc_hz, //璋冨嚭璐т富 + DrHz = dto.dr_hz, //璋冨叆璐т富 + DrCk = dto.dr_ck, //璋冨叆浠撳簱 + DcBm = dto.dc_bm, //璋冨嚭閮ㄩ棬 + DrBm = dto.dr_bm, //璋冨叆閮ㄩ棬 + Type2 = "鐩存帴璋冩嫧鍗�", // + Remark = dto.bz, + Erpid = dto.erpid, + CreateDate = DateTime.Now, + CreateBy = "System", + DbStatus = "鏈皟鎷�", + Status = 1 + }; + + var single = Db.Queryable<MesInvItemDbsq>() + .Where(it => it.Erpid == entity.Erpid) + .First(); + if (single != null) + entity.Id = single.Id; + + return entity; + } + + private List<MesInvItemDbsqItems> MapErpDbckbToDbckb(List<ERPZJDBB> list) + { + var result = new List<MesInvItemDbsqItems>(); + + foreach (var dto in list) + { + var item = new MesInvItemDbsqItems + { + ItemId = Convert.ToDecimal(dto.itemid), + ItemUnit = Convert.ToDecimal(dto.unit), + SqNum = decimal.TryParse(dto.quantity, out var qty) ? qty : 0, + DcOrg = dto.dc_org, + DcDepot = dto.dc_depot, + DrOrg = dto.dr_org, + DrDepot = dto.dr_depot, + DcHz = dto.dc_hz, + DrHz = dto.dr_hz, + Remark = dto.bz, + Erpid = dto.erpid, + Eid = dto.eid, + }; + + var existing = Db.Queryable<MesInvItemDbsqItems>().Where(s => s.Erpid == item.Erpid).Single(); + if (existing != null) item.Id = existing.Id; + + result.Add(item); + } + + return result; + } + + private bool SaveOrUpdateData(SqlSugarScope db, MesInvItemDbsq head, List<MesInvItemDbsqItems> details) + { + if (head.Id != null) + base.DeleteById(head.Id); + + db.Deleteable<MesInvItemDbsqItems>() + .Where(d => d.Eid == head.Erpid) + .ExecuteCommand(); + + var insertedHead = db.Insertable(head) + .IgnoreColumns(true) + .ExecuteReturnIdentity(); + if (insertedHead <= 0) + throw new Exception("涓昏〃鎻掑叆澶辫触锛屾湭杩斿洖ID"); + + var success = db.Insertable(details) + .PageSize(10) + .IgnoreColumnsNull() + .ExecuteCommand() > 0; + + if (insertedHead >= 0 && success) return true; + throw new NotImplementedException("鎻掑叆鎴栨洿鏂板け璐�"); + } + + private bool UpdateData(SqlSugarScope db, MesInvItemDbsq head, List<MesInvItemDbsqItems> details) + { + var ids = details.Select(d => d.Id).ToArray(); + var deletedHead = base.DeleteById(head.Id); + var deletedDetails = db.Deleteable<MesInvItemDbsqItems>().In(ids).ExecuteCommand() > 0; + + if (deletedHead && deletedDetails) return true; + throw new NotImplementedException("鏇存柊澶辫触"); + } + } +} diff --git a/StandardInterface/MESApplication/Controllers/ZJdbController.cs b/StandardInterface/MESApplication/Controllers/ZJdbController.cs new file mode 100644 index 0000000..987dc88 --- /dev/null +++ b/StandardInterface/MESApplication/Controllers/ZJdbController.cs @@ -0,0 +1,103 @@ +锘縰sing Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Dynamic; +using MES.Service.service; +using MES.Service.Dto.webApi; +using MES.Service.util; +using Newtonsoft.Json; +using MES.Service.Modes; + +namespace MESApplication.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class ERPZJDBController : ControllerBase + { + private readonly ERPZJDBManager _manager = new(); // 杩欓噷瀵瑰簲鏂扮殑 Service + private readonly MessageCenterManager _messageManager = new(); + + private const string METHOD = "POST"; + private const string TableName = "ERPZJDB"; + private const string URL = "http://localhost:10054/api/ERPZJDB/"; + + /// <summary> + /// 淇濆瓨鍗曟潯璋冩嫧鍗� + /// </summary> + [HttpPost("Save")] + public ResponseResult Save([FromBody] ERPZJDB data) + { + var msg = new MessageCenter + { + TableName = TableName, + Url = URL + "Save", + Method = METHOD, + Data = JsonConvert.SerializeObject(data), + Status = 1, + CreateBy = "PL017", + Route = data.ERPZJDBA.billno // 娉ㄦ剰鍙� billno + }; + + try + { + dynamic resultInfos = new ExpandoObject(); + var success = _manager.Save(data); + resultInfos.tbBillList = success; + + msg.Result = success ? (short?)1 : (short?)0; + msg.DealWith = 1; + _messageManager.save(msg); + + return new ResponseResult { status = 0, message = "OK", data = resultInfos }; + } + catch (Exception ex) + { + msg.Result = 0; + msg.DealWith = 0; + msg.ResultData = ex.Message; + _messageManager.save(msg); + + return ResponseResult.ResponseError(ex); + } + } + + /// <summary> + /// 鎵归噺淇濆瓨璋冩嫧鍗� + /// </summary> + [HttpPost("SaveList")] + public ResponseResult SaveList([FromBody] List<ERPZJDB> dataList) + { + var msg = new MessageCenter + { + TableName = TableName, + Url = URL + "SaveList", + Method = METHOD, + Data = JsonConvert.SerializeObject(dataList), + Status = 1, + CreateBy = "PL017" + }; + + try + { + dynamic resultInfos = new ExpandoObject(); + var success = _manager.SaveList(dataList); + resultInfos.tbBillList = success; + + msg.Result = success ? (short?)1 : (short?)0; + msg.DealWith = 1; + _messageManager.save(msg); + + return new ResponseResult { status = 0, message = "OK", data = resultInfos }; + } + catch (Exception ex) + { + msg.Result = 0; + msg.DealWith = 0; + msg.ResultData = ex.Message; + _messageManager.save(msg); + + return ResponseResult.ResponseError(ex); + } + } + } +} -- Gitblit v1.9.3