| | |
| | | using SqlSugar; |
| | | using System.Net; |
| | | using System.Xml.Linq; |
| | | using System.Data; |
| | | using System.Data.Common; |
| | | |
| | | namespace MES.Service.service.QC; |
| | | |
| | |
| | | var count = db.Queryable<QsItemIpiItemDetail>() |
| | | .Where(s => s.Pid == detail.Pid).Count(); |
| | | |
| | | |
| | | var result = 0; |
| | | |
| | | if (qsItemIpiItem.LevelNum != count) return 0; |
| | |
| | | return commit; |
| | | }); |
| | | |
| | | |
| | | //自动判定是否合格 |
| | | //获取检验单的检验项目理论个数 |
| | | var sum = db.Queryable<QsItemIpiItem>() |
| | |
| | | //实际个数等于理论个数时对检验单进行判定 |
| | | if (sum == icount) |
| | | { |
| | | result = 0; |
| | | |
| | | //获取这个检验单下的所有合格的检验结果 |
| | | passCount = db.Queryable<QsItemIpiItemDetail>() |
| | | .Where(s => s.Gid == detail.Gid && s.Fstand == "√").Count(); |
| | | |
| | | //合格的检验结果等于总检验数视为合格 |
| | | if (icount == passCount) result = 1; |
| | | |
| | | useTransactionWithOracle += SqlSugarHelper.UseTransactionWithOracle( |
| | | db => |
| | | { |
| | | return db.Updateable<QsItemIpiReq>() |
| | | .SetColumns(s => s.IsPass == result) |
| | | .SetColumns(s => s.StatusUser == detail.CreateBy) |
| | | .SetColumns(s => s.CompleteTime == DateTime.Now) |
| | | .Where(s => s.Id == detail.Gid) |
| | | .ExecuteCommand(); |
| | | }); |
| | | // 调用存储过程进行自动判定和提交 |
| | | CallSJAutoResultStoredProcedure(detail.Gid, detail.CreateBy); |
| | | } |
| | | |
| | | return useTransactionWithOracle; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 调用首检自动判定和提交存储过程 |
| | | /// </summary> |
| | | /// <param name="gid">首检主表ID</param> |
| | | /// <param name="createBy">操作人</param> |
| | | private void CallSJAutoResultStoredProcedure(decimal? gid, string createBy) |
| | | { |
| | | try |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | // 获取首检单信息 |
| | | var sjInfo = db.Queryable<QsItemIpiReq>() |
| | | .Where(s => s.Id == gid) |
| | | .First(); |
| | | |
| | | if (sjInfo == null) return; |
| | | |
| | | // 定义输出参数 |
| | | var outputResult = new SugarParameter("o_Result", null, |
| | | System.Data.DbType.Int32, ParameterDirection.Output, 4000); |
| | | |
| | | var outputMessage = new SugarParameter("o_Msg", null, |
| | | System.Data.DbType.String, ParameterDirection.Output, 4000); |
| | | |
| | | // 定义输入参数 |
| | | var parameters = new List<SugarParameter> |
| | | { |
| | | new("p_Gid", gid, System.Data.DbType.Decimal, ParameterDirection.Input), |
| | | new("p_Bill_No", sjInfo.BillNo, System.Data.DbType.String, ParameterDirection.Input), |
| | | new("p_User", createBy, System.Data.DbType.String, ParameterDirection.Input), |
| | | outputResult, |
| | | outputMessage |
| | | }; |
| | | |
| | | // 执行存储过程 |
| | | db.Ado.ExecuteCommand( |
| | | "BEGIN PRC_MES_SJ_AUTO_RESULT(:p_Gid, :p_Bill_No, :p_User, :o_Result, :o_Msg); END;", |
| | | parameters.ToArray()); |
| | | |
| | | // 获取输出参数的值 |
| | | var resultValue = outputResult.Value?.ToString(); |
| | | var messageValue = outputMessage.Value?.ToString(); |
| | | |
| | | if ("1".Equals(resultValue)) |
| | | { |
| | | throw new Exception($"首检自动判定失败: {messageValue}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录日志但不影响主流程 |
| | | Console.WriteLine($"首检自动判定存储过程调用失败: {ex.Message}"); |
| | | // 可以根据需要决定是否抛出异常 |
| | | // throw new Exception($"首检自动判定失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | public int UpdateQSItemDetail(QsItemIpiItemDetail detail) |
| | | { |
| | | var withOracle = SqlSugarHelper.UseTransactionWithOracle(db => |