|
@@ -1,14 +1,11 @@
|
|
|
package com.jkcredit.query.record.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ciphergateway.ciphersuite.CipherSuiteException;
|
|
|
import com.ciphergateway.ciphersuite.CipherSuiteMacException;
|
|
|
import com.ciphergateway.ciphersuite.CipherSuiteUtils;
|
|
|
import com.jkcredit.query.record.constant.CommonConstant;
|
|
|
-import com.jkcredit.query.record.model.CommonResponseObject;
|
|
|
-import com.jkcredit.query.record.model.LogObject;
|
|
|
-import com.jkcredit.query.record.model.MonthResult;
|
|
|
+import com.jkcredit.query.record.model.*;
|
|
|
import com.jkcredit.query.record.service.QueryRecordService;
|
|
|
import com.jkcredit.query.record.util.IndexUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -63,24 +60,32 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
|
|
|
/**
|
|
|
* 根据月份,车牌号查询
|
|
|
- * @param plateNumber 车牌号
|
|
|
- * @param month 月份
|
|
|
+ *
|
|
|
+ * @param param 车牌号 月份
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResponseObject monthRecords(String plateNumber, String month) {
|
|
|
- String[] indices = {CommonConstant.ES_INDEX + month};
|
|
|
- List<MonthResult> results = find(plateNumber, indices);
|
|
|
+ public CommonResponseObject monthRecords(MonthRecordsRequestParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getPlateNumber()) || StringUtils.isBlank(param.getMonth())) {
|
|
|
+ return new CommonResponseObject(CommonConstant.PARAM_ERROR_CODE, CommonConstant.PARAM_ERROR);
|
|
|
+ }
|
|
|
+ String[] indices = {CommonConstant.ES_INDEX + param.getMonth()};
|
|
|
+ List<MonthResult> results = find(param.getPlateNumber(), indices);
|
|
|
return new CommonResponseObject(CommonConstant.SUCCESS_CODE, JSON.toJSONString(results));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据车牌号,查询12个月的结果
|
|
|
- * @param plateNumber 车牌号
|
|
|
+ *
|
|
|
+ * @param param 车牌号
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResponseObject yearRecords(String plateNumber) {
|
|
|
+ public CommonResponseObject yearRecords(YearRecordsRequestParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getPlateNumber())) {
|
|
|
+ return new CommonResponseObject(CommonConstant.PARAM_ERROR_CODE, CommonConstant.PARAM_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
String[] indices = new String[12];
|
|
|
LocalDate today = LocalDate.now();
|
|
|
for (int i = 0; i < 12; i++) {
|
|
@@ -88,18 +93,23 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
String month = localDate.toString().substring(0, 7).replace("-", "");
|
|
|
indices[i] = CommonConstant.ES_INDEX + month;
|
|
|
}
|
|
|
- List<MonthResult> results = find(plateNumber, indices);
|
|
|
+ List<MonthResult> results = find(param.getPlateNumber(), indices);
|
|
|
return new CommonResponseObject(CommonConstant.SUCCESS_CODE, JSON.toJSONString(results));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询索引中结果总数
|
|
|
- * @param month 月份
|
|
|
+ *
|
|
|
+ * @param param 月份
|
|
|
* @return 结果总数
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResponseObject countByMonth(String month) {
|
|
|
- String index = CommonConstant.ES_INDEX + month;
|
|
|
+ public CommonResponseObject countByMonth(RecordsCountRequestParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getMonth())) {
|
|
|
+ return new CommonResponseObject(CommonConstant.PARAM_ERROR_CODE, CommonConstant.PARAM_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ String index = CommonConstant.ES_INDEX + param.getMonth();
|
|
|
if (!isExistIndex(index)) {
|
|
|
return new CommonResponseObject(CommonConstant.SUCCESS_CODE, "0");
|
|
|
}
|
|
@@ -114,21 +124,26 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
countResponse = esRestClient.count(countRequest, RequestOptions.DEFAULT);
|
|
|
count = countResponse != null ? countResponse.getCount() : 0;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("queryRecordError:", e);
|
|
|
+ log.error("queryRecordCountException:", e);
|
|
|
}
|
|
|
return new CommonResponseObject(CommonConstant.SUCCESS_CODE, String.valueOf(count));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据车牌号,查询多月结果(小于12个月)
|
|
|
- * @param plateNumber 车牌号
|
|
|
- * @param startMonth 起始月份
|
|
|
- * @param endMonth 结束月份
|
|
|
+ *
|
|
|
+ * @param param 车牌号 起始月份 结束月份
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommonResponseObject multipleMonthRecords(String plateNumber, String startMonth, String endMonth) {
|
|
|
- List<String> monthList = getMonthBetween(startMonth, endMonth);
|
|
|
+ public CommonResponseObject multipleMonthRecords(MultipleMonthRecordsRequestParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getStartMonth())
|
|
|
+ || StringUtils.isBlank(param.getEndMonth())
|
|
|
+ || StringUtils.isBlank(param.getPlateNumber())) {
|
|
|
+ return new CommonResponseObject(CommonConstant.PARAM_ERROR_CODE, CommonConstant.PARAM_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> monthList = getMonthBetween(param.getStartMonth(), param.getEndMonth());
|
|
|
if (monthList.size() > 12 || monthList.size() == 0) {
|
|
|
return new CommonResponseObject(CommonConstant.MONTH_ERROR_CODE, CommonConstant.MONTH_ERROR);
|
|
|
}
|
|
@@ -136,14 +151,15 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
for (int i = 0; i < monthList.size(); i++) {
|
|
|
indices[i] = CommonConstant.ES_INDEX + monthList.get(i);
|
|
|
}
|
|
|
- List<MonthResult> results = find(plateNumber, indices);
|
|
|
+ List<MonthResult> results = find(param.getPlateNumber(), indices);
|
|
|
return new CommonResponseObject(CommonConstant.SUCCESS_CODE, JSON.toJSONString(results));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据车牌号,索引查结果
|
|
|
+ *
|
|
|
* @param plateNumber 车牌号
|
|
|
- * @param indices 索引
|
|
|
+ * @param indices 索引
|
|
|
* @return 结果
|
|
|
*/
|
|
|
private List<MonthResult> find(String plateNumber, String[] indices) {
|
|
@@ -196,14 +212,16 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
// 执行请求
|
|
|
searchResponse = esRestClient.search(searchRequest, RequestOptions.DEFAULT);
|
|
|
} catch (IOException e) {
|
|
|
+ log.error("queryRecordException:", e);
|
|
|
+ }
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ if (searchResponse == null) {
|
|
|
logObject.setSuccess(false);
|
|
|
logObject.setMessage(CommonConstant.QUERY_ERROR);
|
|
|
log.info(JSON.toJSONString(logObject));
|
|
|
- log.error("encryptPlateNumberError:{}", plateNumber);
|
|
|
- log.error("queryRecordError:", e);
|
|
|
+ return results;
|
|
|
}
|
|
|
- long endTime = System.currentTimeMillis();
|
|
|
-
|
|
|
// 返回查询到的具体数据
|
|
|
SearchHits searchHits = searchResponse.getHits();
|
|
|
for (SearchHit hit : searchHits.getHits()) {
|
|
@@ -214,13 +232,14 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
logObject.setSuccess(true);
|
|
|
logObject.setMessage(CommonConstant.QUERY_SUCCESS);
|
|
|
logObject.setResult(results);
|
|
|
- logObject.setQueryRecordSuccess(endTime-startTime);
|
|
|
+ logObject.setQueryRecordSuccess(endTime - startTime);
|
|
|
log.info(JSON.toJSONString(logObject));
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断索引是否存在
|
|
|
+ *
|
|
|
* @param index 索引
|
|
|
* @return 结果
|
|
|
*/
|
|
@@ -246,6 +265,7 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
|
|
|
/**
|
|
|
* 获取月份区间
|
|
|
+ *
|
|
|
* @param minDate 开始月
|
|
|
* @param maxDate 结束月
|
|
|
* @return 月份集合
|
|
@@ -276,6 +296,7 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
|
|
|
/**
|
|
|
* 对vehicle_id字段进行加密
|
|
|
+ *
|
|
|
* @param vehicleId 待加密vehicleId
|
|
|
* @return 加密后vehicleId
|
|
|
*/
|
|
@@ -283,7 +304,6 @@ public class QueryRecordServiceImpl implements QueryRecordService {
|
|
|
try {
|
|
|
byte[] plainData = vehicleId.getBytes("UTF-8");
|
|
|
byte[] iv = ivStr.getBytes("UTF-8");
|
|
|
- Long startTime = System.currentTimeMillis();
|
|
|
// 加密
|
|
|
byte[] cipherData = CipherSuiteUtils.encrypt(plainData, algorithm, keyId, metadata, iv);
|
|
|
return DatatypeConverter.printHexBinary(cipherData);
|