|
@@ -32,6 +32,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -98,8 +99,15 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
|
po.setStatus(CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
startService.saveBillStart(po);
|
|
|
} else {
|
|
|
- // 开票中
|
|
|
- startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
+ // 开票中或未结束
|
|
|
+ if (invoiceResultDto.getWaybillStatus().equals(1)) {
|
|
|
+ // 未结束
|
|
|
+ startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_NOT_OVER);
|
|
|
+ } else {
|
|
|
+ // 开票中
|
|
|
+ startService.updateBillStartStatus(invoiceResultDto.getWaybillNum(), CommonConstant.STATUS_MAKING_INVOICE);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
if (invoiceResultDto.getResult() != null) {
|
|
@@ -107,39 +115,25 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
|
SearchInvoiceDto searchInvoiceDto = searchInvoiceService.getSearchInvoiceByNum(invoiceResultDto.getWaybillNum());
|
|
|
if (searchInvoiceDto == null) {
|
|
|
searchInvoiceService.saveSearchInvoice(invoiceResultDto);
|
|
|
+ } else {
|
|
|
+ BeanUtil.copyProperties(searchInvoiceDto, invoiceResultDto);
|
|
|
+ searchInvoiceService.updateSearchInvoice(searchInvoiceDto);
|
|
|
}
|
|
|
+ // todo searchInvoice表状态更新
|
|
|
log.info("invoiceResultDto.getResult().size() = {}", invoiceResultDto.getResult().size());
|
|
|
if (invoiceResultDto.getResult().size() > 0) {
|
|
|
//去重列表
|
|
|
newSearchInvoiceResultList = invoiceResultDto.getResult().stream().collect(
|
|
|
Collectors.collectingAndThen(
|
|
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InvoiceResult::getFee))), ArrayList::new));
|
|
|
+ UserDto userDto = userService.getUser(po.getUserId());
|
|
|
+ UserBalanceDto userBalanceDto = userBalanceService.getUserBalance(po.getUserId());
|
|
|
+ BigDecimal balance = userBalanceDto.getBalance();
|
|
|
//计费
|
|
|
for (InvoiceResult t : newSearchInvoiceResultList) {
|
|
|
if (!redisTemplate.hasKey(CommonConstant.TRANSACTION_ID_KEY + t.getTransactionId())) {
|
|
|
- // todo 此处计费需要使用消息实现
|
|
|
-// UserBalanceDto userBalanceDto = userBalanceService.getUserBalance(po.getUserId());
|
|
|
-// UserBalanceInvoiceDto userBalanceInvoiceDto = new UserBalanceInvoiceDto();
|
|
|
-// BeanUtil.copyProperties(userBalanceInvoiceDto, userBalanceDto);
|
|
|
-// userBalanceInvoiceDto.setNum(t.getWaybillNum());
|
|
|
-// userBalanceInvoiceDto.setTransactionId(t.getTransactionId());
|
|
|
-// //发送到消息队列
|
|
|
-// log.info("发送到消息队列");
|
|
|
-// chargeProducer.send(userBalanceInvoiceDto);
|
|
|
- // 将需要计费数据插入数据库
|
|
|
- UserDto userDto = userService.getUser(po.getUserId());
|
|
|
- NeedChargeDto needChargeDto = new NeedChargeDto();
|
|
|
- needChargeDto.setUserId(po.getUserId());
|
|
|
- needChargeDto.setNum(t.getWaybillNum());
|
|
|
- needChargeDto.setPrice(userDto.getPrice());
|
|
|
- needChargeDto.setTransactionId(t.getTransactionId());
|
|
|
- needChargeService.saveNeedCharge(needChargeDto);
|
|
|
-
|
|
|
- // 计费
|
|
|
- UserBalanceDto userBalanceDto = userBalanceService.getUserBalance(po.getUserId());
|
|
|
- userBalanceDto.setBalance(userBalanceDto.getBalance().subtract(userDto.getPrice()));
|
|
|
- userBalanceService.updateUserBalance(userBalanceDto);
|
|
|
-
|
|
|
+ // 计算余额
|
|
|
+ balance = balance.subtract(userDto.getPrice());
|
|
|
// 实际扣费数据
|
|
|
RealChargeDto realChargeDto = new RealChargeDto();
|
|
|
realChargeDto.setUserId(userBalanceDto.getUserId());
|
|
@@ -148,8 +142,12 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
|
realChargeDto.setTransactionId(t.getTransactionId());
|
|
|
realChargeService.saveRealCharge(realChargeDto);
|
|
|
log.warn("计费日志:{},计费用户id:{}", JSON.toJSONString(t), po.getUserId());
|
|
|
+ //存入redis交易id
|
|
|
+ redisTemplate.opsForValue().set(CommonConstant.TRANSACTION_ID_KEY + t.getTransactionId(), t.getTransactionId());
|
|
|
}
|
|
|
}
|
|
|
+ userBalanceDto.setBalance(balance);
|
|
|
+ userBalanceService.updateUserBalance(userBalanceDto);
|
|
|
}
|
|
|
for (InvoiceResult t : invoiceResultDto.getResult()) {
|
|
|
if (!redisTemplate.hasKey(CommonConstant.NUM_FIND_INVOICE_KEY + t.getInvoiceNum() + "_" + t.getInvoiceCode())) {
|
|
@@ -161,8 +159,6 @@ public class ApiCarFreeChargeServiceImpl implements ApiCarFreeChargeService {
|
|
|
log.info("插入的发票信息:{}", JSON.toJSONString(t));
|
|
|
//存入redis发票信息
|
|
|
redisTemplate.opsForValue().set(CommonConstant.NUM_FIND_INVOICE_KEY + t.getInvoiceNum() + "_" + t.getInvoiceCode(), JSON.toJSONString(t));
|
|
|
- //存入redis交易id
|
|
|
- redisTemplate.opsForValue().set(CommonConstant.TRANSACTION_ID_KEY + t.getTransactionId(), t.getTransactionId());
|
|
|
}
|
|
|
}
|
|
|
}
|