From 7265f705d2d24b8040d0cc9b35350ac8f0aec440 Mon Sep 17 00:00:00 2001 From: wangh <123456> Date: Wed, 16 Feb 2022 16:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E7=BA=BF=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 28 +++-- .../ChinaPostWebServiceApplication.java | 9 +- .../com/example/csb/UploadCSBController.java | 25 ++++- .../java/com/example/services/IService.java | 7 +- .../example/services/impl/ServiceImpl.java | 31 ++++-- .../services/impl/WebSocketServerContent.java | 16 ++- src/main/java/com/example/test/IndexConn.java | 18 +++ src/main/resources/application.yml | 4 + src/main/resources/logback.xml | 103 ++++++++++++++++++ src/main/resources/templates/test.html | 10 ++ 10 files changed, 224 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/example/test/IndexConn.java create mode 100644 src/main/resources/logback.xml create mode 100644 src/main/resources/templates/test.html diff --git a/pom.xml b/pom.xml index befd0d6..12776b2 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 0.0.1-SNAPSHOT ChinaPostWebService ChinaPostWebService - jar + war 1.8 @@ -26,17 +26,25 @@ 3.4.2 + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-starter-thymeleaf + - - - - - - - - - + + + + + + + com.alibaba.csb.sdk http-client diff --git a/src/main/java/com/example/ChinaPostWebServiceApplication.java b/src/main/java/com/example/ChinaPostWebServiceApplication.java index 6ccdcdb..fb33fd5 100644 --- a/src/main/java/com/example/ChinaPostWebServiceApplication.java +++ b/src/main/java/com/example/ChinaPostWebServiceApplication.java @@ -3,9 +3,16 @@ package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication -public class ChinaPostWebServiceApplication { +public class ChinaPostWebServiceApplication extends SpringBootServletInitializer { + // private static Logger logger=Logger.getLogger(PbdStoreWebApplication.class); + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){ + return builder.sources(ChinaPostWebServiceApplication.class); + } public static void main(String[] args) { SpringApplication.run(ChinaPostWebServiceApplication.class, args); diff --git a/src/main/java/com/example/csb/UploadCSBController.java b/src/main/java/com/example/csb/UploadCSBController.java index 3cb9119..f99ee36 100644 --- a/src/main/java/com/example/csb/UploadCSBController.java +++ b/src/main/java/com/example/csb/UploadCSBController.java @@ -25,11 +25,26 @@ public class UploadCSBController { private String pramOut = "containerRegisterQuery"; private String pram; // csb处理 - String requestURL = "http://211.156.197.239:8086/ceshi_csb_broker";//ceshiyun +// String requestURL = "http://211.156.197.239:8086/ceshi_csb_broker";//ceshiyun +// String API_NAME; // CSB发布服务定义的服务名 +// String version = "1.0.0"; +// String ak = "dd979a77b2a44e54b65f01dcbc0bae04"; +// String sk = "kCZfusS4Zn300MTnYtIlWzhdoE8="; + /** + * 发布版 + * syscode:ahzdcz + * ak:69c172fe5d9a4918afb44ad17bcc6406 + * sk:rhny272SwGKwTc3T9RPcxxeCyKc= + * password:Aksh217fdm + * url:http://10.4.191.246:8086/csb_jidi1_1 + */ + String sysCode="ahzdcz"; + String requestURL = "http://10.4.191.246:8086/csb_jidi1_1"; String API_NAME; // CSB发布服务定义的服务名 String version = "1.0.0"; - String ak = "dd979a77b2a44e54b65f01dcbc0bae04"; - String sk = "kCZfusS4Zn300MTnYtIlWzhdoE8="; + String ak = "69c172fe5d9a4918afb44ad17bcc6406"; + String sk = "rhny272SwGKwTc3T9RPcxxeCyKc="; + String password="Aksh217fdm"; @PostMapping("/api/uploadCsb") private String uploadCSBByAndroidInfo(int code, String containerRegisterQuery) { @@ -46,11 +61,11 @@ public class UploadCSBController { // " \"rqtm\": \"1002001300000023\"\n" + // "}"; RequestMessageHeader msg = new RequestMessageHeader(); - msg.setSysCode("aa");// aa + msg.setSysCode(sysCode);// aa msg.setSerialNo(UUID.randomUUID().toString()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); msg.setSendDate(sdf.format(new Date())); - msg.setSign(getSign("CSHIPING12", containerRegisterQuery)); + msg.setSign(getSign(password, containerRegisterQuery)); String msgs = JSONObject.toJSONString(msg); // 转换为JSON String Map params = new HashMap(); params.put("messageHeader", msgs); diff --git a/src/main/java/com/example/services/IService.java b/src/main/java/com/example/services/IService.java index 12fecdb..d131e16 100644 --- a/src/main/java/com/example/services/IService.java +++ b/src/main/java/com/example/services/IService.java @@ -11,10 +11,13 @@ import javax.jws.WebService; */ @WebService(targetNamespace = "http://service.example.com/", name = "authorPortType") public interface IService { + /** * 入库开始读 - * - * @param containerRegisterQuery + * @param containerRegisterQuery 封装json + * @param pdaip 设备ID + * @param functionID 函数ID + * @return */ @WebMethod R getScanInfoInCenterStart( diff --git a/src/main/java/com/example/services/impl/ServiceImpl.java b/src/main/java/com/example/services/impl/ServiceImpl.java index 49ea694..06f9220 100644 --- a/src/main/java/com/example/services/impl/ServiceImpl.java +++ b/src/main/java/com/example/services/impl/ServiceImpl.java @@ -7,6 +7,8 @@ import com.example.api.R; import com.example.entity.ContainerRegisterQuery; import com.example.entity.OutCenter; import com.example.services.IService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.jws.WebParam; import javax.jws.WebService; @@ -29,6 +31,8 @@ import static com.example.services.impl.WebSocketServerContent.getRecMessage; endpointInterface = "com.example.services.IService")//指定发布webservcie的接口类,此类也需要接入@WebService注解 public class ServiceImpl implements IService { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final Logger log = LoggerFactory.getLogger(ServiceImpl.class); + public static String rfid; private static boolean m_GetInCenterStartSuccessful; private static boolean m_GetInCenterStopSuccessful; @@ -83,27 +87,32 @@ public class ServiceImpl implements IService { containerRegisterQuery1.setPdaip(pdaip); containerRegisterQuery1.setCommandCode(functionID); String json = JSONObject.toJSONString(containerRegisterQuery1); + log.error("\n"+sdf.format(new Date())+"调用开始读参数为:" + "\npdaID=" + pdaip + + "\nfunctionID=" + functionID + "\ncontainerRegisterQuery=" + containerRegisterQuery ); // if(StartFlag){ // return R.data(100, "向客户端发送消息失败,请先发送结束入库读指令在进行其他操作!"); // } if (WebSocketServerContent.getSocket(pdaip, json)) { // StartFlag = true; try { - Thread.sleep(1000); + Thread.sleep(3000); if (m_GetInCenterStartSuccessful) { m_GetInCenterStartSuccessful = false; - System.out.println("\n开始读返回:成功" + "\t开始请求时间" + sdf.format(new Date())); + System.out.println("\n开始读返回:成功" + "\t开始请求时间" + sdf.format(new Date()) ); + log.error("\n开始读返回:200成功" + "\t开始请求时间" + sdf.format(new Date()) ); return R.data(200, "向客户端发送消息成功!"); } else { System.out.println("\n开始读返回:消息超时!"); + log.error("\n开始读返回:201消息超时!"); return R.data(201, "向客户端发送消息成功,接收客户端消息超时!"); } } catch (Exception ex) { - + log.error("\n开始读返回:100向客户端发送消息失败!"); return R.data(100, "向客户端发送消息失败!"); } } else { - System.out.println("\n开始读返回:失败!" + "\t返回时间" + sdf.format(new Date())); + log.error("\n开始读返回:101失败!" + "\t返回时间" + sdf.format(new Date())); + System.out.println("\n开始读返回:失败!" + "\t返回时间" + sdf.format(new Date()) ); return R.data(101, "向客户端发送消息失败!"); } @@ -115,7 +124,9 @@ public class ServiceImpl implements IService { public R getScanInfoInCenterStop(String containerRegisterQuery, String pdaip, int functionID) { - System.out.println("\n调用结束读参数为:" + "\npdaID=" + pdaip + "\nfunctionID=" + functionID + "\ncontainerRegisterQuery=" + containerRegisterQuery); + log.error("\n"+sdf.format(new Date()) +"调用结束读参数为:" + "\tpdaID=" + pdaip + + "\tfunctionID=" + functionID + "\ncontainerRegisterQuery=" + containerRegisterQuery); + System.out.println("\n调用结束读参数为:" + "\tpdaID=" + pdaip + "\tfunctionID=" + functionID + "\ncontainerRegisterQuery=" + containerRegisterQuery); ContainerRegisterQuery containerRegisterQuery2 = new ContainerRegisterQuery(); containerRegisterQuery2.setContainerRegisterQuery(containerRegisterQuery); containerRegisterQuery2.setPdaip(pdaip); @@ -123,28 +134,32 @@ public class ServiceImpl implements IService { String json = JSONObject.toJSONString(containerRegisterQuery2); if (WebSocketServerContent.getSocket(pdaip, json)) { try { - +// if (m_GetInCenterStopSuccessful) { m_GetInCenterStopSuccessful = false; System.out.println("\n结束读返回:成功,返回数据=" + rfid); if (functionID==106){ - Thread.sleep(500); + Thread.sleep(3000); + log.error("\n"+"请求时间" + sdf.format(new Date())+"\t结束读返回:成功,返回数据=" + rfid ); return R.data(200, "向客户端发送消息成功!", rfid); - }else { // StartFlag = false; + log.error("\n结束读返回:成功" + "\t开始请求时间" + sdf.format(new Date())); return R.data(200, "向客户端发送消息成功!"); } } else { System.out.println("\n结束读返回:消息超时!"); + log.error("\n结束读返回:消息超时!"); return R.data(201, "向客户端发送消息成功,接收客户端消息超时!"); } } catch (Exception ex) { + log.error("\n结束读返回:100失败!" + "\t返回时间" + sdf.format(new Date())); return R.data(100, "向客户端发送消息失败!"); } } else { System.out.println("\n结束读返回:失败!"); + log.error("\n结束读返回:101失败!" + "\t返回时间" + sdf.format(new Date())); return R.data(101, "向客户端发送消息失败!"); } } diff --git a/src/main/java/com/example/services/impl/WebSocketServerContent.java b/src/main/java/com/example/services/impl/WebSocketServerContent.java index 07d3d33..0dc049e 100644 --- a/src/main/java/com/example/services/impl/WebSocketServerContent.java +++ b/src/main/java/com/example/services/impl/WebSocketServerContent.java @@ -4,6 +4,8 @@ package com.example.services.impl; import com.example.utils.DateUtils; import lombok.SneakyThrows; import net.sf.jsqlparser.expression.DateTimeLiteralExpression; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; @@ -11,12 +13,16 @@ import javax.websocket.*; import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.Semaphore; @ServerEndpoint(value = "/test/{sid}") @Component public class WebSocketServerContent { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final Logger log = LoggerFactory.getLogger(ServiceImpl.class); private String sid = ""; ServiceImpl ServiceImpl = new ServiceImpl(); // RFIDController RFIDController = new RFIDController(); @@ -41,6 +47,7 @@ public class WebSocketServerContent { webSocketSet.add(this); //加入set中 addOnlineCount(); //在线数加1 System.out.println("有一连接加入!" + session.getId() + "当前在线人数为" + getOnlineCount() + ",IP:" + sid); + log.error("\n有一连接加入!" + "\t时间" + sdf.format(new Date()) + "\tPDAID:" + sid); } /** @@ -51,6 +58,7 @@ public class WebSocketServerContent { webSocketSet.remove(this); //从set中删除 subOnlineCount(); //在线数减1 System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount()); + log.error("\n有一连接关闭!" + "\t时间" + sdf.format(new Date()) + "\tPDAID:" + sid); } /** @@ -61,6 +69,7 @@ public class WebSocketServerContent { @OnMessage public void onMessage(String message, Session session) throws InterruptedException { System.out.println("手持机发来的信息是:" + message); + log.error("手持机发来的信息是:" + message+ "\t时间" + sdf.format(new Date())); ServiceImpl.DealValidPack(message); //RecMessage = message; } @@ -78,9 +87,14 @@ public class WebSocketServerContent { @Bean public void Runable() { Thread t1 = new Thread(new Runnable() { + @Override @SneakyThrows public void run() { - DealMessageDoWork(); + try { + DealMessageDoWork(); + } catch (InterruptedException e) { + e.printStackTrace(); + } } }); t1.start(); diff --git a/src/main/java/com/example/test/IndexConn.java b/src/main/java/com/example/test/IndexConn.java new file mode 100644 index 0000000..8535991 --- /dev/null +++ b/src/main/java/com/example/test/IndexConn.java @@ -0,0 +1,18 @@ +package com.example.test; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author wanghao + * @date 2022/2/8 13:56 + */ +@Controller +public class IndexConn { + @RequestMapping({"/test","/"}) + private String test(){ + return "/test"; + } + + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 76d483d..08d9c12 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,3 +3,7 @@ spring: active: dev +# 日志配置 +logging: + level: + com.example: debug diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..28e4790 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/sys-info.log + + + + ${log.path}/sys-info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/sys-error.log + + + + ${log.path}/sys-error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + ${log.path}/sys-user.log + + + ${log.path}/sys-user.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/test.html b/src/main/resources/templates/test.html new file mode 100644 index 0000000..f1c7500 --- /dev/null +++ b/src/main/resources/templates/test.html @@ -0,0 +1,10 @@ + + + + + Title + + +看到这个页面说明你启动成功了 + + \ No newline at end of file