|
@@ -1,29 +1,38 @@
|
|
|
package com.txz.cif.service.impl;
|
|
package com.txz.cif.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.txz.cif.configurer.LocalUtil;
|
|
import com.txz.cif.configurer.LocalUtil;
|
|
|
import com.txz.cif.constants.MyConstants;
|
|
import com.txz.cif.constants.MyConstants;
|
|
|
|
|
+import com.txz.cif.core.AbstractService;
|
|
|
import com.txz.cif.core.ServiceException;
|
|
import com.txz.cif.core.ServiceException;
|
|
|
import com.txz.cif.dao.FlowMapper;
|
|
import com.txz.cif.dao.FlowMapper;
|
|
|
import com.txz.cif.dto.Result;
|
|
import com.txz.cif.dto.Result;
|
|
|
|
|
+import com.txz.cif.dubbo.client.OperatingConfigDubboServiceClient;
|
|
|
import com.txz.cif.enums.AccountFreezdTypeEnum;
|
|
import com.txz.cif.enums.AccountFreezdTypeEnum;
|
|
|
import com.txz.cif.enums.BizTypeEnum;
|
|
import com.txz.cif.enums.BizTypeEnum;
|
|
|
import com.txz.cif.model.*;
|
|
import com.txz.cif.model.*;
|
|
|
-import com.txz.cif.param.*;
|
|
|
|
|
|
|
+import com.txz.cif.param.PayParam;
|
|
|
|
|
+import com.txz.cif.param.RechargeParam;
|
|
|
|
|
+import com.txz.cif.param.RefundParam;
|
|
|
|
|
+import com.txz.cif.param.WithdrawParam;
|
|
|
import com.txz.cif.service.AccountFlowService;
|
|
import com.txz.cif.service.AccountFlowService;
|
|
|
import com.txz.cif.service.AccountFreezdService;
|
|
import com.txz.cif.service.AccountFreezdService;
|
|
|
import com.txz.cif.service.AccountService;
|
|
import com.txz.cif.service.AccountService;
|
|
|
import com.txz.cif.service.FlowService;
|
|
import com.txz.cif.service.FlowService;
|
|
|
-import com.txz.cif.core.AbstractService;
|
|
|
|
|
import com.txz.cif.web.para.FreezdParam;
|
|
import com.txz.cif.web.para.FreezdParam;
|
|
|
|
|
+import com.txz.operating.dto.ConfigDTO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by CodeGenerator on 2022/11/02.
|
|
* Created by CodeGenerator on 2022/11/02.
|
|
@@ -44,6 +53,9 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
@Resource
|
|
@Resource
|
|
|
private AccountFreezdService accountFreezdService;
|
|
private AccountFreezdService accountFreezdService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private OperatingConfigDubboServiceClient operatingConfigDubboServiceClient;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Result freeze(FreezdParam param) {
|
|
public Result freeze(FreezdParam param) {
|
|
|
try {
|
|
try {
|
|
@@ -66,9 +78,19 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
.bizId(flow.getBizId()).aliases(account.getAliases()).transTime(param.getTransTime()).userId(flow.getUserId())
|
|
.bizId(flow.getBizId()).aliases(account.getAliases()).transTime(param.getTransTime()).userId(flow.getUserId())
|
|
|
.bizNo(flow.getBizNo()).balance(account.getBalance()).freezeAmount(account.getFreezeAmount().add(param.getAmount()))
|
|
.bizNo(flow.getBizNo()).balance(account.getBalance()).freezeAmount(account.getFreezeAmount().add(param.getAmount()))
|
|
|
.flowType(4).type(1).bizType(param.getBizType()).flowId(flow.getId()).build());
|
|
.flowType(4).type(1).bizType(param.getBizType()).flowId(flow.getId()).build());
|
|
|
- AccountFreezd freezd = AccountFreezd.builder().accountId(account.getId()).bizId(flow.getId())
|
|
|
|
|
- .amount(param.getAmount()).createTime(today).unfreezeAmount(BigDecimal.ZERO).type(param.getType())
|
|
|
|
|
- .updateTime(today).status(1).build();
|
|
|
|
|
|
|
+ AccountFreezd freezd = AccountFreezd
|
|
|
|
|
+ .builder()
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
|
|
+ .accountId(account.getId())
|
|
|
|
|
+ .bizId(flow.getId())
|
|
|
|
|
+ .amount(param.getAmount())
|
|
|
|
|
+ .createTime(today)
|
|
|
|
|
+ .unfreezeAmount(BigDecimal.ZERO)
|
|
|
|
|
+ .type(param.getType())
|
|
|
|
|
+ .updateTime(today)
|
|
|
|
|
+ .status(1)
|
|
|
|
|
+ .unfreezeTime(param.getUnfreezeTime())
|
|
|
|
|
+ .build();
|
|
|
accountFreezdService.saveUseGeneratedKeys(freezd);
|
|
accountFreezdService.saveUseGeneratedKeys(freezd);
|
|
|
return Result.genSuccessResult(freezd.getId());
|
|
return Result.genSuccessResult(freezd.getId());
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -221,17 +243,43 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
|
|
|
|
|
// 冻结金额
|
|
// 冻结金额
|
|
|
BigDecimal sumFreezdAmount = accountFreezdService.sumFreezdForRefundByUserId(param.getUserId());
|
|
BigDecimal sumFreezdAmount = accountFreezdService.sumFreezdForRefundByUserId(param.getUserId());
|
|
|
- if (account.getBalance().subtract(account.getFreezeAmount()).add(sumFreezdAmount).compareTo(param.getAmount()) == -1) {
|
|
|
|
|
- return Result.genFailResult(LocalUtil.get("account.not.found"));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (sumFreezdAmount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
+ if (account.getBalance().subtract(account.getFreezeAmount()).add(sumFreezdAmount).compareTo(param.getAmount()) == -1) {
|
|
|
|
|
+ return Result.genFailResult(LocalUtil.get("account.not.found"));
|
|
|
|
|
+ }
|
|
|
|
|
+ Condition c = new Condition(AccountFreezd.class);
|
|
|
|
|
+ c.createCriteria()
|
|
|
|
|
+ .andEqualTo("type", AccountFreezdTypeEnum.REFUND_FREEZE)
|
|
|
|
|
+ .andIn("status", CollUtil.newArrayList(1, 2))
|
|
|
|
|
+ .andEqualTo("userId", param.getUserId())
|
|
|
|
|
+ ;
|
|
|
|
|
+ c.setOrderByClause("create_time");
|
|
|
|
|
+ List<AccountFreezd> accounts = accountFreezdService.findByCondition(c);
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(accounts)) {
|
|
|
|
|
+ BigDecimal totalAmount = param.getAmount();
|
|
|
|
|
+ for (AccountFreezd accountFreezd : accounts) {
|
|
|
|
|
+ totalAmount = partialThaw(accountFreezd.getId(), totalAmount);
|
|
|
|
|
+ if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 借:个人账户钱包(贷) -500元
|
|
// 借:个人账户钱包(贷) -500元
|
|
|
// 贷:平台主营收入(贷) +500元
|
|
// 贷:平台主营收入(贷) +500元
|
|
|
Date today = DateUtil.date();
|
|
Date today = DateUtil.date();
|
|
|
- Flow flow = Flow.builder().amount(param.getAmount()).bizType(param.getBizType())
|
|
|
|
|
|
|
+ Flow flow = Flow.builder().amount(param.getAmount())
|
|
|
|
|
+ .bizType(param.getBizType())
|
|
|
.userId(param.getUserId())
|
|
.userId(param.getUserId())
|
|
|
- .bizNo(param.getBizNo()).createTime(today).updateTime(today).transTime(param.getTransTime())
|
|
|
|
|
- .debitAccount(account.getId()).creditAccount(MyConstants.INNER_INCOME).createUser(param.getUserId() + "")
|
|
|
|
|
|
|
+ .bizNo(param.getBizNo())
|
|
|
|
|
+ .createTime(today)
|
|
|
|
|
+ .updateTime(today)
|
|
|
|
|
+ .transTime(param.getTransTime())
|
|
|
|
|
+ .debitAccount(account.getId())
|
|
|
|
|
+ .creditAccount(MyConstants.INNER_INCOME)
|
|
|
|
|
+ .createUser(param.getUserId() + "")
|
|
|
.bizId(param.getBizId()).type(6)
|
|
.bizId(param.getBizId()).type(6)
|
|
|
.build();
|
|
.build();
|
|
|
saveUseGeneratedKeys(flow);
|
|
saveUseGeneratedKeys(flow);
|
|
@@ -271,7 +319,13 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
.debitAccount(MyConstants.INNER_REFUND).creditAccount(account.getId())
|
|
.debitAccount(MyConstants.INNER_REFUND).creditAccount(account.getId())
|
|
|
.bizId(param.getBizId()).type(9).createUser(param.getUserId() + "")
|
|
.bizId(param.getBizId()).type(9).createUser(param.getUserId() + "")
|
|
|
.build();
|
|
.build();
|
|
|
|
|
+
|
|
|
|
|
+ com.txz.operating.result.Result<ConfigDTO> refundFreezeTime = operatingConfigDubboServiceClient.getConfigByCode("refund_freeze_time");
|
|
|
|
|
+ int days = Integer.parseInt(refundFreezeTime.getData().getValueInfo());
|
|
|
|
|
+ Date unfreezeTime = DateUtil.offsetDay(new Date(), days);
|
|
|
|
|
+
|
|
|
freeze(FreezdParam.builder()
|
|
freeze(FreezdParam.builder()
|
|
|
|
|
+ .userId(param.getUserId())
|
|
|
.accountType(account.getType())
|
|
.accountType(account.getType())
|
|
|
.amount(param.getAmount())
|
|
.amount(param.getAmount())
|
|
|
.bizType(param.getBizType())
|
|
.bizType(param.getBizType())
|
|
@@ -280,6 +334,7 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
.transTime(param.getTransTime())
|
|
.transTime(param.getTransTime())
|
|
|
.userId(param.getUserId())
|
|
.userId(param.getUserId())
|
|
|
.type(AccountFreezdTypeEnum.REFUND_FREEZE)
|
|
.type(AccountFreezdTypeEnum.REFUND_FREEZE)
|
|
|
|
|
+ .unfreezeTime(unfreezeTime)
|
|
|
.build()
|
|
.build()
|
|
|
);
|
|
);
|
|
|
saveUseGeneratedKeys(flow);
|
|
saveUseGeneratedKeys(flow);
|
|
@@ -311,11 +366,18 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Date today = DateUtil.date();
|
|
Date today = DateUtil.date();
|
|
|
- Flow flow = Flow.builder().amount(param.getAmount()).bizType(param.getBizType())
|
|
|
|
|
|
|
+ Flow flow = Flow.builder()
|
|
|
|
|
+ .amount(param.getAmount())
|
|
|
|
|
+ .bizType(param.getBizType())
|
|
|
.userId(param.getUserId())
|
|
.userId(param.getUserId())
|
|
|
- .bizNo(param.getBizNo()).createTime(today).updateTime(today).transTime(param.getTransTime())
|
|
|
|
|
- .creditAccount(MyConstants.INNER_CAPITAL).debitAccount(account.getId())
|
|
|
|
|
- .bizId(param.getBizId()).type(3)
|
|
|
|
|
|
|
+ .bizNo(param.getBizNo())
|
|
|
|
|
+ .createTime(today)
|
|
|
|
|
+ .updateTime(today)
|
|
|
|
|
+ .transTime(param.getTransTime())
|
|
|
|
|
+ .creditAccount(MyConstants.INNER_CAPITAL)
|
|
|
|
|
+ .debitAccount(account.getId())
|
|
|
|
|
+ .bizId(param.getBizId())
|
|
|
|
|
+ .type(3)
|
|
|
.build();
|
|
.build();
|
|
|
saveUseGeneratedKeys(flow);
|
|
saveUseGeneratedKeys(flow);
|
|
|
|
|
|
|
@@ -371,5 +433,40 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
|
|
|
return cFlowMapper.countByUserId(map);
|
|
return cFlowMapper.countByUserId(map);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BigDecimal partialThaw(Long id, BigDecimal partialThawAmount) {
|
|
|
|
|
+ AccountFreezd accountFreezd = accountFreezdService.findById(id);
|
|
|
|
|
+ // 可用冻结金额
|
|
|
|
|
+ BigDecimal canUseAmount = accountFreezd.getAmount().subtract(accountFreezd.getUnfreezeAmount());
|
|
|
|
|
+ // 可用金额小于等于总金额
|
|
|
|
|
+ if (canUseAmount.compareTo(partialThawAmount) != 1) {
|
|
|
|
|
+ accountFreezd.setStatus(3);
|
|
|
|
|
+ accountFreezd.setUnfreezeAmount(accountFreezd.getAmount());
|
|
|
|
|
+ accountFreezd.setUpdateTime(new Date());
|
|
|
|
|
+ accountFreezdService.update(accountFreezd);
|
|
|
|
|
+ return partialThawAmount.subtract(canUseAmount);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ accountFreezd.setStatus(2);
|
|
|
|
|
+ accountFreezd.setUnfreezeAmount(accountFreezd.getUnfreezeAmount().add(partialThawAmount));
|
|
|
|
|
+ accountFreezd.setUpdateTime(new Date());
|
|
|
|
|
+ accountFreezdService.update(accountFreezd);
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void unfreezeRefund() {
|
|
|
|
|
+ Condition c = new Condition(AccountFreezd.class);
|
|
|
|
|
+ c.createCriteria()
|
|
|
|
|
+ .andEqualTo("type", AccountFreezdTypeEnum.REFUND_FREEZE)
|
|
|
|
|
+ .andIn("status", CollUtil.newArrayList(1, 2))
|
|
|
|
|
+ .andLessThanOrEqualTo("unfreezeTime", new Date())
|
|
|
|
|
+ ;
|
|
|
|
|
+ List<AccountFreezd> accounts = accountFreezdService.findByCondition(c);
|
|
|
|
|
+ for (AccountFreezd accountFreezd : accounts) {
|
|
|
|
|
+ unFreeze(accountFreezd.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|