|
@@ -8,12 +8,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fire.admin.dto.AdditionalPaymentDto;
|
|
|
import com.fire.admin.mapper.AdditionalPaymentMapper;
|
|
|
import com.fire.admin.service.AdditionalPaymentService;
|
|
|
+import com.fire.admin.service.CustomerService;
|
|
|
import com.fire.admin.util.AliyunOSSUtil;
|
|
|
import com.fire.admin.util.SecurityUtil;
|
|
|
import com.fire.admin.vo.AdditionalPaymentVo;
|
|
|
import com.fire.common.exception.BaseException;
|
|
|
import com.fire.common.redis.RedisAmountScript;
|
|
|
import com.fire.dto.AdditionalPayment;
|
|
|
+import com.fire.dto.CustomerInfo;
|
|
|
import com.fire.dto.enums.Status;
|
|
|
import com.fire.utils.date.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -37,11 +39,13 @@ public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentM
|
|
|
|
|
|
private AliyunOSSUtil aliyunOSSUtil;
|
|
|
private RedisAmountScript redisAmountScript;
|
|
|
+ private CustomerService customerService;
|
|
|
|
|
|
@Autowired
|
|
|
- public AdditionalPaymentServiceImpl(AliyunOSSUtil aliyunOSSUtil, RedisAmountScript redisAmountScript) {
|
|
|
+ public AdditionalPaymentServiceImpl(AliyunOSSUtil aliyunOSSUtil, RedisAmountScript redisAmountScript,CustomerService customerService) {
|
|
|
this.aliyunOSSUtil = aliyunOSSUtil;
|
|
|
this.redisAmountScript = redisAmountScript;
|
|
|
+ this.customerService=customerService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -77,13 +81,20 @@ public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentM
|
|
|
* @Date: 2021/6/7 16:12
|
|
|
*/
|
|
|
private int additionalPayment(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
+
|
|
|
if (ObjectUtil.isNotEmpty(additionalPaymentDto.getType()) && ObjectUtil.isNotEmpty(additionalPaymentDto.getRelationId())) {
|
|
|
- AdditionalPayment payment = new AdditionalPayment();
|
|
|
- BeanUtil.copyProperties(additionalPaymentDto, payment);
|
|
|
- payment.setTime(DateUtils.strformatDatetime(LocalDateTime.now()));
|
|
|
- payment.setPayer(SecurityUtil.getUser().getUsername());
|
|
|
+ AdditionalPayment payment = AdditionalPayment.builder().cardNo(additionalPaymentDto.getCardNo())
|
|
|
+ .bankDeposit(additionalPaymentDto.getBankDeposit())
|
|
|
+ .account(additionalPaymentDto.getAccount())
|
|
|
+ .payer(SecurityUtil.getUser().getUsername())
|
|
|
+ .amount(additionalPaymentDto.getAmount().multiply(new BigDecimal(10000)).longValue())
|
|
|
+ .certificate(additionalPaymentDto.getCertificate())
|
|
|
+ .time(SecurityUtil.getUser().getUsername())
|
|
|
+ .paymentAccount(additionalPaymentDto.getPaymentAccount())
|
|
|
+ .relationId(additionalPaymentDto.getRelationId())
|
|
|
+ .distinguish(additionalPaymentDto.getDistinguish())
|
|
|
+ .undo(0).build();
|
|
|
return baseMapper.insert(payment);
|
|
|
-
|
|
|
} else {
|
|
|
// TODO 请求参数不合法抛异常
|
|
|
throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
|
|
@@ -126,4 +137,46 @@ public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentM
|
|
|
AdditionalPayment payment = AdditionalPayment.builder().id(additionalPaymentDto.getId()).certificate(additionalPaymentDto.getCertificate()).build();
|
|
|
baseMapper.updateById(payment);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: TODO 客户账单撤销
|
|
|
+ * @Param:
|
|
|
+ * @return: void
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/8 14:57
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String cancelAdditionalPayment(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
+
|
|
|
+ // TODO 客户的撤销
|
|
|
+ if(ObjectUtil.isNotEmpty(additionalPaymentDto.getRelationId()) && additionalPaymentDto.getType().equals("customer")){
|
|
|
+ additionalPaymentDto.setUndo(1);
|
|
|
+ // TODO 实例化对象
|
|
|
+ AdditionalPayment payment = this.formatAdditionalPaymentDto(additionalPaymentDto);
|
|
|
+ // TODO 修改记录的撤销状态
|
|
|
+ int count = baseMapper.updateById(payment);
|
|
|
+ // TODO 获取客户授信金额
|
|
|
+ CustomerInfo customerInfo = customerService.getcustomerOne(Long.parseLong(payment.getRelationId()));
|
|
|
+ if(count >0){
|
|
|
+ // TODO 撤销
|
|
|
+ Long amount = redisAmountScript.changeAmount(CUSTOMER_AMOUNT.key(), Long.parseLong(payment.getRelationId()), "sub", payment.getAmount(), customerInfo.getCreditAmount());
|
|
|
+ log.info("客户加款撤销。 客户编号为:【{}】 撤销金额为:【{}】 ,授信额度为:【{}】 剩余额度为:【{}】",payment.getRelationId(),additionalPaymentDto.getAmount(),new BigDecimal(customerInfo.getCreditAmount()).divide(new BigDecimal("10000"),2,BigDecimal.ROUND_DOWN),new BigDecimal(amount).divide(new BigDecimal("10000"),2,BigDecimal.ROUND_DOWN));
|
|
|
+ return payment.getRelationId().concat("_").concat(amount.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private AdditionalPayment formatAdditionalPaymentDto(AdditionalPaymentDto additionalPaymentDto){
|
|
|
+ return AdditionalPayment.builder()
|
|
|
+ .id(additionalPaymentDto.getId())
|
|
|
+ .relationId(additionalPaymentDto.getRelationId())
|
|
|
+ .amount(additionalPaymentDto.getAmount().multiply(new BigDecimal(10000)).longValue())
|
|
|
+ .undo(additionalPaymentDto.getUndo())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|