From da95b0b41366074a2806b7c46447c0fac0f8b77a Mon Sep 17 00:00:00 2001 From: zjh <2207896513@qq.com> Date: 星期六, 02 八月 2025 18:06:04 +0800 Subject: [PATCH] 代码提交 --- StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs | 115 +++++++++++ StandardPda/MES.Service/Dto/service/AsnInfo.cs | 38 +++ StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs | 284 ++++++++++++++++++++++++++- StandardPda/MES.Service/Dto/service/MesMiddleBox.cs | 43 ++++ StandardPda/MES.Service/Dto/service/MesPalletBinding.cs | 50 +++++ StandardPda/MES.Service/DB/OracleSQLHelper.cs | 19 + StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs | 4 StandardPda/MES.Service/Dto/service/MesItemQtList.cs | 2 8 files changed, 535 insertions(+), 20 deletions(-) diff --git a/StandardPda/MES.Service/DB/OracleSQLHelper.cs b/StandardPda/MES.Service/DB/OracleSQLHelper.cs index 9a36dba..ae4fccc 100644 --- a/StandardPda/MES.Service/DB/OracleSQLHelper.cs +++ b/StandardPda/MES.Service/DB/OracleSQLHelper.cs @@ -228,4 +228,23 @@ // } // return result; // } + // 鎵撳紑杩炴帴骞跺紑鍚簨鍔� + public (OracleConnection, OracleTransaction) BeginTransaction() + { + var connection = new OracleConnection(_connectionString); + connection.Open(); + var transaction = connection.BeginTransaction(); + return (connection, transaction); + } + + // 鍏抽棴杩炴帴锛堟彁浜ゆ垨鍥炴粴鍚庣敤锛� + public void CloseConnection(OracleConnection connection) + { + if (connection != null && connection.State != ConnectionState.Closed) + { + connection.Close(); + connection.Dispose(); + } + } + } \ No newline at end of file diff --git a/StandardPda/MES.Service/Dto/service/AsnInfo.cs b/StandardPda/MES.Service/Dto/service/AsnInfo.cs index f21dd93..7a63b3c 100644 --- a/StandardPda/MES.Service/Dto/service/AsnInfo.cs +++ b/StandardPda/MES.Service/Dto/service/AsnInfo.cs @@ -19,6 +19,44 @@ /// </summary> public string snState { get; set; } + /// <summary> + /// 浜ф祴鐧婚檰鍙� + /// </summary> + public string loginId { get; set; } + /// <summary> + /// 澶辫触椤圭洰 + /// </summary> + public List<CcFailItems> failItems { get; set; } + } + /// <summary> + /// 浜ф祴SN澶辫触椤规槑缁嗚〃 + /// </summary> + public class CcFailItems + { + + /// <summary> + /// 涓嶈壇闂 + /// </summary> + public string DefectIssue { get; set; } + + /// <summary> + /// 鍒濇鍘熷洜 + /// </summary> + public string RootCause { get; set; } + + /// <summary> + /// 缁翠慨鏂规/鏂规硶 + /// </summary> + public string RepairMethod { get; set; } + + /// <summary> + /// 涓嶈壇鐗╂枡澶勭悊 + /// </summary> + public string MaterialHandling { get; set; } + + + } + } diff --git a/StandardPda/MES.Service/Dto/service/MesItemQtList.cs b/StandardPda/MES.Service/Dto/service/MesItemQtList.cs index 8200826..278ef10 100644 --- a/StandardPda/MES.Service/Dto/service/MesItemQtList.cs +++ b/StandardPda/MES.Service/Dto/service/MesItemQtList.cs @@ -7,7 +7,7 @@ /// <summary> /// 鐗╂枡缂栧彿 /// </summary> - public string Itemld { get; set; } + public string ItemId { get; set; } /// <summary> /// 璁″垝鏁伴噺 diff --git a/StandardPda/MES.Service/Dto/service/MesMiddleBox.cs b/StandardPda/MES.Service/Dto/service/MesMiddleBox.cs new file mode 100644 index 0000000..0f00368 --- /dev/null +++ b/StandardPda/MES.Service/Dto/service/MesMiddleBox.cs @@ -0,0 +1,43 @@ +锘縩amespace MES.Service.Dto.service +{ + /// <summary> + /// 涓鐮佽〃 + /// </summary> + public class MesMiddleBox + { + + /// <summary> + /// 绫诲瀷锛堟搷浣滐細A缁戝畾锛孎瑙g粦锛� + /// </summary> + public string type { get; set; } + /// <summary> + /// 涓鐮� + /// </summary> + public string MediumBoxCode { get; set; } + + /// <summary> + /// 鐧诲綍鍙� + /// </summary> + public string LoginId { get; set; } + /// <summary> + /// sn鍒楄〃 + /// </summary> + public List<snList> SnList { get; set; } + + public class snList + { + /// <summary> + /// SN鍙� + /// </summary> + public string SnNo { get; set; } + + /// <summary> + /// 宸ュ崟鍗曞彿 + /// </summary> + public string TicketNo { get; set; } + } + + } + + +} diff --git a/StandardPda/MES.Service/Dto/service/MesPalletBinding.cs b/StandardPda/MES.Service/Dto/service/MesPalletBinding.cs new file mode 100644 index 0000000..1ff16dc --- /dev/null +++ b/StandardPda/MES.Service/Dto/service/MesPalletBinding.cs @@ -0,0 +1,50 @@ +锘縩amespace MES.Service.Dto.service +{ + /// <summary> + /// 鏍堟澘缁戝畾琛� + /// </summary> + public class MesPalletBinding + { + + /// <summary> + /// 鎿嶄綔锛欰缁戝畾锛孎瑙g粦 + /// </summary> + public string Type { get; set; } + /// <summary> + /// 鏍堟澘鐮� + /// </summary> + public string StackCode { get; set; } + + /// <summary> + /// 鐧诲綍鍙� + /// </summary> + public string LoginId { get; set; } + + /// <summary> + /// sn鍒楄〃 + /// </summary> + public List<snList1> SnList { get; set; } + public class snList1 + { + /// <summary> + /// SN鍙� + /// </summary> + public string SnNo { get; set; } + + /// <summary> + /// 宸ュ崟鍗曞彿 + /// </summary> + public string TicketNo { get; set; } + + /// <summary> + /// 涓鐮� + /// </summary> + public string MediumBoxCode { get; set; } + } + + + } + + + +} diff --git a/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs b/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs index e1c8217..958c3ec 100644 --- a/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs +++ b/StandardPda/MES.Service/service/Warehouse/MesItemQtManager.cs @@ -247,7 +247,7 @@ var itemIdLinkU9 = Db.Queryable<MesLinkU9>() .Where(s => s.TableType == "MES_ITEMS" - && s.U9Id == ItemQtRKList.Itemld).First(); + && s.U9Id == ItemQtRKList.ItemId).First(); if (itemIdLinkU9 == null) { @@ -260,7 +260,7 @@ if (mesItems == null) { - throw new NotImplementedException("[" + ItemQtRKList.Itemld + + throw new NotImplementedException("[" + ItemQtRKList.ItemId + "]鐗╂枡涓嶅瓨鍦紝璇峰悓姝ョ粰MES"); } var mesDepot = ""; diff --git a/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs b/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs index 88d6769..b0d1277 100644 --- a/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs +++ b/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs @@ -2,12 +2,13 @@ using MES.Service.DB; using MES.Service.Dto.service; using MES.Service.Modes; +using MES.Service.service.BasicData; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Data; namespace MES.Service.service.Warehouse { @@ -26,17 +27,24 @@ // join MES_LINE b on A.LINEID=b.ID // left join WOMDAA C on C.DAA015=B.LINE_NO // left join mes_items s on s.id = C.daa002 - // where LOGINID='" + id+ "' and DAA018='宸插紑宸�' order by DAA016 asc"; - + // where LOGINID='" + id + "' and DAA018='宸插紑宸�' order by DAA016 asc"; //鏀逛负鎸夌珯浣嶅彿鍙嶆煡浜х嚎锛屽啀閫氳繃浜х嚎鏌ュ嚭宸ュ崟淇℃伅 - var sql1 = @"select DAA001 tickeNo,s.ITEM_NO itemNo,s.ITEM_NAME itemName,s.ITEM_MODEL itemModel,DAA008 plannedNum from MESLINE_LIKE_CCLOGIN A - left join MESLINE_LIKE_CCLOGIN_WORKS A1 on A.id=a1.LOGINID - join MES_LINE b on A.LINEID=b.ID - left join WOMDAA C on C.DAA015=B.LINE_NO - left join mes_items s on s.id = C.daa002 - where WORKSNO='" + id + "' and DAA018='宸插紑宸�' order by DAA016 asc"; + //var sql1 = @"select DAA001 tickeNo,s.ITEM_NO itemNo,s.ITEM_NAME itemName,s.ITEM_MODEL itemModel,DAA008 plannedNum from MESLINE_LIKE_CCLOGIN A + // left join MESLINE_LIKE_CCLOGIN_WORKS A1 on A.id=a1.LOGINID + // join MES_LINE b on A.LINEID=b.ID + // left join WOMDAA C on C.DAA015=B.LINE_NO + // left join mes_items s on s.id = C.daa002 + // where WORKSNO='" + id + "' and DAA018='宸插紑宸�' order by DAA016 asc"; + + //鍙栫洿鎺ュ叧鑱旂嚎浣撶殑浜ф祴鐧诲綍鍙锋暟鎹紝鍘诲彇鑾峰彇宸ュ崟 + var sql1 = "select DAA001 tickeNo,s.ITEM_NO itemNo,s.ITEM_NAME itemName,s.ITEM_MODEL itemModel,DAA008 plannedNum from " + + "MESLINE_LIKE_CCLOGIN_WORKS A1" + + " join MES_LINE b on A1.LOGINID=b.ID" + + " left join WOMDAA C on C.DAA015=B.LINE_NO" + + " left join mes_items s on s.id = C.daa002" + + " where WORKSNO='" + id + "' and DAA018='宸插紑宸�' order by DAA016 asc"; return SQLHelper.ExecuteQuery(sql1); } @@ -46,19 +54,265 @@ /// </summary> /// <param name="id"></param> /// <returns></returns> + //public bool AddAsnInfo(AsnInfo asnInfo) + //{ + // OracleSQLHelper SQLHelper = new(); + // //璁板綍浜ф祴杩囩珯淇℃伅 + // var sql1 = @"INSERT INTO MES_SN_STATUS_DETAILS (ID,TICKET_NO,SN_NO,WORKSTATION_NO,SN_STATE,LOGIN_ID) VALUES (SEQ_MES_SN_STATUS_DETAILS_ID.NEXTVAL,'" + asnInfo.tickeNo+ "','"+ asnInfo.snNo+ "','"+ asnInfo.workstationNo+ "','"+ asnInfo.snState+ "','"+asnInfo.loginId+"')"; + // bool result = true; + // int i= SQLHelper.ExecuteNonQuery(sql1); + // //涓昏〃淇℃伅鎻掑叆鎴愬姛锛岀户缁彃鍏ラ」鐩� + // if (i > 0) { + // //鍒ゆ柇椤圭洰鏄惁涓虹┖锛屼负绌轰笉鎻掑叆 + // if (asnInfo.failItems.Count>0) + // { + // //鎻掑叆閫昏緫 + + // } + // else + // { + // result = true; + // } + + + // } else { result = false; } + + // return result; + //} public bool AddAsnInfo(AsnInfo asnInfo) { - OracleSQLHelper SQLHelper = new(); - //璁板綍浜ф祴杩囩珯淇℃伅 - var sql1 = @"INSERT INTO MES_SN_STATUS_DETAILS (ID,TICKET_NO,SN_NO,WORKSTATION_NO,SN_STATE) VALUES (SEQ_MES_SN_STATUS_DETAILS_ID.NEXTVAL,'"+ asnInfo.tickeNo+ "','"+ asnInfo.snNo+ "','"+ asnInfo.workstationNo+ "','"+ asnInfo.snState+ "')"; + var sqlHelper = new OracleSQLHelper(); bool result = true; - int i= SQLHelper.ExecuteNonQuery(sql1); - if (i > 0) {result = true;} else { result = false; } - + // + var (connection, transaction) = sqlHelper.BeginTransaction(); + + try + { + // 涓昏〃鎻掑叆 + var sql1 = $@"INSERT INTO MES_SN_STATUS_DETAILS + (ID, TICKET_NO, SN_NO, WORKSTATION_NO, SN_STATE, LOGIN_ID) + VALUES (SEQ_MES_SN_STATUS_DETAILS_ID.NEXTVAL, + '{asnInfo.tickeNo}', + '{asnInfo.snNo}', + '{asnInfo.workstationNo}', + '{asnInfo.snState}', + '{asnInfo.loginId}')"; + + int i = sqlHelper.ExecuteNonQueryWithTransaction(connection, transaction, sql1); + + if (i > 0 && asnInfo.failItems?.Count > 0) + { + foreach (var item in asnInfo.failItems) + { + var sql2 = $@"INSERT INTO CC_FAIL_ITEMS + (ID, MID, DEFECT_ISSUE, ROOT_CAUSE, REPAIR_METHOD, MATERIAL_HANDLING, CREATE_DATE, CREATED_BY) + VALUES (SEQ_CC_FAIL_ITEMS.NEXTVAL, + SEQ_MES_SN_STATUS_DETAILS_ID.CURRVAL, + '{item.DefectIssue}', + '{item.RootCause}', + '{item.RepairMethod}', + '{item.MaterialHandling}', + SYSDATE, + '{asnInfo.loginId}')"; + + sqlHelper.ExecuteNonQueryWithTransaction(connection, transaction, sql2); + } + } + + // 鍏ㄩ儴鎴愬姛鎻愪氦 + transaction.Commit(); + } + catch (Exception ex) + { + transaction.Rollback(); + result = false; + throw; // 寤鸿璁板綍鏃ュ織 + } + finally + { + sqlHelper.CloseConnection(connection); + } + return result; } + /// <summary> + /// 璁剧疆涓鐮� + /// </summary> + /// <param name="mesMiddleBox"></param> + /// <returns></returns> + public string[] SetMediumBoxCode(MesMiddleBox mesMiddleBox) + { + var sqlHelper = new OracleSQLHelper(); + string[] msg= new string[2]; + msg[0] = "true"; + // + var (connection, transaction) = sqlHelper.BeginTransaction(); + try + { + if (mesMiddleBox.type.ToUpper() =="A") { + if (mesMiddleBox.SnList.Count > 0) + { + string sql1 = "select count(*) count from MES_MIDDLE_BOX where MEDIUMBOXCODE='"+ mesMiddleBox.MediumBoxCode + "'"; + DataTable data= sqlHelper.ExecuteQuery(sql1); + if (data.Rows[0]["COUNT"].ToString() != "0") { + msg[0] = "false"; + msg[1] = "璇ヤ腑绠辩爜宸茬粡缁戝畾SN鏁版嵁锛屽闇�鍐嶆缁戝畾璇峰厛瑙g粦锛佷腑绠辩爜锛�" + mesMiddleBox.MediumBoxCode; + transaction.Rollback(); + + return msg; + } + foreach (var item in mesMiddleBox.SnList) + { + var sql2 = $@"INSERT INTO MES_MIDDLE_BOX + ( + ID, + MEDIUMBOXCODE, + LOGIN_ID, + SN_NO, + TICKET_NO, + CREATE_DATE, + CREATED_BY + ) + VALUES + ( + SEQ_MES_MIDDLE_BOX_ID.NEXTVAL, -- 搴忓垪鐢熸垚涓婚敭 + '{mesMiddleBox.MediumBoxCode.ToString()}', -- 涓鐮� + '{mesMiddleBox.LoginId}', -- 鐧诲綍鍙� + '{item.SnNo}', -- SN鍙� + '{item.TicketNo}', -- 宸ュ崟鍗曞彿 + SYSDATE, -- 鍒涘缓鏃堕棿 + '{mesMiddleBox.LoginId}' -- 鍒涘缓浜� + ) + "; + + sqlHelper.ExecuteNonQueryWithTransaction(connection, transaction, sql2); + } + } + else + { + msg[0] = "false"; + } + } else if(mesMiddleBox.type.ToUpper() == "F") { + //瑙g粦锛屾牴鎹腑绠辩爜鍏ㄩ儴鍒犻櫎 + var sql2 = $@"delete MES_MIDDLE_BOX where MEDIUMBOXCODE='{mesMiddleBox.MediumBoxCode}'"; + + sqlHelper.ExecuteNonQueryWithTransaction(connection, transaction, sql2); + } + else + { + msg[1] = "SN鏄庣粏涓虹┖锛岃纭锛�"; + msg[0] = "false"; + } + + + // 鍏ㄩ儴鎴愬姛鎻愪氦 + transaction.Commit(); + } + catch (Exception ex) + { + transaction.Rollback(); + msg[0] = "false"; + msg[1] = ex.Message; + throw; // 寤鸿璁板綍鏃ュ織 + } + finally + { + sqlHelper.CloseConnection(connection); + } + + return msg; + } + + + public string[] SetStackCode(MesPalletBinding mesPalletBinding) + { + var sqlHelper = new OracleSQLHelper(); + string[] msg = new string[2]; + msg[0] = "true"; + // + var (connection, transaction) = sqlHelper.BeginTransaction(); + + try + { + //缁戝畾 + if (mesPalletBinding.Type.ToUpper() == "A") { + if (mesPalletBinding.SnList.Count > 0) + { + string sql1 = "select count(*) count from MES_PALLET_BINDING where STACKCODE='" + mesPalletBinding.StackCode + "'"; + DataTable data = sqlHelper.ExecuteQuery(sql1); + if (data.Rows[0]["COUNT"].ToString() != "0") + { + msg[0] = "false"; + msg[1] = "璇ユ爤鏉跨爜宸茬粡缁戝畾SN鏁版嵁锛屽闇�鍐嶆缁戝畾璇峰厛瑙g粦锛佹爤鏉跨爜锛�" + mesPalletBinding.StackCode; + transaction.Rollback(); + + return msg; + } + foreach (var item in mesPalletBinding.SnList) + { + var sql2 = $@"INSERT INTO MES_PALLET_BINDING + ( + ID, + STACKCODE, + LOGIN_ID, + SN_NO, + TICKET_NO, + MEDIUMBOXCODE, + CREATE_DATE, + CREATED_BY + ) + VALUES + ( + SEQ_MES_PALLET_BINDING_ID.NEXTVAL, -- 搴忓垪鐢熸垚涓婚敭 + '{mesPalletBinding.StackCode}', -- 鏍堟澘鐮� + '{mesPalletBinding.LoginId}', -- 鐧诲綍鍙� + '{item.SnNo}', -- SN鍙� + '{item.TicketNo}', -- 宸ュ崟鍗曞彿 + '{item.MediumBoxCode}', -- 涓鐮� + SYSDATE, -- 鍒涘缓鏃堕棿 + '{mesPalletBinding.LoginId}' -- 鍒涘缓浜� + ) + + "; + + sqlHelper.ExecuteNonQueryWithTransaction(connection, transaction, sql2); + } + } + else + { + msg[1] = "SN鏄庣粏涓虹┖锛岃纭锛�"; + msg[0] = "false"; + } + } + //瑙g粦 + else if(mesPalletBinding.Type.ToUpper() == "F") + { + //瑙g粦锛屾牴鎹腑绠辩爜鍏ㄩ儴鍒犻櫎 + var sql2 = $@"delete MES_PALLET_BINDING where STACKCODE='" + mesPalletBinding.StackCode + "'"; + + sqlHelper.ExecuteNonQueryWithTransaction(connection, transaction, sql2); + } + + + // 鍏ㄩ儴鎴愬姛鎻愪氦 + transaction.Commit(); + } + catch (Exception ex) + { + transaction.Rollback(); + msg[0] = "false"; + msg[1] = ex.Message; + throw; // 寤鸿璁板綍鏃ュ織 + } + finally + { + sqlHelper.CloseConnection(connection); + } + + return msg; + } } } diff --git a/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs b/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs index c0f541e..dfdcdd9 100644 --- a/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs +++ b/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs @@ -1,4 +1,5 @@ -锘縰sing MES.Service.Dto.service; +锘縰sing AngleSharp.Text; +using MES.Service.Dto.service; using MES.Service.Modes; using MES.Service.service; using MES.Service.service.Warehouse; @@ -18,7 +19,7 @@ private readonly WomdaaManager m = new(); private readonly MessageCenterManager _manager = new(); - + private readonly string METHOD = "POST"; private readonly string TableName = "womdaa"; @@ -111,6 +112,116 @@ } } + /// <summary> + ///璁剧疆涓鐮� + /// </summary> + /// <returns></returns> + [HttpPost("SetMediumBoxCode")] + public ResponseResult SetMediumBoxCode(MesMiddleBox MesMiddleBox) + { + var entity = new MessageCenter(); + entity.TableName = TableName; + entity.Url = URL + "SetMediumBoxCode"; + entity.Method = METHOD; + entity.Data = Newtonsoft.Json.JsonConvert.SerializeObject(MesMiddleBox); + entity.Status = 1; + entity.CreateBy = "PL017"; + try + { + dynamic resultInfos = new ExpandoObject(); + var result = m.SetMediumBoxCode(MesMiddleBox); + resultInfos.tbBillList = result; + + entity.Result = 0; + if (result[0].ToBoolean()) entity.Result = 1; + entity.DealWith = 1; + _manager.save(entity); + + if (result[0].ToBoolean()) + { + return new ResponseResult + { + status = 0, + message = "OK", + data = resultInfos + }; + } + else { + return new ResponseResult + { + status = 1, + message = result[1], + data = resultInfos + }; + } + + } + catch (Exception ex) + { + entity.Result = 0; + entity.DealWith = 0; + entity.ResultData = ex.Message; + _manager.save(entity); + + return ResponseResult.ResponseError(ex); + } + } + + /// <summary> + ///璁剧疆鏍堟澘鐮� + /// </summary> + /// <returns></returns> + [HttpPost("SetStackCode")] + public ResponseResult SetStackCode(MesPalletBinding mesPalletBinding) + { + var entity = new MessageCenter(); + entity.TableName = TableName; + entity.Url = URL + "SetStackCode"; + entity.Method = METHOD; + entity.Data = Newtonsoft.Json.JsonConvert.SerializeObject(mesPalletBinding); + entity.Status = 1; + entity.CreateBy = "PL017"; + try + { + dynamic resultInfos = new ExpandoObject(); + var result = m.SetStackCode(mesPalletBinding); + resultInfos.tbBillList = result; + + entity.Result = 0; + if (result[0].ToBoolean()) entity.Result = 1; + entity.DealWith = 1; + _manager.save(entity); + + if (result[0].ToBoolean()) + { + return new ResponseResult + { + status = 0, + message = "OK", + data = resultInfos + }; + } + else + { + return new ResponseResult + { + status = 1, + message = result[1], + data = resultInfos + }; + } + } + catch (Exception ex) + { + entity.Result = 0; + entity.DealWith = 0; + entity.ResultData = ex.Message; + _manager.save(entity); + + return ResponseResult.ResponseError(ex); + } + } + } } -- Gitblit v1.9.3