3.7
fxl
2023-03-07 52cffc4ab8e9787a6f233295502c7c9788dddae1
src/main/java/com/hxzkoa/services/ZhwService.java
@@ -41,9 +41,14 @@
import com.hxzkoa.json.tb_history_power;
import com.hxzkoa.json.tb_historyinwarning;
import com.hxzkoa.json.tb_icon;
import com.hxzkoa.json.tb_jingwei;
import com.hxzkoa.json.tb_map;
import com.hxzkoa.json.tb_message;
import com.hxzkoa.json.tb_nav;
import com.hxzkoa.json.tb_person;
import com.hxzkoa.json.tb_qihou;
import com.hxzkoa.json.tb_realinwarning;
import com.hxzkoa.json.tb_realkaoqing;
import com.hxzkoa.json.tb_realocation;
import com.hxzkoa.json.tb_realpositoin;
import com.hxzkoa.json.tb_shipin;
@@ -55,6 +60,8 @@
import com.hxzkoa.json.tb_warning;
import com.hxzkoa.json.tb_xunjianbaobiao;
import com.hxzkoa.json.tb_xunjianset;
import com.hxzkoa.util.Config;
import com.hxzkoa.util.ModifyConfig;
@Service
public class ZhwService {
@@ -89,6 +96,48 @@
      return tb_mapList;
   }
   
   public List<tb_person> getpersonid(String tagid) {
      String sql = null;
      Query query = null;
      sql = "SELECT p_x,p_y,p_tagid,p_addtiem FROM tb_person WHERE p_tagid="+tagid;
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_mapList = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person map = new tb_person();
            Object[] obj = (Object[]) resultList.get(i);
            map.setP_x((String) obj[0]);
            map.setP_y((String) obj[1]);
            map.setP_tagid((String) obj[2]);
            map.setP_addtiem((String) obj[3]);
            tb_mapList.add(map);
         }
      }
      return tb_mapList;
   }
   public List<tb_gps> getgpsid(String tagid) {
      String sql = null;
      Query query = null;
      sql = "SELECT gps_weidu,gsp_jingdu,tagid,gps_haiba_gao FROM tb_gps WHERE tagid="+tagid;
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_gps> tb_mapList = new ArrayList<tb_gps>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_gps map = new tb_gps();
            Object[] obj = (Object[]) resultList.get(i);
            map.setGps_weidu((String) obj[0]);
            map.setGsp_jingdu((String) obj[1]);
            map.setTagid((String) obj[2]);
            map.setGps_haiba_gao((String) obj[3]);
            tb_mapList.add(map);
         }
      }
      return tb_mapList;
   }
   public List<tb_map> getMap_all() {
      String sql = null;
      Query query = null;
@@ -114,6 +163,32 @@
      return tb_mapList;
   }
   
   public List<tb_map> getMap_all2(String floor) {
      String sql = null;
      Query query = null;
      sql = "SELECT floor,mapname,x_Truelength,y_Truewidth,x0_length,y0_width,x_Pixel,y_Pixel FROM tb_map WHERE mapname = :floor";
      query = this.em.createNativeQuery(sql);
      query.setParameter("floor", floor);
      List resultList = query.getResultList();
      List<tb_map> tb_mapList = new ArrayList<tb_map>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_map map = new tb_map();
            Object[] obj = (Object[]) resultList.get(i);
            map.setFloor((String) obj[0]);
            map.setMapname((String) obj[1]);
            map.setX_Truelength((String) obj[2]);
            map.setY_Truewidth((String) obj[3]);
            map.setX0_length((String) obj[4]);
            map.setY0_width((String) obj[5]);
            map.setX_Pixel((String) obj[6]);
            map.setY_Pixel((String) obj[7]);
            tb_mapList.add(map);
         }
      }
      return tb_mapList;
   }
   public List<tb_map> getFloor() {
      String sql = null;
      Query query = null;
@@ -133,6 +208,26 @@
      return tb_mapList;
   }
   
   public List<tb_map> getFloor2(String floor) {
      String sql = null;
      Query query = null;
      sql = "SELECT floor,mapname FROM tb_map WHERE mapname = :floor";
      query = this.em.createNativeQuery(sql);
      query.setParameter("floor", floor);
      List resultList = query.getResultList();
      List<tb_map> tb_mapList = new ArrayList<tb_map>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_map map = new tb_map();
            Object[] obj = (Object[]) resultList.get(i);
            map.setFloor((String) obj[0]);
            map.setMapname((String) obj[1]);
            tb_mapList.add(map);
         }
      }
      return tb_mapList;
   }
   public List<tb_map> getFloorByMapname(String mapname) {
      String sql = null;
      Query query = null;
@@ -186,7 +281,7 @@
            fence.setType((String) obj[1]);
            fence.setBumen((String) obj[2]);
            fence.setName((String) obj[3]);
            fence.setZuobiao((String) obj[4]);
            fence.setZuobiao(obj[4].toString().replaceAll(";", ","));
            fence.setShape((String) obj[5]);
            fence.setStart(obj[6] == null ? "" : obj[6].toString());
            fence.setStop(obj[7] == null ? "" : obj[7].toString());
@@ -201,7 +296,7 @@
   public List<tb_fence> getFence_all() {
      String sql = null;
      Query query = null;
      sql = "SELECT floor,type,bumen,name,zuobiao,shape,start,stop,addtime,color FROM tb_fence";
      sql = "SELECT floor,type,bumen,name,zuobiao,shape,start,stop,addtime,color FROM tb_fence where type != '变电站'";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_fence> tb_fenceList = new ArrayList<tb_fence>();
@@ -213,7 +308,35 @@
            fence.setType((String) obj[1]);
            fence.setBumen((String) obj[2]);
            fence.setName((String) obj[3]);
            fence.setZuobiao((String) obj[4]);
            fence.setZuobiao(obj[4].toString().replaceAll(";", ","));
            fence.setShape((String) obj[5]);
            fence.setStart(obj[6] == null ? "" : obj[6].toString());
            fence.setStop(obj[7] == null ? "" : obj[7].toString());
            fence.setAddtime((String) obj[8]);
            fence.setColor((String) obj[9]);
            tb_fenceList.add(fence);
         }
      }
      return tb_fenceList;
   }
   public List<tb_fence> getFenceaaa(String name) {
      String sql = null;
      Query query = null;
      sql = "SELECT floor,type,bumen,name,zuobiao,shape,start,stop,addtime,color FROM tb_fence WHERE name=:name";
      query = this.em.createNativeQuery(sql);
      query.setParameter("name", name);
      List resultList = query.getResultList();
      List<tb_fence> tb_fenceList = new ArrayList<tb_fence>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_fence fence = new tb_fence();
            Object[] obj = (Object[]) resultList.get(i);
            fence.setFloor((String) obj[0]);
            fence.setType((String) obj[1]);
            fence.setBumen((String) obj[2]);
            fence.setName((String) obj[3]);
            fence.setZuobiao(obj[4].toString().replaceAll(";", ","));
            fence.setShape((String) obj[5]);
            fence.setStart(obj[6] == null ? "" : obj[6].toString());
            fence.setStop(obj[7] == null ? "" : obj[7].toString());
@@ -233,7 +356,7 @@
      cs.tb_caozuo("tb_fence", 1);
      query = this.em.createNativeQuery(sql);
      query.setParameter("id", fence.getId());
      query.setParameter("floor", Integer.parseInt(fence.getFloor()));
      query.setParameter("floor", fence.getFloor());
      query.setParameter("type", fence.getType());
      query.setParameter("bumen", fence.getBumen());
      query.setParameter("name", fence.getName());
@@ -247,6 +370,57 @@
   }
   
   @Transactional
   public int drawFence_add2(tb_fence fence) {
      if (fence.getBaoliu7() == "") {
         fence.setBaoliu7("0");
      }
      String sql = null;
      Query query = null;
      sql = "INSERT INTO tb_fence(floor,type,name,zuobiao,shape,start,stop,addtime,color,baoliu1,baoliu3,baoliu4,bumen,baoliu6,baoliu7) VALUES(:floor,:type,:name,:zuobiao,:shape,:start,:stop,now(),:color,:baoliu1,:baoliu3,:baoliu4,:bumen,:baoliu6,:baoliu7)";
      cs.tb_caozuo("tb_fence", 1);
      query = this.em.createNativeQuery(sql);
      query.setParameter("floor", fence.getFloor());
      query.setParameter("type", fence.getType());
      query.setParameter("name", fence.getName());
      query.setParameter("zuobiao", fence.getZuobiao());
      query.setParameter("shape", fence.getShape());
      query.setParameter("start", fence.getStart());
      query.setParameter("stop", fence.getStop());
      query.setParameter("color", fence.getColor());
      query.setParameter("baoliu1", fence.getBaoliu1());
//    query.setParameter("baoliu2", fence.getBaoliu2());
      query.setParameter("baoliu3", fence.getBaoliu3());
      query.setParameter("baoliu4", fence.getBaoliu4());
      query.setParameter("bumen", fence.getBumen());
      query.setParameter("baoliu6", fence.getBaoliu6());
      query.setParameter("baoliu7", fence.getBaoliu7());
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public int sanweiFence_add(tb_fence fence) {
      String sql = null;
      Query query = null;
      sql = "INSERT INTO tb_fence(id,floor,type,bumen,name,zuobiao,shape,start,stop,addtime,color,baoliu1) VALUES(:id,:floor,:type,:bumen,:name,:zuobiao,:shape,:start,:stop,now(),:color,:baoliu1)";
      cs.tb_caozuo("tb_fence", 1);
      query = this.em.createNativeQuery(sql);
      query.setParameter("id", fence.getId());
      query.setParameter("floor", fence.getFloor());
      query.setParameter("type", fence.getType());
      query.setParameter("bumen", fence.getBumen());
      query.setParameter("name", fence.getName());
      query.setParameter("zuobiao", fence.getZuobiao());
      query.setParameter("shape", fence.getShape());
      query.setParameter("start", fence.getStart());
      query.setParameter("stop", fence.getStop());
      query.setParameter("color", fence.getColor());
      query.setParameter("baoliu1", fence.getBaoliu1());
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public int xunjianSet_add(String name) {
      String sql = null;
      Query query = null;
@@ -302,19 +476,19 @@
      Query query = null;
      SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date now=dateFormat.parse(begin_time);
      System.out.print(now);
      //System.out.print(now);
      SimpleDateFormat dateFormat2=new SimpleDateFormat("yyyyMMdd");
      String now2 = dateFormat2.format(now);
      System.out.print(now2);
//    System.out.print(begin_time);
//    System.out.print(end_time);
//    System.out.print(tag_id);
//    System.out.print(floor);
      //System.out.print(now2);
//    //System.out.print(begin_time);
//    //System.out.print(end_time);
//    //System.out.print(tag_id);
//    //System.out.print(floor);
      
      sql = "SELECT tagid,x,y,z,layer,time FROM tb_track_"+now2+" WHERE layer= '"+floor+"' AND tagid= '"+tag_id+"' AND time>= '"+begin_time+"' AND time<= '"+end_time+"' ORDER BY time";
      sql = "SELECT tagid,x,y,z,layer,time,baoliu1,baoliu2,baoliu3,baoliu4 FROM tb_track_"+now2+" WHERE layer= '"+floor+"' AND tagid= '"+tag_id+"' AND time>= '"+begin_time+"' AND time<= '"+end_time+"' ORDER BY time";
//    sql = "SELECT tagid,x,y,z,layer,time FROM tb_track WHERE layer= '"+floor+"' AND tagid= '"+tag_id+"' AND time>= '"+begin_time+"' AND time<= '"+end_time+"'";
      
      System.out.print(sql);
      //System.out.print(sql);
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_track> tb_trackList = new ArrayList<tb_track>();
@@ -328,6 +502,84 @@
            map.setZ((String) obj[3]);
            map.setLayer((String) obj[4]);
            map.setTime((String) obj[5]);
            map.setFangkeid((String) obj[6]);
            map.setJingdu((String) obj[7]);
            map.setWeidu((String) obj[8]);
            map.setGaocheng((String) obj[9]);
            tb_trackList.add(map);
         }
      }
      return tb_trackList;
   }
   public List<tb_track> getTagtrack2(String name,String begin_time,String end_time,String floor) throws ParseException {
      String sql = null;
      Query query = null;
      SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date now=dateFormat.parse(begin_time);
      //System.out.print(now);
      SimpleDateFormat dateFormat2=new SimpleDateFormat("yyyyMMdd");
      String now2 = dateFormat2.format(now);
      //System.out.print(now2);
//    //System.out.print(begin_time);
//    //System.out.print(end_time);
//    //System.out.print(tag_id);
//    //System.out.print(floor);
      sql = "SELECT tagid,x,y,z,layer,time,baoliu1,baoliu2,baoliu3,baoliu4 FROM tb_track_"+now2+" WHERE layer= '"+floor+"' AND baoliu8= '"+name+"' AND time>= '"+begin_time+"' AND time<= '"+end_time+"' ORDER BY time";
//    sql = "SELECT tagid,x,y,z,layer,time FROM tb_track WHERE layer= '"+floor+"' AND tagid= '"+tag_id+"' AND time>= '"+begin_time+"' AND time<= '"+end_time+"'";
      //System.out.print(sql);
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_track> tb_trackList = new ArrayList<tb_track>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_track map = new tb_track();
            Object[] obj = (Object[]) resultList.get(i);
            map.setTagid((String) obj[0]);
            map.setX((String) obj[1]);
            map.setY((String) obj[2]);
            map.setZ((String) obj[3]);
            map.setLayer((String) obj[4]);
            map.setTime((String) obj[5]);
            map.setFangkeid((String) obj[6]);
            map.setJingdu((String) obj[7]);
            map.setWeidu((String) obj[8]);
            map.setGaocheng((String) obj[9]);
            tb_trackList.add(map);
         }
      }
      return tb_trackList;
   }
   public List<tb_track> getTagtrack3(String tag_id,String begin_time,String end_time) throws ParseException {
      String sql = null;
      Query query = null;
      SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date now=dateFormat.parse(begin_time);
      SimpleDateFormat dateFormat2=new SimpleDateFormat("yyyyMMdd");
      String now2 = dateFormat2.format(now);
      sql = "SELECT tagid,x,y,z,layer,time,baoliu1,baoliu2,baoliu3,baoliu4 FROM tb_track_"+now2+" WHERE tagid= '"+tag_id+"' AND time>= '"+begin_time+"' AND time<= '"+end_time+"' ORDER BY time";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_track> tb_trackList = new ArrayList<tb_track>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_track map = new tb_track();
            Object[] obj = (Object[]) resultList.get(i);
            map.setTagid((String) obj[0]);
            map.setX((String) obj[1]);
            map.setY((String) obj[2]);
            map.setZ((String) obj[3]);
            map.setLayer((String) obj[4]);
            map.setTime((String) obj[5]);
            map.setFangkeid((String) obj[6]);
            map.setJingdu((String) obj[7]);
            map.setWeidu((String) obj[8]);
            map.setGaocheng((String) obj[9]);
            tb_trackList.add(map);
         }
      }
@@ -471,7 +723,7 @@
   public List<tb_person> getpersonLocation(String floor) {
      String sql = null;
      Query query = null;
      sql = "SELECT a.* FROM tb_person AS a,( SELECT p_tagid, max( p_addtiem ) time FROM tb_person GROUP BY p_tagid ) AS b WHERE a.p_addtiem = b.time AND a.p_tagid = b.p_tagid AND a.p_floor='"+floor+"'";
      sql = "SELECT * FROM tb_person WHERE p_floor='"+floor+"'";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_realocationList = new ArrayList<tb_person>();
@@ -481,6 +733,9 @@
            Object[] obj = (Object[]) resultList.get(i);
            realocation.setP_name((String) obj[1]);
            realocation.setP_tagid((String) obj[2]);
            realocation.setP_phone((String) obj[5]);
            realocation.setP_department((String) obj[6]);
            realocation.setP_idcardnum((String) obj[9]);
            realocation.setP_x((String) obj[12]);
            realocation.setP_y((String) obj[13]);
            realocation.setP_floor((String) obj[14]);
@@ -495,6 +750,139 @@
            realocation.setP_addtiem((String) obj[23]);
            realocation.setP_sousuo((String) obj[25]);
            realocation.setP_shipin((String) obj[26]);
            realocation.setP_jingdu((String) obj[29]);
            realocation.setP_weidu((String) obj[30]);
            realocation.setP_gaocheng((String) obj[31]);
            realocation.setBaoliu10((String) obj[37]);
            realocation.setBaoliu22((String) obj[49]);
            tb_realocationList.add(realocation);
         }
      }
      return tb_realocationList;
   }
   public List<tb_person> getpersonLocationsan() {
      String sql = null;
      Query query = null;
      sql = "SELECT * FROM tb_person";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_realocationList = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person realocation = new tb_person();
            Object[] obj = (Object[]) resultList.get(i);
            realocation.setP_name((String) obj[1]);
            realocation.setP_tagid((String) obj[2]);
            realocation.setP_sex((String) obj[3]);
            realocation.setP_minzu((String) obj[4]);
            realocation.setP_phone((String) obj[5]);
            realocation.setP_department((String) obj[6]);
            realocation.setP_x((String) obj[12]);
            realocation.setP_y((String) obj[13]);
            realocation.setP_floor((String) obj[14]);
            realocation.setP_sos((String) obj[15]);
            realocation.setP_online((String) obj[16]);
            realocation.setP_power((String) obj[17]);
            realocation.setP_kaoqing((String) obj[18]);
            realocation.setP_fence((String) obj[19]);
            realocation.setP_fencename((String) obj[20]);
            realocation.setP_kaoqqingname((String) obj[21]);
            realocation.setP_image((String) obj[22]);
            realocation.setP_addtiem((String) obj[23]);
            realocation.setP_sousuo((String) obj[25]);
            realocation.setP_shipin((String) obj[26]);
            realocation.setP_fangkeid((String) obj[28]);
            realocation.setP_jingdu((String) obj[29]);
            realocation.setP_weidu((String) obj[30]);
            realocation.setP_gaocheng((String) obj[31]);
            realocation.setBaoliu22((String) obj[49]);
            realocation.setBaoliu23((String) obj[50]);
            realocation.setBaoliu24((String) obj[51]);
            tb_realocationList.add(realocation);
         }
      }
      return tb_realocationList;
   }
   public List<tb_person> getpersonLocationsan3(String floor) {
      String sql = null;
      Query query = null;
      sql = "SELECT * FROM tb_person where p_floor="+floor;
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_realocationList = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person realocation = new tb_person();
            Object[] obj = (Object[]) resultList.get(i);
            realocation.setP_name((String) obj[1]);
            realocation.setP_tagid((String) obj[2]);
            realocation.setP_sex((String) obj[3]);
            realocation.setP_minzu((String) obj[4]);
            realocation.setP_phone((String) obj[5]);
            realocation.setP_department((String) obj[6]);
            realocation.setP_x((String) obj[12]);
            realocation.setP_y((String) obj[13]);
            realocation.setP_floor((String) obj[14]);
            realocation.setP_sos((String) obj[15]);
            realocation.setP_online((String) obj[16]);
            realocation.setP_power((String) obj[17]);
            realocation.setP_kaoqing((String) obj[18]);
            realocation.setP_fence((String) obj[19]);
            realocation.setP_fencename((String) obj[20]);
            realocation.setP_kaoqqingname((String) obj[21]);
            realocation.setP_image((String) obj[22]);
            realocation.setP_addtiem((String) obj[23]);
            realocation.setP_sousuo((String) obj[25]);
            realocation.setP_shipin((String) obj[26]);
            realocation.setP_fangkeid((String) obj[28]);
            realocation.setP_jingdu((String) obj[29]);
            realocation.setP_weidu((String) obj[30]);
            realocation.setP_gaocheng((String) obj[31]);
            realocation.setBaoliu22((String) obj[49]);
            realocation.setBaoliu23((String) obj[50]);
            realocation.setBaoliu24((String) obj[51]);
            tb_realocationList.add(realocation);
         }
      }
      return tb_realocationList;
   }
   public List<tb_person> getpersonLocationsan2() {
      String sql = null;
      Query query = null;
      sql = "SELECT a.p_name,a.p_tagid,a.p_idcardnum,a.p_x,a.p_y,a.p_floor,a.p_sos,a.p_online,a.p_power,a.p_kaoqing,a.p_fence,a.p_fencename,a.p_kaoqqingname,a.p_image,a.p_addtiem,a.p_sousuo,a.p_shipin,a.baoliu1,a.baoliu2,a.baoliu3,a.baoliu4,a.p_phone,b.type FROM tb_person AS a,tb_tag AS b WHERE a.p_tagid=b.tag_id";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_realocationList = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person realocation = new tb_person();
            Object[] obj = (Object[]) resultList.get(i);
            realocation.setP_name((String) obj[0]);
            realocation.setP_tagid((String) obj[1]);
            realocation.setP_idcardnum((String) obj[2]);
            realocation.setP_x((String) obj[3]);
            realocation.setP_y((String) obj[4]);
            realocation.setP_floor((String) obj[5]);
            realocation.setP_sos((String) obj[6]);
            realocation.setP_online((String) obj[7]);
            realocation.setP_power((String) obj[8]);
            realocation.setP_kaoqing((String) obj[9]);
            realocation.setP_fence((String) obj[10]);
            realocation.setP_fencename((String) obj[11]);
            realocation.setP_kaoqqingname((String) obj[12]);
            realocation.setP_image((String) obj[13]);
            realocation.setP_addtiem((String) obj[14]);
            realocation.setP_sousuo((String) obj[15]);
            realocation.setP_shipin((String) obj[16]);
            realocation.setP_fangkeid((String) obj[17]);
            realocation.setP_jingdu((String) obj[18]);
            realocation.setP_weidu((String) obj[19]);
            realocation.setP_gaocheng((String) obj[20]);
            realocation.setP_phone((String)obj[21]);
            realocation.setP_type((String) obj[22]);
            tb_realocationList.add(realocation);
         }
      }
@@ -504,7 +892,7 @@
   public List<tb_person> getpersonLocation_all() {
      String sql = null;
      Query query = null;
      sql = "SELECT a.* FROM tb_person AS a,( SELECT p_tagid, max( p_addtiem ) time FROM tb_person GROUP BY p_tagid ) AS b WHERE a.p_addtiem = b.time AND a.p_tagid = b.p_tagid";
      sql = "SELECT * FROM tb_person";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_realocationList = new ArrayList<tb_person>();
@@ -526,6 +914,11 @@
            realocation.setP_kaoqqingname((String) obj[21]);
            realocation.setP_image((String) obj[22]);
            realocation.setP_addtiem((String) obj[23]);
            realocation.setP_shipin((String) obj[26]);
            realocation.setP_shipingname((String) obj[27]);
            realocation.setBaoliu6((String) obj[33]);
            realocation.setBaoliu20((String) obj[47]);
            realocation.setBaoliu21((String) obj[48]);
            tb_realocationList.add(realocation);
         }
      }
@@ -636,7 +1029,7 @@
   public List<tb_gps> getGPS() {
      String sql = null;
      Query query = null;
      sql = "SELECT a.*,c.p_name FROM tb_gps AS a,( SELECT tagid, max(addtime) time FROM tb_gps GROUP BY tagid ) AS b, tb_person as c WHERE a.addtime = b.time AND a.tagid = b.tagid AND c.p_tagid=a.tagid";
      sql = "SELECT a.id,a.gps_utc_time,a.gps_weidu,a.gps_NS,a.gsp_jingdu,a.gps_EW,a.gps_state,a.gps_num,a.gps_hdop,a.gps_haiba_gao,a.gps_tuoqiu,a.gps_chafen_time,a.gps_chafen_id,a.gps_jiaoyan,a.tagid,a.gps_kahao,a.gps_power,a.gps_sos,a.addtime,c.p_name,c.p_online,c.p_sex,c.p_minzu,c.p_phone,c.p_department,c.baoliu13,c.baoliu14,c.baoliu15,c.p_addtiem FROM tb_gps AS a,( SELECT tagid, max(addtime) time FROM tb_gps GROUP BY tagid ) AS b, tb_person as c WHERE a.addtime = b.time AND a.tagid = b.tagid AND c.p_tagid=a.tagid";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_gps> tb_gpsList = new ArrayList<tb_gps>();
@@ -649,7 +1042,7 @@
            gps.setGps_NS((String) obj[3]);
            gps.setGsp_jingdu((String) obj[4]);
            gps.setGps_EW((String) obj[5]);
            gps.setGps_state((String) obj[6]);
            gps.setGps_state((String) obj[20]);
            gps.setGps_num((String) obj[7]);
            gps.setGps_hdop((String) obj[8]);
            gps.setGps_haiba_gao((String) obj[9]);
@@ -663,6 +1056,14 @@
            gps.setGps_sos((String) obj[17]);
            gps.setAddtime((String) obj[18]);
            gps.setName((String) obj[19]);
            gps.setSex((String) obj[21]);
            gps.setMinzu((String) obj[22]);
            gps.setDianhua((String) obj[23]);
            gps.setBumen((String) obj[24]);
            gps.setBaoliu13((String) obj[25]);
            gps.setBaoliu14((String) obj[26]);
            gps.setBaoliu15((String) obj[27]);
            gps.setP_addtiem((String) obj[28]);
            tb_gpsList.add(gps);
         }
      }
@@ -677,7 +1078,7 @@
      SimpleDateFormat dateFormat2=new SimpleDateFormat("yyyyMMdd");
      String now2 = dateFormat2.format(now);
      sql = "SELECT a.*,b.p_name FROM tb_gps_track_"+now2+" AS a, tb_person AS b WHERE a.tagid= '"+tag_id+"' AND a.addtime>= '"+begin_time+"' AND a.addtime<= '"+end_time+"' AND a.tagid=b.p_tagid ORDER BY addtime";
      System.out.print(sql);
      //System.out.print(sql);
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_gps> tb_trackList = new ArrayList<tb_gps>();
@@ -859,6 +1260,42 @@
   }
   
   @Transactional
   public int chaichugao(String tagid) {
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_person SET baoliu6=0 WHERE p_tagid=:tagid";
      cs.tb_caozuo("tb_person", 3);
      query = this.em.createNativeQuery(sql);
      query.setParameter("tagid", tagid);
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public int jinmengao(String tagid) {
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_person SET baoliu20=0 WHERE p_tagid=:tagid";
      cs.tb_caozuo("tb_person", 3);
      query = this.em.createNativeQuery(sql);
      query.setParameter("tagid", tagid);
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public int chumengao(String tagid) {
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_person SET baoliu21=0 WHERE p_tagid=:tagid";
      cs.tb_caozuo("tb_person", 3);
      query = this.em.createNativeQuery(sql);
      query.setParameter("tagid", tagid);
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public int shipin(String tagid) {
      String sql = null;
      Query query = null;
@@ -882,21 +1319,41 @@
      return status;
   }
   
   public String getfencezuobiao() {
      String sql = null;
      Query query = null;
      sql = "SELECT zuobiao from tb_linshi_fence_22414 WHERE id=1";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      String status = resultList.get(0).toString();
      return status;
   }
   public String getfencehaibagao() {
      String sql = null;
      Query query = null;
      sql = "SELECT baoliu4 from tb_linshi_fence_22414 WHERE id=1";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      String status = resultList.get(0).toString();
      return status;
   }
   public List<tb_person> getfencename(String tagid) {
      String sql = null;
      Query query = null;
      sql = "SELECT p_fencename from tb_person WHERE p_tagid="+tagid;
      query = this.em.createNativeQuery(sql);
//    System.out.print(sql);
//    //System.out.print(sql);
      List resultList = query.getResultList();
//    System.out.print(resultList.size());
//    //System.out.print(resultList.size());
      List<tb_person> tb_person = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person person = new tb_person();
//          Object[] obj = (Object[]) resultList.get(i);
            person.setP_fencename(resultList.get(i) == null ? "" : resultList.get(i).toString());
//          System.out.print(person.getP_fencename());
//          //System.out.print(person.getP_fencename());
            tb_person.add(person);
         }
      }
@@ -915,12 +1372,351 @@
         for (int i = 0; i < resultList.size(); i++) {
            tb_shipin shipin = new tb_shipin();
            Object[] obj = (Object[]) resultList.get(i);
            shipin.setShebeiid((String) obj[0]);
            shipin.setTongdaoid((String) obj[1]);
            shipin.setYonghuming((String) obj[0]);
            shipin.setMima((String) obj[1]);
            tb_shipinList.add(shipin);
         }
      }
      return tb_shipinList;
   }
   public List<tb_qihou> qihoucha() {
      String sql = null;
      Query query = null;
      sql = "SELECT id,time,place,weather,wd,sd FROM tb_qihou";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_qihou> tb_qihouList = new ArrayList<tb_qihou>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_qihou qihou = new tb_qihou();
            Object[] obj = (Object[]) resultList.get(i);
            qihou.setId((int) obj[0]);
            qihou.setTime(obj[1] == null ? "" : obj[1].toString());
            qihou.setPlace(obj[2] == null ? "" : obj[2].toString());
            qihou.setWeather(obj[3] == null ? "" : obj[3].toString());
            qihou.setWd(obj[4] == null ? "" : obj[4].toString());
            qihou.setSd(obj[5] == null ? "" : obj[5].toString());
            tb_qihouList.add(qihou);
         }
      }
      return tb_qihouList;
   }
   public List<tb_qihou> qihoucha(int page) {
      String sql = null;
      Query query = null;
      sql = "SELECT id,time,place,weather,wd,sd FROM (SELECT id,time,place,weather,wd,sd FROM tb_qihou ORDER BY time DESC) s LIMIT :start,:end";
      query = this.em.createNativeQuery(sql);
      query.setParameter("start", (page - 1) * Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage")));
      query.setParameter("end", Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage")));
      List resultList = query.getResultList();
      List<tb_qihou> tb_qihouList = new ArrayList<tb_qihou>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_qihou qihou = new tb_qihou();
            Object[] obj = (Object[]) resultList.get(i);
            qihou.setId((int) obj[0]);
            qihou.setTime(obj[1] == null ? "" : obj[1].toString());
            qihou.setPlace(obj[2] == null ? "" : obj[2].toString());
            qihou.setWeather(obj[3] == null ? "" : obj[3].toString());
            qihou.setWd(obj[4] == null ? "" : obj[4].toString());
            qihou.setSd(obj[5] == null ? "" : obj[5].toString());
            tb_qihouList.add(qihou);
         }
      }
      return tb_qihouList;
   }
   @Transactional
   public int qihouzeng(tb_qihou qihou) {
      String sql = null;
      Query query = null;
      sql = "INSERT INTO tb_qihou(time,place,weather,wd,sd) VALUES(now(),:place,:weather,:wd,:sd)";
      query = this.em.createNativeQuery(sql);
      query.setParameter("place", qihou.getPlace());
      query.setParameter("weather", qihou.getWeather());
      query.setParameter("wd", qihou.getWd());
      query.setParameter("sd", qihou.getSd());
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public void qihoudelete(String[] checkVal) {
      String sql = null;
      Query query = null;
      for (int i = 0; i < checkVal.length; i++) {
         sql = "DELETE FROM tb_qihou WHERE id = :id";
         query = this.em.createNativeQuery(sql);
         query.setParameter("id", checkVal[i]);
         query.executeUpdate();
      }
   }
   @Transactional
   public void qihoudeleteAll() {
      String sql = null;
      Query query = null;
      sql = "DELETE FROM tb_qihou";
      query = this.em.createNativeQuery(sql);
      query.executeUpdate();
   }
   @Transactional
   public void qihougai(tb_qihou qihou) {
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_qihou SET place=:place,weather=:weather,wd=:wd,sd=:sd WHERE id=:id";
      query = this.em.createNativeQuery(sql);
      query.setParameter("id", qihou.getId());
      query.setParameter("place", qihou.getPlace());
      query.setParameter("weather", qihou.getWeather());
      query.setParameter("wd", qihou.getWd());
      query.setParameter("sd", qihou.getSd());
      query.executeUpdate();
   }
   public int getqihouManagementCount() {
      String sql = null;
      Query query = null;
      sql = "SELECT count(1) FROM tb_qihou";
      query = this.em.createNativeQuery(sql);
      return Integer.parseInt(query.getSingleResult().toString());
   }
   public List<tb_realkaoqing> getkaoqinsan() {
      String sql = null;
      Query query = null;
      sql = "SELECT * FROM tb_realkaoqing";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_realkaoqing> tb_realkaoqinList = new ArrayList<tb_realkaoqing>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_realkaoqing realocation = new tb_realkaoqing();
            Object[] obj = (Object[]) resultList.get(i);
            realocation.setArea((String) obj[1]);
            realocation.setName((String) obj[2]);
            realocation.setBumen((String) obj[3]);
            realocation.setTagid((String) obj[4]);
            realocation.setIntime((String) obj[5]);
            realocation.setJuli((String) obj[7]);
            tb_realkaoqinList.add(realocation);
         }
      }
      return tb_realkaoqinList;
   }
   public List<tb_person> getsosgaojing() {
      String sql = null;
      Query query = null;
      sql = "select p_tagid from tb_person where p_sos = '1'";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> soslist = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person person = new tb_person();
            person.setP_tagid(resultList.get(i) == null ? "" : resultList.get(i).toString());
            soslist.add(person);
         }
      }
      return soslist;
   }
   public List<tb_person> getfencegaojing() {
      String sql = null;
      Query query = null;
      sql = "select p_tagid from tb_person where p_fence = '1'";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> soslist = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person person = new tb_person();
            person.setP_tagid(resultList.get(i) == null ? "" : resultList.get(i).toString());
            soslist.add(person);
         }
      }
      return soslist;
   }
   public List<tb_person> getchufencegaojing() {
      String sql = null;
      Query query = null;
      sql = "select p_tagid from tb_person where p_fence = '2'";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> soslist = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person person = new tb_person();
            person.setP_tagid(resultList.get(i) == null ? "" : resultList.get(i).toString());
            soslist.add(person);
         }
      }
      return soslist;
   }
   public List<tb_person> getjinchumengaojing() {
      String sql = null;
      Query query = null;
      sql = "select p_tagid from tb_person where baoliu20 = '1' and baoliu21 = '1'";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> soslist = new ArrayList<tb_person>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_person person = new tb_person();
            person.setP_tagid(resultList.get(i) == null ? "" : resultList.get(i).toString());
            soslist.add(person);
         }
      }
      return soslist;
   }
   public List<tb_jingwei> getjingwei() {
      String sql = null;
      Query query = null;
      sql = "SELECT id,qishi,zhongzhi,jieguo,addtime FROM tb_jingwei ORDER BY addtime DESC";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_jingwei> tb_jingweiList = new ArrayList<tb_jingwei>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_jingwei jingwei = new tb_jingwei();
            Object[] obj = (Object[]) resultList.get(i);
            jingwei.setId((int) obj[0]);
            jingwei.setQishi((String) obj[1]);
            jingwei.setZhongzhi((String) obj[2]);
            jingwei.setJieguo((String) obj[3]);
            jingwei.setAddtime((String) obj[4]);
            tb_jingweiList.add(jingwei);
         }
      }
      return tb_jingweiList;
   }
   @Transactional
   public int addjingwei(tb_jingwei jingwei) {
      String sql = null;
      Query query = null;
      sql = "insert into tb_jingwei(qishi,zhongzhi,jieguo,addtime) values(:qishi,:zhongzhi,:jieguo,:addtime)";
      query = this.em.createNativeQuery(sql);
      query.setParameter("qishi", jingwei.getQishi());
      query.setParameter("zhongzhi", jingwei.getZhongzhi());
      query.setParameter("jieguo", jingwei.getJieguo());
      query.setParameter("addtime", jingwei.getAddtime());
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   public List<tb_nav> getnav() {
      String sql = null;
      Query query = null;
      sql = "SELECT id,label,achor,gps,fence,warning,history,attendance,basiclnfo,video,gas FROM tb_nav";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_nav> navlist = new ArrayList<tb_nav>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            tb_nav nav = new tb_nav();
            Object[] obj = (Object[]) resultList.get(i);
            nav.setId((int) obj[0]);
            nav.setLabel((String) obj[1]);
            nav.setAchor((String) obj[2]);
            nav.setGps((String) obj[3]);
            nav.setFence((String) obj[4]);
            nav.setWarning((String) obj[5]);
            nav.setHistory((String) obj[6]);
            nav.setAttendance((String) obj[7]);
            nav.setBasiclnfo((String) obj[8]);
            nav.setVideo((String) obj[9]);
            nav.setGas((String) obj[10]);
            navlist.add(nav);
         }
      }
      return navlist;
   }
   @Transactional
   public int updatenav(tb_nav nav) {
      String sql = null;
      Query query = null;
      sql = "update tb_nav set label = :label,achor = :achor,gps = :gps,fence = :fence,warning = :warning,history = :history,attendance = :attendance,basiclnfo = :basiclnfo,video = :video,gas = :gas where id = 1";
      query = this.em.createNativeQuery(sql);
      query.setParameter("label", nav.getLabel());
      query.setParameter("achor", nav.getAchor());
      query.setParameter("gps", nav.getGps());
      query.setParameter("fence", nav.getFence());
      query.setParameter("warning", nav.getWarning());
      query.setParameter("history", nav.getHistory());
      query.setParameter("attendance", nav.getAttendance());
      query.setParameter("basiclnfo", nav.getBasiclnfo());
      query.setParameter("video", nav.getVideo());
      query.setParameter("gas", nav.getGas());
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
      
   public List<tb_person> getbumen(){
      String sql = null;
      Query query = null;
      sql = "select p_name,p_department,p_tagid from tb_person";
      query = this.em.createNativeQuery(sql);
      List resultlist = query.getResultList();
      List<tb_person> persons = new ArrayList<>();
      if(resultlist.size() > 0) {
         for(int i=0; i<resultlist.size(); i++) {
            Object[] obj = (Object[]) resultlist.get(i);
            tb_person person = new tb_person();
            person.setP_name(obj[0] == null?null:obj[0].toString());
            person.setP_department(obj[1] == null?null:obj[1].toString());
            person.setP_tagid(obj[2] == null?null:obj[2].toString());
            persons.add(person);
         }
      }
      return persons;
   }
   public List<tb_message> getmessage(){
      String sql = null;
      Query query = null;
      sql = "SELECT * FROM tb_message_history WHERE Replytime IS NOT NULL order by Replytime desc";
      query = this.em.createNativeQuery(sql);
      List resultlist = query.getResultList();
      List<tb_message> messages = new ArrayList<>();
      if (resultlist.size() > 0) {
         for (int i=0; i<resultlist.size(); i++) {
            Object[] obj = (Object[]) resultlist.get(i);
            tb_message mess = new tb_message();
            mess.setId((int)obj[0]);
            mess.setMessage(obj[7]==null?null:obj[7].toString());
            mess.setAddtime(obj[6]==null?null:obj[6].toString());
            mess.setBaoliu2(obj[8]==null?null:obj[8].toString());
            messages.add(mess);
         }
      }
      return messages;
   }
   @Transactional
   public void deletemessage(String date) {
      String sql = null;
      Query query = null;
      sql = "delete from tb_message_history where Replytime < :date";
      query = this.em.createNativeQuery(sql);
      query.setParameter("date", date);
      query.executeUpdate();
   }
   public String getlixian(){
      String sql = null;
      Query query = null;
      sql = "SELECT baoliu5 FROM tb_linshi_fence_22414 WHERE id = 1";
      query = this.em.createNativeQuery(sql);
      List resultlist = query.getResultList();
      return resultlist.get(0).toString();
   }
}