xufenglei
2017-12-19 409696535bdc86f09b57582a355087a2120cb74c
src/main/java/com/moral/controller/ScreenController.java
@@ -4,7 +4,6 @@
import static com.moral.common.util.RedisUtil.hasKey;
import static com.moral.common.util.ResourceUtil.getValue;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
import static org.springframework.util.ObjectUtils.isEmpty;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -19,6 +18,7 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -27,17 +27,17 @@
import com.alibaba.fastjson.JSONReader;
import com.alibaba.fastjson.TypeReference;
import com.moral.common.bean.ResultBean;
import com.moral.common.exception.BusinessException;
import com.moral.entity.Account;
import com.moral.common.util.ValidateUtil;
import com.moral.service.AccountService;
import com.moral.service.DeviceService;
import com.moral.service.HistoryService;
import com.moral.service.MachineActivateService;
/**
 * The Class ScreenController.
 * The Class ScreenController.大屏接口
 */
@RestController
@RequestMapping(value = "screen")
@RequestMapping("screen")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ScreenController {
@@ -52,6 +52,9 @@
   /** The device service. */
   @Resource
   private DeviceService deviceService;
   @Resource
   private MachineActivateService machineActivateService;
   /** The resource. */
   @Value(value = "classpath:system/alarmLevels.json")
@@ -62,7 +65,7 @@
   private RedisTemplate<String, String> redisTemplate;
   /** The level key. */
   private String levelKey = "alarm_level_config";
   private String levelKey = "alarm_";
   /**
    * Screen login. 大屏登录
@@ -84,22 +87,6 @@
      return resultMap;
   }
   @GetMapping("login1")
   public ResultBean<Account> screenLogin1(HttpServletRequest request) {
      ResultBean<Account> resultBean = new ResultBean<Account>(ResultBean.FAIL);
      try {
         Map<String, Object> parameters = getParametersStartingWith(request, null);
         if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
            resultBean.setMsg("用户名及密码不允许为空!");
         } else {
            resultBean = accountService.screenLogin1(parameters);
         }
      } catch (Exception e) {
         e.printStackTrace();
         resultBean = new ResultBean<Account>(e);
      }
      return resultBean;
   }
   /**
    * Gets the equipment states. 获取该账号下所有设备的状态
@@ -110,14 +97,8 @@
    */
   @GetMapping("equipment-state")
   public Map<String, Object> getDeviceStatesByAccount(HttpServletRequest request) {
      Map<String, Object> result = new LinkedHashMap<String, Object>();
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      if (!parameters.containsKey("accountId")) {
         result.put("msg", "参数不能为空!");
      } else {
         result = deviceService.getDeviceStatesByAccount(parameters);
      }
      return result;
      return deviceService.getDeviceStatesByAccount(parameters);
   }
   /**
@@ -129,16 +110,18 @@
    */
   @SuppressWarnings("resource")
   @GetMapping("alarm-levels")
   public Map<String, Object> getAlarmLevels(HttpServletRequest request) {
   public Map<String, Object> getAlarmLevels(HttpServletRequest request,String orgId) {
      Map<String, Object> result = new LinkedHashMap<String, Object>();
      String key = levelKey + orgId;
      try {
         if (hasKey(redisTemplate, levelKey)) {
            String levelConfigStr = get(redisTemplate, levelKey);
         if (hasKey(redisTemplate, key)) {
            String levelConfigStr = get(redisTemplate, key);
            result = JSON.parseObject(levelConfigStr, new TypeReference<Map<String, Object>>() {});
         } else {
            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());
@@ -155,12 +138,9 @@
    */
   @GetMapping("sensor-standard")
   public Map<String, Object> getStandardBySensor(@RequestParam("macKey") String macKey) {
      ValidateUtil.notEmpty(macKey, "param.is.null");
      Map<String, Object> result = new HashMap<String, Object>();
      if (isEmpty(macKey)) {
         throw new BusinessException("参数不能为空!");
      } else {
         result.put("standard", getValue(macKey + "-standard"));
      }
      result.put("standard", getValue(macKey + "-standard"));
      return result;
   }
@@ -173,14 +153,8 @@
    */
   @GetMapping("day-aqi")
   public Map<String, Object> getDayAQIByDevice(HttpServletRequest request) {
      Map<String, Object> result = new HashMap<String, Object>();
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      if (!parameters.containsKey("mac")) {
         result.put("msg", "参数不能为空!");
      } else {
         result = historyService.getDayAQIByDevice(parameters);
      }
      return result;
      return historyService.getDayAQIByDevice(parameters);
   }
   /**
@@ -192,14 +166,8 @@
    */
   @GetMapping("all-average")
   public Map<String, Object> getAllSensorAverageByDevice(HttpServletRequest request) {
      Map<String, Object> result = new LinkedHashMap<String, Object>();
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId"))) {
         result.put("msg", "参数不能为空!");
      } else {
         result = historyService.getAllSensorAverageByDevice(parameters);
      }
      return result;
      return historyService.getAllSensorAverageByDevice(parameters);
   }
   /**
@@ -211,15 +179,8 @@
    */
   @GetMapping("sensor-average")
   public Map<String, Object> getDeviceRankingBySensorAverage(HttpServletRequest request) {
      Map<String, Object> result = new HashMap<String, Object>();
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      if (!(parameters.containsKey("areaCode") && parameters.containsKey("accountId")
            && parameters.containsKey("macKey"))) {
         result.put("msg", "参数不能为空!");
      } else {
         result = historyService.getDeviceRankingBySensorAverage(parameters);
      }
      return result;
      return historyService.getDeviceRankingBySensorAverage(parameters);
   }
   /**
@@ -231,14 +192,21 @@
    */
   @GetMapping("month-sensor-average")
   public Map<String, Object> getMonthAverageBySensor(HttpServletRequest request) {
      Map<String, Object> result = new HashMap<String, Object>();
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      if (!(parameters.containsKey("mac") && parameters.containsKey("macKey"))) {
         result.put("msg", "参数不能为空!");
      } else {
         result = historyService.getMonthAverageBySensor(parameters);
      }
      return result;
      return historyService.getMonthAverageBySensor(parameters);
   }
   @GetMapping("check-activate")
   public ResultBean<Integer> checkActivate(String macCpuCode) {
      Integer result = machineActivateService.checkActivate(macCpuCode);
      return new ResultBean<Integer>(result);
   }
   @PostMapping("activate-machine")
   public ResultBean<Integer> activateMachine(HttpServletRequest request) {
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      Integer result = machineActivateService.activateMachine(parameters);
      return new ResultBean<Integer>(result);
   }
}