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; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; 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; import com.hxzkoa.util.ExcelUtils; import com.hxzkoa.util.PageUtil; import com.hxzkoa.util.RequestUtils; import net.sf.json.JSONObject; @Controller public class MapController { @Autowired private MapService mapService; @RequestMapping(value = "/mapManagement.do", method = { RequestMethod.POST, RequestMethod.GET }) public String mapManagement(HttpServletRequest request) { String toPage = "forward:/hxzk/map/mapManagement.jsp"; List mapManagementList = mapService.getMapManagement(1); request.setAttribute("mapManagementList", mapManagementList); int curPage = 1; int count = mapService.getMapManagementCount(); int minPage = PageUtil.getMinPage(count); request.setAttribute("pageList", PageUtil.getPage(minPage)); request.setAttribute("curPage", curPage); return toPage; } @ResponseBody @RequestMapping(value = "/mapManagement_page.do", method = { RequestMethod.POST, RequestMethod.GET }) public String mapManagement_page(HttpServletRequest request) { String pageStr = request.getParameter("page"); String curPageStr = request.getParameter("curPage"); int count = mapService.getMapManagementCount(); int minPage = PageUtil.getMinPage(count); int curPage = Integer.parseInt(curPageStr); int page = 1; if ("pre".equals(pageStr)) { if (curPage > 1) { page = curPage - 1; } } else if ("next".equals(pageStr)) { if (curPage < minPage) { page = curPage + 1; } } else { page = Integer.parseInt(pageStr); } List mapManagementList = mapService.getMapManagement(page); List pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage); JSONObject json = new JSONObject(); json.put("dataList", mapManagementList); json.put("pageList", pageList); json.put("curPage", page); return json.toString(); } @ResponseBody @RequestMapping(value = "/mapManagement_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public String mapManagement_search(HttpServletRequest request) { String input = request.getParameter("input"); int curPage = 1; List pageList = new ArrayList(); List mapManagementList = mapService.searchMapService(input); pageList.add(1); JSONObject json = new JSONObject(); json.put("dataList", mapManagementList); json.put("pageList", pageList); json.put("curPage", curPage); return json.toString(); } @ResponseBody @RequestMapping(value = "/mapManagement_delete.do", method = { RequestMethod.POST, RequestMethod.GET }) public void mapManagement_delete(HttpServletRequest request) { String checkValStr = request.getParameter("checkVal"); checkValStr = checkValStr.replaceAll("\"", ""); String[] checkVal = checkValStr.split(","); mapService.mapManagement_delete(checkVal); for(int i = 0;i objectToArray(List mapList) { List reList = new ArrayList<>(); for (int i = 0; i < mapList.size(); i++) { List words = new ArrayList(); tb_map map = (tb_map) mapList.get(i); words.add(String.valueOf(map.getId())); words.add(map.getFloor()); words.add(map.getMapname()); words.add(map.getX_Truelength()); words.add(map.getY_Truewidth()); words.add(map.getX0_length()); words.add(map.getY0_width()); words.add(map.getX_Pixel()); words.add(map.getY_Pixel()); words.add(String.valueOf(map.getAddTime())); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } @ResponseBody @RequestMapping(value = "/mapManagement_export.do", method = { RequestMethod.POST, RequestMethod.GET }) public String mapManagement_export(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/map/mapManagement.jsp"; List mapList = mapService.getMapManagement(); String[] rowName = { "序号", "图层", "地图名称", "X实长", "Y实长", "X0坐标", "Y0坐标", "X像素", "Y像素", "时间" }; List dataList = objectToArray(mapList); ExcelUtils excel = new ExcelUtils("地图管理", rowName, dataList); OutputStream out; try { String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls"; String headStr = "attachment; filename=\"" + fileName + "\""; response.setContentType("APPLICATION/OCTET-STREAM"); response.setHeader("Content-Disposition", headStr); out = response.getOutputStream(); excel.export(out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return toPage; } @ResponseBody @RequestMapping(value = "/map_bw_floor.do", method = { RequestMethod.POST, RequestMethod.GET }) public String getMap_floor(HttpServletRequest request) throws IOException { JSONObject json = new JSONObject(); String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_map map = (tb_map) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_map.class); List map_floorList = mapService.getMap_floor(map.getFloor()); if (map_floorList.size()>0){ json.put("result", map_floorList.get(0)); }else { json.put("result", "null"); } return json.toString(); } @ResponseBody @RequestMapping(value = "/mapfloor_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public int mapfloor_search(HttpServletRequest request) { int nn; String floor = request.getParameter("floor"); List mapManagementList = mapService.searchMapfloorService(floor); if(null == mapManagementList || mapManagementList.size() ==0 ) { nn=0; }else { nn=1; } return nn; } @ResponseBody @RequestMapping(value = "/getmap.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject getmap(HttpServletRequest request) { JSONObject json = new JSONObject(); List 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