From 2b8d835217a75650e066de7d39509eee9923ef3c Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期四, 14 八月 2025 21:30:46 +0800 Subject: [PATCH] 111 --- MES.Service/service/QC/XJService.cs | 417 +++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 290 insertions(+), 127 deletions(-) diff --git a/MES.Service/service/QC/XJService.cs b/MES.Service/service/QC/XJService.cs index 5513747..54a24cd 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; @@ -13,7 +14,7 @@ private readonly BaseService _baseService = new(); - private readonly string[] statusArray = ["鐢熶骇", "寰呬骇"]; + private readonly string[] statusArray = ["寮�宸�", "寰呭紑宸�"]; //鐢熸垚鏈�鏂扮殑妫�楠屽崟鍙� public string getMaxReleaseNo() @@ -38,35 +39,16 @@ return "XJN" + date + number; } - public List<MesSchemeResult> getItem(string daa001) + public List<Womdaa> getItem(string daa001) { var db = SqlSugarHelper.GetInstance(); //in鐨勫啓娉� https://www.donet5.com/Home/Doc?typeId=1187 - return db.Queryable<MesSchemeResult, MesDepTask, MesBoardBaseInfo>( - (a, c, b) => - new JoinQueryInfos( - JoinType.Left, a.TaskNo == c.TaskNo, - JoinType.Left, c.BoardItem == b.BoardItem - ) - ) - .Where(a => a.PmoveMk == 0 && - a.BillNo == daa001 && - statusArray.Contains(a.ProcStatus)) - .Select((a, c, b) => new MesSchemeResult - { - BillNo = a.BillNo, - CatQty = a.CatQty, - DetailMem = a.DetailMem, - TaskNo = a.TaskNo, - BoardItem = a.BoardItem, - BoardModel = b.BoardModel, - PlanQty = c.PlanQty, - Mocode = a.Mocode, - BoardStyle = c.BoardStyle, - Id = a.Id - }) + return db.Queryable<Womdaa>() + .Where(a => + a.Daa001 == daa001 && + statusArray.Contains(a.Daa018)) .ToList(); } @@ -74,106 +56,115 @@ { var db = SqlSugarHelper.GetInstance(); - return db.Queryable<MesSchemeResult, MesLine>((a, b) => - new JoinQueryInfos(JoinType.Left, a.LineNo == b.LineNo)) - .Where((a, b) => a.PmoveMk == 0 && b.LineName != null && - statusArray.Contains(a.ProcStatus)) - .Where("BOARD_ITEM like @BoardItem", new { BoardItem = "20%" }) + return db.Queryable<Womdaa, MesLine>((a, b) => + new JoinQueryInfos(JoinType.Left, a.Daa015 == b.LineNo)) + .Where((a, b) => b.LineName != null && + statusArray.Contains(a.Daa018)) .GroupBy((a, b) => new { - a.LineNo, b.LineName + b.LineNo, b.LineName }) .Select((a, b) => new MesLine { - LineNo = a.LineNo, + LineNo = b.LineNo, LineName = b.LineName - }).OrderBy("a.LINE_NO").ToList(); + }).OrderBy("b.LINE_NO").ToList(); } - public List<MesSchemeResult> getDaa001(string daa020, string item) + public List<Womdaa> getDaa001(string daa020, string item) { var db = SqlSugarHelper.GetInstance(); - return db.Queryable<MesSchemeResult>().Where(a => - a.PmoveMk == 0 && a.LineNo == daa020 && a.BillNo != null && - a.BoardItem == item && - statusArray.Contains(a.ProcStatus)) - .Select<MesSchemeResult>(a => new MesSchemeResult + return db.Queryable<Womdaa, MesItems>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.Daa002 == b.Id.ToString())) + .Where((a, b) => + a.Daa015 == daa020 && + b.ItemNo == item && + statusArray.Contains(a.Daa018)) + .Select<Womdaa>(a => new Womdaa { - BillNo = a.BillNo, - DetailMem = a.DetailMem + Id = a.Id, + Daa001 = a.Daa001, + Daa003 = a.Daa003, + Daa008 = a.Daa008 }).ToList(); } - public List<MesSchemeResult> getBoardItem(string lineNo) + public List<MesItems> getBoardItem(string lineNo) { var db = SqlSugarHelper.GetInstance(); - return db.Queryable<MesSchemeResult>() - .Where(a => - a.PmoveMk == 0 && statusArray.Contains(a.ProcStatus) && - a.LineNo == lineNo) - .Where("BOARD_ITEM like @BoardItem", new { BoardItem = "20%" }) - .Select<MesSchemeResult>(a => - new MesSchemeResult + return db.Queryable<Womdaa, MesItems>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.Daa002 == b.Id.ToString())) + .Where((a, b) => statusArray.Contains(a.Daa018) && + a.Daa015 == lineNo) + .OrderBy((a, b) => b.ItemName) + .Select<MesItems>((a, b) => + new MesItems { - BoardItem = a.BoardItem, - DetailMem = a.DetailMem - }).OrderBy(a => a.BoardItem).ToList(); + Id = b.Id, + ItemNo = b.ItemNo, + 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 - .Queryable<QsQaItemXj, MesSchemeResult, MesDepTask, - MesBoardBaseInfo>((s, a, c, b) => + var query = db + .Queryable<QsQaItemXj, Womdaa, MesLine, + MesItems, SysUser>((s, a, c, b, us) => new JoinQueryInfos( - JoinType.Inner, s.BillNo == a.BillNo, - JoinType.Left, a.TaskNo == c.TaskNo, - JoinType.Left, c.BoardItem == b.BoardItem + JoinType.Inner, s.BillNo == a.Daa001, + JoinType.Left, a.Daa015 == c.LineNo, + JoinType.Left, s.ItemId == b.Id, + JoinType.Left, us.Fcode == s.CreateBy ) ) - .WhereIF(lineNo != null && lineNo.Length > 0, - (s, a, c, b) => lineNo.Contains(a.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 { - CatQty = a.CatQty, - MoidNum = s.MoidNum, - Daa020 = a.LineNo, - DetailMem = a.DetailMem, - TaskNo = a.TaskNo, + 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, - BoardModel = b.BoardModel, - PlanQty = c.PlanQty, - Mocode = a.Mocode, - BoardStyle = c.BoardStyle - }).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); } @@ -189,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) @@ -308,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); } @@ -418,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>() @@ -457,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(); }); @@ -535,6 +686,18 @@ .ExecuteCommand(); }); } + + public int saveNotesPid(XJDto dto) + { + return SqlSugarHelper.UseTransactionWithOracle(db => + { + return db.Updateable<QsQaItemXj01>() + .SetColumns(it => + it.Notes == dto.Remarks) //SetColumns鏄彲浠ュ彔鍔犵殑 鍐�2涓氨2涓瓧娈佃祴鍊� + .Where(it => it.Id == dto.pid) + .ExecuteCommand(); + }); + } //瀛欒〃淇敼澶囨敞瀛楁 public int saveRemarksById(XJDto dto) -- Gitblit v1.9.3