src/main/java/com/fzzy/api/data/DepotType.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,49 @@ package com.fzzy.api.data; import com.fzzy.api.entity.ApiTrigger; import java.util.ArrayList; import java.util.List; /** * ä»åºç±»åï¼é对å½åç³»ç»ææ¯æç仿¿ç±»åï¼é彿 ç±»å * * @author jiazx */ public enum DepotType { TYPE_01("01", "å¹³æ¿ä»"), TYPE_02("02", "æµ åä»"), TYPE_03("03", "卿²¹ç½"), TYPE_04("04", "ç«çä»"), TYPE_99("99", "å ¶ä»"); private String code; private String msg; DepotType(String code, String msg) { this.code = code; this.msg = msg; } public String getCode() { return code; } public String getMsg() { return msg; } public static List<ApiTrigger> list() { List<ApiTrigger> result = new ArrayList<>(); result.add(new ApiTrigger(TYPE_01.getCode(), TYPE_01.getMsg())); result.add(new ApiTrigger(TYPE_02.getCode(), TYPE_02.getMsg())); result.add(new ApiTrigger(TYPE_03.getCode(), TYPE_03.getMsg())); result.add(new ApiTrigger(TYPE_04.getCode(), TYPE_04.getMsg())); result.add(new ApiTrigger(TYPE_99.getCode(), TYPE_99.getMsg())); return result; } } src/main/java/com/fzzy/api/view/pr/ApiTriggerPR.java
@@ -3,6 +3,7 @@ import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.Expose; import com.fzzy.api.Constant; import com.fzzy.api.data.DepotType; import com.fzzy.api.entity.ApiTrigger; import com.fzzy.api.utils.ContextUtil; import com.fzzy.api.view.repository.ApiTriggerRep; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; /** @@ -89,4 +91,14 @@ return null; } /** * ä»åºç±»å * ${dorado.getDataProvider("apiTriggerPR#listDepotType").getResult()} */ @DataProvider public List<ApiTrigger> listDepotType() { return DepotType.list(); } } src/main/java/com/fzzy/gateway/GatewayUtils.java
@@ -2,6 +2,7 @@ import com.fzzy.api.Constant; import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.gateway.data.GrainCableData; import com.fzzy.gateway.entity.GatewayDevice; @@ -147,10 +148,13 @@ String cableCir = gatewayDevice.getCableCir(); GrainCableData result = new GrainCableData(); result.setCableRule(cableRule); result.setCableCir(cableCir); int cableY, cableX; String[] attCable = cableRule.split("-"); int cableZ = Integer.valueOf(attCable[0]); if (StringUtils.isEmpty(cableCir)) { cableY = Integer.valueOf(attCable[1]); cableX = Integer.valueOf(attCable[2]); @@ -159,12 +163,10 @@ cableZ = Integer.valueOf(attCir[0]); cableY = 1; cableX = 0; //é对å¤åè®¡ç® //é对å¤åè®¡ç®æ»è¿å¤å°æ ¹çµç¼ for (int i = 0; i < cableCir.length(); i++) { cableX += Integer.valueOf(attCir[i]); cableX += Integer.valueOf(attCable[i]); } result.setCir(true); } result.setCableY(cableY); @@ -172,6 +174,8 @@ result.setCableX(cableX); result.setSumNum(cableZ * cableY * cableX); result.setTotalCircle(attCable.length); return result; } } src/main/java/com/fzzy/gateway/data/GrainCableData.java
@@ -14,6 +14,14 @@ private int sumNum; private boolean isCir = false; //示ä¾ï¼{\"totalCircle\":3,\"smallCircle\":\"4,10,16\"}ï¼totalCircleï¼æ»åæ°ï¼smallCircleï¼æ¯åæå æ ¹ç¼ private int totalCircle; ////示ä¾ï¼{\"totalCircle\":3,\"smallCircle\":\"4,10,16\"}ï¼totalCircleï¼æ»åæ°ï¼smallCircleï¼æ¯åæå æ ¹ç¼ private String smallCircle; private String cableRule; private String cableCir; } src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
@@ -59,6 +59,10 @@ @PropertyDef(label = "åºåºç³»ç»ä»åºç¼ç ") private String depotIdSys; @Column(name = "DEPOT_TYPE_", length = 10) @PropertyDef(label = "ä»åºç±»å", description = "å¹³æ¿ä»") private String depotType; @Column(name = "IP_", length = 20) @PropertyDef(label = "é讯IP") private String ip; src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java
@@ -1,5 +1,6 @@ package com.fzzy.gateway.hx2023.data; import com.alibaba.fastjson.JSONObject; import lombok.Data; @@ -25,6 +26,6 @@ private String weatherStation; private String properties; private JSONObject properties; } src/main/java/com/fzzy/gateway/hx2023/data/KafaGrainData.java
@@ -1,6 +1,6 @@ package com.fzzy.gateway.hx2023.data; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson.JSONObject; import lombok.Data; src/main/java/com/fzzy/gateway/hx2023/data/KafkaGrainDataDetail1.java
@@ -27,8 +27,7 @@ private String rowy; //æµ åä»ãçä»å¿ å¡«ï¼ç¤ºä¾ï¼{\"totalCircle\":3,\"smallCircle\":\"4,10,16\"}ï¼totalCircleï¼æ»åæ°ï¼smallCircleï¼æ¯åæå æ ¹ç¼ private String total_circle; private String totalCircle; //å ·ä½åæ°--æµ åä»ãçä»å¿ å¡« private String circle; @@ -44,4 +43,15 @@ this.linex = linex; this.rowy = rowy; } public KafkaGrainDataDetail1(String cableNum, String layerNumber, String temperature, String position, String linex, String rowy, String circle, String totalCircle) { this.cableNum = cableNum; this.layerNumber = layerNumber; this.temperature = temperature; this.position = position; this.linex = linex; this.rowy = rowy; this.circle = circle; this.totalCircle = totalCircle; } } src/main/java/com/fzzy/gateway/hx2023/data/WebSocketPacket.java
@@ -1,6 +1,6 @@ package com.fzzy.gateway.hx2023.data; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson.JSONObject; import lombok.Data; @Data src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
@@ -1,8 +1,8 @@ package com.fzzy.gateway.hx2023.service; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson.JSONObject; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.PushProtocol; import com.fzzy.api.utils.NumberUtil; import com.fzzy.async.fzzy40.entity.Fz40Grain; import com.fzzy.data.ConfigData; import com.fzzy.gateway.GatewayUtils; @@ -15,7 +15,6 @@ import com.fzzy.gateway.hx2023.data.*; import com.fzzy.gateway.hx2023.kafka.KafkaDeviceReportService; import com.fzzy.mqtt.MqttGatewayService; import jdk.nashorn.internal.runtime.regexp.joni.Config; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateFormatUtils; @@ -92,7 +91,7 @@ weightInfo.setNetWeight(reqData.getWeight()); weightInfo.setWeightUnit("KG"); JSONObject jsonObject = new JSONObject(); jsonObject.put("weightInfo", JSONObject.toJSONString(weightInfo)); jsonObject.put("weightInfo", weightInfo); packet.setProperties(jsonObject); @@ -170,6 +169,21 @@ BaseResp resp = new BaseResp(); GrainCableData cableData = GatewayUtils.getCableData(device); if (null == device.getDepotType()) device.setDepotType(DepotType.TYPE_01.getCode()); //表示çä» if (DepotType.TYPE_02.getCode().equals(device.getDepotType()) || DepotType.TYPE_04.getCode().equals(device.getDepotType())) { return grainData2GatewayApiInfo2(grainData, device, cableData); } //表示为çä»å æ¬æ²¹ç½ä» if (DepotType.TYPE_03.getCode().equals(device.getDepotType())) { return grainData2GatewayApiInfo3(grainData, device, cableData); } KafaGrainData result = new KafaGrainData(); result.setMessageId(ScConstant.getMessageId()); @@ -179,13 +193,6 @@ result.setMinTemperature(grainData.getTempMin() + ""); result.setMaxTemperature(grainData.getTempMax() + ""); result.setCollectTime(DateFormatUtils.format(grainData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); GrainCableData cableData = GatewayUtils.getCableData(device); if(cableData.isCir()){ return grainData2GatewayApiInfo2(grainData, device,cableData); } //å±è¡å int cableZ = cableData.getCableZ(); @@ -254,7 +261,7 @@ temperatureAndhumidity.add(grainTH); trhInfo.put("temperatureAndhumidity", temperatureAndhumidity); //trhInfo.put("temperatureAndhumidity",grainTH); JSONObject params = new JSONObject(); params.put("TRHInfo", trhInfo); @@ -262,113 +269,265 @@ result.setParams(params); //resp.setObj(result); resp.setData(JSONObject.toJSONString(result)); return resp; } private BaseResp grainData2GatewayApiInfo2(Fz40Grain grainData, GatewayDevice device,GrainCableData cableData) { /** * çä» * * @param grainData * @param device * @param cableData * @return */ private BaseResp grainData2GatewayApiInfo2(Fz40Grain grainData, GatewayDevice device, GrainCableData cableData) { BaseResp resp = new BaseResp(); // int cableZ = cableData.getCableZ(); // int cableY = cableData.getCableY(); // int cableX = cableData.getCableX(); // // int sumNum = cableData.getSumNum(); // // //æ°æ®å°è£ // GrainData grain = new GrainData(); // grain.setMessageId(ScConstant.getMessageId()); // grain.setDeviceId(device.getDeviceId()); // grain.setTimestamp(System.currentTimeMillis() + ""); // // ClientHeaders headers = new ClientHeaders(); // headers.setDeviceName(device.getDeviceName()); // headers.setProductId(device.getProductId()); // headers.setOrgId(device.getOrgId()); // headers.setMsgId(ScConstant.getMessageId()); // grain.setHeaders(headers); // // // GrainOutPut outPut = new GrainOutPut(); // // // double max = com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MAX_TEMP, min = com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MIN_TEMP, sumT = 0.0; // // List<GrainTemp> temperature = new ArrayList<>(); // //æ ¹å· // int cableNum = 1, position = 0; // // double curTemp; // int x = 0, y = 0, z = 0; // for (int i = 0; i < sumNum; i++) { // curTemp = temps.get(i); // position = i; // // z = i % cableZ + 1; // x = i / (cableZ * cableY); // y = x * (cableZ * cableY); // y = (i - y) / cableZ; // //æ ¹å· // cableNum = (i / cableZ) + 1; // // temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + "")); // // //æ±æå¤§æå°å¼ // if (curTemp < -900) { // sumNum--; // } else { // sumT += curTemp; // if (curTemp > max) { // max = curTemp; // } // if (curTemp < min) { // min = curTemp; // } // } // } // // if (sumNum == 0) { // sumNum = 1; // log.warn("---å½åç²®æ ééå¼å¸¸--"); // } // //è¿æ»¤æ¯è¾ç¨çæå¤§æå°å¼ // if (max == com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MAX_TEMP) { // max = 0.0; // } // if (min == com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MIN_TEMP) { // min = 0.0; // } // // outPut.setTemperature(temperature); // outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); // outPut.setMinTemperature(min + ""); // outPut.setMaxTemperature(min + ""); // // // com.alibaba.fastjson.JSONObject properties = new com.alibaba.fastjson.JSONObject(); // properties.put("data", com.alibaba.fastjson.JSONObject.toJSONString(outPut)); // properties.put("timestamp", grain.getTimestamp()); // // String height = this.getCacheHeight(device); // if (org.apache.commons.lang3.StringUtils.isEmpty(height)) height = "0.0"; // properties.put("liquidHeight", height); // // grain.setProperties(properties.toJSONString()); // // //å°è£ å¥½çæ°æ® // log.info("---æµ åä»å°è£ 宿----å¼å§æ§è¡æ¨é"); KafaGrainData result = new KafaGrainData(); result.setMessageId(ScConstant.getMessageId()); result.setMessgeId(result.getMessageId()); result.setDeviceID(device.getDeviceId()); result.setAvgTemperature(grainData.getTempAve() + ""); result.setMinTemperature(grainData.getTempMin() + ""); result.setMaxTemperature(grainData.getTempMax() + ""); result.setCollectTime(DateFormatUtils.format(grainData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); //å±è¡å int cableZ = cableData.getCableZ(); //温度éå String[] attr = grainData.getPoints().split(","); //æ ¹å· int cableNum = 1, position = 0; String curTemp; List<KafkaGrainDataDetail1> temperature = new ArrayList<>(); JSONObject totalCircle = new JSONObject(); totalCircle.put("totalCircle", cableData.getTotalCircle() + ""); totalCircle.put("smallCircle", cableData.getSmallCircle()); String totalCircleStr = totalCircle.toJSONString(); int x = 0, y = 0, z = 0, circle = 1; for (int i = 0; i < attr.length; i++) { position = i; z = i % cableZ + 1; //æ ¹å· cableNum = (i / cableZ) + 1; curTemp = attr[i]; circle = this.getCirCle(position, cableNum, cableData); y = 1; //妿æ¯å¼å¸¸å¼,æ§è¡è°æ´æ°æ® TODO if (Double.valueOf(curTemp) < -99.9) { resp.setCode(BaseResp.CODE_500); resp.setMsg("çä»è§£æææªå®ç°"); curTemp = grainData.getTempAve() + ""; } else { //夿æå¤§ if (curTemp.equals(result.getMaxTemperature())) { result.setMaxX(cableNum + ""); result.setMaxY(y + ""); result.setMaxZ(position + ""); } //夿æå° if (curTemp.equals(result.getMinTemperature())) { result.setMinX(cableNum + ""); result.setMinY(y + ""); result.setMinZ(position + ""); } } temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", null, null, circle + "", totalCircleStr)); } //ç²®æ¸©ä¿¡æ¯ JSONObject trhInfo = new JSONObject(); trhInfo.put("temperature", temperature); //仿¸©åº¦ä¿¡æ¯ KafkaGrainTH grainTH = new KafkaGrainTH(); grainTH.setHumidity(grainData.getHumidityIn() + ""); grainTH.setTemperature(grainData.getTempIn() + ""); grainTH.setAirHumidity(grainData.getHumidityOut() + ""); grainTH.setAirTemperature(grainData.getTempOut() + ""); List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>(); temperatureAndhumidity.add(grainTH); trhInfo.put("temperatureAndhumidity", temperatureAndhumidity); JSONObject params = new JSONObject(); params.put("TRHInfo", trhInfo); result.setParams(params); resp.setData(JSONObject.toJSONString(result)); return resp; } /** * è·åå½ç¹æå¨å * * @param cableNum * @param cableData * @return */ private int getCirCle(int position, int cableNum, GrainCableData cableData) { int num1 = 1, num2 = 2; String[] attCable = cableData.getCableRule().split("-"); if (cableData.getTotalCircle() == 1) return 1; if (cableData.getTotalCircle() == 2) { num1 = Integer.valueOf(attCable[0]); if (cableNum <= num1) return 1; return 2; } if (cableData.getTotalCircle() == 3) { num1 = Integer.valueOf(attCable[0]); num2 = num1 + Integer.valueOf(attCable[1]); if (cableNum <= num1) return 1; if (cableNum <= num2) return 2; return 3; } if (cableData.getTotalCircle() == 4) { num1 = Integer.valueOf(attCable[0]); num2 = num1 + Integer.valueOf(attCable[1]); if (cableNum <= num1) return 1; if (cableNum <= num2) return 2; num2 = num1 + Integer.valueOf(attCable[1]) + Integer.valueOf(attCable[2]); if (cableNum <= num2) return 3; return 4; } return 1; } /** * æ²¹ç½ä»çå¤ç * <p> * 2024å¹´1æ20æ¥ ææ¶ç¨çå¹³æ¿ä»æ¥æ * * @param grainData * @param device * @param cableData * @return */ private BaseResp grainData2GatewayApiInfo3(Fz40Grain grainData, GatewayDevice device, GrainCableData cableData) { BaseResp resp = new BaseResp(); KafaGrainData result = new KafaGrainData(); result.setMessageId(ScConstant.getMessageId()); result.setMessgeId(result.getMessageId()); result.setDeviceID(device.getDeviceId()); result.setAvgTemperature(grainData.getTempAve() + ""); result.setMinTemperature(grainData.getTempMin() + ""); result.setMaxTemperature(grainData.getTempMax() + ""); result.setCollectTime(DateFormatUtils.format(grainData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); //å±è¡å int cableZ = cableData.getCableZ(); int cableY = cableData.getCableY(); int cableX = cableData.getCableX(); //温度éå String[] attr = grainData.getPoints().split(","); //æ ¹å· int cableNum = 1, position = 0; String curTemp; List<KafkaGrainDataDetail1> temperature = new ArrayList<>(); int x = 0, y = 0, z = 0; for (int i = 0; i < attr.length; i++) { position = i; z = i % cableZ + 1; x = i / (cableZ * cableY); y = x * (cableZ * cableY); y = (i - y) / cableZ; // å转Xè½´ x = cableX - 1 - x; //æ ¹å· cableNum = (i / cableZ) + 1; curTemp = attr[i]; //妿æ¯å¼å¸¸å¼,æ§è¡è°æ´æ°æ® TODO if (Double.valueOf(curTemp) < -99.9) { curTemp = grainData.getTempAve() + ""; } else { //夿æå¤§ if (curTemp.equals(result.getMaxTemperature())) { result.setMaxX(x + ""); result.setMaxY(y + ""); result.setMaxZ(position + ""); } //夿æå° if (curTemp.equals(result.getMinTemperature())) { result.setMinX(x + ""); result.setMinY(y + ""); result.setMinZ(position + ""); } } temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", x + "", y + "")); } //ç²®æ¸©ä¿¡æ¯ JSONObject trhInfo = new JSONObject(); // TRHInfo trhInfo = new TRHInfo(); trhInfo.put("temperature", temperature); //仿¸©åº¦ä¿¡æ¯ KafkaGrainTH grainTH = new KafkaGrainTH(); grainTH.setHumidity(grainData.getHumidityIn() + ""); grainTH.setTemperature(grainData.getTempIn() + ""); grainTH.setAirHumidity(grainData.getHumidityOut() + ""); grainTH.setAirTemperature(grainData.getTempOut() + ""); List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>(); temperatureAndhumidity.add(grainTH); trhInfo.put("temperatureAndhumidity", temperatureAndhumidity); JSONObject params = new JSONObject(); params.put("TRHInfo", trhInfo); result.setParams(params); resp.setData(JSONObject.toJSONString(result)); return resp; } src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java
@@ -1,23 +1,27 @@ package com.fzzy.gateway.hx2023.service; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson.JSONObject; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.data.PushProtocol; import com.fzzy.api.utils.DateUtil; import com.fzzy.api.utils.NumberUtil; import com.fzzy.api.utils.RedisConst; import com.fzzy.api.utils.RedisUtil; import com.fzzy.async.fzzy40.Fzzy40CommonService; import com.fzzy.async.fzzy40.entity.Fz40Grain; import com.fzzy.data.ConfigData; import com.fzzy.gateway.GatewayUtils; import com.fzzy.gateway.api.GatewayDeviceTestService; import com.fzzy.gateway.data.BaseReqData; import com.fzzy.gateway.data.BaseResp; import com.fzzy.gateway.data.GrainCableData; import com.fzzy.gateway.data.WeatherWebDto; import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.hx2023.ScConstant; import com.fzzy.gateway.hx2023.data.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang3.RandomUtils; import org.springframework.stereotype.Component; @@ -34,6 +38,11 @@ @Resource private DeviceReportServiceImpl deviceReportService; @Resource private ConfigData configData; @Resource private RedisUtil redisUtil; @Override public String getProtocol() { return PushProtocol.GATEWAY_SC_2023.getCode(); @@ -44,14 +53,120 @@ GatewayDevice device = reqData.getDevice(); if (StringUtils.isEmpty(device.getCableCir())) { if (DepotType.TYPE_02.getCode().equals(device.getDepotType())) { return getGrainTest2(reqData, device); } else if (DepotType.TYPE_04.getCode().equals(device.getDepotType())) { return getGrainTest2(reqData, device); } else if (DepotType.TYPE_03.getCode().equals(device.getDepotType())) { return getGrainTest3(reqData, device); } else { return getGrainTest1(reqData, device); } } private BaseResp getGrainTest2(BaseReqData reqData, GatewayDevice device) { BaseResp resp = new BaseResp(); resp.setCode(500); resp.setMsg("没æå¹é å°è§å"); resp.setMsg("ç仿µè¯ææªå®ç°"); return resp; } private BaseResp getGrainTest3(BaseReqData reqData, GatewayDevice device) { BaseResp resp = new BaseResp(); GrainCableData cableData = GatewayUtils.getCableData(device); int cableZ = cableData.getCableZ(); int cableY = cableData.getCableY(); int sumNum = cableData.getSumNum(); WeatherWebDto weather = WeatherWebDto.contextMap.get("default"); double tMIn = 10, tMax = 15; if (null != weather) { double tOut = Double.valueOf(weather.getTem()); tMIn = tOut - 5; tMax = tOut; } if (tMIn < 10) tMIn = 10; if (tMIn > 20) tMIn = 20; if (tMax < 15) tMax = 15; if (tMax > 25) tMax = 25; //æ°æ®å°è£ GrainData grain = new GrainData(); grain.setMessageId(ScConstant.getMessageId()); grain.setDeviceId(device.getDeviceId()); grain.setTimestamp(System.currentTimeMillis() + ""); grain.setMessageType("REPORT_PROPERTY"); ClientHeaders headers = new ClientHeaders(); headers.setDeviceName(device.getDeviceName()); headers.setProductId(device.getProductId()); headers.setOrgId(device.getOrgId()); headers.setMsgId(reqData.getMessageId()); grain.setHeaders(headers); GrainOutPut outPut = new GrainOutPut(); List<GrainTemp> temperature = new ArrayList<>(); //æ ¹å· int cableNum = 1, position = 0; double curTemp = tMIn; double randomNumber = tMIn; int x = 0, y = 0, z = 0; for (int i = 0; i < sumNum; i++) { randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; curTemp = NumberUtil.keepPrecision(randomNumber, 1); position = i; z = i % cableZ + 1; x = i / (cableZ * cableY); y = x * (cableZ * cableY); y = (i - y) / cableZ; //æ ¹å· cableNum = (i / cableZ) + 1; temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + "")); } outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((tMax + tMIn) / 2, 1) + ""); outPut.setMinTemperature(tMax + ""); outPut.setMaxTemperature(tMIn + ""); JSONObject properties = new JSONObject(); properties.put("data", outPut); properties.put("timestamp", grain.getTimestamp()); String height = this.getCacheHeight(device); if (StringUtils.isEmpty(height)) height = "1.0"; properties.put("liquidHeight", height); grain.setProperties(properties); //å°è£ å¥½çæ°æ® log.info("---æ²¹ç½ä»ä¿¡æ¯å°è£ 宿----å¼å§æ§è¡æ¨é"); return new BaseResp(JSONObject.toJSONString(grain)); } /** * ä»REDISä¸è·åæ¶²ä½é«åº¦ä¿¡æ¯ * * @param device * @return */ private String getCacheHeight(GatewayDevice device) { //ç»å ¶ä»è½¯ä½¿ç¨ String key = RedisConst.KEY_DEPOT_HEIGHT + ":" + configData.getCompanyId() + "_" + device.getDepotIdSys(); return (String) redisUtil.get(key); } @Override @@ -81,110 +196,8 @@ //è·åç¬¬ä¸æ¡æ°æ®æ§è¡æ¨é Fz40Grain lastData = listGrain.get(0); log.info(lastData.toString()); return deviceReportService.grainData2GatewayApiInfo(lastData,device); return deviceReportService.grainData2GatewayApiInfo(lastData, device); } // /** // * å°ç²®æ æ°æ®è½¬æ¢ä¸ºæ¨ééè¦çæ°æ®æ ¼å¼ // * // * @param grainData // * @return // */ // private KafaGrainData lastData2PushData(Fz40Grain grainData, GatewayDevice device) { // KafaGrainData result = new KafaGrainData(); // // result.setMessageId(ScConstant.getMessageId()); // result.setMessgeId(result.getMessageId()); // result.setDeviceID(device.getDeviceId()); // result.setAvgTemperature(grainData.getTempAve() + ""); // result.setMinTemperature(grainData.getTempMin() + ""); // result.setMaxTemperature(grainData.getTempMax() + ""); // result.setCollectTime(DateFormatUtils.format(grainData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); // // //å±-è¡-å // String[] attrCable = grainData.getCable().split("-"); // if (StringUtils.isNotEmpty(grainData.getCableCir())) { // return lastData2PushData2(grainData, device); // } // // //å±è¡å // int cableZ = Integer.valueOf(attrCable[0]); // int cableY = Integer.valueOf(attrCable[1]); // int cableX = Integer.valueOf(attrCable[2]); // // //温度éå // String[] attr = grainData.getPoints().split(","); // // //æ ¹å· // int cableNum = 1, position = 0; // String curTemp; // List<KafkaGrainDataDetail1> temperature = new ArrayList<>(); // // int x = 0, y = 0, z = 0; // for (int i = 0; i < attr.length; i++) { // position = i; // z = i % cableZ + 1; // x = i / (cableZ * cableY); // y = x * (cableZ * cableY); // y = (i - y) / cableZ; // // å转Xè½´ // x = cableX - 1 - x; // //æ ¹å· // cableNum = (i / cableZ) + 1; // curTemp = attr[i]; // // // //妿æ¯å¼å¸¸å¼,æ§è¡è°æ´æ°æ® TODO // if (Double.valueOf(curTemp) < -99.9) { // // curTemp = grainData.getTempAve() + ""; // // } else { // //夿æå¤§ // if (curTemp.equals(result.getMaxTemperature())) { // result.setMaxX(x + ""); // result.setMaxY(y + ""); // result.setMaxZ(position + ""); // } // //夿æå° // if (curTemp.equals(result.getMinTemperature())) { // result.setMinX(x + ""); // result.setMinY(y + ""); // result.setMinZ(position + ""); // } // } // // temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", x + "", y + "")); // } // // //ç²®æ¸©ä¿¡æ¯ // JSONObject trhInfo = new JSONObject(); // // TRHInfo trhInfo = new TRHInfo(); // trhInfo.put("temperature", temperature); // // // //仿¸©åº¦ä¿¡æ¯ // KafkaGrainTH grainTH = new KafkaGrainTH(); // grainTH.setHumidity(grainData.getHumidityIn() + ""); // grainTH.setTemperature(grainData.getTempIn() + ""); // grainTH.setAirHumidity(grainData.getHumidityOut() + ""); // grainTH.setAirTemperature(grainData.getTempOut() + ""); // // List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>(); // temperatureAndhumidity.add(grainTH); // // trhInfo.put("temperatureAndhumidity", temperatureAndhumidity); // //trhInfo.put("temperatureAndhumidity",grainTH); // // JSONObject params = new JSONObject(); // params.put("TRHInfo", trhInfo); // // result.setParams(params); // // return result; // } @Override public BaseResp testWeight(BaseReqData reqData) { @@ -205,8 +218,9 @@ weightInfo.setNetWeight(reqData.getWeight()); weightInfo.setNetWeight(reqData.getWeight()); weightInfo.setWeightUnit("KG"); JSONObject jsonObject = new JSONObject(); jsonObject.put("weightInfo", JSONObject.toJSONString(weightInfo)); jsonObject.put("weightInfo", weightInfo); packet.setProperties(jsonObject); src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
@@ -5,6 +5,7 @@ import com.bstek.dorado.annotation.Expose; import com.fzzy.api.Constant; import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.ContextUtil; import com.fzzy.gateway.GatewayUtils; @@ -70,9 +71,11 @@ if (null == data2.getStatus()) { data.setStatus(Constant.YN_Y); if (GatewayDeviceType.TYPE_07.equals(data2.getType())) { data.setStatus(Constant.YN_N); } } if (null == data2.getDeviceSn()) { @@ -83,6 +86,10 @@ } } if (null == data2.getDepotType()) { data2.setDepotType(DepotType.TYPE_01.getCode()); } if (null == data2.getId()) { data2.setId(ContextUtil.getUUID()); gatewayDeviceRep.save(data2); src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
@@ -1,6 +1,6 @@ package com.fzzy.gateway.service; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson.JSONObject; import com.bstek.dorado.annotation.Expose; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.DateUtil; src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
@@ -149,6 +149,15 @@ <Property></Property> <Property name="label">çµç¼ç±»å</Property> </PropertyDef> <PropertyDef name="depotType"> <Property/> <Property name="label">ä»åºç±»å</Property> <Property name="mapping"> <Property name="mapValues">${dorado.getDataProvider("apiTriggerPR#listDepotType").getResult()}</Property> <Property name="keyProperty">code</Property> <Property name="valueProperty">name</Property> </Property> </PropertyDef> </DataType> <DataType name="dtParam" parent="Map"> <PropertyDef name="start"> @@ -534,6 +543,11 @@ <Editor/> </AutoFormElement> <AutoFormElement> <Property name="name">depotType</Property> <Property name="property">depotType</Property> <Editor/> </AutoFormElement> <AutoFormElement> <Property name="name">cableRule</Property> <Property name="property">cableRule</Property> <Editor/> src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java
@@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSONObject; import com.fzzy.api.Constant; import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.BytesUtil; import com.fzzy.api.utils.NumberUtil; @@ -197,9 +198,6 @@ private void analysisGrain2(IoMessage message, BaseReqData reqData, String grainStr, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); // è·å宿´çç²®æ å ä¿¡æ¯ int cableZ = cableData.getCableZ(); int cableY = cableData.getCableY(); int cableX = cableData.getCableX(); int sumNum = cableData.getSumNum(); // æ ¹æ®å±è¡åè·åæå®é¿åº¦ @@ -240,9 +238,13 @@ String key = "GRAIN_" + message.getAddr(); contextMapGrain.put(key, null); if (cableData.isCir()) { if (DepotType.TYPE_02.getCode().equals(device.getDepotType()) || DepotType.TYPE_04.getCode().equals(device.getDepotType())) { //çä» analysisAndPush2(temps, reqData, thDto, cableData); } else if (DepotType.TYPE_03.getCode().equals(device.getDepotType())) { //卿²¹ç½ analysisAndPush3(temps, reqData, thDto, cableData); } else { //å¹³æ¿ä» analysisAndPush1(temps, reqData, thDto, cableData); @@ -250,18 +252,30 @@ } /** * çä»è§£æï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * ç仿¨é * * @param temps * @param reqData * @param thDto * @param cableData */ private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { //TODO log.info("---------------------------ç仿æ å®ç°---------------------------"); } /** * 卿²¹ç½ * * @param temps * @throws Exception */ private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { private void analysisAndPush3(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); int cableZ = cableData.getCableZ(); int cableY = cableData.getCableY(); int cableX = cableData.getCableX(); int sumNum = temps.size(); @@ -336,17 +350,17 @@ JSONObject properties = new JSONObject(); properties.put("data", JSONObject.toJSONString(outPut)); properties.put("data", outPut); properties.put("timestamp", grain.getTimestamp()); String height = this.getCacheHeight(device); if (StringUtils.isEmpty(height)) height = "0.0"; properties.put("liquidHeight", height); grain.setProperties(properties.toJSONString()); grain.setProperties(properties); //å°è£ å¥½çæ°æ® log.info("---æµ åä»å°è£ 宿----å¼å§æ§è¡æ¨é"); log.info("---æ²¹ç½ä»ä¿¡æ¯å°è£ 宿----å¼å§æ§è¡æ¨é"); reqData.setData(JSONObject.toJSONString(grain)); src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
@@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSONObject; import com.fzzy.api.Constant; import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.BytesUtil; import com.fzzy.api.utils.NumberUtil; @@ -239,22 +240,39 @@ contextMapGrain.put(key, null); if (cableData.isCir()) { if(DepotType.TYPE_03.getCode().equals(device.getDepotType())){ //çä» analysisAndPush3(temps, reqData, thDto, cableData); }else if(DepotType.TYPE_02.getCode().equals(device.getDepotType())){ analysisAndPush2(temps, reqData, thDto, cableData); } else { }else if(DepotType.TYPE_04.getCode().equals(device.getDepotType())){ analysisAndPush2(temps, reqData, thDto, cableData); }else { //å¹³æ¿ä» analysisAndPush1(temps, reqData, thDto, cableData); } } /** * çä»è§£æï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * çä»ï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * @param temps * @param reqData * @param thDto * @param cableData */ private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { //TODO log.info("-------------------------ææªå®ç°----------------"); } /** * æ²¹ç½ä»ï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® * * @param temps * @throws Exception */ private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { private void analysisAndPush3(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); @@ -335,14 +353,14 @@ JSONObject properties = new JSONObject(); properties.put("data", JSONObject.toJSONString(outPut)); properties.put("data", outPut); properties.put("timestamp", grain.getTimestamp()); String height = this.getCacheHeight(device); if (StringUtils.isEmpty(height)) height = "0.0"; properties.put("liquidHeight", height); grain.setProperties(properties.toJSONString()); grain.setProperties(properties); //å°è£ å¥½çæ°æ® log.info("---æµ åä»å°è£ 宿----å¼å§æ§è¡æ¨é"); velocity.log