aijinhui
2023-10-07 8c8af4faa4303499fe9e81dd117932e246008eb0
ard-work/src/main/java/com/ruoyi/statistical/service/impl/StatisticalServiceImpl.java
@@ -1,16 +1,30 @@
package com.ruoyi.statistical.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.alarm.access.mapper.ArdAlarmAccessMapper;
import com.ruoyi.alarm.apponekey.mapper.ArdAlarmApponekeyMapper;
import com.ruoyi.alarm.camera.mapper.ArdAlarmCameraMapper;
import com.ruoyi.alarm.digitization3.mapper.ArdAlarmDigitization3Mapper;
import com.ruoyi.alarm.external.mapper.ArdAlarmExternalMapper;
import com.ruoyi.alarm.radar.mapper.ArdAlarmRadarFireMapper;
import com.ruoyi.alarm.radar.mapper.ArdAlarmRadarMoveMapper;
import com.ruoyi.alarm.steal.mapper.ArdAlarmStealelecMapper;
import com.ruoyi.alarm.tube.mapper.ArdAlarmTubeMapper;
import com.ruoyi.alarm.wall.mapper.ArdAlarmWallMapper;
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
import com.ruoyi.common.core.domain.entity.SysConfig;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.statistical.param.ESParam;
import com.ruoyi.statistical.service.StatisticalService;
import com.ruoyi.statistical.vo.CountVo;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.utils.result.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
@@ -23,6 +37,27 @@
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private ArdAlarmpointsWellMapper wellMapper;
    @Autowired
    private ArdAlarmStealelecMapper stealelecMapper;
    @Autowired
    private ArdAlarmCameraMapper cameraMapper;
    @Autowired
    private ArdAlarmRadarMoveMapper moveMapper;
    @Autowired
    private ArdAlarmRadarFireMapper fireMapper;
    @Autowired
    private ArdAlarmExternalMapper externalMapper;
    @Autowired
    private ArdAlarmAccessMapper accessMapper;
    @Autowired
    private ArdAlarmApponekeyMapper apponekeyMapper;
    @Autowired
    private ArdAlarmWallMapper wallMapper;
    @Autowired
    private ArdAlarmDigitization3Mapper digitization3Mapper;
    @Autowired
    private ArdAlarmTubeMapper tubeMapper;
    @Override
    public Results factorySave(Map<String, String> map) {
@@ -69,26 +104,110 @@
                }
            }
        }
        //记录well表中oil_production为抽油机的数据有多少条
        QueryWrapper<ArdAlarmpointsWell> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("oil_production","抽油机");
        int num = wellMapper.selectCount(queryWrapper);
        SysConfig sysConfigUpd = sysConfigMapper.checkConfigKeyUnique("well");
        if(sysConfigUpd!=null){
            sysConfigUpd.setConfigValue(String.valueOf(num));
            sysConfigUpd.setUpdateBy(SecurityUtils.getUsername());
            sysConfigMapper.updateConfig(sysConfigUpd);
        }else {
            SysConfig sysConfig = new SysConfig();
            int randomNum = (int) (Math.random() * (1000 - 1 + 1)) + 1;
            sysConfig.setConfigId((long) randomNum);
            sysConfig.setConfigType("Y");
            sysConfig.setConfigName("抽水井");
            sysConfig.setConfigKey("well");
            sysConfig.setConfigValue(String.valueOf(num));
            sysConfig.setCreateBy(SecurityUtils.getUsername());
            sysConfigMapper.insertConfig(sysConfig);
        }
        return Results.succeed("添加成功!");
    }
    @Override
    public Results factorySelect() {
        JSONObject jsonObject = new JSONObject();
        QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("config_key","area","store","people","well","depot","unit");
        List<SysConfig> list = sysConfigMapper.selectList(queryWrapper);
        for (int i = 0; i < list.size(); i++) {
            SysConfig sysConfig = list.get(i);
            jsonObject.put(sysConfig.getConfigKey(),sysConfig.getConfigValue());
        }
        //记录well表中oil_production为抽油机的数据有多少条
        QueryWrapper<ArdAlarmpointsWell> queryWrapperWell = new QueryWrapper<>();
        queryWrapperWell.eq("oil_production","抽油机");
        int num = wellMapper.selectCount(queryWrapperWell);
        jsonObject.put("well",String.valueOf(num));
        return Results.succeed(jsonObject);
    }
    @Override
    public List<CountVo> stealelecYear(ESParam esParam) {
        List<CountVo> list = stealelecMapper.stealelecYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> cameraYear(ESParam esParam) {
        List<CountVo> list = cameraMapper.cameraYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> moveYear(ESParam esParam) {
        List<CountVo> list = moveMapper.moveYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> fireYear(ESParam esParam) {
        List<CountVo> list = fireMapper.fileYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> externalYear(ESParam esParam) {
        List<CountVo> list = externalMapper.externalYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> accessYear(ESParam esParam) {
        List<CountVo> list = accessMapper.accessYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> apponekeyYear(ESParam esParam) {
        List<CountVo> list = apponekeyMapper.apponekeyYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> wallYear(ESParam esParam) {
        List<CountVo> list = wallMapper.wallYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> digitizationYear(ESParam esParam) {
        List<CountVo> list = digitization3Mapper.digitizationYear(esParam);
        return es(list);
    }
    @Override
    public List<CountVo> tubeYear(ESParam esParam) {
        List<CountVo> list = tubeMapper.tubeYear(esParam);
        return es(list);
    }
    public List<CountVo> es(List<CountVo> list){
        for (int i = 1; i <= 12 ; i++) {
            String month = null;
            if(i<=10){
                month = "0"+i;
            }else {
                month = String.valueOf(i);
            }
            Boolean bo = false;
            for (int j = 0; j < list.size(); j++) {
                CountVo countVo = list.get(j);
                String mon = countVo.getMonth();
                if(mon.equals(month)){
                    bo = true;
                }
            }
            if(!bo){
                CountVo countVo = new CountVo();
                countVo.setMonth(month);
                countVo.setCount(0);
                list.add(countVo);
            }
        }
        return list;
    }
}