AlarmController.java 10.0 KB
package com.skua.modules.app.alarm;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.api.ISysBaseAPI;
import com.skua.core.query.QueryGenerator;
import com.skua.core.api.vo.DictModel;
import com.skua.core.util.DateUtils;
import com.skua.modules.alarm.entity.AlarmCheckRecordMastertable;
import com.skua.modules.alarm.entity.AlarmCheckRecordSubtable;
import com.skua.modules.alarm.service.IAlarmCheckRecordMastertableService;
import com.skua.modules.alarm.service.IAlarmCheckRecordSubtableService;
import com.skua.modules.alarm.vo.AlarmQueryVO;
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.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 异常报警APP接口
 */
@Slf4j
@Api(tags="异常报警APP接口")
@RestController
@RequestMapping("/v1/app/alarm")
public class AlarmController {

    @Autowired
    private IAlarmCheckRecordSubtableService alarmCheckRecordSubtableService;
    @Autowired
    private IAlarmCheckRecordMastertableService alarmCheckRecordMastertableService;
   @Autowired
    private ISysBaseAPI iSysBaseAPI;

    /**
     * 异常报警分页列表
     * @param jsonObject
     * @param req
     * @return
     */
    @AutoLog(value = "异常报警分页列表")
    @ApiOperation(value="异常报警分页列表", notes="异常报警分页列表")
    @PostMapping(value = "/list")
    public Result<IPage<AlarmCheckRecordSubtable>> queryPageList(@RequestBody JSONObject jsonObject, HttpServletRequest req) {
        int pageNo = 1;
        int pageSize = 10;
        Result<IPage<AlarmCheckRecordSubtable>> result = new Result<IPage<AlarmCheckRecordSubtable>>();
        AlarmCheckRecordSubtable alarmCheckRecordSubtable = new AlarmCheckRecordSubtable();
        pageNo = jsonObject.getInteger("pageNo");
        pageSize = jsonObject.getInteger("pageSize");
        String date = jsonObject.getString("date");
        if(!date.equals("")){
            alarmCheckRecordSubtable.setCheAlasTime(date);
        }
        QueryWrapper<AlarmCheckRecordSubtable> queryWrapper = QueryGenerator.initQueryWrapper(alarmCheckRecordSubtable, req.getParameterMap());
        Page<AlarmCheckRecordSubtable> page = new Page<AlarmCheckRecordSubtable>(pageNo, pageSize);
        IPage<AlarmCheckRecordSubtable> pageList = alarmCheckRecordSubtableService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     *  上传异常报警处理详情
     * @param jsonObject
     * @return
     */
    @AutoLog(value = "上传异常报警处理详情")
    @ApiOperation(value="上传异常报警处理详情", notes="上传异常报警处理详情")
    @PostMapping(value = "/edit")
    public Result<AlarmCheckRecordMastertable> edit(@RequestBody JSONObject jsonObject) {
        //设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String id = jsonObject.getString("id");
        //解决办法
        String cheAlamSolution = jsonObject.getString("cheAlamSolution");
        //报警原因
        String cheAlamReason = jsonObject.getString("cheAlamReason");
        //解决人
        String cheAlamSolveUserName = jsonObject.getString("cheAlamSolveUserName");
        //备注
        String cheAlamExtraInfo = jsonObject.getString("cheAlamExtraInfo");
        Result<AlarmCheckRecordMastertable> result = new Result<AlarmCheckRecordMastertable>();
        AlarmCheckRecordMastertable entity = alarmCheckRecordMastertableService.getById(id);
        if(entity==null) {
            result.error500("未找到对应实体");
        }else {
            entity.setCheAlamSolution(cheAlamSolution);
            entity.setCheAlamReason(cheAlamReason);
            entity.setCheAlamSolveUserId(cheAlamSolveUserName);
            entity.setCheAlamExtraInfo(cheAlamExtraInfo);
            entity.setCheAlamEndTime(sdf.format(new Date()));
            entity.setCheAlamState("2");
            boolean ok = alarmCheckRecordMastertableService.updateById(entity);
            if(ok) {
                result.success("上传异常报警处理成功!");
            }else{
                result.error500("上传异常报警处理失败!");
            }
        }
        return result;
    }

    /**
     * 异常报警不分页列表
     * @param
     * @param
     * @return
     */
    @AutoLog(value = "异常报警不分页列表")
    @ApiOperation(value="异常报警不分页列表", notes="异常报警不分页列表")
    @GetMapping(value = "/queryCustomerList")
    public Result<Map<String,Object>> queryCustomerList(AlarmQueryVO alarmQueryVO) {
        Result<Map<String,Object> > result = new Result<Map<String,Object>>();
        Page<Map<String,Object>> records = alarmCheckRecordSubtableService.getAlarmListByTime(alarmQueryVO,null);
//        HashMap<String, Object> map = new HashMap<>();
//        //超标报警
//        int overStandard = 0;
//        //故障报警
//        int fault = 0;
//        List<Map<String, Object>> pageList = records.getRecords();
//        for (int i = 0; i < pageList.size(); i++) {
//            if("0".equals(pageList.get(i).get("type"))){
//                overStandard ++;
//            }else if("2".equals(pageList.get(i).get("type"))){
//                fault ++;
//            }
//        }
        Map<String, Object> map = new HashMap<>(4);
        Map<String, Object> map1 = new HashMap<>(4);
        List<Map<String, Object>> list = new ArrayList<>();
        map1.put("standard_params_name","指标1");
        map1.put("che_alas_time","2020-09-01");
        map1.put("che_alas_desc","指标值超过标准值");
        map1.put("che_alas_value",0);
        map1.put("che_alas_type","超标报警");
        map1.put("che_alam_state","未处理");
        list.add(map1);
        map.put("overStandard",0);
        map.put("fault",0);
        map.put("pageList",list);
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }

    /**
     * 报警趋势app
     * @param alarmQueryVO
     * @return
     */
    @AutoLog(value = "报警趋势app")
    @ApiOperation(value="报警趋势app", notes="报警趋势app")
    @GetMapping(value = "/queryCustomerListapp")
    public Result<Map<String,Object>> queryCustomerListapp(AlarmQueryVO alarmQueryVO) {
        Result<Map<String,Object> > result = new Result<Map<String,Object>>();
        List<Map<String,Object>> qsList = alarmCheckRecordSubtableService.getAlarmListByTimeApp(alarmQueryVO);
        HashMap<String, Object> map = new HashMap<>();
        map.put("dateList",qsList);
        result.setSuccess(true);
        result.setResult(map);
        return result;
    }
    /**
     * 报警说明app
     * @param alarmQueryVO
     * @return
     */
    @AutoLog(value = "报警说明app")
    @ApiOperation(value="报警说明app", notes="报警说明app")
    @GetMapping(value = "/bjsmapplist")
    public Result<Page<Map<String, Object>>> bjsmapplist(AlarmQueryVO alarmQueryVO,
                                                         @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                         @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        Result<Page<Map<String, Object>>> result = new Result<Page<Map<String, Object>>>();
        Page<Map<String, Object>> page=new Page();
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        alarmQueryVO.setStartTime(alarmQueryVO.getChosetime()+"-01 00:00:00");
        alarmQueryVO.setEndTime(DateUtils.getLastDayOfMonth(alarmQueryVO.getChosetime())+" 23:59:59");
        Page<Map<String,Object>> pageList = alarmCheckRecordSubtableService.getAlarmListByTime(alarmQueryVO,page);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }
    /**
     * 报警统计app
     * @param alarmQueryVO
     * @return
     */
    @AutoLog(value = "报警统计app")
    @ApiOperation(value="报警统计app", notes="报警统计app")
    @GetMapping(value = "/bjcsapplist")
    public Result<Map<String, Object>> bjcsapplist(AlarmQueryVO alarmQueryVO) {
        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        int totalCount = alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO);
        // 未处理的
        alarmQueryVO.setAlarmState(1);
        int untreatedCount =alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO);
        // 已处理的
        alarmQueryVO.setAlarmState(2);
        int treatedCount=alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO);

        Map<String, Object> resMap = new LinkedHashMap<>();
        resMap.put("untreatedCount",untreatedCount);
        resMap.put("treatedCount",treatedCount);
        resMap.put("totalCount",totalCount);
        List<JSONObject> jsonArray= Lists.newArrayList();
        //异常报警检测类型字典查询
        List<DictModel> alarmCheckType = iSysBaseAPI.queryDictItemsByCode("alarmCheckType");
        JSONObject jsonObject;
        //去除处理状态的条件
        alarmQueryVO.setAlarmState(null);
        for (DictModel a : alarmCheckType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", a.getText());
            alarmQueryVO.setAlarmType(Integer.parseInt(a.getValue()));
            jsonObject.put("count", alarmCheckRecordSubtableService.getAlarmCountByTime(alarmQueryVO));
            jsonArray.add(jsonObject);
        }
        resMap.put("alarmDatas",jsonArray);
        result.setSuccess(true);
        result.setResult(resMap);
        return result;
    }

}