From 8a44b29fc5599fd92a9b583a07a16952bc6adfd8 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Fri, 08 Jun 2018 13:06:36 +0800 Subject: [PATCH] 添加微信接口 --- src/main/resources/system/sysConfig.properties | 2 src/main/java/com/moral/controller/AlarmController.java | 62 -------------------- src/main/java/com/moral/controller/WeixinController.java | 102 ++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/moral/controller/AlarmController.java b/src/main/java/com/moral/controller/AlarmController.java index d026fa0..a76d137 100644 --- a/src/main/java/com/moral/controller/AlarmController.java +++ b/src/main/java/com/moral/controller/AlarmController.java @@ -38,66 +38,4 @@ 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().getValue(); - 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; - } } diff --git a/src/main/java/com/moral/controller/WeixinController.java b/src/main/java/com/moral/controller/WeixinController.java new file mode 100644 index 0000000..7f67a88 --- /dev/null +++ b/src/main/java/com/moral/controller/WeixinController.java @@ -0,0 +1,102 @@ +package com.moral.controller; + +import com.alibaba.fastjson.JSON; +import com.moral.entity.Alarm; +import com.moral.entity.Device; +import com.moral.entity.Sensor; +import com.moral.entity.alarm.AlarmConfigValue; +import com.moral.service.AlarmConfigService; +import com.moral.service.DeviceService; +import com.moral.service.HistoryService; +import com.moral.service.SensorService; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("weixin") +@CrossOrigin(origins = "*", maxAge = 3600) +public class WeixinController { + private static Logger logger = Logger.getLogger(WeixinController.class); + @Resource + DeviceService deviceService; + @Resource + SensorService sensorService; + @Resource + HistoryService historyService; + @Resource + AlarmConfigService alarmConfigService; + /** + * + * @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().getValue(); + 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)); + logger.warn(message.toString()); + model.setViewName("403"); + } + return model; + } +} diff --git a/src/main/resources/system/sysConfig.properties b/src/main/resources/system/sysConfig.properties index 62a5580..5af58f3 100644 --- a/src/main/resources/system/sysConfig.properties +++ b/src/main/resources/system/sysConfig.properties @@ -27,5 +27,5 @@ e19-standard=50 orgId=5 password=123456 -noFilters=/**/*.css,/**/*.json,/alarm/**,/screen/**,/**/*.jsp,/**/*.js,/**/*.gif,/**/*.png,/**/*.ico,/**/*.html,/**/*.map,/machineactivate/**,/device/**,/sensor/**,/mobile/**,/page/** +noFilters=/**/*.css,/**/*.json,/screen/**,/**/*.jsp,/**/*.js,/**/*.html,/**/*.gif,/**/*.png,/**/*.ico,/machineactivate/**,/mobile/** specialOrgIds=-1,5 \ No newline at end of file -- Gitblit v1.8.0