于紫祥_1901
2020-12-23 e745dd38c5a413eaa000c7c5434621fbcd1800d5
src/main/java/com/moral/controller/AlarmController.java
@@ -18,6 +18,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.*;
@RestController
@@ -34,67 +35,8 @@
    AlarmConfigService alarmConfigService;
    @Resource
    AlarmService alarmService;
    @RequestMapping(value = "/count-by-times", method = RequestMethod.GET)
    public ResultBean<List<Map>> countByTimes(Date start, Date end,@RequestParam(value = "timeUnits")Optional<TimeUnits> timeUnits){
      return  new ResultBean<>(alarmService.countByTimes(start,end,timeUnits.isPresent()?timeUnits.get():null));
    }
    /**
     *
     * @param alarm
     * @return
     */
    @RequestMapping(value = "/alarm-show", method = RequestMethod.GET)
    public ModelAndView alarmShow(Alarm alarm){
        ModelAndView model = new ModelAndView();
        if (alarm.getMac()!=null&&alarm.getState()!=null
            &&alarm.getJson()!=null&&alarm.getTime()!=null){
            model.setViewName("/alarm/device-data");
            Device device = deviceService.getDeviceByMac(alarm.getMac());
            if(!CollectionUtils.isEmpty(device.getOrganizationIds())){
                List<Sensor> sensorList  = sensorService.queryByVersionId(device.getDeviceVersionId()).getData();
                String data = historyService.queryValueByMacAndTime(alarm.getMac(),alarm.getTime());
                AlarmConfigValue alarmConfigValue = alarmConfigService.queryValueByOrganizationId(device.getOrganizationIds().get(0)).get();
                if(device!=null
                    &&!CollectionUtils.isEmpty(sensorList)
                    &&!StringUtils.isEmpty(data)
                    &&alarmConfigValue!=null
                    &&alarmConfigValue.getAlarmLevels()!=null){
                    Map<String,Object> params = new HashMap<>();
                    model.addObject("alarm",JSON.toJSON(alarm));
                    model.addObject("device",JSON.toJSON(device));
                    model.addObject("sensors",JSON.toJSON(sensorList));
                    model.addObject("data",JSON.toJSON(data));
                    model.addObject("alarmLevels",JSON.toJSON(alarmConfigValue.getAlarmLevels()));
                }
                else{
                    StringBuilder message = new StringBuilder();
                    message.append("some params is null,alarm:");
                    message.append(JSON.toJSON(alarm));
                    message.append(",device:");
                    message.append(JSON.toJSON(device));
                    message.append(",sensorList:");
                    message.append(JSON.toJSON(sensorList));
                    message.append(",data:");
                    message.append(JSON.toJSON(data));
                    logger.warn(message.toString());
                    model.setViewName("403");
                }
            }else{
                StringBuilder message = new StringBuilder();
                message.append("some params is null,alarm:");
                message.append(JSON.toJSON(alarm));
                message.append(",device:");
                message.append(JSON.toJSON(device));
                logger.warn(message.toString());
                model.setViewName("403");
            }
        }else{
            StringBuilder message = new StringBuilder();
            message.append("some params is null,alarm:");
            message.append(JSON.toJSON(alarm));
            model.setViewName("403");
        }
        return  model;
    }
/*    @RequestMapping(value = "/count-by-times", method = RequestMethod.GET)
    public ResultBean<List<Map>> countByTimes(Date start, Date end,@RequestParam(value = "timeUnits")Optional<TimeUnits> timeUnits) throws ParseException {
        return  new ResultBean<>(alarmService.countByTimes(start,end,timeUnits.isPresent()?timeUnits.get():null));
    }*/
}