| | |
| | | package com.moral.controller;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.InputStreamReader;
|
| | | import static com.moral.common.util.RedisUtil.get;
|
| | | 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 java.io.*;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.moral.common.bean.PageResult;
|
| | | import com.moral.common.xml.Version;
|
| | | import com.moral.entity.Account;
|
| | | import com.moral.entity.MapBounds;
|
| | | import com.moral.entity.MonitorPoint;
|
| | | import com.moral.service.*;
|
| | | import org.apache.commons.net.ftp.FTPClient;
|
| | | import org.apache.log4j.Logger;
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.Element;
|
| | | import org.dom4j.io.SAXReader;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.core.io.Resource;
|
| | | import org.springframework.data.redis.core.RedisTemplate;
|
| | | import org.springframework.util.ObjectUtils;
|
| | | 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.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.ui.Model;
|
| | | import org.springframework.web.bind.annotation.*;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONReader;
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.moral.util.ResourceUtil;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.DeviceService;
|
| | | import com.moral.service.HistoryService;
|
| | | import com.moral.util.BusinessException;
|
| | | import com.moral.util.RedisUtil;
|
| | | import com.moral.util.WebUtils;
|
| | | import com.moral.common.bean.ResultBean;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import org.springframework.web.servlet.ModelAndView;
|
| | | import org.xml.sax.InputSource;
|
| | |
|
| | | // TODO: Auto-generated Javadoc
|
| | | /**
|
| | | * The Class ScreenController.
|
| | | * The Class ScreenController.大屏接口
|
| | | */
|
| | | @RestController
|
| | | @RequestMapping(value = "screen")
|
| | | @CrossOrigin(origins = "*", maxAge = 3600)
|
| | | @RequestMapping("/screen")
|
| | | //@CrossOrigin(origins = "*", maxAge = 3600)
|
| | | public class ScreenController {
|
| | | public static Logger log = Logger.getLogger(ScreenController.class);
|
| | |
|
| | | @Resource
|
| | | AreaService areaService;
|
| | |
|
| | | @Resource
|
| | | SensorService sensorService;
|
| | | @Resource
|
| | | MonitorPointService monitorPointService;
|
| | |
|
| | | /** The screen service. */
|
| | | @Autowired
|
| | | @Resource
|
| | | private HistoryService historyService;
|
| | |
|
| | | /** The account service. */
|
| | | @Autowired
|
| | | @Resource
|
| | | private AccountService accountService;
|
| | |
|
| | | /** The device service. */
|
| | | @Autowired
|
| | | @Resource
|
| | | private DeviceService deviceService;
|
| | |
|
| | | @Resource
|
| | | private HistoryMinutelyService historyMinutelyService;
|
| | |
|
| | | @Resource
|
| | | private MachineActivateService machineActivateService;
|
| | |
|
| | | /** The resource. */
|
| | | @Value(value = "classpath:system/alarmLevels.json")
|
| | | private Resource resource;
|
| | | private org.springframework.core.io.Resource resource;
|
| | |
|
| | | /** The redis template. */
|
| | | @javax.annotation.Resource
|
| | | RedisTemplate<String, String> redisTemplate;
|
| | | @Resource
|
| | | private RedisTemplate<String, String> redisTemplate;
|
| | |
|
| | | /** The level key. */
|
| | | private String levelKey = "alarm_level_config";
|
| | | private String levelKey = "alarm_";
|
| | |
|
| | | /**
|
| | | * Screen login. 大屏登录
|
| | |
| | | * the request
|
| | | * @return the map
|
| | | */
|
| | | @RequestMapping(value = "login", method = RequestMethod.GET)
|
| | | @GetMapping("login")
|
| | | public Map<String, Object> screenLogin(HttpServletRequest request) {
|
| | | Map<String, Object> resultMap = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
|
| | | resultMap.put("msg", "用户名及密码不允许为空!");
|
| | | resultMap.put("accountId", -1);
|
| | | } else {
|
| | | resultMap = accountService.screenLogin(parameters);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
|
| | | resultMap.put("msg", "用户名及密码不允许为空!");
|
| | | resultMap.put("accountId", -1);
|
| | | resultMap.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | } else {
|
| | | resultMap = accountService.screenLogin(parameters);
|
| | | }
|
| | | return resultMap;
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * Gets the equipment states. 获取该账号下所有设备的状态
|
| | |
| | | * the request
|
| | | * @return the equipment states
|
| | | */
|
| | | @RequestMapping(value = "equipment-state", method = RequestMethod.GET)
|
| | | public Map<String, Object> getDeviceStates(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 = deviceService.getDeviceStates(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | @GetMapping("/equipment-state")
|
| | | @PreAuthorize("hasAnyRole('USER', 'ADMIN')")
|
| | | public Map<String, Object> getDeviceStatesByAccount(HttpServletRequest request) {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | return deviceService.getDeviceStatesByAccount(parameters);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @return the alarm levels
|
| | | */
|
| | | @SuppressWarnings("resource")
|
| | | @RequestMapping(value = "alarm-levels", method = RequestMethod.GET)
|
| | | public Map<String, Object> getAlarmLevels(HttpServletRequest request) {
|
| | | @GetMapping("alarm-levels")
|
| | | public Map<String, Object> getAlarmLevels(HttpServletRequest request,String orgId) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | | String key = levelKey + orgId;
|
| | | try {
|
| | | if (RedisUtil.hasKey(redisTemplate, levelKey)) {
|
| | | String levelConfigStr = RedisUtil.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());
|
| | |
| | | /**
|
| | | * Gets the standard by sensor.获取某传感器标准值
|
| | | *
|
| | | * @param request
|
| | | * @param macKey
|
| | | * the request
|
| | | * @return the standard by sensor
|
| | | */
|
| | | @RequestMapping(value = "sensor-standard", method = RequestMethod.GET)
|
| | | public Map<String, Object> getStandardBySensor(HttpServletRequest request) {
|
| | | @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>();
|
| | | try {
|
| | | String macKey = request.getParameter("macKey");
|
| | | if (ObjectUtils.isEmpty(macKey)) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result.put("standard", ResourceUtil.getValue(macKey + "-standard"));
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | result.put("standard", getValue(macKey + "-standard"));
|
| | | return result;
|
| | | }
|
| | |
|
| | |
| | | * the request
|
| | | * @return the day AQI by sensor
|
| | | */
|
| | | @RequestMapping(value = "day-aqi", method = RequestMethod.GET)
|
| | | @GetMapping("day-aqi")
|
| | | public Map<String, Object> getDayAQIByDevice(HttpServletRequest request) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!parameters.containsKey("mac")) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = historyService.getDayAQIByDevice(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | return historyMinutelyService.getDayAQIByDevice(parameters);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * the request
|
| | | * @return the average by all
|
| | | */
|
| | | @RequestMapping(value = "/all-average", method = RequestMethod.GET)
|
| | | public Map<String, Object> getAverageByAll(HttpServletRequest request) {
|
| | | 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 = historyService.getAverageByAll(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | @GetMapping("all-average")
|
| | | public Map<String, Object> getAllSensorAverageByDevice(HttpServletRequest request) {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | return historyService.getAllSensorAverageByDevice(parameters);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * the request
|
| | | * @return the average by sensor
|
| | | */
|
| | | @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 = historyService.getAverageBySensor(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | @GetMapping("sensor-average")
|
| | | public Map<String, Object> getDeviceRankingBySensorAverage(HttpServletRequest request) {
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | return historyService.getDeviceRankingBySensorAverage(parameters);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * the request
|
| | | * @return the month average by sensor
|
| | | */
|
| | | @RequestMapping(value = "month-sensor-average", method = RequestMethod.GET)
|
| | | @GetMapping("month-sensor-average")
|
| | | public Map<String, Object> getMonthAverageBySensor(HttpServletRequest request) {
|
| | | Map<String, Object> result = new HashMap<String, Object>();
|
| | | try {
|
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
|
| | | if (!(parameters.containsKey("mac") && parameters.containsKey("macKey"))) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | result = historyService.getMonthAverageBySensor(parameters);
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | | be.printStackTrace();
|
| | | result.put("msg", be.getMessage());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | result.put("msg", "系统错误,请联系管理员!原因如下:" + e.getMessage());
|
| | | }
|
| | | return result;
|
| | | Map<String, Object> parameters = getParametersStartingWith(request, null);
|
| | | 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);
|
| | | }
|
| | |
|
| | | /*********************************************
|
| | | * 大屏程序在线升级配置读取
|
| | | *********************************************/
|
| | | private String fileName = "Version.xml";
|
| | | private String ip = "121.40.92.176";
|
| | | private String userName = "ftp_user";
|
| | | private String userPwd = "qwer1234";
|
| | | private int port = 21;
|
| | | private String path = "/";
|
| | |
|
| | | @RequestMapping(value = "/upgrade", method = RequestMethod.GET)
|
| | | public Version index() {
|
| | | Version version = new Version();
|
| | | FTPClient ftpClient = new FTPClient();
|
| | | try {
|
| | | ftpClient.connect(ip, port);
|
| | | ftpClient.login(userName, userPwd);
|
| | | ftpClient.changeWorkingDirectory(path);
|
| | | //ftpClient.enterRemotePassiveMode();
|
| | | ftpClient.enterLocalPassiveMode();
|
| | | InputStream ins = ftpClient.retrieveFileStream(fileName);
|
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(ins,"utf-8"));
|
| | | String line;
|
| | | StringBuilder builder = new StringBuilder();
|
| | | while ((line = reader.readLine()) != null) {
|
| | | builder.append(line);
|
| | | }
|
| | | reader.close();
|
| | | if (ins != null) {
|
| | | ins.close();
|
| | | }
|
| | | ftpClient.getReply();
|
| | | String content = builder.toString();
|
| | | if(ftpClient.isConnected()) {
|
| | | ftpClient.logout();
|
| | | ftpClient.disconnect();
|
| | | }
|
| | | SAXReader saxReader = new SAXReader();
|
| | | Document document = saxReader.read(new InputSource(new ByteArrayInputStream(content.getBytes("utf-8"))));
|
| | | Element root = document.getRootElement();
|
| | | version.setVer(root.element("Ver").getText());
|
| | | version.setFileName(root.element("FileName").getText());
|
| | | version.setFileMD5Hash(root.element("FileMD5Hash").getText());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return version;
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "/map-page", method = RequestMethod.GET)
|
| | | public ModelAndView map(ModelAndView model, @RequestParam("areaCode")int code, @RequestParam("accountId")int accountId){
|
| | | Account account = accountService.getAccountById(accountId);
|
| | | String regionName = areaService.selectFullNameByCode(code);
|
| | | if(account!=null&®ionName!=null){
|
| | | Object sensors = sensorService.queryAll();
|
| | | JSONObject params = new JSONObject();
|
| | | params.put("regionCode",code);
|
| | | params.put("regionName",regionName);
|
| | | params.put("accountId", accountId);
|
| | | params.put("orgId", account.getOrganizationId());
|
| | | params.put("sensors", sensors);
|
| | | String paramsJson = params.toJSONString();
|
| | | model.addObject("mapParams",paramsJson);
|
| | | model.setViewName("map");
|
| | | return model;
|
| | | } else {
|
| | | StringBuilder msg = new StringBuilder();
|
| | | msg.append(" param[0] areaCode:");
|
| | | msg.append(code);
|
| | | msg.append(" param[0] accountId:");
|
| | | msg.append(accountId);
|
| | | log.warn(msg);
|
| | | model.setViewName("401");
|
| | | return model;
|
| | | }
|
| | | }
|
| | | @RequestMapping(value="/get-monitorpoints",method = RequestMethod.GET)
|
| | | @ResponseBody
|
| | | public ResultBean getMonitorpointList(@RequestParam("orgId")String orgId,MapBounds mapBounds){
|
| | | ResultBean<List<MonitorPoint>> resultBean = new ResultBean();
|
| | | Map<String,Object> paramMap = new HashMap<String, Object>();
|
| | | paramMap.put("orgId", orgId);
|
| | | paramMap.put("mapBounds",mapBounds);
|
| | | List<MonitorPoint> list = monitorPointService.queryWithStateByMap(paramMap);
|
| | | resultBean.setData(list);
|
| | | resultBean.setCode(ResultBean.SUCCESS);
|
| | | return resultBean;
|
| | | }
|
| | | @RequestMapping(value = "get-devices-for-popup",method = RequestMethod.GET)
|
| | | @ResponseBody
|
| | | public PageResult getDevicesForPopup(
|
| | | @RequestParam("orgId")Integer orgId,
|
| | | String name,
|
| | | Integer pageSize,
|
| | | Integer pageNo
|
| | | ){
|
| | | return deviceService.query(orgId,name,pageSize,pageNo);
|
| | | }
|
| | | }
|