| | |
| | | a.FcheckLevel, |
| | | a.FacLevel, |
| | | a.QsCode, |
| | | a.QsName |
| | | a.QsName, |
| | | a.Forder |
| | | }).Select((a, b) => new QsItemOqcItem |
| | | { |
| | | ProjName = a.ProjName, |
| | |
| | | FacLevel = a.FacLevel, |
| | | QsCode = a.QsCode, |
| | | QsName = a.QsName, |
| | | Forder = a.Forder, |
| | | isCheck = SqlFunc.AggregateCount(b.Id), |
| | | Result = SqlFunc.AggregateCount(b.Id) == 0 ? "未完成" : |
| | | a.IsPass == 1 ? "合格" : "不合格" |
| | | }).OrderBy("result desc").ToList(); |
| | | }).OrderBy("FORDER").ToList(); |
| | | } |
| | | |
| | | public dynamic save(RKJDto rkjDto) |
| | |
| | | var qsItemOqcReq = |
| | | db.Queryable<QsItemOqcReq>().Single(s => s.Id == gid); |
| | | |
| | | var mesInvItemIns = db.Queryable<MesInvItemIns>() |
| | | .Single(s => s.BillNo == qsItemOqcReq.BillNo); |
| | | //var mesInvItemIns = db.Queryable<MesInvItemIns>() |
| | | // .Single(s => s.BillNo == qsItemOqcReq.BillNo); |
| | | |
| | | var mesSchemeResult = db.Queryable<Womdaa>() |
| | | .Single(s => s.Daa001 == mesInvItemIns.CbillNo); |
| | | |
| | | //.Single(s => s.Daa001 == mesInvItemIns.CbillNo); |
| | | .Single(s => s.Daa001 == qsItemOqcReq.BillNo); |
| | | var entity = new MesQaItemsDetect02(); |
| | | // entity.ItemNo = mesSchemeResult.BoardItem; |
| | | // entity.BoardItem = mesSchemeResult.BoardItem; |
| | |
| | | entity.CreateBy = createBy; |
| | | entity.FcheckBy = createBy; |
| | | |
| | | return SqlSugarHelper.UseTransactionWithOracle(db => db |
| | | .Insertable(entity) |
| | | .ExecuteCommand()); |
| | | // 跳过MES_QA_ITEMS_DETECT_02表的插入操作 |
| | | // 不再自动生成入库检异常对策记录 |
| | | return 0; |
| | | } |
| | | |
| | | |
| | |
| | | if (StringUtil.IsNotNullOrEmpty(queryObj.createUser)) |
| | | lineNo = _baseService.getUserLineNo(queryObj.createUser); |
| | | |
| | | |
| | | return db |
| | | .Queryable<QsItemOqcReq, Womdaa, MesItems>((a, da, b) => |
| | | .Queryable<QsItemOqcReq, Womdaa, MesItems, MesLine>((a, da, b, m) => |
| | | new JoinQueryInfos( |
| | | JoinType.Left, da.Daa001 == a.BillNo, |
| | | JoinType.Left, a.ItemId == b.Id |
| | | JoinType.Left, a.ItemId == b.Id, |
| | | JoinType.Left, da.Daa015 == m.LineNo |
| | | )) |
| | | .WhereIF(lineNo != null && lineNo.Length > 0, |
| | | (a, da, b) => lineNo.Contains(da.Daa015)) |
| | | (a, da, b, m) => lineNo.Contains(da.Daa015)) |
| | | // 添加QC筛选条件:车间和线体 |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.departmentId), |
| | | (a, da, b, m) => m.DepotId.ToString() == queryObj.departmentId) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.lineId), |
| | | (a, da, b, m) => m.LineNo == queryObj.lineId) |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.result) && |
| | | "未完成".Equals(queryObj.result), |
| | | (a, da, b) => a.FcheckResu == null || a.FcheckResu == "") |
| | | (a, da, b, m) => a.FcheckResu == null || a.FcheckResu == "") |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.result) && |
| | | !"未完成".Equals(queryObj.result), |
| | | (a, da, b) => a.FcheckResu != null && a.FcheckResu != "") |
| | | .WhereIF(id > 0, (a, da, b) => a.Id == id) |
| | | // 添加fsubmit字段过滤逻辑 |
| | | (a, da, b, m) => a.FcheckResu != null && a.FcheckResu != "") |
| | | .WhereIF(id > 0, (a, da, b, m) => a.Id == id) |
| | | // 添加fsubmit字段过滤逻辑 - 只有在明确指定fsubmit参数时才过滤,且没有传递id时才过滤 |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1", |
| | | (a, da, b) => a.Fsubmit == 1) |
| | | id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1", |
| | | (a, da, b, m) => a.Fsubmit == 1) |
| | | .WhereIF( |
| | | StringUtil.IsNullOrEmpty(queryObj.fsubmit) || queryObj.fsubmit == "0", |
| | | (a, da, b) => a.Fsubmit == 0 || a.Fsubmit == null) |
| | | .Select((a, da, b) => new QsItemOqcReq |
| | | id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "0", |
| | | (a, da, b, m) => a.Fsubmit == 0 || a.Fsubmit == null) |
| | | // 添加搜索条件 - 根据选择的搜索字段进行精确搜索 |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "billNo", // 工单 |
| | | (a, da, b, m) => a.BillNo.Contains(queryObj.SearchValue)) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "releaseNo", // 检验单号 |
| | | (a, da, b, m) => a.ReleaseNo.Contains(queryObj.SearchValue)) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "daa015", // 产线 |
| | | (a, da, b, m) => da.Daa015.Contains(queryObj.SearchValue)) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "itemNo", // 物料编码 |
| | | (a, da, b, m) => a.ItemNo.Contains(queryObj.SearchValue)) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "itemName", // 物料名称 |
| | | (a, da, b, m) => b.ItemName.Contains(queryObj.SearchValue)) |
| | | // 为了兼容旧版本,如果没有传递 searchField,使用原来的查询逻辑 |
| | | .WhereIF(string.IsNullOrEmpty(queryObj.searchField) && !string.IsNullOrEmpty(queryObj.SearchValue), |
| | | (a, da, b, m) => |
| | | a.ItemNo.Contains(queryObj.SearchValue) || |
| | | b.ItemName.Contains(queryObj.SearchValue) || |
| | | a.BillNo.Contains(queryObj.SearchValue) || |
| | | a.ReleaseNo.Contains(queryObj.SearchValue) || |
| | | da.Daa015.Contains(queryObj.SearchValue)) |
| | | .Select((a, da, b, m) => new QsItemOqcReq |
| | | { |
| | | Id = a.Id, |
| | | ReleaseNo = a.ReleaseNo, |
| | |
| | | var rkjDto = new RKJDto(); |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | var qsItemOqcItem = |
| | | db.Queryable<QsItemOqcItem>().Single(s => s.Id == id); |
| | | |
| | | // 使用JOIN查询获取子表数据和主表的ItemNo字段 |
| | | var qsItemOqcItem = db |
| | | .Queryable<QsItemOqcItem, QsItemOqcReq>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id)) |
| | | .Where((a, b) => a.Id == id) |
| | | .Select((a, b) => new QsItemOqcItem |
| | | { |
| | | 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, |
| | | Remarks = a.Remarks, |
| | | FreQty = a.FreQty, |
| | | // 添加主表的ItemNo字段 |
| | | ItemNo = b.ItemNo |
| | | }).Single(); |
| | | |
| | | if (qsItemOqcItem.IsPass == 0) |
| | | qsItemOqcItem.Result = "不合格"; |
| | |
| | | qsItemOqcItem.Unqualified = count; |
| | | |
| | | rkjDto.ItemXj01 = qsItemOqcItem; |
| | | |
| | | |
| | | rkjDto.ItemXj02s = db.Queryable<QsItemOqcItemDetail>() |
| | | .Where(s => s.Pid == id) |
| | |
| | | /// <param name="id">检验单ID</param> |
| | | /// <param name="userNo">提交用户</param> |
| | | /// <returns>更新结果</returns> |
| | | public int SubmitInspection(decimal id, string userNo) |
| | | public bool SubmitInspection(decimal id, string userNo) |
| | | { |
| | | return SqlSugarHelper.UseTransactionWithOracle(db => |
| | | try |
| | | { |
| | | // 获取检验单详细信息 |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | // 先获取检验单详细信息(用于钉钉推送判断) |
| | | var inspectionData = db.Queryable<QsItemOqcReq>() |
| | | .Where(it => it.Id == id) |
| | | .First(); |
| | |
| | | throw new Exception("检验单不存在"); |
| | | } |
| | | |
| | | // 定义输出参数 |
| | | var outputResult = new SugarParameter("PO_RESULT", null, |
| | | System.Data.DbType.Int32, ParameterDirection.Output, |
| | | 4000); |
| | | |
| | | var outputMessage = new SugarParameter("PO_MSG", 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_USER", userNo, System.Data.DbType.String, ParameterDirection.Input), |
| | | outputResult, |
| | | outputMessage |
| | | }; |
| | | |
| | | // 使用 SqlSugar 执行存储过程 |
| | | db.Ado.ExecuteCommand( |
| | | "BEGIN PRC_RKJ_UPDATE_SH(:P_ID, :P_USER, :PO_RESULT, :PO_MSG); END;", |
| | | parameters.ToArray()); |
| | | |
| | | // 获取输出参数的值 |
| | | var resultValue = outputResult.Value?.ToString(); |
| | | var messageValue = outputMessage.Value?.ToString(); |
| | | |
| | | // 如果返回结果不为0,表示失败 |
| | | if ("1".Equals(resultValue)) |
| | | { |
| | | throw new Exception(messageValue ?? "提交失败"); |
| | | } |
| | | |
| | | // 存储过程执行成功后,处理钉钉推送逻辑 |
| | | // 检查钉钉推送条件:PSZT为待判,且不良原因、不良描述、所属车间不为空 |
| | | bool shouldPushToDingTalk = inspectionData.Pszt == "待判" && |
| | | !string.IsNullOrEmpty(inspectionData.Blyy) && |
| | |
| | | } |
| | | } |
| | | |
| | | // 更新检验单状态 |
| | | return db.Updateable<QsItemOqcReq>() |
| | | .SetColumns(it => it.Fsubmit == 1) // 设置提交状态为1(已提交) |
| | | .SetColumns(it => it.FcheckBy == userNo) // 设置检验人 |
| | | .SetColumns(it => it.FcheckDate == DateTime.Now) // 设置检验时间 |
| | | .Where(it => it.Id == id) |
| | | .ExecuteCommand(); |
| | | }); |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 获取附件信息 |
| | | /// </summary> |
| | | /// <param name="ItemNo">物料编码</param> |
| | | /// <param name="projName">项目名称(用于过滤)</param> |
| | | /// <returns>附件列表</returns> |
| | | public List<QamftpDto> GetAttachments(string ItemNo) |
| | | public List<QamftpDto> GetAttachments(string ItemNo, string projName = null) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | try |
| | | { |
| | | return db.Queryable<MesQamftp>() |
| | | var query = db.Queryable<MesQamftp>() |
| | | .Where(x => x.ItemNo == ItemNo) |
| | | .Where(x => x.Ftype == "入库检"); // 添加FTYPE = '入库检'的限制 |
| | | |
| | | // 如果传入了projName,则按Fversion过滤 |
| | | if (!string.IsNullOrEmpty(projName)) |
| | | { |
| | | query = query.Where(x => x.Fversion == projName); |
| | | } |
| | | |
| | | return query |
| | | .OrderBy(x => x.Fdate, OrderByType.Desc) |
| | | .Select(x => new QamftpDto |
| | | { |
| | |
| | | /// </summary> |
| | | /// <param name="itemNo">物料编码</param> |
| | | /// <param name="fileName">文件名</param> |
| | | /// <param name="ftpServer">FTP服务器地址</param> |
| | | /// <param name="projName">项目名称</param> |
| | | /// <returns>文件字节数组</returns> |
| | | public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer) |
| | | public byte[] GetFtpFile(string itemNo, string fileName, string projName = null) |
| | | { |
| | | // 参数验证 |
| | | if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer)) |
| | | if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName)) |
| | | { |
| | | throw new ArgumentException("参数不能为空: itemNo, fileName, ftpServer"); |
| | | throw new ArgumentException("参数不能为空: itemNo, fileName"); |
| | | } |
| | | |
| | | string ftpUser = "hm_ftp"; |
| | | string ftpPwd = "dell_123"; |
| | | string ftpServer = "ftp://192.168.1.100"; // 默认FTP服务器地址 |
| | | |
| | | // 标准化FTP服务器地址 |
| | | string normalizedServer = NormalizeFtpServer(ftpServer); |
| | | |
| | | // 构建FTP文件路径 - RKJ使用FQC文件夹 |
| | | string ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}"; |
| | | // 构建FTP文件路径 - RKJ使用FQC文件夹,如果有projName则使用projName作为路径的最后一段 |
| | | string ftpPath; |
| | | if (!string.IsNullOrEmpty(projName)) |
| | | { |
| | | ftpPath = $"{normalizedServer}/FQC/{itemNo}/{projName}/{fileName}"; |
| | | } |
| | | else |
| | | { |
| | | ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}"; |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | .ExecuteCommand(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片到检验项目的PICTURE字段 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="imageBytes">图片字节数组</param> |
| | | /// <param name="fileName">原始文件名</param> |
| | | /// <param name="createBy">创建人</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) UploadImageToPicture(decimal id, byte[] imageBytes, string fileName, string createBy) |
| | | { |
| | | try |
| | | { |
| | | if (imageBytes == null || imageBytes.Length == 0) |
| | | { |
| | | return (1, "图片数据为空"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(fileName)) |
| | | { |
| | | return (1, "文件名为空"); |
| | | } |
| | | |
| | | // 验证图片格式 |
| | | var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" }; |
| | | var extension = System.IO.Path.GetExtension(fileName).ToLower(); |
| | | if (!allowedExtensions.Contains(extension)) |
| | | { |
| | | return (1, "不支持的图片格式,仅支持:jpg, jpeg, png, gif, bmp, webp"); |
| | | } |
| | | |
| | | // 验证图片大小(限制为5MB) |
| | | if (imageBytes.Length > 5 * 1024 * 1024) |
| | | { |
| | | return (1, "图片大小不能超过5MB"); |
| | | } |
| | | |
| | | // 生成时间戳文件名,格式:1746945271304.jpg |
| | | var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); |
| | | var timestampFileName = $"{timestamp}{extension}"; |
| | | |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemOqcItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 更新PICTURE字段(LONG RAW类型)和TPICTURENAME字段(时间戳文件名) |
| | | var updateResult = db.Updateable<QsItemOqcItem>() |
| | | .SetColumns(s => s.Picture == imageBytes) |
| | | .SetColumns(s => s.TPicturename == timestampFileName) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片保存成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片保存失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片保存失败:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除检验项目的图片 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) DeleteImageFromPicture(decimal id) |
| | | { |
| | | try |
| | | { |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemOqcItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 清空PICTURE字段和TPICTURENAME字段 |
| | | var updateResult = db.Updateable<QsItemOqcItem>() |
| | | .SetColumns(s => s.Picture == null) |
| | | .SetColumns(s => s.TPicturename == null) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片删除成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片删除失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片删除失败:{ex.Message}"); |
| | | } |
| | | } |
| | | } |