| | |
| | | ) |
| | | ); |
| | | |
| | | // 添加线体筛选条件 |
| | | // 添加线体筛选条件(基于用户权限) |
| | | if (lineNo != null && lineNo.Length > 0) |
| | | { |
| | | query = query.Where((s, a, c, b) => lineNo.Contains(c.LineNo)); |
| | | } |
| | | |
| | | // 添加QC筛选条件:车间和线体 |
| | | if (!string.IsNullOrEmpty(queryObj.departmentId)) |
| | | { |
| | | // 如果指定了车间,筛选该车间下的线体 |
| | | query = query.Where((s, a, c, b) => c.DepotId.ToString() == queryObj.departmentId); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(queryObj.lineId)) |
| | | { |
| | | // 如果指定了线体,直接筛选线体 |
| | | query = query.Where((s, a, c, b) => c.LineNo == queryObj.lineId); |
| | | } |
| | | |
| | | // 添加状态筛选条件 - 明确匹配前端传递的值 |
| | |
| | | { |
| | | query = query.Where((s, a, c, b) => s.Fsubmit == 1); |
| | | } |
| | | } |
| | | |
| | | // 添加搜索条件 - 根据选择的搜索字段进行精确搜索 |
| | | if (!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField)) |
| | | { |
| | | switch (queryObj.searchField) |
| | | { |
| | | case "billNo": // 工单 |
| | | query = query.Where((s, a, c, b) => s.BillNo.Contains(queryObj.SearchValue)); |
| | | break; |
| | | case "releaseNo": // 检验单号 |
| | | query = query.Where((s, a, c, b) => s.ReleaseNo.Contains(queryObj.SearchValue)); |
| | | break; |
| | | case "daa020": // 产线 |
| | | query = query.Where((s, a, c, b) => c.LineNo.Contains(queryObj.SearchValue)); |
| | | break; |
| | | case "itemNo": // 物料编码 |
| | | query = query.Where((s, a, c, b) => s.ItemNo.Contains(queryObj.SearchValue)); |
| | | break; |
| | | case "itemName": // 物料名称 |
| | | query = query.Where((s, a, c, b) => b.ItemName.Contains(queryObj.SearchValue)); |
| | | break; |
| | | default: |
| | | // 如果没有指定字段或字段不匹配,使用原有的模糊查询逻辑作为兜底方案 |
| | | query = query.Where((s, a, c, b) => |
| | | s.ItemNo.Contains(queryObj.SearchValue) || |
| | | b.ItemName.Contains(queryObj.SearchValue) || |
| | | s.BillNo.Contains(queryObj.SearchValue) || |
| | | s.ReleaseNo.Contains(queryObj.SearchValue) || |
| | | c.LineNo.Contains(queryObj.SearchValue)); |
| | | break; |
| | | } |
| | | } |
| | | // 为了兼容旧版本,如果没有传递 searchField,使用原来的查询逻辑 |
| | | else if (string.IsNullOrEmpty(queryObj.searchField) && !string.IsNullOrEmpty(queryObj.SearchValue)) |
| | | { |
| | | // 保持原有的多字段模糊查询逻辑 |
| | | query = query.Where((s, a, c, b) => |
| | | s.ItemNo.Contains(queryObj.SearchValue) || |
| | | b.ItemName.Contains(queryObj.SearchValue) || |
| | | s.BillNo.Contains(queryObj.SearchValue) || |
| | | s.ReleaseNo.Contains(queryObj.SearchValue) || |
| | | c.LineNo.Contains(queryObj.SearchValue)); |
| | | } |
| | | |
| | | // 添加ID筛选条件 |
| | |
| | | var qsQaItemXj01s = db.Queryable<QsQaItemXj01>() |
| | | .WhereIF(pid > 0, a => a.Pid == pid) |
| | | .WhereIF(id > 0, a => a.Id == id) |
| | | .OrderBy(a => a.Forder ?? 0) |
| | | .ToList(); |
| | | |
| | | var array = qsQaItemXj01s.Select(s => s.Id).ToArray(); |
| | |
| | | s.imageData = Convert.ToBase64String(s.Picture); |
| | | }); |
| | | |
| | | //排序,未完成的排在前面 |
| | | qsQaItemXj01s = qsQaItemXj01s.OrderBy(s => s.isCheck).ToList(); |
| | | //排序:只按FORDER顺序排序 |
| | | qsQaItemXj01s = qsQaItemXj01s |
| | | .OrderBy(s => s.Forder ?? 0) |
| | | .ToList(); |
| | | |
| | | return qsQaItemXj01s; |
| | | } |
| | |
| | | var xjDto = new XJDto(); |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | var qsQaItemXj01 = |
| | | db.Queryable<QsQaItemXj01>().Single(s => s.Id == id); |
| | | |
| | | // 使用JOIN查询获取子表数据和主表的ItemNo字段 |
| | | var qsQaItemXj01 = db |
| | | .Queryable<QsQaItemXj01, QsQaItemXj>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id)) |
| | | .Where((a, b) => a.Id == id) |
| | | .Select((a, b) => new QsQaItemXj01 |
| | | { |
| | | 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, |
| | | // 添加主表的ItemNo字段 |
| | | ItemNo = b.ItemNo |
| | | }).Single(); |
| | | |
| | | if (qsQaItemXj01.IsPass == 0) |
| | | qsQaItemXj01.result = "不合格"; |
| | |
| | | Convert.ToBase64String(qsQaItemXj01.Picture); |
| | | |
| | | xjDto.ItemXj01 = qsQaItemXj01; |
| | | |
| | | |
| | | xjDto.ItemXj02s = db.Queryable<QsQaItemXj02>().Where(s => s.Pid == id) |
| | | .ToList(); |
| | |
| | | /// 获取附件信息 |
| | | /// </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) |
| | | .OrderBy(x => x.Fdate, OrderByType.Desc) |
| | | .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 |
| | | { |
| | | Id = x.Id, |
| | |
| | | /// <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 ftpServer, string projName = null) |
| | | { |
| | | // 参数验证 |
| | | if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer)) |
| | |
| | | // 标准化FTP服务器地址 |
| | | string normalizedServer = NormalizeFtpServer(ftpServer); |
| | | |
| | | // 构建FTP文件路径 - 巡检使用OPC目录 |
| | | string ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}"; |
| | | // 构建FTP文件路径 - 巡检使用OPC目录,如果传入了projName则使用新格式 |
| | | string ftpPath; |
| | | if (!string.IsNullOrEmpty(projName)) |
| | | { |
| | | ftpPath = $"{normalizedServer}/OPC/{itemNo}/{projName}/{fileName}"; |
| | | } |
| | | else |
| | | { |
| | | ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}"; |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | /// <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<QsQaItemXj01>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 更新PICTURE字段(LONG RAW类型)和PICTURENAME字段(时间戳文件名) |
| | | var updateResult = db.Updateable<QsQaItemXj01>() |
| | | .SetColumns(s => s.Picture == imageBytes) |
| | | .SetColumns(s => s.Picturename == 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<QsQaItemXj01>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 清空PICTURE字段和PICTURENAME字段 |
| | | var updateResult = db.Updateable<QsQaItemXj01>() |
| | | .SetColumns(s => s.Picture == null) |
| | | .SetColumns(s => s.Picturename == null) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片删除成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片删除失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片删除失败:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |