From 96bca0db0b7298f1e5a8510e3f657c2460276003 Mon Sep 17 00:00:00 2001 From: pzy <2829717936@qq.com> Date: 星期三, 18 九月 2024 10:15:22 +0800 Subject: [PATCH] 导入任务1 --- WebAPI/Controllers/BaseSet/Gy_CheckItemController.cs | 435 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 433 insertions(+), 2 deletions(-) diff --git a/WebAPI/Controllers/BaseSet/Gy_CheckItemController.cs b/WebAPI/Controllers/BaseSet/Gy_CheckItemController.cs index 73d3d35..b5e70f5 100644 --- a/WebAPI/Controllers/BaseSet/Gy_CheckItemController.cs +++ b/WebAPI/Controllers/BaseSet/Gy_CheckItemController.cs @@ -1,13 +1,17 @@ 锘縰sing DBUtility; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using SyntacticSugar.constant; using System; using System.Collections.Generic; using System.Data; +using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Web; using System.Web.Http; +using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�; using WebAPI.Models; namespace WebAPI.Controllers.BaseSet @@ -19,6 +23,7 @@ private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; + public DAL.ClsGy_QCCheckItem_Ctl BillOld = new DAL.ClsGy_QCCheckItem_Ctl(); #region 妫�楠岄」鐩垪琛ㄦ暟鎹� /// <summary> @@ -254,6 +259,18 @@ long HQCCheckClassID = list[0].HQCCheckClassID; string HDefaultResult = list[0].HDefaultResult; + long HUnitID = list[0].HUnitID; + string HAnalysisMethod = list[0].HAnalysisMethod; + string HDefectLevel = list[0].HDefectLevel; + long HDestructInspect = list[0].HDestructInspect; + long HKeyInspect = list[0].HKeyInspect; + long HQualityStdID = list[0].HQualityStdID; + long HInspectMethodID = list[0].HInspectMethodID; + long HInspectInstruMentID = list[0].HInspectInstruMentID; + long HInspectBasisID = list[0].HInspectBasisID; + long HSampleSchemeID = list[0].HSampleSchemeID; + long HISsystemSet = list[0].HISsystemSet; + if (!DBUtility.ClsPub.AllowNumber(HNumber)) { objJsonResult.code = "0"; @@ -270,9 +287,13 @@ //涓昏〃 oCN.RunProc("Insert Into Gy_QCCheckItem " + "(HNumber,HName,HHelpCode,HShortNumber,HParentID" + - ",HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HQCCheckClassID,HDefaultResult) " + + ",HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HQCCheckClassID,HDefaultResult" + + ",HAnalysisMethod,HDefectLevel,HUnitID,HDestructInspect,HKeyInspect,HQualityStdID" + + ",HInspectMethodID,HInspectInstruMentID,HInspectBasisID,HSampleSchemeID,HISsystemSet) " + " values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + HShortNumber + "','" + HItemID + "'" + - ",'"+ HLevel + "','0','" + Convert.ToString(HStopflag ? 1 : 0) + "','" + HRemark + "','鏈娇鐢�','"+ HQCCheckClassID + "','" + HDefaultResult + "')"); + ",'"+ HLevel + "','0','" + Convert.ToString(HStopflag ? 1 : 0) + "','" + HRemark + "','鏈娇鐢�','"+ HQCCheckClassID + "','" + HDefaultResult + + "','" + HAnalysisMethod + "','" + HDefectLevel + "'," + HUnitID + "," + HDestructInspect + "," + HKeyInspect + "," + HQualityStdID + + "," + HInspectMethodID + "," + HInspectInstruMentID + "," + HInspectBasisID + "," + HSampleSchemeID + "," + HISsystemSet + ")"); //淇敼涓婄骇涓洪潪鏈骇浠g爜 if (list[0].HItemID.ToString() != "") { @@ -345,7 +366,19 @@ string HRemark = list[0].HRemark; bool HStopflag = list[0].HStopflag; bool HUseFlag = list[0].HUseFlag; + string HDefaultResult = list[0].HDefaultResult; + long HUnitID = list[0].HUnitID; + string HAnalysisMethod = list[0].HAnalysisMethod; + string HDefectLevel = list[0].HDefectLevel; + long HDestructInspect = list[0].HDestructInspect; + long HKeyInspect = list[0].HKeyInspect; + long HQualityStdID = list[0].HQualityStdID; + long HInspectMethodID = list[0].HInspectMethodID; + long HInspectInstruMentID = list[0].HInspectInstruMentID; + long HInspectBasisID = list[0].HInspectBasisID; + long HSampleSchemeID = list[0].HSampleSchemeID; + long HISsystemSet = list[0].HISsystemSet; if (!DBUtility.ClsPub.AllowNumber(HNumber)) { @@ -378,6 +411,19 @@ ",HStopflag='" + HStopflag + "'" + ",HQCCheckClassID='" + HQCCheckClassID + "'" + ",HDefaultResult='" + HDefaultResult + "'" + + + ",HAnalysisMethod='" + HAnalysisMethod + "'" + + ",HDefectLevel='" + HDefectLevel + "'" + + ",HUnitID='" + HUnitID + "'" + + ",HDestructInspect='" + HDestructInspect + "'" + + ",HKeyInspect='" + HKeyInspect + "'" + + ",HQualityStdID='" + HQualityStdID + "'" + + ",HInspectMethodID='" + HInspectMethodID + "'" + + ",HInspectInstruMentID='" + HInspectInstruMentID + "'" + + ",HInspectBasisID='" + HInspectBasisID + "'" + + ",HSampleSchemeID='" + HSampleSchemeID + "'" + + ",HISsystemSet='" + HISsystemSet + "'" + + ",HRemark= '" + HRemark + "' Where HItemID=" + HItemID, ref DBUtility.ClsPub.sExeReturnInfo); //淇敼瀛愰」鐩唬鐮� //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_RepairCheck,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo); @@ -434,6 +480,37 @@ } #endregion + #region 妫�楠岄」鐩慨鏀硅幏鍙栫粦瀹氭暟鎹鍥� + /// <summary> + /// 缁翠慨鍒楄〃淇敼鎸夐挳鏂规硶 + ///鍙傛暟锛歴tring sql銆� + ///杩斿洖鍊硷細object銆� + /// </summary> + [Route("Gy_CheckItem/xg_View")] + [HttpGet] + public object xg_View(long HInterID) + { + try + { + ds = oCN.RunProcReturn("select * from h_v_Gy_QCCheckItemList_Edit where HItemID=" + HInterID, "h_v_Gy_QCCheckItemList_Edit"); + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = ""; + objJsonResult.data = ds.Tables[0]; + return objJsonResult; + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "Exception锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + #region 妫�楠岄」鐩幏鍙栨爲鍨嬪垪琛ㄦ暟鎹� [Route("Gy_CheckItem/LoadTree")] [HttpGet] @@ -461,5 +538,359 @@ } } #endregion + + #region 妫�楠岄」鐩鏍�/鍙嶅鏍� + [Route("Gy_CheckItem/AuditGy_CheckItem")] + [HttpGet] + public object AuditGy_CheckItem(string HInterID, int Type, string user) + { + try + { + //鍒ゆ柇鏄惁鏈夊鏍告潈闄� + if (!DBUtility.ClsPub.Security_Log("Gy_QCCheckItem_Check", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犳潈闄愬鏍�!"; + objJsonResult.data = null; + return objJsonResult; + } + + if (string.IsNullOrWhiteSpace(HInterID)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "HInterID涓虹┖锛�"; + objJsonResult.data = null; + return objJsonResult; + } + + ClsPub.CurUserName = user; + oCN.BeginTran();//寮�濮嬩簨鍔� + + //Type 1 瀹℃牳 2 鍙嶅鏍� + if (Type == 1) + { + //鍒ゆ柇鍗曟嵁鏄惁宸茬粡瀹℃牳 + DataSet ds; + string sql = "select * from Gy_QCCheckItem where HItemID = " + HInterID; + ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); + if (ds.Tables[0].Rows[0]["HCheckEmp"] != null && ds.Tables[0].Rows[0]["HCheckEmp"].ToString() != "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁宸插鏍�!涓嶈兘鍐嶆瀹℃牳锛�"; + objJsonResult.data = null; + return objJsonResult; + } + //瀹℃牳鍗曟嵁 + if (!BillOld.AuditByID2(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "瀹℃牳澶辫触!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + + else + { + //鍒ゆ柇鍗曟嵁鏄惁宸茬粡鍙嶅鏍� + DataSet ds; + string sql = "select * from Gy_QCCheckItem where HItemID = " + HInterID; + ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); + if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) + { + if (ds.Tables[0].Rows[0]["HCheckEmp"] == null || ds.Tables[0].Rows[0]["HCheckEmp"].ToString() == "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鍗曟嵁鏈鏍�!涓嶉渶瑕佸弽瀹℃牳!"; + objJsonResult.data = null; + return objJsonResult; + } + //鍙嶅鏍稿崟鎹� + if (!BillOld.DeAuditByID2(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) + { + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鍙嶅鏍稿け璐�!鍘熷洜:" + ClsPub.sExeReturnInfo; + objJsonResult.data = null; + return objJsonResult; + } + } + } + + oCN.Commit();//鎻愪氦浜嬪姟 + + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "鎵ц鎴愬姛锛�"; + objJsonResult.data = null; + return objJsonResult; ; + + } + catch (Exception e) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鎵ц澶辫触锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + #region 鏍¢獙椤圭洰鍒楄〃 鏂囦欢涓婁紶 + [Route("Gy_CheckItem/Gy_Process_Excel")] + [HttpPost] + public json Gy_Process_Excel() + { + json res = new json(); + 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 provisional = new DataTable("dt2"); + + //娣诲姞鍒楀悕 + for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) + { + provisional.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); + } + + //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁 + provisional.Columns.Add("HOrgID", typeof(Int32));//缁勭粐ID + provisional.Columns.Add("HDeptID", typeof(Int32));//閮ㄩ棬ID + + //娣诲姞鏁版嵁 + for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) + { + DataRow row = provisional.NewRow(); + for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) + { + row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); + } + provisional.Rows.Add(row); + } + + //鍒ゆ柇鍒� + string error = JudgmentColumns(provisional); + if (error.Length > 0) + { + res.code = "0"; + res.count = 0; + res.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n"; + res.data = null; + return res; + } + + for (int i = 0; i <= provisional.Rows.Count - 1; i++) + { + string HNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["浠g爜"].ToString()); + string HUSEORGID = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["缁勭粐浠g爜"].ToString()); + string HQCCheckClassID = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["妫�楠岄」鐩被鍒唬鐮�"].ToString()); + string HQCCheckClassName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["妫�楠岄」鐩被鍒悕绉�"].ToString()); + string HName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鍚嶇О"].ToString()); + string HORGName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["缁勭粐鍚嶇О"].ToString()); + string HHelpCode = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鍔╄鐮�"]); + string HRemark = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["澶囨敞"].ToString()); + + //鑾峰彇鐪熷疄琛屾暟 + int line = i + 1; + + if (HUSEORGID != "") + { + //鏌ヨ缁勭粐 + ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where HNumber='" + HUSEORGID + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS"); + + if (ds.Tables[0].Rows.Count == 0) + { + res.code = "0"; + res.count = 0; + res.Message = "绗�" + line + "琛�,缁勭粐涓嶅瓨鍦紒"; + res.data = null; + return res; + } + else + { + provisional.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); + } + string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString(); + + //鏌ヨ妫�楠岄」鐩槸鍚﹀瓨鍦� + DataSet checkClass = oCN.RunProcReturn("select * from Gy_QCCheckClass where HNumber = '" + HQCCheckClassID + "' and HName = '" + HQCCheckClassName + "'", "Gy_QCCheckClass"); + if (checkClass.Tables[0].Rows.Count == 0) + { + res.code = CodeConstant.FAIL; + res.count = CountConstant.FAIL; + res.Message = "绗�" + line + "琛�,妫�楠岄」鐩笉瀛樺湪锛�"; + res.data = null; + return res; + } + } + else + { + res.code = CodeConstant.FAIL; + res.count = CountConstant.FAIL; + res.Message = "绗�" + line + "琛�,缁勭粐浠g爜涓虹┖"; + res.data = null; + return res; + } + } + + res.code = "1"; + res.count = 1; + res.Message = error; + res.data = provisional; + return res; + } + catch (Exception e) + { + res.code = "0"; + res.count = 0; + res.Message = "Exception锛�" + e.ToString(); + res.data = null; + return res; + } + } + + /// <summary> + /// 鍒ゆ柇鍒� + /// </summary> + /// <param name="provisional"></param> + /// <returns></returns> + private static string JudgmentColumns(DataTable provisional) + { + var error = ""; + + //鏌ヨ娌℃湁鐨勫垪 + if (!provisional.Columns.Contains("缁勭粐浠g爜")) + error += "娌℃湁鎵惧埌銆愮粍缁囦唬鐮併�戠殑鏍囬,"; + + if(!provisional.Columns.Contains("妫�楠岄」鐩被鍒悕绉�")) + error += "娌℃湁鎵惧埌銆愭楠岄」鐩被鍒悕绉般�戠殑鏍囬,"; + return error; + } + #endregion + + #region 鏍¢獙椤圭洰鍒楄〃 瀵煎叆(淇濆瓨) + [Route("Gy_CheckItem/Gy_Process_btnSave")] + [HttpPost] + public object Gy_Group_btnSave([FromBody] JObject sMainSub) + { + var _value = sMainSub["sMainSub"].ToString(); + string msg1 = _value.ToString(); + string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries); + string msg2 = sArray[0].ToString(); + string user = sArray[1].ToString(); + try + { + if (!DBUtility.ClsPub.Security_Log("Gy_Group_Edit", 1, false, user)) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒"; + objJsonResult.data = null; + return objJsonResult; + } + + List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2); + List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); + + foreach (JObject item in Excel) + { + Dictionary<string, string> dic = new Dictionary<string, string>(); + foreach (var itm in item.Properties()) + { + dic.Add(itm.Name, itm.Value.ToString()); + } + list.Add(dic); + } + + oCN.BeginTran(); + int i = 1; + foreach (Dictionary<string, string> item in list) + { + string HNumber = item["浠g爜"].ToString(); + string HUSEORGID = item["缁勭粐浠g爜"].ToString(); + string HName = item["鍚嶇О"].ToString(); + string HORGName = item["缁勭粐鍚嶇О"].ToString(); + string HHelpCode = item["鍔╄鐮�"]; + string HQCCheckClassID = item["妫�楠岄」鐩被鍒唬鐮�"]; + string HRemark = item["澶囨敞"].ToString(); + + string sShortNumber; + sShortNumber = DBUtility.ClsPub.GetShortNumber(HNumber);//鐭唬鐮� + if (sShortNumber.Trim() == "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛佺煭浠g爜涓虹┖锛�"; + objJsonResult.data = 1; + return objJsonResult; + } + int HEndFlag = 1;//鏈骇鏍囧織 + int HLevel = DBUtility.ClsPub.GetLevel(HNumber); //绛夌骇 + + + if (!DBUtility.ClsPub.AllowNumber(HNumber.Trim())) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛佷唬鐮佷腑涓嶈兘鍑虹幇杩炵画鈥�.鈥欏苟涓旈浣嶆湯浣嶄笉鑳戒负鈥�.鈥欙紒"; + objJsonResult.data = 1; + return objJsonResult; + } + + ds = oCN.RunProcReturn("select * from Gy_QCCheckItem where HNumber='" + HNumber + "'", "Gy_QCCheckItem"); + + if (ds.Tables[0].Rows.Count == 0) + { + + string sql = "insert into Gy_QCCheckItem (HName,HNumber,HUSEORGID,HCREATEORGID,HShortNumber,HQCCheckClassID,HLevel,HHelpCode,HParentID,HStopflag,HUseFlag,HRemark, HMakeTime,HMakeEmp)" + + $"values('{HName}', '{HNumber}', {HUSEORGID}, {HUSEORGID}, '{sShortNumber}','{HQCCheckClassID}',{HLevel},'',0,0,'鏈娇鐢�','{HRemark}', '{System.DateTime.Now.ToString("G")}', '{user}')"; + oCN.RunProc(sql); + } + else + { + oCN.RunProc("update Gy_QCCheckItem set HName='" + HName + "', HHelpCode='" + HHelpCode + "', HQCCheckClassID = '" + HQCCheckClassID + "', HModifyEmp = '" + user + "', HModifyTime = '" + System.DateTime.Now.ToString("G") + "' where HNumber='" + HNumber + "'"); + } + + i++; + } + + oCN.Commit(); + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "瀵煎叆鎴愬姛!"; + objJsonResult.data = null; + return objJsonResult; + } + catch (Exception e) + { + LogService.Write(e); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "Exception锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion } } -- Gitblit v1.9.1