From 5bb3ad3944ff229baff1d8bb92caf55d816ee68b Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期六, 02 十二月 2023 18:34:45 +0800 Subject: [PATCH] 提交粮情协议1 --- src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java | 24 src/main/java/com/fzzy/protocol/fzzy/data/ReMessage.java | 59 ++ src/main/java/com/fzzy/api/data/ApiCommonDevice.java | 30 + src/main/java/com/fzzy/protocol/fzzy/cmd/BaseRemoteImpl.java | 61 ++ src/main/java/com/fzzy/gateway/GatewayUtils.java | 25 src/main/java/com/fzzy/protocol/fzzy/builder/ObjectCommandBuilder.java | 75 ++ src/main/java/com/fzzy/gateway/entity/GatewayDevice.java | 10 src/main/java/com/fzzy/protocol/fzzy/service/FzzyGatewayGrainService.java | 87 +++ src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java | 89 +++ src/main/java/com/fzzy/protocol/fzzy/req/Request2101.java | 10 src/main/java/com/fzzy/protocol/fzzy/data/MessageInfo.java | 28 + src/main/java/com/fzzy/protocol/fzzy/server/FzzyServerEngine.java | 77 ++ src/main/java/com/fzzy/protocol/fzzy/builder/CommandBuilder.java | 67 ++ src/main/java/com/fzzy/protocol/fzzy/builder/SimpleCommandBuilder.java | 96 +++ src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java | 193 ++++++ src/main/java/com/fzzy/protocol/fzzy/server/ServerUtils.java | 219 +++++++ src/main/java/com/fzzy/api/utils/ContextUtil.java | 48 + src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java | 2 src/main/java/com/fzzy/io/request/BaseRequest.java | 50 + src/main/java/com/fzzy/protocol/fzzy/resp/Response1001.java | 9 src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java | 10 src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java | 74 ++ src/main/java/com/fzzy/protocol/fzzy/builder/GrainCommandBuilder.java | 58 ++ src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java | 61 ++ src/main/java/com/fzzy/protocol/fzzy/package-info.java | 1 src/main/java/com/fzzy/io/package-info.java | 1 src/main/java/com/fzzy/api/Constant.java | 54 + src/main/java/com/fzzy/protocol/ProtocolRunner.java | 6 src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java | 4 src/main/java/com/fzzy/protocol/fzzy/data/SendMessage.java | 34 + src/main/java/com/fzzy/protocol/fzzy/resp/Response2102.java | 48 + src/main/resources/application.yml | 15 32 files changed, 1,596 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/fzzy/api/Constant.java b/src/main/java/com/fzzy/api/Constant.java index 981ae0e..b38f697 100644 --- a/src/main/java/com/fzzy/api/Constant.java +++ b/src/main/java/com/fzzy/api/Constant.java @@ -1,9 +1,15 @@ package com.fzzy.api; +import com.fzzy.api.data.ApiCommonDevice; + +import java.util.HashMap; +import java.util.Map; + /** * 鍏ㄥ眬闈欐�佺被 */ public class Constant { + public static final String DEFAULT_CODE = "0"; public static final String YN_N = "N"; @@ -307,4 +313,52 @@ */ public static final String DEFAULT_USER_PASSWORD = "123456"; + + /** + * 鍐呭瓨鏁版嵁缂撳瓨锛岀敤浜庡瓨鍌ㄥ嚭鍏ュ簱鐩稿叧鐨勪复鏃朵俊鎭紝濡傚埛鍗¤澶囧綋鍓嶆渶鏂版暟鎹瓑銆� + */ + public static Map<String, ApiCommonDevice> contextDeviceMap = new HashMap<>(); + + public static ApiCommonDevice getCommonDeviceCache(String sn) { + if (null == sn) return null; + return contextDeviceMap.get(sn); + } + + public static void updateCacheOnline(String sn, String ip, Integer port, boolean isCreate) { + ApiCommonDevice device = getCommonDeviceCache(sn); + if (null == device && isCreate) { + device = new ApiCommonDevice(); + } + if (null != device) { + device.setIp(ip); + device.setPort(port); + device.setStatus(Constant.YN_Y); + device.setCode("SUCCESS"); + device.setMsg("璁惧鍦ㄧ嚎"); + device.setSn(ip); + contextDeviceMap.put(device.getSn(), device); + } + } + + public static void updateCacheOffline(String sn, String ip, Integer port, boolean isCreate) { + ApiCommonDevice device = getCommonDeviceCache(sn); + + if (null == device && isCreate) { + device = new ApiCommonDevice(); + } + + if (null != device) { + device.setIp(ip); + device.setPort(port); + device.setStatus(Constant.YN_N); + device.setCode("ERROR"); + device.setMsg("璁惧绂荤嚎"); + + contextDeviceMap.put(device.getSn(), device); + } + } + + public static void updateCache(ApiCommonDevice device) { + contextDeviceMap.put(device.getSn(), device); + } } diff --git a/src/main/java/com/fzzy/api/data/ApiCommonDevice.java b/src/main/java/com/fzzy/api/data/ApiCommonDevice.java new file mode 100644 index 0000000..4f0906b --- /dev/null +++ b/src/main/java/com/fzzy/api/data/ApiCommonDevice.java @@ -0,0 +1,30 @@ +package com.fzzy.api.data; + +import com.fzzy.api.Constant; +import lombok.Data; + +/** + * 铏氭嫙閫氱敤璁惧锛屼富瑕佺敤浜庨�氳杩囩▼涓殑璁惧淇℃伅锛屼笉鎸佷箙鍖栧埌鏁版嵁搴擄紝鍦ㄥ唴瀛樹腑淇濆瓨鍜屾洿鏂扮姸鎬� + */ +@Data +public class ApiCommonDevice { + + + private String id; + + private String sn; + + private String ip; + + private Integer port; + + //鐘舵�佹槸鍚﹀湪绾� + private String status = Constant.YN_Y; + + private String code = "SUCCESS"; + + private String msg = "鎴愬姛"; + + private String result;//缁撴灉淇℃伅锛屼互瀛楃涓蹭唬鏇� + +} diff --git a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java index 05f205c..2acecef 100644 --- a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java +++ b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java @@ -11,7 +11,7 @@ */ public enum GatewayDeviceProtocol { - GRAIN_FZZY_ZH_2023("GRAIN_FZZY_ZH_2023", "绮儏-椋庢鑷磋繙鎺у埗鏌滃崗璁�2023"), + TCP_FZZY_V3("TCP_FZZY_V3", "绮儏-椋庢鑷磋繙鎺у埗鏌滃崗璁甐3"), GRAIN_FZZY_IGDS_V40("GRAIN_FZZY_IGDS_V40", "绮儏-椋庢鑷磋繙绯荤粺V40"), DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "鍦扮-HTTP鍗忚"), DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "鍦扮-鑰�鍗嶵CP鍗忚"), @@ -26,7 +26,7 @@ public static List<ApiTrigger> listTrigger() { List<ApiTrigger> list = new ArrayList<>(); - list.add(new ApiTrigger(GRAIN_FZZY_ZH_2023.getCode(), GRAIN_FZZY_ZH_2023.getName())); + list.add(new ApiTrigger(TCP_FZZY_V3.getCode(), TCP_FZZY_V3.getName())); list.add(new ApiTrigger(GRAIN_FZZY_IGDS_V40.getCode(), GRAIN_FZZY_IGDS_V40.getName())); list.add(new ApiTrigger(DEVICE_WEIGHT_HTTP.getCode(), DEVICE_WEIGHT_HTTP.getName())); list.add(new ApiTrigger(DEVICE_WEIGHT_TCP_YH.getCode(), DEVICE_WEIGHT_TCP_YH.getName())); diff --git a/src/main/java/com/fzzy/api/utils/ContextUtil.java b/src/main/java/com/fzzy/api/utils/ContextUtil.java index cc8cafe..287452f 100644 --- a/src/main/java/com/fzzy/api/utils/ContextUtil.java +++ b/src/main/java/com/fzzy/api/utils/ContextUtil.java @@ -4,14 +4,18 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; -import java.util.Calendar; -import java.util.Date; -import java.util.UUID; +import java.util.*; /** * */ public class ContextUtil { + + + /** + * 鍏ㄥ眬鍛戒护ID + */ + public static Map<String, Integer> contextOrderId = new HashMap<>(); public static String getUUID() { @@ -147,4 +151,42 @@ public static String getServerKey(String ip, Integer port) { return ip + ":" + port; } + + + /** + * 鏍规嵁鍙傛暟鐢熸垚 鎵ц鍛戒护鐨勭紦瀛楰EY + * + * @param companyId + * @param serId + * @param bizType + * @return + */ + public static final String buildExeOrderId(String companyId, String serId, String bizType) { + Integer start = contextOrderId.get("ORDER_ID") == null ? 5000 : contextOrderId.get("ORDER_ID"); + + contextOrderId.put("ORDER_ID", start + 1); + + return start + ""; + } + + /** + * 璁惧ID鐢熸垚瑙勫垯 + * + * @param companyId + * @param depotId + * @param passCode + * @return + */ + public static final String buildDeviceId(String companyId, String depotId, int passCode) { + return companyId + "_" + depotId + "_" + passCode; + } + + public static String buildDeviceStatusKey(String companyId, String serId, String passCode) { + if (null == passCode) passCode = "NULL"; + return companyId + "_" + serId + "_STATUS_" + passCode; + } + + public static String buildDeviceStatusKey(String companyId, String serId, int passCode) { + return companyId + "_" + serId + "_STATUS_" + passCode; + } } diff --git a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java index 147089f..8daf788 100644 --- a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java +++ b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java @@ -33,7 +33,7 @@ @Component(GatewayTimerScheduled.BEAN_ID) public class GatewayTimerScheduled { - public static String DEFAULT_URL = "https://v0.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}"; + public static String DEFAULT_URL = "https://v1.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}"; public static String DEFAULT_APP_ID = "49421971"; public static String DEFAULT_APP_SECRET = "JmJE48Fv"; public static String DEFAULT_CITYID = "101270101";//鎴愰兘 diff --git a/src/main/java/com/fzzy/gateway/GatewayUtils.java b/src/main/java/com/fzzy/gateway/GatewayUtils.java index 0de33a5..b87a207 100644 --- a/src/main/java/com/fzzy/gateway/GatewayUtils.java +++ b/src/main/java/com/fzzy/gateway/GatewayUtils.java @@ -1,7 +1,10 @@ package com.fzzy.gateway; +import com.fzzy.api.Constant; +import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.gateway.entity.GatewayDevice; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import java.util.*; @@ -11,13 +14,6 @@ */ @Component public class GatewayUtils { - - - /** - * 璁惧鍦ㄧ嚎鏍囪锛岄拡瀵筗EBSocket璇锋眰锛屾帶鍒惰澶囨槸鍚﹀湪绾匡紝key = deviceId锛孷alue=Y/N - */ - public static Map<String, String> contextOnlineMap = new HashMap<>(); - /** * 璁惧缂撳瓨 @@ -74,22 +70,21 @@ cacheMapDeviceSn.remove(data.getDeviceSn()); } - public static void updateOnline(String deviceId) { - contextOnlineMap.put(deviceId, "Y"); + public static String getStatus(String sn) { + ApiCommonDevice device = Constant.getCommonDeviceCache(sn); + if (null == device) return Constant.YN_N; + return device.getStatus(); } - public static void updateOffOnline(String deviceId) { - contextOnlineMap.put(deviceId, "N"); - } public static boolean isOnline(String deviceId) { - String value = contextOnlineMap.get(deviceId); - if (null == value || "N".equals(value)) return false; + GatewayDevice device = getCacheByDeviceId(deviceId); + if (null == device.getStatus() || Constant.YN_N.equals(device.getStatus())) return false; return true; } - public static Collection<GatewayDevice> listDeviceWeight(){ + public static Collection<GatewayDevice> listDeviceWeight() { return cacheMapDeviceWeight.values(); } } diff --git a/src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java b/src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java index da95754..a29e503 100644 --- a/src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java +++ b/src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java @@ -1,5 +1,6 @@ package com.fzzy.gateway.controller; +import com.fzzy.api.data.GatewayDeviceProtocol; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.gateway.GatewayUtils; import com.fzzy.gateway.api.GatewayRemoteManager; @@ -125,7 +126,14 @@ return "ERROR锛氬綋鍓嶈澶囨病鏈夐厤缃竷绾胯鍒欙紝鏃犳硶鎵ц"; } - BaseResp resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(reqData); + BaseResp resp =null; + if(GatewayDeviceProtocol.DEVICE_TEST.getCode().equals(device.getSyncProtocol())){ + resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(reqData); + }else{ + reqData.setAutoReplay(false); + resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(reqData); + } + //鑷姩鎺ㄩ�� if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) { reqData.setData(resp.getData()); diff --git a/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java b/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java index 68c7daa..9d34078 100644 --- a/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java +++ b/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java @@ -2,11 +2,13 @@ import com.bstek.dorado.annotation.PropertyDef; +import com.fzzy.api.Constant; import lombok.Data; import javax.persistence.*; import java.io.Serializable; +import java.util.Date; /** * 缃戝叧鐩稿叧鐨勮澶囩鐞� @@ -117,4 +119,12 @@ @PropertyDef(label = "绛掍粨灞傝鍒�", description = "閽堝绛掍粨") private String cableCir; + @Transient + @PropertyDef(label = "璁惧鍦ㄧ嚎鐘舵��") + private String status = Constant.YN_N; + + @Transient + @PropertyDef(label = "璁惧涓婄嚎鏃堕棿") + private Date onlineTime; + } diff --git a/src/main/java/com/fzzy/io/package-info.java b/src/main/java/com/fzzy/io/package-info.java new file mode 100644 index 0000000..a136c2d --- /dev/null +++ b/src/main/java/com/fzzy/io/package-info.java @@ -0,0 +1 @@ +package com.fzzy.io; \ No newline at end of file diff --git a/src/main/java/com/fzzy/io/request/BaseRequest.java b/src/main/java/com/fzzy/io/request/BaseRequest.java new file mode 100644 index 0000000..e4c41fd --- /dev/null +++ b/src/main/java/com/fzzy/io/request/BaseRequest.java @@ -0,0 +1,50 @@ +package com.fzzy.io.request; + +import com.fzzy.api.utils.ContextUtil; +import lombok.Data; + +import java.util.Date; + +/** + * + */ +@Data +public class BaseRequest { + + private String orderId;//鑷畾涔夊懡浠D + + private String deptId; + + private String companyId;//缁勭粐缂栫爜 + + private String depotId;//浠撳簱缂栧彿 + + private String serId = "0";//鍒嗘満缂栧彿 + + private String ip; //鍒嗘満IP + + private Integer port;//鍒嗘満绔彛鍙� + + private String bizType;//涓氬姟绫诲瀷 + + private String serName; + + private String depotName; + + private String protocol; + + private Date exeTime = new Date();//鎵ц鏃堕棿 + + + public BaseRequest() { + super(); + this.orderId = ContextUtil.buildExeOrderId(null, null, null); + } + + public BaseRequest(String companyId, String serId, String bizType) { + this.orderId = ContextUtil.buildExeOrderId(companyId, serId, bizType); + this.companyId = companyId; + this.serId = serId; + this.bizType = bizType; + } +} diff --git a/src/main/java/com/fzzy/protocol/ProtocolRunner.java b/src/main/java/com/fzzy/protocol/ProtocolRunner.java index 7ec0b23..5287ebb 100644 --- a/src/main/java/com/fzzy/protocol/ProtocolRunner.java +++ b/src/main/java/com/fzzy/protocol/ProtocolRunner.java @@ -1,5 +1,6 @@ package com.fzzy.protocol; +import com.fzzy.protocol.fzzy.server.FzzyServerEngine; import com.fzzy.protocol.weightyh.YhScaleServerEngine; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.CommandLineRunner; @@ -16,9 +17,14 @@ @Override public void run(String... args) throws Exception { + + //鑰�鍗庡湴纾匱CP鍗忚 YhScaleServerEngine.start(); + //椋庢鑷磋繙鎺у埗鏌滃崗璁惎鍔� + FzzyServerEngine.start(null); + } } diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java new file mode 100644 index 0000000..6e02d70 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java @@ -0,0 +1,74 @@ +package com.fzzy.protocol.fzzy.analysis; + +import com.alibaba.fastjson.JSONObject; +import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.gateway.data.BaseReqData; +import com.fzzy.protocol.fzzy.builder.SimpleCommandBuilder; +import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl; +import com.fzzy.protocol.fzzy.data.ReMessage; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.resp.Response2102; +import com.fzzy.protocol.fzzy.server.ServerUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 绮儏瑙f瀽 + * + * @author Andy + */ +@Slf4j +@Component(AnalysisGrain.BEAN_ID) +public class AnalysisGrain extends BaseRemoteImpl { + + public static final String BEAN_ID = "fzzy.analysisGrain"; + + + public static int ERROR_CHECK_TAG = -1000;//绮俯锛屾皵浣擄紝铏锛屾晠闅滃�� + + public static int ERROR_CHECK_TAG2 = -2000;//浼犳劅鍣ㄦ晠闅滄垨鑰呬笉鍦ㄧ嚎 + + + public void analysis2101(ReMessage reMessage, ApiCommonDevice ser) { + //DO NOTHING + } + + /** + * 绮儏杩斿洖淇℃伅瑙f瀽 + * + * @param reMessage + * @param ser + */ + public void analysis2102(ReMessage reMessage, ApiCommonDevice ser) { + + try { + + //杩斿洖鎺у埗鏌滀俊鎭� + returnMsg(ser); + + Response2102 response = JSONObject.parseObject(reMessage.getContent(), Response2102.class); + + String depotId = response.getHouseId(); + + //鑾峰彇璇锋眰淇℃伅 + BaseReqData reqData = ServerUtils.getSyncReq(depotId); + + + //绮儏瑙f瀽 + log.info("鎺у埗鏌�--->骞冲彴绮儏淇℃伅--{}", response); + + + } catch (Exception e) { + + log.error("鎺у埗鏌�--->骞冲彴绮儏淇℃伅寮傚父-{}", e); + + } + } + + private void returnMsg(ApiCommonDevice ser) { + //鍏堝洖澶嶆帶鍒舵煖 + SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance(); + SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_2102); + send(message); + } +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java new file mode 100644 index 0000000..e270adf --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java @@ -0,0 +1,193 @@ +package com.fzzy.protocol.fzzy.analysis; + +import com.fzzy.api.Constant; +import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.protocol.fzzy.data.ReMessage; +import com.fzzy.protocol.fzzy.server.ServerUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + + +/** + * 鍗忚瑙f瀽鎬诲叆鍙� + */ +@Slf4j +@Component(AnalysisService.BEAN_ID) +public class AnalysisService { + + public static final String BEAN_ID = "fzzy.analysisService"; + + @Resource + private AnalysisSystem analysisSystem; + @Resource + private AnalysisGrain analysisGrain; + + /** + * 鍗忚瑙f瀽鍏ュ彛 + * + * @param message 杩斿洖淇℃伅 + */ + public void analysis(ReMessage message) { + try { + if (null == message) return; + + //鐧诲綍瑙f瀽 + if (ServerUtils.FUNCTION_1001.equals(message.getFunctionId())) { + analysisSystem.analysis1001(message); + return; + } + + String checkMsg = checkMsg(message); + if (null != checkMsg) { + log.error("鎺у埗鏌�------>>>骞冲彴锛氬綋鍓嶇粍缁囩紪鐮�={}锛屽垎鏈篒D={}锛屾姤鏂囦俊鎭�-={}锛屽搷搴斿悧杩斿洖涓嶆纭紝鏃犳硶杩涜瑙f瀽," + checkMsg, message.getCompanyId(), message.getIedId(), message.getStrMsg()); + return; + } + + + //鎵ц鐨勫垎鏈轰俊鎭� + ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getSn()); + if (null == commonDevice) { + log.warn("鎺у埗鏌�------>>>骞冲彴锛氬綋鍓嶇粍缁囩紪鐮�={}锛屽垎鏈篒D={}锛岀郴缁熸病鏈夎幏鍙栧埌鍒嗘満淇℃伅锛屾姤鏂囨棤娉曡繘琛岃В鏋�", message.getCompanyId(), message.getIedId()); + return; + } + + + //鏍规嵁鎺ュ彛缂栧彿杩涜瑙f瀽璺敱 + switch (message.getFunctionId()) { + case ServerUtils.FUNCTION_1003: + analysisSystem.analysis1003(message, commonDevice); + break; + case ServerUtils.FUNCTION_1004: + analysisSystem.analysis1004(message, commonDevice); + break; + case ServerUtils.FUNCTION_1005: + analysisSystem.analysis1005(message, commonDevice); + break; + case ServerUtils.FUNCTION_1006: + analysisSystem.analysis1006(message, commonDevice); + break; + case ServerUtils.FUNCTION_1007: + analysisSystem.analysis1007(message, commonDevice); + break; + case ServerUtils.FUNCTION_1008: + analysisSystem.analysis1008(message, commonDevice); + break; + case ServerUtils.FUNCTION_1009: + analysisSystem.analysis1009(message, commonDevice); + break; + case ServerUtils.FUNCTION_1010: + analysisSystem.analysis1010(message, commonDevice); + break; + + case ServerUtils.FUNCTION_2101: + analysisGrain.analysis2101(message, commonDevice); + break; + case ServerUtils.FUNCTION_2102: + analysisGrain.analysis2102(message, commonDevice); + break; + +// case ServerUtils.FUNCTION_2201: +// analysisPest.analysis2201(message, ser); +// break; +// case ServerUtils.FUNCTION_2202: +// analysisPest.analysis2202(message, ser); +// break; +// case ServerUtils.FUNCTION_2203: +// analysisPest.analysis2203(message, ser); +// break; +// case ServerUtils.FUNCTION_2204: +// analysisPest.analysis2204(message, ser); +// break; +// +// case ServerUtils.FUNCTION_2301: +// analysisGas.analysis2301(message, ser); +// break; +// case ServerUtils.FUNCTION_2302: +// analysisGas.analysis2302(message, ser); +// break; +// +// case ServerUtils.FUNCTION_2303: +// analysisGas.analysis2303(message, ser); +// break; +// case ServerUtils.FUNCTION_2304: +// analysisGas.analysis2304(message, ser); +// break; +// +// case ServerUtils.FUNCTION_3101: +// analysisDevice.analysis3101(message, ser); +// break; +// case ServerUtils.FUNCTION_3102: +// analysisDevice.analysis3102(message, ser); +// break; +// case ServerUtils.FUNCTION_3103: +// analysisDevice.analysis3103(message, ser); +// break; +// +// case ServerUtils.FUNCTION_3201: +// analysisDevice.analysis3201(message, ser); +// break; +// +// case ServerUtils.FUNCTION_3301: +// analysisN2.analysis3301(message, ser); +// break; +// case ServerUtils.FUNCTION_3302: +// analysisN2.analysis3302(message, ser); +// break; +// case ServerUtils.FUNCTION_3303: +// analysisN2.analysis3303(message, ser); +// break; +// case ServerUtils.FUNCTION_3304: +// analysisN2.analysis3304(message, ser); +// break; +// +// case ServerUtils.FUNCTION_4001: +// analysisEs.analysis4001(message, ser); +// break; +// +// case ServerUtils.FUNCTION_5001: +// analysisTemp.analysis5001(message, ser); +// break; +// +// case ServerUtils.FUNCTION_5002: +// analysisTemp.analysis5002(message, ser); +// break; +// +// case ServerUtils.FUNCTION_6001: +// analysisIot.analysis6001(message, ser); +// break; + + default: + break; + } + } catch (Exception e) { + log.error("鎺у埗鏌�----->>>>骞冲彴锛氳В鏋愯繑鍥炴姤鏂囧嚭鐜板紓甯革細" + e); + e.printStackTrace(); + } + } + + public String checkMsg(ReMessage message) { + if (StringUtils.isEmpty(message.getRespCode())) return null; + + if (ServerUtils.RESP_0000.equals(message.getRespCode())) return null; + + if (ServerUtils.RESP_1000.equals(message.getRespCode())) return "鎺у埗鏌滅紪鍙烽敊璇�"; + if (ServerUtils.RESP_1001.equals(message.getRespCode())) return "缁堢璁惧涓嶅湪绾�"; + if (ServerUtils.RESP_1010.equals(message.getRespCode())) return "鎺у埗鏌滄巿鏉冨埌鏈�"; + if (ServerUtils.RESP_1011.equals(message.getRespCode())) return "鎺堟潈鐮佹棤鏁�"; + if (ServerUtils.RESP_1012.equals(message.getRespCode())) return "鎺堟潈鐮佸凡琚娇鐢�"; + if (ServerUtils.RESP_1013.equals(message.getRespCode())) return "鎺堟潈鐮佸凡杩囨湡"; + if (ServerUtils.RESP_2000.equals(message.getRespCode())) return "绛惧悕楠岃瘉澶辫触"; + if (ServerUtils.RESP_3000.equals(message.getRespCode())) return "閫氶妯″紡涓嶆敮鎸�"; + if (ServerUtils.RESP_4000.equals(message.getRespCode())) return "姘旇皟妯″紡涓嶆敮鎸�"; + if (ServerUtils.RESP_5000.equals(message.getRespCode())) return "鎺у埗鏌滃綋鍓嶄负鎵嬪姩妯″紡锛屾嫆缁濊繙绋嬫搷浣�"; + if (ServerUtils.RESP_6000.equals(message.getRespCode())) return "閲囬泦鎵ц澶辫触"; + if (ServerUtils.RESP_6001.equals(message.getRespCode())) return "绮儏閲囬泦鎵ц涓�"; + if (ServerUtils.RESP_6002.equals(message.getRespCode())) return "姘斾綋閲囬泦鎵ц涓�"; + if (ServerUtils.RESP_6003.equals(message.getRespCode())) return "铏閲囬泦鎵ц涓�"; + if (ServerUtils.RESP_9999.equals(message.getRespCode())) return "鏈煡閿欒"; + return null; + } +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java new file mode 100644 index 0000000..91db1bd --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java @@ -0,0 +1,89 @@ +package com.fzzy.protocol.fzzy.analysis; + +import com.fzzy.api.Constant; +import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.gateway.GatewayUtils; +import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.protocol.fzzy.builder.ObjectCommandBuilder; +import com.fzzy.protocol.fzzy.builder.SimpleCommandBuilder; +import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl; +import com.fzzy.protocol.fzzy.data.ReMessage; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.resp.Response1001; +import com.fzzy.protocol.fzzy.server.ServerUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.stereotype.Component; + +import java.util.Date; + +/** + * 绯荤粺绫诲崗璁В鏋� + */ +@Slf4j +@Component(AnalysisSystem.BEAN_ID) +public class AnalysisSystem extends BaseRemoteImpl { + + public static final String BEAN_ID = "fzzy.analysisSystem"; + + + public void analysis1001(ReMessage reMessage) { + + //鑾峰彇鍒扮櫥闄嗕俊鎭紝鎵ц璁惧淇℃伅鏁寸悊 + ApiCommonDevice device = Constant.getCommonDeviceCache(reMessage.getSn()); + if (null == device) { + device = new ApiCommonDevice(); + } + device.setIp(reMessage.getIp()); + device.setPort(reMessage.getPort()); + device.setSn(reMessage.getSn()); + device.setId(reMessage.getIedId()); + Constant.updateCache(device); + + + //杩斿洖褰撳墠绯荤粺鏃堕棿 + Response1001 response = new Response1001(); + response.setTime(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss")); + + ObjectCommandBuilder commandBuilder = ObjectCommandBuilder.getInstance(); + SendMessage message = commandBuilder.buildMessage(reMessage, ServerUtils.FUNCTION_1001, response); + send(message); + + log.info("鎺у埗鏌�----->>>骞冲彴锛氭帶鍒舵煖涓婄嚎鐧婚檰鎴愬姛-IP={},PORT={}", reMessage.getIp(), reMessage.getPort()); + } + + public void analysis1003(ReMessage reMessage, ApiCommonDevice ser) { + } + + public void analysis1004(ReMessage reMessage, ApiCommonDevice ser) { + } + + public void analysis1005(ReMessage reMessage, ApiCommonDevice ser) { + //鐩存帴杩斿洖 + SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance(); + SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1005); + send(message); + } + + public void analysis1006(ReMessage reMessage, ApiCommonDevice ser) { + + //TODO + } + + public void analysis1007(ReMessage reMessage, ApiCommonDevice ser) { + + log.info("鎺у埗鏌�----->>>骞冲彴锛氭帶鍒舵煖浠撳簱鐘舵�佷俊鎭悓姝ュ畬鎴�-鎺у埗鏌�={}", ser.getIp()); + } + + public void analysis1008(ReMessage message, ApiCommonDevice ser) { + + } + + public void analysis1009(ReMessage message, ApiCommonDevice ser) { + + } + + public void analysis1010(ReMessage reMessage, ApiCommonDevice ser) { + log.info("鎺у埗鏌�----->>>骞冲彴锛氭帶鍒舵煖浠撳簱閰嶇疆淇℃伅鍚屾瀹屾垚-鎺у埗鏌�={}", ser.getIp()); + } +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/builder/CommandBuilder.java b/src/main/java/com/fzzy/protocol/fzzy/builder/CommandBuilder.java new file mode 100644 index 0000000..e74ce7a --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/builder/CommandBuilder.java @@ -0,0 +1,67 @@ +package com.fzzy.protocol.fzzy.builder; + +import com.alibaba.fastjson.JSONObject; +import com.fzzy.io.request.BaseRequest; +import com.fzzy.protocol.fzzy.data.MessageInfo; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.server.ServerUtils; + + +/** + * 鍛戒护鐢熸垚 + * + * @author Andy + */ +public abstract class CommandBuilder { + + public SendMessage buildMessage(BaseRequest request) { + SendMessage message = new SendMessage(); + message.setIp(request.getIp()); + message.setPort(request.getPort()); + + message.setBegin(ServerUtils.MSG_BEGIN); + + // 璋冩暣淇℃伅 + buildInfo(message, request); + + + message.setEnd(ServerUtils.MSG_END); + + // 鐢熸垚鏁翠綋鍛戒护淇℃伅鍜孊Yte淇℃伅 + build(message); + + return message; + } + + public void buildInfo(SendMessage message, BaseRequest request) { + MessageInfo info = new MessageInfo(); + info.setSign(request.getCompanyId()); + info.setIedId(request.getSerId()); + info.setFunctionId(ServerUtils.FUNCTION_1001); + info.setRespCode("0000"); + info.setOrderId(request.getOrderId()); + info.setUserData("0"); + info.setSign("0000"); + info.setContent(null); + message.setInfo(info); + } + + /** + * 鏍规嵁鐢熸垚鐨勫懡浠わ紝杩涜璋冩暣 + * + * @param message + */ + public void build(SendMessage message) { + StringBuffer hexSb = new StringBuffer(); + hexSb.append(message.getBegin()); + + message.setStrMsg(JSONObject.toJSONString(message.getInfo())); + + hexSb.append(message.getStrMsg()); + + hexSb.append(message.getEnd()); + + message.setByteMsg(hexSb.toString().getBytes()); + } + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/builder/GrainCommandBuilder.java b/src/main/java/com/fzzy/protocol/fzzy/builder/GrainCommandBuilder.java new file mode 100644 index 0000000..3f14083 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/builder/GrainCommandBuilder.java @@ -0,0 +1,58 @@ +package com.fzzy.protocol.fzzy.builder; + + +import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.protocol.fzzy.data.MessageInfo; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.req.Request2101; +import com.fzzy.protocol.fzzy.server.ServerUtils; + +public class GrainCommandBuilder extends CommandBuilder { + + private final static GrainCommandBuilder instance = new GrainCommandBuilder(); + + private GrainCommandBuilder() { + } + + public static GrainCommandBuilder getInstance() { + return instance; + } + + + public SendMessage buildMessage(GatewayDevice device, ApiCommonDevice apiCommonDevice) { + SendMessage message = new SendMessage(); + message.setIp(apiCommonDevice.getIp()); + message.setPort(apiCommonDevice.getPort()); + + message.setBegin(ServerUtils.MSG_BEGIN); + + // 璋冩暣淇℃伅 + buildInfo(message, device,apiCommonDevice); + + message.setEnd(ServerUtils.MSG_END); + + // 鐢熸垚鏁翠綋鍛戒护淇℃伅鍜孊Yte淇℃伅 + build(message); + + return message; + } + + public void buildInfo(SendMessage message, GatewayDevice device,ApiCommonDevice apiCommonDevice) { + MessageInfo info = new MessageInfo(); + info.setSign("0000"); + info.setIedId(apiCommonDevice.getId()); + info.setFunctionId(ServerUtils.FUNCTION_2101); + info.setRespCode("0000"); + info.setOrderId(ServerUtils.getOrderByDepotId(device.getDepotId())); + info.setUserData("0"); + info.setSign("0000"); + + Request2101 request2101 = new Request2101(); + request2101.setHouseId(device.getDepotIdSys()); + info.setContent(request2101); + + message.setInfo(info); + } + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/builder/ObjectCommandBuilder.java b/src/main/java/com/fzzy/protocol/fzzy/builder/ObjectCommandBuilder.java new file mode 100644 index 0000000..76f4d2e --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/builder/ObjectCommandBuilder.java @@ -0,0 +1,75 @@ +package com.fzzy.protocol.fzzy.builder; + + +import com.fzzy.protocol.fzzy.data.MessageInfo; +import com.fzzy.protocol.fzzy.data.ReMessage; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.server.ServerUtils; + +/** + * 绯荤粺鎺ュ彛 + */ +public class ObjectCommandBuilder extends CommandBuilder { + + private final static ObjectCommandBuilder instance = new ObjectCommandBuilder(); + + private ObjectCommandBuilder() { + } + + public static ObjectCommandBuilder getInstance() { + return instance; + } + + + public SendMessage buildMessage(ReMessage reMessage, String functionId, Object obj) { + + SendMessage message = new SendMessage(); + message.setIp(reMessage.getIp()); + message.setPort(reMessage.getPort()); + + message.setBegin(ServerUtils.MSG_BEGIN); + + // 璋冩暣淇℃伅 + buildInfo(message, reMessage, functionId, obj); + + + message.setEnd(ServerUtils.MSG_END); + + // 鐢熸垚鏁翠綋鍛戒护淇℃伅鍜孊Yte淇℃伅 + build(message); + + return message; + } + + public void buildInfo(SendMessage message, ReMessage reMessage, String functionId, Object object) { + MessageInfo info = new MessageInfo(); + info.setSign(reMessage.getCompanyId()); + info.setIedId(reMessage.getIedId()); + info.setFunctionId(functionId); + info.setRespCode("0000"); + info.setOrderId(reMessage.getOrderId()); + info.setUserData("0"); + info.setSign("0000"); + info.setContent(object); + + message.setInfo(info); + } + +// public void buildInfo(SendMessage message, GatewayDevice deviceSer, String functionId, Object object) { +// MessageInfo info = new MessageInfo(); +// info.setSign("0000"); +// info.setIedId(deviceSer.getId()); +// info.setFunctionId(functionId); +// info.setRespCode("0000"); +// info.setOrderId(deviceSer.getOrgId()); +// info.setUserData("0"); +// info.setSign("0000"); +// +// //灏佽娑堟秷鎭唴瀹� +// info.setContent(object); +// +// message.setInfo(info); +// } + + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/builder/SimpleCommandBuilder.java b/src/main/java/com/fzzy/protocol/fzzy/builder/SimpleCommandBuilder.java new file mode 100644 index 0000000..be665d8 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/builder/SimpleCommandBuilder.java @@ -0,0 +1,96 @@ +package com.fzzy.protocol.fzzy.builder; + + +import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.io.request.BaseRequest; +import com.fzzy.protocol.fzzy.data.MessageInfo; +import com.fzzy.protocol.fzzy.data.ReMessage; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.server.ServerUtils; + +/** + * 鏃犳秷鎭綋鐨勫懡浠ゅ皝瑁� + */ +public class SimpleCommandBuilder extends CommandBuilder { + + private final static SimpleCommandBuilder instance = new SimpleCommandBuilder(); + + private SimpleCommandBuilder() { + } + + public static SimpleCommandBuilder getInstance() { + return instance; + } + + public SendMessage buildMessage(ApiCommonDevice deviceSer, String functionId) { + + BaseRequest request = new BaseRequest(); + request.setSerId(deviceSer.getSn()); + request.setBizType("grain"); + request.setCompanyId("0000"); + request.setPort(deviceSer.getPort()); + request.setSerName(deviceSer.getId()); + request.setIp(deviceSer.getIp()); + + SendMessage message = new SendMessage(); + message.setIp(request.getIp()); + message.setPort(request.getPort()); + + message.setBegin(ServerUtils.MSG_BEGIN); + + // 璋冩暣淇℃伅 + buildInfo(message, request, functionId); + + + message.setEnd(ServerUtils.MSG_END); + + // 鐢熸垚鏁翠綋鍛戒护淇℃伅鍜孊Yte淇℃伅 + build(message); + + return message; + } + + public SendMessage buildMessage(ReMessage reMessage, String functionId) { + + BaseRequest request = new BaseRequest(); + request.setSerId(reMessage.getIedId()); + request.setBizType("grain"); + request.setCompanyId(reMessage.getCompanyId()); + request.setPort(reMessage.getPort()); + request.setIp(reMessage.getIp()); + + SendMessage message = new SendMessage(); + message.setIp(request.getIp()); + message.setPort(request.getPort()); + + message.setBegin(ServerUtils.MSG_BEGIN); + + // 璋冩暣淇℃伅 + buildInfo(message, request, functionId); + + + message.setEnd(ServerUtils.MSG_END); + + // 鐢熸垚鏁翠綋鍛戒护淇℃伅鍜孊Yte淇℃伅 + build(message); + + return message; + } + + public void buildInfo(SendMessage message, BaseRequest request, String functionId) { + MessageInfo info = new MessageInfo(); + info.setSign(request.getCompanyId()); + info.setIedId(request.getSerId()); + info.setFunctionId(functionId); + info.setRespCode("0000"); + info.setOrderId(request.getOrderId()); + info.setUserData("0"); + info.setSign("0000"); + info.setContent(null); + + message.setInfo(info); + } + + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/cmd/BaseRemoteImpl.java b/src/main/java/com/fzzy/protocol/fzzy/cmd/BaseRemoteImpl.java new file mode 100644 index 0000000..ae09963 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/cmd/BaseRemoteImpl.java @@ -0,0 +1,61 @@ +package com.fzzy.protocol.fzzy.cmd; + + +import com.fzzy.api.data.GatewayDeviceProtocol; +import com.fzzy.api.utils.ContextUtil; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.server.FzzyServerEngine; +import com.ld.io.api.InvokeResult; +import com.ld.io.api.IoSession; +import com.ld.io.api.IoSessionQuery; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + +@Slf4j +public class BaseRemoteImpl { + + /** + * 鍙戦�佸懡浠� + * + * @param ip + * @param port + * @param msg + * @return + */ + public InvokeResult send(String ip, int port, byte[] msg) { + IoSessionQuery sessionFactory = FzzyServerEngine.ioServer.getSessionQuery(); + List<IoSession> sessions = sessionFactory.getAllSession(); + IoSession session = null; + for (IoSession ioSession : sessions) { + if (ContextUtil.getServerKey(ip, port).equals( + ioSession.getBusinessKey())) { + session = ioSession; + break; + } + } + if (null == session) { + return InvokeResult.CHANNEL_CLOSED; + } + return session.invoke(msg); + } + + public InvokeResult send(SendMessage message) { + log.debug("骞冲彴鍙戦�佹姤鏂�---->>鎺у埗鏌�--{}", message.toString()); + IoSessionQuery sessionFactory = FzzyServerEngine.ioServer.getSessionQuery(); + List<IoSession> sessions = sessionFactory.getAllSession(); + IoSession session = null; + for (IoSession ioSession : sessions) { + if (ContextUtil.getServerKey(message.getIp(), message.getPort()).equals( + ioSession.getBusinessKey())) { + session = ioSession; + break; + } + } + if (null == session) { + return InvokeResult.CHANNEL_CLOSED; + } + return session.invoke(message.getByteMsg()); + } + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/data/MessageInfo.java b/src/main/java/com/fzzy/protocol/fzzy/data/MessageInfo.java new file mode 100644 index 0000000..c65d02d --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/data/MessageInfo.java @@ -0,0 +1,28 @@ +package com.fzzy.protocol.fzzy.data; + +import lombok.Data; + +/** + * 淇℃伅鍐呭瀵规帴 + */ +@Data +public class MessageInfo { + + private String orgId;//缁勭粐缂栫爜锛屽凡缁忎簬2021骞�6鏈�15鏃ュ彇娑堜娇鐢� + + private String sn;//缃戝叧鍞竴鏍囪瘑 + + private String iedId;// 鍒嗘満ID锛屽彲鑳介噸澶� + + private String functionId;// 鍔熻兘缂栫爜 + + private String respCode;// 搴旂瓟缂栫爜 + + private String orderId;//璇锋眰缂栫爜 + + private String userData;//鑷畾涔夋暟鎹� + + private String sign;//绛惧悕绫诲瀷 + + private Object content;//淇℃伅浣� +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/fzzy/data/ReMessage.java b/src/main/java/com/fzzy/protocol/fzzy/data/ReMessage.java new file mode 100644 index 0000000..f44df57 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/data/ReMessage.java @@ -0,0 +1,59 @@ +package com.fzzy.protocol.fzzy.data; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 杩斿洖淇℃伅灏佽 + * + * @author Andy + */ +@Data +public class ReMessage implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private String companyId;//缁勭粐缂栫爜 + + private String begin; + + private String end; + + private String ip;//IP鍦板潃 + + private int port;//绔彛鍙� + + private Date receiveDate = new Date(); + + private String strMsg;// 褰撳墠鍛戒护杞崲涓哄瓧绗︿覆鐨勪俊鎭� + + private String sn;//搴忓垪鍙� + + private String iedId;// 鍒嗘満ID + + private String functionId;// 鍔熻兘缂栫爜 + + private String respCode;// 搴旂瓟缂栫爜 + + private String orderId;//璇锋眰缂栫爜 + + private String userData;//鑷畾涔夋暟鎹� + + private String sign;//绛惧悕绫诲瀷 + + private String content;//娑堟伅浣� + + @Override + public String toString() { + return "ReMessage [ip=" + ip + ", port=" + port + ", receiveDate=" + + receiveDate + ", strMsg=" + strMsg + ", sn=" + sn + + ", iedId=" + iedId + ", functionId=" + functionId + + ", respCode=" + respCode + ", orderId=" + orderId + + ", content=" + content + "]"; + } +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/data/SendMessage.java b/src/main/java/com/fzzy/protocol/fzzy/data/SendMessage.java new file mode 100644 index 0000000..92936ec --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/data/SendMessage.java @@ -0,0 +1,34 @@ +package com.fzzy.protocol.fzzy.data; + +import lombok.Data; + +/** + * 鍙戦�佷俊鎭皝瑁� + */ +@Data +public class SendMessage { + + private String begin; + + private String end; + + private String ip;//IP鍦板潃 + + private int port;//绔彛鍙� + + private String strMsg;// 褰撳墠鍛戒护杞崲涓哄瓧绗︿覆鐨勪俊鎭� + + private byte[] byteMsg;// 褰撳墠鍛戒护鐨勫瓧鑺備俊鎭� + + private MessageInfo info; + + + @Override + public String toString() { + return "SendMessage{" + + "ip='" + ip + '\'' + + ", port=" + port + + ", info=" + info + + '}'; + } +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/fzzy/package-info.java b/src/main/java/com/fzzy/protocol/fzzy/package-info.java new file mode 100644 index 0000000..87dc39f --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/package-info.java @@ -0,0 +1 @@ +package com.fzzy.protocol.fzzy; \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/fzzy/req/Request2101.java b/src/main/java/com/fzzy/protocol/fzzy/req/Request2101.java new file mode 100644 index 0000000..e2946b3 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/req/Request2101.java @@ -0,0 +1,10 @@ +package com.fzzy.protocol.fzzy.req; + +import lombok.Data; + +@Data +public class Request2101 { + + private String houseId; + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/resp/Response1001.java b/src/main/java/com/fzzy/protocol/fzzy/resp/Response1001.java new file mode 100644 index 0000000..feb8651 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/resp/Response1001.java @@ -0,0 +1,9 @@ +package com.fzzy.protocol.fzzy.resp; + +import lombok.Data; + +@Data +public class Response1001 { + + private String time; +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/resp/Response2102.java b/src/main/java/com/fzzy/protocol/fzzy/resp/Response2102.java new file mode 100644 index 0000000..6956d2f --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/resp/Response2102.java @@ -0,0 +1,48 @@ +package com.fzzy.protocol.fzzy.resp; + +import lombok.Data; + +/** + * 绮儏杩斿洖缁撴灉瀵硅薄 + */ +@Data +public class Response2102 { + + private String houseId; + + private Double tIn;//浠撳唴娓╁害锛涘鏈夋晠闅滃垯浼犳晠闅滅紪鐮侊紝鏁呴殰缂栫爜璇﹁闄勫綍浜屻�傚锛�-2000锛屼紶鎰熷櫒涓嶅湪绾裤�� + + private Double hIn;//浠撳唴婀垮害锛涘鏈夋晠闅滃垯浼犳晠闅滅紪鐮侊紝鏁呴殰缂栫爜璇﹁闄勫綍浜屻�傚锛�-2000锛屼紶鎰熷櫒涓嶅湪绾裤�� + + private Double tOut;//浠撳娓╁害锛涘鏈夋晠闅滃垯浼犳晠闅滅紪鐮侊紝鏁呴殰缂栫爜璇﹁闄勫綍浜屻�傚锛�-2000锛屼紶鎰熷櫒涓嶅湪绾裤�� + + private Double hOut;//浠撳婀垮害锛涘鏈夋晠闅滃垯浼犳晠闅滅紪鐮侊紝鏁呴殰缂栫爜璇﹁闄勫綍浜屻�傚锛�-2000锛屼紶鎰熷櫒涓嶅湪绾裤�� + + private String points;// 浠ヨ嫳鏂団��,鈥濋殧寮�鐨勭伯娓╃偣浣嶄俊鎭紱濡傛湁鏁呴殰鍒欎紶鏁呴殰缂栫爜锛屾晠闅滅紪鐮佽瑙侀檮褰曚簩銆傚锛�-1000锛屾晠闅滅偣銆� + + private Double tAvg; + + private Double tMax; + + private Double tMin; + + private String time;//yyyyMMddHHmmss + + private String row;//骞虫柟浠�-甯冪嚎瑙勫垯-琛岄厤缃� + + private String lay;//骞虫柟浠�-甯冪嚎瑙勫垯-灞傞厤缃� + + private String col;//骞充粨浠�-甯冪嚎瑙勫垯-鍒楅厤缃� + + private String layout;//绛掍粨-甯冪嚎瑙勫垯锛屽锛�3-6-9 琛ㄧず鍐呭湀3鏍癸紝涓棿6鏍癸紝澶栧湀9鏍� + + private String layerPerCircle;//绛掍粨-甯冪嚎瑙勫垯锛屽锛�9-9-9 琛ㄧず鍐呭湀9灞傦紝涓棿9灞傦紝澶栧湀9灞� + + private Double houseHeight;//娌圭綈浠�-寤虹瓚鐗╅珮搴︼紝鍗曚綅锛氱背 + + private Double liquidHeight;//娌圭綈浠�-娑蹭綅楂樺害锛屽崟浣嶏細绫� + + private String remark; + + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/server/FzzyServerEngine.java b/src/main/java/com/fzzy/protocol/fzzy/server/FzzyServerEngine.java new file mode 100644 index 0000000..a51ac92 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/server/FzzyServerEngine.java @@ -0,0 +1,77 @@ +package com.fzzy.protocol.fzzy.server; + +import com.ld.io.api.*; +import com.ld.io.netty.NettyServer; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + +/** + * 椋庢鑷磋繙-TCP涓绘湇鍔� + */ +@Slf4j +public class FzzyServerEngine { + + public static final int default_port = 9300; + + public static NettyServer ioServer = null; + + // 閰嶇疆娑堟伅鎺ユ敹绫� + private static MsgConsumer messageConsume = new MsgConsumer(); + // 鐩戝惉浼氳瘽鐨勫垱寤轰笌閿�姣� + private static SessionListener ioSessionListener = new SessionListener(); + + + public static void start(Integer port) throws InterruptedException { + + if (null == port) port = default_port; + + // 閰嶇疆Server鐨勯厤缃� + IoServerOption ioServerOption = new IoServerOption(port); + + ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL); + + ioServerOption.setDelimiter(ServerUtils.MSG_END.getBytes()); + + ioServer = new NettyServer(ioServerOption, messageConsume, ioSessionListener); + + ioServer.startup(); + + + log.info("* ========================"); + log.info("* "); + log.info("* FZZY-TCP-V3.0锛岀鍙e彿={}", port); + log.info("* "); + log.info("* ========================"); + + System.out.println("* ========================"); + System.out.println("* "); + System.out.println("* FZZY-TCP-V3.0锛岀鍙e彿=" + port); + System.out.println("* "); + System.out.println("* ========================"); + } + + /** + * 鍙戦�佷俊鎭� + * + * @param ip + * @param port + * @param msg + * @return + */ + public static InvokeResult push(String ip, int port, byte[] msg) { + IoSessionQuery sessionFactory = ioServer.getSessionQuery(); + List<IoSession> sessions = sessionFactory.getAllSession(); + IoSession session = null; + for (IoSession ioSession : sessions) { + if (ServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) { + session = ioSession; + break; + } + } + if (null == session) { + return InvokeResult.CHANNEL_CLOSED; + } + return session.invoke(msg); + } +} \ No newline at end of file diff --git a/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java b/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java new file mode 100644 index 0000000..7da3623 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java @@ -0,0 +1,61 @@ +package com.fzzy.protocol.fzzy.server; + +import com.alibaba.fastjson.JSON; +import com.fzzy.api.utils.SpringUtil; +import com.fzzy.protocol.fzzy.analysis.AnalysisService; +import com.fzzy.protocol.fzzy.data.ReMessage; +import com.ld.io.api.IoMsgConsumer; +import com.ld.io.api.IoSession; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +/** + * 鎺ユ敹缁堢杩斿洖鍥炴潵鐨勪俊鎭�� + * + * @author Andy + */ +@Slf4j +public class MsgConsumer implements IoMsgConsumer { + + private AnalysisService analysisService; + + private static final String CHARSET = "UTF-8"; + + @Override + public void consume(IoSession session, byte[] bytes) { + ReMessage reMessage = null; + try { + String message = new String(bytes, CHARSET); + + message = message.substring(ServerUtils.MSG_BEGIN.length()); + + reMessage = JSON.parseObject(message, ReMessage.class); + + + if (StringUtils.isEmpty(reMessage.getSn()) || + StringUtils.isEmpty(reMessage.getIedId()) || + StringUtils.isEmpty(reMessage.getFunctionId())) { + log.error("鎺у埗鏌�------>>>>骞冲彴锛氭姤鏂囦俊鎭笉瀹屾暣锛屼笉鍋氳В鏋�-IP={}锛宲ort={}锛宮sg={}", session.getAddress(), session.getPort(), message); + return; + } + reMessage.setIp(session.getAddress()); + reMessage.setPort(session.getPort()); + reMessage.setStrMsg(message); + session.setCompanyId("0000"); + + log.info("鎺у埗鏌�------>>>>骞冲彴锛欼P={}锛孭ORT={}锛宮essage={}", reMessage.getIp(), reMessage.getPort(), message); + + } catch (Exception e) { + log.error("鎺у埗鏌�------>>>>骞冲彴锛氭敹鍒版姤鏂囪В鏋愬紓甯革細{}", e.getMessage()); + e.printStackTrace(); + } + + //璋冪敤瑙f瀽鎺ュ彛寮�濮嬭В鏋� + if (null == analysisService) { + analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); + } + + analysisService.analysis(reMessage); + } + +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/server/ServerUtils.java b/src/main/java/com/fzzy/protocol/fzzy/server/ServerUtils.java new file mode 100644 index 0000000..b205f83 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/server/ServerUtils.java @@ -0,0 +1,219 @@ +package com.fzzy.protocol.fzzy.server; + +import com.fzzy.api.utils.ContextUtil; +import com.fzzy.gateway.data.BaseReqData; +import com.fzzy.gateway.data.BaseResp; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 宸ュ叿绫� + * + * @author Andy + */ +public class ServerUtils { + + private static Map<String, Integer> contextOrder = new HashMap<>(); + + /** + * 璇锋眰缂撳瓨 key = deviceId,value = requData + */ + private static Map<String, BaseReqData> contextSyncReqMap = new HashMap<>(); + + /** + * 灏嗘墽琛屽懡浠や俊鎭瓨鏀惧湪缂撳瓨 + * + * @param depotId 浠撳簱缂栫爜 + * @param reqData 璇锋眰鍙傛暟淇℃伅 + */ + public static void addSyncReq2Map(String depotId, BaseReqData reqData) { + contextSyncReqMap.put(depotId, reqData); + } + + public static BaseReqData getSyncReq(String depotId) { + return contextSyncReqMap.get(depotId); + } + + + public static final String MSG_BEGIN = "<FZZY>"; + public static final String MSG_END = "<END>"; + + //鍔熻兘鐮� + public static final String FUNCTION_1001 = "1001";// 鎺у埗鏌滆姹傜櫥褰曞钩鍙� + public static final String FUNCTION_1003 = "1003";// 骞冲彴鑾峰彇鎺у埗鏌滆澶囦俊鎭� + public static final String FUNCTION_1004 = "1004";// 鎺у埗鏌滃悜骞冲彴鎺ㄩ�佽鍛婇�氱煡 + public static final String FUNCTION_1005 = "1005";// 鎺у埗鏌滀富鍔ㄥ彂璧峰績璺� + public static final String FUNCTION_1006 = "1006";// 骞冲彴閫忎紶鏁版嵁 + public static final String FUNCTION_1007 = "1007";// 鎺у埗鏌滄帹閫佷粨鎴跨姸鎬� + public static final String FUNCTION_1008 = "1008";// 骞冲彴杩滅▼鏇存敼浠撴埧鐘舵�� + public static final String FUNCTION_1009 = "1009";// 骞冲彴杩滅▼鎺堟潈鎺у埗鏌� + public static final String FUNCTION_1010 = "1010";// 骞冲彴鑾峰彇鎺у埗鏌滀粨鎴夸俊鎭� + public static final String FUNCTION_2101 = "2101";// 骞冲彴鍙戣捣绮儏妫�娴嬭姹� + public static final String FUNCTION_2102 = "2102";// 鎺у埗鏌滀笂鎶ョ伯鎯呴噰闆嗙粨鏋� + public static final String FUNCTION_2201 = "2201";// 骞冲彴鍙戣捣妫�娴嬭姹� + public static final String FUNCTION_2202 = "2202";// 鎺у埗涓婃姤閫佹娴嬭繘搴� + public static final String FUNCTION_2203 = "2203";// 鎺у埗鏌滀笂鎶ユ娴嬬粨鏋� + public static final String FUNCTION_2204 = "2204";// 骞冲彴涓铏閲囬泦 + public static final String FUNCTION_2301 = "2301";// 骞冲彴鍙戣捣妫�娴嬭姹� + public static final String FUNCTION_2302 = "2302";// 鎺у埗鏌滀笂鎶ユ娴嬭繘搴� + public static final String FUNCTION_2303 = "2303";// 鎺у埗鏌滀笂鎶ユ娴嬬粨鏋� + public static final String FUNCTION_2304 = "2304";// 骞冲彴涓姘斾綋閲囬泦 + public static final String FUNCTION_3101 = "3101";// 骞冲彴杩滅▼鎿嶄綔璁惧 + public static final String FUNCTION_3102 = "3102";// 骞冲彴鑾峰彇缁堢璁惧鐘舵�� + public static final String FUNCTION_3103 = "3103";// 骞冲彴绱ф�ュ叏鍏崇粓绔澶� + public static final String FUNCTION_3201 = "3201";// 骞冲彴鍙戣捣鑷姩閫氶 + public static final String FUNCTION_3301 = "3301";// 骞冲彴鍙戣捣鑷姩姘旇皟 + public static final String FUNCTION_3302 = "3302";// 骞冲彴杩滅▼鎿嶆帶鍒舵爱鏈� + public static final String FUNCTION_3303 = "3303";// 骞冲彴鑾峰彇鍒舵爱鏈虹姸鎬� + public static final String FUNCTION_3304 = "3304";// 骞冲彴鑾峰彇浠撳唴姘斿帇 + public static final String FUNCTION_4001 = "4001";// 骞冲彴鍙戣捣鑳借�楃洃娴嬭姹� + public static final String FUNCTION_5001 = "5001";// 骞冲彴杩滅▼鎿嶄綔绌鸿皟 + public static final String FUNCTION_5002 = "5002";// 骞冲彴鑾峰彇绌鸿皟鐘舵�� + public static final String FUNCTION_6001 = "6001";// + + + //鍝嶅簲鐮� + public static String RESP_0000 = "0000";// 琛ㄧず鎵ц鎴愬姛 + public static String RESP_1000 = "1000";// 鎺у埗鏌滅紪鍙烽敊璇� + public static String RESP_1001 = "1001";// 缁堢璁惧涓嶅湪绾� + public static String RESP_1010 = "1010";// 鎺у埗鏌滄巿鏉冨埌鏈� + public static String RESP_1011 = "1011";// 鎺堟潈鐮佹棤鏁� + public static String RESP_1012 = "1012";// 鎺堟潈鐮佸凡琚娇鐢� + public static String RESP_1013 = "1013";// 鎺堟潈鐮佸凡杩囨湡 + public static String RESP_2000 = "2000";// 绛惧悕楠岃瘉澶辫触 + public static String RESP_3000 = "3000";// 閫氶妯″紡涓嶆敮鎸� + public static String RESP_4000 = "4000";// 姘旇皟妯″紡涓嶆敮鎸� + public static String RESP_5000 = "5000";// 鎺у埗鏌滃綋鍓嶄负鎵嬪姩妯″紡锛屾嫆缁濊繙绋嬫搷浣� + public static String RESP_6000 = "6000";// 閲囬泦鎵ц澶辫触 + public static String RESP_6001 = "6001";// 绮儏閲囬泦鎵ц涓� + public static String RESP_6002 = "6002";// 姘斾綋閲囬泦鎵ц涓� + public static String RESP_6003 = "6003";// 铏閲囬泦鎵ц涓� + public static String RESP_9999 = "9999";// 鏈煡閿欒 + + //浠撳簱鐘舵�� + static String DEPOT_STATUS_1001 = "1001";//閫氶 + static String DEPOT_STATUS_2001 = "2001";//姘旇皟 + static String DEPOT_STATUS_3001 = "3001";//鐔忚捀 + static String DEPOT_STATUS_4001 = "4001";//娓╂帶 + static String DEPOT_STATUS_5001 = "5001";//缁翠慨 + static String DEPOT_STATUS_6001 = "6001";//鍑哄簱 + static String DEPOT_STATUS_7001 = "7001";//鍏ュ簱 + static String DEPOT_STATUS_8001 = "8001";//婊′粨 + static String DEPOT_STATUS_9001 = "9001";//绌轰粨 + + //璁惧绫诲瀷 + public static String DEVICE_TYPE_1 = "1";// 椋庣獥 + public static String DEVICE_TYPE_2 = "2";// 椋庡彛 + public static String DEVICE_TYPE_3 = "3";// 杞存祦椋庢満 + public static String DEVICE_TYPE_4 = "4";// 娣锋祦椋庢満 + public static String DEVICE_TYPE_5 = "5";// 鐜祦椋庢満 + public static String DEVICE_TYPE_6 = "6";// 绂诲績椋庢満 + public static String DEVICE_TYPE_7 = "7";//鍔犲帇椋庢満 + public static String DEVICE_TYPE_8 = "8";// 鐢靛姩铦堕榾 + public static String DEVICE_TYPE_9 = "9";// 鐓ф槑 + public static String DEVICE_TYPE_10 = "10";//闂ㄧ + public static String DEVICE_TYPE_11 = "11";// 绌鸿皟 + public static String DEVICE_TYPE_12 = "12";// 瑙嗛 + + + //璁惧鐘舵�� + public static String DEVICE_STATUS_01 = "1";// " 寮�(椋庢満姝h浆) 01 + public static String DEVICE_STATUS_02 = "2";// 鍏� 02 + public static String DEVICE_STATUS_03 = "3";// 椋庢満鍙嶈浆 03 + public static String DEVICE_STATUS_04 = "4";// 寮�鎵ц涓� 04 + public static String DEVICE_STATUS_05 = "5";// 鍏虫墽琛屼腑 05 + public static String DEVICE_STATUS_06 = "6";// 鏃犳搷浣� 06 + public static String DEVICE_STATUS_07 = "7";// 鏈煡鐘舵�� 07 + + //绌鸿皟妯″紡 + public static String TEMP_MODE_10 = "10";//閫氶 + public static String TEMP_MODE_11 = "11";//鍒跺喎 + public static String TEMP_MODE_20 = "20";//椋庨�熶綆 + public static String TEMP_MODE_21 = "21";//椋庨�熶腑 + public static String TEMP_MODE_22 = "22";//椋庨�熼珮 + + //鑷姩姘旇皟妯″紡 + public static String AUTO_N2_10 = "10";//鎶借礋鍘� 10 + public static String AUTO_N2_20 = "20";//姘斿瘑鎬ф娴� 20 + public static String AUTO_N2_30 = "30";//姝e父鍏呮爱 30 + public static String AUTO_N2_31 = "31";//鍔犲帇鍏呮爱 31 + public static String AUTO_N2_40 = "40";//鍧囨爱 40 + public static String AUTO_N2_50 = "50";//姘皵鍥炴敹 50 + + + //鑷姩閫氶妯″紡 + public static String AUTO_AIR_10 = "10";// 鎺掔Н鐑�氶 10 + public static String AUTO_AIR_20 = "20";//鑷劧閫氶 20 + public static String AUTO_AIR_30 = "30";//淇濇按闄嶆俯閫氶 30 + public static String AUTO_AIR_40 = "40";//闄ゆ箍閫氶 40 + public static String AUTO_AIR_50 = "50";//鐢ㄦ埛妯″紡閫氶 50 + + + //浠撳簱绫诲瀷 + public static String HOUSE_TYPE_1 = "1";// 骞虫埧浠� + public static String HOUSE_TYPE_2 = "2";//娴呭渾浠� + public static String HOUSE_TYPE_3 = "3";//娌圭綈浠� + public static String HOUSE_TYPE_4 = "4";//绔嬬瓛浠� + public static String HOUSE_TYPE_99 = "99";//鍏朵粬 + + + //璁惧浣嶇疆 + public static String DEVICE_L0 = "0";// 骞虫埧浠�-浠撴闈� + public static String DEVICE_L1 = "1";// 骞虫埧浠�-浠撹儗闈� + public static String DEVICE_L2 = "2";// 绛掍粨-椤堕儴 + public static String DEVICE_L3 = "3";// 绛掍粨-搴曢儴 + + + /** + * 鐢熸垚TCP杩炴帴鐨凨EY + * + * @param ip + * @param port + * @return + */ + public static String getServerKey(String ip, Integer port) { + return ip + ":" + port; + } + + + /** + * 鏍规嵁鎿嶄綔妯″紡锛岃繑鍥炵┖璋冩ā寮� + * + * @param mode + * @return + */ + public static String getTempMode(String mode) { + if (mode.equals("01")) { + return TEMP_MODE_11; + } + if (mode.equals("02")) { + return TEMP_MODE_10; + } + return TEMP_MODE_11; + } + + public static String getOrderByDepotId(String depotId) { + if (null == depotId) { + Integer integer = contextOrder.get("ORDER"); + if (null == integer) integer = 1000; + integer = integer + 1; + contextOrder.put("ORDER", integer); + return integer + ""; + } + + //鍙鏁板瓧 + String regEx = "[^0-9]"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(depotId); + String regDepotId = m.replaceAll("").trim(); + + if (regDepotId.length() > 4) { + regDepotId = regDepotId.substring(regDepotId.length() - 4); + } + + return Integer.valueOf(regDepotId)+""; + } +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java b/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java new file mode 100644 index 0000000..7c30842 --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java @@ -0,0 +1,24 @@ +package com.fzzy.protocol.fzzy.server; + +import com.ld.io.api.IoSession; +import com.ld.io.api.IoSessionListener; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SessionListener implements IoSessionListener { + + @Override + public void onCreate(IoSession session) { + + log.info("++++FZZY-鎺у埗鏌滀笂绾�++++-IP={}锛孭ORT={}", session.getAddress(), session.getPort()); + + // 娣诲姞鑷畾涔変笟鍔D + session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort())); + + } + + @Override + public void onDestroy(IoSession session) { + log.info("----FZZY-鎺у埗鏌滅绾�-----IP={}锛孭ORT={}", session.getAddress(), session.getPort()); + } +} diff --git a/src/main/java/com/fzzy/protocol/fzzy/service/FzzyGatewayGrainService.java b/src/main/java/com/fzzy/protocol/fzzy/service/FzzyGatewayGrainService.java new file mode 100644 index 0000000..8b96cef --- /dev/null +++ b/src/main/java/com/fzzy/protocol/fzzy/service/FzzyGatewayGrainService.java @@ -0,0 +1,87 @@ +package com.fzzy.protocol.fzzy.service; + +import com.fzzy.api.Constant; +import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.api.data.GatewayDeviceProtocol; +import com.fzzy.gateway.api.GatewaySyncGranService; +import com.fzzy.gateway.data.BaseReqData; +import com.fzzy.gateway.data.BaseResp; +import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.protocol.fzzy.builder.GrainCommandBuilder; +import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl; +import com.fzzy.protocol.fzzy.data.SendMessage; +import com.fzzy.protocol.fzzy.server.ServerUtils; +import com.ld.io.api.InvokeResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 椋庢鑷磋繙鎺у埗鏌滃崗璁� + */ +@Slf4j +@Component +public class FzzyGatewayGrainService extends BaseRemoteImpl implements GatewaySyncGranService { + + @Override + public String getGrainProtocol() { + return GatewayDeviceProtocol.TCP_FZZY_V3.getCode(); + } + + @Override + public BaseResp syncGrain(BaseReqData reqData) { + + BaseResp resp = new BaseResp(); + + GatewayDevice device = reqData.getDevice(); + + //鑾峰彇杩炴帴涓殑璁惧淇℃伅 + ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCache(device.getDeviceSn()); + + if (null == apiCommonDevice) { + resp.setCode(500); + resp.setMsg("绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅锛屾棤娉曟墽琛�"); + log.error("----------------绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅,鏃犳硶鎵ц---------"); + return resp; + } + + if (Constant.YN_N.equals(apiCommonDevice.getStatus())) { + resp.setCode(500); + resp.setMsg("涓嬭璁惧涓嶅湪绾�---鏃犳硶鎵ц----" + device.getDeviceName()); + log.error("涓嬭璁惧涓嶅湪绾�---鏃犳硶鎵ц----" + device.getDeviceName()); + return resp; + } + + device.setIp(apiCommonDevice.getIp()); + device.setPort(apiCommonDevice.getPort()); + + reqData.setDevice(device); + + + try { + + //Step 璇锋眰淇℃伅鏀惧叆鍐呭瓨 + ServerUtils.addSyncReq2Map(device.getDepotId(), reqData); + + // Step1 鐢熸垚绮儏淇℃伅 + SendMessage message = GrainCommandBuilder.getInstance().buildMessage(device,apiCommonDevice); + // 鍙戦�佸懡浠� + InvokeResult result = send(device.getIp(), device.getPort(), message.getByteMsg()); + + log.error("骞冲彴------>>>>鎺у埗鏌滐細绮儏妫�娴�-{}", message); + + // 灏佽杩斿洖淇℃伅 + if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { + log.error("骞冲彴------>>>>鎺у埗鏌滐細绮儏妫�娴�-澶辫触{}", result.getMessage()); + resp.setCode(500); + resp.setMsg("骞冲彴------>>>>鎺у埗鏌滐細绮儏妫�娴�-澶辫触锛�" + result.getMessage()); + } + + } catch (Exception e) { + log.error("绮儏妫�娴嬪紓甯革細{}", e); + resp.setCode(500); + resp.setMsg("绮儏妫�娴嬪紓甯革細" + e.getMessage()); + return resp; + } + return resp; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5f05f63..fc4387b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,7 @@ ########################## Server ########################## spring: profiles: - active: proGateway + active: devGateway application: name: igds-api main: @@ -29,15 +29,16 @@ encoding: UTF-8 cache: false +#License 閰嶇疆绀轰緥 +license: + subject: ld_license + publicAlias: publicCert + storePass: PUBLICFZZYXXJSGFYXGS888888 + licensePath: D:/AppData/license/license.lic + publicKeysStorePath: D:/AppData/license/publicCerts.keystore igds: default: companyId: 5326 file-path: C:/app/igds-api img-path: D:/IGDS/FILE/ -license: - subject: ld_license - publicAlias: publicCert - storePass: PUBLICFZZYXXJSGFYXGS888888 - licensePath: D:/IGDS/license/license.lic - publicKeysStorePath: D:/IGDS/license/publicCerts.keystore -- Gitblit v1.9.3