AlarmStatisticsController.java 6.5 KB
package com.skua.modules.controller;

import com.google.common.collect.Lists;
import com.skua.modules.alarmtmp.service.AlarmRecordHistoryService;
import com.skua.modules.alarmtmp.vo.AlarmStatisticsTypeVO;
import com.skua.modules.alarmtmp.vo.AlarmStatisticsVO;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.modules.system.service.ISysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Description 报警统计控制层
 * @Date 2020-12-16 17:08
 * @Param
 * @return
 **/
@Slf4j
@RestController
@RequestMapping("/alarm/statistics")
@Api(tags = "报警统计页面")
public class AlarmStatisticsController {


    @Autowired
    private AlarmRecordHistoryService alarmRecordHistoryService;
    @Autowired
    private ISysDictService sysDictService;


    /**
     * 报警处理情况分页列表查询
     */
    @AutoLog(value = "报警处理情况列表查询")
    @ApiOperation(value = "报警处理情况列表查询", notes = "报警处理情况列表查询")
    @GetMapping(value = "/getAlarmDealList")
    public Result<List<AlarmStatisticsVO>> getAlarmDealList(String startTime, String endTime, String departId) {

        Result<List<AlarmStatisticsVO>> result = new Result<>();
        List<AlarmStatisticsVO> data = Lists.newArrayList();
        DecimalFormat df = new DecimalFormat("#.##%");
        String[] split = departId.split(",");
        List<String> ids = Arrays.asList(split);
        //获取全部报警工单
        List<Map<String, Object>> allData = alarmRecordHistoryService.getAlarmRecordHistoryAll(startTime, endTime, ids);
        if (allData != null) {
            AlarmStatisticsVO alarmStatisticsVO = null;
            String id = "";
            Map<String, Object> map = null;
            Map<String, Object> map1 = null;
            Long pfjs = 0l;
            Long wcjs = 0l;
            Long pftotal = 0l;
            Long wctotal = 0l;
            Long total = 0l;
            //获取字典里的派单及时时间间隔
            String pfTime = sysDictService.queryDictTextByKey("alarm_msg_time", "pftime");
            String wcTime = sysDictService.queryDictTextByKey("alarm_msg_time", "wctime");
            for (Map<String, Object> allDatum : allData) {
                alarmStatisticsVO = new AlarmStatisticsVO();
                pfjs = 0l;
                wcjs = 0l;
                pftotal = 0l;
                wctotal = 0l;
                id = (String) allDatum.get("depart_id");
                total= (Long) allDatum.getOrDefault("count", "0");
                // 工单派发率 派发及时率
                map = alarmRecordHistoryService.getAlarmRecordHistoryPf(startTime, endTime, id, pfTime);
                if (map != null) {
                    pfjs = (Long) map.getOrDefault("pfjs", "0");
                    pftotal = (Long) map.getOrDefault("pftotal", "0");
                }

                //工单完成率 完成及时率
                map1 = alarmRecordHistoryService.getAlarmRecordHistoryWc(startTime, endTime, id, wcTime);
                if (map1 != null) {
                    wcjs = (Long)map1.getOrDefault("wcjs", "0");
                    wctotal = (Long)map1.getOrDefault("wctotal", "0");
                }

                alarmStatisticsVO.setTotal(total.toString());
                alarmStatisticsVO.setDepartId(id);
                alarmStatisticsVO.setDepartName((String) allDatum.get("depart_name"));

                alarmStatisticsVO.setGdpfl(total==0?df.format(0):df.format(pfjs/total.doubleValue()));
                alarmStatisticsVO.setGdwcl(total==0?df.format(0):df.format(wcjs/total.doubleValue()));
                alarmStatisticsVO.setPfjsl(pftotal==0?df.format(0):df.format(pfjs/pftotal.doubleValue()));
                alarmStatisticsVO.setWcjsl(pftotal==0?df.format(0):df.format(wcjs/wctotal.doubleValue()));
                data.add(alarmStatisticsVO);
            }
        }
        result.setResult(data);
        result.setSuccess(true);
        return result;

    }

    /**
     * 报警处理情况分页列表查询
     */
    @AutoLog(value = "报警类型分布查询")
    @ApiOperation(value = "报警类型分布查询", notes = "报警类型分布查询")
    @GetMapping(value = "/getAlarmTypeList")
    public Result<List<AlarmStatisticsTypeVO>> getAlarmTypeList(String startTime, String endTime, String departId) {

        Result<List<AlarmStatisticsTypeVO>> result = new Result<>();
        String[] split = departId.split(",");
        List<String> ids = Arrays.asList(split);
        //按类型分布
        List<AlarmStatisticsTypeVO> allData = alarmRecordHistoryService.getAlarmTypeList(startTime, endTime, ids);
        if(allData==null||allData.size()<2){
           if(allData.size()==1) {
               AlarmStatisticsTypeVO alarmStatisticsTypeVO=allData.get(0);
               if("数据报警".equals(alarmStatisticsTypeVO.getName())){
                   allData.add(new AlarmStatisticsTypeVO("故障报警","0"));
               }else{
                   allData.add(new AlarmStatisticsTypeVO("数据报警","0"));
               }
           }else if(allData.size()==0){
               allData.add(new AlarmStatisticsTypeVO("故障报警","0"));
               allData.add(new AlarmStatisticsTypeVO("数据报警","0"));
           }
        }
        result.setResult(allData);
        result.setSuccess(true);
        return result;

    }

    /**
     * 报警处理情况分页列表查询
     */
    @AutoLog(value = "报警及派单趋势查询")
    @ApiOperation(value = "报警及派单趋势查询", notes = "报警及派单趋势查询")
    @GetMapping(value = "/getAlarmTrendList")
    public Result<List<Map<String,Object>>> getAlarmTrendList(String startTime, String endTime, String departId) {

        Result<List<Map<String,Object>>> result = new Result<>();
        String[] split = departId.split(",");
        List<String> ids = Arrays.asList(split);
        //按类型分布
        List<Map<String,Object>> allData = alarmRecordHistoryService.getAlarmTrendList(startTime, endTime, ids);
        result.setResult(allData);
        result.setSuccess(true);
        return result;

    }

}