diff --git a/SGGL/BLL/Common/Funs.cs b/SGGL/BLL/Common/Funs.cs index 06a92c99..ac8c7aa8 100644 --- a/SGGL/BLL/Common/Funs.cs +++ b/SGGL/BLL/Common/Funs.cs @@ -1446,6 +1446,28 @@ namespace BLL return response.Content; } + public static string RequestPost(string Baseurl, Dictionary Token, string JsonBody) + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + + var client = new RestClient(Baseurl); + client.Timeout = -1; + var request = new RestRequest(Method.POST); + foreach (var item in Token) + { + request.AddHeader(item.Key, item.Value); + } + request.AddHeader("ClientId", SysConstSetService.ClientId); + request.AddHeader("OperationCode", Baseurl.Substring(Baseurl.LastIndexOf("/", StringComparison.Ordinal) + 1)); + if (!string.IsNullOrEmpty(JsonBody)) + { + request.AddJsonBody(JsonBody); + } + + IRestResponse response = client.Execute(request); + return response.Content; + } + /// /// 根据星期几返回值 /// diff --git a/SGGL/BLL/HSSE/CostGoods/CostManageService.cs b/SGGL/BLL/HSSE/CostGoods/CostManageService.cs index fab4c19f..f0f9faef 100644 --- a/SGGL/BLL/HSSE/CostGoods/CostManageService.cs +++ b/SGGL/BLL/HSSE/CostGoods/CostManageService.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; +using WIA; namespace BLL { @@ -373,74 +374,89 @@ namespace BLL } - /// 鎺ㄩ佹暟鎹埌HSE绯荤粺 - /// - public static string PushDataToHSE(string projectId, string contractNum) + public static string PushDataToHSE(string projectId, string contractNum,string costManageId) { try { string message = ""; // 鏌ヨ褰撳墠鍚堝悓鎵鏈夊鏍搁氳繃鐨勬暟鎹 var costData = from x in Funs.DB.CostGoods_CostManage - where x.ProjectId == projectId && x.ContractNum == contractNum && x.States == Const.State_2 - orderby x.CostManageDate descending - select x; - - if (costData.Any()) + where x.ProjectId == projectId && x.ContractNum == contractNum && x.States == Const.State_2 + orderby x.CostManageDate descending + select x; + var projectModel=ProjectService.GetProjectByProjectId(projectId); + var contractModel = CostManageService.GetCostManageById(costManageId); + decimal totalAmount = costData.Sum(x => x.SumMoney ?? 0); + var files = new List(); + if (contractModel!=null) { - // 鑾峰彇鎵鏈夐檮浠舵枃浠 - var files = new List(); - decimal totalAmount = 0; - - foreach (var item in costData) + var fileDetails = GetBase64FilesWithDetails(contractModel.CostManageId); + if (fileDetails != null && fileDetails.Count > 0) { - var fileDetails = GetBase64FilesWithDetails(item.CostManageId); - if (fileDetails != null && fileDetails.Count > 0) - { - files.AddRange(fileDetails); - totalAmount += item.SumMoney ?? 0; - } + files.AddRange(fileDetails); } // 鏋勫缓璇锋眰浣 - var requestBody = new + var requestBody = new { - projectId = projectId, + projectNumber = projectModel.ProjectCode, contractNo = contractNum, amountHSE = totalAmount.ToString(), files = files }; var jsonBody = JsonConvert.SerializeObject(requestBody); + // 璋冪敤HSE鎺ュ彛鎺ㄩ佹暟鎹 - // TODO: 瀹炵幇瀹為檯鐨凥SE鎺ュ彛璋冪敤閫昏緫 - var url="http://172.29.60.33:8080"; - var requestGetTokenUrl = url + "/api/Token/GetToken"; - string requestGetTokenBody = "{\r\n\r\n\"username\": \"coadmin\",\r\n\r\n\"password\": \"coadminPu@2025\"\r\n\r\n}"; + var url = "http://172.29.60.33:8080"; + var requestGetTokenUrl = url + "/auth/getToken"; + string requestGetTokenBody = "{\"username\": \"coadmin\",\"password\": \"coadminPu@2025\"}"; var response = Funs.RequestPost(requestGetTokenUrl, "", requestGetTokenBody); var responseStr = JsonConvert.DeserializeObject(response); - if (responseStr == null || responseStr["data"].ToString() != "200") + APICommonService.SaveSysHttpLog("PU_Token", requestGetTokenUrl, response); + + if (responseStr == null || responseStr["code"]?.ToString() != "200" || responseStr["data"] == null) { message = "鑾峰彇Pu绯荤粺Token澶辫触"; + return message; + } - } - string accessToken = responseStr["data"]["token"].ToString(); - var requestUrl = url + "/api/PuPayCraftAmount/AddPuPayCraftAmount"; - var responseHSE = Funs.RequestPost(requestUrl, accessToken, jsonBody); + string accessToken = responseStr["data"]["token"]?.ToString(); + if (string.IsNullOrEmpty(accessToken)) + { + message = "鑾峰彇Pu绯荤粺Token澶辫触锛孴oken涓虹┖"; + return message; + } + Dictionary headers = new Dictionary(); + headers.Add("Authorization", "Bearer " + accessToken); + var requestUrl = url + "/pu_api/payCraftAmountToHSE/add"; + APICommonService.SaveSysHttpLog("PU_AddPuPayCraftAmount", requestUrl, jsonBody, "Requset"); + var responseHSE = Funs.RequestPost(requestUrl, headers, jsonBody); var responseHSEStr = JsonConvert.DeserializeObject(responseHSE); - if (responseHSEStr == null || responseHSEStr["data"].ToString()!= "200") + APICommonService.SaveSysHttpLog("PU_AddPuPayCraftAmount", requestUrl, responseHSE, "Response"); + if (responseHSEStr == null) { message = "鎺ㄩ佹暟鎹埌HSE绯荤粺澶辫触"; + return message; + } + else if (responseHSEStr["code"]?.ToString() != "200") + { + message = responseHSEStr["message"]?.ToString(); + return message; + } + else + { + message = ""; + return message; } } - return message; + return message; } catch (Exception ex) { // 璁板綍閿欒鏃ュ織 ErrLogInfo.WriteLog(ex.Message, ex.StackTrace); - return "鎺ㄩ佹暟鎹け璐"+ex.Message; - + return "鎺ㄩ佹暟鎹け璐"; } } @@ -456,22 +472,35 @@ namespace BLL var attachments = AttachFileService.getFileUrl(costManageId); if (!string.IsNullOrEmpty(attachments)) - { - string filePath=Funs.RootPath+attachments.Split(',')[0]; - FileInfo file = new FileInfo(filePath); - byte[] fileBytes = File.ReadAllBytes(filePath); - string base64Content = Convert.ToBase64String(fileBytes); - - result.Add(new Model.PuPayCraftAmountFileInput + { + string[] filePaths = attachments.Split(','); + foreach (var filePath in filePaths) { - name = file.Name, - content = base64Content, - thisamount = costManage?.SumMoney?.ToString() ?? "0", - date = costManage?.CostManageDate?.ToString("yyyy-MM-dd") ?? DateTime.Now.ToString("yyyy-MM-dd") - }); + string fullPath = Funs.RootPath + filePath; + if (File.Exists(fullPath)) + { + FileInfo file = new FileInfo(fullPath); + byte[] fileBytes = File.ReadAllBytes(fullPath); + string base64Content = Convert.ToBase64String(fileBytes); + + result.Add(new Model.PuPayCraftAmountFileInput + { + name = file.Name, + content = base64Content, + thisamount = costManage?.SumMoney?.ToString() ?? "0", + date = costManage?.CostManageDate?.ToString("yyyy-MM-dd") ?? DateTime.Now.ToString("yyyy-MM-dd") + }); + } + else + { + /* message += $"闄勪欢鏂囦欢璺緞 {fullPath} 涓嶅瓨鍦紒"; + ErrLogInfo.WriteLog(message, $"File not found: {fullPath}");*/ + } + } } - + return result; } + } } diff --git a/SGGL/FineUIPro.Web/HSSE/CostGoods/CostManage.aspx.cs b/SGGL/FineUIPro.Web/HSSE/CostGoods/CostManage.aspx.cs index d2d9feea..2b427a92 100644 --- a/SGGL/FineUIPro.Web/HSSE/CostGoods/CostManage.aspx.cs +++ b/SGGL/FineUIPro.Web/HSSE/CostGoods/CostManage.aspx.cs @@ -348,7 +348,7 @@ namespace FineUIPro.Web.HSSE.CostGoods } else { - string messaage = CostManageService.PushDataToHSE(this.CurrUser.LoginProjectId, costManage.ContractNum); + string messaage = CostManageService.PushDataToHSE(this.CurrUser.LoginProjectId, costManage.ContractNum,costManageId); if (string.IsNullOrEmpty(messaage)) { Alert.ShowInTop("鎺ㄩ佹垚鍔燂紒", MessageBoxIcon.Success);