| | |
| | | using MES.Service.Modes; |
| | | using MES.Service.util; |
| | | using SqlSugar; |
| | | using System.Data; |
| | | |
| | | namespace MES.Service.service.QC; |
| | | |
| | |
| | | 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(); |
| | | |
| | |
| | | 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) |
| | |
| | | .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); |
| | | } |
| | | |
| | | |
| | |
| | | public List<QsItemIpiItem> getQSItems(decimal? pid, decimal? id) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | // 使用JOIN查询获取子表数据和主表的MNUM、DNUM字段 |
| | | 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, // 从主表获取MNUM |
| | | Dnum = b.Dnum, // 从主表获取DNUM |
| | | Snum = a.Snum, // 送检批数 |
| | | Remarks = a.Remarks |
| | | }).ToList(); |
| | | |
| | | var array = qsItemIpiItems.Select(s => s.Id).ToArray(); |
| | | var qsItemIpiItemDetails = db.Queryable<QsItemIpiItemDetail>() |
| | |
| | | //排序,未完成的排在前面 |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | 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(); |
| | |
| | | item.FcheckResu = detail.FcheckResu; |
| | | item.CreateBy = detail.UpdateBy; |
| | | item.CreateDate = DateTime.Now; |
| | | |
| | | // 如果有起始索引,可以在这里设置相关的索引信息 |
| | | // 注意:这里只是示例,实际可能需要根据业务需求调整 |
| | | result.Add(item); |
| | | } |
| | | |
| | |
| | | |
| | | 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); |
| | | |
| | | // 定义输入参数,固定FLAG为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; |
| | | |
| | | // 解析堵穴号 |
| | | 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在前,true在后) |
| | | .ThenBy(x => x.HoleNumber) // 穴号从小到大 |
| | | .ToList(); |
| | | |
| | | // 重新设置Index,保持连续编号 |
| | | for (int i = 0; i < result.Count; i++) |
| | | { |
| | | result[i].Index = i + 1; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |