xwt
6 天以前 e853dd2fecef3a0c446d161248d0498a5a081e66
StandardInterface/MES.Service/service/QC/XJService.cs
@@ -153,10 +153,23 @@
                )
            );
            
        // 添加线体筛选条件
        // 添加线体筛选条件(基于用户权限)
        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);
        }
        
        // 添加状态筛选条件 - 明确匹配前端传递的值
@@ -287,6 +300,7 @@
        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();
@@ -323,8 +337,52 @@
                s.imageData = Convert.ToBase64String(s.Picture);
        });
        //排序,未完成的排在前面
        qsQaItemXj01s = qsQaItemXj01s.OrderBy(s => s.isCheck).ToList();
        // 从 QS_ITEM_IPI_IMAGE 表中获取图片数据(支持多图片,巡检 QS_TYPE=2)
        var itemIds = qsQaItemXj01s.Select(s => s.Id).ToArray();
        var imageList = db.Queryable<QsItemIpiImage>()
            .Where(s => itemIds.Contains(s.Fid) && s.QsType == 2 && s.ImageData != null)
            .ToList();
        if (imageList.Count > 0)
        {
            // 按检验项目ID分组
            var imageGroups = imageList.GroupBy(img => img.Fid);
            foreach (var group in imageGroups)
            {
                var xjItem = qsQaItemXj01s.Find(t => t.Id == group.Key);
                if (xjItem != null)
                {
                    // 初始化图片列表
                    xjItem.imageList = new List<ImageInfo>();
                    foreach (var img in group)
                    {
                        if (img.ImageData != null && img.ImageData.Length > 0)
                        {
                            xjItem.imageList.Add(new ImageInfo
                            {
                                Id = img.Id ?? 0,
                                FileName = img.Picturename,
                                Base64Data = Convert.ToBase64String(img.ImageData),
                                CreateDate = img.CreateDate,
                                CreateBy = img.CreateBy
                            });
                        }
                    }
                    // 保持向后兼容:如果有图片,设置第一张图片为 imageData
                    if (xjItem.imageList.Count > 0)
                    {
                        xjItem.imageData = xjItem.imageList[0].Base64Data;
                    }
                }
            }
        }
        //排序:只按FORDER顺序排序
        qsQaItemXj01s = qsQaItemXj01s
            .OrderBy(s => s.Forder ?? 0)
            .ToList();
        return qsQaItemXj01s;
    }
@@ -458,6 +516,35 @@
        if (qsQaItemXj01.Picture is { Length: > 0 })
            qsQaItemXj01.imageData =
                Convert.ToBase64String(qsQaItemXj01.Picture);
        // 从 QS_ITEM_IPI_IMAGE 表中获取图片列表(巡检 QS_TYPE=2)
        var imageRecords = db.Queryable<QsItemIpiImage>()
            .Where(s => s.Fid == id && s.QsType == 2 && s.ImageData != null)
            .ToList();
        if (imageRecords.Count > 0)
        {
            qsQaItemXj01.imageList = new List<ImageInfo>();
            foreach (var img in imageRecords)
            {
                if (img.ImageData != null && img.ImageData.Length > 0)
                {
                    qsQaItemXj01.imageList.Add(new ImageInfo
                    {
                        Id = img.Id ?? 0,
                        FileName = img.Picturename,
                        Base64Data = Convert.ToBase64String(img.ImageData),
                        CreateDate = img.CreateDate,
                        CreateBy = img.CreateBy
                    });
                }
            }
            // 保持向后兼容
            if (qsQaItemXj01.imageList.Count > 0)
            {
                qsQaItemXj01.imageData = qsQaItemXj01.imageList[0].Base64Data;
            }
        }
        xjDto.ItemXj01 = qsQaItemXj01;
@@ -678,24 +765,39 @@
    {
        try
        {
            var db = SqlSugarHelper.GetInstance();
            // 直接更新Fsubmit字段为1(已提交状态)
            var result = db.Updateable<QsQaItemXj>()
                .SetColumns(s => s.Fsubmit == 1)
                .SetColumns(s => s.FsubmitBy == dto.userNo)
                .SetColumns(s => s.FsubmitDate == DateTime.Now)
                .Where(s => s.Id == dto.id)
                .ExecuteCommand();
            // 定义输出参数
            var outputResult = new SugarParameter("c_res", null,
                System.Data.DbType.Int32, ParameterDirection.Output,
                4000);
            if (result > 0)
            var outputMessage = new SugarParameter("c_msg", null,
                System.Data.DbType.String,
                ParameterDirection.Output, 4000);
            // 定义输入参数,固定FLAG为1(审核)
            var parameters = new List<SugarParameter>
            {
                return true;
            }
            else
            {
                throw new Exception("提交失败:未找到对应的检验单");
            }
                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_XJ_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)
        {
@@ -1002,9 +1104,9 @@
    }
    /// <summary>
    /// 上传图片到检验项目的PICTURE字段
    /// 上传图片到 QS_ITEM_IPI_IMAGE 表(巡检 QS_TYPE=2)
    /// </summary>
    /// <param name="id">检验项目ID</param>
    /// <param name="id">检验项目ID (FID)</param>
    /// <param name="imageBytes">图片字节数组</param>
    /// <param name="fileName">原始文件名</param>
    /// <param name="createBy">创建人</param>
@@ -1037,30 +1139,34 @@
                return (1, "图片大小不能超过5MB");
            }
            // 生成时间戳文件名,格式:1746945271304.jpg
            var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            var timestampFileName = $"{timestamp}{extension}";
            var result = SqlSugarHelper.UseTransactionWithOracle(db =>
            {
                // 检查检验项目是否存在
                var exists = db.Queryable<QsQaItemXj01>()
                // 检查检验项目是否存在,并获取检验单ID (GID) 和 检验项目名称
                var xjItem = db.Queryable<QsQaItemXj01>()
                    .Where(s => s.Id == id)
                    .Any();
                    .Select(s => new { s.Id, s.Pid, s.ProjName })
                    .First();
                if (!exists)
                if (xjItem == null)
                {
                    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();
                // 每次都创建新的图片记录,支持多图片上传
                var newImage = new QsItemIpiImage
                {
                    Fid = id,                        // 检验项目ID
                    Gid = xjItem.Pid,                // 检验单ID
                    QsType = 2,                      // 巡检类型
                    ImageData = imageBytes,          // 图片二进制数据
                    Picturename = fileName,          // 保留原始文件名
                    JyName = xjItem.ProjName,        // 检验项目名称
                    CreateDate = DateTime.Now,       // 创建时间
                    CreateBy = createBy              // 创建人
                };
                return updateResult;
                var insertResult = db.Insertable(newImage).ExecuteCommand();
                return insertResult;
            });
            if (result > 0)
@@ -1069,7 +1175,7 @@
            }
            else
            {
                return (1, "图片保存失败,未找到对应的检验项目");
                return (1, "图片保存失败");
            }
        }
        catch (Exception ex)
@@ -1079,11 +1185,12 @@
    }
    /// <summary>
    /// 删除检验项目的图片
    /// 删除检验项目的图片(从 QS_ITEM_IPI_IMAGE 表中删除,巡检 QS_TYPE=2)
    /// </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
        {
@@ -1099,14 +1206,23 @@
                    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();
                int deleteResult;
                if (imageId.HasValue)
                {
                    // 删除指定的单张图片
                    deleteResult = db.Deleteable<QsItemIpiImage>()
                        .Where(s => s.Id == imageId.Value && s.Fid == id && s.QsType == 2)
                        .ExecuteCommand();
                }
                else
                {
                    // 删除该检验项目的所有图片
                    deleteResult = db.Deleteable<QsItemIpiImage>()
                        .Where(s => s.Fid == id && s.QsType == 2)
                        .ExecuteCommand();
                }
                return updateResult;
                return deleteResult;
            });
            if (result > 0)
@@ -1115,7 +1231,7 @@
            }
            else
            {
                return (1, "图片删除失败,未找到对应的检验项目");
                return (1, "图片删除失败,未找到对应的图片记录");
            }
        }
        catch (Exception ex)