From c8ec9ec6d9d149eaac6ad78bedd980c3be1c3b5f Mon Sep 17 00:00:00 2001 From: zjh <2207896513@qq.com> Date: 星期六, 23 八月 2025 14:58:49 +0800 Subject: [PATCH] 产测解绑sn代码提交 --- StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs | 53 +++++++++++++++++ StandardPda/MES.Service/Dto/service/UnbindAsnInfoDto.cs | 29 +++++++++ StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs | 87 +++++++++++++++++++++++++++++ StandardPda/MES.Service/DB/OracleSQLHelper.cs | 11 +++ 4 files changed, 180 insertions(+), 0 deletions(-) diff --git a/StandardPda/MES.Service/DB/OracleSQLHelper.cs b/StandardPda/MES.Service/DB/OracleSQLHelper.cs index fea808c..151d31a 100644 --- a/StandardPda/MES.Service/DB/OracleSQLHelper.cs +++ b/StandardPda/MES.Service/DB/OracleSQLHelper.cs @@ -65,6 +65,17 @@ return command.ExecuteNonQuery(); } } + public int ExecuteNonQueryWithTransaction(string sql, OracleParameter[] parameters, OracleConnection connection, OracleTransaction transaction) + { + using (var cmd = new OracleCommand(sql, connection)) + { + cmd.Transaction = transaction; + if (parameters != null) + cmd.Parameters.AddRange(parameters); + + return cmd.ExecuteNonQuery(); + } + } public int ExecuteTransaction(string query1) { diff --git a/StandardPda/MES.Service/Dto/service/UnbindAsnInfoDto.cs b/StandardPda/MES.Service/Dto/service/UnbindAsnInfoDto.cs new file mode 100644 index 0000000..78147a0 --- /dev/null +++ b/StandardPda/MES.Service/Dto/service/UnbindAsnInfoDto.cs @@ -0,0 +1,29 @@ +锘縩amespace MES.Service.Dto.service +{ + public class UnbindAsnInfoDto + { + /// <summary> + /// 鐧诲綍鍙� + /// </summary> + public string loginId { get; set; } + /// <summary> + /// 鎿嶄綔绫诲瀷: 0=瑙g粦, 1=鎾ら攢瑙g粦 + /// </summary> + public int? ActionType { get; set; }= 0; + + public List<SnList> snList { get; set; } + public class SnList + { + /// <summary> + /// 宸ュ崟鍗曞彿 + /// </summary> + public string tickeNo { get; set; } + /// <summary> + /// sn鍙� + /// </summary> + public string snNo { get; set; } + + } + } + +} diff --git a/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs b/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs index b389e65..920f28d 100644 --- a/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs +++ b/StandardPda/MES.Service/service/Warehouse/WomdaaManager.cs @@ -3,6 +3,7 @@ using MES.Service.Dto.service; using MES.Service.Modes; using MES.Service.service.BasicData; +using Oracle.ManagedDataAccess.Client; using System; using System.Collections.Generic; using System.Data; @@ -465,5 +466,91 @@ } + /// <summary> + /// 澶勭悊瑙g粦 / 鎾ら攢瑙g粦 + /// </summary> + public bool ProcessSn(UnbindAsnInfoDto dto) + { + if (dto == null || dto.snList == null || dto.snList.Count == 0) + throw new ArgumentException("杈撳叆鍙傛暟鏃犳晥"); + + var sqlHelper = new OracleSQLHelper(); + bool result = true; + var (connection, transaction) = sqlHelper.BeginTransaction(); + + try + { + foreach (var sn in dto.snList) + { + if (dto.ActionType == 0) // 瑙g粦 + { + string sql = @" + UPDATE MES_SN_STATUS_DETAILS + SET IS_UNBIND = 1, + UNBIND_DATE = SYSDATE, + UNBIND_USER = :LoginId + WHERE TICKET_NO = :TicketNo + AND SN_NO = :SnNo + AND NVL(IS_UNBIND, 0) = 0"; + + var parameters = new[] + { + new OracleParameter(":LoginId", dto.loginId), + new OracleParameter(":TicketNo", sn.tickeNo), + new OracleParameter(":SnNo", sn.snNo) + }; + + int rows = sqlHelper.ExecuteNonQueryWithTransaction(sql, parameters, connection, transaction); + if (rows == 0) + { + throw new Exception($"瑙g粦澶辫触: 宸ュ崟[{sn.tickeNo}], SN[{sn.snNo}] 鏈壘鍒板彲瑙g粦璁板綍鎴栧凡瑙g粦锛�"); + } + } + else if (dto.ActionType == 1) // 鎾ら攢瑙g粦 + { + string sql = @" + UPDATE MES_SN_STATUS_DETAILS + SET IS_UNBIND = 0, + UNBIND_DATE = NULL, + UNBIND_USER = NULL + WHERE TICKET_NO = :TicketNo + AND SN_NO = :SnNo + AND NVL(IS_UNBIND, 0) = 1"; + + var parameters = new[] + { + new OracleParameter(":TicketNo", sn.tickeNo), + new OracleParameter(":SnNo", sn.snNo) + }; + + int rows = sqlHelper.ExecuteNonQueryWithTransaction(sql, parameters, connection, transaction); + if (rows == 0) + { + throw new Exception($"鎾ら攢瑙g粦澶辫触: 宸ュ崟[{sn.tickeNo}], SN[{sn.snNo}] 鏈壘鍒板凡瑙g粦璁板綍锛�"); + } + } + else + { + throw new Exception("鏃犳晥鐨勬搷浣滅被鍨嬶紒鍙兘鏄� 0=瑙g粦 鎴� 1=鎾ら攢瑙g粦"); + } + } + + transaction.Commit(); + } + catch (Exception ex) + { + transaction.Rollback(); + result = false; + // 寤鸿杩欓噷鍐欐棩蹇� ex.Message + throw; + } + finally + { + connection.Close(); + } + + return result; + } + } } diff --git a/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs b/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs index b01caf4..e8f4f52 100644 --- a/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs +++ b/StandardPda/MESApplication/Controllers/Warehouse/womdaaController.cs @@ -224,6 +224,59 @@ } } + /// <summary> + ///瑙g粦sn鐮� + /// </summary> + /// <returns></returns> + [HttpPost("UnbindAsnInfo")] + public ResponseResult UnbindAsnInfo(UnbindAsnInfoDto unbindAsnInfoDto) + { + var entity = new MessageCenter(); + entity.TableName = TableName; + entity.Url = URL + "SetStackCode"; + entity.Method = METHOD; + entity.Data = Newtonsoft.Json.JsonConvert.SerializeObject(unbindAsnInfoDto); + entity.Status = 1; + entity.CreateBy = "PL017"; + try + { + dynamic resultInfos = new ExpandoObject(); + bool result = m.ProcessSn(unbindAsnInfoDto); + resultInfos.tbBillList = result; + entity.Result = 0; + if (result) entity.Result = 1; + entity.DealWith = 1; + _manager.save(entity); + + if (result) + { + return new ResponseResult + { + status = 0, + message = "OK", + data = resultInfos + }; + } + else + { + return new ResponseResult + { + status = 1, + message = result.ToString(), + 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