| | |
| | | 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"; |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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;//ç»æä¿¡æ¯ï¼ä»¥åç¬¦ä¸²ä»£æ¿ |
| | | |
| | | } |
| | |
| | | */ |
| | | public enum GatewayDeviceProtocol { |
| | | |
| | | GRAIN_FZZY_ZH_2023("GRAIN_FZZY_ZH_2023", "ç²®æ
-飿£è´è¿æ§å¶æåè®®2023"), |
| | | TCP_FZZY_V3("TCP_FZZY_V3", "ç²®æ
-飿£è´è¿æ§å¶æåè®®V3"), |
| | | GRAIN_FZZY_IGDS_V40("GRAIN_FZZY_IGDS_V40", "ç²®æ
-飿£è´è¿ç³»ç»V40"), |
| | | DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "å°ç£
-HTTPåè®®"), |
| | | DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "å°ç£
-èåTCPåè®®"), |
| | |
| | | |
| | | 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())); |
| | |
| | | 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() { |
| | |
| | | public static String getServerKey(String ip, Integer port) { |
| | | return ip + ":" + port; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ ¹æ®åæ°çæ æ§è¡å½ä»¤çç¼åKEY |
| | | * |
| | | * @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; |
| | | } |
| | | } |
| | |
| | | @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";//æé½ |
| | |
| | | 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.*; |
| | |
| | | */ |
| | | @Component |
| | | public class GatewayUtils { |
| | | |
| | | |
| | | /** |
| | | * 设å¤å¨çº¿æ è®°ï¼é对WEBSocket请æ±ï¼æ§å¶è®¾å¤æ¯å¦å¨çº¿ï¼key = deviceIdï¼Value=Y/N |
| | | */ |
| | | public static Map<String, String> contextOnlineMap = new HashMap<>(); |
| | | |
| | | |
| | | /** |
| | | * 设å¤ç¼å |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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()); |
| | |
| | | |
| | | 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; |
| | | |
| | | /** |
| | | * ç½å
³ç¸å
³ç设å¤ç®¡ç |
| | |
| | | @PropertyDef(label = "çä»å±è§å", description = "é对çä»") |
| | | private String cableCir; |
| | | |
| | | @Transient |
| | | @PropertyDef(label = "设å¤å¨çº¿ç¶æ") |
| | | private String status = Constant.YN_N; |
| | | |
| | | @Transient |
| | | @PropertyDef(label = "设å¤ä¸çº¿æ¶é´") |
| | | private Date onlineTime; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.io; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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;//èªå®ä¹å½ä»¤ID |
| | | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | @Override |
| | | public void run(String... args) throws Exception { |
| | | |
| | | |
| | | //èåå°ç£
TCPåè®® |
| | | YhScaleServerEngine.start(); |
| | | |
| | | |
| | | //飿£è´è¿æ§å¶æåè®®å¯å¨ |
| | | FzzyServerEngine.start(null); |
| | | |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * ç²®æ
è§£æ |
| | | * |
| | | * @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 |
| | | } |
| | | |
| | | /** |
| | | * ç²®æ
è¿åä¿¡æ¯è§£æ |
| | | * |
| | | * @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); |
| | | |
| | | |
| | | //ç²®æ
è§£æ |
| | | 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); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | |
| | | |
| | | /** |
| | | * åè®®è§£ææ»å
¥å£ |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisService.BEAN_ID) |
| | | public class AnalysisService { |
| | | |
| | | public static final String BEAN_ID = "fzzy.analysisService"; |
| | | |
| | | @Resource |
| | | private AnalysisSystem analysisSystem; |
| | | @Resource |
| | | private AnalysisGrain analysisGrain; |
| | | |
| | | /** |
| | | * å议解æå
¥å£ |
| | | * |
| | | * @param message è¿åä¿¡æ¯ |
| | | */ |
| | | public void analysis(ReMessage message) { |
| | | try { |
| | | if (null == message) return; |
| | | |
| | | //ç»å½è§£æ |
| | | if (ServerUtils.FUNCTION_1001.equals(message.getFunctionId())) { |
| | | analysisSystem.analysis1001(message); |
| | | return; |
| | | } |
| | | |
| | | String checkMsg = checkMsg(message); |
| | | if (null != checkMsg) { |
| | | log.error("æ§å¶æ------>>>å¹³å°ï¼å½åç»ç»ç¼ç ={}ï¼åæºID={}ï¼æ¥æä¿¡æ¯-={}ï¼ååºåè¿å䏿£ç¡®ï¼æ æ³è¿è¡è§£æ," + checkMsg, message.getCompanyId(), message.getIedId(), message.getStrMsg()); |
| | | return; |
| | | } |
| | | |
| | | |
| | | //æ§è¡çåæºä¿¡æ¯ |
| | | ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getSn()); |
| | | if (null == commonDevice) { |
| | | log.warn("æ§å¶æ------>>>å¹³å°ï¼å½åç»ç»ç¼ç ={}ï¼åæºID={}ï¼ç³»ç»æ²¡æè·åå°åæºä¿¡æ¯ï¼æ¥ææ æ³è¿è¡è§£æ", message.getCompanyId(), message.getIedId()); |
| | | return; |
| | | } |
| | | |
| | | |
| | | //æ ¹æ®æ¥å£ç¼å·è¿è¡è§£æè·¯ç± |
| | | 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; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | 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()); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | 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); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | 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); |
| | | // } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | 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); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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()); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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;//ä¿¡æ¯ä½ |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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 + "]"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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 + |
| | | '}'; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.fzzy; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.fzzy.req; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class Request2101 { |
| | | |
| | | private String houseId; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.fzzy.resp; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class Response1001 { |
| | | |
| | | private String time; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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ï¼ç«¯å£å·={}", port); |
| | | log.info("* "); |
| | | log.info("* ========================"); |
| | | |
| | | System.out.println("* ========================"); |
| | | System.out.println("* "); |
| | | System.out.println("* FZZY-TCP-V3.0ï¼ç«¯å£å·=" + 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); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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={}ï¼port={}ï¼msg={}", session.getAddress(), session.getPort(), message); |
| | | return; |
| | | } |
| | | reMessage.setIp(session.getAddress()); |
| | | reMessage.setPort(session.getPort()); |
| | | reMessage.setStrMsg(message); |
| | | session.setCompanyId("0000"); |
| | | |
| | | log.info("æ§å¶æ------>>>>å¹³å°ï¼IP={}ï¼PORT={}ï¼message={}", reMessage.getIp(), reMessage.getPort(), message); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("æ§å¶æ------>>>>å¹³å°ï¼æ¶å°æ¥æè§£æå¼å¸¸ï¼{}", e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | //è°ç¨è§£ææ¥å£å¼å§è§£æ |
| | | if (null == analysisService) { |
| | | analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); |
| | | } |
| | | |
| | | analysisService.analysis(reMessage); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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";// " å¼(飿ºæ£è½¬) 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";//æ£å¸¸å
æ°® 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è¿æ¥çKEY |
| | | * |
| | | * @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)+""; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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={}ï¼PORT={}", session.getAddress(), session.getPort()); |
| | | |
| | | // æ·»å èªå®ä¹ä¸å¡ID |
| | | session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onDestroy(IoSession session) { |
| | | log.info("----FZZY-æ§å¶æç¦»çº¿-----IP={}ï¼PORT={}", session.getAddress(), session.getPort()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | ########################## Server ########################## |
| | | spring: |
| | | profiles: |
| | | active: proGateway |
| | | active: devGateway |
| | | application: |
| | | name: igds-api |
| | | main: |
| | |
| | | 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 |