| | |
| | | using MES.Service.Modes; |
| | | using MES.Service.util; |
| | | using SqlSugar; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
| | | |
| | | namespace MES.Service.service.QC; |
| | | |
| | |
| | | { |
| | | Id = a.Id, |
| | | Daa001 = a.Daa001, |
| | | Daa003 = a.Daa003 |
| | | Daa003 = a.Daa003, |
| | | Daa008 = a.Daa008 |
| | | }).ToList(); |
| | | } |
| | | |
| | |
| | | .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) => |
| | | 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 |
| | | ) |
| | | ) |
| | | .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) => s.SubmitStatus == 0 || s.SubmitStatus == null) |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.result) && |
| | | !"未完成".Equals(queryObj.result), |
| | | (s, a, c, b) => s.FcheckResu != null) |
| | | (s, a, c, b) => s.SubmitStatus == 1) |
| | | .WhereIF(id > 0, (s, a, c, b) => s.Id == id) |
| | | .Select((s, a, c, b) => new QsQaItemXj |
| | | { |
| | | MoidNum = s.MoidNum, |
| | | Daa020 = c.LineNo, |
| | | Id = s.Id, |
| | | PlanQty = a.Daa008, |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | private List<QsQaItemXj01> getJYItemOptimized(ISqlSugarClient db, decimal xjId) |
| | | { |
| | | return db.Queryable<QsQaItemXj01>() |
| | | .Where(a => a.Pid == xjId) |
| | | .ToList(); |
| | | } |
| | | |
| | | 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, ""); |
| | | } |
| | | |
| | | xjDto.items = getJYItem(xjDto.gid, null); |
| | | |
| | | xjDto.items.ForEach(s => |
| | | 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); |
| | | }); |
| | | if (s.MaxValue != null || s.StandardValue != null || 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); |
| | | } |
| | | |
| | | |
| | |
| | | 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(); |
| | | }); |