From 4ded390f6dab41192bf786d1c1bea6040a08d24c Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 17 十一月 2025 09:37:04 +0800
Subject: [PATCH] 1.存货档案批量关联该工艺查询多存货 2.存货档案批量关联该工艺提交多存货
---
VueWebCoreApi/DLL/DAL/ProductModelDAL.cs | 342 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 342 insertions(+), 0 deletions(-)
diff --git a/VueWebCoreApi/DLL/DAL/ProductModelDAL.cs b/VueWebCoreApi/DLL/DAL/ProductModelDAL.cs
index 180b3d3..612b45c 100644
--- a/VueWebCoreApi/DLL/DAL/ProductModelDAL.cs
+++ b/VueWebCoreApi/DLL/DAL/ProductModelDAL.cs
@@ -1122,6 +1122,206 @@
}
#endregion
+ #region[瀛樿揣妗f鍏宠仈宸ヨ壓(宸ヨ壓璺嚎鎴栧伐搴�)鏌ヨ澶氬瓨璐
+ public static ToMessage TMaterielFileAssociationRouteList(List<string> partcode, User us)
+ {
+ string sql = "";
+ var dynamicParams = new DynamicParameters();
+ List<MaterialRoutList> list = new List<MaterialRoutList>();
+ try
+ {
+ dynamic dynObj = JObject.Parse(us.mesSetting);
+ bool route = dynObj.route;
+ if (route) //宸ヨ壓璺嚎鐗�
+ {
+ // 1. 鎵归噺鑾峰彇鎵�鏈夌墿鏂欑殑鍩虹淇℃伅
+ var baseInfoSql = @"SELECT M.partcode, M.partname, M.default_route as default_routecode, R.name as default_routename
+ FROM TMateriel_Info M
+ LEFT JOIN TFlw_Rout R ON M.default_route = R.code
+ WHERE M.partcode IN @PartCodes";
+ var baseInfos = DapperHelper.select<dynamic>(baseInfoSql, new { PartCodes = partcode }).ToDictionary(x => (string)x.partcode, x => x);
+ if (!baseInfos.Any())
+ {
+ mes.code = "200";
+ mes.message = "鏈壘鍒板搴旂殑鐗╂枡淇℃伅";
+ mes.data = list;
+ return mes;
+ }
+ // 2. 鎵归噺鑾峰彇鎵�鏈夌墿鏂欑殑宸ヨ壓璺嚎淇℃伅
+ var routeSql = @"SELECT mi.partcode AS partcode,fr.code AS routecode,fr.name AS routename,
+ CASE
+ WHEN mr.materiel_code IS NOT NULL THEN 'Y'
+ ELSE 'N'
+ END AS flag
+ FROM TMateriel_Info mi
+ CROSS JOIN TFlw_Rout fr
+ LEFT JOIN TMateriel_Route mr ON mi.partcode = mr.materiel_code AND fr.code = mr.route_code
+ WHERE mi.partcode IN @PartCodes AND fr.enable = 'Y'
+ ORDER BY mi.partcode, fr.code";
+ var allRoutes = DapperHelper.select<dynamic>(routeSql, new { PartCodes = partcode }).GroupBy(x => (string)x.partcode).ToDictionary(g => g.Key, g => g.ToList());
+
+ // 3. 鎵归噺鑾峰彇鎵�鏈夊伐搴忎俊鎭紙涓�娆℃�ф煡璇級
+ var allRouteCodes = allRoutes.Values
+ .SelectMany(routes => routes.Select(r => (string)r.routecode))
+ .Distinct()
+ .ToList();
+
+ Dictionary<string, DataTable> routeSteps = new Dictionary<string, DataTable>();
+
+ if (allRouteCodes.Any())
+ {
+ var stepSql = @"SELECT A.rout_code as route_code, A.seq, B.stepcode, B.stepname, B.enable
+ FROM TFlw_Rtdt A
+ INNER JOIN TStep B ON A.step_code = B.stepcode
+ WHERE A.rout_code IN @RouteCodes AND B.is_delete <> '1'
+ ORDER BY A.rout_code, A.seq ASC";
+ var allSteps = DapperHelper.select<dynamic>(stepSql, new { RouteCodes = allRouteCodes });
+ // 灏嗗伐搴忔暟鎹寜宸ヨ壓璺嚎缂栫爜鍒嗙粍
+ routeSteps = allSteps
+ .GroupBy(x => (string)x.route_code)
+ .ToDictionary(
+ g => g.Key,
+ g =>
+ {
+ // 灏嗗姩鎬佺被鍨嬭浆鎹负DataTable锛堟牴鎹偍鍘熸湁浠g爜鐨勮繑鍥炵被鍨嬭皟鏁达級
+ var dt = new DataTable();
+ dt.Columns.Add("seq");
+ dt.Columns.Add("stepcode");
+ dt.Columns.Add("stepname");
+ dt.Columns.Add("enable");
+
+ foreach (var step in g.OrderBy(s => s.seq))
+ {
+ dt.Rows.Add(step.seq, step.stepcode, step.stepname, step.enable);
+ }
+ return dt;
+ });
+ }
+ // 4. 鍦ㄥ唴瀛樹腑缁勫悎鏁版嵁
+ foreach (var part in partcode)
+ {
+ if (!baseInfos.ContainsKey(part)) continue;
+
+ var baseInfo = baseInfos[part];
+ var routlist = new MaterialRoutList
+ {
+ partcode = baseInfo.partcode,
+ partname = baseInfo.partname,
+ defalutroutecode = baseInfo.default_routecode,
+ defalutroutename = baseInfo.default_routename,
+ children = new List<RouteList>()
+ };
+
+ // 娣诲姞璇ョ墿鏂欑殑宸ヨ壓璺嚎
+ if (allRoutes.ContainsKey(part))
+ {
+ foreach (var routeInfo in allRoutes[part])
+ {
+ var rout = new RouteList
+ {
+ routecode = routeInfo.routecode,
+ routename = routeInfo.routename,
+ flag = routeInfo.flag
+ };
+
+ // 娣诲姞宸ュ簭淇℃伅
+ if (routeSteps.ContainsKey(rout.routecode))
+ {
+ rout.Data = routeSteps[rout.routecode];
+ }
+
+ routlist.children.Add(rout);
+ }
+ }
+
+ list.Add(routlist);
+ }
+
+ mes.data = list;
+ mes.code = "200";
+ mes.message = $"鏌ヨ鎴愬姛锛屽叡澶勭悊{list.Count}涓墿鏂�";
+ }
+ else //宸ュ簭鐗�
+ {
+ // 1. 鎵归噺鑾峰彇鎵�鏈夌墿鏂欏熀纭�淇℃伅
+ var baseInfoSql = @"SELECT partcode, partname FROM TMateriel_Info
+ WHERE partcode IN @PartCodes";
+ var baseInfos = DapperHelper.select<dynamic>(baseInfoSql, new { PartCodes = partcode })
+ .ToDictionary(x => (string)x.partcode, x => x);
+
+ if (!baseInfos.Any())
+ {
+ mes.code = "200";
+ mes.message = "鏈壘鍒板搴旂殑鐗╂枡淇℃伅";
+ mes.data = new List<MaterialRoutList>();
+ return mes;
+ }
+
+ // 2. 鎵归噺鑾峰彇鎵�鏈夌墿鏂欑殑宸ュ簭淇℃伅
+ var stepSql = @"SELECT A.materiel_code as partcode, A.step_seq, A.step_code,
+ S.stepname, A.isbott, A.isend
+ FROM TMateriel_Step A
+ INNER JOIN TStep S ON A.step_code = S.stepcode
+ WHERE A.materiel_code IN @PartCodes AND S.is_delete <> '1'
+ ORDER BY A.materiel_code, A.step_seq";
+
+ var allSteps = DapperHelper.select<dynamic>(stepSql, new { PartCodes = partcode })
+ .GroupBy(x => (string)x.partcode)
+ .ToDictionary(g => g.Key, g => g.ToList());
+
+ // 3. 鍐呭瓨涓粍鍚堟暟鎹�
+ foreach (var part in partcode)
+ {
+ if (!baseInfos.ContainsKey(part)) continue;
+
+ var baseInfo = baseInfos[part];
+ var routlist = new MaterialRoutList
+ {
+ partcode = baseInfo.partcode,
+ partname = baseInfo.partname,
+ children = new List<RouteList>()
+ };
+
+ // 娣诲姞宸ュ簭淇℃伅
+ if (allSteps.ContainsKey(part))
+ {
+ // 杞崲涓篋ataTable锛堝闇�淇濇寔鍘熸湁缁撴瀯锛�
+ var stepData = allSteps[part];
+ var dataTable = new DataTable();
+ dataTable.Columns.Add("step_seq");
+ dataTable.Columns.Add("step_code");
+ dataTable.Columns.Add("step_name");
+ dataTable.Columns.Add("isbott");
+ dataTable.Columns.Add("isend");
+
+ foreach (var step in stepData.OrderBy(s => s.step_seq))
+ {
+ dataTable.Rows.Add(step.step_seq, step.step_code,
+ step.stepname, step.isbott, step.isend);
+ }
+
+ routlist.children.Add(new RouteList { Data = dataTable });
+ }
+
+ list.Add(routlist);
+ }
+
+ mes.data = list;
+ mes.code = "200";
+ mes.message = $"鏌ヨ鎴愬姛锛屽叡澶勭悊{list.Count}涓墿鏂�";
+ }
+ }
+ catch (Exception e)
+ {
+ mes.code = "300";
+ mes.count = 0;
+ mes.message = e.Message;
+ mes.data = null;
+ }
+ return mes;
+ }
+ #endregion
+
#region[瀛樿揣妗f鍏宠仈宸ヨ壓(宸ヨ壓璺嚎鎴栧伐搴�)鎻愪氦]
public static ToMessage SaveTMaterielFile(User us, List<MaterialCraftsSave> json)
{
@@ -1258,6 +1458,148 @@
}
#endregion
+ #region[瀛樿揣妗f鍏宠仈宸ヨ壓(宸ヨ壓璺嚎鎴栧伐搴�)鎻愪氦澶氬瓨璐
+ public static ToMessage SaveTMaterielFileList(User us, List<MaterialCraftsSave> json)
+ {
+ var sql = "";
+ List<object> list = new List<object>();
+ var dynamicParams = new DynamicParameters();
+ try
+ {
+ list.Clear();
+ dynamic dynObj = JObject.Parse(us.mesSetting);
+ bool route = dynObj.route;
+ if (route) //宸ヨ壓璺嚎鐗�
+ {
+ for (int i = 0; i < json.Count; i++)
+ {
+ if (json[i].children == null || json[i].children.Count <= 0)
+ {
+ //娓呴櫎鐗╂枡鍏宠仈宸ヨ壓璺嚎琛ㄦ暟鎹�
+ sql = @"delete TMateriel_Route where materiel_code=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ //鏍囪鐗╂枡琛ㄥ叧鑱斿伐鑹鸿矾绾挎爣璇�
+ sql = @"update TMateriel_Info set is_retdproc='N',default_route='' where partcode=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ //娓呴櫎鑺傛媿宸ヤ环琛ㄥ搴旀暟鎹�
+ sql = @"delete TPrteEqp_Stad where materiel_code=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ }
+ else
+ {
+ //娓呴櫎瀛樿揣鍏宠仈宸ヨ壓璺嚎琛ㄦ暟鎹�
+ sql = @"delete TMateriel_Route where materiel_code=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ //寰幆鍐欏叆瀛樿揣鍏宠仈宸ヨ壓璺嚎琛�
+ for (int j = 0; j < json[i].children.Count; j++)
+ {
+ sql = @"insert into TMateriel_Route(materiel_code,route_code,lm_user,lm_date) values(@materiel_code,@route_code,@lm_user,@lm_date)";
+ list.Add(new
+ {
+ str = sql,
+ parm = new
+ {
+ materiel_code = json[i].partcode,
+ route_code = json[i].children[j].code,
+ lm_user = us.usercode,
+ lm_date = DateTime.Now.ToString()
+ }
+ });
+ }
+ //鏍囪鐗╂枡琛ㄥ叧鑱斿伐鑹鸿矾绾挎爣璇�
+ sql = @"update TMateriel_Info set is_retdproc='Y',default_route=@defaultroute_code where partcode=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode, defaultroute_code = json[i].defaultroute_code } });
+
+ //娓呴櫎鑺傛媿宸ヤ环琛ㄥ綋鍓嶄骇鍝佸搴斿伐鑹鸿矾绾夸笉鍖呭惈姝ゆ璁剧疆鐨勫叾瀹冩暟鎹�
+ //string鍒嗗壊杞瑂tring[]
+ string[] routcode = Array.ConvertAll<string, string>(string.Join(",", json[i].children.Select(s => s.code)).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString());
+ sql = @"delete TPrteEqp_Stad where materiel_code=@partcode and route_code not in @routecode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode, routecode = routcode } });
+ }
+ }
+ }
+ else //宸ュ簭鐗�
+ {
+ for (int i = 0; i < json.Count; i++)
+ {
+ if (json[i].children == null || json[i].children.Count <= 0)
+ {
+ //娓呴櫎鐗╂枡鍏宠仈宸ヨ壓璺嚎琛ㄦ暟鎹�
+ sql = @"delete TMateriel_Step where materiel_code=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ //鏍囪鐗╂枡琛ㄥ叧鑱斿伐鑹鸿矾绾挎爣璇�
+ sql = @"update TMateriel_Info set is_retdproc='N',default_route='' where partcode=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ //娓呴櫎鑺傛媿宸ヤ环琛ㄥ搴旀暟鎹�
+ sql = @"delete TPrteEqp_Stad where materiel_code=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ }
+ else
+ {
+ //娓呴櫎瀛樿揣鍏宠仈宸ヨ壓璺嚎琛ㄦ暟鎹�
+ sql = @"delete TMateriel_Step where materiel_code=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode } });
+ //寰幆鍐欏叆瀛樿揣鍏宠仈宸ヨ壓璺嚎琛�
+ for (int j = 0; j < json[i].children.Count; j++)
+ {
+ sql = @"insert into TMateriel_Step(materiel_code,step_seq,step_code,isbott,isend,lm_user,lm_date)
+ values(@materiel_code,@step_seq,@step_code,@isbott,@isend,@lm_user,@lm_date)";
+ list.Add(new
+ {
+ str = sql,
+ parm = new
+ {
+ materiel_code = json[i].partcode,
+ step_seq = json[i].children[j].seq,
+ step_code = json[i].children[j].code,
+ isbott = json[i].children[j].isbott,
+ isend = json[i].children[j].isend,
+ lm_user = us.usercode,
+ lm_date = DateTime.Now.ToString()
+ }
+ });
+ }
+ //鏍囪鐗╂枡琛ㄥ叧鑱斿伐鑹鸿矾绾挎爣璇�
+ sql = @"update TMateriel_Info set is_retdproc='Y',default_route=@defaultroute_code where partcode=@partcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode, defaultroute_code = json[i].defaultroute_code } });
+
+ //娓呴櫎鑺傛媿宸ヤ环琛ㄥ綋鍓嶄骇鍝佸搴斿伐搴忎笉鍖呭惈姝ゆ璁剧疆鐨勫叾瀹冩暟鎹�
+ //string鍒嗗壊杞瑂tring[]
+ string[] stepcode = Array.ConvertAll<string, string>(string.Join(",", json[i].children.Select(s => s.code)).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString());
+ sql = @"delete TPrteEqp_Stad where materiel_code=@partcode and step_code not in @stepcode";
+ list.Add(new { str = sql, parm = new { partcode = json[i].partcode, stepcode = stepcode } });
+ }
+ }
+ }
+ bool aa = DapperHelper.DoTransaction(list);
+ if (aa)
+ {
+ //鍐欏叆鎿嶄綔璁板綍琛�
+ LogHelper.DbOperateLog(us.usercode, "瀛樿揣鍏宠仈宸ヨ壓", "浜у搧锛�" + string.Join(",", json.Select(x => x.partcode)) + "鍏宠仈浜嗗伐鑹�:" + string.Join(",", json.SelectMany(x => x.children?.Select(c => c.code) ?? Enumerable.Empty<string>())), us.usertype);
+ mes.code = "200";
+ mes.count = 0;
+ mes.message = "鎿嶄綔鎴愬姛!";
+ mes.data = null;
+ }
+ else
+ {
+ mes.code = "300";
+ mes.count = 0;
+ mes.message = "鎿嶄綔澶辫触!";
+ mes.data = null;
+ }
+ }
+ catch (Exception e)
+ {
+ mes.code = "300";
+ mes.count = 0;
+ mes.message = e.Message;
+ mes.data = null;
+ }
+ return mes;
+ }
+ #endregion
+
#region[宸ュ崟浜у搧淇℃伅涓嬫媺妗嗘煡璇
public static ToMessage PartSelect()
--
Gitblit v1.9.3