From 16a061f9c284c607a0470f5c37a03652796c61d0 Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期五, 25 四月 2025 14:17:37 +0800
Subject: [PATCH] 从金蝶云同步物料信息、生产订单到小诸葛
---
WebAPI/Controllers/SCGL/日计划管理/JIT_DayPlanPlatFormImportController.cs | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 281 insertions(+), 0 deletions(-)
diff --git "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs" "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs"
index dc5bd44..e14a89d 100644
--- "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs"
+++ "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/JIT_DayPlanPlatFormImportController.cs"
@@ -503,5 +503,286 @@
return objJsonResult;
}
#endregion
+
+ #region 鐢熶骇鏃ヨ鍒�(涓夊崌瀵煎叆) 鏂囦欢涓婁紶
+ [Route("JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_SS")]
+ [HttpPost]
+ public object JIT_DayPlanPlatFormImport_SS()
+ {
+ try
+ {
+ //鑾峰彇鏂囦欢鍚嶇О
+ var file = HttpContext.Current.Request.Files[0];
+ //鑾峰彇鏂囦欢鐗╃悊璺緞
+ string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+ //淇濆瓨鏂囦欢
+ file.SaveAs(ExcelPath);
+
+ NpoiHelper np = new NpoiHelper();
+ DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+ //鍒犻櫎鏂囦欢
+ File.Delete(ExcelPath);
+
+ //鍒涘缓涓存椂琛�
+ DataTable tb2 = new DataTable("dt2");
+
+ //娣诲姞鍒楀悕
+ for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+ {
+ tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+ }
+ //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+ tb2.Columns.Add("hmainid", typeof(Int32));
+ tb2.Columns.Add("HMaterID", typeof(Int32));
+ tb2.Columns.Add("ICMOBillHInterID", typeof(Int32));
+ tb2.Columns.Add("ICMOBillHEntryID", typeof(Int32));
+ //鑾峰彇绯荤粺鍙傛暟
+ string Ret = "";
+ oSystemParameter.ShowBill(ref Ret);
+
+ LogService.Write("excel鍊硷細" + ExcelDs.Tables[0].Rows[1][1].ToString());//2024-11-26
+ //娣诲姞鏁版嵁
+ for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
+ {
+ DataRow row = tb2.NewRow();
+ for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
+ {
+ row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
+ }
+ //濡傛灉琛ㄦ牸绗琲琛岀殑绗竴鍒椾负绌猴紝鍒欏垽鏂负杩欎竴琛岀殑鏁版嵁涓虹┖锛岃烦鍑哄惊鐜苟涓斾笉鎶婃暟鎹啓鍏� tb2
+ if (ExcelDs.Tables[0].Rows[i][0].ToString() == "" && ExcelDs.Tables[0].Rows[i][1].ToString() == "")
+ {
+ continue;
+ }
+
+ else
+ {
+ tb2.Rows.Add(row);
+ }
+ }
+
+ var error = "";
+ var ErrorResult = "";
+
+ //鏌ヨ鐢熶骇璁㈠崟琛ㄥ垽鏂湁娌℃湁鐢熶骇璁㈠崟淇℃伅
+ for (int i = 0; i < tb2.Rows.Count; i++)
+ {
+ //if (tb2.Rows[i]["璁″垝缁撴潫鏃ユ湡"].ToString() == "")
+ // error += "璁″垝缁撴潫鏃ユ湡涓嶈兘涓虹┖;";
+ if (tb2.Rows[i]["瀹㈡埛璁㈠崟鍙�"].ToString() == "")
+ error += "瀹㈡埛璁㈠崟鍙蜂笉鑳戒负绌�;";
+ if (tb2.Rows[i]["鐗╂枡缂栫爜"].ToString() == "")
+ error += "鐗╂枡缂栫爜涓嶈兘涓虹┖;";
+
+ if (error.Length > 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = ErrorResult += $"Excel妯℃澘瀛樺湪閿欒锛岃鏁皗i + 1}:{error}\r\n"; ;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ //鏌ユ壘鏄惁瀛樺湪瀵瑰簲鐢熶骇璁㈠崟
+ string sql1 = string.Format("select * from h_v_IF_ICMOBillList where 瀹㈡埛璁㈠崟鍙�='{0}' and 浜у搧浠g爜='{1}' and 鐘舵�� in ('璁″垝纭','寮�宸�')",
+ tb2.Rows[i]["瀹㈡埛璁㈠崟鍙�"].ToString(), tb2.Rows[i]["鐗╂枡缂栫爜"].ToString());
+ ds = oCN.RunProcReturn(sql1, "h_v_IF_ICMOBillList");
+
+ if (ds.Tables[0].Rows.Count == 0)
+ {
+ error += $"娌℃湁绗﹀悎鏉′欢寰楃敓浜ц鍗曚俊鎭紝瀹㈡埛璁㈠崟鍙�:{ tb2.Rows[i]["瀹㈡埛璁㈠崟鍙�"].ToString()},浜у搧浠g爜:{tb2.Rows[i]["鐗╂枡缂栫爜"].ToString()}";
+ }
+
+ if (error.Length > 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = ErrorResult += $"Excel妯℃澘瀛樺湪閿欒锛岃鏁皗i + 1}:{error}\r\n"; ;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ else
+ {
+ tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HMaterID"].ToString();
+ tb2.Rows[i]["ICMOBillHInterID"] = ds.Tables[0].Rows[0]["hmainid"].ToString();//鐢熶骇璁㈠崟涓籭d
+ tb2.Rows[i]["ICMOBillHEntryID"] = ds.Tables[0].Rows[0]["HEntryID"].ToString();//鐢熶骇璁㈠崟瀛恑d
+ }
+ //鏌ユ壘鏄惁瀛樺湪瀵瑰簲鏃ヨ鍒掑伐鍗�
+ var dt = oCN.RunProcReturn($"select * from h_v_JIT_Sc_WorkBillSortBillList where 婧愬崟涓诲唴鐮� in({ds.Tables[0].Rows[0]["hmainid"].ToString()}) and 婧愬崟瀛愬唴鐮� in({ds.Tables[0].Rows[0]["HEntryID"].ToString()})", "h_v_JIT_Sc_WorkBillSortBillList");
+ if (dt.Tables[0].Rows.Count > 0)
+ {
+ tb2.Rows[i]["hmainid"] = dt.Tables[0].Rows[0]["hmainid"].ToString();
+ }
+
+ }
+
+ objJsonResult.code = "1";
+ objJsonResult.count = 1;
+ objJsonResult.Message = ErrorResult;
+ objJsonResult.data = tb2;
+ return objJsonResult;
+ }
+ catch (Exception e)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "Exception锛�" + e.ToString();
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ }
+ #endregion
+
+ #region 鐢熶骇鏃ヨ鍒掍笁鍗� 瀵煎叆(淇濆瓨)
+ [Route("JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_btnSave_SS")]
+ [HttpPost]
+ public object JIT_DayPlanPlatFormImport_btnSave_SS([FromBody] JObject sMainSub)
+ {
+ var _value = sMainSub["sMainSub"].ToString();
+ string msg1 = _value.ToString();
+ oCN.BeginTran();
+ //淇濆瓨涓昏〃
+ objJsonResult = AddBillMain_SS(msg1);
+ if (objJsonResult.code == "0")
+ {
+ oCN.RollBack();
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = objJsonResult.Message;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ oCN.Commit();
+ objJsonResult.code = "1";
+ objJsonResult.count = 1;
+ objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+
+ public json AddBillMain_SS(string msg1)
+ {
+ string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+ string msg2 = sArray[0].ToString();
+ string msg3 = sArray[1].ToString();
+ string user = sArray[2].ToString();
+
+ try
+ {
+ if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Edit", 1, false, user))
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+
+ //琛ㄥご瀛楁
+ omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<Sc_WorkBillSortBillMain>(msg2);
+
+ //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚�
+ List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
+ List<object> jb = JsonConvert.DeserializeObject<List<object>>(msg3);
+ foreach (JObject item in jb)
+ {
+ Dictionary<string, string> dic = new Dictionary<string, string>();
+ foreach (var itm in item.Properties())
+ {
+ dic.Add(itm.Name, itm.Value.ToString());
+ }
+ list.Add(dic);
+ }
+
+
+
+
+ for (int i = 0; i < list.Count; i++)
+ {
+ long HInterID = 0;
+ var HBillNo = "";
+ if (list[i]["hmainid"].ToString() == "")
+ {
+ HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);//鑾峰緱涓�涓柊鐨勫崟鎹彿
+ HInterID = DBUtility.ClsPub.CreateBillID_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo);//鑾峰緱涓�涓柊鐨刬d
+ var HMainSourceInterID = list[i]["ICMOBillHInterID"].ToString();
+ var HMainSourceEntryID = list[i]["ICMOBillHEntryID"].ToString();
+ var HPlanEndDate = list[i]["璁″垝缁撴潫鏃ユ湡"].ToString();
+ //鑾峰彇瀵瑰簲璁㈠崟淇℃伅
+ ds = oCN.RunProcReturn($"exec h_p_ICMOBillList_PrimarySubTable '{HMainSourceInterID}','{HMainSourceEntryID}'", "h_p_ICMOBillList_PrimarySubTable");
+ if (ds.Tables[0].Rows.Count == 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = $"娌℃壘鍒板搴旂鍚堟潯浠跺緱璁㈠崟淇℃伅锛岃鏁皗i + 1}\r\n"; ;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ var HICMOBillNo = ds.Tables[0].Rows[0]["鐢熶骇璁㈠崟鍙�"].ToString();
+ var HICMOEntrySEQ = ds.Tables[0].Rows[0]["鐢熶骇璁㈠崟鏄庣粏琛屽彿"].ToString();
+ var HProdORGID = ds.Tables[0].Rows[0]["HProdORGID"].ToString();
+ var HWorkShopID = ds.Tables[0].Rows[0]["HWorkShopID"].ToString();
+ var HSourceID = ds.Tables[0].Rows[0]["HSourceID"].ToString();
+ var HWorkQty = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["灏忔椂浜ц兘"].ToString());
+ var HYX = ds.Tables[0].Rows[0]["浼樺厛绾�"].ToString();
+ var HEmpID = ds.Tables[0].Rows[0]["鎿嶄綔宸�"].ToString();
+ var HMaterID = ds.Tables[0].Rows[0]["HMaterID"].ToString();
+ var HMaterName = ds.Tables[0].Rows[0]["鐗╂枡鍚嶇О"].ToString();
+ var HMaterModel = ds.Tables[0].Rows[0]["瑙勬牸鍨嬪彿"].ToString();
+ var HUnitID = ds.Tables[0].Rows[0]["HUnitID"].ToString();
+ var HBatchNo = "";//鎵规鍙�
+ var HSeOrderBillQty = ds.Tables[0].Rows[0]["閿�鍞鍗曟暟閲�"].ToString();
+ var HPlanQty = ds.Tables[0].Rows[0]["璁″垝鏁伴噺"].ToString();
+ var HCompleteQty = "";//鎬婚綈濂楁暟閲�
+ var HOrderType = omdelMian.HOrderType;
+ var HDate = omdelMian.HDate;
+ var HSeOrderBillNo = ds.Tables[0].Rows[0]["閿�鍞鍗曞彿"].ToString();
+ //涓昏〃
+ oCN.RunProc("insert into Sc_WorkBillSortBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType," +
+ "HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HICMOBillNo,HOrderType," +
+ "HICMOEntrySEQ,HWorkShopID,HSourceID, HYX,HWorkQty, HEmpID," +
+ " HMaterID, HMaterName, HMaterModel, HUnitID, HBatchNo," +
+ " HSeOrderBillQty, HPlanQty, HCompleteQty,HPreparatDate," +
+ "HMainSourceInterID,HMainSourceEntryID,HICMOInterID,HICMOEntryID,HProdORGID,HICMOInterID_Sec,HICMOEntryID_Sec" +
+ ",HSeOrderBillNo,HPlanEndDate)values" +
+ $"({HInterID},'{HBillNo}',{DateTime.Now.Year},{DateTime.Now.Month},'{BillType}'," +
+ $"'{BillType}',GETDATE(),1,'{user}','{HDate}','{HICMOBillNo}','{HOrderType}'," +
+ $"{(HICMOEntrySEQ == "" ? 0.ToString() : HICMOEntrySEQ)},{(HWorkShopID == "" ? 0.ToString() : HWorkShopID)},{(HSourceID == "" ? 0.ToString() : HSourceID)}, {(HYX == "" ? 0.ToString() : HYX)},{(HWorkQty)}, {(HEmpID == "" ? 0.ToString() : HEmpID)}," +
+ $" {(HMaterID == "" ? 0.ToString() : HMaterID)}, '{HMaterName}', '{HMaterModel}', {(HUnitID == "" ? 0.ToString() : HUnitID)}, '{HBatchNo}'," +
+ $" {(HSeOrderBillQty == "" ? 0.ToString() : HSeOrderBillQty)}, {(HPlanQty == "" ? 0.ToString() : HPlanQty)}, {(HCompleteQty == "" ? 0.ToString() : HCompleteQty)},getdate()," +
+ $" {HMainSourceInterID},{HMainSourceEntryID},{HMainSourceInterID},{HMainSourceEntryID},{HProdORGID}, {HMainSourceInterID},{HMainSourceEntryID}" +
+ $",'{HSeOrderBillNo}','{HPlanEndDate}')");
+ //鎻掑叆瀛愯〃鏁版嵁
+ objJsonResult = AddBillSub(HInterID.ToString(), HBillNo, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0);
+ }//濡傛灉宸插瓨鍦ㄦ棩璁″垝宸ュ崟鏇存柊瀵瑰簲璁″垝缁撴潫鏃ユ湡
+ else
+ {
+ var hmainid = list[i]["hmainid"].ToString();
+ var HPlanEndDate = list[i]["璁″垝缁撴潫鏃ユ湡"].ToString();
+ //涓昏〃
+ oCN.RunProc($"update Sc_WorkBillSortBillMain set HPlanEndDate = '{HPlanEndDate}' where HInterID ={hmainid}" );
+ }
+
+ }
+
+
+
+ objJsonResult.code = "1";
+ objJsonResult.count = 1;
+ objJsonResult.Message = null;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ catch (Exception e)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "Exception锛�" + e.ToString();
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ }
+ #endregion
+
}
}
\ No newline at end of file
--
Gitblit v1.9.1