111
啊鑫
2 天以前 e937af660a22640ace71147853cb70078673928f
MES.Service/service/QC/XJService.cs
@@ -107,7 +107,8 @@
                }).ToList();
    }
    public (List<QsQaItemXj> items, int totalCount) getPage(XJPageResult queryObj)
    public (List<QsQaItemXj> items, int totalCount) getPage(
        XJPageResult queryObj)
    {
        var db = SqlSugarHelper.GetInstance();
@@ -120,13 +121,14 @@
        //if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
        //    lineNo = _baseService.getUserLineNo(queryObj.createUser);
       var query= db
        var query = db
            .Queryable<QsQaItemXj, Womdaa, MesLine,
                MesItems>((s, a, c, b) =>
                MesItems, SysUser>((s, a, c, b, us) =>
                new JoinQueryInfos(
                    JoinType.Inner, s.BillNo == a.Daa001,
                    JoinType.Left, a.Daa015 == c.LineNo,
                    JoinType.Left, s.ItemId == b.Id
                    JoinType.Left, s.ItemId == b.Id,
                    JoinType.Left, us.Fcode == s.CreateBy
                )
            )
            //.WhereIF(lineNo != null && lineNo.Length > 0,
@@ -134,17 +136,20 @@
            .WhereIF(
                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                "未完成".Equals(queryObj.result),
                (s, a, c, b) => s.SubmitStatus == 0 || s.SubmitStatus == null)
                (s, a, c, b, us) =>
                    s.SubmitStatus == 0 || s.SubmitStatus == null)
            .WhereIF(
                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                !"未完成".Equals(queryObj.result),
                (s, a, c, b) => s.SubmitStatus == 1)
            .WhereIF(id > 0, (s, a, c, b) => s.Id == id)
            .Select((s, a, c, b) => new QsQaItemXj
                (s, a, c, b, us) => s.SubmitStatus == 1)
            .WhereIF(id > 0, (s, a, c, b, us) => s.Id == id)
            .Select((s, a, c, b, us) => new QsQaItemXj
            {
                Daa020 = c.LineNo,
                Id = s.Id,
                PlanQty = a.Daa008,
                LineName = c.LineName,
                CreateUser = us.Fname,
                CreateBy = s.CreateBy,
                CreateDate = s.CreateDate,
                ReleaseNo = s.ReleaseNo,
@@ -156,7 +161,8 @@
                CheckResult = s.CheckResult,
                Remarks = s.Remarks
            }).OrderBy(s => s.CreateDate, OrderByType.Desc);
        var items = query.ToPageList(queryObj.PageIndex, queryObj.Limit,ref totalCount);
        var items = query.ToPageList(queryObj.PageIndex, queryObj.Limit,
            ref totalCount);
        return (items, totalCount);
    }
@@ -174,29 +180,28 @@
        return db
            .Queryable<MesQualityStandard>()
            .Where(b => b.QsType == "2"
                        && b.ItemNo == itemNo).Select(
                b => new QsQaItemXj01
                {
                    ProjName = b.ProjName,
                    ItemMod = b.ItemMod,
                    InspectionMethod = b.InspectionMethod,
                    UsingInstruments = b.UsingInstruments,
                    LevelNum = SqlFunc.IsNull(
                        SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
                        b.InspectionLevel),
                    MaxValue = b.MaxValue,
                    StandardValue = b.StandardValue,
                    MinValue = b.MinValue,
                    Notes = b.Notes,
                    FcheckLevel = b.FcheckLevel,
                    FacLevel = b.FacLevel,
                    QsCode = b.QsCode,
                    QsName = b.QsName,
                    result = "未检测",
                    isCheck = 0,
                    Picture = b.Picture,
                    Picturename = b.Picturename
                }).ToList();
                        && b.ItemNo == itemNo).Select(b => new QsQaItemXj01
            {
                ProjName = b.ProjName,
                ItemMod = b.ItemMod,
                InspectionMethod = b.InspectionMethod,
                UsingInstruments = b.UsingInstruments,
                LevelNum = SqlFunc.IsNull(
                    SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
                    b.InspectionLevel),
                MaxValue = b.MaxValue,
                StandardValue = b.StandardValue,
                MinValue = b.MinValue,
                Notes = b.Notes,
                FcheckLevel = b.FcheckLevel,
                FacLevel = b.FacLevel,
                QsCode = b.QsCode,
                QsName = b.QsName,
                result = "未检测",
                isCheck = 0,
                Picture = b.Picture,
                Picturename = b.Picturename
            }).ToList();
    }
    public List<QsQaItemXj01> getJYItem(decimal? pid, decimal? id)
@@ -292,7 +297,7 @@
        return Convert.ToInt32(xj.Id);
    }
    public bool XJQaSubmit(LLJDto rkjDto)
    {
        var useTransactionWithOracle =
@@ -357,20 +362,22 @@
            // 获取检验项目数据
            var jyItems = getJYItemOptimized(db, xjDto.gid.Value);
            if (jyItems.Any())
            {
                // 处理业务逻辑计算
                var allDetails = PrepareDetailsData(jyItems, xjDto.gid.Value, userNo);
                var allDetails =
                    PrepareDetailsData(jyItems, xjDto.gid.Value, userNo);
                if (allDetails.Count > 0)
                {
                    // 批量插入检验详情
                    db.Insertable(allDetails).ExecuteCommand();
                    // 计算结果
                    var (pidResults, fcheckResu) = CalculateResults(allDetails, jyItems);
                    var (pidResults, fcheckResu) =
                        CalculateResults(allDetails, jyItems);
                    // 批量更新检验项目结果
                    foreach (var (pidValue, result) in pidResults)
                    {
@@ -381,7 +388,9 @@
                    }
                    // 更新主表检验结果
                    var totalSum = jyItems.Where(x => x.MaxValue == null && x.StandardValue == null && x.MinValue == null)
                    var totalSum = jyItems.Where(x =>
                            x.MaxValue == null && x.StandardValue == null &&
                            x.MinValue == null)
                        .Sum(x => x.LevelNum);
                    if (totalSum == allDetails.Count)
                    {
@@ -400,33 +409,39 @@
            return Convert.ToInt32(xjDto.gid);
        });
    }
    private List<QsQaItemXj01> getJYItemOptimized(ISqlSugarClient db, decimal xjId)
    private List<QsQaItemXj01> getJYItemOptimized(ISqlSugarClient db,
        decimal xjId)
    {
        return db.Queryable<QsQaItemXj01>()
            .Where(a => a.Pid == xjId)
            .ToList();
    }
    private (bool isValid, string errorMsg) ValidateItemsData(List<QsQaItemXj01> items)
    private (bool isValid, string errorMsg) ValidateItemsData(
        List<QsQaItemXj01> items)
    {
        if (items == null || !items.Any()) return (false, "检验项目不能为空");
        var invalidItems = items.Where(x => x.LevelNum <= 0 || string.IsNullOrEmpty(x.ProjName)).ToList();
        if (invalidItems.Any())
        var invalidItems = items
            .Where(x => x.LevelNum <= 0 || string.IsNullOrEmpty(x.ProjName))
            .ToList();
        if (invalidItems.Any())
            return (false, $"存在{invalidItems.Count}个无效的检验项目");
        return (true, "");
    }
    private List<QsQaItemXj02> PrepareDetailsData(List<QsQaItemXj01> jyItems, decimal gid, string userNo)
    private List<QsQaItemXj02> PrepareDetailsData(List<QsQaItemXj01> jyItems,
        decimal gid, string userNo)
    {
        var allDetails = new List<QsQaItemXj02>();
        var now = DateTime.Now;
        foreach (var s in jyItems)
        {
            if (s.MaxValue != null || s.StandardValue != null || s.MinValue != null)
            if (s.MaxValue != null || s.StandardValue != null ||
                s.MinValue != null)
                continue;
            for (var i = 0; i < s.LevelNum; i++)
@@ -442,15 +457,17 @@
                });
            }
        }
        return allDetails;
    }
    private (List<(decimal pid, int result)> pidResults, string fcheckResu) CalculateResults(
        List<QsQaItemXj02> allDetails, List<QsQaItemXj01> jyItems)
    private (List<(decimal pid, int result)> pidResults, string fcheckResu)
        CalculateResults(
            List<QsQaItemXj02> allDetails, List<QsQaItemXj01> jyItems)
    {
        var pidGroups = allDetails.GroupBy(x => x.Pid).ToList();
        var pidResults = new List<(decimal pid, int result)>();
        foreach (var group in pidGroups)
        {
            var count = group.Count();
@@ -459,11 +476,16 @@
            pidResults.Add((group.Key.Value, result));
        }
        var totalSum = jyItems.Where(x => x.MaxValue == null && x.StandardValue == null && x.MinValue == null)
        var totalSum = jyItems.Where(x =>
                x.MaxValue == null && x.StandardValue == null &&
                x.MinValue == null)
            .Sum(x => x.LevelNum);
        var totalCount = allDetails.Count;
        var totalPassCount = allDetails.Count(x => x.Fstand == "√");
        var fcheckResu = (totalSum == totalCount && totalCount == totalPassCount) ? "合格" : "不合格";
        var fcheckResu =
            (totalSum == totalCount && totalCount == totalPassCount)
                ? "合格"
                : "不合格";
        return (pidResults, fcheckResu);
    }
@@ -547,8 +569,8 @@
        if (count == passCount) result = 1;
        var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle(
            db =>
        var useTransactionWithOracle =
            SqlSugarHelper.UseTransactionWithOracle(db =>
            {
                var commit = 0;
                commit += db.Updateable<QsQaItemXj01>()