Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / zhz / DevicecAlarmController.java
package com.newfiber.api.pc.controller.zhz;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.ReqBodyObj;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.core.commons.ResultObj;
import com.newfiber.api.core.commons.SmsTemplateConfig;
import com.newfiber.api.core.utils.SmsSendUtils;
import com.newfiber.api.core.utils.StringUtil;
import com.newfiber.api.pc.model.entity.DeviceAlarm;
import com.newfiber.api.pc.model.entity.DeviceAlarmCountDto;
import com.newfiber.api.pc.model.entity.PondingDeviceVo;
import com.newfiber.api.pc.service.DeviceAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("/device")
@Api(value = "DevicecAlarmController",tags = "设备异常", position = 103)
public class DevicecAlarmController {

	@Autowired
	private DeviceAlarmService deviceAlarmService;
    @Autowired
	private SmsSendUtils smsSendUtils;

    @ApiOperation(value = "防汛应急指挥-预警报警-异常报警列表")
    @PostMapping(value="/alarmList")
    @ResponseBody
    @SysLog(actionType = "4",value = "防汛应急指挥-预警报警-异常报警列表")
    public ResultObj alarmList(@RequestBody ReqBodyObj<Map<String, Object>> params){
        Integer pageNo = params.getCurrent();
        Integer pageSize = params.getSize();
        String alarmType = params.getData()==null || params.getData().get("alarmType")==null?"":params.getData().get("alarmType").toString();
        String address = params.getData()==null || params.getData().get("address")==null?"":params.getData().get("address").toString();
//        return new ResultObj<>(ResultCode.OK,deviceAlarmService.selectAlarmList(alarmType,address,pageNo,pageSize));
        return new ResultObj<>(ResultCode.OK,deviceAlarmService.selectList(alarmType,address,pageNo,pageSize));
    }

    @ApiOperation(value = "防汛应急指挥-预警报警-异常报警列表状态手动恢复")
    @PostMapping(value="/update")
    @ResponseBody
    @SysLog(actionType = "3",value = "防汛应急指挥-预警报警-异常报警列表状态手动恢复")
    public ResultObj update(@RequestBody ReqBodyObj<Map<String, Object>> params){
        String id = String.valueOf(params.getData().get("id").toString());
        return new ResultObj<>(ResultCode.OK,deviceAlarmService.udpdate(id));
    }

	@ApiOperation(value = "一张图-应急指挥-异常报警列表")
	@PostMapping(value="/list")
	@ResponseBody
    @SysLog(actionType = "4",value = "一张图-应急指挥-异常报警列表")
	public ResultObj list(@RequestBody ReqBodyObj<Map<String, Object>> params){
		Integer pageNo = params.getCurrent();
		Integer pageSize = params.getSize();
        String alarmType = params.getData()==null || params.getData().get("alarmType")==null?"":params.getData().get("alarmType").toString();
        String address = params.getData()==null || params.getData().get("address")==null?"":params.getData().get("address").toString();
        return new ResultObj<>(ResultCode.OK,deviceAlarmService.selectList(alarmType,address,pageNo,pageSize));
	}

	@ApiOperation(value = "异常报警列表数量")
	@PostMapping(value="/count")
	@ResponseBody
    @SysLog(actionType = "4",value = "异常报警列表数量")
	public ResultObj list(){
        List<DeviceAlarmCountDto> deviceAlarmCountDtos = deviceAlarmService.selectCount();
        LinkedList<DeviceAlarmCountDto> result = new LinkedList<>(deviceAlarmCountDtos);
        if(!result.isEmpty()){
            int total = 0;
            for (DeviceAlarmCountDto deviceAlarmCountDto : deviceAlarmCountDtos) {
                Integer count = deviceAlarmCountDto.getCount();
                total += count;
            }
            DeviceAlarmCountDto dto = new DeviceAlarmCountDto();
            dto.setCount(total);
            dto.setAlarmType((byte)0);
            dto.setAlarmName("报警预警总数");
            result.addFirst(dto);
        }
        return new ResultObj<>(ResultCode.OK,result);
	}

    @ApiOperation(value = "积水点实时数据")
    @PostMapping(value="/realTimeData")
    @ResponseBody
    @SysLog(actionType = "4",value = "积水点实时数据")
    public ResultObj realTime(){
        List<PondingDeviceVo> result = deviceAlarmService.selectDeviceList();
        return new ResultObj<>(ResultCode.OK,result);
    }

    @ApiOperation(value = "查询积水点历史数据")
    @PostMapping(value="/getHistoryData")
    @ResponseBody
    @SysLog(actionType = "4",value = "查询积水点历史数据")
    public ResultObj getHistoryData(@RequestBody ReqBodyObj<Map<String, Object>> params){
        String deviceId = params.getData().get("deviceId")==null?"":params.getData().get("deviceId").toString();
        String startTime = StringUtils.isEmpty(params.getData().get("startTime"))?null:params.getData().get("startTime").toString();
        String endTime = StringUtils.isEmpty(params.getData().get("endTime"))?null:params.getData().get("endTime").toString();
        return new ResultObj<>(ResultCode.OK,deviceAlarmService.getHistoryData(deviceId,startTime,endTime));
    }

    @ApiOperation(value = "积水点报警短信推送")
    @PostMapping(value="/pushLevelWarn")
    @ResponseBody
    @SysLog(actionType = "5",value = "积水点报警短信推送")
    public ResultObj pushLevelWarn(@RequestBody ReqBodyObj<Map<String, Object>> params){
        List<String> array= (List<String>) params.getData().get("phones");
        List<String> phones= new ArrayList<>();
        if(null!=array && array.size()>0){
            for (String str : array) {
                if(StringUtil.isNotEmpty(str)){
                    phones.add(str);
                }
            }
        }
        if(CollectionUtil.isNotEmpty(phones)){
            String address =(null==params.getData().get("address"))?"":params.getData().get("address").toString();
            String depth =(null==params.getData().get("depth"))?"":params.getData().get("depth").toString();
            smsSendUtils.sendJiShuiDianShuiWei(phones,address,depth);
            return ResultObj.ok();
        }else{
            return ResultObj.error("所选联系人电话为空");
        }

    }

}