diff --git a/src/main/java/com/example/entity/ContainerRegisterQuery.java b/src/main/java/com/example/entity/ContainerRegisterQuery.java index 1e71d34..d40a7bb 100644 --- a/src/main/java/com/example/entity/ContainerRegisterQuery.java +++ b/src/main/java/com/example/entity/ContainerRegisterQuery.java @@ -10,7 +10,15 @@ public class ContainerRegisterQuery implements Serializable { private String userName; private String province; private String pdaip; + private int commandCode; + public int getCommandCode() { + return commandCode; + } + + public void setCommandCode(int commandCode) { + this.commandCode = commandCode; + } public String getMessageHeader() { return messageHeader; } diff --git a/src/main/java/com/example/entity/OutCenter.java b/src/main/java/com/example/entity/OutCenter.java new file mode 100644 index 0000000..c54751f --- /dev/null +++ b/src/main/java/com/example/entity/OutCenter.java @@ -0,0 +1,143 @@ +package com.example.entity; + +import java.io.Serializable; + +public class OutCenter implements Serializable { + + private String messageHeader; + private String opOrgCode; + private String opOrgName; + private String userCode; + private String userName; + private String provice; + + private String rqzlmc; + private String zbid; + private String destinationOrgName; + private String destinationOrgCode; + private String rqzl; + private String rqxh; + private String rqxhmc; + private String pdaip; + private int commandCode; + + public String getPdaip() { + return pdaip; + } + + public void setPdaip(String pdaip) { + this.pdaip = pdaip; + } + + public int getCommandCode() { + return commandCode; + } + + public void setCommandCode(int commandCode) { + this.commandCode = commandCode; + } + + public String getMessageHeader() { + return messageHeader; + } + + public void setMessageHeader(String messageHeader) { + this.messageHeader = messageHeader; + } + + public String getOpOrgCode() { + return opOrgCode; + } + + public void setOpOrgCode(String opOrgCode) { + this.opOrgCode = opOrgCode; + } + + public String getOpOrgName() { + return opOrgName; + } + + public void setOpOrgName(String opOrgName) { + this.opOrgName = opOrgName; + } + + public String getUserCode() { + return userCode; + } + + public void setUserCode(String userCode) { + this.userCode = userCode; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getProvice() { + return provice; + } + + public void setProvice(String provice) { + this.provice = provice; + } + + public String getRqzlmc() { + return rqzlmc; + } + + public void setRqzlmc(String rqzlmc) { + this.rqzlmc = rqzlmc; + } + + public String getZbid() { + return zbid; + } + + public void setZbid(String zbid) { + this.zbid = zbid; + } + + public String getDestinationOrgName() { + return destinationOrgName; + } + + public void setDestinationOrgName(String destinationOrgName) { + this.destinationOrgName = destinationOrgName; + } + + public String getDestinationOrgCode() { + return destinationOrgCode; + } + + public void setDestinationOrgCode(String destinationOrgCode) { + this.destinationOrgCode = destinationOrgCode; + } + + public String getRqzl() { + return rqzl; + } + + public void setRqzl(String rqzl) { + this.rqzl = rqzl; + } + + public String getRqxh() { + return rqxh; + } + + public void setRqxh(String rqxh) { + this.rqxh = rqxh; + } + + public String getRqxhmc() { + return rqxhmc; + } + + public void setRqxhmc(String rqxhmc) { + this.rqxhmc = rqxhmc; + } +} diff --git a/src/main/java/com/example/services/IService.java b/src/main/java/com/example/services/IService.java index a0bddf9..edbee53 100644 --- a/src/main/java/com/example/services/IService.java +++ b/src/main/java/com/example/services/IService.java @@ -26,20 +26,19 @@ public interface IService { */ @WebMethod R getScanInfoInCenterStart( + @WebParam(name = "messageHeader") String messageHeader, +// @WebParam(name = "ContainerRegisterQuery") String ContainerRegisterQuery, + @WebParam(name = "opOrgCode") String opOrgCode, + @WebParam(name = "userCode") String userCode, + @WebParam(name = "userName") String userName, + @WebParam(name = "province") String province, @WebParam(name = "pdaip") String pdaip); -// MyResult getScanInfoInCenterStart(@WebParam(name = "messageHeader") String messageHeader, -// @WebParam(name = "ContainerRegisterQuery") String ContainerRegisterQuery, -// @WebParam(name = "opOrgCode") String opOrgCode, -// @WebParam(name = "userCode") String userCode, -// @WebParam(name = "userName") String userName, -// @WebParam(name = "province") String province, -// @WebParam(name = "pdaip") String pdaip); /** * 入库 结束读 * * @param messageHeader 入参1,参数名: - * @param containerRegisterQuery 入参2,将下列参数封装到containerRegisterQuery +// * @param containerRegisterQuery 入参2,将下列参数封装到containerRegisterQuery * @param opOrgCode 机构代码 * @param userCode 登录人代码 * @param userName 登录人名称 @@ -48,8 +47,9 @@ public interface IService { * @return */ @WebMethod - MyResult getScanInfoInCenterStop(@WebParam(name = "messageHeader") String messageHeader, - @WebParam(name = "ContainerRegisterQuery") String containerRegisterQuery, + R getScanInfoInCenterStop( + @WebParam(name = "messageHeader") String messageHeader, +// @WebParam(name = "ContainerRegisterQuery") String containerRegisterQuery, @WebParam(name = "opOrgCode") String opOrgCode, @WebParam(name = "userCode") String userCode, @WebParam(name = "userName") String userName, @@ -78,7 +78,7 @@ public interface IService { * @param pdaip 指定pda开始读的ip */ @WebMethod - MyResult getScanInfoOutCenterStart(@WebParam(name = "messageHeader") String messageHeader, + R getScanInfoOutCenterStart(@WebParam(name = "messageHeader") String messageHeader, @WebParam(name = "ContainerRegisterQuery") String containerRegisterQuery, @WebParam(name = "opOrgCode") String opOrgCode, @WebParam(name = "opOrgName") String opOrgName, @@ -116,7 +116,7 @@ public interface IService { * @return */ @WebMethod - MyResult getScanInfoOutCenterStop(@WebParam(name = "messageHeader") String messageHeader, + R getScanInfoOutCenterStop(@WebParam(name = "messageHeader") String messageHeader, @WebParam(name = "ContainerRegisterQuery") String containerRegisterQuery, @WebParam(name = "opOrgCode") String opOrgCode, @WebParam(name = "opOrgName") String opOrgName, diff --git a/src/main/java/com/example/services/impl/ServiceImpl.java b/src/main/java/com/example/services/impl/ServiceImpl.java index ea06789..1784157 100644 --- a/src/main/java/com/example/services/impl/ServiceImpl.java +++ b/src/main/java/com/example/services/impl/ServiceImpl.java @@ -4,9 +4,12 @@ import com.alibaba.fastjson.JSONObject; import com.example.MyResult; import com.example.api.R; import com.example.entity.ContainerRegisterQuery; +import com.example.entity.OutCenter; import com.example.services.IService; import javax.jws.WebService; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; /** * Created by wangh on 2021/1/14-10:29。 @@ -18,12 +21,33 @@ import javax.jws.WebService; endpointInterface = "com.example.services.IService")//指定发布webservcie的接口类,此类也需要接入@WebService注解 public class ServiceImpl implements IService { - private static boolean m_GetDataSuccessful; + private static boolean m_GetInCenterStartSuccessful; + private static boolean m_GetInCenterStopSuccessful; + private static boolean m_GetOutCenterStartSuccessful; + private static boolean m_GetOutCenterStopSuccessful; + private static final Semaphore m_RecData = new Semaphore(1); public boolean DealValidPack(String ValidData){ try { - if(!ValidData.isEmpty()){ - m_GetDataSuccessful = true; + if(!ValidData.isEmpty()||!ValidData.equals("")){ +// m_RecData.release(); + switch (ValidData){ + case "101": + m_GetInCenterStartSuccessful = true; + break; + case "102": + m_GetInCenterStopSuccessful = true; + break; + case "103": + m_GetOutCenterStartSuccessful = true; + break; + case"104": + m_GetOutCenterStopSuccessful = true; + break; + default: + m_GetInCenterStartSuccessful = true; + break; + } } } catch (Exception ex){ @@ -41,21 +65,29 @@ public class ServiceImpl implements IService { // String province, // String pdaip) { public R getScanInfoInCenterStart( - String pdaip) { + String messageHeader, + String opOrgCode, + String userCode, + String userName, + String province, + String pdaip) { boolean isSendFlag = false; //示例 - ContainerRegisterQuery containerRegisterQuery = new ContainerRegisterQuery(); -// containerRegisterQuery.setMessageHeader(messageHeader); -// containerRegisterQuery.setOpOrgCode(opOrgCode); -// containerRegisterQuery.getUserCode(userCode); - containerRegisterQuery.setPdaip(pdaip); - String json = JSONObject.toJSONString("1"); + ContainerRegisterQuery containerRegisterQuery1 = new ContainerRegisterQuery(); + containerRegisterQuery1.setMessageHeader(messageHeader); + containerRegisterQuery1.setOpOrgCode(opOrgCode); + containerRegisterQuery1.setUserCode(userCode); + containerRegisterQuery1.setUserName(userName); + containerRegisterQuery1.setProvince(province); + containerRegisterQuery1.setPdaip(pdaip); + containerRegisterQuery1.setCommandCode(101); + String json = JSONObject.toJSONString(containerRegisterQuery1); if(WebSocketServerContent.getSocket(pdaip, json)){ try { Thread.sleep(2000); - if(m_GetDataSuccessful){ + if(m_GetInCenterStartSuccessful){ isSendFlag = true; - m_GetDataSuccessful = false; + m_GetInCenterStartSuccessful = false; return R.data(200,"向客户端发送消息成功!"); } else { @@ -63,6 +95,25 @@ public class ServiceImpl implements IService { isSendFlag = false; return R.data(201,"向客户端发送消息成功,接收客户端消息超时!"); } +// if(m_RecData.tryAcquire(2000, TimeUnit.MILLISECONDS)) { +// if(m_GetDataSuccessful){ +// isSendFlag = true; +// m_GetDataSuccessful = false; +// return R.data(200,"success"); +// } +// else { +// System.out.println("《《《等待客户端返回消息超时!"); +// isSendFlag = false; +// m_GetDataSuccessful = false; +// return R.data(401,"timeout"); +// } +// } +// else{ +// System.out.println("《《《等待信号量释放超时!"); +// isSendFlag = false; +// return R.data(402,"semtimeout"); +// } + }catch (Exception ex){ return R.data(100,"向客户端发送消息失败!"); } @@ -70,21 +121,128 @@ public class ServiceImpl implements IService { else { return R.data(101,"向客户端发送消息失败!"); } - } @Override - public MyResult getScanInfoInCenterStop(String messageHeader, String containerRegisterQuery, String opOrgCode, String userCode, String userName, String province, String pdaip) { - return null; + public R getScanInfoInCenterStop( + String messageHeader, String opOrgCode, String userCode, String userName, String province, + String pdaip) { + boolean isSendFlag = false; + //示例 + ContainerRegisterQuery containerRegisterQuery2 = new ContainerRegisterQuery(); + containerRegisterQuery2.setMessageHeader(messageHeader); + containerRegisterQuery2.setOpOrgCode(opOrgCode); + containerRegisterQuery2.setUserCode(userCode); + containerRegisterQuery2.setUserName(userName); + containerRegisterQuery2.setProvince(province); + containerRegisterQuery2.setPdaip(pdaip); + containerRegisterQuery2.setCommandCode(102); + String json = JSONObject.toJSONString(containerRegisterQuery2); + if(WebSocketServerContent.getSocket(pdaip, json)){ + try { + Thread.sleep(2000); + if(m_GetInCenterStopSuccessful){ + isSendFlag = true; + m_GetInCenterStopSuccessful = false; + return R.data(200,"向客户端发送消息成功!"); + } + else { + System.out.println("《《《等待客户端返回消息超时!"); + isSendFlag = false; + return R.data(201,"向客户端发送消息成功,接收客户端消息超时!"); + } + }catch (Exception ex){ + return R.data(100,"向客户端发送消息失败!"); + } + } + else { + return R.data(101,"向客户端发送消息失败!"); + } } @Override - public MyResult getScanInfoOutCenterStart(String messageHeader, String containerRegisterQuery, String opOrgCode, String opOrgName, String userCode, String userName, String provice, String rqzlmc, String zbid, String destinationOrgName, String destinationOrgCode, String rqzl, String rqxh, String rqxhmc, String pdaip) { - return null; + public R getScanInfoOutCenterStart(String messageHeader, String containerRegisterQuery, String opOrgCode, String opOrgName, String userCode, String userName, String provice, String rqzlmc, String zbid, String destinationOrgName, String destinationOrgCode, String rqzl, String rqxh, String rqxhmc, String pdaip) { + boolean isSendFlag = false; + //示例 + OutCenter outCenter1 = new OutCenter(); + outCenter1.setMessageHeader(messageHeader); + outCenter1.setOpOrgCode(opOrgCode); + outCenter1.setOpOrgName(opOrgName); + outCenter1.setUserCode(userCode); + outCenter1.setUserName(userName); + outCenter1.setProvice(provice); + outCenter1.setRqzlmc(rqzlmc); + outCenter1.setZbid(zbid); + outCenter1.setDestinationOrgName(destinationOrgName); + outCenter1.setDestinationOrgCode(destinationOrgCode); + outCenter1.setRqzl(rqzl); + outCenter1.setRqxh(rqxh); + outCenter1.setRqxhmc(rqxhmc); + outCenter1.setPdaip(pdaip); + outCenter1.setCommandCode(103); + String json = JSONObject.toJSONString(outCenter1); + if(WebSocketServerContent.getSocket(pdaip, json)){ + try { + Thread.sleep(2000); + if(m_GetOutCenterStartSuccessful){ + isSendFlag = true; + m_GetOutCenterStartSuccessful = false; + return R.data(200,"向客户端发送消息成功!"); + } + else { + System.out.println("《《《等待客户端返回消息超时!"); + isSendFlag = false; + return R.data(201,"向客户端发送消息成功,接收客户端消息超时!"); + } + }catch (Exception ex){ + return R.data(100,"向客户端发送消息失败!"); + } + } + else { + return R.data(101,"向客户端发送消息失败!"); + } } @Override - public MyResult getScanInfoOutCenterStop(String messageHeader, String containerRegisterQuery, String opOrgCode, String opOrgName, String userCode, String userName, String provice, String rqzlmc, String zbid, String destinationOrgName, String destinationOrgCode, String rqzl, String rqxh, String rqxhmc, String pdaip) { - return null; + public R getScanInfoOutCenterStop(String messageHeader, String containerRegisterQuery, String opOrgCode, String opOrgName, String userCode, String userName, String provice, String rqzlmc, String zbid, String destinationOrgName, String destinationOrgCode, String rqzl, String rqxh, String rqxhmc, String pdaip) { + boolean isSendFlag = false; + //示例 + OutCenter outCenter2 = new OutCenter(); + outCenter2.setMessageHeader(messageHeader); + outCenter2.setOpOrgCode(opOrgCode); + outCenter2.setOpOrgName(opOrgName); + outCenter2.setUserCode(userCode); + outCenter2.setUserName(userName); + outCenter2.setProvice(provice); + outCenter2.setRqzlmc(rqzlmc); + outCenter2.setZbid(zbid); + outCenter2.setDestinationOrgName(destinationOrgName); + outCenter2.setDestinationOrgCode(destinationOrgCode); + outCenter2.setRqzl(rqzl); + outCenter2.setRqxh(rqxh); + outCenter2.setRqxhmc(rqxhmc); + outCenter2.setPdaip(pdaip); + outCenter2.setCommandCode(104); + String json = JSONObject.toJSONString(outCenter2); + if(WebSocketServerContent.getSocket(pdaip, json)){ + try { + Thread.sleep(2000); + if(m_GetOutCenterStopSuccessful){ + isSendFlag = true; + m_GetOutCenterStopSuccessful = false; + return R.data(200,"向客户端发送消息成功!"); + } + else { + System.out.println("《《《等待客户端返回消息超时!"); + isSendFlag = false; + return R.data(201,"向客户端发送消息成功,接收客户端消息超时!"); + } + }catch (Exception ex){ + return R.data(100,"向客户端发送消息失败!"); + } + } + else { + 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 60def66..cda26ca 100644 --- a/src/main/java/com/example/services/impl/WebSocketServerContent.java +++ b/src/main/java/com/example/services/impl/WebSocketServerContent.java @@ -16,6 +16,7 @@ import java.util.concurrent.Semaphore; @Component public class WebSocketServerContent { private String sid = ""; + ServiceImpl ServiceImpl = new ServiceImpl(); // RFIDController RFIDController = new RFIDController(); //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 private static int onlineCount = 0; @@ -81,13 +82,13 @@ public class WebSocketServerContent { } private void DealMessageDoWork() throws InterruptedException { while (true){ -// if(RFIDController != null){ -// if(!RecMessage.isEmpty() || !RecMessage.equals("")){ -// RFIDController.DealValidPack(RecMessage); -// RecMessage = ""; -// } -// } - System.out.println("一开始就运行"); + if(ServiceImpl != null){ + if(!RecMessage.isEmpty() || !RecMessage.equals("")){ + ServiceImpl.DealValidPack(RecMessage); + RecMessage = ""; + } + } +// System.out.println("一开始就运行"); Thread.sleep(1000); } } @@ -106,19 +107,29 @@ public class WebSocketServerContent { } public static synchronized boolean getSocket(String id,String message) { + boolean isFlag = false; try { - boolean isFlag = false; - for (WebSocketServerContent i: webSocketSet - ) { - if(i.sid.equals(id)){ - i.sendMessage(message,i.session); + + if(id.equals("") || id == null){ + for (WebSocketServerContent i: webSocketSet + ) { + i.sendMessage(message, i.session); isFlag = true; } } - return isFlag; + else{ + for (WebSocketServerContent i: webSocketSet + ) { + if(i.sid.equals(id)){ + i.sendMessage(message,i.session); + isFlag = true; + } + } + } }catch (Exception ex){ return false; } + return isFlag; } public static synchronized int getOnlineCount() { return onlineCount; diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index c087423..7605695 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,5 +1,5 @@ server: - port: 8090 + port: 9090 servlet: context-path: /