上线版

master
wangh 3 years ago
parent dbb1e1052a
commit 7265f705d2

@ -13,7 +13,7 @@
<version>0.0.1-SNAPSHOT</version>
<name>ChinaPostWebService</name>
<description>ChinaPostWebService</description>
<packaging>jar</packaging>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
@ -26,17 +26,25 @@
<version>3.4.2</version>
</dependency>
<!--外置tomcat启动-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jdbc</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jdbc</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.alibaba.csb.sdk</groupId>
<artifactId>http-client</artifactId>

@ -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);

@ -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<String, String> params = new HashMap<String, String>();
params.put("messageHeader", msgs);

@ -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(

@ -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, "向客户端发送消息失败!");
}
}

@ -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();

@ -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";
}
}

@ -3,3 +3,7 @@ spring:
active: dev
# 日志配置
logging:
level:
com.example: debug

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="/home/haiwei/logs" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/sys-info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/sys-error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 用户访问日志输出 -->
<appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/sys-user.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天回滚 daily -->
<fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.haiwei" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="info" />
<root level="info">
<appender-ref ref="console" />
</root>
<!-- &lt;!&ndash;系统操作日志&ndash;&gt;-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
</root>
<!--系统用户操作日志-->
<logger name="sys-user" level="info">
<appender-ref ref="sys-user"/>
</logger>
<!--生产环境:输出到文件-->
<springProfile name="pro">
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="INFO_FILE" />
<appender-ref ref="ERROR_FILE" />
<appender-ref ref="WARN_FILE" />
</root>
</springProfile>
</configuration>

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p5>看到这个页面说明你启动成功了</p5>
</body>
</html>
Loading…
Cancel
Save