| | |
| | | using SqlSugar; |
| | | using System.Net; |
| | | using System.Xml.Linq; |
| | | using System.Data; |
| | | using System.Data.Common; |
| | | |
| | | namespace MES.Service.service.QC; |
| | | |
| | |
| | | // result = "未检测" |
| | | // }).ToList(); |
| | | // } |
| | | public List<QsItemIpiItem> SetQSItems(string itemNo) |
| | | public List<QsItemIpiItem> SetQSItems(string itemNo, decimal? workQty = null) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | |
| | | |
| | | if (count <= 0) return []; |
| | | |
| | | return db |
| | | .Queryable<MesQualityStandard>() |
| | | .Where(b => b.QsType == "1" && b.ItemNo == itemNo).Select( |
| | | b => new QsItemIpiItem |
| | | // 如果没有传递工单数量,尝试从工单表中获取 |
| | | if (workQty == null || workQty <= 0) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"SJService.SetQSItems - itemNo: {itemNo}, workQty: {workQty}"); |
| | | |
| | | // 通过物料编码(Daa002)匹配工单 |
| | | var workOrder = db.Queryable<Womdaa>() |
| | | .Where(w => w.Daa002 == itemNo) |
| | | .OrderByDescending(w => w.Id) |
| | | .First(); |
| | | |
| | | if (workOrder != null) |
| | | { |
| | | workQty = workOrder.Daa008; // 工单数量 |
| | | System.Diagnostics.Debug.WriteLine($"Found work order by Daa002 (物料编码): {workOrder.Daa001}, Daa002: {workOrder.Daa002}, Daa003: {workOrder.Daa003}, workQty: {workQty}"); |
| | | } |
| | | else |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"No work order found for itemNo (物料编码): {itemNo}"); |
| | | |
| | | // 如果通过物料编码找不到,尝试通过产品名称匹配 |
| | | var workOrderByName = db.Queryable<Womdaa>() |
| | | .Where(w => w.Daa003.Contains(itemNo) || itemNo.Contains(w.Daa003)) |
| | | .OrderByDescending(w => w.Id) |
| | | .First(); |
| | | |
| | | if (workOrderByName != null) |
| | | { |
| | | ProjName = b.ProjName, |
| | | ItemMod = b.ItemMod, |
| | | InspectionMethod = b.InspectionMethod, |
| | | UsingInstruments = b.UsingInstruments, |
| | | LevelNum = SqlFunc.IsNull( |
| | | SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1), |
| | | b.InspectionLevel), |
| | | MaxValue = b.MaxValue, |
| | | StandardValue = b.StandardValue, |
| | | MinValue = b.MinValue, |
| | | Notes = b.Notes, |
| | | FcheckLevel = b.FcheckLevel, |
| | | FacLevel = b.FacLevel, |
| | | QsCode = b.QsCode, |
| | | QsName = b.QsName, |
| | | Picture = b.Picture, |
| | | Picturename = b.Picturename, |
| | | result = "未检测", |
| | | isCheck = 0 |
| | | }).ToList(); |
| | | workQty = workOrderByName.Daa008; // 工单数量 |
| | | System.Diagnostics.Debug.WriteLine($"Found work order by name: {workOrderByName.Daa001}, Daa002: {workOrderByName.Daa002}, Daa003: {workOrderByName.Daa003}, workQty: {workQty}"); |
| | | } |
| | | else |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"No work order found by name for itemNo: {itemNo}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 先获取基础数据 |
| | | var qualityStandards = db |
| | | .Queryable<MesQualityStandard>() |
| | | .Where(b => b.QsType == "1" && b.ItemNo == itemNo) |
| | | .ToList(); |
| | | |
| | | // 在内存中计算检验数量 |
| | | return qualityStandards.Select(b => new QsItemIpiItem |
| | | { |
| | | ProjName = b.ProjName, |
| | | ItemMod = b.ItemMod, |
| | | InspectionMethod = b.InspectionMethod, |
| | | UsingInstruments = b.UsingInstruments, |
| | | LevelNum = CalculateInspectionQuantity(b.LevelNum, b.InspectionLevel, workQty), |
| | | MaxValue = b.MaxValue, |
| | | StandardValue = b.StandardValue, |
| | | MinValue = b.MinValue, |
| | | Notes = b.Notes, |
| | | FcheckLevel = b.FcheckLevel, |
| | | FacLevel = b.FacLevel, |
| | | QsCode = b.QsCode, |
| | | QsName = b.QsName, |
| | | Picture = b.Picture, |
| | | Picturename = b.Picturename, |
| | | result = "未检测", |
| | | isCheck = 0 |
| | | }).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 计算检验数量:如果工单数量小于抽验数量,则检验数量为工单数量,否则为抽检数量 |
| | | /// </summary> |
| | | /// <param name="levelNum">每模多少个</param> |
| | | /// <param name="inspectionLevel">模数</param> |
| | | /// <param name="workQty">工单数量</param> |
| | | /// <returns>检验数量</returns> |
| | | private decimal? CalculateInspectionQuantity(decimal? levelNum, decimal? inspectionLevel, decimal? workQty) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"SJService.CalculateInspectionQuantity - INPUT: levelNum={levelNum}, inspectionLevel={inspectionLevel}, workQty={workQty}"); |
| | | |
| | | // 直接使用levelNum作为抽检数量,不再计算 |
| | | var samplingQuantity = levelNum ?? 1; |
| | | |
| | | System.Diagnostics.Debug.WriteLine($"SJService.CalculateInspectionQuantity - samplingQuantity (from levelNum): {samplingQuantity}"); |
| | | |
| | | // 如果没有工单数量,使用抽检数量 |
| | | if (workQty == null || workQty <= 0) |
| | | {return samplingQuantity; |
| | | } |
| | | |
| | | // 如果工单数量小于抽检数量,则检验数量为工单数量 |
| | | // 如果工单数量大于等于抽检数量,则检验数量为抽检数量 |
| | | var result = workQty < samplingQuantity ? workQty : samplingQuantity; |
| | | |
| | | System.Diagnostics.Debug.WriteLine($"SJService.CalculateInspectionQuantity - FINAL: workQty={workQty}, samplingQuantity={samplingQuantity}, result={result}"); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | |
| | | 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 => |