package com.mvc.controller.taizhang;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.DeviceAlarmModel;
import com.mvc.service.taizhang.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.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "设备预警信息接口")
@RequestMapping("/DeviceAlarmAction")
@Controller
public class DeviceAlarmAction {

    @Autowired
    private DeviceAlarmService deviceAlarmService;

    @ApiOperation("分页查询设备预警信息")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllDeviceAlarm(@RequestBody DeviceAlarmModel model){
        try {
            Map<String,Object> res= deviceAlarmService.findAllDeviceAlarm(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("新增设备预警信息")
    @RequestMapping(value = "/saveDeviceAlarm",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveDeviceAlarm(@RequestBody DeviceAlarmModel model){
        try {
            DeviceAlarmModel resModel= deviceAlarmService.saveDeviceAlarm(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("更新设备预警信息")
    @RequestMapping(value = "/updateDeviceAlarm",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody DeviceAlarmModel model){
        try {
            DeviceAlarmModel resModel= deviceAlarmService.updateDeviceAlarm(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("删除设备预警信息")
    @RequestMapping(value = "/deleteDeviceAlarm/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteDeviceAlarm(@PathVariable("id") int id){
        try {
            int  res= deviceAlarmService.deleteDeviceAlarm(id);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("生成设备预警信息")
    @RequestMapping(value = "/generateDeviceAlarmByTime",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> generateDeviceAlarmByTime(){
        try {
            deviceAlarmService.generateDeviceAlarmByTime();
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res","");
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }
}
