fxl
2023-05-04 e150655a785de36a65a26a0dc4d3d6d65fe7e9d0
src/main/java/com/hxzkoa/services/LabelService.java
@@ -16,6 +16,7 @@
import com.hxzkoa.json.tb_achor;
import com.hxzkoa.json.tb_adress_and_port;
import com.hxzkoa.json.tb_history_power;
import com.hxzkoa.json.tb_permission;
import com.hxzkoa.json.tb_person;
import com.hxzkoa.json.tb_tag;
import com.hxzkoa.json.tb_tagpower;
@@ -60,10 +61,10 @@
   public List<tb_tag> getLabelManagement(int page) {
      String sql = null;
      Query query = null;
      sql = "SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu FROM (SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu FROM tb_tag ORDER BY id DESC) s LIMIT :start,:end";
      sql = "SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM (SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM tb_tag ORDER BY id 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")));
      query.setParameter("end", 50);
      List resultList = query.getResultList();
      List<tb_tag> tb_tagList = new ArrayList<tb_tag>();
      if (resultList.size() > 0) {
@@ -80,6 +81,7 @@
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
@@ -89,7 +91,7 @@
   public List<tb_tag> getLabelManagementa() {
      String sql = null;
      Query query = null;
      sql = "SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu FROM (SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu FROM tb_tag ORDER BY id DESC) s";
      sql = "SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM (SELECT id,tag_id,state,power,status,gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM tb_tag ORDER BY id DESC) s";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_tag> tb_tagList = new ArrayList<tb_tag>();
@@ -107,16 +109,41 @@
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
      return tb_tagList;
   }
   public List<tb_person> getLabelManagementa2() {
      String sql = null;
      Query query = null;
      sql = "SELECT id,p_tagid,p_name,p_fencename,p_department,baoliu4,baoliu16 FROM (SELECT id,p_tagid,p_name,p_fencename,p_department,baoliu4,baoliu16 FROM tb_person ORDER BY id DESC) s";
      query = this.em.createNativeQuery(sql);
      List resultList = query.getResultList();
      List<tb_person> tb_personList = new ArrayList<tb_person>();
      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.setId((int) obj[0]);
            person.setP_tagid(obj[1] == null ? "" : obj[1].toString());
            person.setP_name(obj[2] == null ? "" : obj[2].toString());
            person.setP_fencename(obj[3] == null ? "" : obj[3].toString());
            person.setP_department(obj[4] == null ? "" : obj[4].toString());
            person.setBaoliu4(obj[5] == null ? "" : obj[5].toString());
            person.setBaoliu12(obj[6] == null ? "" : obj[6].toString());
            tb_personList.add(person);
         }
      }
      return tb_personList;
   }
   public List<tb_tag> searchLabelManagement(String input) {
      String sql = null;
      Query query = null;
      sql = "SELECT id,tag_id,state,power,'status',gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu FROM tb_tag WHERE tag_id = :tag_id";
      sql = "SELECT id,tag_id,state,power,'status',gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM tb_tag WHERE tag_id = :tag_id OR state = :tag_id";
      query = this.em.createNativeQuery(sql);
      query.setParameter("tag_id", input);
      List resultList = query.getResultList();
@@ -135,6 +162,36 @@
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
      return tb_tagList;
   }
   public List<tb_tag> searchLabelManagementaa(String input) {
      String sql = null;
      Query query = null;
      sql = "SELECT id,tag_id,state,power,'status',gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM tb_tag WHERE tag_id = :tag_id";
      query = this.em.createNativeQuery(sql);
      query.setParameter("tag_id", input);
      List resultList = query.getResultList();
      List<tb_tag> tb_tagList = new ArrayList<tb_tag>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            Object[] obj = (Object[]) resultList.get(i);
            tb_tag tag = new tb_tag();
            tag.setId((int) obj[0]);
            tag.setStatus(obj[4] == null ? "" : obj[4].toString());
            tag.setTag_id(obj[1] == null ? "" : obj[1].toString());
            tag.setState(obj[2] == null ? "" : obj[2].toString());
            tag.setPower(obj[3] == null ? "" : obj[3].toString());
            tag.setGaodu(obj[5] == null ? "" : obj[5].toString());
            tag.setSudu(obj[6] == null ? "" : obj[6].toString());
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
@@ -148,6 +205,24 @@
      query = this.em.createNativeQuery(sql);
      return Integer.parseInt(query.getSingleResult().toString());
   }
   public int getdepartmentCount(String input) {
      String sql = null;
      Query query = null;
      sql = "SELECT count(1) FROM tb_person WHERE p_department = :department";
      query = this.em.createNativeQuery(sql);
      query.setParameter("department", input);
      return Integer.parseInt(query.getSingleResult().toString());
   }
   public int getdepartmentCount2(String input) {
      String sql = null;
      Query query = null;
      sql = "SELECT count(1) FROM tb_person WHERE p_department = :department and p_online = 1";
      query = this.em.createNativeQuery(sql);
      query.setParameter("department", input);
      return Integer.parseInt(query.getSingleResult().toString());
   }
   public List<String> getLabelManagementTagid() {
      String sql = null;
@@ -195,6 +270,62 @@
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public int anchorManagement_modifyaa(tb_achor achor) {
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_achor SET baoliu6=:baoliu6,baoliu7=:baoliu7 WHERE anchorid=:anchorid";
      query = this.em.createNativeQuery(sql);
      query.setParameter("anchorid", achor.getAnchorid());
      query.setParameter("baoliu6", achor.getBaoliu6());
      query.setParameter("baoliu7", achor.getBaoliu7());
      int aaa = query.executeUpdate();
      return aaa;
   }
   @Transactional
   public int updatetagname(tb_tag tag) {
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_tag SET state=:state WHERE tag_id=:tag_id";
      query = this.em.createNativeQuery(sql);
      query.setParameter("state", tag.getState());
      query.setParameter("tag_id", tag.getTag_id());
      int aaa = query.executeUpdate();
      return aaa;
   }
   @Transactional
   public int labelManagement_adda(tb_tag tag) {
      //默认值逻辑处理
      tag.setStatus("1");
      tag.setPower("100");
      if(("").equals(tag.getState())){
         tag.setState("未绑定");
      }
      if(("").equals(tag.getGaodu())){
         tag.setGaodu("150");
      }
      if(("").equals(tag.getSudu())){
         tag.setSudu("1000");
      }
      String sql = null;
      Query query = null;
      sql = "INSERT INTO tb_tag(status,tag_id,state,power,gaodu,sudu,pinglv,version,addtime) VALUES(:status,:tag_id,:state,:power,:gaodu,:sudu,:pinglv,:version,now())";
      cs.tb_caozuo("tb_tag", 1);
      query = this.em.createNativeQuery(sql);
      query.setParameter("status", tag.getStatus());
      query.setParameter("tag_id", tag.getTag_id());
      query.setParameter("state", tag.getState());
      query.setParameter("power", tag.getPower());
      query.setParameter("gaodu", tag.getGaodu());
      query.setParameter("sudu", tag.getSudu());
      query.setParameter("pinglv", tag.getPinglv());
      query.setParameter("version", tag.getVersion());
      int executeUpdate = query.executeUpdate();
      return executeUpdate;
   }
   @Transactional
   public void labelManagement_modify(tb_tag tag) {
@@ -207,7 +338,7 @@
      }
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_tag SET state=:state,gaodu=:gaodu,sudu=:sudu,pinglv=:pinglv WHERE tag_id=:tag_id";
      sql = "UPDATE tb_tag SET state=:state,gaodu=:gaodu,sudu=:sudu,pinglv=:pinglv,type=:type WHERE tag_id=:tag_id";
      cs.tb_caozuo("tb_tag", 3);
      query = this.em.createNativeQuery(sql);
      query.setParameter("tag_id", tag.getTag_id());
@@ -215,6 +346,7 @@
      query.setParameter("gaodu", tag.getGaodu());
      query.setParameter("sudu", tag.getSudu());
      query.setParameter("pinglv", tag.getPinglv());
      query.setParameter("type", tag.getType());
      query.executeUpdate();
   }
   
@@ -272,7 +404,7 @@
      }
      String sql = null;
      Query query = null;
      sql = "UPDATE tb_tag SET state=:state,gaodu=:gaodu,sudu=:sudu,pinglv=:pinglv WHERE tag_id=:tag_id";
      sql = "UPDATE tb_tag SET state=:state,gaodu=:gaodu,sudu=:sudu,pinglv=:pinglv,type=:type WHERE tag_id=:tag_id";
      cs.tb_caozuo("tb_tag", 3);
      query = this.em.createNativeQuery(sql);
      query.setParameter("tag_id", tag.getTag_id());
@@ -280,6 +412,7 @@
      query.setParameter("gaodu", tag.getGaodu());
      query.setParameter("sudu", tag.getSudu());
      query.setParameter("pinglv", tag.getPinglv());
      query.setParameter("type", tag.getType());
      int aaa = query.executeUpdate();
      return aaa;
   }
@@ -521,7 +654,7 @@
      sql = "SELECT * FROM (SELECT * FROM tb_tagpower ORDER BY time DESC) tp 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")));
      query.setParameter("end", 50);
      List resultList = query.getResultList();
      List<tb_tagpower> tagpowerList = new ArrayList<tb_tagpower>();
      if (resultList.size() > 0) {
@@ -550,7 +683,7 @@
   public List<vo_tp_t_p> searchRealTimePower(String input) {
      String sql = null;
      Query query = null;
      sql = "SELECT tp.id,tp.tagid,t.power,tp.time,t.pinglv,p.p_name FROM tb_tagpower tp,tb_tag t,tb_person p WHERE tp.tagid = t.tag_id AND tp.tagid = p.p_tagid AND tp.tagid = :tag_id";
      sql = "SELECT tp.id,tp.tagid,tp.power,tp.time,tp.hz,p.p_name FROM tb_tagpower tp,tb_tag t,tb_person p WHERE tp.tagid = t.tag_id AND tp.tagid = p.p_tagid AND tp.tagid = :tag_id OR tp.`name` = t.state AND tp.`name` = p.p_name AND tp.`name` = :tag_id";
      query = this.em.createNativeQuery(sql);
      query.setParameter("tag_id", input);
      List resultList = query.getResultList();
@@ -597,7 +730,7 @@
      sql = "SELECT id,tagid,power,time FROM (SELECT * FROM tb_history_power ORDER BY time DESC) thp 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")));
      query.setParameter("end", 50);
      List resultList = query.getResultList();
      List<tb_history_power> tb_history_powerList = new ArrayList<tb_history_power>();
      if (resultList.size() > 0) {
@@ -625,7 +758,7 @@
   public List<tb_history_power> searchHistoricalPower(String input) {
      String sql = null;
      Query query = null;
      sql = "SELECT id,tagid,power,time FROM tb_history_power WHERE tagid = :tag_id";
      sql = "SELECT h.id,h.tagid,h.power,h.time FROM tb_history_power h,tb_person p WHERE h.tagid = p.p_tagid AND h.tagid = :tag_id OR h.tagid = p.p_tagid AND p.p_name = :tag_id";
      query = this.em.createNativeQuery(sql);
      query.setParameter("tag_id", input);
      List resultList = query.getResultList();
@@ -765,5 +898,134 @@
      }
      return tb_tagList;
   }
   public String findpname(String tagid){
      String sql = null;
      Query query = null;
      sql = "select p_name from tb_person where p_tagid = :tagid";
      query = this.em.createNativeQuery(sql);
      query.setParameter("tagid", tagid);
      List resultList = query.getResultList();
      return resultList.get(0).toString();
   }
   public String findptagid(String name){
      String sql = null;
      Query query = null;
      sql = "select p_tagid from tb_person where p_name = :name";
      query = this.em.createNativeQuery(sql);
      query.setParameter("name", name);
      List resultList = query.getResultList();
      return resultList.get(0).toString();
   }
   public List<String> findleixing(){
      String sql = null;
      Query query = null;
      sql = "select type from tb_tag where type is not null group by type";
      query = this.em.createNativeQuery(sql);
      List resultlist = query.getResultList();
      List<String> strs = new ArrayList<>();
      for (int i=0; i<resultlist.size(); i++) {
//       Object[] obj = (Object[])resultlist.get(i);
         strs.add(resultlist.get(i).toString());
      }
      return strs;
   }
   public List<tb_tag> shailabel1(String leixing,String bumen) {
      String sql = null;
      Query query = null;
      sql = "SELECT t.id,t.tag_id,t.state,t.power,t.status,t.gaodu,t.sudu,t.pinglv,t.sleep_satus,t.sleep_time,t.gongfang,t.dong_status,t.version,t.addtime,t.imu,t.type FROM tb_tag t,tb_person p WHERE p.p_tagid = t.tag_id and p.p_department = :bumen and t.type = :leixing";
      query = this.em.createNativeQuery(sql);
      query.setParameter("leixing", leixing);
      query.setParameter("bumen", bumen);
      List resultList = query.getResultList();
      List<tb_tag> tb_tagList = new ArrayList<tb_tag>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            Object[] obj = (Object[]) resultList.get(i);
            tb_tag tag = new tb_tag();
            tag.setId((int) obj[0]);
            tag.setStatus(obj[4] == null ? "" : obj[4].toString());
            tag.setTag_id(obj[1] == null ? "" : obj[1].toString());
            tag.setState(obj[2] == null ? "" : obj[2].toString());
            tag.setPower(obj[3] == null ? "" : obj[3].toString());
            tag.setGaodu(obj[5] == null ? "" : obj[5].toString());
            tag.setSudu(obj[6] == null ? "" : obj[6].toString());
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
      return tb_tagList;
   }
   public List<tb_tag> shailabel2(String bumen) {
      String sql = null;
      Query query = null;
      sql = "SELECT t.id,t.tag_id,t.state,t.power,t.status,t.gaodu,t.sudu,t.pinglv,t.sleep_satus,t.sleep_time,t.gongfang,t.dong_status,t.version,t.addtime,t.imu,t.type FROM tb_tag t,tb_person p WHERE p.p_tagid = t.tag_id and p.p_department = :bumen";
      query = this.em.createNativeQuery(sql);
      query.setParameter("bumen", bumen);
      List resultList = query.getResultList();
      List<tb_tag> tb_tagList = new ArrayList<tb_tag>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            Object[] obj = (Object[]) resultList.get(i);
            tb_tag tag = new tb_tag();
            tag.setId((int) obj[0]);
            tag.setStatus(obj[4] == null ? "" : obj[4].toString());
            tag.setTag_id(obj[1] == null ? "" : obj[1].toString());
            tag.setState(obj[2] == null ? "" : obj[2].toString());
            tag.setPower(obj[3] == null ? "" : obj[3].toString());
            tag.setGaodu(obj[5] == null ? "" : obj[5].toString());
            tag.setSudu(obj[6] == null ? "" : obj[6].toString());
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
      return tb_tagList;
   }
   public List<tb_tag> shailabel3(String leixing) {
      String sql = null;
      Query query = null;
      sql = "SELECT id,tag_id,state,power,'status',gaodu,sudu,pinglv,sleep_satus,sleep_time,gongfang,dong_status,version,addtime,imu,type FROM tb_tag WHERE type = :leixing";
      query = this.em.createNativeQuery(sql);
      query.setParameter("leixing", leixing);
      List resultList = query.getResultList();
      List<tb_tag> tb_tagList = new ArrayList<tb_tag>();
      if (resultList.size() > 0) {
         for (int i = 0; i < resultList.size(); i++) {
            Object[] obj = (Object[]) resultList.get(i);
            tb_tag tag = new tb_tag();
            tag.setId((int) obj[0]);
            tag.setStatus(obj[4] == null ? "" : obj[4].toString());
            tag.setTag_id(obj[1] == null ? "" : obj[1].toString());
            tag.setState(obj[2] == null ? "" : obj[2].toString());
            tag.setPower(obj[3] == null ? "" : obj[3].toString());
            tag.setGaodu(obj[5] == null ? "" : obj[5].toString());
            tag.setSudu(obj[6] == null ? "" : obj[6].toString());
            tag.setPinglv(obj[7] == null ? "" : obj[7].toString());
            tag.setVersion(obj[12] == null ? "" : obj[12].toString());
            tag.setAddtime(obj[13] == null ? "" : obj[13].toString());
            tag.setType(obj[15] == null ? "" : obj[15].toString());
            tb_tagList.add(tag);
         }
      }
      return tb_tagList;
   }
   public int getweibangding() {
      String sql = null;
      Query query = null;
      sql = "SELECT count(1) FROM tb_person where p_name = '未绑定'";
      query = this.em.createNativeQuery(sql);
      return Integer.parseInt(query.getSingleResult().toString());
   }
}