From e937af660a22640ace71147853cb70078673928f Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期二, 12 八月 2025 16:17:30 +0800 Subject: [PATCH] 111 --- MES.Service/service/QC/XJService.cs | 307 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 241 insertions(+), 66 deletions(-) diff --git a/MES.Service/service/QC/XJService.cs b/MES.Service/service/QC/XJService.cs index ad76d93..deed3d0 100644 --- a/MES.Service/service/QC/XJService.cs +++ b/MES.Service/service/QC/XJService.cs @@ -3,6 +3,7 @@ using MES.Service.Modes; using MES.Service.util; using SqlSugar; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace MES.Service.service.QC; @@ -83,7 +84,8 @@ { Id = a.Id, Daa001 = a.Daa001, - Daa003 = a.Daa003 + Daa003 = a.Daa003, + Daa008 = a.Daa008 }).ToList(); } @@ -98,58 +100,71 @@ .Select<MesItems>((a, b) => new MesItems { + Id = b.Id, ItemNo = b.ItemNo, - ItemName = b.ItemName + ItemName = b.ItemName, + ItemModel = b.ItemModel }).ToList(); } - public List<QsQaItemXj> getPage(XJPageResult queryObj) + public (List<QsQaItemXj> items, int totalCount) getPage( + XJPageResult queryObj) { var db = SqlSugarHelper.GetInstance(); + + int totalCount = 0; var id = Convert.ToDecimal(queryObj.id); string[]? lineNo = null; - if (StringUtil.IsNotNullOrEmpty(queryObj.createUser)) - lineNo = _baseService.getUserLineNo(queryObj.createUser); + //if (StringUtil.IsNotNullOrEmpty(queryObj.createUser)) + // lineNo = _baseService.getUserLineNo(queryObj.createUser); - return db + var query = db .Queryable<QsQaItemXj, Womdaa, MesLine, - MesItems>((s, a, c, b) => + MesItems, SysUser>((s, a, c, b, us) => new JoinQueryInfos( JoinType.Inner, s.BillNo == a.Daa001, JoinType.Left, a.Daa015 == c.LineNo, - JoinType.Left, s.ItemNo == b.ItemNo + JoinType.Left, s.ItemId == b.Id, + JoinType.Left, us.Fcode == s.CreateBy ) ) - .WhereIF(lineNo != null && lineNo.Length > 0, - (s, a, c, b) => lineNo.Contains(c.LineNo)) + //.WhereIF(lineNo != null && lineNo.Length > 0, + // (s, a, c, b) => lineNo.Contains(c.LineNo)) .WhereIF( StringUtil.IsNotNullOrEmpty(queryObj.result) && "鏈畬鎴�".Equals(queryObj.result), - (s, a, c, b) => s.FcheckResu == null) + (s, a, c, b, us) => + s.SubmitStatus == 0 || s.SubmitStatus == null) .WhereIF( StringUtil.IsNotNullOrEmpty(queryObj.result) && !"鏈畬鎴�".Equals(queryObj.result), - (s, a, c, b) => s.FcheckResu != null) - .WhereIF(id > 0, (s, a, c, b) => s.Id == id) - .Select((s, a, c, b) => new QsQaItemXj + (s, a, c, b, us) => s.SubmitStatus == 1) + .WhereIF(id > 0, (s, a, c, b, us) => s.Id == id) + .Select((s, a, c, b, us) => new QsQaItemXj { - MoidNum = s.MoidNum, Daa020 = c.LineNo, Id = s.Id, + PlanQty = a.Daa008, + LineName = c.LineName, + CreateUser = us.Fname, CreateBy = s.CreateBy, CreateDate = s.CreateDate, ReleaseNo = s.ReleaseNo, ItemNo = s.ItemNo, - ItemUnit = s.ItemUnit, BillNo = s.BillNo, - FcheckBy = s.FcheckBy, - FcheckResu = s.FcheckResu, - Remarks = s.Remarks, - }).OrderBy(s => s.CreateDate, OrderByType.Desc) - .ToPageList(queryObj.PageIndex, queryObj.Limit); + ItemName = b.ItemName, + ItemModel = b.ItemModel, + CheckBy = s.CheckBy, + CheckResult = s.CheckResult, + Remarks = s.Remarks + }).OrderBy(s => s.CreateDate, OrderByType.Desc); + var items = query.ToPageList(queryObj.PageIndex, queryObj.Limit, + ref totalCount); + + return (items, totalCount); } @@ -165,29 +180,28 @@ return db .Queryable<MesQualityStandard>() .Where(b => b.QsType == "2" - && b.ItemNo == itemNo).Select( - b => new QsQaItemXj01 - { - 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, - result = "鏈娴�", - isCheck = 0, - Picture = b.Picture, - Picturename = b.Picturename - }).ToList(); + && b.ItemNo == itemNo).Select(b => new QsQaItemXj01 + { + 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, + result = "鏈娴�", + isCheck = 0, + Picture = b.Picture, + Picturename = b.Picturename + }).ToList(); } public List<QsQaItemXj01> getJYItem(decimal? pid, decimal? id) @@ -284,35 +298,196 @@ return Convert.ToInt32(xj.Id); } + public bool XJQaSubmit(LLJDto rkjDto) + { + var useTransactionWithOracle = + SqlSugarHelper.UseTransactionWithOracle(db => + { + return db.Updateable<QsQaItemXj>() + .SetColumns(s => s.SubmitStatus == 1) + .SetColumns(s => s.SubmitBy == rkjDto.userNo) + .SetColumns(s => s.SubmitDate == DateTime.Now) + .Where(s => s.Id == rkjDto.gid) + .ExecuteCommand(); + }); + + return useTransactionWithOracle > 0; + } + + // public int saveItem(XJDto xjDto) + // { + // var items = xjDto.items; + // var userNo = xjDto.userNo; + // + // SqlSugarHelper.UseTransactionWithOracle(db => + // { + // foreach (var item in items) item.Pid = xjDto.gid; + // + // return db.Insertable(items).ExecuteCommand(); + // }); + // + // xjDto.items = getJYItem(xjDto.gid, null); + // + // xjDto.items.ForEach(s => + // { + // if (s.MaxValue != null || s.StandardValue != null || + // s.MinValue != null) return; + // var detail = new QsQaItemXj02(); + // detail.Pid = s.Id; + // detail.Gid = xjDto.gid; + // detail.Fstand = "鈭�"; + // detail.FcheckResu = "1"; + // detail.UpdateBy = xjDto.userNo; + // detail.count = (int?)s.LevelNum; + // SetQSItemDetail(detail); + // }); + // + // return Convert.ToInt32(xjDto.gid); + // } public int saveItem(XJDto xjDto) { var items = xjDto.items; var userNo = xjDto.userNo; - SqlSugarHelper.UseTransactionWithOracle(db => + // 鏁版嵁楠岃瘉 + var validationResult = ValidateItemsData(items); + if (!validationResult.isValid) + throw new Exception($"妫�楠岄」鐩獙璇佸け璐�: {validationResult.errorMsg}"); + + return SqlSugarHelper.UseTransactionWithOracle(db => { + // 璁剧疆澶栭敭鍏宠仈骞舵壒閲忔彃鍏ュ瓙琛� foreach (var item in items) item.Pid = xjDto.gid; + db.Insertable(items).ExecuteCommand(); - return db.Insertable(items).ExecuteCommand(); + // 鑾峰彇妫�楠岄」鐩暟鎹� + var jyItems = getJYItemOptimized(db, xjDto.gid.Value); + + if (jyItems.Any()) + { + // 澶勭悊涓氬姟閫昏緫璁$畻 + var allDetails = + PrepareDetailsData(jyItems, xjDto.gid.Value, userNo); + + if (allDetails.Count > 0) + { + // 鎵归噺鎻掑叆妫�楠岃鎯� + db.Insertable(allDetails).ExecuteCommand(); + + // 璁$畻缁撴灉 + var (pidResults, fcheckResu) = + CalculateResults(allDetails, jyItems); + + // 鎵归噺鏇存柊妫�楠岄」鐩粨鏋� + foreach (var (pidValue, result) in pidResults) + { + db.Updateable<QsQaItemXj01>() + .SetColumns(s => s.IsPass == result) + .Where(s => s.Id == pidValue) + .ExecuteCommand(); + } + + // 鏇存柊涓昏〃妫�楠岀粨鏋� + var totalSum = jyItems.Where(x => + x.MaxValue == null && x.StandardValue == null && + x.MinValue == null) + .Sum(x => x.LevelNum); + if (totalSum == allDetails.Count) + { + db.Updateable<QsQaItemXj>() + .SetColumns(s => s.CheckResult == fcheckResu) + .SetColumns(s => s.CheckDate == DateTime.Now) + .SetColumns(s => s.CheckBy == userNo) + .SetColumns(s => s.LastUpdateBy == userNo) + .SetColumns(s => s.LastUpdateDate == DateTime.Now) + .Where(s => s.Id == xjDto.gid) + .ExecuteCommand(); + } + } + } + + return Convert.ToInt32(xjDto.gid); }); + } - xjDto.items = getJYItem(xjDto.gid, null); + private List<QsQaItemXj01> getJYItemOptimized(ISqlSugarClient db, + decimal xjId) + { + return db.Queryable<QsQaItemXj01>() + .Where(a => a.Pid == xjId) + .ToList(); + } - xjDto.items.ForEach(s => + private (bool isValid, string errorMsg) ValidateItemsData( + List<QsQaItemXj01> items) + { + if (items == null || !items.Any()) return (false, "妫�楠岄」鐩笉鑳戒负绌�"); + + var invalidItems = items + .Where(x => x.LevelNum <= 0 || string.IsNullOrEmpty(x.ProjName)) + .ToList(); + if (invalidItems.Any()) + return (false, $"瀛樺湪{invalidItems.Count}涓棤鏁堢殑妫�楠岄」鐩�"); + + return (true, ""); + } + + private List<QsQaItemXj02> PrepareDetailsData(List<QsQaItemXj01> jyItems, + decimal gid, string userNo) + { + var allDetails = new List<QsQaItemXj02>(); + var now = DateTime.Now; + + foreach (var s in jyItems) { if (s.MaxValue != null || s.StandardValue != null || - s.MinValue != null) return; - var detail = new QsQaItemXj02(); - detail.Pid = s.Id; - detail.Gid = xjDto.gid; - detail.Fstand = "鈭�"; - detail.FcheckResu = "1"; - detail.UpdateBy = xjDto.userNo; - detail.count = (int?)s.LevelNum; - SetQSItemDetail(detail); - }); + s.MinValue != null) + continue; - return Convert.ToInt32(xjDto.gid); + for (var i = 0; i < s.LevelNum; i++) + { + allDetails.Add(new QsQaItemXj02 + { + Gid = gid, + Pid = s.Id, + Fstand = "鈭�", + FcheckResu = "1", + CreateBy = userNo, + CreateDate = now + }); + } + } + + return allDetails; + } + + private (List<(decimal pid, int result)> pidResults, string fcheckResu) + CalculateResults( + List<QsQaItemXj02> allDetails, List<QsQaItemXj01> jyItems) + { + var pidGroups = allDetails.GroupBy(x => x.Pid).ToList(); + var pidResults = new List<(decimal pid, int result)>(); + + foreach (var group in pidGroups) + { + var count = group.Count(); + var passCount = group.Count(x => x.Fstand == "鈭�"); + var result = (count == passCount) ? 1 : 0; + pidResults.Add((group.Key.Value, result)); + } + + var totalSum = jyItems.Where(x => + x.MaxValue == null && x.StandardValue == null && + x.MinValue == null) + .Sum(x => x.LevelNum); + var totalCount = allDetails.Count; + var totalPassCount = allDetails.Count(x => x.Fstand == "鈭�"); + var fcheckResu = + (totalSum == totalCount && totalCount == totalPassCount) + ? "鍚堟牸" + : "涓嶅悎鏍�"; + + return (pidResults, fcheckResu); } @@ -394,8 +569,8 @@ if (count == passCount) result = 1; - var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle( - db => + var useTransactionWithOracle = + SqlSugarHelper.UseTransactionWithOracle(db => { var commit = 0; commit += db.Updateable<QsQaItemXj01>() @@ -433,11 +608,11 @@ SqlSugarHelper.UseTransactionWithOracle(db => { return db.Updateable<QsQaItemXj>() - .SetColumns(s => s.FcheckResu == FcheckResu) - .SetColumns(s => s.FcheckDate == DateTime.Now) - .SetColumns(s => s.FcheckBy == detail.CreateBy) - .SetColumns(s => s.LastupdateBy == detail.CreateBy) - .SetColumns(s => s.LastupdateDate == DateTime.Now) + .SetColumns(s => s.CheckResult == FcheckResu) + .SetColumns(s => s.CheckDate == DateTime.Now) + .SetColumns(s => s.CheckBy == detail.CreateBy) + .SetColumns(s => s.LastUpdateBy == detail.CreateBy) + .SetColumns(s => s.LastUpdateDate == DateTime.Now) .Where(s => s.Id == detail.Gid) .ExecuteCommand(); }); -- Gitblit v1.9.3