3.7
fxl
2023-03-07 52cffc4ab8e9787a6f233295502c7c9788dddae1
src/main/java/com/hxzkoa/controller/MapController.java
@@ -1,7 +1,11 @@
package com.hxzkoa.controller;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -18,6 +22,7 @@
import org.springframework.web.multipart.MultipartFile;
import com.hxzkoa.json.tb_map;
import com.hxzkoa.json.tb_system;
import com.hxzkoa.services.MapService;
import com.hxzkoa.udp.Udp_Out;
import com.hxzkoa.util.Config;
@@ -125,6 +130,8 @@
      map.setY0_width(request.getParameter("y0_a"));
      map.setX_Pixel(request.getParameter("pixelX_a"));
      map.setY_Pixel(request.getParameter("pixelY_a"));
      map.setBaoliu3(request.getParameter("baoliu3"));
      map.setBaoliu4(request.getParameter("baoliu4"));
      mapService.mapManagement_add(map);
      String xieyi = "BSTOCS1,ADDMAP,"+map.getFloor()+","+map.getMapname()+","+map.getX_Truelength()+","+map.getY_Truewidth()+","+map.getX0_length()+","+map.getY0_width()+","+map.getX_Pixel()+","+map.getY_Pixel()+",END";
      Udp_Out.udp_to_cs(xieyi);
@@ -171,6 +178,8 @@
         map.setY0_width(request.getParameter("y0_m"));
         map.setX_Pixel(request.getParameter("pixelX_m"));
         map.setY_Pixel(request.getParameter("pixelY_m"));
         map.setBaoliu3(request.getParameter("baoliu3"));
         map.setBaoliu4(request.getParameter("baoliu4"));
         mapService.mapManagement_modify(map);
         String xieyi = "BSTOCS1,ALTERMAP,"+map.getFloor()+","+map.getMapname()+","+map.getX_Truelength()+","+map.getY_Truewidth()+","+map.getX0_length()+","+map.getY0_width()+","+map.getX_Pixel()+","+map.getY_Pixel()+",END";
         Udp_Out.udp_to_cs(xieyi);
@@ -184,6 +193,8 @@
         map.setY0_width(request.getParameter("y0_m"));
         map.setX_Pixel(request.getParameter("pixelX_m"));
         map.setY_Pixel(request.getParameter("pixelY_m"));
         map.setBaoliu3(request.getParameter("baoliu3"));
         map.setBaoliu4(request.getParameter("baoliu4"));
         mapService.mapManagement_modify2(map);
         return toPage;
      }
@@ -288,4 +299,119 @@
      return nn;
   }
   @ResponseBody
   @RequestMapping(value = "/getmap.do", method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject getmap(HttpServletRequest request) {
      JSONObject json = new JSONObject();
      List<tb_map> mapManagementList = mapService.getMapManagementa();
      json.put("dataList", mapManagementList);
      return json;
   }
   @ResponseBody
   @RequestMapping(value = "/addMap.do")
   public String addMap(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) {
      String filePath1 = Config.getMapPath() + "/";
      String filePath2 = request.getServletContext().getRealPath("/") + "hxzk/image/mapfile/";
      String filename = files[0].getOriginalFilename();
      tb_map map = new tb_map();
      map.setFloor(request.getParameter("floor_a"));
      map.setMapname(filename);
      map.setX_Truelength(request.getParameter("realX_a"));
      map.setY_Truewidth(request.getParameter("realY_a"));
      map.setX0_length(request.getParameter("x0_a"));
      map.setY0_width(request.getParameter("y0_a"));
      map.setX_Pixel(request.getParameter("pixelX_a"));
      map.setY_Pixel(request.getParameter("pixelY_a"));
      int aaa = mapService.mapManagement_add(map);
      String xieyi = "BSTOCS1,ADDMAP,"+map.getFloor()+","+map.getMapname()+","+map.getX_Truelength()+","+map.getY_Truewidth()+","+map.getX0_length()+","+map.getY0_width()+","+map.getX_Pixel()+","+map.getY_Pixel()+",END";
      Udp_Out.udp_to_cs(xieyi);
      try {
         File existFile1 = new File(filePath1);
         if (!existFile1.exists()) {
            existFile1.mkdir();
         }
         for (MultipartFile file : files) {
            file.transferTo(new File(filePath1 + file.getOriginalFilename()));
         }
      } catch (IOException e) {
         e.printStackTrace();
      }
      try {
         File existFile2 = new File(filePath2);
         if (!existFile2.exists()) {
            existFile2.mkdir();
         }
         for (MultipartFile file : files) {
            file.transferTo(new File(filePath2 + file.getOriginalFilename()));
         }
      } catch (IOException e) {
         e.printStackTrace();
      }
      return ""+aaa;
   }
   @ResponseBody
   @RequestMapping(value = "/modifyMapa.do")
   public String modifya(HttpServletRequest request) {
      tb_map map = new tb_map();
         map.setFloor(request.getParameter("floor_m"));
         map.setMapname(request.getParameter("filename"));
         map.setId(Integer.parseInt(request.getParameter("mapId")));
         //System.out.print(request.getParameter("mapId"));
         map.setX_Truelength(request.getParameter("realX_m"));
         map.setY_Truewidth(request.getParameter("realY_m"));
         map.setX0_length(request.getParameter("x0_m"));
         map.setY0_width(request.getParameter("y0_m"));
         map.setX_Pixel(request.getParameter("pixelX_m"));
         map.setY_Pixel(request.getParameter("pixelY_m"));
         int aaa = mapService.mapManagement_modify(map);
         String xieyi = "BSTOCS1,ALTERMAP,"+map.getFloor()+","+map.getMapname()+","+map.getX_Truelength()+","+map.getY_Truewidth()+","+map.getX0_length()+","+map.getY0_width()+","+map.getX_Pixel()+","+map.getY_Pixel()+",END";
         Udp_Out.udp_to_cs(xieyi);
      return ""+aaa;
   }
   @ResponseBody
   @RequestMapping(value = "/mapManagement_deletea.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String mapManagement_deletea(HttpServletRequest request) {
      String checkValStr = request.getParameter("checkVal");
      checkValStr = checkValStr.replaceAll("\"", "");
      String[] checkVal = checkValStr.split(",");
      mapService.mapManagement_delete(checkVal);
      for(int i = 0;i<checkVal.length;i++) {
         String xieyi = "BSTOCS1,DELETEMAP,"+checkVal[i]+",END";
         Udp_Out.udp_to_cs(xieyi);
      }
      return ""+checkVal.length;
   }
   @ResponseBody
   @RequestMapping(value = "getmapid.do", method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject getmapid() {
      JSONObject json = new JSONObject();
      String path = this.getClass().getClassLoader().getResource("").getPath();
      File file = new File(path+"fengmap.properties");
      String mapid = "";
      String themeid = "";
      String[] strs = new String[2];
      try {
         InputStream in = new FileInputStream(file);
         InputStreamReader inr = new InputStreamReader(in);
         BufferedReader br = new BufferedReader(inr);
         for (int i=0; i<2; i++) {
            strs[i] = br.readLine();
         }
         mapid = strs[0].split("=")[1];
         themeid = strs[1].split("=")[1];
         br.close();
         inr.close();
         in.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
      json.put("mapid", mapid);
      json.put("themeid", themeid);
      return json;
   }
}