From 02aea9b1a44461c5f4f79d458670b2212e505a86 Mon Sep 17 00:00:00 2001 From: yangle <admin@YINMOU> Date: 星期四, 09 三月 2023 13:26:29 +0800 Subject: [PATCH] 末道工序同步 --- WebAPI/Config/kdapi.config | 10 WebAPI/InvokeHelper.cs | 264 ++++++++++++++++++++ WebAPI/Utility/Util.cs | 124 +++++++++ WebAPI/WebAPI.csproj | 4 WebAPI/HttpClient.cs | 103 +++++++ WebAPI/Controllers/ReportController.cs | 257 +++++++++++++++++++ 6 files changed, 761 insertions(+), 1 deletions(-) diff --git a/WebAPI/Config/kdapi.config b/WebAPI/Config/kdapi.config new file mode 100644 index 0000000..45e2a70 --- /dev/null +++ b/WebAPI/Config/kdapi.config @@ -0,0 +1,10 @@ +锘�<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <appSettings> + <add key="DbId" value="6204a70eba35fc"></add> + <add key="UserName" value="Administrator"></add> + <add key="PassWord" value="qaz!@#123"></add> + <add key="KDApiUrl" value="http://47.96.97.237/K3Cloud/"></add> + <add key="DataBaseName" value="AIS20210811135644"></add> + </appSettings> +</configuration> \ No newline at end of file diff --git a/WebAPI/Controllers/ReportController.cs b/WebAPI/Controllers/ReportController.cs index a60ca4b..1c27082 100644 --- a/WebAPI/Controllers/ReportController.cs +++ b/WebAPI/Controllers/ReportController.cs @@ -1,4 +1,5 @@ -锘縰sing Newtonsoft.Json.Linq; +锘縰sing Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; @@ -115,5 +116,259 @@ } // + + #region 鏈亾宸ュ簭姹囨姤鍏ュ簱 + /// <summary> + /// 鏈亾宸ュ簭姹囨姤鍏ュ簱鍒楄〃 + /// </summary> + /// <param name="sWhere"></param> + /// <param name="user"></param> + /// <returns></returns> + [Route("Sc_ProcessMangement/Sc_ProcessReportList_Last")] + [HttpGet] + public object Sc_ProcessReportList_Last(string sWhere, string user) + { + try + { + string sql1 = "select * from h_v_Sc_ProcessReportList_Last where 1 = 1 and HLastProc='鏄�'"; + string sql = sql1 + sWhere + " order by hmainid desc"; + ds = oCN.RunProcReturn(sql, "h_v_Sc_ProcessReportList_Last"); + + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "Sucess锛�"; + 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 鏂帿灏� 鏈亾宸ュ簭姹囨姤鍒楄〃 姹囨姤 鍏ュ簱 + /// <summary> + /// 鐢熸垚 鐢熶骇姹囨姤鍗� + /// 鍚屾閲戣澏浜� 宸ュ簭姹囨姤鍏ュ簱鍗� 鍏ュ簱 + /// </summary> + /// <param name="InterID"></param> + /// <param name="user"></param> + /// <param name="BillNo"></param> + /// <param name="OrganizationID"></param> + /// <returns></returns> + [Route("Sc_ProcessMangement/SRM_SaveICMOReportBill")] + [HttpGet] + public object SRM_SaveICMOReportBill(string InterID, string user, string BillNo, string OrganizationID) + { + try + { + //鑾峰彇鐢熶骇姹囨姤鍗曟渶澶nterID鍜屽崟鎹彿 + Int64 HInterID = DBUtility.ClsPub.CreateBillID("3711", ref DBUtility.ClsPub.sExeReturnInfo); + string HBillNo = DBUtility.ClsPub.CreateBillCode("3711", ref DBUtility.ClsPub.sExeReturnInfo, true); + HBillNo = "9010-" + HBillNo; + //鑾峰彇缁勭粐浠g爜 + string OrganizationNUM = oCN.RunProcReturn("select HNumber from Xt_ORGANIZATIONS where HItemID=" + OrganizationID, "Xt_ORGANIZATIONS").Tables[0].Rows[0]["HNumber"].ToString(); + //鏍规嵁宸ュ簭姹囨姤鍗曚富ID鑾峰彇宸ュ簭姹囨姤鍏ュ簱鍗曠殑鏁版嵁 + DataSet ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList_LastProc where HInterID=" + InterID, "h_v_MES_StationOutBillList_LastProc"); + DataRow dr = ds.Tables[0].Rows[0]; + + //淇濆瓨 + oCN.BeginTran(); + DataSet DsTable = oCN.RunProcReturn($"select * from Sc_ICMOReportBillMain where HBillNo='{HBillNo}'", "Sc_ICMOReportBillMain"); + if (DsTable.Tables[0].Rows.Count > 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "宸插叆搴�,璇蜂笉瑕侀噸澶嶅叆搴�"; + objJsonResult.data = null; + return objJsonResult; + } + //鐢熶骇姹囨姤鍗曚富琛� + oCN.RunProc("Insert Into Sc_ICMOReportBillMain " + + "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" + + ",HYear,HPeriod,HRemark,HEmpID,HEmpNumber" + + ",HGroupID,HDeptID,HDeptNumber" + + ",HMainSourceBillNo,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillType" + + ") " + + " values('3711','3711'," + HInterID.ToString() + ",'" + HBillNo + "',getdate(),'" + user + "',getdate(),2,'" + user + "',getdate()" + + ",DATENAME(YEAR,GETDATE()),"+DateTime.Now.Month+",'','" + dr["HEmpID"].ToString() + "','" + dr["鎿嶄綔鍛樹唬鐮�"].ToString() + + "','" + dr["HGroupID"].ToString() + "',0,''" + + ",'" + BillNo.ToString() + "'," + InterID.ToString() + ", 0,'3791'" + + ") "); + //鐢熶骇姹囨姤鍗曞瓙琛� + oCN.RunProc("Insert into Sc_ICMOReportBillSub " + + " (HInterID,HEntryID,HMaterID,HMaterNumber" + + ",HQty,HUnitID,HUnitNumber,HTimes,HSourceID" + + ",HQtyMust,HWorkerID,HWorkerNumber,HBadCount,HWasterQty," + + "HCloseMan,HCloseType,HRemark," + + "HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + + ",HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo" + + ",HICMOInterID,HICMOBillNo,HBarCode" + + ") values(" + + HInterID.ToString() + ",1," + dr["HMaterID"].ToString() + ",'" + dr["浜у搧浠g爜"].ToString() + "'" + + "," + dr["鍚堟牸鏁伴噺"].ToString() + ",0,'',0,0" + + "," + dr["鎺ユ敹鏁伴噺"].ToString() + "," + dr["HEmpID"].ToString() + ",'" + dr["鎿嶄綔鍛樹唬鐮�"].ToString() + "'," + dr["涓嶈壇鏁伴噺"].ToString() + "," + dr["鎶ュ簾鏁伴噺"].ToString() + + ",'',0,''" + + "," + InterID.ToString() + ",0,'" + BillNo.ToString() + "','3791',0,0" + + ",0,0,''" + + "," + dr["HICMOInterID"].ToString() + ",'" + dr["浠诲姟鍗�"].ToString() + "',''" + + ") "); + //鍚屾閲戣澏 + //璁块棶閲戣澏 + var loginRet = InvokeHelper.Login(); + var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>(); + if (isSuccess == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鎿嶄綔澶辫触,閲戣澏璐﹀彿鐧诲綍寮傚父銆�" + loginRet; + objJsonResult.data = null; + return objJsonResult; + } + + //鏍规嵁浠诲姟鍗曟煡鎵惧埌閲戣澏鐨勭敓浜ц鍗� + DataSet ds1 = oCN.RunProcReturn("select * from h_v_TOERP_StationOutBillList_LastProc_SMR where 鍗曟嵁鍙�='" + dr["鍗曟嵁鍙�"].ToString()+"'" , "h_v_TOERP_StationOutBillList_LastProc_SMR"); + + if (ds1.Tables[0].Rows.Count == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "鎿嶄綔澶辫触,閫氳繃鍑虹珯鍗曟煡涓嶅埌鐢熶骇璁㈠崟鏁版嵁"; + objJsonResult.data = null; + return objJsonResult; + } + DataRow dr1 = ds1.Tables[0].Rows[0]; + + JObject model = new JObject(); + model.Add("FBillType", new JObject() { ["Fnumber"] = "SCHBD01_SYS" }); //鍗曟嵁绫诲瀷鐢熶骇姹囨姤鈥淪CHBD02_SYS鈥� 鍏ュ簱姹囨姤SCHBD01_SYS + model.Add("FPrdOrgId", new JObject() { ["Fnumber"] = dr1["FPrdOrgNUMBER"].ToString() }); //鐢熶骇缁勭粐1 + model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //鍗曟嵁鏃ユ湡1 + model.Add("FBillNo", HBillNo); + model.Add("F_RCZU_LZKH", dr1["宸ュ簭娴佽浆鍗″彿"].ToString()); + + JArray Fentity = new JArray(); + + foreach (DataRow item in ds.Tables[0].Rows) + { + JObject FentityModel = new JObject(); + FentityModel.Add("FIsNew", false);// 婧愬崟绫诲瀷 + FentityModel.Add("FReportType", new JObject() { ["Fnumber"] = dr1["FREPORTTYPENUMBER"].ToString() });//鐢熶骇姹囨姤绫诲瀷 + FentityModel.Add("FSrcBillType", "PRD_MO");// 婧愬崟绫诲瀷 + FentityModel.Add("FProductType", "1");// 浜у搧绫诲瀷 + FentityModel.Add("FSrcBillNo", item["浠诲姟鍗�"].ToString());// 婧愬崟缂栧彿 + FentityModel.Add("FSrcInterId", dr1["FMOID"].ToString());// 婧愬崟鍐呯爜 + FentityModel.Add("FSrcEntryId", dr1["FMOENTRYID"].ToString());// 婧愬崟鍒嗗綍鍐呯爜銆� + FentityModel.Add("FSRCENTRYSEQ", dr1["FMOENTRYSEQ"].ToString());// 婧愬崟鍒嗗綍琛屽彿 + FentityModel.Add("FUNITID", new JObject() { ["Fnumber"] = dr1["FUNITNUMBER"].ToString() });//鍗曚綅 + FentityModel.Add("FTimeUnitId", "1");//鏃堕棿鍗曚綅 + FentityModel.Add("FWorkshipId", new JObject() { ["Fnumber"] = dr1["FWorkShopNUM"].ToString() }); // 鐢熶骇杞﹂棿 + FentityModel.Add("FStandHourUnitId", "3600"); // 鍗曚綅鏍囧噯宸ユ椂鍗曚綅 + FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = dr1["FMaterialNUM"].ToString() }); // 鐗╂枡缂栫爜 + FentityModel.Add("FMoEntrySeq", dr1["FMOENTRYSEQ"].ToString());//鐢熶骇璁㈠崟琛屽彿 + FentityModel.Add("FMoId", dr1["HICMOInterID"].ToString());//鐢熶骇璁㈠崟鍐呯爜 + FentityModel.Add("FFinishQty", item["鎺ユ敹鏁伴噺"].ToString());//瀹屾垚鏁伴噺1 + FentityModel.Add("FQuaQty", item["鍚堟牸鏁伴噺"].ToString());//鍚堟牸鏁伴噺1FFailQty + FentityModel.Add("FFailQty", item["涓嶈壇鏁伴噺"].ToString());//涓嶅悎鏍兼暟閲� + FentityModel.Add("FStockInOrgId ", new JObject() { ["Fnumber"] = OrganizationNUM });// 鍏ュ簱缁勭粐 + FentityModel.Add("FStockId", new JObject() { ["Fnumber"] = dr1["FStockNUM"].ToString() }); // 浠撳簱 + FentityModel.Add("FMOBILLNO", dr1["FMOBILLNO"].ToString());// + FentityModel.Add("FMOENTRYID", dr1["FMOENTRYID"].ToString());// + FentityModel.Add("FOwnerTypeId", dr1["FOWNERTYPEID"].ToString()); //璐т富绫诲瀷锛欶OwnerTypeId(蹇呭~椤�) + FentityModel.Add("FOwnerId", new JObject() { ["Fnumber"] = dr1["FOwnerNumber"].ToString() }); //璐т富锛欶OwnerId(蹇呭~椤�) + FentityModel.Add("FBomId", new JObject() { ["F number"] = dr1["FBOMNUM"].ToString() }); //BOM鐗堟湰锛欶BomId(蹇呭~椤�) + FentityModel.Add("FCostRate", dr1["FCostRate"].ToString());// 鎴愭湰鏉冮噸 + FentityModel.Add("FISBACKFLUSH", dr1["FISBACKFLUSH"].ToString() == "1" ? true : false);// 鍊掑啿棰嗘枡 + FentityModel.Add("FMOMAINENTRYID", dr1["FMOENTRYID"].ToString());// + FentityModel.Add("FLot", new JObject() { ["FNumber"] = dr1["FBATCHNO"].ToString() }); //鎵瑰彿 + //FentityModel.Add("F_RCZU_LZKH", dr1["宸ュ簭娴佽浆鍗″彿"].ToString());// 宸ュ簭娴佽浆鍗� + JArray Fentity2 = new JArray(); + JObject FentityModel2 = new JObject(); + FentityModel2.Add("FEntity_Link_FFlowId", "f6e6eec3-5267-4f02-8593-b633da508a72"); + FentityModel2.Add("FEntity_Link_FFlowLineId", "PRD_MO2MORPT"); + FentityModel2.Add("FEntity_Link_FRuleId", "3"); + FentityModel2.Add("FEntity_Link_FSTableId", "0"); + FentityModel2.Add("FEntity_Link_FSTableName", "T_PRD_MOENTRY"); + FentityModel2.Add("FEntity_Link_FSBillId", dr1["FMOID"].ToString()); + FentityModel2.Add("FEntity_Link_FSId", dr1["FMOENTRYID"].ToString()); + FentityModel2.Add("FEntity_Link_FBaseQuaQtyOld", item["鍚堟牸鏁伴噺"].ToString()); + FentityModel2.Add("FEntity_Link_FBaseQuaQty", item["鍚堟牸鏁伴噺"].ToString()); + Fentity2.Add(FentityModel2); + FentityModel.Add("FEntity_Link", Fentity2); + Fentity.Add(FentityModel); + } + model.Add("FEntity", Fentity); //鏄庣粏淇℃伅 + JObject jsonRoot = new JObject() + { + ["Creator"] = "", + ["NeedUpDateFields"] = new JArray(), + ["NeedReturnFields"] = new JArray(), + ["IsDeleteEntry"] = "false", + ["SubSystemId"] = "", + ["IsVerifyBaseDataField"] = "false", + //["IsAutoSubmitAndAudit"] = true,//鑷姩璋冪敤鎻愪氦鍜屽鏍稿姛鑳� + ["Model"] = model + }; + + string result = InvokeHelper.Save("PRD_MORPT", JsonConvert.SerializeObject(jsonRoot));//淇濆瓨 + //鍒ゆ柇淇濆瓨鏄惁鎴愬姛 + if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE") + { + LogService.Write("宸ュ簭姹囨姤鍗曞叆搴撻敊璇痡sonRoot:" + jsonRoot); + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = $"鐢熶骇姹囨姤鍏ュ簱鍗曞悓姝ラ噾铦朵簯澶辫触锛佸崟鍙�:{dr["鍗曟嵁鍙�"].ToString()}" + result; + objJsonResult.data = null; + return objJsonResult; + } + //鎻愪氦瀹℃牳 + string result1 = string.Empty; + string result2 = string.Empty; + var fID = JObject.Parse(result)["Result"]["Id"].ToString(); + var fBillNo = JObject.Parse(result)["Result"]["Number"].ToString(); + var json = new + { + Ids = fID, + }; + result1 = InvokeHelper.Submit("PRD_MORPT", JsonConvert.SerializeObject(json));//鎻愪氦 + result2 = InvokeHelper.Audit("PRD_MORPT", JsonConvert.SerializeObject(json));//鎻愪氦 + if (JObject.Parse(result1)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE") + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = $"鐢熶骇姹囨姤鍗曞崟鍙凤細{fBillNo}锛屾彁浜ゅけ璐�" + result; + objJsonResult.data = null; + return objJsonResult; + } + + oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where HBillNo='" + BillNo + "'"); + + oCN.Commit(); + objJsonResult.code = "0"; + objJsonResult.count = 1; + objJsonResult.Message = "淇濆瓨鎴愬姛锛�"; + objJsonResult.data = 1; + return objJsonResult; + } + catch (Exception e) + { + oCN.RollBack(); + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "Exception锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + #endregion + + } } \ No newline at end of file diff --git a/WebAPI/HttpClient.cs b/WebAPI/HttpClient.cs new file mode 100644 index 0000000..609f1b6 --- /dev/null +++ b/WebAPI/HttpClient.cs @@ -0,0 +1,103 @@ +锘縰sing System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System.Threading.Tasks; + +namespace WebAPI +{ + public class HttpClient + { + /// <summary> + /// Seivice URL + /// </summary> + public string Url { get; set; } + /// <summary> + /// 鍐呭 + /// </summary> + public string Content { get; set; } + /// <summary> + /// Cookie锛屼繚璇佺櫥褰曞悗锛屾墍鏈夎闂寔鏈変竴涓狢ookie锛� + /// </summary> + static CookieContainer Cookie = new CookieContainer(); + + /// <summary> + /// HTTP璁块棶 + /// </summary> + public string SyncRequest() + { + HttpWebRequest httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest; + httpRequest.Method = "POST"; + httpRequest.ContentType = "application/json"; + httpRequest.CookieContainer = Cookie; + httpRequest.Timeout = 1000 * 60 * 10;//10min + + using (Stream reqStream = httpRequest.GetRequestStream()) + { + JObject jObj = new JObject(); + jObj.Add("format", 1); + jObj.Add("useragent", "ApiClient"); + jObj.Add("rid", Guid.NewGuid().ToString().GetHashCode().ToString()); + jObj.Add("parameters", Content); + jObj.Add("timestamp", DateTime.Now); + jObj.Add("v", "1.0"); + string sContent = jObj.ToString(); + var bytes = UnicodeEncoding.UTF8.GetBytes(sContent); + reqStream.Write(bytes, 0, bytes.Length); + reqStream.Flush(); + } + using (var repStream = httpRequest.GetResponse().GetResponseStream()) + { + using (var reader = new StreamReader(repStream)) + { + return ValidateResult(reader.ReadToEnd()); + } + } + } + + + public async Task<string> AsyncRequest() + { + HttpWebRequest httpRequest = WebRequest.Create(Url) as HttpWebRequest; + httpRequest.Method = "POST"; + httpRequest.ContentType = "application/json"; + httpRequest.CookieContainer = Cookie; + httpRequest.Timeout = 1000 * 60 * 10;//10min + + using (Stream reqStream = await httpRequest.GetRequestStreamAsync()) + { + JObject jObj = new JObject(); + jObj.Add("format", 1); + jObj.Add("useragent", "ApiClient"); + jObj.Add("rid", Guid.NewGuid().ToString().GetHashCode().ToString()); + jObj.Add("parameters", Content); + jObj.Add("timestamp", DateTime.Now); + jObj.Add("v", "1.0"); + string content = jObj.ToString(); + var bytes = Encoding.UTF8.GetBytes(content); + reqStream.Write(bytes, 0, bytes.Length); + reqStream.Flush(); + } + using (var repStream = (await httpRequest.GetResponseAsync()).GetResponseStream()) + { + using (var reader = new StreamReader(repStream)) + { + return ValidateResult(await reader.ReadToEndAsync()); + } + } + } + + private static string ValidateResult(string responseText) + { + if (responseText.StartsWith("response_error:")) + { + responseText.TrimStart("response_error:".ToCharArray()); + } + return responseText; + } + } +} \ No newline at end of file diff --git a/WebAPI/InvokeHelper.cs b/WebAPI/InvokeHelper.cs new file mode 100644 index 0000000..2cdb5c3 --- /dev/null +++ b/WebAPI/InvokeHelper.cs @@ -0,0 +1,264 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using WebAPI.Utility; + +namespace WebAPI +{ + public static class InvokeHelper + { + private static string CloudUrl = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "KDApiUrl");//K/3 Cloud 涓氬姟绔欑偣鍦板潃 + /// <summary> + /// 鐧婚檰 + /// </summary> + public static string Login() + { + var dbId = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DbId"); + var useName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "UserName"); + var pwd = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "PassWord"); + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc"); + + List<object> Parameters = new List<object>(); + Parameters.Add(dbId);//璐﹀鏍囩ず + Parameters.Add(useName);//鐢ㄦ埛鍚� + Parameters.Add(pwd);//瀵嗙爜 + Parameters.Add(2052);//2052浠h〃涓枃 + httpClient.Content = JsonConvert.SerializeObject(Parameters); + + return httpClient.SyncRequest(); + } + + public static async Task<string> LoginAsync() + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc"); + List<object> Parameters = new List<object>(); + Parameters.Add("622703e117d642");//璐﹀鏍囩ず + Parameters.Add("Administrator");//鐢ㄦ埛鍚� + Parameters.Add("sa@123456");//瀵嗙爜 + Parameters.Add(2052);//2052浠h〃涓枃 + httpClient.Content = JsonConvert.SerializeObject(Parameters); + + return await httpClient.AsyncRequest(); + } + + /// <summary> + /// 淇濆瓨 + /// </summary> + /// <param name="formId"></param> + /// <param name="content"></param> + /// <returns></returns> + public static string Save(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + + public static string BatchSave(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + + public static async Task<string> SaveAsync(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save.common.kdsvc"); + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return await httpClient.AsyncRequest(); + } + + /// <summary> + /// 鎻愪氦 + /// </summary> + /// <param name="formId"></param> + /// <param name="content"></param> + /// <returns></returns> + public static string Submit(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + /// <summary> + /// 鍒犻櫎 + /// </summary> + /// <param name="formId"></param> + /// <param name="content"></param> + /// <returns></returns> + public static string Delete(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + + public static async Task<string> DeleteAsync(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return await httpClient.AsyncRequest(); + } + + + /// <summary> + /// 瀹℃牳 + /// </summary> + /// <param name="formId"></param> + /// <param name="content"></param> + /// <returns></returns> + public static string Audit(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + /// <summary> + /// 鏌ヨ + /// </summary> + /// <param name="formId"></param> + /// <param name="content"></param> + /// <returns></returns> + public static string View(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + + //鍙嶅鏍� + public static string UnAudit(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + //涓嬫帹 + public static string Push(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Push.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + + public static string Query(string formId, string content) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc"); + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + //Parameters.Add(formId); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + + /// <summary> + /// 鑷畾涔� + /// </summary> + /// <param name="key">鑷畾涔夋柟娉曟爣璇�</param> + /// <param name="args">鍙傛暟</param> + /// <returns></returns> + public static string AbstractWebApiBusinessService(string key, List<object> args) + { + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, key, ".common.kdsvc"); + + httpClient.Content = JsonConvert.SerializeObject(args); + return httpClient.SyncRequest(); + } + + //鐢熶骇璁㈠崟 鎵ц + public static string ExcuteOperation(string formId, string opNumber, string content) + { + LogService.Write("鐢熶骇璁㈠崟 鎵ц锛宱pNumber锛� " + opNumber + ",content:" + content); + HttpClient httpClient = new HttpClient(); + httpClient.Url = string.Concat(CloudUrl, "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExcuteOperation.common.kdsvc"); + + List<object> Parameters = new List<object>(); + //涓氬姟瀵硅薄Id + Parameters.Add(formId); + //鎿嶄綔 寮�宸�"ToStart" + Parameters.Add(opNumber); + //Json瀛椾覆 + Parameters.Add(content); + httpClient.Content = JsonConvert.SerializeObject(Parameters); + return httpClient.SyncRequest(); + } + } +} diff --git a/WebAPI/Utility/Util.cs b/WebAPI/Utility/Util.cs new file mode 100644 index 0000000..3e818fc --- /dev/null +++ b/WebAPI/Utility/Util.cs @@ -0,0 +1,124 @@ +锘縰sing Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace WebAPI.Utility +{ + public class Util + { + public static string GetObjectType(object obj) + { + var isType = false; + isType = obj.GetType() == typeof(string); + if (isType) + { + return "string"; + } + + isType = obj.GetType() == typeof(double); + if (isType) + { + return "double"; + } + + isType = obj.GetType() == typeof(long); + if (isType) + { + return "long"; + } + + isType = obj.GetType() == typeof(DateTime); + if (isType) + { + return "date"; + } + + isType = obj.GetType() == typeof(int); + if (isType) + { + return "int"; + } + + isType = obj.GetType() == typeof(decimal); + if (isType) + { + return "decimal"; + } + + return "string"; + } + + public static JObject JsonVerify(string json) + { + if (string.IsNullOrEmpty(json)) + { + throw new Exception("鍙傛暟涓嶈兘涓虹┖"); + } + try + { + return JObject.Parse(json.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", "")); + } + catch (Exception) + { + throw; + } + } + + //public static T DeepCopy<T>(T obj) + //{ + // object retval; + // using (MemoryStream ms = new MemoryStream()) + // { + // XmlSerializer xml = new XmlSerializer(typeof(T)); + // xml.Serialize(ms, obj); + // ms.Seek(0, SeekOrigin.Begin); + // retval = xml.Deserialize(ms); + // ms.Close(); + // } + // return (T)retval; + //} + + public static String GetConfigKey(String configPath, String key) + { + Configuration ConfigurationInstance = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() + { + ExeConfigFilename = configPath + }, ConfigurationUserLevel.None); + + + if (ConfigurationInstance.AppSettings.Settings[key] != null) + return ConfigurationInstance.AppSettings.Settings[key].Value; + else + + return string.Empty; + } + + public static bool SetConfigKey(String configPath, String key, String vls) + { + try + { + Configuration ConfigurationInstance = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() + { + ExeConfigFilename = configPath + }, ConfigurationUserLevel.None); + + if (ConfigurationInstance.AppSettings.Settings[key] != null) + ConfigurationInstance.AppSettings.Settings[key].Value = vls; + else + ConfigurationInstance.AppSettings.Settings.Add(key, vls); + ConfigurationInstance.Save(ConfigurationSaveMode.Modified); + ConfigurationManager.RefreshSection("appSettings"); + return true; + } + catch + { + return false; + } + } + } +} diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj index 14e122f..b9a9f23 100644 --- a/WebAPI/WebAPI.csproj +++ b/WebAPI/WebAPI.csproj @@ -248,6 +248,7 @@ <Content Include="Scripts\bootstrap.js" /> <Content Include="Scripts\bootstrap.min.js" /> <Fakes Include="Fakes\Newtonsoft.Json.fakes" /> + <Content Include="Config\kdapi.config" /> <None Include="Properties\PublishProfiles\API.pubxml" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> @@ -356,6 +357,8 @@ <Compile Include="Controllers\Sc_PackUnionBillController.cs" /> <Compile Include="Controllers\SellOutBackController.cs" /> <Compile Include="Controllers\SellOutController.cs" /> + <Compile Include="HttpClient.cs" /> + <Compile Include="InvokeHelper.cs" /> <Compile Include="ListModels.cs" /> <Compile Include="Models\ClsCg_POInStockBill.cs" /> <Compile Include="Models\GroupOrderBill.cs" /> @@ -373,6 +376,7 @@ <DesignTimeSharedInput>True</DesignTimeSharedInput> <DependentUpon>Settings.settings</DependentUpon> </Compile> + <Compile Include="Utility\Util.cs" /> <Compile Include="Web References\WebS\Reference.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> -- Gitblit v1.9.1