Newer
Older
device-data-creator / src / main / java / com / casic / service / impl / DayDataProvider.java
chaizhuang on 17 May 2023 4 KB 中海油新增
package com.casic.service.impl;

import com.casic.config.DeviceTypeConfig;
import com.casic.dao.*;
import com.casic.entity.*;
import com.casic.service.DayDataService;
import com.casic.util.SnowBizPhyId;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

@Service
public class DayDataProvider implements DayDataService {

    @Resource
    private DayDataDao dayDataDao;
    @Resource
    private HydrantDataMapper hydrantDataMapper;
    @Resource
    private WellInfoDao wellInfoDao;
    @Resource
    private LiquidDataMapper liquidDataMapper;
    @Resource
    private NoiseDataMapper noiseDataMapper;
    @Resource
    private HarmfulDataMapper harmfulDataMapper;
    @Resource
    private DeviceTypeConfig deviceTypeConfig;


    @Override
    public void nextDayData() {
        String[] deviceTypeList = deviceTypeConfig.getDayTypes().split(",");
        for (String deviceType : deviceTypeList) {
            List<Map<String, String>> devcodeList = dayDataDao.getListDevcodeByType(deviceType);
            devcodeList.stream().forEach(
                    devcodeMap -> {
                        String devcode = deviceType == "7" ? devcodeMap.get("DBID") : devcodeMap.get("DEVCODE");
                        deviceManger(deviceType, devcode);
                    }
            );
        }
    }

    //噪声是1  液位是5  有害气体是 7  消防栓是 14
    private void deviceManger(String deviceType, String devcode) {
        switch (deviceType) {
            case "1":
                noiseDataCreator(devcode);
                break;
            case "5":
                liquidDataCreator(devcode);
                break;
            case "7":
                harmfulDataCreator(devcode);
                break;
            case "13":
                wellDataCreator(devcode);
                break;
            case "14":
                hydrantDataCreator(devcode);
                break;
        }
    }

    private Random random = new Random();

    private void wellDataCreator(String devcode) {
        WellInfo wellInfo = new WellInfo();
        wellInfo.setDbid(SnowBizPhyId.getBizPhyId());
        wellInfo.setDevcode(devcode);
        wellInfo.setDescn("状态正常");
        wellInfo.setCell("96");
        wellInfo.setStatus("0");
        wellInfo.setLogtime(new Date());
        wellInfoDao.insert(wellInfo);
    }

    private void hydrantDataCreator(String devcode) {
        HydrantData hydrantData = new HydrantData();
        hydrantData.setDbid(SnowBizPhyId.getBizPhyId());
        hydrantData.setDevcode(devcode);
        hydrantData.setDescn("状态正常");
        hydrantData.setCell("98");
        hydrantData.setStatus("0");
        hydrantData.setLogtime(new Date());
        hydrantDataMapper.insert(hydrantData);
    }

    private void harmfulDataCreator(String devcode) {
        HarmfulData harmfulData = new HarmfulData();
        harmfulData.setDbid(SnowBizPhyId.getBizPhyId());
        harmfulData.setCo("0");
        harmfulData.setDevid(devcode);
        harmfulData.setFiregas("0.0");
        harmfulData.setH2s("0");
        harmfulData.setO2("21.0");
        harmfulData.setUptime(new Date());
        harmfulData.setIsopen("0");
        harmfulDataMapper.insert(harmfulData);
    }

    private void noiseDataCreator(String devcode) {
        NoiseData noiseData = new NoiseData();
        DecimalFormat df = new DecimalFormat("0.0000");
        noiseData.setDbid(SnowBizPhyId.getBizPhyId());
        noiseData.setDevcode(devcode);
        noiseData.setCell("95");
        noiseData.setDdata(df.format(random.nextDouble()));
        noiseData.setFrequency(String.valueOf(random.nextInt(2000)));
        noiseData.setLogtime(new Date());
        noiseData.setUptime(new Date());
        noiseDataMapper.insert(noiseData);
    }

    private void liquidDataCreator(String devcode) {
        LiquidData liquidData = new LiquidData();
        DecimalFormat df = new DecimalFormat("0.00");
        liquidData.setDbid(SnowBizPhyId.getBizPhyId());
        liquidData.setDevcode(devcode);
        liquidData.setCell("92");
        liquidData.setLiquiddata(df.format(random.nextDouble()*5));
        liquidData.setLogtime(new Date());
        liquidData.setUptime(new Date());
        liquidDataMapper.insert(liquidData);
    }


}