智慧保安后台管理-外网项目备份
tangzy
2021-11-30 bb72c40ff327fc6a7a1b3a96e0589507711f0cdf
1.押运
10 files modified
5 files added
1038 ■■■■■ changed files
src/main/java/org/springblade/common/utils/DowloadZipUtil.java 66 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/utils/FileZip.java 100 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/utils/HttpReqUtil.java 235 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/utils/Md5SignUtil.java 54 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/equipage/controller/fixed.java 330 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/equipage/entity/Car.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/equipage/mapper/CarMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/equipage/mapper/CarMapper.xml 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/equipage/service/CarService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/equipage/service/impl/CarServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/location/controller/LiveLocationController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/location/controller/LocusController.java 210 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/location/entity/LiveLocation.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/location/entity/Locus.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/record/mapper/RecordMapper.xml 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/utils/DowloadZipUtil.java
New file
@@ -0,0 +1,66 @@
package org.springblade.common.utils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class DowloadZipUtil {
    //urlPath:目标文件路径, downloadDir:下载后要放的文件路径
    public static File downloadFile(String urlPath, String downloadDir) {
        File file = null;
        try {
            // 统一资源
            URL url = new URL(urlPath);
            // 连接类的父类,抽象类
            URLConnection urlConnection = url.openConnection();
            // http的连接类
            HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
            // 设定请求的方法,默认是GET
            httpURLConnection.setRequestMethod("GET");
            // 设置字符编码
            httpURLConnection.setRequestProperty("Charset", "UTF-8");
            // 打开到此 URL 引用的资源的通信链接(如果尚未建立这样的连接)。
            httpURLConnection.connect();
            // 文件大小
            int fileLength = httpURLConnection.getContentLength();
            // 文件名
            String filePathUrl = httpURLConnection.getURL().getFile();
            String[]  strs=filePathUrl.split("/");
            String s = strs[4].toString();
            System.out.println(s);
            //File.separatorChar代表的是分隔符“/”或者“\”,若详知 自行百度
            String fileFullName = filePathUrl.substring(filePathUrl.lastIndexOf(File.separatorChar) + 1);
            System.out.println("file length---->" + fileLength);
            URLConnection con = url.openConnection();
            BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
            String path = downloadDir + "/"+strs[4].toString();
            file = new File(path);
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            OutputStream out = new FileOutputStream(file);
            int size = 0;
            int len = 0;
            byte[] buf = new byte[1024];
            while ((size = bin.read(buf)) != -1) {
                len += size;
                out.write(buf, 0, size);
                // 打印下载百分比
                // System.out.println("下载了-------> " + len * 100 / fileLength +
                // "%\n");
            }
            bin.close();
            out.close();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            return file;
        }
    }
}
src/main/java/org/springblade/common/utils/FileZip.java
New file
@@ -0,0 +1,100 @@
package org.springblade.common.utils;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class FileZip {
    /**
     * zip文件压缩
     * @param inputFile 待压缩文件夹/文件名
     * @param outputFile 生成的压缩包名字
     */
    public static void ZipCompress(String inputFile, String outputFile) throws Exception {
        //创建zip输出流
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
        //创建缓冲输出流
        BufferedOutputStream bos = new BufferedOutputStream(out);
        File input = new File(inputFile);
        compress(out, bos, input,null);
        bos.close();
        out.close();
    }
    /**
     * @param name 压缩文件名,可以写为null保持默认
     */
    //递归压缩
    public static void compress(ZipOutputStream out, BufferedOutputStream bos, File input, String name) throws IOException {
        if (name == null) {
            name = input.getName();
        }
        //如果路径为目录(文件夹)
        if (input.isDirectory()) {
            //取出文件夹中的文件(或子文件夹)
            File[] flist = input.listFiles();
            if (flist.length == 0)//如果文件夹为空,则只需在目的地zip文件中写入一个目录进入
            {
                out.putNextEntry(new ZipEntry(name + "/"));
            } else//如果文件夹不为空,则递归调用compress,文件夹中的每一个文件(或文件夹)进行压缩
            {
                for (int i = 0; i < flist.length; i++) {
                    compress(out, bos, flist[i], name + "/" + flist[i].getName());
                }
            }
        } else//如果不是目录(文件夹),即为文件,则先写入目录进入点,之后将文件写入zip文件中
        {
            out.putNextEntry(new ZipEntry(name));
            FileInputStream fos = new FileInputStream(input);
            BufferedInputStream bis = new BufferedInputStream(fos);
            int len=-1;
            //将源文件写入到zip文件中
            byte[] buf = new byte[1024];
            while ((len = bis.read(buf)) != -1) {
                bos.write(buf,0,len);
            }
            bis.close();
            fos.close();
        }
    }
    /**
     * zip解压
     * @param inputFile 待解压文件名
     * @param destDirPath  解压路径
     */
    public static void ZipUncompress(String inputFile,String destDirPath) throws Exception {
        File srcFile = new File(inputFile);//获取当前压缩文件
        // 判断源文件是否存在
        if (!srcFile.exists()) {
            throw new Exception(srcFile.getPath() + "所指文件不存在");
        }
        //开始解压
        //构建解压输入流
        ZipInputStream zIn = new ZipInputStream(new FileInputStream(srcFile));
        ZipEntry entry = null;
        File file = null;
        while ((entry = zIn.getNextEntry()) != null) {
            if (!entry.isDirectory()) {
                file = new File(destDirPath, entry.getName());
                if (!file.exists()) {
                    new File(file.getParent()).mkdirs();//创建此文件的上级目录
                }
                OutputStream out = new FileOutputStream(file);
                BufferedOutputStream bos = new BufferedOutputStream(out);
                int len = -1;
                byte[] buf = new byte[1024];
                while ((len = zIn.read(buf)) != -1) {
                    bos.write(buf, 0, len);
                }
                // 关流顺序,先打开的后关闭
                bos.close();
                out.close();
            }
        }
    }
}
src/main/java/org/springblade/common/utils/HttpReqUtil.java
New file
@@ -0,0 +1,235 @@
package org.springblade.common.utils;
import com.alibaba.fastjson.JSON;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.*;
import java.util.Map.Entry;
public class HttpReqUtil {
    protected final static Log LOG = LogFactory.getLog(HttpReqUtil.class);
    private static HttpReqUtil instance;
    protected Charset charset;
    private HttpReqUtil(){}
    public static HttpReqUtil getInstance() {
        return getInstance(Charset.defaultCharset());
    }
    public static HttpReqUtil getInstance(Charset charset){
        if(instance == null){
            instance = new HttpReqUtil();
        }
        instance.setCharset(charset);
        return instance;
    }
    public void setCharset(Charset charset) {
        this.charset = charset;
    }
    /**
     * post请求
     */
    public String doPost(String url) throws Exception {
        return doPost(url, null, null);
    }
    public String doPost(String url, Map<String, Object> params) throws Exception {
        return doPost(url, params, null);
    }
    public String doPost(String url, Map<String, Object> params, Map<String, String> header) throws Exception {
        String body = null;
        try {
            // Post请求
            LOG.debug(" protocol: POST");
            LOG.debug("      url: " + url);
            HttpPost httpPost = new HttpPost(url.trim());
            // 设置参数
            LOG.debug("   params: " + JSON.toJSONString(params));
            httpPost.setEntity(new UrlEncodedFormEntity(map2NameValuePairList(params), charset));
            // 设置Header
            if (header != null && !header.isEmpty()) {
                LOG.debug("   header: " + JSON.toJSONString(header));
                for (Iterator<Entry<String, String>> it = header.entrySet().iterator(); it.hasNext();) {
                    Entry<String, String> entry = (Entry<String, String>) it.next();
                    httpPost.setHeader(new BasicHeader(entry.getKey(), entry.getValue()));
                }
            }
            // 发送请求,获取返回数据
            body = execute(httpPost);
        } catch (Exception e) {
            throw e;
        }
        LOG.debug("   result: " + body);
        return body;
    }
    /**
     * postJson请求
     */
    public String doPostJson(String url, Map<String, Object> params) throws Exception {
        return doPostJson(url, params, null);
    }
    public String doPostJson(String url, Map<String, Object> params, Map<String, String> header) throws Exception {
        String json = null;
        if (params != null && !params.isEmpty()) {
            for (Iterator<Entry<String, Object>> it = params.entrySet().iterator(); it.hasNext();) {
                Entry<String, Object> entry = (Entry<String, Object>) it.next();
                Object object = entry.getValue();
                if (object == null) {
                    it.remove();
                }
            }
            json = JSON.toJSONString(params);
        }
        return postJson(url, json, header);
    }
    public String doPostJson(String url, String json) throws Exception {
        return doPostJson(url, json, null);
    }
    public String doPostJson(String url, String json, Map<String, String> header) throws Exception {
        return postJson(url, json, header);
    }
    private String postJson(String url, String json, Map<String, String> header) throws Exception {
        String body = null;
        try {
            // Post请求
            LOG.debug(" protocol: POST");
            LOG.debug("      url: " + url);
            HttpPost httpPost = new HttpPost(url.trim());
            // 设置参数
            LOG.debug("   params: " + json);
            httpPost.setEntity(new StringEntity(json, ContentType.DEFAULT_TEXT.withCharset(charset)));
            httpPost.setHeader(new BasicHeader("Content-Type", "application/json"));
            LOG.debug("     type: JSON");
            // 设置Header
            if (header != null && !header.isEmpty()) {
                LOG.debug("   header: " + JSON.toJSONString(header));
                for (Iterator<Entry<String, String>> it = header.entrySet().iterator(); it.hasNext();) {
                    Entry<String, String> entry = (Entry<String, String>) it.next();
                    httpPost.setHeader(new BasicHeader(entry.getKey(), entry.getValue()));
                }
            }
            // 发送请求,获取返回数据
            body = execute(httpPost);
        } catch (Exception e) {
            throw e;
        }
        LOG.debug("  result: " + body);
        return body;
    }
    /**
     * get请求
     */
    public String doGet(String url) throws Exception {
        return doGet(url, null, null);
    }
    public String doGet(String url, Map<String, String> header) throws Exception {
        return doGet(url, null, header);
    }
    public String doGet(String url, Map<String, Object> params, Map<String, String> header) throws Exception {
        String body = null;
        try {
            // Get请求
            LOG.debug("protocol: GET");
            HttpGet httpGet = new HttpGet(url.trim());
            // 设置参数
            if (params != null && !params.isEmpty()) {
                String str = EntityUtils.toString(new UrlEncodedFormEntity(map2NameValuePairList(params), charset));
                String uri = httpGet.getURI().toString();
                if(uri.indexOf("?") >= 0){
                    httpGet.setURI(new URI(httpGet.getURI().toString() + "&" + str));
                }else {
                    httpGet.setURI(new URI(httpGet.getURI().toString() + "?" + str));
                }
            }
            LOG.debug("     url: " + httpGet.getURI());
            // 设置Header
            if (header != null && !header.isEmpty()) {
                LOG.debug("   header: " + header);
                for (Iterator<Entry<String, String>> it = header.entrySet().iterator(); it.hasNext();) {
                    Entry<String, String> entry = (Entry<String, String>) it.next();
                    httpGet.setHeader(new BasicHeader(entry.getKey(), entry.getValue()));
                }
            }
            // 发送请求,获取返回数据
            body =  execute(httpGet);
        } catch (Exception e) {
            throw e;
        }
        LOG.debug("  result: " + body);
        return body;
    }
    private String execute(HttpRequestBase requestBase) throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        String body = null;
        try {
            CloseableHttpResponse response = httpclient.execute(requestBase);
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    body = EntityUtils.toString(entity, charset.toString());
                }
                EntityUtils.consume(entity);
            } catch (Exception e) {
                throw e;
            }finally {
                response.close();
            }
        } catch (Exception e) {
            throw e;
        } finally {
            httpclient.close();
        }
        return body;
    }
    private List<NameValuePair> map2NameValuePairList(Map<String, Object> params) {
        if (params != null && !params.isEmpty()) {
            List<NameValuePair> list = new ArrayList<NameValuePair>();
            Iterator<String> it = params.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next();
                if(params.get(key) != null) {
                    String value = String.valueOf(params.get(key));
                    list.add(new BasicNameValuePair(key, value));
                }
            }
            return list;
        }
        return null;
    }
}
src/main/java/org/springblade/common/utils/Md5SignUtil.java
New file
@@ -0,0 +1,54 @@
package org.springblade.common.utils;
import com.google.common.hash.Hashing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
public class Md5SignUtil {
    private final static Logger logger = LoggerFactory.getLogger(Md5SignUtil.class);
    public static String signRequest(Map<String, Object> params, String secret) throws IOException {
        // 第一步:检查参数是否已经排序
        String[] keys = params.keySet().toArray(new String[0]);
        Arrays.sort(keys);
        // 第二步:把所有参数名和参数值串在一起
        StringBuilder query = new StringBuilder();
        query.append(secret);
        for (String key : keys) {
            Object o = params.get(key);
            if (o!= null && o!="") {
                query.append(key).append(o);
            }
        }
        query.append(secret);
//        logger.info("query={}",query);
        // 第三步:使用MD5加密
        byte[] bytes = encryptMD5(query.toString());
        // 第四步:把二进制转化为大写的十六进制(正确签名应该为32大写字符串,此方法需要时使用)
        return byte2hex(bytes);
    }
    public static byte[] encryptMD5(String data) throws IOException {
        return Hashing.md5().hashBytes(data.getBytes("utf-8")).asBytes();
    }
    public static String byte2hex(byte[] bytes) {
        StringBuilder sign = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(bytes[i] & 0xFF);
            if (hex.length() == 1) {
                sign.append("0");
            }
            sign.append(hex.toUpperCase());
        }
        return sign.toString();
    }
}
src/main/java/org/springblade/modules/equipage/controller/fixed.java
New file
@@ -0,0 +1,330 @@
package org.springblade.modules.equipage.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.springblade.common.utils.HttpReqUtil;
import org.springblade.common.utils.Md5SignUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.equipage.service.CarService;
import org.springblade.modules.location.entity.LiveLocation;
import org.springblade.modules.location.entity.Locus;
import org.springblade.modules.location.service.LiveLocationService;
import org.springblade.modules.location.service.LocusService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Component
public class fixed {
    private static final DateFormat JSON = null;
    @Autowired
    private LiveLocationService liveLocationService;
    @Autowired
    private IUserService userService;
    @Autowired
    private LocusService locusService;
    @Autowired
    private CarService carService;
    /**
     * 押运人员
     *
     * @return
     * @throws Exception
     */
    //@Scheduled(cron = "0 */1 * * * ?")
    public void Peo() throws Exception {
        String url = "http://223.82.109.183:2080/Escort/getgis.php";
        //查询有押运人员的数据
        List<Map<String, Object>> list = userService.selectEquipent();
        for (int i = 0; i < list.size(); i++) {
            //实时位置实体类
            LiveLocation liveLocation = new LiveLocation();
            liveLocation.setType(1);
            String id = list.get(i).get("id").toString();
            liveLocation.setWorkerId(id);
            Map<String, Object> params = new HashMap<>();
            String equipmentCode = list.get(i).get("code").toString();
            //设备imei号
            params.put("acc", equipmentCode);
            String res = null;
            res = HttpReqUtil.getInstance().doPost(url, params, null);
            JSONArray jsonArray = JSONArray.fromObject(res);
            JSONArray sortedJsonArray = new JSONArray();
            List<JSONObject> jsonValues = new ArrayList<JSONObject>();
            for (int j = 0; j < jsonArray.size(); j++) {
                jsonValues.add(jsonArray.getJSONObject(j));
            }
            Collections.sort(jsonValues, new Comparator<JSONObject>() {
                private static final String KEY_NAME = "date";
                String string1;
                String string2;
                @Override
                public int compare(JSONObject a, JSONObject b) {
                    try {
                        string1 = a.getString(KEY_NAME).replaceAll("-", "");
                        string2 = b.getString(KEY_NAME).replaceAll("-", "");
                    } catch (JSONException e) {
                        // 处理异常
                    }
                    //这里是按照时间逆序排列,不加负号为正序排列
                    return -string1.compareTo(string2);
                }
            });
            for (int c = 0; c < jsonArray.size(); c++) {
                sortedJsonArray.add(jsonValues.get(c));
            }
            //经度
            String gis_jd = sortedJsonArray.getJSONObject(0).getString("gis_jd");
            //纬度
            String gis_wd = sortedJsonArray.getJSONObject(0).getString("gis_wd");
            String date = sortedJsonArray.getJSONObject(0).getString("date");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date dates = formatter.parse(date);
            //经度
            liveLocation.setLongitude(gis_jd);
            liveLocation.setLatitude(gis_wd);
            //纬度
            liveLocation.setRecordTime(dates);
            //先查询是否已有实时位置信息,如果有,则更新,没有则插入
            LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation);
            boolean status = false;
            if (null == liveLocationInfo) {
                //新增
                status = liveLocationService.save(liveLocation);
                //数据推送
                String s1 =
                    "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time,location) " +
                        "values(" + "'" + liveLocation.getId() + "'" + "," +
                        "'" + liveLocation.getType() + "'" + "," +
                        "'" + liveLocation.getWorkerId() + "'" + "," +
                        "'" + liveLocation.getLongitude() + "'" + "," +
                        "'" + liveLocation.getLatitude() + "'" + "," +
                        "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'" + "," +
                        "'" + liveLocation.getLocation() + "'" + ")";
                FtpUtil.sqlFileUpload(s1);
            } else {
                status = liveLocationService.updateById(liveLocationInfo);
                //内网同步
                String s1 =
                    "update sys_live_location set type = " + "'" + liveLocationInfo.getType() + "'" +
                        ",worker_id = " + "'" + liveLocationInfo.getWorkerId() + "'" +
                        ",longitude = " + "'" + liveLocationInfo.getLongitude() + "'" +
                        ",latitude = " + "'" + liveLocationInfo.getLatitude() + "'" +
                        ",record_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocationInfo.getRecordTime()) + "'" +
                        ",location = " + "'" + liveLocationInfo.getLocation() + "'" +
                        " " + "where id = " + "'" + liveLocationInfo.getId() + "'";
                FtpUtil.sqlFileUpload(s1);
            }
        }
    }
    /**
     * 押运人员轨迹
     *
     * @return
     * @throws Exception
     */
    //@Scheduled(cron = "0 */1 * * * ?")
    public void Peog() throws Exception {
        String url = "http://47.104.104.46/api/client/getgistrack.php";
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //查询有押运人员的数据
        List<Map<String, Object>> list = userService.selectEquipent();
        for (int i = 0; i < list.size(); i++) {
            //实时位置实体类
            Locus locus = new Locus();
            locus.setType(1);
            String id = list.get(i).get("id").toString();
            locus.setWorkerId(id);
            Map<String, Object> params = new HashMap<>();
            String equipmentCode = list.get(i).get("code").toString();
            //设备imei号
            params.put("number", 7730);
            params.put("acc", 7731);
            params.put("startTime", df.format(calendar.getTime()));
            params.put("endTime", df.format(new Date()));
            String res = null;
            res = HttpReqUtil.getInstance().doPost(url, params, null);
            String a="["+res+"]";
            JSONArray jsonArray = JSONArray.fromObject(a);
            String track = jsonArray.getJSONObject(0).get("track").toString();
            JSONArray jsonArray1 = JSONArray.fromObject(track);
            for (int j = 0; j < jsonArray1.size(); j++) {
                String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
                String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
                String date = jsonArray1.getJSONObject(j).get("date").toString();
                SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    //使用SimpleDateFormat的parse()方法生成Date
                    Date dates = sf.parse(date);
                    locus.setRecordTime(dates);
                    //打印Date
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                locus.setLongitude(gis_jd);
                locus.setLatitude(gis_wd);
                locusService.save(locus);
//                //数据推送
//                String s1 = "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) " +
//                        "values(" + "'" + locus.getId() + "'" + "," +
//                        "'" + locus.getType() + "'" + "," +
//                        "'" + locus.getWorkerId() + "'" + "," +
//                        "'" + locus.getLongitude() + "'" + "," +
//                        "'" + locus.getLatitude() + "'" + "," +
//                      "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
//                FtpUtil.sqlFileUpload(s1);
            }
        }
    }
    /**
     * 车辆实时位置
     */
    //@Scheduled(cron = "0 */1 * * * ?")
    public void locationcar() {
        String url = "http://dvopenapi.aimap.net.cn/openapi/device/location";
        String res = null;
        List<Map<Object, Object>> maps = carService.selectCar();
        for (int i = 0; i < maps.size(); i++) {
            Map<String, Object> params = new HashMap<>();
            params.put("imei", maps.get(i).get("code").toString());
            params.put("appId", "PO00000761");
            params.put("timestamp", System.currentTimeMillis());
            String secert = "dXRGb2pRNVdWOGQ3d1ouV29UYzc1MnJaUnBwTzUx";
            String computeSign = "";
            try {
                computeSign = Md5SignUtil.signRequest(params, secert);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            params.put("sign", computeSign);
            try {
                res = HttpReqUtil.getInstance().doPost(url, params, null);
                String a = "[" + res + "]";
                JSONArray jsonArray = JSONArray.fromObject(a);
                String data = jsonArray.getJSONObject(0).get("data").toString();
                String b = "[" + data + "]";
                JSONArray jsonArrayb = JSONArray.fromObject(b);
                String x = jsonArrayb.getJSONObject(0).get("x").toString();
                String y = jsonArrayb.getJSONObject(0).get("y").toString();
                String timestamp = jsonArrayb.getJSONObject(0).get("timestamp").toString();
                //实时位置实体类
                LiveLocation liveLocation = new LiveLocation();
                liveLocation.setType(2);
                String carnumber = maps.get(i).get("carnumber").toString();
                liveLocation.setWorkerId(carnumber);
                //经度
                liveLocation.setLongitude(x);
                //纬度
                liveLocation.setLatitude(y);
                Date date = timeStamp2Date(timestamp);
                liveLocation.setRecordTime(date);
                //先查询是否已有实时位置信息,如果有,则更新,没有则插入
                LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation);
                boolean status = false;
                if (null == liveLocationInfo) {
                    //新增
                    status = liveLocationService.save(liveLocation);
                    //数据推送
                    String s1 =
                        "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time,location) " +
                            "values(" + "'" + liveLocation.getId() + "'" + "," +
                            "'" + liveLocation.getType() + "'" + "," +
                            "'" + liveLocation.getWorkerId() + "'" + "," +
                            "'" + liveLocation.getLongitude() + "'" + "," +
                            "'" + liveLocation.getLatitude() + "'" + "," +
                            "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'" + "," +
                            "'" + liveLocation.getLocation() + "'" + ")";
                    FtpUtil.sqlFileUpload(s1);
                } else {
                    status = liveLocationService.updateById(liveLocationInfo);
                    //内网同步
                    String s1 =
                        "update sys_live_location set type = " + "'" + liveLocation.getType() + "'" +
                            ",worker_id = " + "'" + liveLocation.getWorkerId() + "'" +
                            ",longitude = " + "'" + liveLocation.getLongitude() + "'" +
                            ",latitude = " + "'" + liveLocation.getLatitude() + "'" +
                            ",record_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'" +
                            ",location = " + "'" + liveLocation.getLocation() + "'" +
                            " " + "where id = " + "'" + liveLocation.getId() + "'";
                    FtpUtil.sqlFileUpload(s1);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static Date timeStamp2Date(String time) {
        Long timeLong = Long.parseLong(time);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:00:00");//要转换的时间格式
        Date date;
        try {
            date = sdf.parse(sdf.format(timeLong));
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 查询车辆轨迹
     */
    //@Scheduled(cron = "0 */1 * * * ?")
    public void locationhistoryTrack() {
        Calendar calendar = Calendar.getInstance();
        /* HOUR_OF_DAY 指示一天中的小时 */
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH");
        String url = "http://dvopenapi.aimap.net.cn/openapi/device/historyTrack";
        String res = null;
        List<Map<Object, Object>> maps = carService.selectCar();
        for (int i = 0; i < maps.size(); i++) {
            Map<String, Object> params = new HashMap<>();
            params.put("imei", maps.get(i).get("code").toString());
            params.put("beginTime", df.format(calendar.getTime()));
            params.put("endTime", df.format(new Date()));
            params.put("rectify", 0);
            params.put("callbackUrl", "http://2h3f861221.wicp.vip/locus/SaveUrl");
            params.put("callbackId", maps.get(i).get("carnumber").toString());
            params.put("appId", "PO00000761");
            params.put("timestamp", System.currentTimeMillis());
            String secert = "dXRGb2pRNVdWOGQ3d1ouV29UYzc1MnJaUnBwTzUx";
            String computeSign = "";
            try {
                computeSign = Md5SignUtil.signRequest(params, secert);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            params.put("sign", computeSign);
            try {
                res = HttpReqUtil.getInstance().doPost(url, params, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
src/main/java/org/springblade/modules/equipage/entity/Car.java
@@ -82,4 +82,10 @@
    private String jurisdiction;
    /**
     * 押运人员设备编号
     */
    @TableField("equipment_code")
    private String equipmentCode;
}
src/main/java/org/springblade/modules/equipage/mapper/CarMapper.java
@@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
/**
 * 车辆Mapper 接口
@@ -30,4 +31,5 @@
     * @return
     */
    CarVo selectCarInfo(@Param("car") Car car);
    List<Map<Object,Object>> selectCar();
}
src/main/java/org/springblade/modules/equipage/mapper/CarMapper.xml
@@ -67,4 +67,8 @@
            and sc.id = #{car.id}
        </if>
    </select>
    <select id="selectCar" resultType="java.util.HashMap">
        SELECT equipment_code as code,car_number as carnumber FROM `sys_car` WHERE equipment_code IS NOT NULL
    </select>
</mapper>
src/main/java/org/springblade/modules/equipage/service/CarService.java
@@ -9,6 +9,7 @@
import org.springblade.modules.equipage.vo.CarVo;
import java.util.List;
import java.util.Map;
public interface CarService extends IService<Car> {
@@ -33,4 +34,5 @@
     * @param isCovered
     */
    void importCar(List<CarExcel> data, Boolean isCovered,String deptId);
    List<Map<Object,Object>> selectCar();
}
src/main/java/org/springblade/modules/equipage/service/impl/CarServiceImpl.java
@@ -16,6 +16,7 @@
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
@@ -94,4 +95,9 @@
            throw new ServiceException("没有数据");
        }
    }
    @Override
    public List<Map<Object,Object>> selectCar() {
        return baseMapper.selectCar();
    }
}
src/main/java/org/springblade/modules/location/controller/LiveLocationController.java
@@ -152,7 +152,7 @@
        liveLocation.setLongitude(locationVOTest.getLongitude().toString());
        liveLocation.setLatitude(locationVOTest.getLatitude().toString());
        liveLocation.setType(2);
        liveLocation.setWorkerId(16L);
        liveLocation.setWorkerId("16L");
        //先查询是否已有实时位置信息,如果有,则更新,没有则插入
        LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation);
src/main/java/org/springblade/modules/location/controller/LocusController.java
@@ -1,17 +1,41 @@
package org.springblade.modules.location.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csvreader.CsvReader;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import liquibase.pro.packaged.E;
import liquibase.pro.packaged.S;
import lombok.AllArgsConstructor;
import net.sf.json.JSONArray;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springblade.common.utils.DowloadZipUtil;
import org.springblade.common.utils.FileZip;
import org.springblade.common.utils.HttpReqUtil;
import org.springblade.common.utils.Md5SignUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.equipage.service.CarService;
import org.springblade.modules.location.entity.Locus;
import org.springblade.modules.location.service.LocusService;
import org.springblade.modules.location.vo.LocusVo;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
/**
 * @author zhongrj
@@ -24,9 +48,12 @@
public class LocusController {
    private final LocusService locusService;
    private final CarService carService;
    private IUserService userService;
    /**
     * 自定义分页
     *
     * @param query page,size
     * @param locus 轨迹信息对象
     */
@@ -38,6 +65,7 @@
    /**
     * 新增
     *
     * @param locus 轨迹信息对象
     */
    @PostMapping("/save")
@@ -48,6 +76,7 @@
    /**
     * 修改
     *
     * @param locus 轨迹信息对象
     */
    @PostMapping("/update")
@@ -57,6 +86,7 @@
    /**
     * 新增或修改
     *
     * @param locus 轨迹信息对象
     */
    @PostMapping("/submit")
@@ -66,6 +96,7 @@
    /**
     * 删除
     *
     * @param ids 轨迹信息ids 数组
     */
    @PostMapping("/remove")
@@ -75,6 +106,7 @@
    /**
     * 详情
     *
     * @param locus 轨迹信息对象
     */
    @GetMapping("/detail")
@@ -84,4 +116,182 @@
        return R.data(detail);
    }
    /**
     * 查询车辆轨迹
     */
    @GetMapping("/locationhistoryTrack")
    public void locationhistoryTrack() {
        String url = "http://dvopenapi.aimap.net.cn/openapi/device/historyTrack";
        String res = null;
        List<Map<Object, Object>> maps = carService.selectCar();
        for (int i = 0; i < maps.size(); i++) {
            Map<String, Object> params = new HashMap<>();
            params.put("imei", maps.get(i).get("code").toString());
            params.put("beginTime", "2021112510");
            params.put("endTime", "2021112511");
            params.put("rectify", 0);
            params.put("callbackUrl", "http://2h3f861221.wicp.vip/locus/SaveUrl");
            params.put("callbackId", maps.get(i).get("carnumber").toString());
            params.put("appId", "PO00000761");
            params.put("timestamp", System.currentTimeMillis());
            String secert = "dXRGb2pRNVdWOGQ3d1ouV29UYzc1MnJaUnBwTzUx";
            String computeSign = "";
            try {
                computeSign = Md5SignUtil.signRequest(params, secert);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            params.put("sign", computeSign);
            try {
                res = HttpReqUtil.getInstance().doPost(url, params, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 轨迹回调
     *
     * @param callbackId
     * @param fileUrl
     */
    @PostMapping("/SaveUrl")
    @ApiOperation(value = "详情", notes = "传入car")
    public void SaveUrl(String callbackId, String fileUrl) throws Exception {
        DowloadZipUtil dowloadZipUtil = new DowloadZipUtil();
        File file = dowloadZipUtil.downloadFile(fileUrl, "D:\\caiji");
        //文件名
        String name = file.getName();
        String substring = name.substring(0, name.length() - 4);
        //解压数据
        FileZip fileZip = new FileZip();
        fileZip.ZipUncompress("D:\\caiji\\" + substring + ".zip", "D:\\caiji");
        try {
            // 用来保存数据
            ArrayList<String[]> csvFileList = new ArrayList<String[]>();
            // 定义一个CSV路径
            String csvFilePath = "D:\\caiji\\" + substring + ".csv";
            // 创建CSV读对象 例如:CsvReader(文件路径,分隔符,编码格式);
            CsvReader reader = new CsvReader(csvFilePath, ',', Charset.forName("UTF-8"));
            // 跳过表头 如果需要表头的话,这句可以忽略
            reader.readHeaders();
            // 逐行读入除表头的数据
            while (reader.readRecord()) {
                csvFileList.add(reader.getValues());
            }
            reader.close();
            Locus locus = new Locus();
            String s1 = "";
            //遍历读取的CSV文件
            for (int row = 0; row < csvFileList.size(); row++) {
                // 取得第row行第0列的数据
                String cell = csvFileList.get(row)[0];
                String cell1 = csvFileList.get(row)[1];
                String cell2 = csvFileList.get(row)[2];
                Date date = timeStamp2Date(cell2);
                locus.setType(2);
                locus.setLongitude(cell);
                locus.setLatitude(cell1);
                locus.setRecordTime(date);
                locus.setWorkerId(callbackId);
                locusService.save(locus);
                //数据推送
                s1 +=
                    "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) " +
                        "values(" + "'" + locus.getId() + "'" + "," +
                        "'" + locus.getType() + "'" + "," +
                        "'" + locus.getWorkerId() + "'" + "," +
                        "'" + locus.getLongitude() + "'" + "," +
                        "'" + locus.getLatitude() + "'" + "," +
                        "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
                if (row != csvFileList.size() - 1) {
                    s1 += ";";
                }
            }
            FtpUtil.sqlFileUpload(s1);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Date timeStamp2Date(String time) {
        Long timeLong = Long.parseLong(time);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式
        Date date;
        try {
            date = sdf.parse(sdf.format(timeLong));
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
    @PostMapping("/ss")
    public void Peog() throws Exception {
        String url = "http://47.104.104.46/api/client/getgistrack.php";
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
        //查询有押运人员的数据
        List<Map<String, Object>> list = userService.selectEquipent();
        for (int i = 0; i < list.size(); i++) {
            //实时位置实体类
            Locus locus = new Locus();
            locus.setType(1);
            String id = list.get(i).get("id").toString();
            locus.setWorkerId(id);
            Map<String, Object> params = new HashMap<>();
            String equipmentCode = list.get(i).get("code").toString();
            //设备imei号
            params.put("number", 7730);
            params.put("acc", equipmentCode);
            params.put("startTime", "2021-06-01");
            params.put("endTime", "2021-08-01");
            String res = null;
            res = HttpReqUtil.getInstance().doPost(url, params, null);
            String a = "[" + res + "]";
            JSONArray jsonArray = JSONArray.fromObject(a);
            String track = jsonArray.getJSONObject(0).get("track").toString();
            JSONArray jsonArray1 = JSONArray.fromObject(track);
            String s1 = "";
            String sql="insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) values ";
            for (int j = 0; j < jsonArray1.size(); j++) {
                String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
                String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
                String date = jsonArray1.getJSONObject(j).get("date").toString();
                SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    //使用SimpleDateFormat的parse()方法生成Date
                    Date dates = sf.parse(date);
                    locus.setRecordTime(dates);
                    //打印Date
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                locus.setLongitude(gis_jd);
                locus.setLatitude(gis_wd);
                locusService.save(locus);
                //数据推送
                s1 += "(" + "'" + locus.getId() + "'" + "," +
                    "'" + locus.getType() + "'" + "," +
                    "'" + locus.getWorkerId() + "'" + "," +
                    "'" + locus.getLongitude() + "'" + "," +
                    "'" + locus.getLatitude() + "'" + "," +
                    "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
                if (j != jsonArray1.size() - 1) {
                    s1 += ",";
                }
                else {
                    s1+=";";
                }
            }
            String c = "a" +sql+ s1;
            FtpUtil.sqlFileUpload(c);
        }
    }
}
src/main/java/org/springblade/modules/location/entity/LiveLocation.java
@@ -38,7 +38,7 @@
     * 押运人员/车辆/枪支id
     */
    @TableField("worker_id")
    private Long workerId;
    private String workerId;
    /**
src/main/java/org/springblade/modules/location/entity/Locus.java
@@ -53,4 +53,17 @@
     */
    private String latitude;
    /**
     * 类型  1:押运人员  2:押运车辆  3:枪支
     */
    @TableField("type")
    private Integer type;
    /**
     * 押运人员/车辆/枪支id
     */
    @TableField("worker_id")
    private String workerId;
}
src/main/java/org/springblade/modules/record/mapper/RecordMapper.xml
@@ -56,12 +56,6 @@
        <if test="record.jurisdiction!=null and record.jurisdiction != '' and record.jurisdiction!='1372091709474910209'">
            and (sj.id = #{record.jurisdiction} or sj.parent_id = #{record.jurisdiction})
        </if>
        <!--        <if test="record.usetype=='1'.toString()">-->
        <!--            and jurisdiction in(${jurisdiction})-->
        <!--        </if>-->
        <!--        <if test="record.usetype=='2'.toString()">-->
        <!--            and  jurisdiction=#{record.jurisdiction}-->
        <!--        </if>-->
        <if test="record.papprove!=null and record.papprove!=''">
            and papprove=#{record.papprove}
        </if>