| src/main/java/org/springblade/common/constant/FtpConstant.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/equipage/controller/CarController.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/equipage/controller/DowloadZipUtil.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/equipage/controller/FileZip.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/equipage/controller/HttpReqUtil.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/equipage/controller/Md5SignUtil.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/recordk/entity/Recordk.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/recordk/mapper/RecordkMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/org/springblade/common/constant/FtpConstant.java
@@ -16,7 +16,7 @@ String sql_connect_dev = "jdbc:mysql://223.82.109.183:2083/zhbay?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true"; //ftp服务器IP地址 String ftpHost_dev = "192.168.0.112"; String ftpHost_dev = "192.168.0.107"; //ftp服务器IP地址 // String ftpHost_dev = "47.49.21.194"; src/main/java/org/springblade/modules/equipage/controller/CarController.java
@@ -13,6 +13,15 @@ import org.springblade.modules.equipage.vo.CarVo; import org.springframework.web.bind.annotation.*; import java.awt.*; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author zhongrj * @time 2021-07-06 @@ -24,6 +33,7 @@ public class CarController { private final CarService carService; private static String csvurl; /** * 自定义分页 @@ -83,5 +93,161 @@ CarVo detail = carService.selectCarInfo(car); return R.data(detail); } /** * 查询车辆实时位置 */ @GetMapping("/locationcar") public String locationcar(String imei) { String url = "http://dvopenapi.aimap.net.cn/openapi/device/location"; String res = null; Map<String, Object> params = new HashMap<>(); params.put("imei", imei); 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 { //String res = HttpReqUtil.getInstance().doGet(url, params, null); res = HttpReqUtil.getInstance().doPost(url, params, null); System.out.println("----" + res); } catch (Exception e) { e.printStackTrace(); } return res; } /** * 查询车辆轨迹 */ @GetMapping("/locationhistoryTrack") public R locationhistoryTrack(String beginTime, String endTime, String rectify) throws AWTException { String url = "http://dvopenapi.aimap.net.cn/openapi/device/historyTrack"; String res = null; Map<String, Object> params = new HashMap<>(); params.put("imei", "861636056082414"); params.put("beginTime", beginTime); params.put("endTime", endTime); params.put("rectify", rectify); params.put("callbackUrl", "http://2h3f861221.wicp.vip/car/SaveUrl"); params.put("callbackId", "1"); 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 { //String res = HttpReqUtil.getInstance().doGet(url, params, null); res = HttpReqUtil.getInstance().doPost(url, params, null); Thread.sleep(2000); } catch (Exception e) { e.printStackTrace(); } return R.data(csvurl); } /** * 实时视频直播指令下发接口 */ @GetMapping("/cmd") public String cmd(int camera, String action) { String url = "http://dvopenapi.aimap.net.cn/openapi/live/cmd"; String res = null; Map<String, Object> params = new HashMap<>(); //设备imei号 params.put("imei", "861636056082414"); //摄像头ID params.put("camera", camera); //实时视频指令类型 params.put("action", action); 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 { //String res = HttpReqUtil.getInstance().doGet(url, params, null); res = HttpReqUtil.getInstance().doPost(url, params, null); System.out.println("----" + res); } catch (Exception e) { e.printStackTrace(); } return res; } /** * 轨迹回调 * * @param callbackId * @param fileUrl * @throws UnsupportedEncodingException */ @PostMapping("/SaveUrl") @ApiOperation(value = "详情", notes = "传入car") public void SaveUrl(String callbackId, String fileUrl) throws Exception { csvurl = null; List<String> allString = new ArrayList<>(); 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"); csvurl = "D:\\caiji\\" + substring + ".csv"; } /** * 人员 * @return * @throws Exception */ @GetMapping("/Peo") public String cs() throws Exception { String url = "http://223.82.109.183:2080/Escort/getgis.php"; Map<String, Object> params = new HashMap<>(); //设备imei号 params.put("acc", "7731"); String res = null; res = HttpReqUtil.getInstance().doPost(url, params, null); return res; } /** * 轨迹 * @return * @throws Exception */ @GetMapping("/Peog") public String Peocar() throws Exception { String url = "http://223.82.109.183:2080/Escort/getgistrack.php"; Map<String, Object> params = new HashMap<>(); //设备imei号 params.put("number", "7730"); params.put("acc", "7731"); String res = null; res = HttpReqUtil.getInstance().doPost(url, params, null); return res; } } src/main/java/org/springblade/modules/equipage/controller/DowloadZipUtil.java
New file @@ -0,0 +1,66 @@ package org.springblade.modules.equipage.controller; 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/modules/equipage/controller/FileZip.java
New file @@ -0,0 +1,100 @@ package org.springblade.modules.equipage.controller; 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/modules/equipage/controller/HttpReqUtil.java
New file @@ -0,0 +1,264 @@ package org.springblade.modules.equipage.controller; 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; } public static void main(String[] args) { String url = "http://dvopenapi.aimap.net.cn/openapi/device/location"; Map<String, Object> params = new HashMap<>(); // params.put("beginTime", 1585059861400L); // params.put("endTime", 1585059862400L); // params.put("alarmType ", "8"); params.put("imei", "861636056082414"); 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 { //String res = HttpReqUtil.getInstance().doGet(url, params, null); String res = HttpReqUtil.getInstance().doPost(url, params, null); System.out.println("----"+res); } catch (Exception e) { e.printStackTrace(); } } } src/main/java/org/springblade/modules/equipage/controller/Md5SignUtil.java
New file @@ -0,0 +1,54 @@ package org.springblade.modules.equipage.controller; 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/recordk/entity/Recordk.java
@@ -151,5 +151,27 @@ private String contacts; private String contactscell; private String approve; //派出所审批 private String papprove; //县审批 private String xapprove; //市审批 private String sapprove; //派出意见 private String popinion; //县意见 private String xopinion; //市意见 private String sopinion; @ApiModelProperty(value = "审批时间") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd") private Date overtime; @ApiModelProperty(value = "提交时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date permitime; } src/main/java/org/springblade/modules/recordk/mapper/RecordkMapper.xml
@@ -28,6 +28,13 @@ <result column="contacts" property="contacts"/> <result column="contactscell" property="contactscell"/> <result column="approve" property="approve"/> <result column="papprove" property="papprove"/> <result column="xapprove" property="xapprove"/> <result column="sapprove" property="sapprove"/> <result column="popinion" property="popinion"/> <result column="xopinion" property="xopinion"/> <result column="sopinion" property="sopinion"/> <result column="overtime" property="overtime"/> </resultMap>