| | |
| | | if (!string.IsNullOrEmpty(rkjDto.RbillNo)) |
| | | xj.RbillNo = rkjDto.RbillNo; |
| | | |
| | | // 确保Quantity字段被正确设置 |
| | | // 确保工单数量字段被正确设置(QUANTITY) |
| | | if (xj.Quantity == null && rkjDto.quantity != null) |
| | | { |
| | | xj.Quantity = rkjDto.quantity; |
| | | } |
| | | |
| | | // 确保送检数量字段被正确设置(SJQTY) |
| | | if (xj.Sjqty == null && rkjDto.sjqty != null) |
| | | { |
| | | xj.Sjqty = rkjDto.sjqty; |
| | | } |
| | | |
| | | // 确保提交状态被正确设置(默认为未提交) |
| | |
| | | detail.Pid = s.Id; |
| | | detail.Gid = rkjDto.gid; |
| | | detail.Fstand = "√"; |
| | | detail.FcheckResu = "1"; |
| | | detail.FcheckResu = "OK"; |
| | | detail.UpdateBy = rkjDto.userNo; |
| | | detail.count = (int?)s.LevelNum; |
| | | SetQSItemDetail(detail); |
| | |
| | | } |
| | | |
| | | |
| | | public List<QsItemOqcReq> getPage(XJPageResult queryObj) |
| | | public (List<QsItemOqcReq>, int) getPage(XJPageResult queryObj) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | |
| | | if (StringUtil.IsNotNullOrEmpty(queryObj.createUser)) |
| | | lineNo = _baseService.getUserLineNo(queryObj.createUser); |
| | | |
| | | var totalCount = 0; |
| | | |
| | | return db |
| | | var data = db |
| | | .Queryable<QsItemOqcReq, Womdaa, MesItems, MesLine>((a, da, b, m) => |
| | | new JoinQueryInfos( |
| | | JoinType.Left, da.Daa001 == a.BillNo, |
| | |
| | | ItemName = b.ItemName, |
| | | ItemModel = b.ItemModel, |
| | | Daa015 = da.Daa015, |
| | | Quantity = a.Quantity |
| | | Quantity = a.Quantity, // 工单数量 |
| | | Sjqty = a.Sjqty // 送检数量 |
| | | }).OrderBy(a => a.CreateDate, OrderByType.Desc) |
| | | .ToPageList(queryObj.PageIndex, queryObj.Limit); |
| | | .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount); |
| | | |
| | | // 修正检验结果:如果显示为“合格”但没有检验项目,则改为空(待检验) |
| | | if (data.Count > 0) |
| | | { |
| | | var ids = data.Select(d => d.Id).ToList(); |
| | | |
| | | // 批量查询检验项目数量 |
| | | var itemCounts = db.Queryable<QsItemOqcItem>() |
| | | .Where(item => ids.Contains(item.Pid.Value)) |
| | | .GroupBy(item => item.Pid) |
| | | .Select(g => new { Pid = g.Pid, Count = SqlFunc.AggregateCount(g.Id) }) |
| | | .ToList(); |
| | | |
| | | // 修正每条记录的检验结果 |
| | | foreach (var item in data) |
| | | { |
| | | var itemCount = itemCounts.FirstOrDefault(ic => ic.Pid == item.Id); |
| | | var hasItems = itemCount != null && itemCount.Count > 0; |
| | | |
| | | // 如果没有检验项目,则将检验结果清空(显示为待检验) |
| | | if (!hasItems) |
| | | { |
| | | item.FcheckResu = null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return (data, totalCount); |
| | | } |
| | | |
| | | //删除主表并且连级删除子表和孙表 |
| | |
| | | if (qsItemOqcItem.Picture is { Length: > 0 }) |
| | | qsItemOqcItem.imageData = |
| | | Convert.ToBase64String(qsItemOqcItem.Picture); |
| | | |
| | | // 从 QS_ITEM_IPI_IMAGE 表中获取图片列表(入库检 QS_TYPE=3) |
| | | var imageRecords = db.Queryable<QsItemIpiImage>() |
| | | .Where(s => s.Fid == id && s.QsType == 3 && s.ImageData != null) |
| | | .ToList(); |
| | | |
| | | if (imageRecords.Count > 0) |
| | | { |
| | | qsItemOqcItem.imageList = new List<ImageInfo>(); |
| | | foreach (var img in imageRecords) |
| | | { |
| | | if (img.ImageData != null && img.ImageData.Length > 0) |
| | | { |
| | | qsItemOqcItem.imageList.Add(new ImageInfo |
| | | { |
| | | Id = img.Id ?? 0, |
| | | FileName = img.Picturename, |
| | | Base64Data = Convert.ToBase64String(img.ImageData), |
| | | CreateDate = img.CreateDate, |
| | | CreateBy = img.CreateBy |
| | | }); |
| | | } |
| | | } |
| | | // 保持向后兼容 |
| | | if (qsItemOqcItem.imageList.Count > 0 && string.IsNullOrEmpty(qsItemOqcItem.imageData)) |
| | | { |
| | | qsItemOqcItem.imageData = qsItemOqcItem.imageList[0].Base64Data; |
| | | } |
| | | } |
| | | |
| | | //获取不合格数 |
| | | var count = db.Queryable<QsItemOqcItemDetail>() |
| | |
| | | detail.Pid = s.Id; |
| | | detail.Gid = rkjDto.gid; |
| | | detail.Fstand = "√"; |
| | | detail.FcheckResu = "1"; |
| | | detail.FcheckResu = "OK"; |
| | | detail.UpdateBy = rkjDto.userNo; |
| | | detail.count = (int?)s.LevelNum; |
| | | SetQSItemDetail(detail); |
| | |
| | | /// <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> |
| | | /// 上传图片到检验项目的PICTURE字段 |
| | | /// 上传图片到 QS_ITEM_IPI_IMAGE 表(入库检 QS_TYPE=3,支持多图片) |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="id">检验项目ID (FID)</param> |
| | | /// <param name="imageBytes">图片字节数组</param> |
| | | /// <param name="fileName">原始文件名</param> |
| | | /// <param name="createBy">创建人</param> |
| | |
| | | |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemOqcItem>() |
| | | // 检查检验项目是否存在,并获取检验单ID和检验项目名称 |
| | | var oqcItem = db.Queryable<QsItemOqcItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | .Select(s => new { s.Id, s.Pid, s.ProjName }) |
| | | .First(); |
| | | |
| | | if (!exists) |
| | | if (oqcItem == null) |
| | | { |
| | | 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; |
| | | // 每次都创建新的图片记录,支持多图片上传 |
| | | var newImage = new QsItemIpiImage |
| | | { |
| | | Fid = id, // 检验项目ID (QS_ITEM_OQC_ITEM.ID) |
| | | Gid = oqcItem.Pid, // 检验单ID (QS_ITEM_OQC_REQ.ID) |
| | | QsType = 3, // 入库检类型 |
| | | ImageData = imageBytes, |
| | | Picturename = timestampFileName, |
| | | JyName = oqcItem.ProjName, // 检验项目名称 |
| | | CreateDate = DateTime.Now, |
| | | CreateBy = createBy |
| | | }; |
| | | return db.Insertable(newImage).ExecuteCommand(); |
| | | }); |
| | | |
| | | if (result > 0) |
| | |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片保存失败,未找到对应的检验项目"); |
| | | return (1, "图片保存失败"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除检验项目的图片 |
| | | /// 删除检验项目的图片(从 QS_ITEM_IPI_IMAGE 表中删除,入库检 QS_TYPE=3) |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="id">检验项目ID (FID),当imageId为空时删除该检验项目的所有图片</param> |
| | | /// <param name="imageId">图片ID,用于删除单张图片(可选)</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) DeleteImageFromPicture(decimal id) |
| | | public (int status, string message) DeleteImageFromPicture(decimal id, decimal? imageId = null) |
| | | { |
| | | try |
| | | { |
| | |
| | | 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(); |
| | | int deleteResult; |
| | | if (imageId.HasValue && imageId.Value > 0) |
| | | { |
| | | // 删除单张图片 |
| | | deleteResult = db.Deleteable<QsItemIpiImage>() |
| | | .Where(s => s.Id == imageId.Value && s.Fid == id && s.QsType == 3) |
| | | .ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | // 删除该检验项目的所有图片 |
| | | deleteResult = db.Deleteable<QsItemIpiImage>() |
| | | .Where(s => s.Fid == id && s.QsType == 3) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | return updateResult; |
| | | return deleteResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片删除失败,未找到对应的检验项目"); |
| | | return (0, "没有找到要删除的图片"); |
| | | } |
| | | } |
| | | catch (Exception ex) |