jiazx0107@163.com
2023-12-24 66b091963fb0f3356f27ec094c013369bf91db89
src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java
@@ -1,12 +1,13 @@
package com.fzzy.gateway.hx2023.service;
import com.alibaba.fastjson2.JSONObject;
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.async.fzzy40.Fzzy40CommonService;
import com.fzzy.async.fzzy40.entity.Fz40Grain;
import com.fzzy.gateway.api.GatewayDeviceReportService;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.api.GatewayDeviceTestService;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
@@ -17,6 +18,7 @@
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;
import javax.annotation.Resource;
@@ -234,6 +236,8 @@
    public BaseResp testLpr(BaseReqData reqData) {
        GatewayDevice device = reqData.getDevice();
        WebSocketPacket packet = new WebSocketPacket();
        WebSocketPacketHeader header = new WebSocketPacketHeader();
        header.setDeviceName(reqData.getDeviceName());
@@ -249,7 +253,7 @@
        lpr.setCarNumber(reqData.getCarNumber());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("carNumber", reqData.getCarNumber());
        jsonObject.put("position", "big");
        jsonObject.put("position", device.getPosition());
        packet.setProperties(jsonObject);
        packet.setTimestamp(System.currentTimeMillis());
@@ -268,15 +272,16 @@
        WeatherWebDto weather = WeatherWebDto.contextMap.get("default");
        double tMIn = 20, tMax = 25;
        double tMIn = 10, tMax = 15;
        if (null != weather) {
            double tOut = Double.valueOf(weather.getTem());
            tMIn = tOut - 4;
            if (tMIn < 4) tMIn = 5;
            tMax = tOut + 0;
            if (tMax < 15) tMax = 15;
            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();
@@ -288,7 +293,7 @@
        headers.setDeviceName(device.getDeviceName());
        headers.setProductId(device.getProductId());
        headers.setOrgId(device.getOrgId());
        headers.setMsgId(ScConstant.getMessageId());
        headers.setMsgId(reqData.getMessageId());
        grain.setHeaders(headers);
        GrainOutPut outPut = new GrainOutPut();
@@ -306,24 +311,22 @@
        double randomNumber = tMIn;
        int x = 0, y = 0, z = 0;
        for (int i = 0; i < sumNum; i++) {
            if ((i) % Integer.valueOf(cableRule[0]) == 0) {
                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            } else if ((i) % Integer.valueOf(cableRule[0]) == 1) {
                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            } else if ((i) % Integer.valueOf(cableRule[0]) == 2) {
                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            } else if ((i) % Integer.valueOf(cableRule[0]) == 3) {
                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            } else if ((i) % Integer.valueOf(cableRule[0]) == 4) {
                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            } else {
                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            log.info("i=:" + i);
            if (i % cableZ == 0) {
                randomNumber = RandomUtils.nextDouble(tMIn, tMax+1.5);
                log.info("第1层温度:" + randomNumber);
            } else if (i % cableZ == 1)  {
                randomNumber = RandomUtils.nextDouble(tMIn-1, tMax-0);
                log.info("第2层温度:" + randomNumber);
            } else if (i % cableZ == 2)  {
                randomNumber = RandomUtils.nextDouble(tMIn-2, tMax-1.5);
                log.info("第3层温度:" + randomNumber);
            } else if (i % cableZ == 3)  {
                randomNumber = RandomUtils.nextDouble(tMIn-3, tMax-3);
                log.info("第4层温度:" + randomNumber);
            } else if (i % cableZ == 4)  {
                randomNumber = RandomUtils.nextDouble(tMIn-4, tMax-4.5);
                log.info("第5层温度:" + randomNumber);
            }
            // randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
            curTemp = NumberUtil.keepPrecision(randomNumber, 1);
@@ -340,13 +343,26 @@
        }
        outPut.setTemperature(temperature);
        List<GrainTH> ths = new ArrayList<>();
        grain.setOutPut(outPut);
        ths.add(new GrainTH(weather.getTem()!=null?weather.getTem()+"":"",weather.getHumidity()!=null?weather.getHumidity()+"":"","1"));
        outPut.setTemperatureAndhumidity(ths);
        grain.setOutput(JSONObject.toJSONString(outPut));
        GatewayDevice gatewayDeviceWeather = GatewayUtils.getCacheByDeviceTypeOne(GatewayDeviceType.TYPE_09.getCode());
        //气象信息
        GrainWeather weatherStation = new GrainWeather();
        weatherStation.setMessageId(ScConstant.getMessageId());
        weatherStation.setId(device.getDeviceId());
        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());
@@ -356,7 +372,7 @@
        weatherStation.setWindDirection(weather.getWin());
        weatherStation.setWindPower(weather.getWin_meter());
        weatherStation.setWindSpeed(weather.getWin_speed());
        grain.setWeatherStation(weatherStation);
        grain.setWeatherStation(JSONObject.toJSONString(weatherStation));
        return new BaseResp(JSONObject.toJSONString(grain));
    }