jiazx0107@163.com
2024-01-20 fbcbe6c975554786683c38798ce8527d27993543
测试调整筒仓的逻辑
已删除1个文件
已添加1个文件
已修改15个文件
794 ■■■■■ 文件已修改
src/main/java/com/fzzy/api/data/DepotType.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/view/pr/ApiTriggerPR.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/GatewayUtils.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/data/GrainCableData.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/KafaGrainData.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/KafkaGrainDataDetail1.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/WebSocketPacket.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java 369 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java 230 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
velocity.log 补丁 | 查看 | 原始文档 | blame | 历史
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(&quot;apiTriggerPR#listDepotType&quot;).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