jiazx0107@163.com
2024-01-19 6a9cf62f7ca4b45c48a571c63fd484c186070a0e
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
@@ -2,11 +2,14 @@
import com.alibaba.fastjson2.JSONObject;
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;
import com.fzzy.gateway.api.GatewayDeviceReportService;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.data.GrainCableData;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.hx2023.data.*;
@@ -177,16 +180,17 @@
        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 grainData2GatewayApiInfo2(grainData, device);
        GrainCableData cableData = GatewayUtils.getCableData(device);
        if(cableData.isCir()){
            return grainData2GatewayApiInfo2(grainData, device,cableData);
        }
        //层行列
        int cableZ = Integer.valueOf(attrCable[0]);
        int cableY = Integer.valueOf(attrCable[1]);
        int cableX = Integer.valueOf(attrCable[2]);
        int cableZ = cableData.getCableZ();
        int cableY = cableData.getCableY();
        int cableX = cableData.getCableX();
        //温度集合
        String[] attr = grainData.getPoints().split(",");
@@ -265,8 +269,104 @@
        return resp;
    }
    private BaseResp grainData2GatewayApiInfo2(Fz40Grain grainData, GatewayDevice device) {
    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("---浅圆仓封装完成----开始执行推送");
        resp.setCode(BaseResp.CODE_500);
        resp.setMsg("筒仓解析暂未实现");
        return resp;