From 3ac5b86d184f76c52c893c9ba0cbaa76c3ab7a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Fri, 24 Mar 2023 17:45:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nl/acs/common/WebServiceUtil.java | 45 ++++++++----------- .../wms/service/impl/AcsToWmsServiceImpl.java | 11 ++--- .../wms/service/impl/WmsToAcsServiceImpl.java | 26 +++++------ .../org/nl/acs/test/rest/TestController.java | 8 +++- .../org/nl/acs/test/service/TestService.java | 2 +- .../test/service/impl/TestServiceImpl.java | 7 ++- 6 files changed, 46 insertions(+), 53 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/common/WebServiceUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/common/WebServiceUtil.java index 23fbc9d..2f933de 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/common/WebServiceUtil.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/common/WebServiceUtil.java @@ -1,5 +1,6 @@ package org.nl.acs.common; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; @@ -9,6 +10,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -27,7 +29,7 @@ public class WebServiceUtil { * @return 第三方系统返回的JSONObject调用结果 * @throws Exception 工具类一般不处理具体异常,抛出由调用方处理,否则容易形成黑箱 */ - public static String process(String url, String method, HashMap form) throws Exception { + public static String process(String url, String method, JSONObject form) throws Exception { //构建返回值 JSONObject result = new JSONObject(); //第一步:创建服务地址 @@ -69,7 +71,7 @@ public class WebServiceUtil { //获取当前连接请求返回的数据流 InputStream is = connection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is, "utf-8"); + InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(isr); @@ -88,9 +90,9 @@ public class WebServiceUtil { ret = ret.replaceAll("\\<\\?.+\\?\\>", ""); else ret = (new StringBuilder("")).append(ret).toString(); - + /* String now = xml2jsonString(ret); - System.out.println("打印返回结果转成jsonString-------------"); + System.out.println("打印返回结果转成jsonString-------------"); result =JSONObject.parseObject(now);*/ is.close(); isr.close(); @@ -110,28 +112,17 @@ public class WebServiceUtil { * @param form 查询条件 * @return */ - private static String getXML(Map form, String method) { - StringBuffer sb = new StringBuffer(); - sb.append(" "); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - if (method.contains("ZSd0002SendMatMd")) - sb.append(""); - // 设置请求参数 - for (Iterator it = form.keySet().iterator(); it.hasNext(); ) { - String key = it.next(); - String value = form.get(key); - sb.append(" <" + key + ">" + value + ""); - } - if (method.contains("ZSd0002SendMatMd")) - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - log.info("getXML组织参数为-----------------" + sb.toString()); - return sb.toString(); - + private static String getXML(JSONObject form, String method) { + return " " + + "" + + "" + + "" + + "" + + form.toJSONString() + + "" + + "" + + "" + + ""; } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index be580fb..cae15d2 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -21,6 +21,7 @@ import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.acs.wsdl.org.tempuri.IRTMSAGVSERVICE; +import org.nl.acs.wsdl.org.tempuri.RTMSAGVSERVICE; import org.nl.modules.system.service.ParamService; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; @@ -538,14 +539,8 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { MDC.put(log_file_type, log_type); // log.info("shipDeviceUpdate-----输入参数{}", param); if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); - AddressDto addressDto = addressService.findByCode("taskExecution"); - String methods_url = addressDto.getMethods_url(); - String url = wmsUrl + methods_url; - return HttpRequest - .post(url) - .body(param.toString()) - .execute(); + String s = new RTMSAGVSERVICE().getBasicHttpBindingIRTMSAGVSERVICE().atrAgvCallback(param.toJSONString()); + log.info(s); } } catch (Throwable ignored) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index e6ae005..de7039b 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -465,7 +465,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { for (int i = 0; i < datas.size(); i++) { String data = datas.get(i).toString(); CreateTaskRequest request = JsonUtl.format(data, CreateTaskRequest.class); - String ext_task_id = request.getREQCODE(); +// String ext_task_id = request.getREQCODE(); String task_code = request.getTASKCODE(); String start_device_code = request.getSTARTPOSITION(); // String start_device_code2 = request.getStart_device_code2(); @@ -493,21 +493,21 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { String next_point_code2 = ""; String put_point_code = ""; if (StrUtil.isEmpty(task_code)) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG("任务号不能为空!"); return response; } if (StrUtil.isEmpty(start_device_code)) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG("起点不能为空!"); return response; } if (StrUtil.isEmpty(next_device_code)) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG("终点不能为空!"); @@ -584,7 +584,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { // } TaskDto taskDto = taskService.findByCodeFromCache(task_code); if (taskDto != null) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG("不能存在相同的任务号!"); @@ -593,7 +593,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (!StrUtil.isEmpty(vehicle_code)) { TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); if (vehicle_dto != null) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG("不能存在相同的料车号!"); @@ -602,14 +602,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } if (StrUtil.isEmpty(start_point_code)) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG(start_device_code + "未找到对应点位!"); return response; } if (StrUtil.isEmpty(next_point_code)) { - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG(next_device_code + "未找到对应点位!"); @@ -618,7 +618,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONObject jo = new JSONObject(); jo.put("task_code", task_code); - jo.put("task_id", ext_task_id); + jo.put("task_id", task_code); jo.put("start_point_code", start_point_code); jo.put("next_point_code", next_point_code); jo.put("start_point_code2", start_point_code2); @@ -641,8 +641,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("params", params); jo.put("task_type", task_type); - if (!StrUtil.isEmpty(ext_task_id)) { - jo.put("ext_task_id", ext_task_id); + if (!StrUtil.isEmpty(task_code)) { + jo.put("ext_task_id", task_code); } TaskDto task_dto = jo.toJavaObject(TaskDto.class); @@ -675,7 +675,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } else { JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); +// json.put("ext_task_id", ext_task_id); json.put("message", resp.getComment()); json.put("code", resp.code); json.put("data", data); @@ -688,7 +688,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } } catch (Exception e) { // e.printStackTrace(); - response.setREQCODE(ext_task_id); + response.setREQCODE(task_code); response.setREPLYTIME(DateUtil.now()); response.setREQCODE("1"); response.setRTMSG(e.getMessage()); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java b/acs/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java index 50d710c..2213e91 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java @@ -2,12 +2,14 @@ package org.nl.acs.test.rest; +import cn.dev33.satoken.annotation.SaIgnore; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.test.service.TestService; import org.nl.modules.logging.annotation.Log; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -34,10 +36,12 @@ public class TestController { @Log("test1") @ApiOperation("test1") @PostMapping("/test1") + @SaIgnore //@PreAuthorize("@el.check('task:add')") public ResponseEntity test1() throws IOException { - testService.test1(); - return new ResponseEntity<>(HttpStatus.CREATED); + HttpHeaders headers = new HttpHeaders(); + headers.add(HttpHeaders.CONTENT_TYPE,"text/plain;charset=UTF-8"); + return new ResponseEntity<>(testService.test1(), headers, HttpStatus.CREATED); } @Log("test2") diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java b/acs/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java index ef80fe4..906d3cc 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java @@ -19,7 +19,7 @@ public interface TestService { * * @throws IOException */ - void test1() throws IOException; + String test1() throws IOException; /** * 触发打印 diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java index 5d1ff4f..bf719e1 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java @@ -6,9 +6,11 @@ import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.test.service.TestService; +import org.nl.acs.wsdl.org.tempuri.RTMSAGVSERVICE; import org.springframework.stereotype.Service; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Map; /** @@ -23,8 +25,9 @@ public class TestServiceImpl implements TestService { @Override - public void test1() throws IOException { - + public String test1() { + String s = new RTMSAGVSERVICE().getBasicHttpBindingIRTMSAGVSERVICE().atrAgvCallback("{}"); + return new String(s.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); } @Override