package com.hxzkoa.controller; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; 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_achor; import com.hxzkoa.json.tb_anchor_nearby; import com.hxzkoa.json.tb_tongbuanchor; import com.hxzkoa.json.tb_wifi; import com.hxzkoa.services.AnchorService; 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 jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; import net.sf.json.JSONObject; @Controller public class AnchorController { @Autowired private AnchorService anchorService; @RequestMapping(value = "/anchorManagement.do", method = { RequestMethod.POST, RequestMethod.GET }) public String anchorManagement(HttpServletRequest request) { String toPage = "forward:/hxzk/anchor/anchorManagement.jsp"; List achorManagementList = anchorService.getAnchorManagement(1); request.setAttribute("achorManagementList", achorManagementList); int curPage = 1; int count = anchorService.getAnchorManagementCount(); int minPage = PageUtil.getMinPage(count); request.setAttribute("pageList", PageUtil.getPage(minPage)); request.setAttribute("curPage", curPage); return toPage; } @ResponseBody @RequestMapping(value = "/anchorManagementaa.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject anchorManagementaa(HttpServletRequest request) { JSONObject json = new JSONObject(); List achorManagementList = anchorService.getAnchorManagement(1); int curPage = 1; int count = anchorService.getAnchorManagementCount(); int minPage = PageUtil.getMinPage(count); json.put("dataList", achorManagementList); json.put("pageList", PageUtil.getPage(minPage)); json.put("curPage", curPage); return json; } @ResponseBody @RequestMapping(value = "/anchorManagementa.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject anchorManagementa(HttpServletRequest request) { JSONObject json = new JSONObject(); List achorManagementList = anchorService.getAnchorManagementa(); json.put("dataList", achorManagementList); return json; } @RequestMapping(value = "/anchor_bw_status.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchor_bw_status(HttpServletRequest request) throws IOException { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_achor anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); anchorService.anchor_modify_status(anchor); } @RequestMapping(value = "/anchorManagement_add.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchorManagement_add(HttpServletRequest request) throws IOException { tb_achor anchor = new tb_achor(); String anchorid = request.getParameter("anchorid"); if (("").equals(anchorid) || anchorid == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); List searchAnchorList = anchorService.searchAnchorManagement(anchor.getAnchorid()); if (searchAnchorList.size() == 0) { anchorService.anchorManagement_add(anchor); } } else { anchor.setAnchorid(anchorid); anchor.setPOSX(request.getParameter("POSX")); anchor.setPOSY(request.getParameter("POSY")); anchor.setPOSZ(request.getParameter("POSZ")); anchor.setLayer(request.getParameter("layer")); anchor.setZu(request.getParameter("zu")); anchor.setLiangcheng(request.getParameter("liangcheng")); if(("").equals(anchor.getLiangcheng())){ anchor.setLiangcheng("100000"); } anchor.setAnchorip(request.getParameter("anchorip")); anchor.setAnchormode("1"); anchor.setVersion(Config.getVersion()); // 如果该anchorid不存在,新增一条 List searchAnchorList = anchorService.searchAnchorManagement(anchorid); if (searchAnchorList.size() == 0) { anchorService.anchorManagement_add(anchor); String xieyi = "BSTOCS1,ADDANC,"+anchor.getAnchorid()+","+anchor.getPOSX()+","+anchor.getPOSY()+","+anchor.getPOSZ()+","+anchor.getLayer()+","+anchor.getZu()+","+anchor.getLiangcheng()+","+anchor.getAnchorip()+",END"; Udp_Out.udp_to_cs(xieyi); } } //新增临近基站和同步基站 tb_anchor_nearby nearby = new tb_anchor_nearby(); nearby.setAnchorid(anchor.getAnchorid()); nearby.setQiehuan("0"); anchorService.proximityConfiguration_add(nearby); tb_tongbuanchor tongbu = new tb_tongbuanchor(); tongbu.setAnchorid(anchor.getAnchorid()); tongbu.setType(anchor.getAnchormode()); tongbu.setState("0"); anchorService.syncConfiguration_add(tongbu); } @ResponseBody @RequestMapping(value = "/anchorManagement_adda.do", method = { RequestMethod.POST, RequestMethod.GET }) public int anchorManagement_adda(HttpServletRequest request) throws IOException { tb_achor anchor = new tb_achor(); int aaa = 0; String anchorid = request.getParameter("anchorid"); if (("").equals(anchorid) || anchorid == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); List searchAnchorList = anchorService.searchAnchorManagement(anchor.getAnchorid()); if (searchAnchorList.size() == 0) { anchorService.anchorManagement_add(anchor); } } else { anchor.setAnchorid(anchorid); anchor.setPOSX(request.getParameter("POSX")); anchor.setPOSY(request.getParameter("POSY")); anchor.setPOSZ(request.getParameter("POSZ")); anchor.setLayer(request.getParameter("layer")); anchor.setZu(request.getParameter("zu")); anchor.setLiangcheng(request.getParameter("liangcheng")); if(("").equals(anchor.getLiangcheng())){ anchor.setLiangcheng("100000"); } anchor.setAnchorip(request.getParameter("anchorip")); anchor.setAnchormode("1"); anchor.setVersion(Config.getVersion()); // 如果该anchorid不存在,新增一条 List searchAnchorList = anchorService.searchAnchorManagement(anchorid); if (searchAnchorList.size() == 0) { aaa = anchorService.anchorManagement_add(anchor); String xieyi = "BSTOCS1,ADDANC,"+anchor.getAnchorid()+","+anchor.getPOSX()+","+anchor.getPOSY()+","+anchor.getPOSZ()+","+anchor.getLayer()+","+anchor.getZu()+","+anchor.getLiangcheng()+","+anchor.getAnchorip()+",END"; Udp_Out.udp_to_cs(xieyi); } } //新增临近基站和同步基站 tb_anchor_nearby nearby = new tb_anchor_nearby(); nearby.setAnchorid(anchor.getAnchorid()); nearby.setQiehuan("0"); anchorService.proximityConfiguration_add(nearby); tb_tongbuanchor tongbu = new tb_tongbuanchor(); tongbu.setAnchorid(anchor.getAnchorid()); tongbu.setType(anchor.getAnchormode()); tongbu.setState("0"); anchorService.syncConfiguration_add(tongbu); return aaa; } @RequestMapping(value = "/anchorManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchorManagement_modify(HttpServletRequest request) { tb_achor anchor = new tb_achor(); anchor.setAnchorid(request.getParameter("anchorid")); anchor.setPOSX(request.getParameter("POSX")); anchor.setPOSY(request.getParameter("POSY")); anchor.setPOSZ(request.getParameter("POSZ")); anchor.setLayer(request.getParameter("layer")); anchor.setZu(request.getParameter("zu")); anchor.setLiangcheng(request.getParameter("liangcheng")); anchor.setAnchorip(request.getParameter("anchorip")); anchorService.anchorManagement_modify(anchor); String xieyi = "BSTOCS1,ALTERANC,"+anchor.getAnchorid()+","+anchor.getPOSX()+","+anchor.getPOSY()+","+anchor.getPOSZ()+","+anchor.getLayer()+","+anchor.getZu()+","+anchor.getLiangcheng()+","+anchor.getAnchorip()+",END"; Udp_Out.udp_to_cs(xieyi); //修改临近基站和同步基站 tb_tongbuanchor tongbu = new tb_tongbuanchor(); tongbu.setAnchorid(anchor.getAnchorid()); tongbu.setType(anchor.getAnchormode()); anchorService.syncConfiguration_modify(tongbu); } @ResponseBody @RequestMapping(value = "/anchorManagement_modifya.do", method = { RequestMethod.POST, RequestMethod.GET }) public int anchorManagement_modifya(HttpServletRequest request) { tb_achor anchor = new tb_achor(); anchor.setAnchorid(request.getParameter("anchorid")); anchor.setPOSX(request.getParameter("POSX")); anchor.setPOSY(request.getParameter("POSY")); anchor.setPOSZ(request.getParameter("POSZ")); anchor.setLayer(request.getParameter("layer")); anchor.setZu(request.getParameter("zu")); anchor.setLiangcheng(request.getParameter("liangcheng")); anchor.setAnchorip(request.getParameter("anchorip")); int aaa = anchorService.anchorManagement_modify(anchor); String xieyi = "BSTOCS1,ALTERANC,"+anchor.getAnchorid()+","+anchor.getPOSX()+","+anchor.getPOSY()+","+anchor.getPOSZ()+","+anchor.getLayer()+","+anchor.getZu()+","+anchor.getLiangcheng()+","+anchor.getAnchorip()+",END"; Udp_Out.udp_to_cs(xieyi); //修改临近基站和同步基站 tb_tongbuanchor tongbu = new tb_tongbuanchor(); tongbu.setAnchorid(anchor.getAnchorid()); tongbu.setType(anchor.getAnchormode()); anchorService.syncConfiguration_modify(tongbu); return aaa; } @RequestMapping(value = "/anchorManagement_heart.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchorManagement_heart(HttpServletRequest request) throws IOException { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_achor achor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); achor.setAnchormode("1"); anchorService.anchorManagement_modify_mode(achor); } @RequestMapping(value = "/anchorManagement_heart_tongbu.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchorManagement_heart_tongbu(HttpServletRequest request) throws IOException { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_tongbuanchor tongbuanchor = (tb_tongbuanchor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tongbuanchor.class); anchorService.syncConfiguration_update_state(tongbuanchor); } @ResponseBody @RequestMapping(value = "/anchorManagement_delete.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchorManagement_delete(HttpServletRequest request) { String checkValStr = request.getParameter("checkVal"); String anchorids = request.getParameter("anchorids"); checkValStr = checkValStr.replaceAll("\"", ""); String[] checkVal = checkValStr.split(","); String[] anchorid = anchorids.split(","); anchorService.anchorManagement_delete(checkVal); for(int i = 0; i < anchorid.length; i++) { String xieyi = "BSTOCS1,DELETEANC,"+anchorid[i]+",END"; Udp_Out.udp_to_cs(xieyi); } anchorService.anchorProx_delete(anchorid); anchorService.anchorSync_delete(anchorid); } @ResponseBody @RequestMapping(value = "/anchorManagement_deletea.do", method = { RequestMethod.POST, RequestMethod.GET }) public int anchorManagement_deletea(HttpServletRequest request) { String checkValStr = request.getParameter("checkVal"); checkValStr = checkValStr.replaceAll("\"", ""); String[] checkVal = checkValStr.split(","); // String[] anchorid = new String[checkVal.length]; // for (int i = 0; i < checkVal.length; i++) { // List anchors = anchorService.searchidAnchorManagement(checkVal[i]); // System.out.print(anchors.get(0).getAnchorid()); // anchorid[i] = anchors.get(0).getAnchorid(); // } int aaa = anchorService.anchorManagement_deletea(checkVal); anchorService.anchorProx_delete(checkVal); anchorService.anchorSync_delete(checkVal); return aaa; } @ResponseBody @RequestMapping(value = "/anchorManagement_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET }) public void anchorManagement_deleteAll(HttpServletRequest request) { anchorService.anchorManagement_deleteAll(); String xieyi = "BSTOCS1,DELETEALLANC,END"; Udp_Out.udp_to_cs(xieyi); } @ResponseBody @RequestMapping(value = "/anchorManagement_deleteAlla.do", method = { RequestMethod.POST, RequestMethod.GET }) public int anchorManagement_deleteAlla(HttpServletRequest request) { int aaa = anchorService.anchorManagement_deleteAll(); String xieyi = "BSTOCS1,DELETEALLANC,END"; Udp_Out.udp_to_cs(xieyi); return aaa; } @ResponseBody @RequestMapping(value = "/anchorManagement_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public String anchorManagement_search(HttpServletRequest request) throws IOException { JSONObject json = new JSONObject(); String input = request.getParameter("input"); if (("").equals(input) || input == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_achor anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); input = anchor.getAnchorid(); List anchorManagementList = anchorService.searchAnchorManagement(input); if (anchorManagementList.size()>0){ json.put("result", anchorManagementList.get(0)); } else { json.put("result", "null"); } } else { int curPage = 1; List pageList = new ArrayList(); List anchorManagementList = anchorService.searchAnchorManagement(input); pageList.add(1); json.put("dataList", anchorManagementList); json.put("pageList", pageList); json.put("curPage", curPage); } return json.toString(); } @ResponseBody @RequestMapping(value = "/anchorManagement_searcha.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject anchorManagement_searcha(HttpServletRequest request) throws IOException { JSONObject json = new JSONObject(); String input = request.getParameter("anchorid"); if (("").equals(input) || input == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_achor anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); input = anchor.getAnchorid(); List anchorManagementList = anchorService.searchAnchorManagement(input); if (anchorManagementList.size()>0){ json.put("result", anchorManagementList.get(0)); } else { json.put("result", "null"); } } else { List anchorManagementList = anchorService.searchAnchorManagement(input); json.put("dataList", anchorManagementList); } return json; } @ResponseBody @RequestMapping(value = "/anchorManagement_page.do", method = { RequestMethod.POST, RequestMethod.GET }) public String anchorManagement_page(HttpServletRequest request) { String pageStr = request.getParameter("page"); String curPageStr = request.getParameter("curPage"); int count = anchorService.getAnchorManagementCount(); 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 anchorManagementList = anchorService.getAnchorManagement(page); List pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage); JSONObject json = new JSONObject(); json.put("dataList", anchorManagementList); json.put("pageList", pageList); json.put("curPage", page); return json.toString(); } @ResponseBody @RequestMapping(value = "/anchorManagement_exportTemplate.do", method = { RequestMethod.POST, RequestMethod.GET }) public String anchorManagement_exportTemplate(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/anchor/anchorManagement.jsp"; List anchorTemplateList = anchorService.getAnchorManagement(1); String[] rowName = { "基站ID", "X坐标/cm", "Y坐标/cm", "Z坐标/cm", "层", "同步", "ip地址"}; List dataList = anchorTemplateobjectToArray(anchorTemplateList); 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; } // 对象转数组 public static List anchorTemplateobjectToArray(List achorList) { List reList = new ArrayList<>(); for (int i = 0; i < achorList.size(); i++) { List words = new ArrayList(); tb_achor achor = (tb_achor) achorList.get(i); words.add(achor.getAnchorid()); words.add(achor.getPOSX()); words.add(achor.getPOSY()); words.add(achor.getPOSZ()); words.add(achor.getLayer()); words.add(achor.getAnchormode()); words.add(achor.getAnchorip()); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } @ResponseBody @RequestMapping(value = "/anchorManagement_import.do", method = { RequestMethod.POST, RequestMethod.GET }) public String anchorManagement_import(HttpServletRequest request) { String path = request.getParameter("path"); if (path.indexOf("fakepath") != -1) { String[] fileNameArr = path.split("\\\\"); String fileName = fileNameArr[fileNameArr.length - 1]; path = "C:/hxzkoa/" + fileName; } ; int result = 0; // 选取Excel文件得到工作薄 Workbook workbook; try { File file = new File(path); workbook = Workbook.getWorkbook(file); // 选择工作表,通过Workbook的getSheet方法选择第一个工作表(从0开始) Sheet sheet = workbook.getSheet(0); int rows = sheet.getRows(); // 选择Cell,读取单元格 通过Sheet的getCell方法选择位置为C2的单元格(两个参数都从0开始) for (int i = 1; i < rows; i++) { // 读取信息,通过Cell的getContents方法读取单元格的值把单元格中的信息以字符的形式读取出来 String anchorid = sheet.getCell(0, i).getContents(); String POSX = sheet.getCell(1, i).getContents(); String POSY = sheet.getCell(2, i).getContents(); String POSZ = sheet.getCell(3, i).getContents(); String layer = sheet.getCell(4, i).getContents(); String anchormode = sheet.getCell(7, i).getContents(); String anchorip = sheet.getCell(8, i).getContents(); if (!("").equals(anchorid)) { tb_achor anchor = new tb_achor(); anchor.setAnchorid(anchorid); anchor.setPOSX(POSX); anchor.setPOSY(POSY); anchor.setPOSZ(POSZ); anchor.setLayer(layer); anchor.setZu("0"); anchor.setLiangcheng("无"); anchor.setAnchormode(anchormode); anchor.setAnchorip(anchorip); anchor.setVersion(Config.getVersion()); result = anchorService.anchorManagement_add(anchor); } } // 释放资源 workbook.close(); } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } JSONObject json = new JSONObject(); json.put("result", result); return json.toString(); } @RequestMapping(value = "/uploadAnchor.do") public String uploadPerson(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) { String toPage = "forward:/hxzk/anchor/anchorManagement.jsp"; String filePath = request.getServletContext().getRealPath("/") + "hxzk\\upload\\"; String filename = files[0].getOriginalFilename(); try { File existFile = new File(filePath); if (!existFile.exists()) { existFile.mkdir(); } for (MultipartFile file : files) { file.transferTo(new File(filePath + file.getOriginalFilename())); ////System.out.print(file.getOriginalFilename()); } } catch (IOException e) { e.printStackTrace(); } int result = 0; String path = filePath + filename; // 选取Excel文件得到工作薄 Workbook workbook; try { File file = new File(path); workbook = Workbook.getWorkbook(file); // 选择工作表,通过Workbook的getSheet方法选择第一个工作表(从0开始) Sheet sheet = workbook.getSheet(0); int rows = sheet.getRows(); // 选择Cell,读取单元格 通过Sheet的getCell方法选择位置为C2的单元格(两个参数都从0开始) for (int i = 3; i < rows; i++) { // 读取信息,通过Cell的getContents方法读取单元格的值把单元格中的信息以字符的形式读取出来 String anchorid = sheet.getCell(0, i).getContents(); String POSX = sheet.getCell(1, i).getContents(); String POSY = sheet.getCell(2, i).getContents(); String POSZ = sheet.getCell(3, i).getContents(); String layer = sheet.getCell(4, i).getContents(); String anchormode = sheet.getCell(5, i).getContents(); String anchorip = sheet.getCell(6, i).getContents(); if (!("").equals(anchorid)) { tb_achor anchor = new tb_achor(); anchor.setAnchorid(anchorid); anchor.setPOSX(POSX); anchor.setPOSY(POSY); anchor.setPOSZ(POSZ); anchor.setLayer(layer); anchor.setZu("无"); anchor.setLiangcheng("无"); anchor.setAnchormode(anchormode); anchor.setAnchorip(anchorip); anchor.setVersion(Config.getVersion()); result = anchorService.anchorManagement_add(anchor); } } // 释放资源 workbook.close(); } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } request.setAttribute("resultList", result); List achorManagementList = anchorService.getAnchorManagement(1); request.setAttribute("achorManagementList", achorManagementList); int curPage = 1; int count = anchorService.getAnchorManagementCount(); int minPage = PageUtil.getMinPage(count); request.setAttribute("pageList", PageUtil.getPage(minPage)); request.setAttribute("curPage", curPage); File file = new File(path); file.delete(); return toPage; } @ResponseBody @RequestMapping(value = "/anchorManagement_export.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower_export(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/label/anchorManagement.jsp"; List anchorManagementList = anchorService.getAnchorManagement(); String[] rowName = { "基站ID", "X坐标/CM", "Y坐标/CM", "Z坐标/CM", "层", "组", "量程/CM", "同步", "IP地址", "版本", "更新时间" }; List dataList = objectToArray_anchorManagement(anchorManagementList); 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; } // tb_achor 导出表格 对象转数组 public static List objectToArray_anchorManagement(List vo_tp_t_pList) { List reList = new ArrayList<>(); for (int i = 0; i < vo_tp_t_pList.size(); i++) { List words = new ArrayList(); tb_achor achor = (tb_achor) vo_tp_t_pList.get(i); words.add(achor.getAnchorid()); words.add(achor.getPOSX()); words.add(achor.getPOSY()); words.add(achor.getPOSZ()); words.add(achor.getLayer()); words.add(achor.getZu()); words.add(achor.getLiangcheng()); words.add(achor.getAnchormode()); words.add(achor.getAnchorip()); words.add(achor.getVersion()); words.add(achor.getGreateTime()); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } @RequestMapping(value = "/proximityConfiguration.do", method = { RequestMethod.POST, RequestMethod.GET }) public String proximityConfiguration(HttpServletRequest request) { String toPage = "forward:/hxzk/anchor/proximityConfiguration.jsp"; List proximityConfigurationList = anchorService.getProximityConfiguration(); request.setAttribute("proximityConfigurationList", proximityConfigurationList); return toPage; } @ResponseBody @RequestMapping(value = "/proximityConfiguration_replace.do", method = { RequestMethod.POST, RequestMethod.GET }) public String proximityConfiguration_replace(HttpServletRequest request) { String tableData = request.getParameter("tableData"); String replace_a = request.getParameter("replace_a"); String replace_b = request.getParameter("replace_b"); List reList = new ArrayList(); String[] rows = tableData.split(";"); for (int i = 0; i < rows.length; i++) { String row = rows[i]; String[] columns = row.split(",",-1); tb_anchor_nearby anchor_nearby = new tb_anchor_nearby(); String anchorid = columns[0]; String near1 = columns[1]; String near2 = columns[2]; String near3 = columns[3]; String near4 = columns[4]; String near5 = columns[5]; String near6 = columns[6]; String near7 = columns[7]; String near8 = columns[8]; if (anchorid.equals(replace_a)) { anchor_nearby.setAnchorid(replace_b); } else { anchor_nearby.setAnchorid(anchorid); } if (near1.equals(replace_a)) { anchor_nearby.setNear1(replace_b); } else { anchor_nearby.setNear1(near1); } if (near2.equals(replace_a)) { anchor_nearby.setNear2(replace_b); } else { anchor_nearby.setNear2(near2); } if (near3.equals(replace_a)) { anchor_nearby.setNear3(replace_b); } else { anchor_nearby.setNear3(near3); } if (near4.equals(replace_a)) { anchor_nearby.setNear4(replace_b); } else { anchor_nearby.setNear4(near4); } if (near5.equals(replace_a)) { anchor_nearby.setNear5(replace_b); } else { anchor_nearby.setNear5(near5); } if (near6.equals(replace_a)) { anchor_nearby.setNear6(replace_b); } else { anchor_nearby.setNear6(near6); } if (near7.equals(replace_a)) { anchor_nearby.setNear7(replace_b); } else { anchor_nearby.setNear7(near7); } if (near8.equals(replace_a)) { anchor_nearby.setNear8(replace_b); } else { anchor_nearby.setNear8(near8); } if (columns.length==9){ anchor_nearby.setQiehuan(""); }else { anchor_nearby.setQiehuan(columns[9]); } reList.add(anchor_nearby); } JSONObject json = new JSONObject(); json.put("dataList", reList); return json.toString(); } @ResponseBody @RequestMapping(value = "/proximityConfiguration_four.do", method = { RequestMethod.POST, RequestMethod.GET }) public String proximityConfiguration_four(HttpServletRequest request) { String tableData = request.getParameter("tableData"); List tb_anchor_nearbyList = new ArrayList(); List reList = new ArrayList(); String[] rows = tableData.split(";"); for (int i = 0; i < rows.length; i++) { String row = rows[i]; String[] columns = row.split(",",-1); tb_anchor_nearby anchor_nearby = new tb_anchor_nearby(); anchor_nearby.setAnchorid(columns[0]); anchor_nearby.setQiehuan(columns[9]); tb_anchor_nearbyList.add(anchor_nearby); } int count; for (int i = 0; i < tb_anchor_nearbyList.size(); i++) { tb_anchor_nearby tb_anchor_nearby_i = tb_anchor_nearbyList.get(i); count = 0; for (int j = 0; j < tb_anchor_nearbyList.size(); j++) { if (i != j) { tb_anchor_nearby tb_anchor_nearby_j = tb_anchor_nearbyList.get(j); if (count == 0) { tb_anchor_nearby_i.setNear1(tb_anchor_nearby_j.getAnchorid()); count++; } else if (count == 1) { tb_anchor_nearby_i.setNear2(tb_anchor_nearby_j.getAnchorid()); count++; } else if (count == 2) { tb_anchor_nearby_i.setNear3(tb_anchor_nearby_j.getAnchorid()); count++; } else if (count == 3) { tb_anchor_nearby_i.setNear4(tb_anchor_nearby_j.getAnchorid()); count++; } } } reList.add(tb_anchor_nearby_i); } JSONObject json = new JSONObject(); json.put("dataList", reList); return json.toString(); } @ResponseBody @RequestMapping(value = "/proximityConfiguration_save.do", method = { RequestMethod.POST, RequestMethod.GET }) public void proximityConfiguration_save(HttpServletRequest request) { String tableData = request.getParameter("tableData"); // 解析表格 String[] rows = tableData.split(";"); anchorService.proximityConfiguration_delete(); for (int i = 0; i < rows.length; i++) { String row = rows[i]; String[] columns = row.split(",",-1); tb_anchor_nearby anchor_nearby = new tb_anchor_nearby(); anchor_nearby.setAnchorid(columns[0]); anchor_nearby.setNear1(columns[1]); anchor_nearby.setNear2(columns[2]); anchor_nearby.setNear3(columns[3]); anchor_nearby.setNear4(columns[4]); anchor_nearby.setNear5(columns[5]); anchor_nearby.setNear6(columns[6]); anchor_nearby.setNear7(columns[7]); anchor_nearby.setNear8(columns[8]); if (columns.length==9){ anchor_nearby.setQiehuan(""); }else { anchor_nearby.setQiehuan(columns[9]); } anchorService.proximityConfiguration_add(anchor_nearby); } } @RequestMapping(value = "/proximityConfiguration_add.do", method = { RequestMethod.POST, RequestMethod.GET }) public void proximityConfiguration_add(HttpServletRequest request) throws IOException { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_anchor_nearby anchor_nearby = (tb_anchor_nearby) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_anchor_nearby.class); List searchList = anchorService.searchAnchornearby(anchor_nearby.getAnchorid()); if (searchList.size() == 0) { anchorService.proximityConfiguration_add(anchor_nearby); } } @RequestMapping(value = "/syncConfiguration.do", method = { RequestMethod.POST, RequestMethod.GET }) public String syncConfiguration(HttpServletRequest request) { String toPage = "forward:/hxzk/anchor/syncConfiguration.jsp"; List syncConfigurationList = anchorService.getSyncConfiguration(); request.setAttribute("syncConfigurationList", syncConfigurationList); return toPage; } @ResponseBody @RequestMapping(value = "/syncConfiguration_syncAnchor.do", method = { RequestMethod.POST, RequestMethod.GET }) public String syncConfiguration_syncAnchor(HttpServletRequest request) { String syncAnchorText = request.getParameter("syncAnchorText"); List syncConfigurationList = anchorService.getSyncConfiguration(); List reList = new ArrayList(); for (int i = 0; i < syncConfigurationList.size(); i++) { tb_tongbuanchor tongbuanchor = syncConfigurationList.get(i); String anchorid = tongbuanchor.getAnchorid(); if (syncAnchorText.equals(anchorid)) { tongbuanchor.setRootanchorid("0"); tongbuanchor.setType("1"); tongbuanchor.setState("1"); } else { tongbuanchor.setRootanchorid(syncAnchorText); tongbuanchor.setType("0"); tongbuanchor.setState("1"); } reList.add(tongbuanchor); } JSONObject json = new JSONObject(); json.put("dataList", reList); return json.toString(); } @ResponseBody @RequestMapping(value = "/syncConfiguration_replace.do", method = { RequestMethod.POST, RequestMethod.GET }) public String syncConfiguration_replace(HttpServletRequest request) { String tableData = request.getParameter("tableData"); String replace_a = request.getParameter("replace_a"); String replace_b = request.getParameter("replace_b"); List reList = new ArrayList(); String[] rows = tableData.split(";"); for (int i = 0; i < rows.length; i++) { String row = rows[i]; String[] columns = row.split(",",-1); tb_tongbuanchor tongbuanchor = new tb_tongbuanchor(); String anchorid = columns[0]; String rootanchorid = columns[1]; if (anchorid.equals(replace_a)) { tongbuanchor.setAnchorid(replace_b); } else { tongbuanchor.setAnchorid(anchorid); } if (rootanchorid.equals(replace_a)) { tongbuanchor.setRootanchorid(replace_b); } else { tongbuanchor.setRootanchorid(rootanchorid); } tongbuanchor.setType(columns[2]); tongbuanchor.setState(columns[3]); tongbuanchor.setAddtime(columns[4]); reList.add(tongbuanchor); } JSONObject json = new JSONObject(); json.put("dataList", reList); return json.toString(); } @ResponseBody @RequestMapping(value = "/syncConfiguration_save.do", method = { RequestMethod.POST, RequestMethod.GET }) public void syncConfiguration_save(HttpServletRequest request) { String tableData = request.getParameter("tableData"); // 解析表格 String[] rows = tableData.split(";"); anchorService.syncConfiguration_delete(); for (int i = 0; i < rows.length; i++) { String row = rows[i]; String[] columns = row.split(",",-1); tb_tongbuanchor tongbuanchor = new tb_tongbuanchor(); tongbuanchor.setAnchorid(columns[0]); tongbuanchor.setRootanchorid(columns[1]); tongbuanchor.setType(columns[2]); tongbuanchor.setState(columns[3]); anchorService.syncConfiguration_add(tongbuanchor); } } @RequestMapping(value = "/syncConfiguration_add.do", method = { RequestMethod.POST, RequestMethod.GET }) public void syncConfiguration_add(HttpServletRequest request) throws IOException { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_tongbuanchor tongbuanchor = (tb_tongbuanchor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tongbuanchor.class); List searchList = anchorService.searchTongbuanchor(tongbuanchor.getAnchorid()); if (searchList.size() == 0) { anchorService.syncConfiguration_add(tongbuanchor); } } @RequestMapping(value = "/upload.do") public String upload(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) { String toPage = "forward:/hxzk/anchor/anchorManagement.jsp"; String filePath = request.getServletContext().getRealPath("/") + "upload/"; try { File existFile = new File(filePath); if (!existFile.exists()) { existFile.mkdir(); } for (MultipartFile file : files) { file.transferTo(new File(filePath + file.getOriginalFilename())); } } catch (IOException e) { e.printStackTrace(); } return toPage; } @RequestMapping(value = "/wifiManagement.do", method = { RequestMethod.POST, RequestMethod.GET }) public String wifiManagement(HttpServletRequest request) { String toPage = "forward:/hxzk/anchor/wifiConfiguration.jsp"; tb_wifi wifi = anchorService.getWifiManagement(); request.setAttribute("wifi", wifi); return toPage; } @RequestMapping(value = "/wifiManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET }) public void wifiManagement_add(HttpServletRequest request) { tb_wifi wifi = new tb_wifi(); wifi.setId(Integer.parseInt(request.getParameter("id"))); wifi.setWebname(request.getParameter("webname")); wifi.setWebPass(request.getParameter("webPass")); wifi.setAnchorid(request.getParameter("anchorid")); wifi.setPort(request.getParameter("port")); wifi.setXieyitype(request.getParameter("xieyitype")); wifi.setModel(request.getParameter("model")); wifi.setWifiname(request.getParameter("wifiname")); wifi.setWifipass(request.getParameter("wifipass")); wifi.setIp(request.getParameter("ip")); wifi.setWangguan(request.getParameter("wangguan")); wifi.setZiwang(request.getParameter("ziwang")); wifi.setFuwuip(request.getParameter("fuwuip")); wifi.setJiamileixing(request.getParameter("jiamileixing")); wifi.setJiamisuanfa(request.getParameter("jiamisuanfa")); wifi.setSousuoport(request.getParameter("sousuoport")); wifi.setKeyword(request.getParameter("keyword")); anchorService.wifiManagement_modify(wifi); } @RequestMapping(value = "/networkManagement_more.do", method = { RequestMethod.POST, RequestMethod.GET }) public void networkManagement_more(HttpServletRequest request) { try { Runtime.getRuntime().exec("cmd /c systemFiles\\IP\\anchormage.exe"); } catch (IOException e1) { e1.printStackTrace(); } } @ResponseBody @RequestMapping(value = "/anchorid_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public int anchorid_search(HttpServletRequest request) throws IOException { JSONObject json = new JSONObject(); String anchorid = request.getParameter("anchorid"); List anchorManagementList = null; int nn; if (("").equals(anchorid) || anchorid == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_achor anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class); anchorid = anchor.getAnchorid(); anchorManagementList = anchorService.searchAnchorManagement(anchorid); if (anchorManagementList.size()>0){ json.put("result", anchorManagementList.get(0)); } else { json.put("result", "null"); } } else { int curPage = 1; List pageList = new ArrayList(); anchorManagementList = anchorService.searchAnchorManagement(anchorid); pageList.add(1); json.put("dataList", anchorManagementList); json.put("pageList", pageList); json.put("curPage", curPage); } if(null == anchorManagementList || anchorManagementList.size() ==0 ) { nn=0; }else { nn=1; } return nn; } }