cjl
2023-08-22 58fdbd07beae496c4c3b0744efe86a7d82e382b7
screen-api/src/main/java/com/moral/api/service/impl/AlarmInfoServiceImpl.java
@@ -16,10 +16,7 @@
import org.springframework.util.ObjectUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -94,30 +91,30 @@
            String index = parameters.get("index").toString();
            if (!index.equals("all")){
                map.put("index",index);
                alarmInfoQueryWrapper.eq("index", index);
                alarmInfoQueryWrapper.eq("`index`", index);
            }
            String alarmType = parameters.get("alarmType").toString();
            switch (alarmType){
                case "超限" : map.put("alarmType","超限");
                    alarmInfoQueryWrapper.eq("alarmType","超限");
                case "overrun" : map.put("alarmType","超限");
                    alarmInfoQueryWrapper.eq("alarm_type","超限");
                    break;
                case "突然高" : map.put("alarmType","突然高");
                    alarmInfoQueryWrapper.eq("alarmType","突然高");
                case "sudden" : map.put("alarmType","突然高");
                    alarmInfoQueryWrapper.eq("alarm_type","突然高");
                    break;
                case "国控站100" : map.put("alarmType","超过国控站点100%");
                    alarmInfoQueryWrapper.eq("alarmType","超过国控站点100%");
                case "state100" : map.put("alarmType","超过国控站点100%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点100%");
                    break;
                case "国控站150" : map.put("alarmType","超过国控站点150%");
                    alarmInfoQueryWrapper.eq("alarmType","超过国控站点150%");
                case "state150" : map.put("alarmType","超过国控站点150%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点150%");
                    break;
                case "国控站250" : map.put("alarmType","超过国控站点250%");
                    alarmInfoQueryWrapper.eq("alarmType","超过国控站点250%");
                case "state250" : map.put("alarmType","超过国控站点250%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点250%");
                    break;
                case "市区均值150" : map.put("alarmType","超过市区均值150%");
                    alarmInfoQueryWrapper.eq("alarmType","超过市区均值150%");
                case "city150" : map.put("alarmType","超过市区均值150%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过市区均值150%");
                    break;
                case "市区均值250" : map.put("alarmType","超过市区均值250%");
                    alarmInfoQueryWrapper.eq("alarmType","超过市区均值250%");
                case "city250" : map.put("alarmType","超过市区均值250%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过市区均值250%");
                    break;
                default:break;
            }
@@ -143,10 +140,10 @@
    }
    @Override
    public Map<String, Object> alarmReminder(Map<String, Object> parameters) {
        Map<String,Object> resultMap = new HashMap<>();
    public Map<String, Object> getDataByConditionWithoutPage(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        //定义一个集合,存放所有id
       /* //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
@@ -175,6 +172,139 @@
            }else {
                continue;
            }
        }*/
        List<Integer> deviceIdList = deviceMapper.deviceIdList(orgId);
        if (deviceIdList.size()>0){
            Map<String, Object> map = new HashMap<>();
            QueryWrapper<AlarmInfo> alarmInfoQueryWrapper = new QueryWrapper<>();
            map.put("deviceIds",deviceIdList);
            alarmInfoQueryWrapper.in("device_id",deviceIdList);
            String startTime = parameters.get("startTime")+" 00:00:00";
            String endTime = parameters.get("endTime")+" 23:59:59";
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            alarmInfoQueryWrapper.between("alarm_time", startTime, endTime);
            String index = parameters.get("index").toString();
            if (!index.equals("all")){
                map.put("index",index);
                alarmInfoQueryWrapper.eq("`index`", index);
            }
            String alarmType = parameters.get("alarmType").toString();
            switch (alarmType){
                case "overrun" : map.put("alarmType","超限");
                    alarmInfoQueryWrapper.eq("alarm_type","超限");
                    break;
                case "sudden" : map.put("alarmType","突然高");
                    alarmInfoQueryWrapper.eq("alarm_type","突然高");
                    break;
                case "state100" : map.put("alarmType","超过国控站点100%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点100%");
                    break;
                case "state150" : map.put("alarmType","超过国控站点150%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点150%");
                    break;
                case "state250" : map.put("alarmType","超过国控站点250%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过国控站点250%");
                    break;
                case "city150" : map.put("alarmType","超过市区均值150%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过市区均值150%");
                    break;
                case "city250" : map.put("alarmType","超过市区均值250%");
                    alarmInfoQueryWrapper.eq("alarm_type","超过市区均值250%");
                    break;
                default:break;
            }
            List<Map<String, Object>> resultList = alarmInfoMapper.selectDataByConditionWithoutPage(map);
            SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (Map<String, Object> alarmInfo:resultList) {
                String alarm_time = SDF.format(alarmInfo.get("alarm_time"));
                alarmInfo.put("alarm_time",alarm_time);
            }
            Integer totalNumber = alarmInfoMapper.selectCount(alarmInfoQueryWrapper);
            resultMap.put("alarmInfos", resultList);
            return resultMap;
        }
        return null;
    }
    @Override
    public Map<String, Object> alarmReminder(Map<String, Object> parameters) {
        Map<String,Object> resultMap = new HashMap<>();
        int orgId = Integer.parseInt(parameters.get("organization_id").toString());
        /*//定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        //声明一个list,存放设备id
        List<Integer> deviceIdList = new ArrayList<>();
        for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
            //根据id查询所属设备
            QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
            wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
            List<Device> devices = new ArrayList<>();
            devices = deviceMapper.selectList(wrapper_device);
            if (devices.size()>0){
                for (Device device:devices) {
                    int deviceId = device.getId();
                    deviceIdList.add(deviceId);
                }
            }else {
                continue;
            }
        }*/
      //  if (deviceIdList.size()>0){
            Map<String, Object> map = new HashMap<>();
            //map.put("deviceIds",deviceIdList);
            int size = Integer.parseInt(parameters.get("size").toString());
            map.put("size",size);
            map.put("orgId",orgId);
            List<Map<String, Object>> resultList = alarmInfoMapper.selectNewestData(map);
            SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (Map<String, Object> alarmInfo:resultList) {
                String alarm_time = SDF.format(alarmInfo.get("alarm_time"));
                alarmInfo.put("alarm_time",alarm_time);
            }
            resultMap.put("alarmInfors",resultList);
            Integer totalNumber = alarmInfoMapper.numNews(orgId);
            /*QueryWrapper<AlarmInfo> alarmInfoQueryWrapper = new QueryWrapper<>();
            alarmInfoQueryWrapper.in("device_id",deviceIdList);
            Integer totalNumber = alarmInfoMapper.selectCount(alarmInfoQueryWrapper);*/
            resultMap.put("totalNumber",totalNumber);
            return resultMap;
       // }
       // return null;
    }
    @Override
    public Map<String, Object> alarmReminderByMonitorPointIds(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<>();
        String monitorPointIds = parameters.get("monitorPointIds").toString();
        monitorPointIds.replace("[","");
        monitorPointIds.replace("]","");
        String[] monitorPointIdArray = monitorPointIds.split(",");
        List<String> monitorPointIdList = new ArrayList<>(Arrays.asList(monitorPointIdArray));
        //声明一个list,存放设备id
        List<Integer> deviceIdList = new ArrayList<>();
        //根据id查询所属设备
        QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
        wrapper_device.eq("is_delete",Constants.NOT_DELETE);
        wrapper_device.in("monitor_point_id",monitorPointIdList);
        List<Device> devices = new ArrayList<>();
        devices = deviceMapper.selectList(wrapper_device);
        if (devices.size()>0){
            for (Device device:devices) {
                int deviceId = device.getId();
                deviceIdList.add(deviceId);
            }
        }
        if (deviceIdList.size()>0){
            Map<String, Object> map = new HashMap<>();