package com.hxzkoa.services;
|
|
import java.io.BufferedReader;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
import java.io.FileReader;
|
import java.io.IOException;
|
import java.io.InputStreamReader;
|
import java.io.Reader;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.LinkedList;
|
import java.util.List;
|
|
import javax.persistence.EntityManager;
|
import javax.persistence.PersistenceContext;
|
import javax.persistence.Query;
|
|
import org.apache.commons.io.FileUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.hxzkoa.json.tb_fence;
|
import com.hxzkoa.json.tb_gas;
|
import com.hxzkoa.json.tb_gps;
|
import com.hxzkoa.json.tb_person;
|
import com.hxzkoa.json.tb_realocation;
|
import com.hxzkoa.json.tb_system;
|
import com.hxzkoa.json.tb_track;
|
import com.hxzkoa.util.Config;
|
import com.hxzkoa.util.ModifyConfig;
|
|
@Service
|
public class GpsService {
|
@PersistenceContext
|
private EntityManager em;
|
@Autowired
|
private CaozuoService cs;
|
|
|
public List<String> txt() {
|
List<String> list = new LinkedList<>();
|
|
String filePath="D:\\baowen.txt";
|
|
File file=new File(filePath);
|
|
BufferedReader reader = null;//字符输入流进行读取操作读取
|
|
String tempString = null;//每一行的内容
|
|
int line =1;//行号
|
|
try {
|
//输入字节流,FileInputStream主要用来操作文件输入流
|
FileInputStream intput = new FileInputStream(file);
|
|
// System.out.println("以行为单位读取文件内容,一次读一整行:")
|
//InputStreamReader是转换流,将字节流转成字符流
|
reader = new BufferedReader(new InputStreamReader(intput));
|
|
while ((tempString = reader.readLine()) != null) {
|
list.add(tempString);
|
}
|
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}finally{
|
if(reader != null){
|
try {
|
reader.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
return list;
|
}
|
|
public List<tb_gps> getGpsManagement() {
|
String sql = null;
|
Query query = null;
|
sql = "SELECT id,gps_utc_time,gps_weidu,gps_NS,gsp_jingdu,gps_EW,gps_state,gps_num,gps_hdop,gps_haiba_gao,gps_tuoqiu,gps_chafen_time,gps_chafen_id,gps_jiaoyan,tagid,gps_kahao,gps_power,gps_sos,addtime FROM tb_gps";
|
query = this.em.createNativeQuery(sql);
|
List resultList = query.getResultList();
|
List<tb_gps> tb_gpsList = new ArrayList<tb_gps>();
|
if (resultList.size() > 0) {
|
for (int i = 0; i < resultList.size(); i++) {
|
tb_gps gps = new tb_gps();
|
Object[] obj = (Object[]) resultList.get(i);
|
gps.setId((int) obj[0]);
|
gps.setGps_utc_time(obj[1] == null ? "" : obj[1].toString());
|
gps.setGps_weidu(obj[2] == null ? "" : obj[2].toString());
|
gps.setGps_NS(obj[3] == null ? "" : obj[3].toString());
|
gps.setGsp_jingdu(obj[4] == null ? "" : obj[4].toString());
|
gps.setGps_EW(obj[5] == null ? "" : obj[5].toString());
|
gps.setGps_state(obj[6] == null ? "" : obj[6].toString());
|
gps.setGps_num(obj[7] == null ? "" : obj[7].toString());
|
gps.setGps_hdop(obj[8] == null ? "" : obj[8].toString());
|
gps.setGps_haiba_gao(obj[9] == null ? "" : obj[9].toString());
|
gps.setGps_tuoqiu(obj[10] == null ? "" : obj[10].toString());
|
gps.setGps_chafen_time(obj[11] == null ? "" : obj[11].toString());
|
gps.setGps_chafen_id(obj[12] == null ? "" : obj[12].toString());
|
gps.setTagid(obj[13] == null ? "" : obj[13].toString());
|
gps.setGps_kahao(obj[14] == null ? "" : obj[14].toString());
|
gps.setGps_power(obj[15] == null ? "" : obj[15].toString());
|
gps.setGps_sos(obj[16] == null ? "" : obj[16].toString());
|
gps.setAddtime(obj[17] == null ? "" : obj[17].toString());
|
tb_gpsList.add(gps);
|
}
|
}
|
return tb_gpsList;
|
}
|
|
public List<tb_gps> getGpsManagement(int page) {
|
int perPage = Integer.parseInt(ModifyConfig.readData(Config.getPageConfig(), "perPage"));
|
int start = (page - 1) * perPage;
|
int end = perPage;
|
String sql = null;
|
Query query = null;
|
sql = "SELECT id,gps_utc_time,gps_weidu,gps_NS,gsp_jingdu,gps_EW,gps_state,gps_num,gps_hdop,gps_haiba_gao,gps_tuoqiu,gps_chafen_time,gps_chafen_id,gps_jiaoyan,tagid,gps_kahao,gps_power,gps_sos,addtime FROM tb_gps order by addtime desc LIMIT :start,:end";
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("start", start);
|
query.setParameter("end", end);
|
List resultList = query.getResultList();
|
List<tb_gps> tb_gpsList = new ArrayList<tb_gps>();
|
if (resultList.size() > 0) {
|
for (int i = 0; i < resultList.size(); i++) {
|
tb_gps gps = new tb_gps();
|
Object[] obj = (Object[]) resultList.get(i);
|
gps.setId((int) obj[0]);
|
gps.setGps_utc_time(obj[1] == null ? "" : obj[1].toString());
|
gps.setGps_weidu(obj[2] == null ? "" : obj[2].toString());
|
gps.setGps_NS(obj[3] == null ? "" : obj[3].toString());
|
gps.setGsp_jingdu(obj[4] == null ? "" : obj[4].toString());
|
gps.setGps_EW(obj[5] == null ? "" : obj[5].toString());
|
gps.setGps_state(obj[6] == null ? "" : obj[6].toString());
|
gps.setGps_num(obj[7] == null ? "" : obj[7].toString());
|
gps.setGps_hdop(obj[8] == null ? "" : obj[8].toString());
|
gps.setGps_haiba_gao(obj[9] == null ? "" : obj[9].toString());
|
gps.setGps_tuoqiu(obj[10] == null ? "" : obj[10].toString());
|
gps.setGps_chafen_time(obj[11] == null ? "" : obj[11].toString());
|
gps.setGps_chafen_id(obj[12] == null ? "" : obj[12].toString());
|
gps.setGps_jiaoyan(obj[13] == null ? "" : obj[13].toString());
|
gps.setTagid(obj[14] == null ? "" : obj[14].toString());
|
gps.setGps_kahao(obj[15] == null ? "" : obj[15].toString());
|
gps.setGps_power(obj[16] == null ? "" : obj[16].toString());
|
gps.setGps_sos(obj[17] == null ? "" : obj[17].toString());
|
gps.setAddtime(obj[18] == null ? "" : obj[18].toString());
|
tb_gpsList.add(gps);
|
}
|
}
|
return tb_gpsList;
|
}
|
|
public int getGpsManagementCount() {
|
String sql = null;
|
Query query = null;
|
sql = "SELECT count(1) FROM tb_gps";
|
query = this.em.createNativeQuery(sql);
|
return Integer.parseInt(query.getSingleResult().toString());
|
}
|
|
public List<tb_gps> searchGpsManagement(String input) {
|
String tagid = input;
|
String sql = null;
|
Query query = null;
|
sql = "SELECT id,gps_utc_time,gps_weidu,gps_NS,gsp_jingdu,gps_EW,gps_state,gps_num,gps_hdop,gps_haiba_gao,gps_tuoqiu,gps_chafen_time,gps_chafen_id,gps_jiaoyan,tagid,gps_kahao,gps_power,gps_sos,addtime FROM tb_gps WHERE tagid = :tagid";
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("tagid", tagid);
|
List resultList = query.getResultList();
|
List<tb_gps> tb_gpsList = new ArrayList<tb_gps>();
|
if (resultList.size() > 0) {
|
for (int i = 0; i < resultList.size(); i++) {
|
tb_gps gps = new tb_gps();
|
Object[] obj = (Object[]) resultList.get(i);
|
gps.setId((int) obj[0]);
|
gps.setGps_utc_time(obj[1] == null ? "" : obj[1].toString());
|
gps.setGps_weidu(obj[2] == null ? "" : obj[2].toString());
|
gps.setGps_NS(obj[3] == null ? "" : obj[3].toString());
|
gps.setGsp_jingdu(obj[4] == null ? "" : obj[4].toString());
|
gps.setGps_EW(obj[5] == null ? "" : obj[5].toString());
|
gps.setGps_state(obj[6] == null ? "" : obj[6].toString());
|
gps.setGps_num(obj[7] == null ? "" : obj[7].toString());
|
gps.setGps_hdop(obj[8] == null ? "" : obj[8].toString());
|
gps.setGps_haiba_gao(obj[9] == null ? "" : obj[9].toString());
|
gps.setGps_tuoqiu(obj[10] == null ? "" : obj[10].toString());
|
gps.setGps_chafen_time(obj[11] == null ? "" : obj[11].toString());
|
gps.setGps_chafen_id(obj[12] == null ? "" : obj[12].toString());
|
gps.setGps_jiaoyan(obj[13] == null ? "" : obj[13].toString());
|
gps.setTagid(obj[14] == null ? "" : obj[14].toString());
|
gps.setGps_kahao(obj[15] == null ? "" : obj[15].toString());
|
gps.setGps_power(obj[16] == null ? "" : obj[16].toString());
|
gps.setGps_sos(obj[17] == null ? "" : obj[17].toString());
|
gps.setAddtime(obj[18] == null ? "" : obj[18].toString());
|
tb_gpsList.add(gps);
|
}
|
}
|
return tb_gpsList;
|
}
|
|
@Transactional
|
public void gpszeng(tb_system system) {
|
String sql = null;
|
Query query = null;
|
sql = "UPDATE tb_system SET origin_jingdu=:origin_jingdu,origin_weidu=:origin_weidu,origin_jiaodu=:origin_jiaodu WHERE id=1";
|
cs.tb_caozuo("tb_system", 3);
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("origin_jingdu",system.getOrigin_jingdu());
|
query.setParameter("origin_weidu",system.getOrigin_weidu());
|
query.setParameter("origin_jiaodu",system.getOrigin_jiaodu());
|
query.executeUpdate();
|
}
|
|
@Transactional
|
public void gpsManagement_delete(String[] checkVal) {
|
String sql = null;
|
Query query = null;
|
for (int i = 0; i < checkVal.length; i++) {
|
int tagid = Integer.parseInt(checkVal[i]);
|
sql = "DELETE FROM tb_gps WHERE tagid = :tagid";
|
cs.tb_caozuo("tb_gps", 2);
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("tagid", tagid);
|
query.executeUpdate();
|
}
|
}
|
|
public List<tb_gps> getTrack(String date,int page,int perPage) {
|
// 日期格式 例20210101
|
String sql = null;
|
Query query = null;
|
sql = "SELECT * FROM tb_gps_track_"+ date +" LIMIT :start,:end";
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("start", (page - 1) * perPage);
|
query.setParameter("end", perPage);
|
List resultList = query.getResultList();
|
List<tb_gps> tb_trackList = new ArrayList<tb_gps>();
|
if (resultList.size() > 0) {
|
for (int i = 0; i < resultList.size(); i++) {
|
tb_gps gps = new tb_gps();
|
Object[] obj = (Object[]) resultList.get(i);
|
gps.setId((int) obj[0]);
|
gps.setGps_utc_time(obj[1] == null ? "" : obj[1].toString());
|
gps.setGps_weidu(obj[2] == null ? "" : obj[2].toString());
|
gps.setGps_NS(obj[3] == null ? "" : obj[3].toString());
|
gps.setGsp_jingdu(obj[4] == null ? "" : obj[4].toString());
|
gps.setGps_EW(obj[5] == null ? "" : obj[5].toString());
|
gps.setGps_state(obj[6] == null ? "" : obj[6].toString());
|
gps.setGps_num(obj[7] == null ? "" : obj[7].toString());
|
gps.setGps_hdop(obj[8] == null ? "" : obj[8].toString());
|
gps.setGps_haiba_gao(obj[9] == null ? "" : obj[9].toString());
|
gps.setGps_tuoqiu(obj[10] == null ? "" : obj[10].toString());
|
gps.setGps_chafen_time(obj[11] == null ? "" : obj[11].toString());
|
gps.setGps_chafen_id(obj[12] == null ? "" : obj[12].toString());
|
gps.setGps_jiaoyan(obj[13] == null ? "" : obj[13].toString());
|
gps.setTagid(obj[14] == null ? "" : obj[14].toString());
|
gps.setGps_kahao(obj[15] == null ? "" : obj[15].toString());
|
gps.setGps_power(obj[16] == null ? "" : obj[16].toString());
|
gps.setGps_sos(obj[17] == null ? "" : obj[17].toString());
|
gps.setAddtime(obj[18] == null ? "" : obj[18].toString());
|
tb_trackList.add(gps);
|
}
|
}
|
return tb_trackList;
|
}
|
|
public int getgpsRealTimeLocationCount(String date) {
|
String sql = null;
|
Query query = null;
|
sql = "SELECT count(1) FROM tb_gps_track_" +date+ "";
|
query = this.em.createNativeQuery(sql);
|
return Integer.parseInt(query.getSingleResult().toString());
|
}
|
|
public List<String> getgpsTrackDateList() {
|
String sql = null;
|
Query query = null;
|
sql = "select right(table_name,8) from information_schema.tables where table_schema='hxzkuwb' and table_name like 'tb_gps_track_%'";
|
query = this.em.createNativeQuery(sql);
|
List<String> resultList = query.getResultList();
|
return resultList;
|
}
|
|
@Transactional
|
public void realTimegpsLocation_delete(String[] checkVal,String date) {
|
String sql = null;
|
Query query = null;
|
for (int i = 0; i < checkVal.length; i++) {
|
int id = Integer.parseInt(checkVal[i]);
|
sql = "DELETE FROM tb_gps_track_" +date+ " WHERE id = :id";
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("id", id);
|
query.executeUpdate();
|
}
|
}
|
|
@Transactional
|
public void realTimegpsLocation_deleteAll(String date) {
|
String sql = null;
|
Query query = null;
|
sql = "DELETE FROM tb_gps_track_" +date+ "";
|
query = this.em.createNativeQuery(sql);
|
query.executeUpdate();
|
}
|
|
public List<tb_gps> searchRealTimegpsLocation(String input,String date) {
|
String sql = null;
|
Query query = null;
|
sql = "SELECT * FROM tb_gps_track_" + date + " WHERE tagid = :p_tagid";
|
query = this.em.createNativeQuery(sql);
|
query.setParameter("p_tagid", input);
|
List resultList = query.getResultList();
|
List<tb_gps> tb_trackList = new ArrayList<tb_gps>();
|
if (resultList.size() > 0) {
|
for (int i = 0; i < resultList.size(); i++) {
|
tb_gps gps = new tb_gps();
|
Object[] obj = (Object[]) resultList.get(i);
|
gps.setId((int) obj[0]);
|
gps.setGps_utc_time(obj[1] == null ? "" : obj[1].toString());
|
gps.setGps_weidu(obj[2] == null ? "" : obj[2].toString());
|
gps.setGps_NS(obj[3] == null ? "" : obj[3].toString());
|
gps.setGsp_jingdu(obj[4] == null ? "" : obj[4].toString());
|
gps.setGps_EW(obj[5] == null ? "" : obj[5].toString());
|
gps.setGps_state(obj[6] == null ? "" : obj[6].toString());
|
gps.setGps_num(obj[7] == null ? "" : obj[7].toString());
|
gps.setGps_hdop(obj[8] == null ? "" : obj[8].toString());
|
gps.setGps_haiba_gao(obj[9] == null ? "" : obj[9].toString());
|
gps.setGps_tuoqiu(obj[10] == null ? "" : obj[10].toString());
|
gps.setGps_chafen_time(obj[11] == null ? "" : obj[11].toString());
|
gps.setGps_chafen_id(obj[12] == null ? "" : obj[12].toString());
|
gps.setGps_jiaoyan(obj[13] == null ? "" : obj[13].toString());
|
gps.setTagid(obj[14] == null ? "" : obj[14].toString());
|
gps.setGps_kahao(obj[15] == null ? "" : obj[15].toString());
|
gps.setGps_power(obj[16] == null ? "" : obj[16].toString());
|
gps.setGps_sos(obj[17] == null ? "" : obj[17].toString());
|
gps.setAddtime(obj[18] == null ? "" : obj[18].toString());
|
tb_trackList.add(gps);
|
}
|
}
|
return tb_trackList;
|
}
|
|
public List<tb_gps> getRealTimegpsLocation(String tagid,String begin,String end,String date) {
|
String sql = null;
|
Query query = null;
|
sql = "SELECT id,gps_weidu,gsp_jingdu,gps_state,gps_num,gps_haiba_gao,gps_chafen_id,tagid,gps_power,addtime FROM tb_gps_track_"+date+" WHERE tagid = '"+tagid+"' AND addtime>= '"+begin+"' AND addtime<= '"+end+"' ORDER BY addtime";
|
System.out.print(sql);
|
query = this.em.createNativeQuery(sql);
|
List resultList = query.getResultList();
|
List<tb_gps> tb_realocationList = new ArrayList<tb_gps>();
|
if (resultList.size() > 0) {
|
for (int i = 0; i < resultList.size(); i++) {
|
tb_gps realocation = new tb_gps();
|
Object[] obj = (Object[]) resultList.get(i);
|
realocation.setId((int) obj[0]);
|
realocation.setGps_weidu(obj[1] == null ? "" : obj[1].toString());
|
realocation.setGsp_jingdu(obj[2] == null ? "" : obj[2].toString());
|
realocation.setGps_state(obj[3] == null ? "" : obj[3].toString());
|
realocation.setGps_num(obj[4] == null ? "" : obj[4].toString());
|
realocation.setGps_haiba_gao(obj[5] == null ? "" : obj[5].toString());
|
realocation.setGps_chafen_id(obj[6] == null ? "" : obj[6].toString());
|
realocation.setTagid(obj[7] == null ? "" : obj[7].toString());
|
realocation.setGps_power(obj[8] == null ? "" : obj[8].toString());
|
realocation.setAddtime(obj[9] == null ? "" : obj[9].toString());
|
tb_realocationList.add(realocation);
|
}
|
}
|
return tb_realocationList;
|
}
|
|
public String getpersontagid(String tagid) {
|
String sql = null;
|
Query query = null;
|
sql = "SELECT p_online FROM tb_person WHERE p_tagid ='" +tagid+ "'";
|
query = this.em.createNativeQuery(sql);
|
//query.setParameter("tagid", tagid);
|
List resultList = query.getResultList();
|
String zhuantai = resultList.get(0).toString();
|
return zhuantai;
|
}
|
}
|