package com.hxzkoa.controller; import java.awt.Image; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.swing.ImageIcon; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; 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_adress_and_port; import com.hxzkoa.json.tb_department; import com.hxzkoa.json.tb_fence; import com.hxzkoa.json.tb_history_power; import com.hxzkoa.json.tb_map; import com.hxzkoa.json.tb_person; import com.hxzkoa.json.tb_tag; import com.hxzkoa.json.tb_tagpower; import com.hxzkoa.json.tb_wifi; import com.hxzkoa.json.vo_tp_t_p; import com.hxzkoa.services.AnchorService; import com.hxzkoa.services.BasicInfoService; import com.hxzkoa.services.FenceService; import com.hxzkoa.services.LabelService; import com.hxzkoa.services.MapService; import com.hxzkoa.udp.ControTag; import com.hxzkoa.udp.GetNowTime; import com.hxzkoa.udp.IDcard; import com.hxzkoa.udp.Udp_Out; /*import com.hxzkoa.udp.Udp_Receive;*/ import com.hxzkoa.udp.bmpToJPG; import com.hxzkoa.util.Config; import com.hxzkoa.util.ExcelUtils; import com.hxzkoa.util.HttpUtil; import com.hxzkoa.util.LineXy; import com.hxzkoa.util.ModifyConfig; 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 LabelController { @Autowired private LabelService labelService; @Autowired private BasicInfoService basicInfoService; @Autowired private AnchorService anchorService; @Autowired private MapService mapService; @Autowired private FenceService fenceService; @ResponseBody @RequestMapping(value = "/to_cs_pinlv.do", method = { RequestMethod.POST, RequestMethod.GET }) public void pinlv(HttpServletRequest request) { String tag_id = request.getParameter("tag_id"); String hz = request.getParameter("hz"); String xieyi = "55BB,ALERT_TAG_HZ," + hz + "," + tag_id + ",END"; Udp_Out.udp_to_cs(xieyi); } @ResponseBody @RequestMapping(value = "/to_cs_xiumian_time.do", method = { RequestMethod.POST, RequestMethod.GET }) public void xiumiantime(HttpServletRequest request) { String tag_id = request.getParameter("tag_id"); String hz = request.getParameter("hz"); String xieyi = "55BB,ALERT_SLEEP_TIME," + hz + "," + tag_id + ",END"; Udp_Out.udp_to_cs(xieyi); } @ResponseBody @RequestMapping(value = "/to_cs_xiumian_.do", method = { RequestMethod.POST, RequestMethod.GET }) public void xiumian(HttpServletRequest request) { String tag_id = request.getParameter("tag_id"); String hz = request.getParameter("hz"); String xieyi = "55BB,OPEN_OR_CLOSE_SLEEP," + hz + "," + tag_id + ",END"; Udp_Out.udp_to_cs(xieyi); } @ResponseBody @RequestMapping(value = "/to_cs_zhendong_.do", method = { RequestMethod.POST, RequestMethod.GET }) public void zhendong(HttpServletRequest request) { String tag_id = request.getParameter("tag_id"); String hz = request.getParameter("hz"); String xieyi = "55BB,TAG_SHAKE," + hz + "," + tag_id + ",END"; Udp_Out.udp_to_cs(xieyi); } @RequestMapping(value = "/labelManagement.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement(HttpServletRequest request) { String toPage = "forward:/hxzk/label/labelManagement.jsp"; List labelManagementList = labelService.getLabelManagement(1); List labelManagementListaa = labelService.getLabelManagementa(); List realAttendance_k = new ArrayList(); List departments = basicInfoService.getDepartmentManagement2(); for (int i =0;i < departments.size(); i++) { realAttendance_k.add(departments.get(i).getDepartmentName()); } List leixings = labelService.findleixing(); String[] strs = new String[4]; int renyuannum = 0; int chezainum = 0; int wuzinum = 0; int weibangdingnum = 0; for (int i=0; i labelManagementList = labelService.getLabelManagementa(); JSONObject json = new JSONObject(); json.put("dataList", labelManagementList); return json; } @ResponseBody @RequestMapping(value = "/labelManagementad.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject labelManagementad(HttpServletRequest request) { List labelManagementList = labelService.getLabelManagementa2(); JSONObject json = new JSONObject(); json.put("dataList", labelManagementList); return json; } @ResponseBody @RequestMapping(value = "/labelManagementaa.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject labelManagementaa(HttpServletRequest request) { JSONObject json = new JSONObject(); List labelManagementList = labelService.getLabelManagement(1); int curPage = 1; int count = labelService.getLabelManagementCount(); int minPage = PageUtil.getMinPage(count); json.put("dataList", labelManagementList); json.put("pageList", PageUtil.getPage(minPage)); json.put("curPage", curPage); return json; } @RequestMapping(value = "/labelManagement_add.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelManagement_add(HttpServletRequest request) throws IOException { tb_tag tag = new tb_tag(); String tag_id = request.getParameter("tag_id"); if (("").equals(tag_id) || tag_id == null) { // 接口处理逻辑 String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); tag_id = tag.getTag_id(); } else { // 网页请求逻辑 tag.setTag_id(request.getParameter("tag_id")); tag.setState(request.getParameter("state")); tag.setGaodu(request.getParameter("gaodu")); tag.setSudu(request.getParameter("sudu")); tag.setPinglv(request.getParameter("pinglv")); tag.setType(request.getParameter("type")); tag.setVersion(Config.getVersion()); } // 如果该tag_id不存在,新增一条 List searchLabelManagement = labelService.searchLabelManagement(tag_id); if (searchLabelManagement.size() == 0) { // labelService.labelManagement_add(tag); if (("").equals(tag.getState())) { tag.setState("未绑定"); } if (("").equals(tag.getGaodu())) { tag.setGaodu("150"); } if (("").equals(tag.getSudu())) { tag.setSudu("1000"); } String xieyi = "BSTOCS1,ADDTAG," + tag.getTag_id() + "," + tag.getState() + "," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + "," + tag.getType() + ",END"; Udp_Out.udp_to_cs(xieyi); // 新增标签同时需要在tb_person中插入一条数据 tb_person person = new tb_person(); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_power(tag.getPower()); person.setP_sex("男"); person.setP_minzu("汉"); person.setP_phone("131******88"); person.setP_department("系统默认"); person.setP_x("0"); person.setP_y("0"); person.setP_floor("0"); person.setP_sos("0"); person.setP_online("0"); person.setP_kaoqing("0"); person.setP_fence("0"); person.setP_image("image/targeticon/default.png"); // basicInfoService.personManagement_add(person); } } @ResponseBody @RequestMapping(value = "/labelManagement_adda.do", method = { RequestMethod.POST, RequestMethod.GET }) public int labelManagement_adda(HttpServletRequest request) throws IOException { tb_tag tag = new tb_tag(); int aaa = 0; String tag_id = request.getParameter("tag_id"); if (("").equals(tag_id) || tag_id == null) { // 接口处理逻辑 String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); tag_id = tag.getTag_id(); } else { // 网页请求逻辑 tag.setTag_id(request.getParameter("tag_id")); tag.setState(request.getParameter("state")); tag.setGaodu(request.getParameter("gaodu")); tag.setSudu(request.getParameter("sudu")); tag.setPinglv(request.getParameter("pinglv")); tag.setType(request.getParameter("type")); tag.setVersion(Config.getVersion()); } // 如果该tag_id不存在,新增一条 List searchLabelManagement = labelService.searchLabelManagement(tag_id); if (searchLabelManagement.size() == 0) { aaa = labelService.labelManagement_adda(tag); if (("").equals(tag.getState())) { tag.setState("未绑定"); } if (("").equals(tag.getGaodu())) { tag.setGaodu("150"); } if (("").equals(tag.getSudu())) { tag.setSudu("1000"); } String xieyi = "BSTOCS1,ADDTAG," + tag.getTag_id() + "," + tag.getState() + "," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + ",END"; Udp_Out.udp_to_cs(xieyi); // 新增标签同时需要在tb_person中插入一条数据 tb_person person = new tb_person(); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_power(tag.getPower()); person.setP_sex("男"); person.setP_minzu("汉"); person.setP_phone("131******88"); person.setP_department("系统默认"); person.setP_x("0"); person.setP_y("0"); person.setP_floor("0"); person.setP_sos("0"); person.setP_online("0"); person.setP_kaoqing("0"); person.setP_fence("0"); person.setP_image("image/targeticon/default.png"); basicInfoService.personManagement_add(person); } return aaa; } @ResponseBody @RequestMapping(value = "/labelManagement_addad.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_addad(HttpServletRequest request) throws IOException { tb_tag tag = new tb_tag(); String str = "1"; String bumen = ""; String fence = ""; int aaa = 0; Boolean abc = isLetterDigit(request.getParameter("tagid")); List lables = labelService.searchLabelManagement(request.getParameter("tagid")); if(abc.equals(true) && (lables.size() == 0)){ String tag_id = request.getParameter("tagid"); if (("").equals(tag_id) || tag_id == null) { // 接口处理逻辑 String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); tag_id = tag.getTag_id(); } else { // 网页请求逻辑 tag.setTag_id(request.getParameter("tagid")); tag.setState(request.getParameter("name")); tag.setGaodu(request.getParameter("height")); tag.setSudu("1000"); tag.setPinglv("1"); bumen = request.getParameter("department"); fence = request.getParameter("fencename"); tag.setVersion(Config.getVersion()); } // 如果该tag_id不存在,新增一条 List searchLabelManagement = labelService.searchLabelManagement(tag_id); if (searchLabelManagement.size() == 0) { aaa = labelService.labelManagement_adda(tag); if (("").equals(tag.getState())) { tag.setState("未绑定"); } if (("").equals(tag.getGaodu())) { tag.setGaodu("150"); } if (("").equals(tag.getSudu())) { tag.setSudu("1000"); } if (("").equals(tag.getPinglv())) { tag.setPinglv("1"); } String xieyi = "BSTOCS1,U1ADDTAG," + tag.getTag_id() + "," + tag.getState() + "," + tag.getGaodu() + "," + bumen + "," + fence + ",END"; Udp_Out.udp_to_cs(xieyi); // 新增标签同时需要在tb_person中插入一条数据 tb_person person = new tb_person(); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_department(bumen); person.setBaoliu4(tag.getGaodu()); person.setBaoliu12(fence); person.setP_sex("男"); person.setP_minzu("汉") ; person.setP_phone("131******88"); person.setP_department("系统默认"); person.setP_x("0"); person.setP_y("0"); person.setP_floor("0"); person.setP_sos("0"); person.setP_online("0"); person.setP_kaoqing("0"); person.setP_fence("0"); person.setP_image("image/targeticon/default.png"); basicInfoService.personManagement_add(person); } } else if (lables.size() != 0){ str = "标签ID已存在"; } else { str = "标签ID只能使用数字或字母"; } return str; } @RequestMapping(value = "/labelManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelManagement_modify(HttpServletRequest request) { tb_tag tag = new tb_tag(); tag.setTag_id(request.getParameter("tag_id")); tag.setState(request.getParameter("state")); tag.setGaodu(request.getParameter("gaodu")); tag.setSudu(request.getParameter("sudu")); tag.setPinglv(request.getParameter("pinglv")); tag.setType(request.getParameter("type")); labelService.labelManagement_modify(tag); String xieyi = "BSTOCS1,ALTERTAG," + tag.getTag_id() + "," + tag.getState() + "," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + "," + tag.getType() + ",END"; Udp_Out.udp_to_cs(xieyi); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id()); if (searchPersonManagement != null) { tb_person person = searchPersonManagement.get(0); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_power(tag.getPower()); basicInfoService.personManagement_modify(person); } } @ResponseBody @RequestMapping(value = "/labelManagement_modifya.do", method = { RequestMethod.POST, RequestMethod.GET }) public int labelManagement_modifya(HttpServletRequest request) { tb_tag tag = new tb_tag(); tag.setTag_id(request.getParameter("tag_id")); tag.setState(request.getParameter("state")); tag.setGaodu(request.getParameter("gaodu")); tag.setSudu(request.getParameter("sudu")); tag.setPinglv(request.getParameter("pinglv")); tag.setType(request.getParameter("type")); int aaa = labelService.labelManagement_modifya(tag); String xieyi = "BSTOCS1,ALTERTAG," + tag.getTag_id() + "," + tag.getState() + "," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + ",END"; Udp_Out.udp_to_cs(xieyi); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id()); if (searchPersonManagement != null) { tb_person person = searchPersonManagement.get(0); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_power(tag.getPower()); basicInfoService.personManagement_modify(person); } return aaa; } //修改标签 @ResponseBody @RequestMapping(value = "/labelManagement_modifyad.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_modifyad(HttpServletRequest request) { tb_tag tag = new tb_tag(); String str = "1"; if(isLetterDigit(request.getParameter("tagid"))){ tag.setTag_id(request.getParameter("tagid")); tag.setState(request.getParameter("name")); tag.setGaodu(request.getParameter("height")); String bumen = request.getParameter("department"); String fence = request.getParameter("fencename"); // int aaa = labelService.labelManagement_modifya(tag); if (("").equals(tag.getState())) { tag.setState("未绑定"); } if (("").equals(tag.getGaodu())) { tag.setGaodu("150"); } if (("").equals(tag.getSudu())) { tag.setSudu("1000"); } if (("").equals(tag.getPinglv())) { tag.setPinglv("1"); } // String xieyi = "BSTOCS1,ALTERTAG," + tag.getTag_id() + "," + tag.getState() + "," + bumen + "," // + fence + ",END"; String xieyi = "BSTOCS1,U1ALTERTAG,"+tag.getTag_id()+","+tag.getState()+","+tag.getGaodu()+","+bumen+","+fence+",END"; Udp_Out.udp_to_cs(xieyi); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id()); if (searchPersonManagement != null) { // tb_person person = searchPersonManagement.get(0); // person.setP_tagid(tag.getTag_id()); // person.setP_name(tag.getState()); // person.setP_power(tag.getPower()); // basicInfoService.personManagement_modify(person); } } else { str = "标签ID只能使用数字或字母"; } return str; } // 绑定用户 @ResponseBody @RequestMapping(value = "/labelManagement_modifyaa.do", method = { RequestMethod.POST, RequestMethod.GET }, produces ="application/json; charset=utf-8") public int labelManagement_modifyaa(@RequestBody Map map) { tb_tag tag = new tb_tag(); tag.setTag_id(map.get("tag_id").toString()); tag.setState(map.get("name").toString()); List searchtagManagement = basicInfoService.searchPersonManagementa(tag.getTag_id()); int aaa = 0; if (searchtagManagement != null) { aaa = labelService.labelManagement_modifytag(tag); List tags = labelService.searchLabelManagement(tag.getTag_id()); // String xieyi = "BSTOCS1,ALTERTAG," + tag.getTag_id() + "," + tag.getState() + "," + tags.get(0).getGaodu() + "," // + tags.get(0).getSudu() + "," + tags.get(0).getPinglv() + ",END"; // Udp_Out.udp_to_cs(xieyi); tb_person person = new tb_person(); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); // person.setP_sex(request.getParameter("sex")); // person.setP_minzu(request.getParameter("minzu")); person.setP_fangkeid(map.get("fangkeid").toString()); person.setP_idcardnum(map.get("idcardnum").toString()); // person.setP_adress(request.getParameter("adress")); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id()); if (searchPersonManagement != null) { labelService.labelManagement_modifyperson(person); } } return aaa; } // 用户解绑 @ResponseBody @RequestMapping(value = "/labelManagement_modifyaaa.do", method = { RequestMethod.POST, RequestMethod.GET }, produces ="application/json; charset=utf-8") public int labelManagement_modifyaaa(@RequestBody Map map) { tb_tag tag = new tb_tag(); tag.setTag_id(map.get("tag_id").toString()); tag.setState("未绑定"); List searchtagManagement = basicInfoService.searchPersonManagementa(tag.getTag_id()); int aaa = 0; if (searchtagManagement != null) { aaa = labelService.labelManagement_modifytag(tag); // List tags = labelService.searchLabelManagement(tag.getTag_id()); // String xieyi = "BSTOCS1,ALTERTAG,"+tag.getTag_id()+","+tag.getState()+","+tags.get(0).getGaodu()+","+tags.get(0).getSudu()+","+tags.get(0).getPinglv()+",END"; // Udp_Out.udp_to_cs(xieyi); tb_person person = new tb_person(); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_sex("-"); person.setP_minzu("-"); person.setP_phone("-"); person.setP_idcardnum("-"); person.setP_adress("-"); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id()); if (searchPersonManagement != null) { labelService.labelManagement_modifyperson(person); } } return aaa; } @RequestMapping(value = "/labelManagement_modifyAll.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelManagement_modifyAll(HttpServletRequest request) { tb_tag tag = new tb_tag(); tag.setGaodu(request.getParameter("gaodu")); tag.setSudu(request.getParameter("sudu")); tag.setPinglv(request.getParameter("pinglv")); labelService.labelManagement_modifyAll(tag); String xieyi = "BSTOCS1,ALTERALLTAG," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + ",END"; Udp_Out.udp_to_cs(xieyi); // 需要遍历修改 List labelList = labelService.getLabelManagement(); for (int i = 0; i < labelList.size(); i++) { String tag_id = labelList.get(i).getTag_id(); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag_id); if (searchPersonManagement != null) { tb_person person = searchPersonManagement.get(0); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_power(tag.getPower()); basicInfoService.personManagement_modify(person); } } } @ResponseBody @RequestMapping(value = "/labelManagement_modifyAlla.do", method = { RequestMethod.POST, RequestMethod.GET }) public int labelManagement_modifyAlla(HttpServletRequest request) { tb_tag tag = new tb_tag(); tag.setGaodu(request.getParameter("gaodu")); tag.setSudu(request.getParameter("sudu")); tag.setPinglv(request.getParameter("pinglv")); int aaa = labelService.labelManagement_modifyAlla(tag); String xieyi = "BSTOCS1,ALTERALLTAG," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + ",END"; Udp_Out.udp_to_cs(xieyi); // 需要遍历修改 List labelList = labelService.getLabelManagement(); for (int i = 0; i < labelList.size(); i++) { String tag_id = labelList.get(i).getTag_id(); // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空 List searchPersonManagement = basicInfoService.searchPersonManagement(tag_id); if (searchPersonManagement != null) { tb_person person = searchPersonManagement.get(0); person.setP_tagid(tag.getTag_id()); person.setP_name(tag.getState()); person.setP_power(tag.getPower()); basicInfoService.personManagement_modify(person); } } return aaa; } @ResponseBody @RequestMapping(value = "/labelManagement_delete.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelManagement_delete(HttpServletRequest request) { String checkValStr = request.getParameter("checkVal"); checkValStr = checkValStr.replaceAll("\"", ""); String[] checkVal = checkValStr.split(","); labelService.labelManagement_delete(checkVal); for (int i = 0; i < checkVal.length; i++) { String xieyi = "BSTOCS1,DELETETAG," + checkVal[i] + ",END"; Udp_Out.udp_to_cs(xieyi); } // 删除标签同时需要删除tb_person labelService.labelperson_delete(checkVal); } @ResponseBody @RequestMapping(value = "/labelManagement_deletea.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_deletea(HttpServletRequest request) { String checkValStr = request.getParameter("checkVal"); checkValStr = checkValStr.replaceAll("\"", ""); String[] checkVal = checkValStr.split(","); // String[] tagids = new String[checkVal.length]; // for (int i = 0; i < checkVal.length; i++) { // List tags = labelService.searchidLabelManagement(checkVal[i]); // tagids[i] = tags.get(0).getTag_id(); // } for (int i = 0; i < checkVal.length; i++) { // String xieyi = "BSTOCS1,DELETETAG," + checkVal[i] + ",END"; String xieyi = "BSTOCS1,U1DELETETAG," + checkVal[i] + ",END"; Udp_Out.udp_to_cs(xieyi); } int aaa = labelService.labelManagement_deletea(checkVal); // 删除标签同时需要删除tb_person labelService.labelperson_delete(checkVal); return ""+aaa; } @ResponseBody @RequestMapping(value = "/labelManagement_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelManagement_deleteAll(HttpServletRequest request) { labelService.labelManagement_deleteAll(); String xieyi = "BSTOCS1,DELETEALLTAG,END"; Udp_Out.udp_to_cs(xieyi); // 删除标签同时需要删除tb_person basicInfoService.personManagement_deleteAll(); } @ResponseBody @RequestMapping(value = "/labelManagement_deleteAlla.do", method = { RequestMethod.POST, RequestMethod.GET }) public int labelManagement_deleteAlla(HttpServletRequest request) { int aaa = labelService.labelManagement_deleteAlla(); String xieyi = "BSTOCS1,DELETEALLTAG,END"; Udp_Out.udp_to_cs(xieyi); // 删除标签同时需要删除tb_person basicInfoService.personManagement_deleteAll(); return aaa; } @ResponseBody @RequestMapping(value = "/labelManagement_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_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_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); input = tag.getTag_id(); List labelManagementList = labelService.searchLabelManagement(input); if (labelManagementList.size() > 0) { json.put("result", labelManagementList.get(0)); } else { json.put("result", "null"); } } else { int curPage = 1; List pageList = new ArrayList(); List labelManagementList = labelService.searchLabelManagement(input); pageList.add(1); json.put("dataList", labelManagementList); json.put("pageList", pageList); json.put("curPage", curPage); } return json.toString(); } @ResponseBody @RequestMapping(value = "/labelManagement_searcha.do", method = { RequestMethod.POST, RequestMethod.GET }) public JSONObject labelManagement_searcha(HttpServletRequest request) throws IOException { JSONObject json = new JSONObject(); String input = request.getParameter("tagid"); if (("").equals(input) || input == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); input = tag.getTag_id(); List labelManagementList = labelService.searchLabelManagementaa(input); if (labelManagementList.size() > 0) { json.put("result", labelManagementList.get(0)); } else { json.put("result", "null"); } } else { List labelManagementList = labelService.searchLabelManagementaa(input); json.put("dataList", labelManagementList); } return json; } @ResponseBody @RequestMapping(value = "/labelManagement_page.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_page(HttpServletRequest request) { String pageStr = request.getParameter("page"); String curPageStr = request.getParameter("curPage"); int count = labelService.getLabelManagementCount(); 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 labelManagementList = labelService.getLabelManagement(page); List pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage); JSONObject json = new JSONObject(); json.put("dataList", labelManagementList); json.put("pageList", pageList); json.put("curPage", page); return json.toString(); } @ResponseBody @RequestMapping(value = "/labelManagement_exportTemplate.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_exportTemplate(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/label/labelManagement.jsp"; List labelTemplateList = labelService.getLabelManagement(1); String[] rowName = { "标签ID", "绑定对象" }; List dataList = labelTemplateobjectToArray(labelTemplateList); 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 labelTemplateobjectToArray(List labelList) { List reList = new ArrayList<>(); for (int i = 0; i < labelList.size(); i++) { List words = new ArrayList(); tb_tag tag = (tb_tag) labelList.get(i); words.add(tag.getTag_id()); words.add(tag.getState()); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } @ResponseBody @RequestMapping(value = "/labelManagement_import.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_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 status = sheet.getCell(0, i).getContents(); String tag_id = sheet.getCell(1, i).getContents(); String state = sheet.getCell(2, i).getContents(); String power = sheet.getCell(3, i).getContents(); String gaodu = sheet.getCell(4, i).getContents(); String sudu = sheet.getCell(5, i).getContents(); String pinglv = sheet.getCell(6, i).getContents(); String version = sheet.getCell(7, i).getContents(); if (!("").equals(tag_id)) { tb_tag tag = new tb_tag(); tag.setStatus(status); tag.setTag_id(tag_id); tag.setState(state); tag.setPower(power); tag.setGaodu(gaodu); tag.setSudu(sudu); tag.setPinglv(pinglv); tag.setVersion(version); labelService.labelManagement_add(tag); } } // 释放资源 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 = "/uploadLabel.do") public String uploadPerson(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) { String toPage = "forward:/hxzk/label/labelManagement.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 status = sheet.getCell(0, i).getContents(); String tag_id = sheet.getCell(0, i).getContents(); String state = sheet.getCell(1, i).getContents(); if (!("").equals(tag_id)) { List labelManagementList = labelService.searchLabelManagement(tag_id); if (labelManagementList.size() == 0) { result = 1; tb_tag tag = new tb_tag(); // tag.setStatus(status); tag.setTag_id(tag_id); tag.setState(state); tag.setPower("100"); tag.setGaodu("150"); tag.setSudu("无"); tag.setPinglv("1"); tag.setVersion("无"); tag.setType(""); // result = labelService.labelManagement_add(tag); // tb_person person = new tb_person(); // person.setP_tagid(tag.getTag_id()); // person.setP_name(tag.getState()); // person.setP_power(tag.getPower()); // person.setP_sex("男"); // person.setP_minzu("汉"); // person.setP_phone("131******88"); // person.setP_department("系统默认"); // person.setP_x("0"); // person.setP_y("0"); // person.setP_floor("0"); // person.setP_sos("0"); // person.setP_online("0"); // person.setP_kaoqing("0"); // person.setP_fence("0"); // person.setP_image("image/targeticon/default.png"); // basicInfoService.personManagement_add(person); String xieyi = "BSTOCS1,ADDTAG," + tag.getTag_id() + "," + tag.getState() + "," + tag.getGaodu() + "," + tag.getSudu() + "," + tag.getPinglv() + "," + tag.getType() + ",END"; Udp_Out.udp_to_cs(xieyi); } } } // 释放资源 workbook.close(); } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.print(result+"-------------"); request.setAttribute("resultList", result); List labelManagementList = labelService.getLabelManagement(1); request.setAttribute("labelManagementList", labelManagementList); int curPage = 1; int count = labelService.getLabelManagementCount(); int minPage = PageUtil.getMinPage(count); request.setAttribute("pageList", PageUtil.getPage(minPage)); request.setAttribute("curPage", curPage); File file = new File(path); file.delete(); return toPage; } @RequestMapping(value = "/uploadLabel2.do") public String uploadPerson2(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) { String toPage = "forward:/hxzk/label/labelManagement.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 status = sheet.getCell(0, i).getContents(); String tag_id = sheet.getCell(0, i).getContents(); String jingdu = sheet.getCell(1, i).getContents(); jingdu = todufen(jingdu.substring(0, 3),jingdu.substring(3, 5),jingdu.substring(5)); String weidu = sheet.getCell(2, i).getContents(); weidu = todufen(weidu.substring(0, 2),weidu.substring(2,4),weidu.substring(4)); if (!("").equals(tag_id)) { tb_achor achor = new tb_achor(); // tag.setStatus(status); achor.setAnchorid(tag_id); achor.setBaoliu6(jingdu); achor.setBaoliu7(weidu); result = labelService.anchorManagement_modifyaa(achor); } } // 释放资源 workbook.close(); } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } request.setAttribute("resultList", result); List labelManagementList = labelService.getLabelManagement(1); request.setAttribute("labelManagementList", labelManagementList); int curPage = 1; int count = labelService.getLabelManagementCount(); 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 = "/labelManagement_export.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_export(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/label/labelManagement.jsp"; List tb_tagList = labelService.getLabelManagement(); String[] rowName = { "标签ID", "绑定对象", "电量%", "佩戴高度/cm", "速度限制cm/s", "定位频率(HZ)", "版本", "添加时间" }; List dataList = objectToArray_labelManagement(tb_tagList); 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_tag 导出表格 对象转数组 public static List objectToArray_labelManagement(List tb_tagList) { List reList = new ArrayList<>(); for (int i = 0; i < tb_tagList.size(); i++) { List words = new ArrayList(); tb_tag tag = (tb_tag) tb_tagList.get(i); words.add(tag.getTag_id()); words.add(tag.getState()); words.add(tag.getPower()); words.add(tag.getGaodu()); words.add(tag.getSudu()); words.add(tag.getPinglv()); words.add(tag.getVersion()); words.add(tag.getAddtime()); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } @ResponseBody @RequestMapping(value = "/labelManagement_tagid.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelManagement_tagid(HttpServletRequest request) { JSONObject json = new JSONObject(); List labelManagementList = labelService.getLabelManagement(); List reList = new ArrayList(); for (int i = 0; i < labelManagementList.size(); i++) { reList.add(labelManagementList.get(i).getTag_id()); } json.put("dataList", reList); return json.toString(); } @RequestMapping(value = "/labelManagement_more.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelManagement_more(HttpServletRequest request) { tb_tag tag = new tb_tag(); tag.setTag_id(request.getParameter("tag_id")); tag.setSleep_satus(request.getParameter("sleep_satus")); tag.setSleep_time(request.getParameter("sleep_time")); tag.setGongfang(request.getParameter("gongfang")); tag.setPinglv(request.getParameter("pinglv")); tag.setImu(request.getParameter("imu")); tag.setDong_status(request.getParameter("dong_status")); if (request.getParameter("tag_id").equals("ALL")) { List persons = labelService.getLabelManagement(); for (int i=0; i tagList = null; if (("ALL").equals(tagid)) { tagList = labelService.getLabelManagement(); } // 获取 port,wifi_mode tb_wifi wifiManagement = anchorService.getWifiManagement(); String port = wifiManagement.getPort(); String wifi_mode = wifiManagement.getModel(); // 1.开启或者关闭标签休眠 // 2.修改标签休眠时间 // 3.修改标签的功率 // 4.下发标签振动 // 5.修改标签的频率 // 6.修改加速度计阈值 // 7.修改静止时间 // 8.开启或者关闭标签振动功能 if (("1").equals(tag)) { // 1.开启或者关闭标签休眠 int sleep_open = Integer.parseInt(hz); ControTag.set_tag_sleep_open(sleep_open, tagid, tagList, port, wifi_mode); result = "休眠指令已经下发完成!"; } else if (("2").equals(tag)) { // 2.修改标签休眠时间 int sleeptime = Integer.parseInt(hz); ControTag.set_tag_sleep_time(sleeptime, tagid, tagList, port, wifi_mode); result = "休眠时间修改指令下发完成!"; } else if (("3").equals(tag)) { // 3.修改标签的功率 int gonglv = Integer.parseInt(hz); ControTag.set_tag_gonglv(gonglv, tagid, tagList, port, wifi_mode); result = "功率修改指令下发完成!"; } else if (("4").equals(tag)) { // 4.下发标签振动 if (hz == null || ("").equals(hz)) { result = "振动时间不能为空!"; } else { int time = Integer.parseInt(hz); if (time > 255) { result = "振动时间为0~255秒!"; } else { ControTag.set_tag_zhendong(time, tagid, tagList, port, wifi_mode); result = "振动指令已下发完毕!"; } } } else if (("5").equals(tag)) { // 5.修改标签的频率 ControTag.set_tag_hz(hz, tagid, tagList, port, wifi_mode); result = "修改频率指令已下发完毕!"; } else if (("6").equals(tag)) { // 6.修改加速度计阈值 int yuzhi = Integer.parseInt(hz); ControTag.set_tag_jiasu(yuzhi, tagid, tagList, port, wifi_mode); result = "修改加速度计阈值指令下发完成!"; } else if (("7").equals(tag)) { // 7.修改静止时间 int time = Integer.parseInt(hz); ControTag.set_tag_jingzhi(time, tagid, tagList, port, wifi_mode); result = "静止时间修改指令下发完成!"; } else if (("8").equals(tag)) { // 8.开启或者关闭标签振动功能 int jck_move = Integer.parseInt(hz); ControTag.set_tag_move(jck_move, tagid, tagList, port, wifi_mode); if (jck_move == 1) { result = "开启振动改指令下发完成!"; } else { result = "关闭振动指令下发完成!"; } } json.put("result", result); return json.toString(); } @RequestMapping(value = "/labelDeliver.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelDeliver(HttpServletRequest request) { String toPage = "forward:/hxzk/label/labelDeliver.jsp"; List department = basicInfoService.getAllDepartmentManagement(); request.setAttribute("department", department); return toPage; } @RequestMapping(value = "/labelDeliver_add.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelDeliver_add(HttpServletRequest request) { String p_tagid = request.getParameter("p_tagid"); String p_name = request.getParameter("p_name"); tb_person person = new tb_person(); String p_sos = "0"; String p_online = "0"; String p_power = "100"; person.setP_tagid(p_tagid); person.setP_name(p_name); person.setP_sex(request.getParameter("p_sex")); person.setP_minzu(request.getParameter("p_minzu")); person.setP_phone(request.getParameter("p_phone")); person.setP_department(request.getParameter("p_department")); person.setP_idcardnum(request.getParameter("p_idcardnum")); person.setP_adress(request.getParameter("p_adress")); person.setP_sos(p_sos); person.setP_online(p_online); person.setP_power(p_power); int exist = labelService.labelDeliver_exist(p_tagid); if (exist > 0) { labelService.labelDeliver_modify(person); } else { labelService.labelDeliver_add(person); } labelService.labelManagement_state(p_name, p_tagid); } @RequestMapping(value = "/labelDeliver_remove.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelDeliver_remove(HttpServletRequest request) { String p_tagid = request.getParameter("p_tagid"); String p_name = "未绑定"; tb_person person = new tb_person(); person.setP_tagid(p_tagid); person.setP_name(p_name); person.setP_sex(request.getParameter("p_sex")); person.setP_minzu(request.getParameter("p_minzu")); person.setP_phone(request.getParameter("p_phone")); person.setP_department(request.getParameter("p_department")); person.setP_idcardnum(request.getParameter("p_idcardnum")); person.setP_adress(request.getParameter("p_adress")); int exist = labelService.labelDeliver_exist(p_tagid); if (exist > 0) { labelService.labelDeliver_modify(person); labelService.labelManagement_state(p_name, p_tagid); } } @ResponseBody @RequestMapping(value = "/labelDeliver_conn.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelDeliver_conn(HttpServletRequest request) { JSONObject json = new JSONObject(); List adress_and_port = labelService.getAdress_and_port(); String result = "0"; String state = IDcard.chushi(adress_and_port); if (("发卡设备准备就绪...").equals(state)) { result = "1"; } json.put("result", result); json.put("port", adress_and_port.get(0).getPort()); json.put("btl", adress_and_port.get(0).getBaoliu()); return json.toString(); } @ResponseBody @RequestMapping(value = "/labelDeliver_readIDcard.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelDeliver_readIDcard(HttpServletRequest request) { JSONObject json = new JSONObject(); List adress_and_port = labelService.getAdress_and_port(); String result; String state = IDcard.chushi(adress_and_port); String idcard = ""; String imageStr = ""; if (("发卡设备准备就绪...").equals(state)) { int i = 0; // 卡认证 while (i < 3) { boolean rz = IDcard.CVR_Authenticate(); if (rz) { i = 8; System.out.println("卡认证成功..."); break; } else { try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } System.out.println(i + "请放身份证..."); result = i + "请放身份证..."; i++; } } if (i == 8) { result = "卡认证成功..."; if (IDcard.RedaCard() == 1) { idcard = IDcard.name + "_"; idcard = IDcard.sex + "_"; idcard = IDcard.minzu + "_"; idcard = IDcard.chushengdate + "_"; idcard = IDcard.startdate + "-" + IDcard.jizhidate + "_"; idcard = IDcard.idnum + "_"; idcard = IDcard.address + "_"; idcard = IDcard.fazhengjiguan; } try { bmpToJPG.bmp2jpg(); } catch (IOException e1) { e1.printStackTrace(); } // 身份证照片 // image.setIcon(bmpToJPG.getImages()); ImageIcon images = bmpToJPG.getImages(); Image image = images.getImage(); imageStr = image.toString(); } else { result = "卡认证失败..."; } } else { result = "发卡设备状态不正常!请先连接设备..."; } json.put("idcard", idcard); json.put("result", result); json.put("image", imageStr); return json.toString(); } @ResponseBody @RequestMapping(value = "/labelDeliver_readPoscard.do", method = { RequestMethod.POST, RequestMethod.GET }) public String labelDeliver_readPoscard(HttpServletRequest request) { JSONObject json = new JSONObject(); List adress_and_port = labelService.getAdress_and_port(); String rfidnum = ""; if (IDcard.M1_MF_HL_Request(adress_and_port) == 144) { rfidnum = String.valueOf(IDcard.kaohao); } ; json.put("rfidnum", rfidnum); return json.toString(); } @RequestMapping(value = "/labelDeliver_savePort.do", method = { RequestMethod.POST, RequestMethod.GET }) public void labelDeliver_savePort(HttpServletRequest request) throws IOException { String p_port = request.getParameter("p_port"); String p_btl = request.getParameter("p_btl"); tb_adress_and_port port = new tb_adress_and_port(); port.setBaoliu(p_port); port.setBaoliu2(p_btl); port.setName("faka "); labelService.updateAdress_and_port(port); } @RequestMapping(value = "/realTimePower.do", method = { RequestMethod.POST, RequestMethod.GET }) public String realTimePower(HttpServletRequest request) { String toPage = "forward:/hxzk/label/realTimePower.jsp"; List realTimePowerList = labelService.getRealTimePower(1); request.setAttribute("realTimePowerList", realTimePowerList); int curPage = 1; int count = labelService.getRealTimePowerCount(); int minPage = PageUtil.getMinPage(count); request.setAttribute("pageList", PageUtil.getPage(minPage)); request.setAttribute("curPage", curPage); return toPage; } @ResponseBody @RequestMapping(value = "/realTimePower_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public String realTimePower_search(HttpServletRequest request) { String input = request.getParameter("input"); int curPage = 1; List pageList = new ArrayList(); List realTimePowerList = labelService.searchRealTimePower(input); pageList.add(1); JSONObject json = new JSONObject(); json.put("dataList", realTimePowerList); json.put("pageList", pageList); json.put("curPage", curPage); return json.toString(); } @ResponseBody @RequestMapping(value = "/realTimePower_page.do", method = { RequestMethod.POST, RequestMethod.GET }) public String realTimePower_page(HttpServletRequest request) { String pageStr = request.getParameter("page"); String curPageStr = request.getParameter("curPage"); int count = labelService.getRealTimePowerCount(); 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 realTimePowerList = labelService.getRealTimePower(page); List pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage); JSONObject json = new JSONObject(); json.put("dataList", realTimePowerList); json.put("pageList", pageList); json.put("curPage", page); return json.toString(); } @ResponseBody @RequestMapping(value = "/realTimePower_export.do", method = { RequestMethod.POST, RequestMethod.GET }) public String realTimePower_export(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/label/realTimePower.jsp"; List realTimePowerList = labelService.getRealTimePower(); String[] rowName = { "姓名", "标签ID", "标签频率(HZ)", "电量%", "更新时间" }; List dataList = objectToArray_realTimePower(realTimePowerList); 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; } // vo_tp_t_p 导出表格 对象转数组 public static List objectToArray_realTimePower(List vo_tp_t_pList) { List reList = new ArrayList<>(); for (int i = 0; i < vo_tp_t_pList.size(); i++) { List words = new ArrayList(); vo_tp_t_p tp_t_p = (vo_tp_t_p) vo_tp_t_pList.get(i); words.add(tp_t_p.getP_name()); words.add(tp_t_p.getTagid()); words.add(tp_t_p.getPinglv()); words.add(tp_t_p.getPower()); words.add(tp_t_p.getTime()); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } @RequestMapping(value = "/historicalPower.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower(HttpServletRequest request) { String toPage = "forward:/hxzk/label/historicalPower.jsp"; List historicalPowerList = labelService.getHistoricalPower(1); request.setAttribute("historicalPowerList", historicalPowerList); int curPage = 1; int count = labelService.getHistoricalPowerCount(); int minPage = PageUtil.getMinPage(count); request.setAttribute("pageList", PageUtil.getPage(minPage)); request.setAttribute("curPage", curPage); return toPage; } @ResponseBody @RequestMapping(value = "/historicalPower_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower_search(HttpServletRequest request) { String input = request.getParameter("input"); int curPage = 1; List pageList = new ArrayList(); List historicalPowerList = labelService.searchHistoricalPower(input); pageList.add(1); JSONObject json = new JSONObject(); json.put("dataList", historicalPowerList); json.put("pageList", pageList); json.put("curPage", curPage); return json.toString(); } @ResponseBody @RequestMapping(value = "/historicalPower_searchname.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower_searchname(HttpServletRequest request) { String begin = request.getParameter("begin"); String end = request.getParameter("end"); String tagida = request.getParameter("tagida"); System.out.print(begin + "-----" + end + "--------" + tagida); int curPage = 1; List pageList = new ArrayList(); List historicalPowerList = labelService.searchnameHistoricalPower(begin, end, tagida); System.out.print(historicalPowerList.get(0)); pageList.add(1); JSONObject json = new JSONObject(); json.put("dataList", historicalPowerList); json.put("pageList", pageList); json.put("curPage", curPage); return json.toString(); } @ResponseBody @RequestMapping(value = "/historicalPower_powerAnalysis.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower_powerAnalysis(HttpServletRequest request) throws Exception { String input = request.getParameter("input"); int curPage = 1; List pageList = new ArrayList(); List historicalPowerList = labelService.searchPowerAnalysis(input); String sysPath = request.getServletContext().getRealPath("/"); LineXy.getJFreeChart_hp(input, historicalPowerList, sysPath); pageList.add(1); JSONObject json = new JSONObject(); String filePath = "hxzk/image/powerAnalysis/" + input + "电量分析.jpeg"; json.put("dataList", historicalPowerList); json.put("pageList", pageList); json.put("curPage", curPage); json.put("path", filePath); return json.toString(); } @ResponseBody @RequestMapping(value = "/historicalPower_page.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower_page(HttpServletRequest request) { String pageStr = request.getParameter("page"); String curPageStr = request.getParameter("curPage"); int count = labelService.getHistoricalPowerCount(); 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 historicalPowerList = labelService.getHistoricalPower(page); List pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage); JSONObject json = new JSONObject(); json.put("dataList", historicalPowerList); json.put("pageList", pageList); json.put("curPage", page); return json.toString(); } @ResponseBody @RequestMapping(value = "/historicalPower_delete.do", method = { RequestMethod.POST, RequestMethod.GET }) public void historicalPower_delete(HttpServletRequest request) { String checkValStr = request.getParameter("checkVal"); checkValStr = checkValStr.replaceAll("\"", ""); String[] checkVal = checkValStr.split(","); labelService.historicalPower_delete(checkVal); } @ResponseBody @RequestMapping(value = "/historicalPower_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET }) public void historicalPower_deleteAll(HttpServletRequest request) { labelService.historicalPower_deleteAll(); } @ResponseBody @RequestMapping(value = "/historicalPower_export.do", method = { RequestMethod.POST, RequestMethod.GET }) public String historicalPower_export(HttpServletRequest request, HttpServletResponse response) { String toPage = "forward:/hxzk/label/historicalPower.jsp"; List historicalPowerList = labelService.getHistoricalPower(); String[] rowName = { "序号", "标签ID", "电量%", "时间" }; List dataList = objectToArray_historicalPower(historicalPowerList); 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_history_power 导出表格 对象转数组 public static List objectToArray_historicalPower(List history_powerList) { List reList = new ArrayList<>(); for (int i = 0; i < history_powerList.size(); i++) { List words = new ArrayList(); tb_history_power history_power = (tb_history_power) history_powerList.get(i); words.add(history_power.getId() + ""); words.add(history_power.getTagid()); words.add(history_power.getPower()); words.add(history_power.getTime()); String[] array = words.toArray(new String[0]); reList.add(array); } return reList; } // 报文收取 改标签的状态和电量信息 @RequestMapping(value = "/label_bw_power.do", method = { RequestMethod.POST, RequestMethod.GET }) public void label_bw_power(HttpServletRequest request) throws IOException { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); // 显示sql String sqlString = "UPDATE tb_tag SET power=" + tag.getPower() + " WHERE tag_id=" + tag.getTag_id(); String messageJson = GetNowTime.timestamp2() + " 收:" + sqlString; String BaowenPath = Config.getBaowenConfig(); String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch"); if (baowenStatus.equals("1")) { /* Udp_Receive.mysqlMessage.add(messageJson); */ } // labelService.label_bw_power(tag); } @ResponseBody @RequestMapping(value = "/labeltag_id_search.do", method = { RequestMethod.POST, RequestMethod.GET }) public int labeltag_id_search(HttpServletRequest request) throws IOException { JSONObject json = new JSONObject(); String tag_id = request.getParameter("tag_id"); List labelManagementList = null; int nn; if (("").equals(tag_id) || tag_id == null) { String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset()); tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class); tag_id = tag.getTag_id(); labelManagementList = labelService.searchLabelManagement(tag_id); if (labelManagementList.size() > 0) { json.put("result", labelManagementList.get(0)); } else { json.put("result", "null"); } } else { int curPage = 1; List pageList = new ArrayList(); labelManagementList = labelService.searchLabelManagement(tag_id); pageList.add(1); json.put("dataList", labelManagementList); json.put("pageList", pageList); json.put("curPage", curPage); } if (null == labelManagementList || labelManagementList.size() == 0) { nn = 0; } else { nn = 1; } return nn; } @RequestMapping( value = "/toaddTask.do", method = { RequestMethod.POST, RequestMethod.GET }) public String toaddTask(HttpServletRequest request) { String toPage = "forward:/hxzk/label/addTask.jsp"; List maps = mapService.getMapManagement(); request.setAttribute("mapList", maps); return toPage; } @ResponseBody @RequestMapping( value="getMapFence.do", method={ RequestMethod.POST,RequestMethod.GET }) public String getMapFence(HttpServletRequest request) { JSONObject json = new JSONObject(); String map = request.getParameter("value"); List fences = fenceService.searchFenceLista(map); json.put("fenceList", fences); return json.toString(); } @ResponseBody @RequestMapping(value="shailabel.do",method= {RequestMethod.POST,RequestMethod.GET}) public String shailabel(HttpServletRequest request) { JSONObject json = new JSONObject(); String leixing = request.getParameter("leixing"); String bumen = request.getParameter("bumen"); List tags = new ArrayList<>(); if(!leixing.equals("全部") && !bumen.equals("全部")) { if (leixing.equals("人员标签")) { List tags1 = labelService.shailabel1("系统默认", bumen); List tags2 = labelService.shailabel1("融合终端", bumen); List tags3 = labelService.shailabel1("心率带屏", bumen); List tags4 = labelService.shailabel1("工牌标签", bumen); List tags5 = labelService.shailabel1("安全帽标签", bumen); List tags6 = labelService.shailabel1("URT+CO", bumen); if (tags2.size() > 0) { for (int i=0; i 0) { for (int i=0; i 0) { for (int i=0; i 0) { for (int i=0; i 0) { for (int i=0; i tags1 = labelService.shailabel1("车载带屏", bumen); List tags2 = labelService.shailabel1("车载无屏", bumen); if (tags2.size() > 0) { for (int i=0; i tags1 = labelService.shailabel3("系统默认"); List tags2 = labelService.shailabel3("融合终端"); List tags3 = labelService.shailabel3("心率带屏"); List tags4 = labelService.shailabel3("工牌标签"); List tags5 = labelService.shailabel3("安全帽标签"); List tags6 = labelService.shailabel1("URT+CO", bumen); if (tags2.size() > 0) { for (int i=0; i 0) { for (int i=0; i 0) { for (int i=0; i 0) { for (int i=0; i 0) { for (int i=0; i tags1 = labelService.shailabel3("车载带屏"); List tags2 = labelService.shailabel3("车载无屏"); if (tags2.size() > 0) { for (int i=0; i