| | |
| | | { |
| | | public (List<LtsLlj> item, int TotalCount) GetPage(XJPageResult queryObj) |
| | | { |
| | | if (queryObj == null) |
| | | throw new ArgumentNullException(nameof(queryObj)); |
| | | |
| | | if (string.IsNullOrEmpty(queryObj.createUser)) |
| | | return (new List<LtsLlj>(), 0); |
| | | |
| | | if (queryObj.createUser.IsNullOrEmpty()) return ([], 0); |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | var id = Convert.ToDecimal(queryObj.id); |
| | | //安全的类型转换 |
| | | if (!decimal.TryParse(queryObj.id, out var id)) |
| | | id = 0; |
| | | |
| | | var totalCount = 0; |
| | | |
| | |
| | | |
| | | //加筛选条件,根据供应商,物料编码,物料名称搜索 |
| | | //.WhereIF(queryObj.SearchValue!=null && queryObj.SearchValue!="", (a) => a.SuppName == queryObj.SearchValue|| a.ItemName == queryObj.SearchValue || a.ItemNo == queryObj.SearchValue ) |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue), |
| | | a => a.SuppName.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()) |
| | | || a.ItemName.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()) |
| | | || a.ItemNo.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower())) |
| | | .WhereIF( |
| | | queryObj.SelectedIndex == "0" && |
| | | !string.IsNullOrEmpty(queryObj.SearchValue), |
| | | a => (a.ItemNo.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()))) |
| | | .WhereIF( |
| | | queryObj.SelectedIndex == "1" && |
| | | !string.IsNullOrEmpty(queryObj.SearchValue), |
| | | a => (a.ItemName.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()))) |
| | | .WhereIF( |
| | | queryObj.SelectedIndex == "2" && |
| | | !string.IsNullOrEmpty(queryObj.SearchValue), |
| | | a => (a.SuppName.ToLower() |
| | | .Contains(queryObj.SearchValue.ToLower()))) |
| | | .WhereIF(queryObj.result == "已完成", |
| | | a => (a.IqcDate >= queryObj.startDate.ToDateTime() && |
| | | a.IqcDate <= queryObj.endDate.ToDateTime().AddDays(1))) |
| | | .WhereIF(queryObj.result == "已完成" && queryObj.state != "所有状态", |
| | | a => a.FcheckResu == queryObj.state) |
| | | .OrderByDescending(a => a.Id) |
| | | .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount); |
| | | |
| | |
| | | // FcheckItem = b.FcheckItem, |
| | | // FdownAllow = b.FdownAllow, |
| | | // FcheckLevel = b.Frequency, |
| | | // Fstand = b.Fstand, |
| | | // Fstand = decimal.Parse(b.Fstand), |
| | | // FupAllow = b.FupAllow, |
| | | // SampleSizeNo = b.SampleSizeNo, |
| | | // FenterQty = 0, |
| | |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | return db.Queryable<MesQaItemsDetectDetail5, MesQaItemsDetectDetail12>( |
| | | (a, b) => |
| | | new JoinQueryInfos(JoinType.Left, a.Id == b.MainId)) |
| | | return db |
| | | .Queryable<MesQaItemsDetectDetail5, |
| | | MesQaItemsDetectDetail12>((a, b) => |
| | | new JoinQueryInfos(JoinType.Left, a.Id == b.MainId)) |
| | | .Where((a, b) => a.ReleaseNo == releaseNo) |
| | | // .WhereIF(id > 0, (a, b) => a.Id == id) |
| | | .GroupBy((a, b) => new |
| | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 自动处理检验结果的主方法 |
| | | /// </summary> |
| | | private int autoResult(MesQaItemsDetectDetail12 detail) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | // 获取检验项目信息 |
| | | var inspectionItem = GetInspectionItem(detail.MainId); |
| | | if (inspectionItem == null) return 0; |
| | | |
| | | // Single 没有查询到结果时返回Null,如果结果大于1条会抛出错误 |
| | | var QsItemOqcItem = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Single(s => s.Id == detail.MainId); |
| | | |
| | | if (QsItemOqcItem == null) return 0; |
| | | |
| | | //查询这个检验项目下的检验结果 |
| | | var count = db.Queryable<MesQaItemsDetectDetail12>() |
| | | .Where(s => s.MainId == detail.MainId).Count(); |
| | | |
| | | // 获取检验计数信息 |
| | | var inspectionCounts = GetInspectionCounts(detail.MainId); |
| | | |
| | | // 更新检验明细 |
| | | updateDetail5(detail); |
| | | var result = ""; |
| | | |
| | | //检验实际结果不等于应该检验的个数时直接推出 |
| | | if (QsItemOqcItem.CheckQyt != count) return 0; |
| | | // 检查是否检验完成 |
| | | if (!IsInspectionItemComplete(inspectionItem, inspectionCounts.TotalCount)) |
| | | return 0; |
| | | |
| | | //合格的有多少个 |
| | | // 确定检验结果 |
| | | var itemResult = DetermineInspectionItemResult(inspectionCounts, inspectionItem); |
| | | |
| | | // 更新检验项目结果 |
| | | var updateResult = UpdateInspectionItemResult(detail.MainId, itemResult, inspectionCounts.TotalCount); |
| | | |
| | | // 检查整个检验单是否完成 |
| | | if (IsInspectionOrderComplete(detail.ReleaseNo)) |
| | | { |
| | | ProcessCompleteInspectionOrder(detail); |
| | | } |
| | | |
| | | return updateResult; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取检验项目信息 |
| | | /// </summary> |
| | | private MesQaItemsDetectDetail5? GetInspectionItem(decimal? mainId) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | return db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Single(s => s.Id == mainId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取检验计数信息 |
| | | /// </summary> |
| | | private (int TotalCount, int PassCount, int FailCount) GetInspectionCounts(decimal? mainId) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | var totalCount = db.Queryable<MesQaItemsDetectDetail12>() |
| | | .Where(s => s.MainId == mainId).Count(); |
| | | |
| | | var passCount = db.Queryable<MesQaItemsDetectDetail12>() |
| | | .Where(s => s.MainId == detail.MainId && s.Fstand == "√").Count(); |
| | | //不合格的有多少个 |
| | | var noCount = db.Queryable<MesQaItemsDetectDetail12>() |
| | | .Where(s => s.MainId == detail.MainId && s.Fstand == "×").Count(); |
| | | .Where(s => s.MainId == mainId && s.Fstand == "√").Count(); |
| | | |
| | | var failCount = db.Queryable<MesQaItemsDetectDetail12>() |
| | | .Where(s => s.MainId == mainId && s.Fstand == "×").Count(); |
| | | |
| | | if (count == passCount) |
| | | result = "合格"; |
| | | //else if (count - passCount < QsItemOqcItem.FreQty) |
| | | // result = "不合格"; |
| | | else if (noCount >= QsItemOqcItem.FreQty) |
| | | result = "不合格"; |
| | | var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle( |
| | | db => |
| | | { |
| | | var commit = 0; |
| | | commit += db.Updateable<MesQaItemsDetectDetail5>() |
| | | .SetColumns(s => s.FcheckResu == result) |
| | | .SetColumns(s => s.FenterQty == count) |
| | | .Where(s => s.Id == detail.MainId) |
| | | .ExecuteCommand(); |
| | | return (totalCount, passCount, failCount); |
| | | } |
| | | |
| | | return commit; |
| | | }); |
| | | /// <summary> |
| | | /// 检查检验项目是否完成 |
| | | /// </summary> |
| | | private bool IsInspectionItemComplete(MesQaItemsDetectDetail5 inspectionItem, int actualCount) |
| | | { |
| | | return inspectionItem.CheckQyt == actualCount; |
| | | } |
| | | |
| | | var isNull = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == null) |
| | | /// <summary> |
| | | /// 确定检验项目结果 |
| | | /// </summary> |
| | | private string DetermineInspectionItemResult((int TotalCount, int PassCount, int FailCount) counts, |
| | | MesQaItemsDetectDetail5 inspectionItem) |
| | | { |
| | | if (counts.TotalCount == counts.PassCount) |
| | | return "合格"; |
| | | else if (counts.FailCount >= inspectionItem.FreQty) |
| | | return "不合格"; |
| | | else |
| | | return string.Empty; // 未完成状态 |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新检验项目结果 |
| | | /// </summary> |
| | | private int UpdateInspectionItemResult(decimal? mainId, string result, int count) |
| | | { |
| | | return SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | return db.Updateable<MesQaItemsDetectDetail5>() |
| | | .SetColumns(s => s.FcheckResu == result) |
| | | .SetColumns(s => s.FenterQty == count) |
| | | .Where(s => s.Id == mainId) |
| | | .ExecuteCommand(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检查整个检验单是否完成 |
| | | /// </summary> |
| | | private bool IsInspectionOrderComplete(string? releaseNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | // 检查是否还有未完成的检验项目 |
| | | var incompleteCount = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == releaseNo && s.FcheckResu == null) |
| | | .Count(); |
| | | |
| | | if (isNull > 0) return 1; |
| | | return incompleteCount == 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 处理完成的检验单 |
| | | /// </summary> |
| | | private void ProcessCompleteInspectionOrder(MesQaItemsDetectDetail12 detail) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | // 获取检验单下的所有检验项目 |
| | | var inspectionCounts = GetInspectionOrderCounts(detail.ReleaseNo); |
| | | |
| | | // 确定整个检验单的结果 |
| | | var orderResult = DetermineInspectionOrderResult(inspectionCounts); |
| | | |
| | | // 获取用户信息 |
| | | var sysUser = GetUserInfo(detail.CreateBy); |
| | | |
| | | // 更新检验单结果 |
| | | UpdateInspectionOrderResult(detail.ReleaseNo, orderResult, sysUser?.Fname, detail.CreateBy); |
| | | } |
| | | |
| | | //获取检验单的检验项目的个数 |
| | | var sum = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == detail.ReleaseNo).Count(); |
| | | |
| | | if (sum == 0) return 1; |
| | | |
| | | //获取检验单下的合格的检验项目个数 |
| | | var icount = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == "合格") |
| | | /// <summary> |
| | | /// 获取检验单统计信息 |
| | | /// </summary> |
| | | private (int TotalItems, int PassedItems) GetInspectionOrderCounts(string? releaseNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | var totalItems = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == releaseNo).Count(); |
| | | |
| | | var passedItems = db.Queryable<MesQaItemsDetectDetail5>() |
| | | .Where(s => s.ReleaseNo == releaseNo && s.FcheckResu == "合格") |
| | | .Count(); |
| | | |
| | | var FcheckResu = "不合格"; |
| | | return (totalItems, passedItems); |
| | | } |
| | | |
| | | //实际个数等于理论个数时对检验单进行判定 |
| | | if (sum == icount) |
| | | //合格的检验结果等于总检验数视为合格 |
| | | FcheckResu = "合格"; |
| | | /// <summary> |
| | | /// 确定检验单结果 |
| | | /// </summary> |
| | | private string DetermineInspectionOrderResult((int TotalItems, int PassedItems) counts) |
| | | { |
| | | // 所有检验项目都合格时,整个检验单才合格 |
| | | return counts.TotalItems == counts.PassedItems ? "合格" : "不合格"; |
| | | } |
| | | |
| | | var sysUser = db.Queryable<SysUser>() |
| | | .Where(s => s.Fcode == detail.CreateBy).First(); |
| | | /// <summary> |
| | | /// 获取用户信息 |
| | | /// </summary> |
| | | private SysUser? GetUserInfo(string? userCode) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | return db.Queryable<SysUser>() |
| | | .Where(s => s.Fcode == userCode).First(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新检验单结果 |
| | | /// </summary> |
| | | private void UpdateInspectionOrderResult(string? releaseNo, string result, string? checkedBy, string? updatedBy) |
| | | { |
| | | SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | return db.Updateable<MesQaItemsDetect01>() |
| | | .SetColumns(s => s.FcheckResu == FcheckResu) |
| | | .SetColumns(s => s.FcheckResu == result) |
| | | .SetColumns(s => s.FcheckDate == DateTime.Now) |
| | | .SetColumns(s => s.FcheckBy == sysUser.Fname) |
| | | .SetColumns(s => s.LastupdateBy == detail.CreateBy) |
| | | .SetColumns(s => s.FcheckBy == checkedBy) |
| | | .SetColumns(s => s.LastupdateBy == updatedBy) |
| | | .SetColumns(s => s.LastupdateDate == DateTime.Now) |
| | | .Where(s => s.ReleaseNo == detail.ReleaseNo) |
| | | .Where(s => s.ReleaseNo == releaseNo) |
| | | .ExecuteCommand(); |
| | | }); |
| | | // if (FcheckResu.Equals("不合格")) |
| | | //自动生成入库检异常对策 |
| | | /// saveDetect02(detail.Id, detail.CreateBy); |
| | | |
| | | return useTransactionWithOracle; |
| | | } |
| | | /* public int saveDetect02(decimal? gid, string? createBy) |
| | | { |