|
|
|
|
@ -1,260 +0,0 @@
|
|
|
|
|
package com.nmggs.query.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.nmggs.query.common.emnu.MessageEnum;
|
|
|
|
|
import com.nmggs.query.common.exception.PPException;
|
|
|
|
|
import com.nmggs.query.common.utils.CheckUtils;
|
|
|
|
|
import com.nmggs.query.common.utils.FileUtil;
|
|
|
|
|
import com.nmggs.query.common.utils.LogUtil;
|
|
|
|
|
import com.nmggs.query.common.utils.MD5Util;
|
|
|
|
|
import com.nmggs.query.common.utils.PropertiesUtil;
|
|
|
|
|
import com.nmggs.query.mapper.AddInterfaceMapper;
|
|
|
|
|
import com.nmggs.query.service.AddInterfaceService;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author: shuguang
|
|
|
|
|
* @date: 2025年04月27日 9:51
|
|
|
|
|
* @description:
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class AddInterfaceServiceImpl implements AddInterfaceService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AddInterfaceMapper addInterfaceMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询收费门架费率
|
|
|
|
|
*
|
|
|
|
|
* @param params 查询参数
|
|
|
|
|
* @param uuid uuid
|
|
|
|
|
* @return java.lang.String
|
|
|
|
|
* @author shuguang
|
|
|
|
|
* @date 2025-04-27 9:53
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String gantryfee(Map<String, Object> params, String uuid) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-开始通过接口获取收费门架费率,参数为" + params, "AddInterfaceServiceImpl-gantryfee");
|
|
|
|
|
//鉴权码
|
|
|
|
|
String authKey = PropertiesUtil.getValue("authKey");
|
|
|
|
|
int version = (Integer) params.get("version");
|
|
|
|
|
String reqAuthKey = (String) params.get("authKey");
|
|
|
|
|
String reqMd5 = (String) params.get("md5");
|
|
|
|
|
String verifyMd5 = MD5Util.md5(version + authKey);
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-鉴权码为:" + authKey + ",请求鉴权码为:" + reqAuthKey + ",请求md5为:" + reqMd5 + ",验证md5为:" + verifyMd5, "AddInterfaceServiceImpl-QueryExStationTrans");
|
|
|
|
|
CheckUtils.checkAddParams(authKey, reqAuthKey, reqMd5, verifyMd5);
|
|
|
|
|
int maxIdx = addInterfaceMapper.getNodefeeMaxIdx();
|
|
|
|
|
List<Map<String, Object>> list;
|
|
|
|
|
String result = "";
|
|
|
|
|
if (version >= maxIdx) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-当前查询的版本号" + version + "收费门架费率数据已是最新数据,查询不返回数据", "AddInterfaceServiceImpl-gantryfee");
|
|
|
|
|
throw new PPException(MessageEnum.当前数据已为最新.getCode(), MessageEnum.当前数据已为最新.getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
list = addInterfaceMapper.selectNodefeeList();
|
|
|
|
|
}
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-获取查询数据,条数为" + list.size(), "AddInterfaceServiceImpl-gantryfee");
|
|
|
|
|
result = conversionJson(list, uuid);
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询连通关系
|
|
|
|
|
*
|
|
|
|
|
* @param params 查询参数
|
|
|
|
|
* @param uuid uuid
|
|
|
|
|
* @return java.lang.String
|
|
|
|
|
* @author shuguang
|
|
|
|
|
* @date 2025-04-27 9:53
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String gantryinfo(Map<String, Object> params, String uuid) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-开始通过接口获取连通关系数据,参数为" + params, "AddInterfaceServiceImpl-gantryinfo");
|
|
|
|
|
//鉴权码
|
|
|
|
|
String authKey = PropertiesUtil.getValue("authKey");
|
|
|
|
|
int version = (Integer) params.get("version");
|
|
|
|
|
String reqAuthKey = (String) params.get("authKey");
|
|
|
|
|
String reqMd5 = (String) params.get("md5");
|
|
|
|
|
String verifyMd5 = MD5Util.md5(version + authKey);
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-鉴权码为:" + authKey + ",请求鉴权码为:" + reqAuthKey + ",请求md5为:" + reqMd5 + ",验证md5为:" + verifyMd5, "AddInterfaceServiceImpl-QueryExStationTrans");
|
|
|
|
|
CheckUtils.checkAddParams(authKey, reqAuthKey, reqMd5, verifyMd5);
|
|
|
|
|
int maxIdx = addInterfaceMapper.getNoderelationMaxIdx();
|
|
|
|
|
List<Map<String, Object>> list;
|
|
|
|
|
String result = "";
|
|
|
|
|
if (version >= maxIdx) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-当前查询的版本号" + version + "收费门架费率数据已是最新数据,查询不返回数据", "AddInterfaceServiceImpl-gantryinfo");
|
|
|
|
|
throw new PPException(MessageEnum.当前数据已为最新.getCode(), MessageEnum.当前数据已为最新.getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
list = addInterfaceMapper.selectNoderelationList();
|
|
|
|
|
}
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-获取查询数据,条数为" + list.size(), "AddInterfaceServiceImpl-gantryinfo");
|
|
|
|
|
result = conversionJson(list, uuid);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据参数下载最小费额文件
|
|
|
|
|
*
|
|
|
|
|
* @param params 参数
|
|
|
|
|
* @param uuid uuid
|
|
|
|
|
* @param response HttpServletResponse
|
|
|
|
|
* @author shuguang
|
|
|
|
|
* @date 2025-04-27 9:53
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public void minPath(Map<String, Object> params, String uuid, HttpServletResponse response) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-开始通过接口根据参数下载最小费额文件,参数为" + params, "AddInterfaceServiceImpl-minPath");
|
|
|
|
|
String version = (String) params.get("version");
|
|
|
|
|
int subcomno = (Integer) params.get("subcomno");
|
|
|
|
|
int stano = (Integer) params.get("stano");
|
|
|
|
|
//鉴权码
|
|
|
|
|
String authKey = PropertiesUtil.getValue("authKey");
|
|
|
|
|
String reqAuthKey = (String) params.get("authKey");
|
|
|
|
|
String reqMd5 = (String) params.get("md5");
|
|
|
|
|
String verifyMd5 = MD5Util.md5(version+subcomno+stano + authKey);
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-鉴权码为:" + authKey + ",请求鉴权码为:" + reqAuthKey + ",请求md5为:" + reqMd5 + ",验证md5为:" + verifyMd5, "AddInterfaceServiceImpl-QueryExStationTrans");
|
|
|
|
|
CheckUtils.checkAddParams(authKey, reqAuthKey, reqMd5, verifyMd5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String minFeeFilePath = PropertiesUtil.getValue("minFeeFilePath");
|
|
|
|
|
List<Long> longs = FileUtil.folderNames(minFeeFilePath);
|
|
|
|
|
if (longs.size() > 0) {
|
|
|
|
|
long latestVersion = Collections.max(longs);
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-当前请求下载的版本号" + version + "最小费额文件最新版本号为:" + latestVersion, "AddInterfaceServiceImpl-minPath");
|
|
|
|
|
|
|
|
|
|
if (Long.parseLong(version) >= latestVersion) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-当前查询的版本号" + version + "最小费额文件已是最新数据,查询不返回数据", "AddInterfaceServiceImpl-minPath");
|
|
|
|
|
throw new PPException(MessageEnum.当前数据已为最新.getCode(), MessageEnum.当前数据已为最新.getMessage());
|
|
|
|
|
}
|
|
|
|
|
minFeeFilePath = minFeeFilePath + File.separator + latestVersion + File.separator + subcomno;
|
|
|
|
|
// 构造正则表达式
|
|
|
|
|
String regex = ".*ALLROADMINFEE_"+latestVersion+"_" +stano+"_.*\\.ZLIB$";
|
|
|
|
|
// 检查文件是否存在
|
|
|
|
|
String filePath = checkFileExistsAndGetPath(minFeeFilePath, regex);
|
|
|
|
|
|
|
|
|
|
if (filePath == null) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-当前查询的版本号" + version + "最小费额文件不存在,查询不返回数据", "AddInterfaceServiceImpl-minPath");
|
|
|
|
|
throw new PPException(MessageEnum.最小费额文件不存在.getCode(), MessageEnum.最小费额文件不存在.getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
// 将文件以下载形式返回
|
|
|
|
|
File file = new File(filePath);
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
response.setContentLengthLong(file.length());
|
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=\"" + file.getName() + "\"");
|
|
|
|
|
|
|
|
|
|
try (FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
|
|
OutputStream outputStream = response.getOutputStream()) {
|
|
|
|
|
byte[] buffer = new byte[4096];
|
|
|
|
|
int bytesRead;
|
|
|
|
|
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
|
|
|
|
|
outputStream.write(buffer, 0, bytesRead);
|
|
|
|
|
}
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-文件流操作失败:" + e.getMessage(), "AddInterfaceServiceImpl-minPath");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new PPException(MessageEnum.最小费额文件不存在.getCode(), MessageEnum.最小费额文件不存在.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 出口交易查询
|
|
|
|
|
*
|
|
|
|
|
* @param params 查询参数
|
|
|
|
|
* @param uuid uuid
|
|
|
|
|
* @return java.lang.String
|
|
|
|
|
* @author shuguang
|
|
|
|
|
* @date 2025-04-27 9:53
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String QueryExStationTrans(Map<String, Object> params, String uuid) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-开始通过接口获取出口交易数据,参数为" + params, "AddInterfaceServiceImpl-QueryExStationTrans");
|
|
|
|
|
String vehiclePlate = (String) params.get("VehiclePlate");
|
|
|
|
|
String dateStart = (String) params.get("dateStart");
|
|
|
|
|
String dateEnd = (String) params.get("dateEnd");
|
|
|
|
|
//鉴权码
|
|
|
|
|
String authKey = PropertiesUtil.getValue("authKey");
|
|
|
|
|
String reqAuthKey = (String) params.get("authKey");
|
|
|
|
|
String reqMd5 = (String) params.get("md5");
|
|
|
|
|
String verifyMd5 = MD5Util.md5(vehiclePlate+dateStart+dateEnd + authKey);
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-鉴权码为:" + authKey + ",请求鉴权码为:" + reqAuthKey + ",请求md5为:" + reqMd5 + ",验证md5为:" + verifyMd5, "AddInterfaceServiceImpl-QueryExStationTrans");
|
|
|
|
|
CheckUtils.checkAddParams(authKey, reqAuthKey, reqMd5, verifyMd5);
|
|
|
|
|
List<Map<String, Object>> list = addInterfaceMapper.selectExStationTransList(vehiclePlate, dateStart, dateEnd);
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-获取查询数据,条数为" + list.size(), "AddInterfaceServiceImpl-QueryExStationTrans");
|
|
|
|
|
Map<String, Object> map = new java.util.HashMap<>();
|
|
|
|
|
map.put("dataCount", list.size());
|
|
|
|
|
map.put("dataList", list);
|
|
|
|
|
return conversionMapToJson(map, uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String conversionJson(List<Map<String, Object>> list, String uuid) {
|
|
|
|
|
String result = "";
|
|
|
|
|
// 使用ObjectMapper将List<Map<String, Object>>转换为JSON字符串
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
try {
|
|
|
|
|
result = objectMapper.writeValueAsString(list);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-转换json数据报错:" + e.getMessage(), "AddInterfaceServiceImpl-conversionJson");
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String conversionMapToJson(Map<String, Object> map, String uuid) {
|
|
|
|
|
String result = "";
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
try {
|
|
|
|
|
result = objectMapper.writeValueAsString(map);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
LogUtil.WriteLog_AddInterface("[uuid:" + uuid + "]-转换json数据报错:" + e.getMessage(), "AddInterfaceServiceImpl-conversionMapToJson");
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String checkFileExistsAndGetPath(String directoryPath, String regex) {
|
|
|
|
|
try {
|
|
|
|
|
// 获取目录路径
|
|
|
|
|
Path path = Paths.get(directoryPath);
|
|
|
|
|
|
|
|
|
|
// 遍历目录中的文件
|
|
|
|
|
return Files.list(path)
|
|
|
|
|
// 确保是文件
|
|
|
|
|
.filter(Files::isRegularFile)
|
|
|
|
|
// 获取文件名
|
|
|
|
|
.map(Path::getFileName)
|
|
|
|
|
// 转换为字符串
|
|
|
|
|
.map(Path::toString)
|
|
|
|
|
// 匹配正则表达式
|
|
|
|
|
.filter(fileName -> fileName.matches(regex))
|
|
|
|
|
// 获取文件路径
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(fileName -> directoryPath + File.separator + fileName)
|
|
|
|
|
.orElse(null);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|