From 3b3d2378bd52268dad426c70b853473eccee3b87 Mon Sep 17 00:00:00 2001 From: xwt <2740516069@qq.com> Date: 星期一, 15 九月 2025 09:24:03 +0800 Subject: [PATCH] 首检穴模数 --- StandardInterface/MES.Service/service/QC/SJService.cs | 248 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 236 insertions(+), 12 deletions(-) diff --git a/StandardInterface/MES.Service/service/QC/SJService.cs b/StandardInterface/MES.Service/service/QC/SJService.cs index ed68577..e53d43e 100644 --- a/StandardInterface/MES.Service/service/QC/SJService.cs +++ b/StandardInterface/MES.Service/service/QC/SJService.cs @@ -3,6 +3,7 @@ using MES.Service.Modes; using MES.Service.util; using SqlSugar; +using System.Data; namespace MES.Service.service.QC; @@ -30,11 +31,11 @@ number = no.ToString().PadLeft(4, '0'); } - return "SJN" + date.Replace("-", "") + number; + return "SJ" + date.Replace("-", "") + number; } //鑾峰彇鎵�鏈夋暟鎹垎椤� - public List<SJPageResult> getPage(SJPageResult queryObj) + public (List<SJPageResult> item, int TotalCount) getPage(SJPageResult queryObj) { var db = SqlSugarHelper.GetInstance(); @@ -43,7 +44,7 @@ if (StringUtil.IsNotNullOrEmpty(queryObj.StatusUser)) lineNo = _baseService.getUserLineNo(queryObj.StatusUser); - var data = db.Queryable<SJPageResult>() + var query = db.Queryable<SJPageResult>() .WhereIF(lineNo != null && lineNo.Length > 0, a => lineNo.Contains(a.line)) .WhereIF(queryObj.Id != null, a => a.Id == queryObj.Id) @@ -52,15 +53,60 @@ .WhereIF( StringUtil.IsNotNullOrEmpty(queryObj.Result) && "鏈畬鎴�".Equals(queryObj.Result), - a => a.Result == queryObj.Result) + a => a.Fsubmit == 0) .WhereIF( StringUtil.IsNotNullOrEmpty(queryObj.Result) && !"鏈畬鎴�".Equals(queryObj.Result), - a => a.Result != "鏈畬鎴�") - .OrderBy(a => a.BillNo, OrderByType.Desc) - .ToPageList(queryObj.PageIndex, queryObj.Limit); + a => a.Fsubmit == 1); - return data; + // 鏂板鐨勫姩鎬佹悳绱㈤�昏緫 + if (!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField)) + { + switch (queryObj.searchField) + { + case "daa001": // 宸ュ崟 + query = query.Where(x => x.daa001.Contains(queryObj.SearchValue)); + break; + case "billNo": // 妫�楠屽崟鍙� + query = query.Where(x => x.BillNo.Contains(queryObj.SearchValue)); + break; + case "line": // 浜х嚎 + query = query.Where(x => x.line.Contains(queryObj.SearchValue)); + break; + case "itemNo": // 鐗╂枡缂栫爜 + query = query.Where(x => x.ItemNo.Contains(queryObj.SearchValue)); + break; + case "daa003": // 鐗╂枡鍚嶇О + query = query.Where(x => x.Daa003.Contains(queryObj.SearchValue)); + break; + default: + // 濡傛灉娌℃湁鎸囧畾瀛楁鎴栧瓧娈典笉鍖归厤锛屼娇鐢ㄥ師鏈夌殑妯$硦鏌ヨ閫昏緫浣滀负鍏滃簳鏂规 + query = query.Where(x => + x.ItemNo.Contains(queryObj.SearchValue) || + x.Daa003.Contains(queryObj.SearchValue) || + x.daa001.Contains(queryObj.SearchValue) || + x.BillNo.Contains(queryObj.SearchValue) || + x.line.Contains(queryObj.SearchValue)); + break; + } + } + // 涓轰簡鍏煎鏃х増鏈紝濡傛灉娌℃湁浼犻�� searchField锛屼娇鐢ㄥ師鏉ョ殑鏌ヨ閫昏緫 + else if (string.IsNullOrEmpty(queryObj.searchField) && !string.IsNullOrEmpty(queryObj.SearchValue)) + { + // 淇濇寔鍘熸湁鐨勫瀛楁妯$硦鏌ヨ閫昏緫 + query = query.Where(x => + x.ItemNo.Contains(queryObj.SearchValue) || + x.Daa003.Contains(queryObj.SearchValue) || + x.daa001.Contains(queryObj.SearchValue) || + x.BillNo.Contains(queryObj.SearchValue) || + x.line.Contains(queryObj.SearchValue)); + } + + var totalCount = 0; + var data = query.OrderBy(a => a.BillNo, OrderByType.Desc) + .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount); + + return (data, totalCount); } @@ -132,10 +178,38 @@ public List<QsItemIpiItem> getQSItems(decimal? pid, decimal? id) { var db = SqlSugarHelper.GetInstance(); + + // 浣跨敤JOIN鏌ヨ鑾峰彇瀛愯〃鏁版嵁鍜屼富琛ㄧ殑MNUM銆丏NUM瀛楁 var qsItemIpiItems = db - .Queryable<QsItemIpiItem>() - .WhereIF(pid > 0, a => a.Pid == pid) - .WhereIF(id > 0, a => a.Id == id).ToList(); + .Queryable<QsItemIpiItem, QsItemIpiReq>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id)) + .WhereIF(pid > 0, (a, b) => a.Pid == pid) + .WhereIF(id > 0, (a, b) => a.Id == id) + .Select((a, b) => new QsItemIpiItem + { + Id = a.Id, + Pid = a.Pid, + ProjName = a.ProjName, + ItemMod = a.ItemMod, + InspectionMethod = a.InspectionMethod, + UsingInstruments = a.UsingInstruments, + LevelNum = a.LevelNum, + MaxValue = a.MaxValue, + StandardValue = a.StandardValue, + MinValue = a.MinValue, + Notes = a.Notes, + FcheckLevel = a.FcheckLevel, + FacLevel = a.FacLevel, + QsCode = a.QsCode, + QsName = a.QsName, + Picture = a.Picture, + Picturename = a.Picturename, + IsPass = a.IsPass, + ItemId = a.ItemId, + Mnum = b.Mnum, // 浠庝富琛ㄨ幏鍙朚NUM + Dnum = b.Dnum, // 浠庝富琛ㄨ幏鍙朌NUM + Snum = a.Snum, // 閫佹鎵规暟 + Remarks = a.Remarks + }).ToList(); var array = qsItemIpiItems.Select(s => s.Id).ToArray(); var qsItemIpiItemDetails = db.Queryable<QsItemIpiItemDetail>() @@ -182,6 +256,16 @@ //鎺掑簭锛屾湭瀹屾垚鐨勬帓鍦ㄥ墠闈� qsItemIpiItems = qsItemIpiItems.OrderBy(s => s.isCheck).ToList(); + // 涓烘瘡涓楠岄」鐩敓鎴愮┐鍙蜂俊鎭� + qsItemIpiItems.ForEach(item => + { + if (item.Mnum > 0 && item.Snum > 0) + { + // 浣跨敤SNUM浣滀负閫佹鎵规暟鏉ヨ绠楁�荤紪鍙锋暟閲� + item.HoleNumbers = GenerateHoleNumbers(item.Mnum, item.Dnum, item.Snum); + } + }); + return qsItemIpiItems; } @@ -224,7 +308,7 @@ item.Items = getQSItems(qsItemIpiReq.Id, null); var sjPageResult = new SJPageResult { Id = item.From.Id, Limit = 1, PageIndex = 1 }; - item.Result = getPage(sjPageResult)[0]; + item.Result = getPage(sjPageResult).item[0]; return item; } @@ -267,6 +351,10 @@ var oracle = SqlSugarHelper.UseTransactionWithOracle(db => { List<QsItemIpiItemDetail> result = new(); + + // 鑾峰彇璧峰绱㈠紩锛屽鏋滄病鏈夋寚瀹氬垯浠�0寮�濮� + int startIndex = detail.startIndex ?? 0; + for (var i = 0; i < detail.count; i++) { var item = new QsItemIpiItemDetail(); @@ -276,6 +364,9 @@ item.FcheckResu = detail.FcheckResu; item.CreateBy = detail.UpdateBy; item.CreateDate = DateTime.Now; + + // 濡傛灉鏈夎捣濮嬬储寮曪紝鍙互鍦ㄨ繖閲岃缃浉鍏崇殑绱㈠紩淇℃伅 + // 娉ㄦ剰锛氳繖閲屽彧鏄ず渚嬶紝瀹為檯鍙兘闇�瑕佹牴鎹笟鍔¢渶姹傝皟鏁� result.Add(item); } @@ -456,4 +547,137 @@ return withOracle; } + //鍒锋柊妫�楠岄」鐩� + public (int result, string message) GenUpdate(decimal? id, string? no, string? user) + { + var outputResult = new SugarParameter("PO_RESULT", null, System.Data.DbType.Int32, ParameterDirection.Output, 4000); + var outputMessage = new SugarParameter("PO_TEXT", null, System.Data.DbType.String, ParameterDirection.Output, 4000); + + var parameters = new List<SugarParameter> + { + new("P_ID", id, System.Data.DbType.Decimal, ParameterDirection.Input), + new("P_NO", no, System.Data.DbType.String, ParameterDirection.Input), + new("P_USER", user, System.Data.DbType.String, ParameterDirection.Input), + outputResult, + outputMessage + }; + + var db = SqlSugarHelper.GetInstance(); + db.Ado.ExecuteCommand( + "BEGIN PRC_GEN_UPDATE(:P_ID, :P_NO, :P_USER, :PO_RESULT, :PO_TEXT); END;", + parameters.ToArray()); + + int result = outputResult.Value == null ? -1 : Convert.ToInt32(outputResult.Value); + string message = outputMessage.Value?.ToString() ?? ""; + + return (result, message); + } + + public bool SjSubmit(SJDto dto) + { + try + { + // 瀹氫箟杈撳嚭鍙傛暟 + var outputResult = new SugarParameter("c_res", null, + System.Data.DbType.Int32, ParameterDirection.Output, + 4000); + + var outputMessage = new SugarParameter("c_msg", null, + System.Data.DbType.String, + ParameterDirection.Output, 4000); + + // 瀹氫箟杈撳叆鍙傛暟锛屽浐瀹欶LAG涓�1锛堝鏍革級 + var parameters = new List<SugarParameter> + { + new("P_ID", dto.id, System.Data.DbType.Decimal, ParameterDirection.Input), + new("P_FLAG", 1, System.Data.DbType.Int32, ParameterDirection.Input), + new("P_USER", dto.userNo, System.Data.DbType.String, ParameterDirection.Input), + outputResult, + outputMessage + }; + + var db = SqlSugarHelper.GetInstance(); + + // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼ + db.Ado.ExecuteCommand( + "BEGIN PRC_WOMDAA_SJ_UPDATE_RES(:P_ID, :P_FLAG, :P_USER, :c_res, :c_msg); END;", + parameters.ToArray()); + + // 鑾峰彇杈撳嚭鍙傛暟鐨勫�� + var resultValue = outputResult.Value?.ToString(); + var messageValue = outputMessage.Value?.ToString(); + + if ("1".Equals(resultValue)) throw new Exception(messageValue); + + return true; + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + } + + /// <summary> + /// 鐢熸垚绌村彿淇℃伅 + /// </summary> + /// <param name="mnum">寮�绌存�绘暟</param> + /// <param name="dnum">鍫电┐鍙凤紙閫楀彿鍒嗛殧锛�</param> + /// <param name="snum">閫佹鎵规暟</param> + /// <returns>绌村彿淇℃伅鍒楄〃</returns> + private List<HoleNumberInfo> GenerateHoleNumbers(decimal? mnum, string? dnum, decimal? snum) + { + var result = new List<HoleNumberInfo>(); + + if (mnum == null || mnum <= 0 || snum == null || snum <= 0) + return result; + + // 瑙f瀽鍫电┐鍙� + var blockedHoles = new HashSet<int>(); + if (!string.IsNullOrEmpty(dnum)) + { + var holeNumbers = dnum.Split(',', StringSplitOptions.RemoveEmptyEntries); + foreach (var holeStr in holeNumbers) + { + if (int.TryParse(holeStr.Trim(), out int holeNum)) + { + blockedHoles.Add(holeNum); + } + } + } + + int totalHoles = (int)mnum.Value; + int batchCount = (int)snum.Value; // 閫佹鎵规暟 + + // 璁$畻鎬荤紪鍙锋暟閲忥細寮�绌存�绘暟 脳 閫佹鎵规暟 + int totalIndexes = totalHoles * batchCount; + + for (int i = 1; i <= totalIndexes; i++) + { + // 绌村彿寰幆锛�1-8, 1-8... + int holeNumber = ((i - 1) % totalHoles) + 1; + bool isBlocked = blockedHoles.Contains(holeNumber); + + result.Add(new HoleNumberInfo + { + Index = i, + HoleNumber = holeNumber, + IsBlocked = isBlocked, + RecordValue = isBlocked ? "/" : null, + CheckResult = isBlocked ? "/" : null + }); + } + + // 鎺掑簭锛氬牭绌存帓鏈�鍚庝紭鍏堢骇绗竴锛岀劧鍚庣┐鍙蜂粠灏忓埌澶ф帓锛岀┐鍙风浉鍚岀殑鎺掍竴璧� + result = result.OrderBy(x => x.IsBlocked) // 鍫电┐鎺掓渶鍚庯紙false鍦ㄥ墠锛宼rue鍦ㄥ悗锛� + .ThenBy(x => x.HoleNumber) // 绌村彿浠庡皬鍒板ぇ + .ToList(); + + // 閲嶆柊璁剧疆Index锛屼繚鎸佽繛缁紪鍙� + for (int i = 0; i < result.Count; i++) + { + result[i].Index = i + 1; + } + + return result; + } } \ No newline at end of file -- Gitblit v1.9.3