From f0aa3d758d72891edb08f8e3ac14ffcd95fbb30c Mon Sep 17 00:00:00 2001 From: 沈斌 <bluelazysb@hotmail.com> Date: Tue, 07 Nov 2017 09:47:56 +0800 Subject: [PATCH] test --- src/main/java/com/moral/monitor/controller/ScreenController.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/moral/monitor/controller/ScreenController.java b/src/main/java/com/moral/monitor/controller/ScreenController.java index 88ea294..b4e0675 100644 --- a/src/main/java/com/moral/monitor/controller/ScreenController.java +++ b/src/main/java/com/moral/monitor/controller/ScreenController.java @@ -1,5 +1,7 @@ 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; @@ -10,11 +12,15 @@ 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 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; @@ -29,6 +35,9 @@ /** The screen service. */ @Autowired private ScreenService screenService; + + @Value(value="classpath:system/alarmLevels.json") + private Resource resource; /** * Screen login. @@ -88,7 +97,7 @@ } } catch (Exception e) { e.printStackTrace(); - result.put("msg", "������������������������������"); + result.put("msg", "���������������������������������������������������"+e.getMessage()); } return result; } @@ -114,7 +123,7 @@ result.put("msg", be.getMessage()); } catch (Exception e) { e.printStackTrace(); - result.put("msg", "������������������������������"); + result.put("msg", "���������������������������������������������������"+e.getMessage()); } return result; } @@ -140,8 +149,42 @@ result.put("msg", be.getMessage()); } catch (Exception e) { e.printStackTrace(); - //result.put("msg", "������������������������������"); - result.put("msg", e.getMessage()); + 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,Object> getAlarmLevels(HttpServletRequest request){ + Map<String,Object> result = new LinkedHashMap<String, Object>(); + try { + InputStreamReader reader = new InputStreamReader(resource.getInputStream()); + result = new JSONReader(reader).readObject(new TypeReference<LinkedHashMap<String,Object>>(){}); + } catch (IOException e) { + e.printStackTrace(); + result.put("msg", "���������������������������������������������������"+e.getMessage()); } return result; } -- Gitblit v1.8.0