| | |
| | | package com.moral.monitor.controller;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.InputStreamReader;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | |
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.apache.commons.lang.StringUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.core.io.Resource;
|
| | | 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.util.WebUtils;
|
| | |
|
| | | import com.alibaba.fastjson.JSONReader;
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.moral.monitor.entity.AccountEntity;
|
| | | import com.moral.monitor.service.ScreenService;
|
| | | import com.moral.monitor.util.BusinessException;
|
| | | import com.moral.monitor.util.Crypto;
|
| | | import com.moral.monitor.util.WebUtils;
|
| | |
|
| | | @RestController
|
| | | @RequestMapping(value = "screen")
|
| | | @CrossOrigin(origins = "*", maxAge = 3600)
|
| | | public class ScreenController {
|
| | |
|
| | | /** The screen service. */
|
| | | @Autowired
|
| | | private ScreenService screenService;
|
| | | private ScreenService screenService;
|
| | |
|
| | | @Value(value="classpath:system/alarmLevels.json")
|
| | | private Resource resource; |
| | |
|
| | | /**
|
| | | * Screen login.
|
| | | *
|
| | |
| | | resultMap.put("accountId", accountId);
|
| | | return resultMap;
|
| | | }
|
| | | |
| | | @RequestMapping(value = "/month-average", method = RequestMethod.GET)
|
| | | public Map<String, Object> getDataByEquipmentMac(HttpServletRequest request) {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null);
|
| | | Map<String, Object> resu = screenService.getDataByEquipmentMac(parameters);
|
| | | return resu;
|
| | |
|
| | | /**
|
| | | * Gets the month data by equipment.
|
| | | *
|
| | | * @param request the request
|
| | | * @return the month data by equipment
|
| | | */
|
| | | @RequestMapping(value = "/month", method = RequestMethod.GET)
|
| | | public Map<String, Object> getMonthDataByEquipment(HttpServletRequest request) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("mac") && parameters.containsKey("macKey"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = screenService.getMonthDataByEquipment(parameters);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:"+e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Gets the average by all.
|
| | | *
|
| | | * @param request the request
|
| | | * @return the average by all
|
| | | */
|
| | | @RequestMapping(value = "/all-average", method = RequestMethod.GET)
|
| | | public Map<String, Object> getAverageByAll(HttpServletRequest request) {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null);
|
| | | Map<String, Object> resu = screenService.getAverageByAll(parameters);
|
| | | return resu;
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = screenService.getAverageByAll(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:"+e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Gets the equipment states.
|
| | | *
|
| | | * @param request the request
|
| | | * @return the equipment states
|
| | | */
|
| | | @RequestMapping(value = "/equipment-state", method = RequestMethod.GET)
|
| | | public Map<String, Object> getEquipmentStates(HttpServletRequest request) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!parameters.containsKey("accountId")) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = screenService.getEquipmentStates(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:"+e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | | |
| | | |
| | | @RequestMapping(value = "/sensor-average", method = RequestMethod.GET)
|
| | | public Map<String, Object> getAverageBySensor(HttpServletRequest request) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId") && parameters.containsKey("macKey"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = screenService.getAverageBySensor(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:"+e.getMessage());
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | |
|
| | | @RequestMapping(value = "/alarm-levels", method = RequestMethod.GET)
|
| | | public Map<String,Map<String,Double>> getAlarmLevels(HttpServletRequest request) throws IOException {
|
| | | InputStreamReader reader=new InputStreamReader(resource.getInputStream());
|
| | | JSONReader jsonReader = new JSONReader(reader);
|
| | | Map<String,Map<String,Double>> result= jsonReader.readObject(new TypeReference<Map<String,Map<String,Double>>>(){});
|
| | | return result;
|
| | | }
|
| | | }
|