|
@@ -80,48 +80,20 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
if (apiResponseData.getData().equals(CommonConstant.SUCCESS_CODE)
|
|
if (apiResponseData.getData().equals(CommonConstant.SUCCESS_CODE)
|
|
&& apiResponseData.getCode().equals(ApiResponseCodeEnum.CODE_200.getValue())) {
|
|
&& apiResponseData.getCode().equals(ApiResponseCodeEnum.CODE_200.getValue())) {
|
|
// 接口调用成功
|
|
// 接口调用成功
|
|
|
|
+ // 接口返回数据解析
|
|
InvoiceResultDto invoiceResultDto = JSON.toJavaObject(JSON.parseObject(apiResponseData.getMsg()), InvoiceResultDto.class);
|
|
InvoiceResultDto invoiceResultDto = JSON.toJavaObject(JSON.parseObject(apiResponseData.getMsg()), InvoiceResultDto.class);
|
|
List<InvoiceResult> newSearchInvoiceResultList;
|
|
List<InvoiceResult> newSearchInvoiceResultList;
|
|
|
|
|
|
- // 根据运单发票状态更新运单状态
|
|
|
|
- if (invoiceResultDto.getWaybillStatus().equals(CommonConstant.STATUS_INVOICE_OVER)) {
|
|
|
|
- if (po.getId() == null) {
|
|
|
|
- po.setIsSearch(2);
|
|
|
|
- po.setStatus(CommonConstant.STATUS_INVOICE_OVER);
|
|
|
|
- startService.saveBillStart(po);
|
|
|
|
- } else {
|
|
|
|
- // 开票完成
|
|
|
|
- startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_INVOICE_OVER);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (po.getId() == null) {
|
|
|
|
- po.setIsSearch(2);
|
|
|
|
- po.setStatus(CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
|
- startService.saveBillStart(po);
|
|
|
|
- } else {
|
|
|
|
- // 开票中或未结束
|
|
|
|
- if (invoiceResultDto.getWaybillStatus().equals(1)) {
|
|
|
|
- // 未结束
|
|
|
|
- startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_NOT_OVER);
|
|
|
|
- } else {
|
|
|
|
- // 开票中
|
|
|
|
- startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
|
- }
|
|
|
|
|
|
+ // 根据接口返回运单状态更新表h_car_free_carrier_bill_start 状态
|
|
|
|
+ updateWaybillStartStatus(po, invoiceResultDto);
|
|
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
if (invoiceResultDto.getResult() != null) {
|
|
if (invoiceResultDto.getResult() != null) {
|
|
- // 判断运单查询发票返回共用信息在数据库中是否存在,不存在则存入
|
|
|
|
- SearchInvoiceDto searchInvoiceDto = searchInvoiceService.getSearchInvoiceByNum(invoiceResultDto.getWaybillNum());
|
|
|
|
- if (searchInvoiceDto == null) {
|
|
|
|
- searchInvoiceService.saveSearchInvoice(invoiceResultDto);
|
|
|
|
- } else {
|
|
|
|
- BeanUtil.copyProperties(searchInvoiceDto, invoiceResultDto);
|
|
|
|
- searchInvoiceService.updateSearchInvoice(searchInvoiceDto);
|
|
|
|
- }
|
|
|
|
|
|
+ // 保存运单查询发票接口返回的外层数据,表h_search_invoice
|
|
|
|
+ saveSearchInvoice(invoiceResultDto);
|
|
log.info("invoiceResultDto.getResult().size() = {}", invoiceResultDto.getResult().size());
|
|
log.info("invoiceResultDto.getResult().size() = {}", invoiceResultDto.getResult().size());
|
|
- if (invoiceResultDto.getResult().size() > 0) {
|
|
|
|
- //去重列表
|
|
|
|
|
|
+
|
|
|
|
+ if (!invoiceResultDto.getResult().isEmpty()) {
|
|
|
|
+ //接口返回发票去重列表
|
|
newSearchInvoiceResultList = invoiceResultDto.getResult().stream().collect(
|
|
newSearchInvoiceResultList = invoiceResultDto.getResult().stream().collect(
|
|
Collectors.collectingAndThen(
|
|
Collectors.collectingAndThen(
|
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InvoiceResult::getFee))), ArrayList::new));
|
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InvoiceResult::getFee))), ArrayList::new));
|
|
@@ -147,17 +119,19 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
}
|
|
}
|
|
userBalanceDto.setBalance(balance);
|
|
userBalanceDto.setBalance(balance);
|
|
userBalanceService.updateUserBalance(userBalanceDto);
|
|
userBalanceService.updateUserBalance(userBalanceDto);
|
|
- }
|
|
|
|
- for (InvoiceResult t : invoiceResultDto.getResult()) {
|
|
|
|
- if (!redisTemplate.hasKey(CommonConstant.NUM_FIND_INVOICE_KEY + t.getInvoiceNum() + "_" + t.getInvoiceCode())) {
|
|
|
|
- SearchInvoiceResultDto dto = new SearchInvoiceResultDto();
|
|
|
|
- BeanUtil.copyProperties(dto, t);
|
|
|
|
- dto.setUserId(po.getUserId());
|
|
|
|
- //插入发票信息
|
|
|
|
- searchInvoiceResultService.saveSearchInvoiceResult(dto);
|
|
|
|
- log.info("插入的发票信息:{}", JSON.toJSONString(t));
|
|
|
|
- //存入redis发票信息
|
|
|
|
- redisTemplate.opsForValue().set(CommonConstant.NUM_FIND_INVOICE_KEY + t.getInvoiceNum() + "_" + t.getInvoiceCode(), JSON.toJSONString(t));
|
|
|
|
|
|
+
|
|
|
|
+ // 保存发票信息
|
|
|
|
+ for (InvoiceResult t : invoiceResultDto.getResult()) {
|
|
|
|
+ if (!redisTemplate.hasKey(CommonConstant.NUM_FIND_INVOICE_KEY + t.getInvoiceNum() + "_" + t.getInvoiceCode())) {
|
|
|
|
+ SearchInvoiceResultDto dto = new SearchInvoiceResultDto();
|
|
|
|
+ BeanUtil.copyProperties(dto, t);
|
|
|
|
+ dto.setUserId(po.getUserId());
|
|
|
|
+ //插入发票信息
|
|
|
|
+ searchInvoiceResultService.saveSearchInvoiceResult(dto);
|
|
|
|
+ log.info("插入的发票信息:{}", JSON.toJSONString(t));
|
|
|
|
+ //存入redis发票信息
|
|
|
|
+ redisTemplate.opsForValue().set(CommonConstant.NUM_FIND_INVOICE_KEY + t.getInvoiceNum() + "_" + t.getInvoiceCode(), JSON.toJSONString(t));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -167,4 +141,46 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
throw new ServiceException("调用接口失败");
|
|
throw new ServiceException("调用接口失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 根据接口返回运单状态更新表h_car_free_carrier_bill_start 状态
|
|
|
|
+ private void updateWaybillStartStatus(CarFreeCarrierBillStartPo po, InvoiceResultDto invoiceResultDto) {
|
|
|
|
+ if (invoiceResultDto.getWaybillStatus().equals(CommonConstant.STATUS_INVOICE_OVER)) {
|
|
|
|
+ if (po.getId() == null) {
|
|
|
|
+ po.setIsSearch(2);
|
|
|
|
+ po.setStatus(CommonConstant.STATUS_INVOICE_OVER);
|
|
|
|
+ startService.saveBillStart(po);
|
|
|
|
+ } else {
|
|
|
|
+ // 开票完成
|
|
|
|
+ startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_INVOICE_OVER);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (po.getId() == null) {
|
|
|
|
+ po.setIsSearch(2);
|
|
|
|
+ po.setStatus(CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
|
+ startService.saveBillStart(po);
|
|
|
|
+ } else {
|
|
|
|
+ // 开票中或未结束
|
|
|
|
+ if (invoiceResultDto.getWaybillStatus().equals(1)) {
|
|
|
|
+ // 未结束
|
|
|
|
+ startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_NOT_OVER);
|
|
|
|
+ } else {
|
|
|
|
+ // 开票中
|
|
|
|
+ startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 保存运单查询发票接口返回的外层数据
|
|
|
|
+ private void saveSearchInvoice(InvoiceResultDto invoiceResultDto) {
|
|
|
|
+ // 判断运单查询发票返回共用信息在数据库中是否存在,不存在则存入
|
|
|
|
+ SearchInvoiceDto searchInvoiceDto = searchInvoiceService.getSearchInvoiceByNum(invoiceResultDto.getWaybillNum());
|
|
|
|
+ if (searchInvoiceDto == null) {
|
|
|
|
+ searchInvoiceService.saveSearchInvoice(invoiceResultDto);
|
|
|
|
+ } else {
|
|
|
|
+ BeanUtil.copyProperties(searchInvoiceDto, invoiceResultDto);
|
|
|
|
+ searchInvoiceService.updateSearchInvoice(searchInvoiceDto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|