已重命名1个文件
已修改7个文件
已添加30个文件
| | |
| | | |
| | | // è·ååæºä¿¡æ¯ |
| | | DeviceSer deviceSer = coreSerService.getCacheSer(param.getCompanyId(), |
| | | depotConf.getGrainSer()); |
| | | depotConf.getGasSer()); |
| | | |
| | | CheckGasRequest request = new CheckGasRequest(); |
| | | request.setDepotId(param.getDepotId()); |
| | |
| | | TCP_FZZY_QUANTITY_V35("TCP_FZZY_QUANTITY_V35", "æ°éæ£æµV35"), |
| | | TCP_BHZH_GRAIN_FM_V1("TCP_BHZH_GRAIN_FM_V1", "馿µ·æºè½æ 线主æºçV1"), |
| | | TCP_BHZH_GRAIN_V2("TCP_BHZH_GRAIN_V2", "馿µ·æºè½æçº¿çV2"), |
| | | TCP_BHZH_VERB_V2("TCP_BHZH_VERB_V2", "馿µ·æ§å¶ææºè½æçº¿çV2"), |
| | | FZZY_OPENAPI_HTTP("FZZY_OPENAPI_HTTP", "飿£è´è¿API-HTTPåè®®"); |
| | | private String code; |
| | | private String msg; |
| | |
| | | @PropertyDef(label = "è½èåæº") |
| | | private String esSer; |
| | | |
| | | @Column(name = "GAS_SER_", length = 40) |
| | | @PropertyDef(label = "æ°ä½åæº") |
| | | private String gasSer; |
| | | |
| | | @Column(name = "GRAIN_FREQ_", length = 4) |
| | | @PropertyDef(label = "ç²®æ
ä¿åé¢ç", description = "é»è®¤ä¸å¤©å¤æ¬¡") |
| | | private String grainFreq = GrainFrequence.FREQ_01.getCode(); |
| | |
| | | <Property name="labelSeparator">ï¼</Property> |
| | | <Property name="labelWidth">120</Property> |
| | | <AutoFormElement> |
| | | <Property name="name">gasSer</Property> |
| | | <Property name="property">gasSer</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">gasStart</Property> |
| | | <Property name="property">gasStart</Property> |
| | | <Editor/> |
| | |
| | | <Property name="valueProperty">name</Property> |
| | | </Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gasSer"> |
| | | <Property/> |
| | | <Property name="label">æ°ä½åæº</Property> |
| | | </PropertyDef> |
| | | </DataType> |
| | | <DataType name="dtDicSlogan"> |
| | | <Property name="creationType">com.ld.igds.models.DicSlogan</Property> |
ÎļþÃû´Ó igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv2/ServerRunner.java ÐÞ¸Ä |
| | |
| | | package com.ld.igds.protocol.bhzn.grainv2; |
| | | package com.ld.igds.protocol.bhzn; |
| | | |
| | | import com.ld.igds.data.ConfigData; |
| | | import com.ld.igds.protocol.bhzn.grainv2.server.BhznGrainV2ServerEngine; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerEngine; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.core.annotation.Order; |
| | |
| | | private ConfigData configData; |
| | | @Autowired |
| | | private BhznGrainV2ServerEngine bhznGrainServerEngine; |
| | | |
| | | @Autowired |
| | | private BhznVerbServerEngine bhznVerbServerEngine; |
| | | @Override |
| | | public void run(String... strings) throws Exception { |
| | | |
| | | if (configData.getActive().indexOf("pro") >= 0) { |
| | | bhznGrainServerEngine.start(BhznGrainV2ServerEngine.PORT); |
| | | bhznVerbServerEngine.start(BhznVerbServerEngine.PORT); |
| | | } |
| | | if (configData.getActive().indexOf("dev") >= 0) { |
| | | bhznGrainServerEngine.start(BhznGrainV2ServerEngine.PORT); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.analysis; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ld.igds.common.CoreDeviceService; |
| | | import com.ld.igds.constant.DeviceStatus; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.io.request.ExeDevice; |
| | | import com.ld.igds.models.Device; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.protocol.bhzn.verb.command.BaseRemoteImpl; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Res247; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | import com.ld.igds.temp.dto.TempParam; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | /** |
| | | * è®¾å¤æä½ç±» |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisDevice.BEAN_ID) |
| | | public class AnalysisDevice extends BaseRemoteImpl { |
| | | |
| | | public static final String BEAN_ID = "bhzn.analysisDevice"; |
| | | |
| | | @Autowired |
| | | private CoreDeviceService deviceService; |
| | | @Autowired |
| | | private NotifyWebInvoker notifyInvoker; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 设å¤ç¶æ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis(IoMessage reMessage, DeviceSer ser) { |
| | | Res247 res247 = JSONObject.parseObject(reMessage.getContentStr(),Res247.class); |
| | | AnalysisWin(ser,res247.getWin_Str()); |
| | | AnalysisFan(ser,res247.getFan_Str()); |
| | | AnalysisAir(ser,res247.getAir_Str()); |
| | | AnalysisLight(ser,res247.getLight_Str()); |
| | | // BhznVerbServerUtils.add2StatusMap(ser.getCompanyId(), ser.getId(),0, ""); |
| | | // } |
| | | deviceService.updateStatus(ser.getCompanyId(), ser.getId(), BhznVerbServerUtils.getStatusMap()); |
| | | // |
| | | // notifyInvoker.notifyAnalysisStatusSuccess(ser.getCompanyId(), ser.getId(), OrderRespEnum.MSG_SUCCESS, "设å¤ç¶ææ¥è¯¢æåå¹¶å®æè§£æï¼"); |
| | | } |
| | | |
| | | /** |
| | | * è§£æçªæ·ç¶æ |
| | | * @param ser |
| | | * @param winStr |
| | | */ |
| | | private void AnalysisWin(DeviceSer ser,Integer[] winStr){ |
| | | if(winStr == null || winStr.length == 0)return; |
| | | for (int i=1;i<= winStr.length;i++) { |
| | | BhznVerbServerUtils.add2StatusMap(ser.getCompanyId(), ser.getId(),i, getWinStatus(winStr[i-1])); |
| | | } |
| | | } |
| | | /** |
| | | * è§£æé£æºç¶æ |
| | | * @param ser |
| | | * @param fanStr |
| | | */ |
| | | private void AnalysisFan(DeviceSer ser,Integer[] fanStr){ |
| | | if(fanStr == null || fanStr.length == 0)return; |
| | | for (int i=1;i<= fanStr.length;i++) { |
| | | BhznVerbServerUtils.add2StatusMap(ser.getCompanyId(), ser.getId(),i+20, getFanStatus(fanStr[i-1])); |
| | | } |
| | | } |
| | | /** |
| | | * è§£æç©ºè°ç¶æ |
| | | * @param ser |
| | | * @param airStr |
| | | */ |
| | | private void AnalysisAir(DeviceSer ser,Integer[] airStr){ |
| | | if(airStr == null || airStr.length == 0)return; |
| | | Integer s= 0; |
| | | for (int i=1;i<= airStr.length;i++) { |
| | | List<Device> devices = deviceService.getCacheDeviceBySerId(ser.getCompanyId(),ser.getId()); |
| | | // è°æ´ç¼å |
| | | if (null == devices || devices.isEmpty()) |
| | | return; |
| | | // æ´æ°ç¼å |
| | | Device temp; |
| | | s = airStr[i-1]; |
| | | for (int j = 0; j < devices.size(); j++) { |
| | | if(i == (devices.get(j).getPassCode() - 40)){ |
| | | // 4608 -12 00 |
| | | String hexStr = BytesUtil.intToHexStr(s); |
| | | for (int k =0;k<4;k++){ |
| | | if(hexStr.length() < 16){ |
| | | hexStr = "0" + hexStr; |
| | | } |
| | | } |
| | | // 12 |
| | | String l = hexStr.substring(0,2); |
| | | //00 |
| | | String h = hexStr.substring(2,4); |
| | | String hb = BytesUtil.toBinary8String(BytesUtil.hexToInt(h)); |
| | | //00000000 0000 0 000 |
| | | Integer status = Integer.parseInt(hb.substring(4,5)); |
| | | Integer t = BytesUtil.hexToInt(l); |
| | | BhznVerbServerUtils.add2StatusMap(ser.getCompanyId(), ser.getId(), devices.get(j).getId(), getLightStatus(status)); |
| | | TempParam param = new TempParam(); |
| | | param.setId( devices.get(j).getId()); |
| | | param.setTargetTemp(t+""); |
| | | param.setTargetStatus(getLightStatus(status)); |
| | | param.setTargetModel("01"); |
| | | List<ExeDevice> exeDeviceList = new ArrayList<>(); |
| | | ExeDevice dev = new ExeDevice(); |
| | | dev.setSerId(ser.getId()); |
| | | exeDeviceList.add(dev); |
| | | param.setDeviceList(exeDeviceList); |
| | | param.setCompanyId(ser.getCompanyId()); |
| | | deviceService.updateTempControlInfo(param); |
| | | |
| | | log.info("空è°ç¶æè§£æå®æï¼"+param.toString()); |
| | | //BhznVerbServerUtils.add2StatusMap(ser.getCompanyId(), ser.getId(),i+40, getWinStatus(airStr[i])); |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * è§£æç
§æç¶æ |
| | | * @param ser |
| | | * @param lightStr |
| | | */ |
| | | private void AnalysisLight(DeviceSer ser,Integer[] lightStr){ |
| | | if(lightStr == null || lightStr.length == 0)return; |
| | | for (int i=1;i<= lightStr.length;i++) { |
| | | BhznVerbServerUtils.add2StatusMap(ser.getCompanyId(), ser.getId(),i+60, getLightStatus(lightStr[i-1])); |
| | | } |
| | | } |
| | | |
| | | private String getWinStatus(Integer s){ |
| | | if(s == null)return DeviceStatus.ZERO.getCode(); |
| | | String hexStr = BytesUtil.intToHexStr(s); |
| | | for (int i =0;i<4;i++){ |
| | | if(hexStr.length() < 4){ |
| | | hexStr = "0" + hexStr; |
| | | } |
| | | } |
| | | String h = hexStr.substring(0,2); |
| | | String l = hexStr.substring(2,4); |
| | | h = BytesUtil.toBinary8String(BytesUtil.hexToInt(h)); |
| | | int kaidu = (BytesUtil.hexToInt(l)); |
| | | String temp = h.substring(6,8); |
| | | if("00".equals(temp ) && kaidu == 100){ |
| | | return DeviceStatus.OPEN.getCode(); |
| | | } |
| | | if("00".equals(temp ) && kaidu == 0){ |
| | | return DeviceStatus.CLOSE.getCode(); |
| | | } |
| | | if("01".equals(temp )){ |
| | | return DeviceStatus.OPEN.getCode(); |
| | | } |
| | | if("10".equals(temp )){ |
| | | return DeviceStatus.CLOSE.getCode(); |
| | | } |
| | | |
| | | return DeviceStatus.ZERO.getCode(); |
| | | } |
| | | private String getFanStatus(Integer s){ |
| | | if(0 == s){ |
| | | return DeviceStatus.CLOSE.getCode(); |
| | | } |
| | | if(1 == s){ |
| | | return DeviceStatus.OPEN.getCode(); |
| | | } |
| | | return DeviceStatus.ZERO.getCode(); |
| | | } |
| | | |
| | | private String getLightStatus(Integer s){ |
| | | if(0 == s){ |
| | | return DeviceStatus.CLOSE.getCode(); |
| | | } |
| | | if(1 == s){ |
| | | return DeviceStatus.OPEN.getCode(); |
| | | } |
| | | return DeviceStatus.ZERO.getCode(); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.analysis; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ld.igds.common.CoreCommonService; |
| | | import com.ld.igds.common.CoreDeviceService; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.DeviceStatus; |
| | | import com.ld.igds.gas.CoreGasService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.io.request.ExeDevice; |
| | | import com.ld.igds.models.*; |
| | | import com.ld.igds.protocol.bhzn.verb.command.BaseRemoteImpl; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Res209; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Res247; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | import com.ld.igds.temp.dto.TempParam; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æ°ä½è§£æ |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisGas.BEAN_ID) |
| | | public class AnalysisGas extends BaseRemoteImpl { |
| | | |
| | | public static final String BEAN_ID = "bhzn.analysisGas"; |
| | | |
| | | @Autowired |
| | | private CoreDeviceService deviceService; |
| | | @Autowired |
| | | private NotifyWebInvoker notifyInvoker; |
| | | @Autowired |
| | | private CoreGasService gasService; |
| | | @Autowired |
| | | private CoreCommonService commonService; |
| | | |
| | | |
| | | /** |
| | | * 设å¤ç¶æ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis(IoMessage reMessage, DeviceSer ser) { |
| | | |
| | | log.info("æ°ä½æ£æµå¼å§è§£æ"); |
| | | Res209 res209 = JSONObject.parseObject(reMessage.getContentStr(),Res209.class); |
| | | |
| | | DepotConf depotConf = commonService.getCacheDepotConfBySerId(ser.getCompanyId(),ser.getId() ); |
| | | //主ä½ä¿¡æ¯ |
| | | Gas gas = new Gas(); |
| | | gas.setBatchId(ContextUtil.getDefaultBatchId()); |
| | | gas.setCheckNum(res209.getCO2ValArray().length); |
| | | gas.setCompanyId(ser.getCompanyId()); |
| | | gas.setDepotId(depotConf.getDepotId()); |
| | | gas.setGasEnd(depotConf.getPestEnd()); |
| | | gas.setGasStart(depotConf.getPestStart()); |
| | | gas.setReceiveDate(new Date()); |
| | | StringBuffer sb = new StringBuffer(); |
| | | List<GasInfo> items = new ArrayList<>(); |
| | | GasInfo info; |
| | | Integer[] n2ValArray = res209.getN2ValArray(); |
| | | Integer[] pH3ValArray = res209.getPH3ValArray(); |
| | | Integer[] cO2ValArray = res209.getCO2ValArray(); |
| | | for (int i=0;i<res209.getCO2ValArray().length;i++){ |
| | | info = new GasInfo(); |
| | | info.setId(ContextUtil.buildInfoId(gas.getCompanyId(), gas.getDepotId(), gas.getBatchId())); |
| | | info.setPassCode(i+1); |
| | | info.setPerCo2(cO2ValArray[i].doubleValue()); |
| | | info.setPerO2(99 - (n2ValArray[i].doubleValue() /10 )); |
| | | info.setPerPh3(pH3ValArray[i].doubleValue()); |
| | | info.setPerN2(n2ValArray[i].doubleValue() / 10); |
| | | items.add(info); |
| | | if(i == 0){ |
| | | //æ·»å æå¤§å¼åæå°å¼ |
| | | gas.setPerCo2Max(info.getPerCo2()); |
| | | gas.setPerCo2Min(info.getPerCo2()); |
| | | gas.setPerO2Max(info.getPerO2()); |
| | | gas.setPerO2Min(info.getPerO2()); |
| | | gas.setPerPh3Max(info.getPerPh3()); |
| | | gas.setPerPh3Min(info.getPerPh3()); |
| | | gas.setPerN2Max(info.getPerN2()); |
| | | gas.setPerN2Min(info.getPerN2()); |
| | | } |
| | | if (info.getPerCo2() > gas.getPerCo2Max()) { |
| | | gas.setPerCo2Max(info.getPerCo2()); |
| | | } |
| | | if (info.getPerCo2() < gas.getPerCo2Min()) { |
| | | gas.setPerCo2Min(info.getPerCo2()); |
| | | } |
| | | |
| | | if (info.getPerO2() > gas.getPerO2Max()) { |
| | | gas.setPerO2Max(info.getPerO2()); |
| | | } |
| | | |
| | | if (info.getPerO2() < gas.getPerO2Min()) { |
| | | gas.setPerO2Min(info.getPerO2()); |
| | | } |
| | | |
| | | if (info.getPerPh3() > gas.getPerPh3Max()) { |
| | | gas.setPerPh3Max(info.getPerPh3()); |
| | | } |
| | | |
| | | if (info.getPerPh3() < gas.getPerPh3Min()) { |
| | | gas.setPerPh3Min(info.getPerPh3()); |
| | | } |
| | | |
| | | if (info.getPerN2() > gas.getPerN2Max()) { |
| | | gas.setPerN2Max(info.getPerN2()); |
| | | } |
| | | |
| | | if (info.getPerN2() < gas.getPerN2Min()) { |
| | | gas.setPerN2Min(info.getPerN2()); |
| | | } |
| | | |
| | | //åºå®ä¸ºï¼passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;" |
| | | sb.append(info.getPassCode()); |
| | | sb.append(","); |
| | | sb.append(info.getPerCo2()); |
| | | sb.append(","); |
| | | sb.append(info.getPerO2()); |
| | | sb.append(","); |
| | | sb.append(info.getPerPh3()); |
| | | sb.append(","); |
| | | sb.append(info.getPerN2()); |
| | | sb.append(";"); |
| | | } |
| | | gas.setPoints(sb.toString()); |
| | | gasService.saveInfoGas(items); |
| | | |
| | | gasService.saveOrUpdateData(gas); |
| | | |
| | | // è°ç¨éç¥å端 |
| | | notifyInvoker.notifyWeb(gas.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GAS, depotConf.getDepotName() + " æ°ä½æ£æµï¼ç»æè¿åæå."); |
| | | |
| | | log.info("æ§å¶æ----->>>å¹³å°ï¼æ°ä½è§£æå®æ-ä»åº={}", depotConf.getDepotName()); |
| | | |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.analysis; |
| | | |
| | | import com.ld.igds.common.CoreCommonService; |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.common.dto.THDto; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.Constant; |
| | | import com.ld.igds.grain.GrainUtil; |
| | | import com.ld.igds.grain.dto.GrainItemInfo; |
| | | import com.ld.igds.io.notify.NotifyGrainInvoker; |
| | | import com.ld.igds.models.DepotConf; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.models.DicSysConf; |
| | | import com.ld.igds.models.Grain; |
| | | import com.ld.igds.order.ExeOrderService; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.warn.WarnUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * å议解æ |
| | | * |
| | | * @author vince |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisService.BEAN_ID) |
| | | public class AnalysisService { |
| | | |
| | | |
| | | public static final String BEAN_ID = "bhznVerb.analysisService"; |
| | | |
| | | @Autowired |
| | | private CoreSerService coreSerService; |
| | | @Autowired |
| | | private CoreCommonService commonService; |
| | | @Autowired |
| | | private NotifyGrainInvoker notifyGrainInvoker; |
| | | @Autowired |
| | | private GrainUtil grainUtil; |
| | | @Autowired |
| | | private WarnUtils warnUtils; |
| | | @Autowired |
| | | private ExeOrderService exeOrderService; |
| | | @Autowired |
| | | private AnalysisDevice analysisDevice; |
| | | @Autowired |
| | | private AnalysisGas analysisGas; |
| | | |
| | | |
| | | /** |
| | | * @param message |
| | | */ |
| | | public void analysis(IoMessage message) { |
| | | try{ |
| | | DeviceSer ser = coreSerService.getCacheSerBySn(message.getCompanyId(), message.getSn()); |
| | | if (null == ser) { |
| | | log.warn("æ§å¶æ------>>>å¹³å°ï¼å½åç»ç»ç¼ç ={}ï¼åæºID={}ï¼ç³»ç»æ²¡æè·åå°åæºä¿¡æ¯ï¼æ¥ææ æ³è¿è¡è§£æ", message.getCompanyId(), message.getSn()); |
| | | |
| | | return; |
| | | }else{ |
| | | ser.setIp(message.getIp()); |
| | | ser.setPort(message.getPort()); |
| | | ser.setStatus(Constant.YN_Y); |
| | | coreSerService.updateByData(ser); |
| | | } |
| | | //æ ¹æ®æ¥å£ç¼å·è¿è¡è§£æè·¯ç± |
| | | switch (message.getCmd()) { |
| | | case 247: |
| | | analysisDevice.analysis(message, ser); |
| | | break; |
| | | case 209: |
| | | analysisGas.analysis(message, ser); |
| | | break; |
| | | default: |
| | | log.error("æ§å¶æå½ä»¤ç è§£æå¤±è´¥ï¼"); |
| | | break; |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("æ§å¶æè§£æå¤±è´¥åºéï¼" + e.getMessage(),e); |
| | | } |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.builder; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | |
| | | |
| | | /** |
| | | * å½ä»¤çæ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public abstract class CommandBuilder { |
| | | |
| | | public IoMessage buildMessage(BaseRequest request) { |
| | | IoMessage message = new IoMessage(); |
| | | message.setIp(request.getIp()); |
| | | message.setPort(request.getPort()); |
| | | message.setBegin(BhznVerbServerUtils.MSG_START1); |
| | | // è°æ´ä¿¡æ¯ |
| | | buildInfo(message, request); |
| | | message.setSign("0000"); |
| | | message.setStNum(Integer.parseInt(request.getDepotId())); |
| | | message.setVersion("V1.0000000"); |
| | | message.setCmd(248); |
| | | message.setResult(""); |
| | | message.setOrderId(request.getOrderId()); |
| | | message.setContent(null); |
| | | message.setEnd(BhznVerbServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildInfo(IoMessage message, BaseRequest request) { |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®çæçå½ä»¤ï¼è¿è¡è°æ´ |
| | | * |
| | | * @param message |
| | | */ |
| | | public void build(IoMessage message) { |
| | | StringBuffer hexSb = new StringBuffer(); |
| | | hexSb.append(message.getBegin()); |
| | | SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); |
| | | filter.getExcludes().add("ip"); |
| | | filter.getExcludes().add("port"); |
| | | filter.getExcludes().add("companyId"); |
| | | filter.getExcludes().add("strMsg"); |
| | | filter.getExcludes().add("begin"); |
| | | filter.getExcludes().add("end"); |
| | | filter.getExcludes().add("byteMsg"); |
| | | filter.getExcludes().add("contentSr"); |
| | | message.setContent(JSONObject.parseObject(message.getContentStr())); |
| | | message.setStrMsg(JSONObject.toJSONString(message,filter)); |
| | | hexSb.append(message.getStrMsg()); |
| | | hexSb.append(message.getEnd()); |
| | | message.setByteMsg(hexSb.toString().getBytes()); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.builder; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ld.igds.constant.DeviceStatus; |
| | | import com.ld.igds.constant.DeviceType; |
| | | import com.ld.igds.io.request.DeviceControlRequest; |
| | | import com.ld.igds.io.request.ExeDevice; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Req248; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class ControlCommandBuilder extends CommandBuilder { |
| | | |
| | | private final static ControlCommandBuilder instance = new ControlCommandBuilder(); |
| | | |
| | | private ControlCommandBuilder() { |
| | | } |
| | | |
| | | public static ControlCommandBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public IoMessage buildMessage(DeviceControlRequest request) { |
| | | |
| | | IoMessage message = new IoMessage(); |
| | | message.setIp(request.getIp()); |
| | | message.setPort(request.getPort()); |
| | | message.setBegin(BhznVerbServerUtils.MSG_START1); |
| | | // è°æ´ä¿¡æ¯ |
| | | buildInfo(message, request); |
| | | message.setSign("0000"); |
| | | message.setVersion("V1.0000000"); |
| | | message.setStNum(Integer.parseInt(request.getDepotId())); |
| | | message.setSn(request.getSerId()); |
| | | message.setCmd(248); |
| | | message.setResult(""); |
| | | message.setOrderId(request.getOrderId()); |
| | | message.setEnd(BhznVerbServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildInfo(IoMessage message, DeviceControlRequest request) { |
| | | Req248 info = new Req248(); |
| | | Integer[] winStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | Integer[] fanStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | Integer[] airStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | Integer[] lightStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | int winCount = 0,fanCount = 0,airCount = 0,lightCount = 0; |
| | | List<ExeDevice> deviceList = request.getDeviceList(); |
| | | for (ExeDevice exeDevice : deviceList) { |
| | | //çªæ·ç±»åè®¾å¤ å
å« |
| | | if( |
| | | DeviceType.TYPE_0B.getCode().equals(exeDevice.getType()) |
| | | || DeviceType.TYPE_01.getCode().equals(exeDevice.getType()) |
| | | || DeviceType.TYPE_02.getCode().equals(exeDevice.getType()) |
| | | || DeviceType.TYPE_0C.getCode().equals(exeDevice.getType()) |
| | | ){ |
| | | winStr[exeDevice.getPassCode()-1] = getVinStatus(exeDevice.getTargetStatus()); |
| | | if(exeDevice.getPassCode() > winCount){ |
| | | winCount = exeDevice.getPassCode(); |
| | | } |
| | | if(StringUtils.isNotEmpty(exeDevice.getLink()) && !"null".equals(exeDevice.getLink())){ |
| | | fanStr[Integer.parseInt(exeDevice.getLink())-21] = getFanStatus(exeDevice.getTargetStatus()); |
| | | if(Integer.parseInt(exeDevice.getLink()) > fanCount){ |
| | | fanCount = exeDevice.getPassCode(); |
| | | } |
| | | } |
| | | } |
| | | //飿ºç±»åè®¾å¤ |
| | | if(DeviceType.TYPE_04.getCode().equals(exeDevice.getType()) |
| | | ){ |
| | | fanStr[exeDevice.getPassCode()-21] = getFanStatus(exeDevice.getTargetStatus()); |
| | | if(exeDevice.getPassCode() > fanCount){ |
| | | fanCount = exeDevice.getPassCode(); |
| | | } |
| | | } |
| | | //空è°ç±»åè®¾å¤ |
| | | // if(DeviceType.TYPE_05.getCode().equals(exeDevice.getType()) |
| | | // ){ |
| | | // fanStr[exeDevice.getPassCode()-1] = getFanStatus(exeDevice.getTargetStatus()); |
| | | // if(exeDevice.getPassCode() > fanCount){ |
| | | // fanCount = exeDevice.getPassCode(); |
| | | // } |
| | | // } |
| | | //ç
§æç±»åè®¾å¤ |
| | | if(DeviceType.TYPE_06.getCode().equals(exeDevice.getType()) |
| | | ){ |
| | | lightStr[exeDevice.getPassCode()-61] = getFanStatus(exeDevice.getTargetStatus()); |
| | | if(exeDevice.getPassCode() > lightCount){ |
| | | lightCount = exeDevice.getPassCode(); |
| | | } |
| | | } |
| | | } |
| | | info.setWinCount(winCount); |
| | | info.setWin_Str(winStr); |
| | | info.setFanCount(fanCount); |
| | | info.setFan_Str(fanStr); |
| | | info.setAirCount(airCount); |
| | | info.setAir_Str(airStr); |
| | | info.setLightCount(lightCount); |
| | | info.setLight_Str(lightStr); |
| | | message.setContentStr(JSON.toJSONString(info)); |
| | | } |
| | | |
| | | |
| | | private int getVinStatus(String deviceStatus){ |
| | | if(DeviceStatus.W_OPEN.getCode().equals(deviceStatus) || DeviceStatus.OPEN.getCode().equals(deviceStatus)){ |
| | | return 1; |
| | | } |
| | | if(DeviceStatus.W_CLOSE.getCode().equals(deviceStatus) || DeviceStatus.CLOSE.getCode().equals(deviceStatus)){ |
| | | return 2; |
| | | } |
| | | if(DeviceStatus.F_CLOSE.getCode().equals(deviceStatus) ){ |
| | | return 0; |
| | | } |
| | | if(DeviceStatus.F_OPEN.getCode().equals(deviceStatus) ||DeviceStatus.F_OPEN_F.getCode().equals(deviceStatus) ){ |
| | | return 1; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | private int getFanStatus(String deviceStatus){ |
| | | if(DeviceStatus.F_CLOSE.getCode().equals(deviceStatus) ){ |
| | | return 0; |
| | | } |
| | | if(DeviceStatus.F_OPEN.getCode().equals(deviceStatus) ||DeviceStatus.F_OPEN_F.getCode().equals(deviceStatus) ){ |
| | | return 1; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | // private int getAirStatus(ExeDevice exeDevice){ |
| | | // String s = ""; |
| | | // s += "001"; |
| | | // if(exeDevice.) |
| | | // return 0; |
| | | // } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.builder; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ld.igds.io.request.CheckGasRequest; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Req209; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | |
| | | public class GasCommandBuilder extends CommandBuilder { |
| | | private final static GasCommandBuilder instance = new GasCommandBuilder(); |
| | | |
| | | private GasCommandBuilder() { |
| | | } |
| | | |
| | | public static GasCommandBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public IoMessage buildMessage(CheckGasRequest request) { |
| | | |
| | | |
| | | IoMessage message = new IoMessage(); |
| | | message.setIp(request.getIp()); |
| | | message.setPort(request.getPort()); |
| | | message.setBegin(BhznVerbServerUtils.MSG_START1); |
| | | // è°æ´ä¿¡æ¯ |
| | | buildInfo(message, request); |
| | | message.setSign("0000"); |
| | | message.setVersion("V1.0000000"); |
| | | message.setStNum(Integer.parseInt(request.getDepotId())); |
| | | message.setSn(request.getSerId()); |
| | | message.setCmd(209); |
| | | message.setResult(""); |
| | | message.setOrderId(request.getOrderId()); |
| | | message.setEnd(BhznVerbServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | return message; |
| | | } |
| | | |
| | | public void buildInfo(IoMessage message, CheckGasRequest request) { |
| | | Req209 info = new Req209(); |
| | | info.setStart(1); |
| | | info.setChannel(0); |
| | | message.setContentStr(JSON.toJSONString(info)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.builder; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ld.igds.io.request.CheckGasRequest; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Req209; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | |
| | | public class GasStopCommandBuilder extends CommandBuilder { |
| | | private final static GasStopCommandBuilder instance = new GasStopCommandBuilder(); |
| | | |
| | | private GasStopCommandBuilder() { |
| | | } |
| | | |
| | | public static GasStopCommandBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public IoMessage buildMessage(CheckGasRequest request) { |
| | | |
| | | IoMessage message = new IoMessage(); |
| | | message.setIp(request.getIp()); |
| | | message.setPort(request.getPort()); |
| | | message.setBegin(BhznVerbServerUtils.MSG_START1); |
| | | // è°æ´ä¿¡æ¯ |
| | | buildInfo(message, request); |
| | | message.setSign("0000"); |
| | | message.setVersion("V1.0000000"); |
| | | message.setStNum(Integer.parseInt(request.getDepotId())); |
| | | message.setSn(request.getSerId()); |
| | | message.setCmd(209); |
| | | message.setResult(""); |
| | | message.setOrderId(request.getOrderId()); |
| | | message.setEnd(BhznVerbServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | return message; |
| | | } |
| | | |
| | | public void buildInfo(IoMessage message, CheckGasRequest request) { |
| | | Req209 info = new Req209(); |
| | | info.setStart(1); |
| | | info.setChannel(0); |
| | | message.setContentStr(JSON.toJSONString(info)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.builder; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ld.igds.constant.DeviceStatus; |
| | | import com.ld.igds.constant.DeviceType; |
| | | import com.ld.igds.io.request.ExeDevice; |
| | | import com.ld.igds.io.request.TempControlRequest; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.Req248; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import java.util.List; |
| | | @Slf4j |
| | | public class TempControlCommandBuilder extends CommandBuilder { |
| | | |
| | | private final static TempControlCommandBuilder instance = new TempControlCommandBuilder(); |
| | | |
| | | private TempControlCommandBuilder() { |
| | | } |
| | | |
| | | public static TempControlCommandBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public IoMessage buildMessage(TempControlRequest request) { |
| | | |
| | | IoMessage message = new IoMessage(); |
| | | message.setIp(request.getIp()); |
| | | message.setPort(request.getPort()); |
| | | message.setBegin(BhznVerbServerUtils.MSG_START1); |
| | | // è°æ´ä¿¡æ¯ |
| | | buildInfo(message, request); |
| | | message.setSign("0000"); |
| | | message.setVersion("V1.0000000"); |
| | | message.setStNum(Integer.parseInt(request.getDepotId())); |
| | | message.setSn(request.getSerId()); |
| | | message.setCmd(248); |
| | | message.setResult(""); |
| | | message.setOrderId(request.getOrderId()); |
| | | message.setEnd(BhznVerbServerUtils.MSG_END); |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildInfo(IoMessage message, TempControlRequest request) { |
| | | Req248 info = new Req248(); |
| | | Integer[] winStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | Integer[] fanStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | Integer[] airStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | Integer[] lightStr = new Integer[]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
| | | int winCount = 0,fanCount = 0,airCount = 0,lightCount = 0; |
| | | ExeDevice exeDevice = request.getExeDevice(); |
| | | |
| | | //空è°ç±»åè®¾å¤ |
| | | airStr[exeDevice.getPassCode()-41] = getAirStatus(request); |
| | | airCount = exeDevice.getPassCode()-41; |
| | | info.setWinCount(winCount); |
| | | info.setWin_Str(winStr); |
| | | info.setFanCount(fanCount); |
| | | info.setFan_Str(fanStr); |
| | | info.setAirCount(airCount); |
| | | info.setAir_Str(airStr); |
| | | info.setLightCount(lightCount); |
| | | info.setLight_Str(lightStr); |
| | | message.setContentStr(JSON.toJSONString(info)); |
| | | } |
| | | |
| | | |
| | | private Integer getAirStatus(TempControlRequest request){ |
| | | try{ |
| | | String h = ""; |
| | | String l = ""; |
| | | h = "001"+h; |
| | | if(DeviceStatus.OPEN.getCode().equals(request.getExeDevice().getTargetStatus())){ |
| | | h = "1"+h; |
| | | }else{ |
| | | h = "0"+h; |
| | | } |
| | | h = "0000"+h; |
| | | h = BytesUtil.hexToInt(BytesUtil.bin2Hex(h)) + ""; |
| | | if (h.length() < 2) { |
| | | h = "0" + h; |
| | | } |
| | | l = BytesUtil.intToHexStr1(Integer.parseInt(request.getTargetTemp())); |
| | | String s= l+ h ; |
| | | return BytesUtil.hexToInt(s); |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage(),e); |
| | | return -1; |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.command; |
| | | |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerEngine; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.io.api.InvokeResult; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionQuery; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Component(BaseRemoteImpl.BEAN_ID) |
| | | public class BaseRemoteImpl { |
| | | public static final String BEAN_ID = "bhzn.remoteBaseCommonService"; |
| | | public String getProtocol() { |
| | | return ProtocolEnum.TCP_BHZH_VERB_V2.getCode(); |
| | | } |
| | | |
| | | @Autowired |
| | | private BhznVerbServerEngine bhznVerbServerEngine; |
| | | |
| | | /** |
| | | * åéå½ä»¤ |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @param msg |
| | | * @return |
| | | */ |
| | | public InvokeResult send(String ip, int port, byte[] msg) { |
| | | log.debug("平尿¨éæ¥æä¿¡æ¯--{}", BytesUtil.bytesToString(msg)); |
| | | IoSessionQuery sessionFactory = bhznVerbServerEngine.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(IoMessage message) { |
| | | log.debug("平尿¨éæ¥æä¿¡æ¯--{}", message.toString()); |
| | | IoSessionQuery sessionFactory = bhznVerbServerEngine.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.ld.igds.protocol.bhzn.verb.command; |
| | | |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.io.RemoteCommonService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.io.request.*; |
| | | import com.ld.igds.io.response.BaseResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * å½ååè®®å®ç°ï¼ç²®æ
模åå½ä»¤æ¥å£ |
| | | * |
| | | * @author jiazx |
| | | */ |
| | | @Slf4j |
| | | @Component(RemoteCommonImpl.BEAN_ID) |
| | | public class RemoteCommonImpl extends BaseRemoteImpl implements RemoteCommonService { |
| | | |
| | | public static final String BEAN_ID = "bhzn.remoteCommonService"; |
| | | |
| | | @Autowired |
| | | private NotifyWebInvoker notifyWebInvoker; |
| | | |
| | | @Override |
| | | public BaseResponse checkTh(CheckThRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullDevice(BaseRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BaseResponse pullDepot(BaseRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullAccess(AccessRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullDepotStatus(DepotStatusRequest request) { |
| | | |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse heartBeat(BaseRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse readConf(GrainSerConfRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse writeConf(GrainSerConfRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse initCable(BaseRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse updateGrainSerCable(GrainSerConfRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse destroyCon(BaseRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse checkGrainSerCable(GrainSerConfRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse sumGrainSerCable(GrainSerConfRequest request) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse updateSysDepotConf(BaseRequest request) { |
| | | return null; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.command; |
| | | |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.DeviceStatus; |
| | | import com.ld.igds.constant.DeviceType; |
| | | import com.ld.igds.io.RemoteControlService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.io.request.DeviceAutoControlRequest; |
| | | import com.ld.igds.io.request.DeviceControlRequest; |
| | | import com.ld.igds.io.request.ExeDevice; |
| | | import com.ld.igds.io.request.TempControlRequest; |
| | | import com.ld.igds.io.response.BaseResponse; |
| | | import com.ld.igds.io.response.DeviceControlResponse; |
| | | import com.ld.igds.protocol.bhzn.verb.builder.ControlCommandBuilder; |
| | | import com.ld.igds.protocol.bhzn.verb.builder.TempControlCommandBuilder; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Component(RemoteControlServiceImpl.BEAN_ID) |
| | | public class RemoteControlServiceImpl extends BaseRemoteImpl implements RemoteControlService { |
| | | |
| | | public static final String BEAN_ID = "bhzn.remoteControlService"; |
| | | |
| | | @Autowired |
| | | private NotifyWebInvoker notifyWebInvoker; |
| | | |
| | | |
| | | @Override |
| | | public DeviceControlResponse deviceControl(DeviceControlRequest request) { |
| | | try { |
| | | controlBatchExe(request); |
| | | } catch (Exception e) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼è®¾å¤æä½-å端å¼å¸¸-{}", e); |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), e.getMessage()); |
| | | } |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_SUCCESS); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¤ä¸ªè®¾å¤æ§è¡ |
| | | * |
| | | * @param request |
| | | * @throws Exception |
| | | */ |
| | | public void controlBatchExe(DeviceControlRequest request) throws Exception { |
| | | |
| | | IoMessage message = ControlCommandBuilder.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>>æ§å¶æï¼è®¾å¤æä½-{}", message.toString()); |
| | | |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å¦æææ§è¡å¼å¸¸ï¼ç´æ¥éç¥å°å端 |
| | | if (InvokeResult.SUCCESS.getCode() != result.getCode()) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼è®¾å¤æä½-æ§è¡å¤±è´¥-{}", result.getMessage()); |
| | | notifyWeb(request.getCompanyId(), OrderRespEnum.ORDER_ERROR, "è®¾å¤æä½å¼å¸¸ï¼åå ï¼" + result.getMessage()); |
| | | |
| | | return; |
| | | } |
| | | |
| | | List<ExeDevice> listDevice = request.getDeviceList(); |
| | | String deviceType = listDevice.get(0).getType(); |
| | | String targetStatus = listDevice.get(0).getTargetStatus(); |
| | | |
| | | //é´éæ¶é´å®ä¹ |
| | | long longTime = 1000; |
| | | |
| | | if (DeviceType.TYPE_01.getCode().equals(deviceType)) { |
| | | longTime = 15 * 1000; |
| | | } |
| | | if (DeviceType.TYPE_0B.getCode().equals(deviceType)) { |
| | | longTime = 15 * 1000; |
| | | } |
| | | if (DeviceType.TYPE_07.getCode().equals(deviceType)) { |
| | | longTime = 15 * 1000; |
| | | } |
| | | if (DeviceType.TYPE_06.getCode().equals(deviceType)) { |
| | | longTime = 500; |
| | | } |
| | | if (DeviceType.TYPE_09.getCode().equals(deviceType)) { |
| | | longTime = 15 * 1000; |
| | | } |
| | | if (DeviceStatus.W_OPEN.getCode().equals(targetStatus) || DeviceStatus.W_CLOSE.getCode().equals(targetStatus)) { |
| | | longTime = 15 * 1000; |
| | | } |
| | | if (DeviceStatus.F_OPEN.getCode().equals(targetStatus) || DeviceStatus.F_OPEN_F.getCode().equals(targetStatus)) { |
| | | longTime = 3 * 1000; |
| | | } |
| | | |
| | | Thread.sleep(longTime); |
| | | |
| | | //妿䏿¯ç³»ç»æ§è¡ï¼ç´æ¥è¯¶è·å设å¤ç¶æ |
| | | if (!request.isSysExeTag()) { |
| | | log.debug("--------------------æ§è¡å®æåï¼ç³»ç»èªå¨åéç¶ææ¥è¯¢------------------{}", request.getDepotId()); |
| | | //queryStatus(request); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public DeviceControlResponse closeAll(DeviceControlRequest request) { |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public DeviceControlResponse queryStatus(DeviceControlRequest request) { |
| | | |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public DeviceControlResponse tempControl(TempControlRequest request) { |
| | | try { |
| | | IoMessage message = TempControlCommandBuilder.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>>æ§å¶æï¼ç©ºè°è®¾å¤æä½-{}", message.toString()); |
| | | |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å¦æææ§è¡å¼å¸¸ï¼ç´æ¥éç¥å°å端 |
| | | if (InvokeResult.SUCCESS.getCode() != result.getCode()) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼ç©ºè°è®¾å¤æä½-æ§è¡å¤±è´¥-{}", result.getMessage()); |
| | | |
| | | // notifyWeb(request.getCompanyId(), OrderRespEnum.ORDER_ERROR, "è®¾å¤æä½å¼å¸¸ï¼åå ï¼" + result.getMessage()); |
| | | |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "æ§è¡å¼å¸¸ï¼åå ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼ç©ºè°è®¾å¤æä½-å端å¼å¸¸-{}", e); |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), e.getMessage()); |
| | | } |
| | | |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_SUCCESS); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public DeviceControlResponse n2AutoControl(DeviceAutoControlRequest request) { |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * èªå¨éé£ï¼æºè½æ§å¶ææ§è¡ |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @Override |
| | | public DeviceControlResponse airAutoControl(DeviceAutoControlRequest request) { |
| | | return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "å½ååè®®ä¸æ¯æå½å模å¼ï¼"); |
| | | } |
| | | |
| | | /** |
| | | * 页é¢éç¥ |
| | | * |
| | | * @param companyId |
| | | * @param orderResp |
| | | * @param notifyMsg |
| | | */ |
| | | private void notifyWeb(String companyId, OrderRespEnum orderResp, |
| | | String notifyMsg) { |
| | | notifyWebInvoker.notifyWeb(companyId, orderResp, BizType.AREATION, |
| | | notifyMsg); |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.command; |
| | | |
| | | import com.ld.igds.io.RemoteGasService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.CheckGasRequest; |
| | | import com.ld.igds.io.response.GasResponse; |
| | | import com.ld.igds.protocol.bhzn.verb.builder.GasCommandBuilder; |
| | | import com.ld.igds.protocol.bhzn.verb.builder.GasStopCommandBuilder; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æ°ä½ééå½ä»¤å®ç° |
| | | */ |
| | | @Slf4j |
| | | @Component(RemoteGasServiceImpl.BEAN_ID) |
| | | public class RemoteGasServiceImpl extends BaseRemoteImpl implements RemoteGasService { |
| | | |
| | | public static final String BEAN_ID = "bhzn.remoteGasService"; |
| | | |
| | | |
| | | @Override |
| | | public GasResponse checkGas(CheckGasRequest request) { |
| | | try { |
| | | IoMessage message = GasCommandBuilder.getInstance().buildMessage(request); |
| | | |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼æ°ä½æ£æµ-{}", message.toString()); |
| | | |
| | | if (InvokeResult.SUCCESS != result) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼æ°ä½æ£æµ-失败{}", result.getMessage()); |
| | | return new GasResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "ééæ§è¡å¤±è´¥ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("æ°ä½æ£æµå¼å¸¸ï¼{}", e); |
| | | return new GasResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "ééå¼å¸¸ï¼åå ï¼" + e.getMessage()); |
| | | } |
| | | return new GasResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "æ°ä½ééå½ä»¤åéæåï¼"); |
| | | } |
| | | |
| | | @Override |
| | | public GasResponse stopCheckGas(CheckGasRequest request) { |
| | | try { |
| | | IoMessage message = GasStopCommandBuilder.getInstance().buildMessage(request); |
| | | |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼æ°ä½æ£æµ-{}", message.toString()); |
| | | |
| | | if (InvokeResult.SUCCESS != result) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼æ°ä½æ£æµ-失败{}", result.getMessage()); |
| | | return new GasResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "ééæ§è¡å¤±è´¥ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("æ°ä½æ£æµå¼å¸¸ï¼{}", e); |
| | | return new GasResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "ééå¼å¸¸ï¼åå ï¼" + e.getMessage()); |
| | | } |
| | | return new GasResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "æ°ä½ééå½ä»¤åéæåï¼"); |
| | | } |
| | | |
| | | @Override |
| | | public GasResponse checkGasByPoint(CheckGasRequest request) { |
| | | return checkGas(request); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.command; |
| | | |
| | | import com.ld.igds.io.RemoteGrainService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.CheckGrainRequest; |
| | | import com.ld.igds.io.response.DeviceControlResponse; |
| | | import com.ld.igds.io.response.GrainResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * å½ååè®®å®ç°ï¼ç²®æ
模åå½ä»¤æ¥å£ |
| | | * |
| | | * @author jiazx |
| | | */ |
| | | @Slf4j |
| | | @Component(RemoteGrainServiceImpl.BEAN_ID) |
| | | public class RemoteGrainServiceImpl extends BaseRemoteImpl implements |
| | | RemoteGrainService { |
| | | |
| | | public static final String BEAN_ID = "bhzn.remoteGrainService"; |
| | | |
| | | @Override |
| | | public GrainResponse checkGrain(CheckGrainRequest request) { |
| | | |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.command; |
| | | |
| | | import com.ld.igds.io.RemotePestService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.CheckPestRequest; |
| | | import com.ld.igds.io.response.GrainResponse; |
| | | import com.ld.igds.io.response.PestResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æ£æµè«å®³ |
| | | */ |
| | | @Slf4j |
| | | @Component(RemotePestServiceImpl.BEAN_ID) |
| | | public class RemotePestServiceImpl extends BaseRemoteImpl implements RemotePestService { |
| | | |
| | | public static final String BEAN_ID = "bhzn.remotePestService"; |
| | | |
| | | @Override |
| | | public PestResponse checkPest(CheckPestRequest request) { |
| | | return new PestResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public PestResponse stopCheckPest(CheckPestRequest request) { |
| | | return new PestResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public PestResponse checkPestByPoint(CheckPestRequest request) { |
| | | return checkPest(request); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.dto; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.annotation.JSONField; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class IoMessage { |
| | | @JSONField(serialize = false) |
| | | private String ip; |
| | | @JSONField(serialize = false) |
| | | private int port; |
| | | private String sn; |
| | | private Integer stNum; |
| | | private String sign; |
| | | private String version; |
| | | private Integer cmd; |
| | | private String result; |
| | | private String orderId; |
| | | |
| | | private JSONObject content; |
| | | @JSONField(serialize = false) |
| | | private String contentStr; |
| | | |
| | | @JSONField(serialize = false) |
| | | private String companyId; |
| | | @JSONField(serialize = false) |
| | | private String strMsg; |
| | | @JSONField(serialize = false) |
| | | private String begin; |
| | | @JSONField(serialize = false) |
| | | private String end; |
| | | @JSONField(serialize = false) |
| | | private byte[] byteMsg; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * æ°ä½æ£æµå½ä»¤ |
| | | */ |
| | | @Data |
| | | public class Req209 { |
| | | |
| | | private Integer Start; |
| | | /** |
| | | * 1-10 0æè
空表示ææéé |
| | | */ |
| | | private Integer Channel = 0; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * è®¾å¤æ§å¶ |
| | | */ |
| | | @Data |
| | | public class Req248 { |
| | | |
| | | |
| | | private Integer WinCount; |
| | | private Integer[] Win_Str; |
| | | private Integer FanCount; |
| | | private Integer[] Fan_Str; |
| | | private Integer AirCount; |
| | | private Integer[] Air_Str; |
| | | private Integer LightCount; |
| | | private Integer[] Light_Str; |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * æ°ä½æ£æµè¿å |
| | | */ |
| | | @Data |
| | | public class Res209 { |
| | | |
| | | private Integer State; |
| | | private String Error; |
| | | private Integer N2Avage; |
| | | private Integer PH3Avage; |
| | | private Integer CO2Avage; |
| | | private Integer[] N2ValArray; |
| | | private Integer[] PH3ValArray; |
| | | private Integer[] CO2ValArray; |
| | | private Integer[] N2LayAvage; |
| | | private Integer[] PH3LayAvage; |
| | | private Integer[] CO2LayAvage; |
| | | private Integer[] WormVal; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.dto; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 设å¤ç¶æè¿å |
| | | */ |
| | | @Data |
| | | public class Res247 { |
| | | |
| | | private Integer State; |
| | | private String Error; |
| | | private Integer THCount; |
| | | private Integer[] TH_Str; |
| | | private Integer WinCount; |
| | | private Integer[] Win_Str; |
| | | private Integer FanCount; |
| | | private Integer[] Fan_Str; |
| | | private Integer AirCount; |
| | | private Integer[] Air_Str; |
| | | private Integer Mode; |
| | | private Integer[] Light_Str; |
| | | private Integer LightCount; |
| | | private Integer GasDev; |
| | | private Integer N2Val; |
| | | private Integer PH3Val; |
| | | private Integer CO2Val; |
| | | private Integer N2Avage; |
| | | private Integer PH3Avage; |
| | | private Integer CO2Avage; |
| | | private Integer AirPVal; |
| | | private Integer[] ValveSt; |
| | | private Integer[] AriSt; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * è®¾å¤æ§å¶ |
| | | */ |
| | | @Data |
| | | public class Res248 { |
| | | |
| | | private Integer State; |
| | | private String Error; |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.msg; |
| | | |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * æ ¹æ®æ¥æ¶å°çä¿¡æ¯è¿è¡å°è£
|
| | | * |
| | | * @author vince |
| | | */ |
| | | public class ReMessageBuilder { |
| | | |
| | | |
| | | public final static String ERROR_TAG = "3CF6"; |
| | | public static double FAULT_CHECK_TAG = 85.0; |
| | | public static double MAX_TEMP = -50.0; |
| | | public static double MIN_TEMP = 50.0; |
| | | private final static ReMessageBuilder instance = new ReMessageBuilder(); |
| | | |
| | | private ReMessageBuilder() { |
| | | } |
| | | |
| | | public static ReMessageBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | /** |
| | | * @param message |
| | | * @return |
| | | */ |
| | | public IoMessage buildMessage(String message) throws Exception { |
| | | IoMessage ioMessage = new IoMessage(); |
| | | return ioMessage; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * 馿µ·æ§å¶æåè®® |
| | | */ |
| | | package com.ld.igds.protocol.bhzn.verb; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.server; |
| | | |
| | | |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; |
| | | import com.ld.io.api.HeartbeatProvider; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * æä¾å¿è·³ä¿¡æ¯ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class BhznVerbHeartbeatImpl implements HeartbeatProvider { |
| | | |
| | | @Override |
| | | public byte[] provide(IoSession session) { |
| | | |
| | | |
| | | //ç´æ¥æ ¹æ®ä¸»æºSESSIOn夿 |
| | | //IoSession session1 = BhznVerbServerUtils.getSession(); |
| | | |
| | | Long lastBeatTime = BhznVerbServerUtils.getHearBeat(session); |
| | | |
| | | if (null == lastBeatTime) { |
| | | return null; |
| | | } |
| | | |
| | | //妿æå䏿¬¡ç»ç«¯å¿è·³æ¶é´è·ç¦»å½åæ¶é´å¤§äº ç»ç«¯å¿è·³æ¶é´ç3次ï¼åå¤æä¸ºç¦»çº¿ |
| | | long deTime = System.currentTimeMillis() - lastBeatTime; |
| | | |
| | | if (deTime > (BhznVerbServerUtils.HEART_BEAT_TIME * 3 * 1000)) { |
| | | log.info("-----------è¶
è¿{}ç§æªè·åå°å¿è·³ä¿¡æ¯ï¼å¤å®ç»ç«¯ç¦»çº¿ï¼è¸¢åºè¿æ¥------------{}-{}", deTime, session.getAddress(), session.getPort()); |
| | | |
| | | session.destroy(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.server; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.ld.igds.protocol.bhzn.verb.analysis.AnalysisService; |
| | | import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; |
| | | import com.ld.igds.protocol.bhzn.verb.msg.ReMessageBuilder; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.igds.util.SpringUtil; |
| | | import com.ld.io.api.IoMsgConsumer; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import static com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils.CHARSET; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class BhznVerbMessageConsumer implements IoMsgConsumer { |
| | | |
| | | |
| | | @Autowired |
| | | private AnalysisService analysisService; |
| | | |
| | | /** |
| | | * å¤çæ¶æ¯ |
| | | * |
| | | * @param session |
| | | * @param bytes |
| | | */ |
| | | @Override |
| | | public void consume(IoSession session, byte[] bytes) { |
| | | if (null == bytes) { |
| | | log.error("Reply bytes is null"); |
| | | return; |
| | | } |
| | | //æ·»å ä¿¡æ¯å¿è·³æ è®° |
| | | BhznVerbServerUtils.addHeartBeat(session); |
| | | IoMessage reMessage = null; |
| | | try { |
| | | String message = new String(bytes, CHARSET); |
| | | message = message.substring(message.indexOf(BhznVerbServerUtils.MSG_START1) + BhznVerbServerUtils.MSG_START1.length()); |
| | | log.info("ã"+session.getAddress()+"ãæ§å¶æ------>>>>å¹³å°ï¼"+message); |
| | | reMessage = JSON.parseObject(message, IoMessage.class); |
| | | JSONObject jsonObject = JSON.parseObject(message); |
| | | reMessage.setContentStr(jsonObject.getString("content")); |
| | | if (StringUtils.isEmpty(reMessage.getSn()) || |
| | | reMessage.getStNum()== null || |
| | | reMessage.getCmd() == null) { |
| | | log.error("æ§å¶æ------>>>>å¹³å°ï¼æ¥æä¿¡æ¯ä¸å®æ´ï¼ä¸åè§£æ-IP={}ï¼port={}ï¼msg={}", session.getAddress(), session.getPort(), message); |
| | | return; |
| | | } |
| | | |
| | | //æ ¹æ®SNè·åç»ç»ç¼ç |
| | | String companyId = ContextUtil.getCompanyIdBySn(reMessage.getSn()); |
| | | if (null == companyId) { |
| | | log.error("æ§å¶æ------>>>>å¹³å°ï¼æ¥æä¿¡æ¯ä¸å®æ´ï¼å½ååæºç³»ç»æªæ³¨åï¼ä¸åè§£æ-IP={}ï¼port={}ï¼msg={}", session.getAddress(), session.getPort(), message); |
| | | return; |
| | | } |
| | | |
| | | reMessage.setCompanyId(companyId); |
| | | reMessage.setIp(session.getAddress()); |
| | | reMessage.setPort(session.getPort()); |
| | | reMessage.setStrMsg(message); |
| | | session.setCompanyId(companyId); |
| | | |
| | | log.info("æ§å¶æ------>>>>å¹³å°ï¼IP={}ï¼PORT={}ï¼message={}", reMessage.getIp(), reMessage.getPort(), message); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("æ§å¶æ------>>>>å¹³å°ï¼æ¶å°æ¥æè§£æå¼å¸¸ï¼{}" , e.getMessage()); |
| | | log.error(e.getMessage(),e); |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | //è°ç¨è§£ææ¥å£å¼å§è§£æ |
| | | if (null == analysisService) { |
| | | analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); |
| | | } |
| | | analysisService.analysis(reMessage); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.server; |
| | | |
| | | import com.ld.io.api.*; |
| | | import com.ld.io.netty.NettyServer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Desc: 馿µ·æºè½çº¯ç²®æ
åè®® |
| | | * @author: Andy |
| | | * @update-time: 2023/5/11 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class BhznVerbServerEngine { |
| | | |
| | | public static final Integer PORT = 9310; |
| | | |
| | | @Autowired |
| | | private BhznVerbMessageConsumer defaultMessageConsumer; |
| | | @Autowired |
| | | private BhznVerbSessionListener defaultSessionListener; |
| | | // å¿è·³æä¾ |
| | | private static HeartbeatProvider heartbeatProvider = new BhznVerbHeartbeatImpl(); |
| | | |
| | | private IoSessionQuery sessionQuery; |
| | | |
| | | public void start(Integer port) { |
| | | IoServerOption ioServerOption = new IoServerOption(); |
| | | |
| | | if (null != port) { |
| | | ioServerOption.setPort(port); |
| | | } else { |
| | | ioServerOption.setPort(PORT); |
| | | } |
| | | |
| | | //确认ç»å°¾æ å¿ |
| | | ioServerOption.setDelimiter(BhznVerbServerUtils.MSG_END.getBytes()); |
| | | |
| | | // é
置系ç»å¿è·³é´é |
| | | ioServerOption.setReaderIdleTime(5 * 60); |
| | | |
| | | NettyServer ioServer = new NettyServer(ioServerOption, defaultMessageConsumer, defaultSessionListener, heartbeatProvider); |
| | | ioServer.startup(); |
| | | |
| | | sessionQuery = ioServer.getSessionQuery(); |
| | | |
| | | |
| | | log.info("* "); |
| | | log.info("* ========================"); |
| | | log.info("* "); |
| | | log.info("* [VERB-SERVERï¼BHZN_VERB,PORT={}]", PORT); |
| | | log.info("* "); |
| | | log.info("* ========================"); |
| | | log.info("* "); |
| | | |
| | | System.out.println("* ========================"); |
| | | System.out.println("* "); |
| | | System.out.println("* [VERB-SERVERï¼BHZN_VERB,PORT={}]" + port); |
| | | System.out.println("* "); |
| | | System.out.println("* ========================"); |
| | | } |
| | | |
| | | public IoSessionQuery getSessionQuery() { |
| | | return sessionQuery; |
| | | } |
| | | |
| | | /** |
| | | * åéä¿¡æ¯ |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @param msg |
| | | * @return |
| | | */ |
| | | public InvokeResult push(String ip, int port, byte[] msg) { |
| | | IoSessionQuery sessionFactory = getSessionQuery(); |
| | | List<IoSession> sessions = sessionFactory.getAllSession(); |
| | | IoSession session = null; |
| | | for (IoSession ioSession : sessions) { |
| | | if (BhznVerbServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) { |
| | | session = ioSession; |
| | | break; |
| | | } |
| | | } |
| | | if (null == session) { |
| | | return InvokeResult.CHANNEL_CLOSED; |
| | | } |
| | | return session.invoke(msg); |
| | | } |
| | | |
| | | |
| | | // public InvokeResult push(String ip, int port, String hexStr) { |
| | | // |
| | | // byte[] msg = BytesUtil.hexStrToBytes(hexStr); |
| | | // |
| | | // IoSessionQuery sessionFactory = getSessionQuery(); |
| | | // List<IoSession> sessions = sessionFactory.getAllSession(); |
| | | // IoSession session = null; |
| | | // for (IoSession ioSession : sessions) { |
| | | // if (BhznGrainV1ServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) { |
| | | // session = ioSession; |
| | | // break; |
| | | // } |
| | | // } |
| | | // |
| | | // if (null == session) { |
| | | // return InvokeResult.CHANNEL_CLOSED; |
| | | // } |
| | | // return session.invoke(msg); |
| | | // } |
| | | |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.server; |
| | | |
| | | |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.io.api.IoSession; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * å·¥å
·ç±» |
| | | * |
| | | * @author vince |
| | | */ |
| | | public class BhznVerbServerUtils { |
| | | |
| | | |
| | | /** |
| | | * 设å¤ç¶æè¿åçç»æ KEY= serId + "_STATUS_" + deviceId value = ç»æç¶æ |
| | | */ |
| | | private static Map<String, String> contextStatusMap = new HashMap<>(); |
| | | |
| | | |
| | | /** |
| | | * 设å¤è§£æåçè£
æ³åæ¾ |
| | | * |
| | | * @param serId |
| | | * @param passcode 设å¤ééID |
| | | * @param status |
| | | */ |
| | | public static void add2StatusMap(String companyId, String serId, String passcode, String status) { |
| | | contextStatusMap.put(ContextUtil.buildDeviceStatusKey(companyId, serId, passcode), status); |
| | | } |
| | | public static void add2StatusMap(String companyId, String serId, int passcode, String status) { |
| | | contextStatusMap.put(ContextUtil.buildDeviceStatusKey(companyId, serId, passcode), status); |
| | | } |
| | | public static Map<String, String> getStatusMap() { |
| | | return contextStatusMap; |
| | | } |
| | | /** |
| | | * è®°å½æ¯ä¸ªè¿æ¥çæå䏿¬¡ä¿¡æ¯æ¶é´ key = è¿æ¥çKYEï¼data =å½åæ¶é´æ³ |
| | | */ |
| | | public static Map<String, Long> contextMapHeart = new HashMap<>(); |
| | | |
| | | public static Map<String, IoSession> contextIoSession = new HashMap<>(); |
| | | |
| | | |
| | | public static int HEART_BEAT_TIME = 30;//å¿è·³é´éæ¶é´ |
| | | |
| | | |
| | | public static String MSG_START = "3C42485A4E3E";//<BHZN> |
| | | public static String MSG_START1 = "<BHZN>";//<BHZN> |
| | | public static String MSG_START2 = "AA"; |
| | | public static String MSG_END = "<END>";//<END> |
| | | public static String MSG_END_16 = "3C454E443E";//<END> |
| | | public static final String CHARSET = "UTF-8"; |
| | | |
| | | |
| | | /** |
| | | * é对æ 线粮æ
主æºçé»è®¤IDé
ç½® |
| | | */ |
| | | public static String DEFAULT_MAC_ID = "53681"; |
| | | |
| | | public static String FUNCTION_ID_00 = "00"; |
| | | public static String FUNCTION_ID_F1 = "F1"; |
| | | public static String FUNCTION_ID_F2 = "F2"; |
| | | public static String FUNCTION_ID_83 = "83"; |
| | | public static String FUNCTION_ID_93 = "93"; |
| | | public static String FUNCTION_ID_92 = "92"; |
| | | |
| | | |
| | | /** |
| | | * çæTCPè¿æ¥çKEY |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @return |
| | | */ |
| | | public static String getServerKey(String ip, Integer port) { |
| | | return ip + ":" + port; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ·»å ææ°å¿è·³æ¶é´æ³ |
| | | * |
| | | * @param session |
| | | */ |
| | | public static void addHeartBeat(IoSession session) { |
| | | contextMapHeart.put(getServerKey(session.getAddress(), session.getPort()), System.currentTimeMillis()); |
| | | } |
| | | |
| | | public static Long getHearBeat(IoSession session) { |
| | | return contextMapHeart.get(getServerKey(session.getAddress(), session.getPort())); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * è®¡ç®æ ¡éª |
| | | * |
| | | * @param content |
| | | * @return |
| | | */ |
| | | public static String getCheck(String content) { |
| | | int start = BhznVerbServerUtils.MSG_START.length() + BhznVerbServerUtils.MSG_START2.length(); |
| | | content = content.substring(start); |
| | | int sum = 0; |
| | | String hex; |
| | | for (int i = 0; i < content.length() / 2; i++) { |
| | | hex = content.substring(i * 2, i * 2 + 2); |
| | | sum += BytesUtil.hexToInt(hex); |
| | | } |
| | | String hexSum = BytesUtil.intToHexStr(sum); |
| | | int check = BytesUtil.hexToInt(hexSum.substring(hexSum.length() - 2)); |
| | | |
| | | return BytesUtil.intToHexStr(256 - check).substring(2); |
| | | } |
| | | |
| | | // public static void addSession(IoSession session) { |
| | | // contextIoSession.put(DEFAULT_MAC_ID, session); |
| | | // } |
| | | // |
| | | // public static IoSession getSession() { |
| | | // return contextIoSession.get(DEFAULT_MAC_ID); |
| | | // } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.bhzn.verb.server; |
| | | |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionListener; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class BhznVerbSessionListener implements IoSessionListener { |
| | | |
| | | @Autowired |
| | | private CoreSerService coreSerService; |
| | | |
| | | /** |
| | | * 设å¤å建å¨çº¿ï¼éè¦æ³¨æå½å使ç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºä¸çº¿é»è®¤ææç¸åSNé
ç½®çåæºå
¨é¨ä¸çº¿ |
| | | * |
| | | * @param session |
| | | */ |
| | | @Override |
| | | public void onCreate(IoSession session) { |
| | | |
| | | // //æ·»å å°å
å |
| | | // BhznVerbServerUtils.addSession(session); |
| | | |
| | | log.info("++++æ°å»ºè¿æ¥++++-IP={}ï¼PORT={}", session.getAddress(), session.getPort()); |
| | | |
| | | // æ·»å èªå®ä¹ä¸å¡ID |
| | | session.setBusinessKey(BhznVerbServerUtils.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | //项ç®éç¨æ çº¿ä¸»æºæ¨¡å¼ï¼ç´æ¥è·åé»è®¤è®¾å¤ |
| | | // DeviceSer deviceSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID); |
| | | |
| | | //if (null == deviceSer) return; |
| | | |
| | | //coreSerService.onlineBySn(session.getAddress(), session.getPort(), deviceSer.getSn(), Constant.YN_Y); |
| | | //æ´æ°ç¼å |
| | | // coreSerService.refreshCache(deviceSer.getCompanyId()); |
| | | } |
| | | |
| | | /** |
| | | * 注æï¼å½åéç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºç¦»çº¿ææç¸åSNé
ç½®çåæºå
¨é¨ç¦»çº¿ |
| | | * |
| | | * @param session |
| | | */ |
| | | @Override |
| | | public void onDestroy(IoSession session) { |
| | | log.info("----è¿æ¥æå¼-----IP={}ï¼PORT={}", session.getAddress(), session.getPort()); |
| | | |
| | | // //项ç®éç¨æ çº¿ä¸»æºæ¨¡å¼ï¼ç´æ¥è·åé»è®¤è®¾å¤ |
| | | // DeviceSer deviceSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID); |
| | | // |
| | | // if (null == deviceSer) return; |
| | | |
| | | //ç±äºè®¾å¤æçº¿åèªå¨è°æ´ |
| | | // coreSerService.onlineBySn(session.getAddress(), session.getPort(), deviceSer.getSn(), Constant.YN_N); |
| | | // //æ´æ°ç¼å |
| | | // coreSerService.refreshCache(deviceSer.getCompanyId()); |
| | | } |
| | | } |
| | |
| | | public static void main(String[] args) { |
| | | |
| | | int i = calcCrc16(BytesUtil.hexStrToBytes("01050046000001")); |
| | | |
| | | System.out.println(BytesUtil.intToHexStr(i)); |
| | | String s = "<BHZN>"; |
| | | System.out.println(s.length()); |
| | | } |
| | | } |
| | |
| | | ## 5322_001 广ä¸å¾é» |
| | | verb.mapImg.5322_001.a=default_pfc_a.png |
| | | verb.mapImg.5322_001.b=default_pfc_b.png |
| | | |
| | | |
| | | ## 5322_001 广ä¸å¾é» |
| | | verb.mapImg.5324_001.a=default_pfc_a.png |
| | | verb.mapImg.5324_001.b=default_pfc_b.png |
| | | verb.mapImg.5324_1.a=pfc_a.png |
| | | verb.mapImg.5324_1.b=pfc_b.png |
| | | verb.mapImg.5324_2.a=pfc_a.png |
| | | verb.mapImg.5324_2.b=pfc_b.png |
| | | verb.mapImg.5324_3.a=pfc_a.png |
| | | verb.mapImg.5324_3.b=pfc_b.png |
| | | verb.mapImg.5324_4.a=pfc_a.png |
| | | verb.mapImg.5324_4.b=pfc_b.png |
| | | verb.mapImg.5324_5.a=pfc_a.png |
| | | verb.mapImg.5324_5.b=pfc_b.png |
| | | verb.mapImg.5324_6.a=pfc_a.png |
| | | verb.mapImg.5324_6.b=pfc_b.png |
| | | verb.mapImg.5324_7.a=pfc_a.png |
| | | verb.mapImg.5324_7.b=pfc_b.png |
| | | verb.mapImg.5324_8.a=pfc_a.png |
| | | verb.mapImg.5324_8.b=pfc_b.png |
| | | verb.mapImg.5324_9.a=pfc_a.png |
| | | verb.mapImg.5324_9.b=pfc_b.png |
| | | verb.mapImg.5324_10.a=pfc_a.png |
| | | verb.mapImg.5324_10.b=pfc_b.png |
| | | verb.mapImg.5324_11.a=pfc_a.png |
| | | verb.mapImg.5324_11.b=pfc_b.png |