15832144755
2022-03-17 bc131131c5c96f8cb3bed679d4a359820c22e335
src/main/java/com/hxzkoa/controller/LabelController.java
@@ -8,6 +8,7 @@
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;
@@ -15,6 +16,7 @@
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;
@@ -110,6 +112,29 @@
      return toPage;
   }
   @ResponseBody
   @RequestMapping(value = "/labelManagementa.do", method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject labelManagementa(HttpServletRequest request) {
      List<tb_tag> labelManagementList = labelService.getLabelManagementa();
      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<tb_tag> 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();
@@ -141,7 +166,8 @@
         if(("").equals(tag.getSudu())){
            tag.setSudu("1000");
         }
         String xieyi = "BSTOCS1,ADDTAG,"+tag.getTag_id()+","+tag.getState()+","+tag.getGaodu()+","+tag.getSudu()+","+tag.getPinglv()+",END";
         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();
@@ -164,6 +190,64 @@
      }
   }
   @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.setVersion(Config.getVersion());
      }
      // 如果该tag_id不存在,新增一条
      List<tb_tag> searchLabelManagement = labelService.searchLabelManagement(tag_id);
      if (searchLabelManagement.size() == 0) {
         aaa = 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() + ",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;
   }
   @RequestMapping(value = "/labelManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void labelManagement_modify(HttpServletRequest request) {
      tb_tag tag = new tb_tag();
@@ -173,7 +257,8 @@
      tag.setSudu(request.getParameter("sudu"));
      tag.setPinglv(request.getParameter("pinglv"));
      labelService.labelManagement_modify(tag);
      String xieyi = "BSTOCS1,ALTERTAG,"+tag.getTag_id()+","+tag.getState()+","+tag.getGaodu()+","+tag.getSudu()+","+tag.getPinglv()+",END";
      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<tb_person> searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id());
@@ -186,6 +271,94 @@
      }
   }
   @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"));
      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<tb_person> 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_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<tb_tag> searchtagManagement = basicInfoService.searchPersonManagementa(tag.getTag_id());
      int aaa = 0;
      if (searchtagManagement != null) {
         aaa = labelService.labelManagement_modifytag(tag);
         List<tb_tag> 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<tb_person> 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<tb_tag> searchtagManagement = basicInfoService.searchPersonManagementa(tag.getTag_id());
      int aaa = 0;
      if (searchtagManagement != null) {
         aaa = labelService.labelManagement_modifytag(tag);
//       List<tb_tag> 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<tb_person> 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();
@@ -212,6 +385,33 @@
   }
   @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<tb_tag> labelList = labelService.getLabelManagement();
      for (int i = 0; i < labelList.size(); i++) {
         String tag_id = labelList.get(i).getTag_id();
         // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空
         List<tb_person> 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");
@@ -227,6 +427,23 @@
   }
   @ResponseBody
   @RequestMapping(value = "/labelManagement_deletea.do", method = { RequestMethod.POST, RequestMethod.GET })
   public int 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<tb_tag> tags = labelService.searchidLabelManagement(checkVal[i]);
//       tagids[i] = tags.get(0).getTag_id();
//    }
      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();
@@ -237,6 +454,17 @@
   }
   @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();
@@ -265,6 +493,29 @@
   }
   @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<tb_tag> labelManagementList = labelService.searchLabelManagement(input);
         if (labelManagementList.size() > 0) {
            json.put("result", labelManagementList.get(0));
         } else {
            json.put("result", "null");
         }
      } else {
         List<tb_tag> labelManagementList = labelService.searchLabelManagement(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");
@@ -430,6 +681,23 @@
               tag.setPinglv("无");
               tag.setVersion("无");
               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);
            }
         }
         // 释放资源
@@ -746,7 +1014,8 @@
      String rfidnum = "";
      if(IDcard.M1_MF_HL_Request(adress_and_port)==144) {
          rfidnum=String.valueOf(IDcard.kaohao);   
      };
      }
      ;
      json.put("rfidnum", rfidnum);
      return json.toString();
   }
@@ -890,6 +1159,25 @@
   }
   @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<Integer> pageList = new ArrayList<Integer>();
      List<tb_history_power> 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");