From 47d3c9e31edd16c02e3c74ff45e9772f9ca550b2 Mon Sep 17 00:00:00 2001 From: zyf <1071160500@qq.com> Date: 星期三, 28 五月 2025 19:26:49 +0800 Subject: [PATCH] 采购申请和BOM接口 --- MES.Service/service/QC/LljService.cs | 342 +++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 210 insertions(+), 132 deletions(-) diff --git a/MES.Service/service/QC/LljService.cs b/MES.Service/service/QC/LljService.cs index 2c67b1e..262c14c 100644 --- a/MES.Service/service/QC/LljService.cs +++ b/MES.Service/service/QC/LljService.cs @@ -1,74 +1,86 @@ -锘縰sing MES.Service.DB; +锘縰sing System.Data; +using MES.Service.DB; using MES.Service.Dto.service; using MES.Service.Modes; using MES.Service.util; using SqlSugar; +using DbType = System.Data.DbType; namespace MES.Service.service.QC; public class LljService { - - public List<LtsLlj> GetPage(XJPageResult queryObj) + public (List<LtsLlj> item, int TotalCount) GetPage(XJPageResult queryObj) { var db = SqlSugarHelper.GetInstance(); var id = Convert.ToDecimal(queryObj.id); - - return db.Queryable<LtsLlj>() - .WhereIF( - StringUtil.IsNotNullOrEmpty(queryObj.result) && - "鏈畬鎴�".Equals(queryObj.result), - (a) =>a.FcheckResu == null) - .WhereIF( - StringUtil.IsNotNullOrEmpty(queryObj.result) && - !"鏈畬鎴�".Equals(queryObj.result), - (a) => a.FcheckResu != null) - .WhereIF(id > 0, (a) => a.Id == id) - .ToPageList(queryObj.PageIndex, queryObj.Limit); - + + var totalCount = 0; + + var pageList = db.Queryable<LtsLlj>() + .WhereIF( + StringUtil.IsNotNullOrEmpty(queryObj.result) && + "鏈畬鎴�".Equals(queryObj.result), + a => a.FcheckResu == null) + .WhereIF( + StringUtil.IsNotNullOrEmpty(queryObj.result) && + !"鏈畬鎴�".Equals(queryObj.result), + a => a.FcheckResu != null) + .WhereIF(id > 0, a => a.Id == id) + //鍔犵瓫閫夋潯浠�,鏍规嵁渚涘簲鍟嗭紝鐗╂枡缂栫爜锛岀墿鏂欏悕绉版悳绱� + //.WhereIF(queryObj.SearchValue!=null && queryObj.SearchValue!="", (a) => a.SuppName == queryObj.SearchValue|| a.ItemName == queryObj.SearchValue || a.ItemNo == queryObj.SearchValue ) + .WhereIF(queryObj.SearchValue != null && queryObj.SearchValue != "", + (a) => (a.SuppName.ToLower().Contains(queryObj.SearchValue.ToLower()) + || a.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()) + || a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))) + .OrderByDescending(a => a.Id) + .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount); + + return (pageList, totalCount); } - //鏍规嵁妫�楠屾爣鍑嗘潵璁$畻妫�楠屼釜鏁� - public List<MesQaItemsDetectDetail5> SetItems(string itemNo, decimal quantity,string releaseNo) + + //鏍规嵁妫�楠屾爣鍑嗘潵璁$畻妫�楠屼釜鏁� + public List<MesQaItemsDetectDetail5> SetItems(string itemNo, + decimal quantity, string releaseNo) { var db = SqlSugarHelper.GetInstance(); - - var count = db.Queryable<MesQaIqc>().Where(s => s.EE == 1 && s.ISENABLED == 1 - && s.ItemNo == itemNo && s.FTYPE == "1").Count(); + + var count = db.Queryable<MesQaIqc>().Where(s => s.EE == 1 && + s.ISENABLED == 1 + && s.ItemNo == itemNo && s.FTYPE == "1").Count(); if (count <= 0) return []; var mesQaIqcItem = db .Queryable<MesQaIqc>().Where(s => s.EE == 1 && s.ISENABLED == 1 - && s.ItemNo == itemNo && s.FTYPE == "1").Select( + && s.ItemNo == itemNo && s.FTYPE == "1").Select( b => new MesQaItemsDetectDetail5 { - - ReleaseNo = releaseNo, - FacLevel = b.FacLevel, - FcheckItem = b.FcheckItem , - FdownAllow = b.FdownAllow, - FcheckLevel = b.FREQUENCY, - Fstand =b.FSTAND, - FupAllow = b.FupAllow, - SampleSizeNo = b.SampleSizeNo , + ReleaseNo = releaseNo, + FacLevel = b.FacLevel, + FcheckItem = b.FcheckItem, + FdownAllow = b.FdownAllow, + FcheckLevel = b.FREQUENCY, + Fstand = b.FSTAND, + FupAllow = b.FupAllow, + SampleSizeNo = b.SampleSizeNo, FenterQty = 0, - Factory = "1000", + Factory = "1000", Company = "1000", - - - // FcheckItemDesc = "0", - // FcheckResu = "0", - FcheckTool = b.FcheckTool, - FspecRequ = b.FspecRequ, - // FtextType = "0", - // Funit = "0", - // LastupdateBy = "0", - // ProcNo = "0", - // WorkshopCenterCode = "0" - + + + // FcheckItemDesc = "0", + // FcheckResu = "0", + FcheckTool = b.FcheckTool, + FspecRequ = b.FspecRequ + // FtextType = "0", + // Funit = "0", + // LastupdateBy = "0", + // ProcNo = "0", + // WorkshopCenterCode = "0" }).ToList(); mesQaIqcItem.ForEach(item => @@ -76,25 +88,28 @@ string LEV = null; switch (item.FcheckLevel) { - case string s when s.Contains("S1"): + case null: + LEV = ""; // 榛樿鍊� + break; + case { } s when s.Contains("S1"): LEV = "B.FLEVEL_S1"; break; - case string s when s.Contains("S2"): + case { } s when s.Contains("S2"): LEV = "B.FLEVEL_S2"; break; - case string s when s.Contains("S3"): + case { } s when s.Contains("S3"): LEV = "B.FLEVEL_S3"; break; - case string s when s.Contains("S4"): + case { } s when s.Contains("S4"): LEV = "B.FLEVEL_S4"; break; - case string s when s.Contains("(I)"): + case { } s when s.Contains("(I)"): LEV = "B.FLEVEL_I"; break; - case string s when s.Contains("(II)"): + case { } s when s.Contains("(II)"): LEV = "B.FLEVEL_II"; break; - case string s when s.Contains("(III)"): + case { } s when s.Contains("(III)"): LEV = "B.FLEVEL_III"; break; default: @@ -102,21 +117,32 @@ break; } + if (string.IsNullOrEmpty(LEV)) + throw new Exception(item.SampleSizeNo + "鐨勬楠屾按骞充笉姝g‘"); + var sql = "SELECT " + LEV + " FROM MES_QM_AQL1 A LEFT JOIN MES_QM_AQL2 B ON B.AQL1_ID=A.ID WHERE A.SAMPLE_SIZE_NO='" + - item.SampleSizeNo + "' AND B.LOT_FROM<= " + quantity + " AND " + + item.SampleSizeNo + "' AND B.LOT_FROM<= " + quantity + + " AND " + quantity + "<=B.LOT_TO"; var maxBillNo = db.Ado.SqlQuerySingle<string>(sql); + if (string.IsNullOrEmpty(maxBillNo)) + throw new Exception(item.SampleSizeNo + "涓嬬殑" + quantity + + "杩欎釜鑼冨洿涓嬫病鏈夊尮閰嶅埌妫�楠岄」鐩�"); var result = ExtractSubstring(item.FacLevel, '(', ')'); + if (string.IsNullOrEmpty(result)) + throw new Exception(item.SampleSizeNo + "涓嬬殑" + quantity + + "鎷掓敹姘村钩涓嶆纭�"); sql = "SELECT FSAMPLE_SIZE_WORD, " + result + " Result FROM MES_QM_AQL1 A LEFT JOIN MES_QM_AQL3 C ON C.AQL1_ID=A.ID WHERE A.SAMPLE_SIZE_NO= '" + - item.SampleSizeNo + "' AND SAMPLE_SIZE_WORD= '" + maxBillNo + "'"; + item.SampleSizeNo + "' AND SAMPLE_SIZE_WORD= '" + maxBillNo + + "'"; var resultClass = db.Ado.SqlQuerySingle<ResultClass>(sql); item.CheckQyt = resultClass.FSAMPLE_SIZE_WORD; @@ -140,6 +166,7 @@ var length = endIndex - startIndex - 1; return input.Substring(startIndex + 1, length); } + public int saveItem(LLJDto rkjDto) { var items = rkjDto.items; @@ -153,34 +180,30 @@ }); rkjDto.items = GetItems(rkjDto.releaseNo, null); - + var db = SqlSugarHelper.GetInstance(); rkjDto.items.ForEach(s => { - if (s.FupAllow != null || s.Fstand != null || - s.FdownAllow != null ) return; - + if (s.FupAllow != null || s.Fstand != null || + s.FdownAllow != null) return; + // 娌℃湁褰曞叆鍙傝�冨�硷紝鍒ゆ柇鏈夊灏戜釜NG锛岄偅涔堝綍鍏ョ殑鎶芥缁撴灉蹇呴』鏄疧K鎴栬�匩G锛孨G浠h〃涓嶅悎鏍� var ifck = db.Queryable<MesQaItemsDetectDetail12>() .Where(x => x.FcheckResu == "NG" && x.MainId == s.Id).Count(); //妫�楠屾槑缁嗘�绘暟 - var count = db.Queryable<MesQaItemsDetectDetail12>().Where(x1 => x1.MainId == s.Id).Count(); + var count = db.Queryable<MesQaItemsDetectDetail12>() + .Where(x1 => x1.MainId == s.Id).Count(); if (ifck > s.FreQty && s.CheckQyt == count) - { s.FcheckResu = "涓嶅悎鏍�"; - }else if (ifck < s.FreQty && s.CheckQyt == count) - { + else if (ifck < s.FreQty && s.CheckQyt == count) s.FcheckResu = "鍚堟牸"; - } else - { s.FcheckResu = "鏈畬鎴�"; - } - - + + var detail = new MesQaItemsDetectDetail12(); detail.MainId = s.Id; detail.ReleaseNo = rkjDto.releaseNo; @@ -193,54 +216,55 @@ return Convert.ToInt32(rkjDto.gid); } - public List<MesQaItemsDetectDetail5> GetItems(string? releaseNo, decimal? id) + + public List<MesQaItemsDetectDetail5> GetItems(string? releaseNo, + decimal? id) { 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) + // .WhereIF(id > 0, (a, b) => a.Id == id) .GroupBy((a, b) => new { a.Id, - a.ReleaseNo, - a.FacLevel, - a.FcheckItem , - a.FcheckTool , - a.FdownAllow, - a.FcheckLevel, - a.Fstand, - a.FupAllow, - a.SampleSizeNo , - a.FspecRequ , - a.FreQty, - a.CheckQyt, - a.FcheckResu - - + a.ReleaseNo, + a.FacLevel, + a.FcheckItem, + a.FcheckTool, + a.FdownAllow, + a.FcheckLevel, + a.Fstand, + a.FupAllow, + a.SampleSizeNo, + a.FspecRequ, + a.FreQty, + a.CheckQyt, + a.FcheckResu }).Select((a, b) => new MesQaItemsDetectDetail5 { Id = a.Id, ReleaseNo = a.ReleaseNo, CheckQyt = a.CheckQyt, - FacLevel = a.FacLevel, - FcheckItem = a.FcheckItem , - FcheckTool = a.FcheckTool , - FdownAllow = a.FdownAllow, - FcheckLevel = a.FcheckLevel, - Fstand =a.Fstand, - FupAllow = a.FupAllow, - SampleSizeNo = a.SampleSizeNo , - FspecRequ =a.FspecRequ , - FreQty = a.FreQty, - Factory = "1000", + FacLevel = a.FacLevel, + FcheckItem = a.FcheckItem, + FcheckTool = a.FcheckTool, + FdownAllow = a.FdownAllow, + FcheckLevel = a.FcheckLevel, + Fstand = a.Fstand, + FupAllow = a.FupAllow, + SampleSizeNo = a.SampleSizeNo, + FspecRequ = a.FspecRequ, + FreQty = a.FreQty, + Factory = "1000", Company = "1000", FenterQty = SqlFunc.AggregateCount(b.Id), - FcheckResu = a.FcheckResu + FcheckResu = a.FcheckResu }).ToList(); } - + public int SetQSItemDetail(MesQaItemsDetectDetail12 detail) { var dbd = SqlSugarHelper.GetInstance(); @@ -259,22 +283,20 @@ item.Factory = "1000"; item.Company = "1000"; result.Add(item); - } - + return db.Insertable(result).ExecuteCommand(); - }); detail.CreateBy = detail.LastupdateBy; - - + + autoResult(detail); return oracle; } - - + + private int autoResult(MesQaItemsDetectDetail12 detail) { var db = SqlSugarHelper.GetInstance(); @@ -288,7 +310,7 @@ //鏌ヨ杩欎釜妫�楠岄」鐩笅鐨勬楠岀粨鏋� var count = db.Queryable<MesQaItemsDetectDetail12>() .Where(s => s.MainId == detail.MainId).Count(); - + updateDetail5(detail); var result = ""; @@ -306,7 +328,7 @@ result = "鍚堟牸"; //else if (count - passCount < QsItemOqcItem.FreQty) // result = "涓嶅悎鏍�"; - else if (noCount >= QsItemOqcItem.FreQty) + else if (noCount >= QsItemOqcItem.FreQty) result = "涓嶅悎鏍�"; var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle( db => @@ -322,7 +344,8 @@ }); var isNull = db.Queryable<MesQaItemsDetectDetail5>() - .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == null).Count(); + .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == null) + .Count(); if (isNull > 0) return 1; @@ -335,7 +358,8 @@ //鑾峰彇妫�楠屽崟涓嬬殑鍚堟牸鐨勬楠岄」鐩釜鏁� var icount = db.Queryable<MesQaItemsDetectDetail5>() - .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == "鍚堟牸").Count(); + .Where(s => s.ReleaseNo == detail.ReleaseNo && s.FcheckResu == "鍚堟牸") + .Count(); var FcheckResu = "涓嶅悎鏍�"; @@ -358,9 +382,9 @@ .Where(s => s.ReleaseNo == detail.ReleaseNo) .ExecuteCommand(); }); - // if (FcheckResu.Equals("涓嶅悎鏍�")) - //鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥 - /// saveDetect02(detail.Id, detail.CreateBy); + // if (FcheckResu.Equals("涓嶅悎鏍�")) + //鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥 + /// saveDetect02(detail.Id, detail.CreateBy); return useTransactionWithOracle; } @@ -408,7 +432,7 @@ .ExecuteCommand()); } */ - + public LLJDto getXjDetail02ById(decimal? id) { var rkjDto = new LLJDto(); @@ -417,17 +441,17 @@ var qsItemOqcItem = db.Queryable<MesQaItemsDetectDetail5>().Single(s => s.Id == id); - /* if (qsItemOqcItem.IsPass == 0) - qsItemOqcItem.Result = "涓嶅悎鏍�"; - else if (qsItemOqcItem.IsPass == 1) - qsItemOqcItem.Result = "鍚堟牸"; - else - qsItemOqcItem.Result = "鏈畬鎴�"; + /* if (qsItemOqcItem.IsPass == 0) + qsItemOqcItem.Result = "涓嶅悎鏍�"; + else if (qsItemOqcItem.IsPass == 1) + qsItemOqcItem.Result = "鍚堟牸"; + else + qsItemOqcItem.Result = "鏈畬鎴�"; - if (qsItemOqcItem.Picture is { Length: > 0 }) - qsItemOqcItem.imageData = - Convert.ToBase64String(qsItemOqcItem.Picture); -*/ + if (qsItemOqcItem.Picture is { Length: > 0 }) + qsItemOqcItem.imageData = + Convert.ToBase64String(qsItemOqcItem.Picture); + */ //鑾峰彇涓嶅悎鏍兼暟 var count = db.Queryable<MesQaItemsDetectDetail12>() .Where(s => s.Fstand == "脳" && s.MainId == id).Count(); @@ -450,9 +474,8 @@ { return db.Updateable<MesQaItemsDetectDetail12>() .SetColumns(s => s.LastupdateBy == detail.LastupdateBy) - // .SetColumns(s => s.LastupdateDate == DateTime.Now) + // .SetColumns(s => s.LastupdateDate == DateTime.Now) .SetColumnsIF(StringUtil.IsNotNullOrEmpty(detail.Fstand), - s => s.Fstand == detail.Fstand) .SetColumnsIF(StringUtil.IsNotNullOrEmpty(detail.FcheckResu), s => s.FcheckResu == detail.FcheckResu) @@ -466,15 +489,16 @@ return withOracle; } + //鏇存柊妫�楠屾槑缁嗗凡妫�銆佷笉鍚堟牸鏁伴噺 private int updateDetail5(MesQaItemsDetectDetail12 detail) { var db = SqlSugarHelper.GetInstance(); - + //鏌ヨ杩欎釜妫�楠岄」鐩笅鐨勬楠屾暟閲� var count = db.Queryable<MesQaItemsDetectDetail12>() .Where(s => s.MainId == detail.MainId).Count(); - + //鑾峰彇涓嶅悎鏍兼暟 var countNo = db.Queryable<MesQaItemsDetectDetail12>() .Where(s => s.MainId == detail.MainId && s.Fstand == "脳").Count(); @@ -487,9 +511,10 @@ .Where(s => s.Id == detail.MainId) .ExecuteCommand(); }); - + return withOracle; } + //涓昏〃淇敼澶囨敞瀛楁 public int saveRemarksGid(LLJDto dto) { @@ -502,6 +527,7 @@ .ExecuteCommand(); }); } + //瀛愯〃淇敼澶囨敞瀛楁 public int saveRemarksPid(LLJDto dto) { @@ -514,7 +540,7 @@ .ExecuteCommand(); }); } - + //鍒犻櫎涓昏〃骞朵笖杩炵骇鍒犻櫎瀛愯〃鍜屽瓩琛� public int removeXJ(string? releaseNo) { @@ -522,10 +548,12 @@ { var commit = 0; //鍒犻櫎涓昏〃 - commit += db.Deleteable<MesQaItemsDetect01>().Where(s => s.ReleaseNo == releaseNo) + commit += db.Deleteable<MesQaItemsDetect01>() + .Where(s => s.ReleaseNo == releaseNo) .ExecuteCommand(); //鍒犻櫎瀛愯〃 - commit += db.Deleteable<MesQaItemsDetectDetail5>().Where(s => s.ReleaseNo == releaseNo) + commit += db.Deleteable<MesQaItemsDetectDetail5>() + .Where(s => s.ReleaseNo == releaseNo) .ExecuteCommand(); //鍒犻櫎瀛欒〃 commit += db.Deleteable<MesQaItemsDetectDetail12>() @@ -536,4 +564,54 @@ return withOracle; } + + public bool IqcQaSubmit(LLJDto dto) + { + var (factory, company) = UserUtil.GetFactory(dto.userNo); + try + { + // 瀹氫箟杈撳嚭鍙傛暟 + var outputResult = new SugarParameter("o_Result", null, + DbType.Int32, ParameterDirection.Output, + 4000); + + var outputMessage = new SugarParameter("o_Msg", null, + DbType.String, + ParameterDirection.Output, 4000); + + // 瀹氫箟杈撳叆鍙傛暟 + var parameters = new List<SugarParameter> + { + new("PI_FACTORY", factory, + DbType.String, ParameterDirection.Input), + new("PI_COMPANY", company, DbType.String, + ParameterDirection.Input), + new("p_Release_No", dto.releaseNo, DbType.String, + ParameterDirection.Input), + new("p_User", dto.userNo, DbType.String, + ParameterDirection.Input), + outputResult, + outputMessage + }; + + var db = SqlSugarHelper.GetInstance(); + + // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼ + db.Ado.ExecuteCommand( + "BEGIN Prc_Mes_Iqc_Qa_Submit82(:PI_FACTORY, :PI_COMPANY, :p_Release_No, :p_User, :o_Result, :o_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) + { + throw new Exception(ex.Message); + } + } } \ No newline at end of file -- Gitblit v1.9.3