diff --git a/win-admin/src/main/java/com/win/web/controller/base/CommandController.java b/win-admin/src/main/java/com/win/web/controller/base/CommandController.java index f7a333f..25ff018 100644 --- a/win-admin/src/main/java/com/win/web/controller/base/CommandController.java +++ b/win-admin/src/main/java/com/win/web/controller/base/CommandController.java @@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.net.URLDecoder; import java.util.List; @RestController @@ -71,6 +72,15 @@ public class CommandController { if(/*!activeProfile.contains("dev") && */!StringUtils.equals(sign, computeSign.toUpperCase())) { return AjaxResult.error(HttpStatus.SIGN_ERROR, "签名不正确"); } + //url特殊字符要转换 + body = body.replace("+", "%2B"); + body = body.replace("/", "%2F"); + body = body.replace("?", "%3F"); + body = body.replace("#", "%23"); + body = body.replace("&", "%26"); + body = body.replace("=", "%3D"); + //处理kettle加密中文有问题 + body = URLDecoder.decode(body, "UTF-8"); JSONObject jsonObject = JSONObject.parseObject(body); String key = ""; for(String keyTemp : jsonObject.keySet()) { @@ -88,6 +98,7 @@ public class CommandController { QueryWrapper linuxAccessQueryWrapper = new QueryWrapper<>(); linuxAccessQueryWrapper.eq("company_code", companyCode); linuxAccessQueryWrapper.eq("uri", interfaceName); + linuxAccessQueryWrapper.isNull("delete_time"); LinuxAccess linuxAccess = linuxAccessService.getOne(linuxAccessQueryWrapper); if(linuxAccess == null) { return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在"); @@ -95,6 +106,7 @@ public class CommandController { QueryWrapper qadAccessQueryWrapper = new QueryWrapper<>(); qadAccessQueryWrapper.eq("company_code", companyCode); qadAccessQueryWrapper.eq("domain", domain); + qadAccessQueryWrapper.isNull("delete_time"); QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper); if(qadAccess == null) { return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR"); diff --git a/win-admin/src/main/java/com/win/web/controller/base/ExcelController.java b/win-admin/src/main/java/com/win/web/controller/base/ExcelController.java index 1c9623d..5615ee6 100644 --- a/win-admin/src/main/java/com/win/web/controller/base/ExcelController.java +++ b/win-admin/src/main/java/com/win/web/controller/base/ExcelController.java @@ -159,6 +159,15 @@ public class ExcelController { String schdLineDate = jsonObjectLine.getString("schd_line_date"); String schdLineDateDl = jsonObjectLine.getString("schd_line_date_dl"); String schdLineDateTh = jsonObjectLine.getString("schd_line_date_th"); + if(schdLineDate != null) { + schdLineDate = schdLineDate.replace("-", "/"); + } + if(schdLineDateDl != null) { + schdLineDateDl = schdLineDateDl.replace("-", "/"); + } + if(schdLineDateTh != null) { + schdLineDateTh = schdLineDateTh.replace("-", "/"); + } if (schdLineDate != null) { if ("F".equals(schdLineFcQual)) { JSONObject firm = firmMap.get(schdLineDate); @@ -247,7 +256,9 @@ public class ExcelController { if("changchun".equals(type)) {//长春模板 fileNames.add(fillChangchun(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); } else if("foshan".equals(type)) { - fileNames.add(fillFoshanQingdao(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); + fileNames.add(fillFoshan(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); + } else if("qingdao".equals(type)) { + fileNames.add(fillQingdao(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); } else if("guowai1".equals(type)) { fileNames.add(fillGuowai1(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); } else if("guowai2".equals(type)) { @@ -419,7 +430,177 @@ public class ExcelController { } /** - * 横财佛山青岛格式excel + * 横财佛山格式excel + * @param orderNo 订单号 + * @param jsonObjectHeader 头部信息 + * @param orderArray 订单数据 + * @param firmArray firm数据 + * @param forecastArray forecast数据 + * @return 生成文件的路径 + * @throws IOException io异常 + */ + private String fillFoshan(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException { + ClassPathResource templateFile = new ClassPathResource("foshan.xls"); + String filePath = WinConfig.getUploadPath(); + String fileName = orderNo + ".xls"; + File file = new File(filePath); + if (!file.exists()) { + file.mkdirs(); + } + file = new File(filePath + "/" + fileName); + if (file.exists()) { + file.delete(); + } + final ExcelWriter excelWriter = EasyExcelFactory.write(filePath + "/" + fileName).excelType(ExcelTypeEnum.XLS).withTemplate(templateFile.getInputStream()).build(); + try { + final WriteSheet writeSheet = EasyExcelFactory.writerSheet().build(); + //默认纵向添加数据 + FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); + //基础数据 + excelWriter.fill(jsonObjectHeader, writeSheet); + //order数据 + excelWriter.fill(new FillWrapper("order", orderArray), fillConfig, writeSheet); + } finally { + if (excelWriter != null) { + excelWriter.finish(); + } + } + FileInputStream inputStream = new FileInputStream(filePath + "/" + fileName); + Workbook workbook = new HSSFWorkbook(inputStream); + Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表 + CellStyle cellStyle1 = getCellStyle(sheet, 14, 8);//Firm订标题样式 + CellStyle cellStyle2 = getCellStyle(sheet, 14, 9);//Pick Up Date提货时间 + CellStyle cellStyle3 = getCellStyle(sheet, 14, 10);//forecast标题 + CellStyle cellStyle4 = getCellStyle(sheet, 15, 8);//Firm日期样式 + CellStyle cellStyle5 = getCellStyle(sheet, 15, 10);//Forecast日期样式 + CellStyle cellStyle6 = getCellStyle(sheet, 16, 8);//Firm数据样式 + CellStyle cellStyle7 = getCellStyle(sheet, 16, 10);//Forecast数据样式 + Row row14 = sheet.getRow(14); + Row row15 = sheet.getRow(15); + for (int i = 0; i < firmArray.size(); i++) { + int cellIndex = 8 + i; + JSONObject firm = firmArray.getJSONObject(i); + //设置firm标题 + Cell firmCell = row14.getCell(cellIndex); + if (firmCell == null) { + firmCell = row14.createCell(cellIndex); + } + firmCell.setCellValue("Firm订单"); + firmCell.setCellStyle(cellStyle1); + //设置firm日期 + Cell firmDateCell = row15.getCell(cellIndex); + if (firmDateCell == null) { + firmDateCell = row15.createCell(cellIndex); + } + firmDateCell.setCellValue(firm.getString("schd_line_date")); + firmDateCell.setCellStyle(cellStyle4); + //设置每个firm订单数据 + for (int count = 0; count < orderArray.size(); count++) { + int cellValue = 0; + JSONObject object = orderArray.getJSONObject(count); + JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); + Row nextRow = sheet.getRow(16 + count); + Cell nextCell = nextRow.getCell(cellIndex); + if (nextCell == null) { + nextCell = nextRow.createCell(cellIndex); + } + if (order != null) { + cellValue = order.getIntValue("schd_line_qty"); + } + if (cellValue != 0) { + nextCell.setCellValue(cellValue); + } else { + nextCell.setCellValue(""); + } + nextCell.setCellStyle(cellStyle6); + } + } + //设置firm前的Pick Up Date 提货日期列 + for (int count = 0; count < orderArray.size(); count++) { + Row beforeRow = sheet.getRow(16 + count); + Cell beforeCell = beforeRow.getCell(7); + if (beforeCell == null) { + beforeCell = beforeRow.createCell(7); + } + beforeCell.setCellValue(""); + beforeCell.setCellStyle(cellStyle1); + } + //设置forecast前的Pick Up Date 提货日期列 + for (int count = 0; count < orderArray.size() + 2; count++) { + int cellIndex = 8 + firmArray.size(); + Row nextRow = sheet.getRow(14 + count); + Cell nextCell = nextRow.getCell(cellIndex); + if (nextCell == null) { + nextCell = nextRow.createCell(cellIndex); + } + nextCell.setCellValue(""); + nextCell.setCellStyle(cellStyle2); + if (count == 0) { + nextCell.setCellValue("Pick Up Date 提货日期"); + nextCell.setCellStyle(cellStyle2); + } else if (count == 1) { + nextCell.setCellValue("ETA " + jsonObjectHeader.getString("schm_header_arrive_us") + "\n到达" + jsonObjectHeader.getString("schm_header_arrive_ch") + "时间"); + } else { + nextCell.setCellValue(""); + } + } + for (int i = 0; i < forecastArray.size(); i++) { + int cellIndex = 9 + firmArray.size() + i; + //设置forecast标题 + Cell forecastCell = row14.getCell(cellIndex); + if (forecastCell == null) { + forecastCell = row14.createCell(cellIndex); + } + if (i == 0) { + forecastCell.setCellValue("forecast 预测"); + } else { + forecastCell.setCellValue(""); + } + forecastCell.setCellStyle(cellStyle3); + //设置forecast日期 + JSONObject forecast = forecastArray.getJSONObject(i); + Cell forecastDateCell = row15.getCell(cellIndex); + if (forecastDateCell == null) { + forecastDateCell = row15.createCell(cellIndex); + } + forecastDateCell.setCellValue(forecast.getString("schd_line_date")); + forecastDateCell.setCellStyle(cellStyle5); + //设置forecast每个订单数据 + for (int count = 0; count < orderArray.size(); count++) { + int cellValue = 0; + JSONObject object = orderArray.getJSONObject(count); + JSONObject order = forecast.getJSONObject(object.getString("schd_line_line")); + Row nextRow = sheet.getRow(16 + count); + if (order != null) { + cellValue = order.getIntValue("schd_line_qty"); + } + Cell nextCell = nextRow.getCell(cellIndex); + if (nextCell == null) { + nextCell = nextRow.createCell(cellIndex); + } + if (cellValue != 0) { + nextCell.setCellValue(cellValue); + } else { + nextCell.setCellValue(""); + } + nextCell.setCellStyle(cellStyle7); + } + } + if (!forecastArray.isEmpty() && forecastArray.size() > 1) { + // 合并单元格 + CellRangeAddress cellRangeAddress3 = new CellRangeAddress(14, 14, firmArray.size() + 9, firmArray.size() + forecastArray.size() + 8); + sheet.addMergedRegion(cellRangeAddress3); + } + inputStream.close(); + FileOutputStream outputStream = new FileOutputStream(filePath + "/" + fileName); + workbook.write(outputStream); + workbook.close(); + outputStream.close(); + return fileName; + } + + /** + * 横财青岛格式excel * @param orderNo 订单号 * @param jsonObjectHeader 头部信息 * @param orderArray 订单数据 @@ -428,8 +609,8 @@ public class ExcelController { * @return 生成文件的路径 * @throws IOException io异常 */ - private String fillFoshanQingdao(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException { - ClassPathResource templateFile = new ClassPathResource("foshan_qingdao.xls"); + private String fillQingdao(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException { + ClassPathResource templateFile = new ClassPathResource("qingdao.xls"); String filePath = WinConfig.getUploadPath(); String fileName = orderNo + ".xls"; File file = new File(filePath); diff --git a/win-admin/src/main/java/com/win/web/controller/base/ShellController.java b/win-admin/src/main/java/com/win/web/controller/base/ShellController.java index b2ea2bd..6cd26b3 100644 --- a/win-admin/src/main/java/com/win/web/controller/base/ShellController.java +++ b/win-admin/src/main/java/com/win/web/controller/base/ShellController.java @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.net.URLDecoder; import java.util.List; @RestController @@ -60,18 +61,27 @@ public class ShellController { return AjaxResult.error(HttpStatus.TIMESTAMP_ERROR, "时间戳不正确"); } String tmp = interfaceName + body + "Wenyin@2024" + timestamp; - String computeSign = DigestUtils.md5DigestAsHex(tmp.getBytes()).toUpperCase(); + String computeSign = DigestUtils.md5DigestAsHex(tmp.getBytes()); long tenTimestamp = timestamp + (10 * 60 * 1000); // 计算10分钟后的时间戳 long currentTimestamp = System.currentTimeMillis(); // 获取当前时间戳 //过期 - if(timestamp > currentTimestamp || tenTimestamp < currentTimestamp) { + if(tenTimestamp < currentTimestamp) { return AjaxResult.error(HttpStatus.EXPIRE_ERROR, "请求已过期"); } List activeProfile = ProfileUtil.getActiveProfile(); //dev环境不校验签名 - if(/*!activeProfile.contains("dev") && */!StringUtils.equals(sign, computeSign)) { + if(/*!activeProfile.contains("dev") && */!StringUtils.equals(sign, computeSign.toUpperCase())) { return AjaxResult.error(HttpStatus.SIGN_ERROR, "签名不正确"); } + //url特殊字符要转换 + body = body.replace("+", "%2B"); + body = body.replace("/", "%2F"); + body = body.replace("?", "%3F"); + body = body.replace("#", "%23"); + body = body.replace("&", "%26"); + body = body.replace("=", "%3D"); + //处理kettle加密中文有问题 + body = URLDecoder.decode(body, "UTF-8"); JSONObject jsonObject = JSONObject.parseObject(body); String key = ""; for(String keyTemp : jsonObject.keySet()) { @@ -89,6 +99,7 @@ public class ShellController { QueryWrapper linuxAccessQueryWrapper = new QueryWrapper<>(); linuxAccessQueryWrapper.eq("company_code", companyCode); linuxAccessQueryWrapper.eq("uri", interfaceName); + linuxAccessQueryWrapper.isNull("delete_time"); LinuxAccess linuxAccess = linuxAccessService.getOne(linuxAccessQueryWrapper); if(linuxAccess == null) { return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在"); @@ -96,6 +107,7 @@ public class ShellController { QueryWrapper qadAccessQueryWrapper = new QueryWrapper<>(); qadAccessQueryWrapper.eq("company_code", companyCode); qadAccessQueryWrapper.eq("domain", domain); + qadAccessQueryWrapper.isNull("delete_time"); QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper); if(qadAccess == null) { return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR"); diff --git a/win-admin/src/main/resources/application-dev.yml b/win-admin/src/main/resources/application-dev.yml index 9d68e32..831092b 100644 --- a/win-admin/src/main/resources/application-dev.yml +++ b/win-admin/src/main/resources/application-dev.yml @@ -148,3 +148,5 @@ swagger: enabled: true # 请求前缀 pathMapping: / +faway-url: + dashboardtb: http://36.97.178.71:20202/services/infoapi?wsdl diff --git a/win-admin/src/main/resources/application-prod.yml b/win-admin/src/main/resources/application-prod.yml index 94dcb9c..04cd4b8 100644 --- a/win-admin/src/main/resources/application-prod.yml +++ b/win-admin/src/main/resources/application-prod.yml @@ -148,3 +148,5 @@ swagger: enabled: false # 请求前缀 pathMapping: / +faway-url: + dashboardtb: http://36.97.178.71:20202/services/infoapi?wsdl \ No newline at end of file diff --git a/win-admin/src/main/resources/application-test.yml b/win-admin/src/main/resources/application-test.yml index 94dcb9c..04cd4b8 100644 --- a/win-admin/src/main/resources/application-test.yml +++ b/win-admin/src/main/resources/application-test.yml @@ -148,3 +148,5 @@ swagger: enabled: false # 请求前缀 pathMapping: / +faway-url: + dashboardtb: http://36.97.178.71:20202/services/infoapi?wsdl \ No newline at end of file diff --git a/win-admin/src/main/resources/changchun.xls b/win-admin/src/main/resources/changchun.xls index f0125cc..97ca89e 100644 Binary files a/win-admin/src/main/resources/changchun.xls and b/win-admin/src/main/resources/changchun.xls differ diff --git a/win-admin/src/main/resources/changchun.xlsx b/win-admin/src/main/resources/changchun.xlsx index c7d90be..9eb859b 100644 Binary files a/win-admin/src/main/resources/changchun.xlsx and b/win-admin/src/main/resources/changchun.xlsx differ diff --git a/win-admin/src/main/resources/foshan.xls b/win-admin/src/main/resources/foshan.xls new file mode 100644 index 0000000..eb51f95 Binary files /dev/null and b/win-admin/src/main/resources/foshan.xls differ diff --git a/win-admin/src/main/resources/foshan_qingdao.xlsx b/win-admin/src/main/resources/foshan_qingdao.xlsx index cd77e74..c7cbffe 100644 Binary files a/win-admin/src/main/resources/foshan_qingdao.xlsx and b/win-admin/src/main/resources/foshan_qingdao.xlsx differ diff --git a/win-admin/src/main/resources/guowai1.xls b/win-admin/src/main/resources/guowai1.xls index ba5f0a0..6fa33ed 100644 Binary files a/win-admin/src/main/resources/guowai1.xls and b/win-admin/src/main/resources/guowai1.xls differ diff --git a/win-admin/src/main/resources/guowai1.xlsx b/win-admin/src/main/resources/guowai1.xlsx index fe257db..f6eedf8 100644 Binary files a/win-admin/src/main/resources/guowai1.xlsx and b/win-admin/src/main/resources/guowai1.xlsx differ diff --git a/win-admin/src/main/resources/guowai2.xls b/win-admin/src/main/resources/guowai2.xls index fffda30..176feef 100644 Binary files a/win-admin/src/main/resources/guowai2.xls and b/win-admin/src/main/resources/guowai2.xls differ diff --git a/win-admin/src/main/resources/guowai2.xlsx b/win-admin/src/main/resources/guowai2.xlsx index aa15402..99c6739 100644 Binary files a/win-admin/src/main/resources/guowai2.xlsx and b/win-admin/src/main/resources/guowai2.xlsx differ diff --git a/win-admin/src/main/resources/logback-spring.xml b/win-admin/src/main/resources/logback-spring.xml index 1168b5c..8d6b5c5 100644 --- a/win-admin/src/main/resources/logback-spring.xml +++ b/win-admin/src/main/resources/logback-spring.xml @@ -35,7 +35,7 @@ ${log.path}/sys-debug.%d{yyyy-MM-dd}.log - 7 + 1 ${log.pattern} @@ -58,7 +58,7 @@ ${log.path}/sys-info.%d{yyyy-MM-dd}.log - 7 + 1 ${log.pattern} @@ -81,7 +81,7 @@ ${log.path}/sys-warn.%d{yyyy-MM-dd}.log - 7 + 1 ${log.pattern} @@ -102,8 +102,8 @@ ${log.path}/sys-error.%d{yyyy-MM-dd}.log - - 7 + + 1 ${log.pattern} @@ -130,7 +130,7 @@ - + diff --git a/win-admin/src/main/resources/foshan_qingdao.xls b/win-admin/src/main/resources/qingdao.xls similarity index 93% rename from win-admin/src/main/resources/foshan_qingdao.xls rename to win-admin/src/main/resources/qingdao.xls index ffa932a..8ff6bd9 100644 Binary files a/win-admin/src/main/resources/foshan_qingdao.xls and b/win-admin/src/main/resources/qingdao.xls differ diff --git a/win-quartz/pom.xml b/win-quartz/pom.xml index 82ed246..a8e9030 100644 --- a/win-quartz/pom.xml +++ b/win-quartz/pom.xml @@ -34,6 +34,10 @@ com.win win-common + + com.win + win-system + diff --git a/win-quartz/src/main/java/com/win/quartz/task/WinTask.java b/win-quartz/src/main/java/com/win/quartz/task/WinTask.java index f9a2fc9..94197ed 100644 --- a/win-quartz/src/main/java/com/win/quartz/task/WinTask.java +++ b/win-quartz/src/main/java/com/win/quartz/task/WinTask.java @@ -1,10 +1,28 @@ package com.win.quartz.task; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.win.common.core.domain.AjaxResult; +import com.win.common.utils.uuid.UUID; +import com.win.quartz.util.JsonToXmlConverter; +import com.win.system.domain.LinuxAccess; +import com.win.system.domain.QadAccess; +import com.win.system.service.LinuxAccessService; +import com.win.system.service.QadAccessService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +import java.io.IOException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + /** * 定时任务调度 * @@ -14,43 +32,71 @@ import org.springframework.web.client.RestTemplate; @Component("winTask") public class WinTask { + @Autowired + private LinuxAccessService linuxAccessService; + @Autowired + private QadAccessService qadAccessService; @Autowired private RestTemplate restTemplate; + @Value("${faway-url.dashboardtb:}") + private String dashboardtb; - public void haveParams(String params) { -// // 创建一个请求头对象 -// HttpHeaders headers = new HttpHeaders(); -// // 设置请求头对象contentTyp的为text/xml;charset=UTF-8 -// MediaType type = MediaType.parseMediaType("text/xml;charset=UTF-8"); -// headers.setContentType(type); -// -// // 将请求参数进行封装并进行远程接口服务调用 -// // 构造webservice请求参数 -// // 请求参数,根据实际情况进行配置,以下仅作为示例 -// StringBuilder requestData = new StringBuilder(); -// requestData.append(""); -// requestData.append(""); -// requestData.append(""); -// requestData.append(""); -// -// // 请求参数,根据实际情况进行配置,以下仅作为示例 -// requestData.append("").append("zhangsan").append(""); -// requestData.append("").append("123456").append(""); -// -// requestData.append(""); -// requestData.append(""); -// -// log.info("请求报文为:" + requestData.toString()); -// log.info("url:" + url); -// try { -// // 创建请求 -// HttpEntity request = new HttpEntity<>(requestData.toString(), headers); -// // 发送post请求并获取到响应结果 -// String str = restTemplate.postForObject(url, request, String.class); -// log.info("-----------Response content-----------: " + str); -// } catch (Exception e) { -// log.error("baseWebServiceRequest出现异常:" + e.getMessage(), e); -// } + //总账科目信息 + public void fawaydashboardtb() throws IOException { + String companyCode = "HFLTESTDVL"; + String interfaceName = "fawaydashboardtb"; + String domain = "HFLCC"; + QueryWrapper linuxAccessQueryWrapper = new QueryWrapper<>(); + linuxAccessQueryWrapper.eq("company_code",companyCode); + linuxAccessQueryWrapper.eq("uri", interfaceName); + LinuxAccess linuxAccess = linuxAccessService.getOne(linuxAccessQueryWrapper); + if(linuxAccess == null) { + throw new RuntimeException("linux访问控制不存在"); + } + QueryWrapper qadAccessQueryWrapper = new QueryWrapper<>(); + qadAccessQueryWrapper.eq("company_code",companyCode); + qadAccessQueryWrapper.eq("domain",domain); + QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper); + if(qadAccess == null) { + throw new RuntimeException("QAD访问控制不存在"); + } + // 获取今天的日期 + LocalDate today = LocalDate.now(); + // 获取上个月的日期 + LocalDate lastMonth = today.minusMonths(1); + // 格式化输出 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + String formattedMonth = lastMonth.format(formatter); + JSONArray jsonArray = new JSONArray(); + JSONObject ttSearchCondition = new JSONObject(); + ttSearchCondition.put("report_type", "tb"); + ttSearchCondition.put("report_period", formattedMonth); + jsonArray.add(ttSearchCondition); + JSONObject dsSearchCondition = new JSONObject(); + dsSearchCondition.put("dsSearchCondition", jsonArray); + String json = dsSearchCondition.toString(); + UUID traceid = UUID.randomUUID(); + AjaxResult ajaxResult = linuxAccessService.executeCommand(linuxAccess, qadAccess, traceid.toString(), json, domain); + JSONObject jsonObject = JSONObject.parseObject(ajaxResult.get("msg").toString()); + jsonObject = JSONObject.parseObject(jsonObject.getString("dsTB")); + JSONArray dataJsonArray = JSONArray.parse(jsonObject.getString("TB")); + String xml = JsonToXmlConverter.jsonToXml(dataJsonArray); + // 创建一个请求头对象 + HttpHeaders headers = new HttpHeaders(); + // 设置请求头对象contentTyp的为text/xml;charset=UTF-8 + MediaType type = MediaType.parseMediaType("text/xml;charset=UTF-8"); + headers.setContentType(type); + log.info("请求报文为:" + xml); + log.info("url:" + this.dashboardtb); + try { + // 创建请求 + HttpEntity request = new HttpEntity<>(xml, headers); + // 发送post请求并获取到响应结果 + String str = restTemplate.postForObject(this.dashboardtb, request, String.class); + log.info("-----------Response content-----------: " + str); + } catch (Exception e) { + log.error("baseWebServiceRequest出现异常:" + e.getMessage(), e); + } } } diff --git a/win-quartz/src/main/java/com/win/quartz/util/JsonToXmlConverter.java b/win-quartz/src/main/java/com/win/quartz/util/JsonToXmlConverter.java new file mode 100644 index 0000000..4e119bc --- /dev/null +++ b/win-quartz/src/main/java/com/win/quartz/util/JsonToXmlConverter.java @@ -0,0 +1,61 @@ +package com.win.quartz.util; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; + +public class JsonToXmlConverter { + + public static String jsonToXml(String jsonStr) { + JSONObject jsonObject = JSON.parseObject(jsonStr); + return jsonToXml(jsonObject, "root"); + } + + public static String jsonToXml(Object jsonObject) { + return jsonToXml(jsonObject, "root"); + } + + private static String jsonToXml(Object jsonObj, String tagName) { + StringBuilder xml = new StringBuilder(); + if (jsonObj instanceof JSONObject) { + xml.append("<" + tagName + ">"); + JSONObject jsonObject = (JSONObject) jsonObj; + for (String key : jsonObject.keySet()) { + Object value = jsonObject.get(key); + if (value instanceof JSONObject) { + xml.append(jsonToXml(value, key)); + } else if (value instanceof JSONArray) { + xml.append(arrayToXml(key, (JSONArray) value)); + } else { + xml.append("<" + key + ">" + value + ""); + } + } + xml.append(""); + } else if (jsonObj instanceof JSONArray) { + xml.append(arrayToXml(tagName, (JSONArray) jsonObj)); + } else { + xml.append("<" + tagName + ">" + jsonObj.toString() + ""); + } + return xml.toString(); + } + + private static String arrayToXml(String tagName, JSONArray jsonArray) { + StringBuilder xml = new StringBuilder(); + for (int i = 0; i < jsonArray.size(); i++) { + Object jsonObj = jsonArray.get(i); + if (jsonObj instanceof JSONObject) { + xml.append(jsonToXml(jsonObj, tagName)); + } else { + xml.append("<" + tagName + ">" + jsonObj.toString() + ""); + } + } + return xml.toString(); + } + + public static void main(String[] args) { + String jsonStr = "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}"; + String xmlStr = jsonToXml(jsonStr); + System.out.println(xmlStr); + } + +}