jiazx0107@163.com
2023-12-05 ebaaa34038ebda73630c9ab82465c5f76692b5c2
提交粮情协议2,完成
已删除1个文件
已修改5个文件
213 ■■■■ 文件已修改
src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java 154 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java
ÎļþÒÑɾ³ý
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java
@@ -2,7 +2,17 @@
import com.alibaba.fastjson.JSONObject;
import com.fzzy.api.data.ApiCommonDevice;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.NumberUtil;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.api.GatewayDeviceReportService;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
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 com.fzzy.protocol.fzzy.builder.SimpleCommandBuilder;
import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl;
import com.fzzy.protocol.fzzy.data.ReMessage;
@@ -10,7 +20,12 @@
import com.fzzy.protocol.fzzy.resp.Response2102;
import com.fzzy.protocol.fzzy.server.ServerUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
 * ç²®æƒ…解析
@@ -20,6 +35,9 @@
@Slf4j
@Component(AnalysisGrain.BEAN_ID)
public class AnalysisGrain extends BaseRemoteImpl {
    @Resource
    private GatewayRemoteManager gatewayRemoteManager;
    public static final String BEAN_ID = "fzzy.analysisGrain";
@@ -48,14 +66,16 @@
            Response2102 response = JSONObject.parseObject(reMessage.getContent(), Response2102.class);
            String depotId = response.getHouseId();
            //获取请求信息
            BaseReqData reqData = ServerUtils.getSyncReq(depotId);
            //粮情解析
            log.info("控制柜--->平台粮情信息--{}", response);
            log.info("控制柜--->平台,推动的粮情信息--{}", response);
            //粮情封装和处理
            if (StringUtils.isEmpty(response.getLayerPerCircle())) {
                buildBizInfo1(response);
            } else {
                buildBizInfo2(response);
            }
        } catch (Exception e) {
@@ -65,6 +85,128 @@
        }
    }
    private void buildBizInfo2(Response2102 response) {
        //TODO ç­’仓的封装解析待处理
    }
    //信息调整封装
    private void buildBizInfo1(Response2102 response) {
        String depotId = response.getHouseId();
        //获取请求信息
        BaseReqData reqData = ServerUtils.getSyncReq(depotId);
        if (null == reqData) {
            log.error("--粮情封装解析,未获取到请求相关参数----");
            return;
        }
        int cableZ = Integer.valueOf(response.getLay());
        int cableY = Integer.valueOf(response.getRow());
        int cableX = Integer.valueOf(response.getCol());
        GatewayDevice device = reqData.getDevice();
        //数据封装
        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(reqData.getMessageId());
        grain.setHeaders(headers);
        GrainOutPut outPut = new GrainOutPut();
        outPut.setAvgTemperature(response.getTAvg() + "");
        outPut.setMinTemperature(response.getTMin() + "");
        outPut.setMaxTemperature(response.getTMax() + "");
        List<GrainTemp> temperature = new ArrayList<>();
        //根号
        int cableNum = 1, position = 0;
        double curTemp = response.getTMin();
        String[] attr = response.getPoints().split(",");
        int x = 0, y = 0, z = 0;
        for (int i = 0; i < attr.length; i++) {
            curTemp = Double.valueOf(attr[i]);
            if (curTemp < -900) {
                curTemp = ERROR_CHECK_TAG;
            }
            //数据优化
            if (curTemp > 35) {
                curTemp = response.getTAvg();
            }
            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);
        grain.setOutput(com.alibaba.fastjson2.JSONObject.toJSONString(outPut));
        GatewayDevice gatewayDeviceWeather = GatewayUtils.getCacheByDeviceTypeOne(GatewayDeviceType.TYPE_09.getCode());
        //系统气象站信息
        WeatherWebDto weather = WeatherWebDto.contextMap.get("default");
        //气象信息
        GrainWeather weatherStation = new GrainWeather();
        weatherStation.setMessageId(ScConstant.getMessageId());
        weatherStation.setMessgeId(weatherStation.getMessageId());
        if (null != gatewayDeviceWeather) {
            weatherStation.setId(gatewayDeviceWeather.getDeviceId());
        } else {
            weatherStation.setId(device.getDeviceId());
        }
        weatherStation.setAirPressure(weather.getPressure());
        weatherStation.setHumidity(weather.getHumidity());
        weatherStation.setPm(weather.getAir_pm25());
        weatherStation.setRadiation("0");
        weatherStation.setRainfallAmount(weather.getWea());
        weatherStation.setTemperature(weather.getTem());
        weatherStation.setWindDirection(weather.getWin());
        weatherStation.setWindPower(weather.getWin_meter());
        weatherStation.setWindSpeed(weather.getWin_speed());
        grain.setWeatherStation(JSONObject.toJSONString(weatherStation));
        //封装好的数据
        log.info("---粮情机械封装完成----开始执行推送");
        reqData.setData(JSONObject.toJSONString(grain));
        doPushGrain(reqData);
    }
    private void doPushGrain(BaseReqData reqData) {
        GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol());
        if (null == reportService) {
            log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", reqData.getDevice().getDeviceName());
        }
        reportService.reportGrainData(reqData);
    }
    private void returnMsg(ApiCommonDevice ser) {
        //先回复控制柜
        SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java
@@ -46,14 +46,12 @@
                return;
            }
            //执行的分机信息
            ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getSn());
            if (null == commonDevice) {
                log.warn("控制柜------>>>平台:当前组织编码={},分机ID={},系统没有获取到分机信息,报文无法进行解析", message.getCompanyId(), message.getIedId());
                return;
            }
            //根据接口编号进行解析路由
            switch (message.getFunctionId()) {
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java
@@ -49,7 +49,7 @@
        SendMessage message = commandBuilder.buildMessage(reMessage, ServerUtils.FUNCTION_1001, response);
        send(message);
        log.info("控制柜----->>>平台:控制柜上线登陆成功-IP={},PORT={}", reMessage.getIp(), reMessage.getPort());
        log.info("控制柜----->>>平台,控制柜登陆解析完成-报文-{}", reMessage);
    }
    public void analysis1003(ReMessage reMessage, ApiCommonDevice ser) {
src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java
@@ -43,19 +43,19 @@
            reMessage.setStrMsg(message);
            session.setCompanyId("0000");
            log.info("控制柜------>>>>平台:IP={},PORT={},message={}", reMessage.getIp(), reMessage.getPort(), message);
            log.debug("控制柜到---->>>>平台,未解析信息:IP={},PORT={},message={}", reMessage.getIp(), reMessage.getPort(), message);
            //调用解析接口开始解析
            if (null == analysisService) {
                analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID);
            }
            analysisService.analysis(reMessage);
        } catch (Exception e) {
            log.error("控制柜------>>>>平台:收到报文解析异常:{}", e.getMessage());
            e.printStackTrace();
        }
        //调用解析接口开始解析
        if (null == analysisService) {
            analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID);
        }
        analysisService.analysis(reMessage);
    }
}
src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java
@@ -10,7 +10,7 @@
    @Override
    public void onCreate(IoSession session) {
        log.info("++++FZZY-控制柜上线++++-IP={},PORT={}", session.getAddress(), session.getPort());
        log.info("++++FZZY-控制个协议有新设备连接++++-IP={},PORT={}", session.getAddress(), session.getPort());
        // æ·»åŠ è‡ªå®šä¹‰ä¸šåŠ¡ID
        session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort()));
@@ -19,6 +19,6 @@
    @Override
    public void onDestroy(IoSession session) {
        log.info("----FZZY-控制柜离线-----IP={},PORT={}", session.getAddress(), session.getPort());
        log.info("----FZZY-控制个协议有设备离线-----IP={},PORT={}", session.getAddress(), session.getPort());
    }
}