工业级运维app手机api
xufenglei
2017-11-03 d1c0c991624ecb68bf44cbae163eaf28640296df
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.
@@ -144,4 +153,34 @@
      }
      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;
   }
}