沈斌
2018-04-26 b98924dab9f433d152944f189e0a28edb09ed7e7
src/main/java/com/moral/controller/ScreenController.java
@@ -7,6 +7,9 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -26,6 +29,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -40,6 +44,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.moral.common.bean.Constants;
import com.moral.common.bean.JsonData;
import com.moral.common.bean.PageResult;
import com.moral.common.bean.ResultBean;
@@ -53,6 +58,7 @@
import com.moral.entity.alarm.AlarmSensorLevel;
import com.moral.service.AccountService;
import com.moral.service.AlarmConfigService;
import com.moral.service.AlarmService;
import com.moral.service.AreaService;
import com.moral.service.DeviceService;
import com.moral.service.HistoryMinutelyService;
@@ -67,6 +73,7 @@
@RestController
@RequestMapping("/screen")
//@CrossOrigin(origins = "*", maxAge = 3600)
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
public class ScreenController {
   public  static Logger log = Logger.getLogger(ScreenController.class);
    @Resource
@@ -108,6 +115,8 @@
   /** The level key. */
   private String levelKey = "alarm_";
   @Resource
   private AlarmService alarmService;
   /**
    * Screen login. 大屏登录
    * 
@@ -150,7 +159,6 @@
    *            the request
    * @return the alarm levels
    */
   @SuppressWarnings("resource")
   @GetMapping("alarm-levels")
   public Object getAlarmLevels(HttpServletRequest request, Integer orgId) {
        List<Map<String,Object>> sensorAlarmList = null;
@@ -257,39 +265,56 @@
    * 大屏程序在线升级配置读取
    *********************************************/
   private String fileName = "Version.xml";
   private String ip = "121.40.92.176";
   private String ip = "47.96.19.115";
   private String userName = "ftp_user";
   private String userPwd = "qwer1234";
   private int port = 21;
   private String path = "/";
   private String urlStr = "http://www.7drlb.com/apps/Version.xml";
   @RequestMapping(value = "/upgrade", method = RequestMethod.GET)
   public Version index() {
      Version version = new Version();
      FTPClient ftpClient = new FTPClient();
//      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"));
//         ftpClient.connect(ip, port);
//         ftpClient.login(userName, userPwd);
//         ftpClient.changeWorkingDirectory(path);
//         //ftpClient.enterRemotePassiveMode();
//         //ftpClient.enterLocalPassiveMode();
//         ftpClient.enterLocalActiveMode();
//         //ftpClient.enterRemoteActiveMode(InetAddress.getByName(ip), port);
//
//         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();
//         }
         URL realUrl = new URL(urlStr);
         URLConnection connection = realUrl.openConnection();
         connection.connect();
         StringBuffer result = new StringBuffer();
         BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
         String line;
         StringBuilder builder = new StringBuilder();
         while ((line = reader.readLine()) != null) {
            builder.append(line);
         while ((line = in.readLine()) != null) {
            result.append(line);
         }
         reader.close();
         if (ins != null) {
            ins.close();
         }
         ftpClient.getReply();
         String content = builder.toString();
         if(ftpClient.isConnected()) {
            ftpClient.logout();
            ftpClient.disconnect();
         }
         String content = result.toString();
         SAXReader saxReader = new SAXReader();
         Document document = saxReader.read(new InputSource(new ByteArrayInputStream(content.getBytes("utf-8"))));
         Element root = document.getRootElement();
@@ -301,6 +326,13 @@
      }
      return version;
   }
   public static void main(String[] args) {
      ScreenController sc = new ScreenController();
      Version a = sc.index();
      System.out.println(a.getVer());
   }
   /**
    * 地图接口
    * 开始
@@ -337,7 +369,7 @@
         msg.append(" param[0] accountId:");
         msg.append(accountId);
         log.warn(msg);
         model.setViewName("401");
         model.setViewName("403");
         return model;
      }
   }
@@ -434,7 +466,7 @@
      String sensorKey = parameters.remove("sensorKey").toString();
      List<String> sensorKeys = new ArrayList<String>();
      sensorKeys.add(sensorKey);
      parameters.put("sensorKeys", sensorKeys);
      parameters.put("sensors", sensorKeys);
      List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
      
      for (Map<String, Object> map : list) {
@@ -445,4 +477,27 @@
      }
      return new ResultBean<List<Map<String, Object>>>(list);
   }
   @GetMapping("report_alarm_datas")
   public ResultBean<List<Map<String, Object>>> getAlarmData(HttpServletRequest request) throws Exception {
      Map<String, Object> parameters = getParametersStartingWith(request, null);
      parameters.put("type", "month");
      String sensorKey = "list";
      if (ObjectUtils.isEmpty(parameters.get("sensorKey"))) {
         parameters.put("description", "description");
      } else {
         sensorKey = parameters.remove("sensorKey").toString();
         List<String> sensorKeys = new ArrayList<String>();
         sensorKeys.add(sensorKey);
         parameters.put("sensors", sensorKeys);
      }
      if (!ObjectUtils.isEmpty(parameters.get("organizationId"))) {
         if (!Constants.isNotSpecialOrgId(Integer.valueOf(parameters.get("organizationId").toString()))) {
            parameters.remove("organizationId");
         }
      }
      Map pieData = alarmService.getPieData(parameters);
      List<Map<String, Object>> list = (List<Map<String, Object>>) pieData.get(sensorKey);
      return new ResultBean<List<Map<String, Object>>>(list);
   }
}