|
@@ -36,68 +36,69 @@ import java.util.List;
|
|
|
public class AccountServiceImpl extends AbstractService<Account> implements AccountService {
|
|
public class AccountServiceImpl extends AbstractService<Account> implements AccountService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private AccountMapper cAccountMapper;
|
|
private AccountMapper cAccountMapper;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private SubjectService subjectService;
|
|
private SubjectService subjectService;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private AccountFlowService accountFlowService;
|
|
private AccountFlowService accountFlowService;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private FlowService flowService;
|
|
private FlowService flowService;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void deal(AccountFlow accountFlow) {
|
|
public void deal(AccountFlow accountFlow) {
|
|
|
- if (accountFlow.getFlowType() == 4){
|
|
|
|
|
- //冻结
|
|
|
|
|
- cAccountMapper.dealFreeze(accountFlow.getAccountId(),accountFlow.getAmount());
|
|
|
|
|
- } else if (accountFlow.getFlowType() == 5){
|
|
|
|
|
- //解冻
|
|
|
|
|
- cAccountMapper.dealFreeze(accountFlow.getAccountId(),accountFlow.getAmount().negate());
|
|
|
|
|
|
|
+ if (accountFlow.getFlowType() == 4) {
|
|
|
|
|
+ // 冻结
|
|
|
|
|
+ cAccountMapper.dealFreeze(accountFlow.getAccountId(), accountFlow.getAmount());
|
|
|
|
|
+ } else if (accountFlow.getFlowType() == 5) {
|
|
|
|
|
+ // 解冻
|
|
|
|
|
+ cAccountMapper.dealFreeze(accountFlow.getAccountId(), accountFlow.getAmount().negate());
|
|
|
} else {
|
|
} else {
|
|
|
-
|
|
|
|
|
- if (accountFlow.getType() == 1){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (accountFlow.getType() == 1) {
|
|
|
if (BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.WITHDRAW
|
|
if (BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.WITHDRAW
|
|
|
- || BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.RECHARGE){
|
|
|
|
|
- int i = cAccountMapper.dealWithDayCutHasTotal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
|
|
|
|
|
- if (i == 0){
|
|
|
|
|
- cAccountMapper.dealHasTotal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
|
|
|
|
|
|
|
+ || BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.RECHARGE) {
|
|
|
|
|
+ int i = cAccountMapper.dealWithDayCutHasTotal(accountFlow.getAccountId(), accountFlow.getAmount().negate());
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ cAccountMapper.dealHasTotal(accountFlow.getAccountId(), accountFlow.getAmount().negate());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(),accountFlow.getAmount().negate());
|
|
|
|
|
- if (i == 0){
|
|
|
|
|
- cAccountMapper.deal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
|
|
|
|
|
|
|
+ int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(), accountFlow.getAmount().negate());
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ cAccountMapper.deal(accountFlow.getAccountId(), accountFlow.getAmount().negate());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.WITHDRAW
|
|
if (BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.WITHDRAW
|
|
|
- || BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.RECHARGE){
|
|
|
|
|
- int i = cAccountMapper.dealWithDayCutHasTotal(accountFlow.getAccountId(),accountFlow.getAmount());
|
|
|
|
|
- if (i == 0){
|
|
|
|
|
- cAccountMapper.dealHasTotal(accountFlow.getAccountId(),accountFlow.getAmount());
|
|
|
|
|
|
|
+ || BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.RECHARGE) {
|
|
|
|
|
+ int i = cAccountMapper.dealWithDayCutHasTotal(accountFlow.getAccountId(), accountFlow.getAmount());
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ cAccountMapper.dealHasTotal(accountFlow.getAccountId(), accountFlow.getAmount());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(),accountFlow.getAmount());
|
|
|
|
|
- if (i == 0){
|
|
|
|
|
- cAccountMapper.deal(accountFlow.getAccountId(),accountFlow.getAmount());
|
|
|
|
|
|
|
+ int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(), accountFlow.getAmount());
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ cAccountMapper.deal(accountFlow.getAccountId(), accountFlow.getAmount());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ accountFlow.setCreateTime(new Date());
|
|
|
accountFlowService.save(accountFlow);
|
|
accountFlowService.save(accountFlow);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void innerRecharge(RechargeForm form) {
|
|
public void innerRecharge(RechargeForm form) {
|
|
|
- SnowflakeGenerator snowflake =new SnowflakeGenerator();
|
|
|
|
|
|
|
+ SnowflakeGenerator snowflake = new SnowflakeGenerator();
|
|
|
String bizNo = snowflake.next().toString();
|
|
String bizNo = snowflake.next().toString();
|
|
|
Date today = DateUtil.date();
|
|
Date today = DateUtil.date();
|
|
|
Account innerAccount = findById(form.getInnerAccountId());
|
|
Account innerAccount = findById(form.getInnerAccountId());
|
|
|
- if (innerAccount == null){
|
|
|
|
|
|
|
+ if (innerAccount == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
Account account = findById(form.getAccountId());
|
|
Account account = findById(form.getAccountId());
|
|
|
- if (account == null){
|
|
|
|
|
|
|
+ if (account == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
Flow flow = Flow.builder().amount(form.getAmount()).bizType(1001).createUser(
|
|
Flow flow = Flow.builder().amount(form.getAmount()).bizType(1001).createUser(
|
|
@@ -107,78 +108,78 @@ public class AccountServiceImpl extends AbstractService<Account> implements Acco
|
|
|
.type(1)
|
|
.type(1)
|
|
|
.build();
|
|
.build();
|
|
|
flowService.saveUseGeneratedKeys(flow);
|
|
flowService.saveUseGeneratedKeys(flow);
|
|
|
- //借 :资金应收-渠道款-银行xx元 内部户1(资产类:借方账户)+钱
|
|
|
|
|
|
|
+ // 借 :资金应收-渠道款-银行xx元 内部户1(资产类:借方账户)+钱
|
|
|
deal(AccountFlow.builder().accountId(form.getInnerAccountId()).amount(flow.getAmount())
|
|
deal(AccountFlow.builder().accountId(form.getInnerAccountId()).amount(flow.getAmount())
|
|
|
.bizId(flow.getBizNo()).aliases(innerAccount.getAliases()).transTime(today)
|
|
.bizId(flow.getBizNo()).aliases(innerAccount.getAliases()).transTime(today)
|
|
|
.balance(innerAccount.getBalance().add(flow.getAmount()))
|
|
.balance(innerAccount.getBalance().add(flow.getAmount()))
|
|
|
.freezeAmount(innerAccount.getFreezeAmount())
|
|
.freezeAmount(innerAccount.getFreezeAmount())
|
|
|
.flowType(1).type(2).bizType(1001).flowId(flow.getId()).build());
|
|
.flowType(1).type(2).bizType(1001).flowId(flow.getId()).build());
|
|
|
- //贷 :客户资金账户xx元 客户账号(负债类:贷方账户)+钱
|
|
|
|
|
|
|
+ // 贷 :客户资金账户xx元 客户账号(负债类:贷方账户)+钱
|
|
|
deal(AccountFlow.builder().accountId(form.getAccountId()).amount(flow.getAmount())
|
|
deal(AccountFlow.builder().accountId(form.getAccountId()).amount(flow.getAmount())
|
|
|
.bizId(flow.getBizNo()).aliases(account.getAliases()).transTime(today)
|
|
.bizId(flow.getBizNo()).aliases(account.getAliases()).transTime(today)
|
|
|
.balance(account.getBalance().add(flow.getAmount()))
|
|
.balance(account.getBalance().add(flow.getAmount()))
|
|
|
.freezeAmount(account.getFreezeAmount())
|
|
.freezeAmount(account.getFreezeAmount())
|
|
|
.flowType(1).type(2).bizType(1001).flowId(flow.getId()).build());
|
|
.flowType(1).type(2).bizType(1001).flowId(flow.getId()).build());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void innerCarry() {
|
|
public void innerCarry() {
|
|
|
- SnowflakeGenerator snowflake =new SnowflakeGenerator();
|
|
|
|
|
|
|
+ SnowflakeGenerator snowflake = new SnowflakeGenerator();
|
|
|
String bizNo = snowflake.next().toString();
|
|
String bizNo = snowflake.next().toString();
|
|
|
Date today = DateUtil.date();
|
|
Date today = DateUtil.date();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition c = new Condition(Subject.class);
|
|
Condition c = new Condition(Subject.class);
|
|
|
- c.createCriteria().andEqualTo("parentId",3).andEqualTo("leaf",1);
|
|
|
|
|
|
|
+ c.createCriteria().andEqualTo("parentId", 3).andEqualTo("leaf", 1);
|
|
|
List<Subject> subjectList = subjectService.findByCondition(c);
|
|
List<Subject> subjectList = subjectService.findByCondition(c);
|
|
|
- if (CollUtil.isEmpty(subjectList)){
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(subjectList)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
Account innerAccount = findById(MyConstants.INNER_PROFIT);
|
|
Account innerAccount = findById(MyConstants.INNER_PROFIT);
|
|
|
- if (innerAccount == null){
|
|
|
|
|
|
|
+ if (innerAccount == null) {
|
|
|
log.error("[日切-结转]本年利润账户未找到");
|
|
log.error("[日切-结转]本年利润账户未找到");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- for (Subject subject:subjectList) {
|
|
|
|
|
- Account account = findBy("aliases",subject.getAliases());
|
|
|
|
|
- if (account == null){
|
|
|
|
|
- log.error("[日切-结转]别名为"+subject.getAliases()+"的账户未找到。");
|
|
|
|
|
|
|
+ for (Subject subject : subjectList) {
|
|
|
|
|
+ Account account = findBy("aliases", subject.getAliases());
|
|
|
|
|
+ if (account == null) {
|
|
|
|
|
+ log.error("[日切-结转]别名为" + subject.getAliases() + "的账户未找到。");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (account.getBeforeDayBalance().compareTo(BigDecimal.ZERO) == 0){
|
|
|
|
|
|
|
+ if (account.getBeforeDayBalance().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- BigDecimal amount = account.getBeforeDayBalance();
|
|
|
|
|
- if (!DateUtil.isSameDay(account.getBeforeDayTime(),DateUtil.date())){
|
|
|
|
|
|
|
+ BigDecimal amount = account.getBeforeDayBalance();
|
|
|
|
|
+ if (!DateUtil.isSameDay(account.getBeforeDayTime(), DateUtil.date())) {
|
|
|
amount = account.getBalance();
|
|
amount = account.getBalance();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- //借方结转
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 借方结转
|
|
|
/**
|
|
/**
|
|
|
* 借方结转
|
|
* 借方结转
|
|
|
* 借:本年利润(贷) -500元
|
|
* 借:本年利润(贷) -500元
|
|
|
* 贷:专家提成(借) -500元
|
|
* 贷:专家提成(借) -500元
|
|
|
*/
|
|
*/
|
|
|
- if (StrUtil.equals("D",subject.getDirection())){
|
|
|
|
|
|
|
+ if (StrUtil.equals("D", subject.getDirection())) {
|
|
|
Flow flow = Flow.builder().amount(amount).bizType(6001).createUser("sys")
|
|
Flow flow = Flow.builder().amount(amount).bizType(6001).createUser("sys")
|
|
|
.bizNo(bizNo).createTime(today).updateTime(today).transTime(today)
|
|
.bizNo(bizNo).createTime(today).updateTime(today).transTime(today)
|
|
|
.debitAccount(innerAccount.getId()).creditAccount(account.getId())
|
|
.debitAccount(innerAccount.getId()).creditAccount(account.getId())
|
|
|
.type(8)
|
|
.type(8)
|
|
|
.build();
|
|
.build();
|
|
|
flowService.saveUseGeneratedKeys(flow);
|
|
flowService.saveUseGeneratedKeys(flow);
|
|
|
- //借:本年利润(贷) -500元
|
|
|
|
|
|
|
+ // 借:本年利润(贷) -500元
|
|
|
deal(AccountFlow.builder().accountId(innerAccount.getId()).amount(flow.getAmount())
|
|
deal(AccountFlow.builder().accountId(innerAccount.getId()).amount(flow.getAmount())
|
|
|
.bizId(flow.getBizNo()).aliases(innerAccount.getAliases())
|
|
.bizId(flow.getBizNo()).aliases(innerAccount.getAliases())
|
|
|
.balance(innerAccount.getBalance().subtract(flow.getAmount()))
|
|
.balance(innerAccount.getBalance().subtract(flow.getAmount()))
|
|
|
.freezeAmount(innerAccount.getFreezeAmount()).transTime(today)
|
|
.freezeAmount(innerAccount.getFreezeAmount()).transTime(today)
|
|
|
.flowType(8).type(1).bizType(6001).flowId(flow.getId()).build());
|
|
.flowType(8).type(1).bizType(6001).flowId(flow.getId()).build());
|
|
|
- //贷:专家提成(借) -500元
|
|
|
|
|
|
|
+ // 贷:专家提成(借) -500元
|
|
|
deal(AccountFlow.builder().accountId(account.getId()).amount(flow.getAmount())
|
|
deal(AccountFlow.builder().accountId(account.getId()).amount(flow.getAmount())
|
|
|
.bizId(flow.getBizNo()).aliases(account.getAliases())
|
|
.bizId(flow.getBizNo()).aliases(account.getAliases())
|
|
|
.balance(account.getBalance().subtract(flow.getAmount()))
|
|
.balance(account.getBalance().subtract(flow.getAmount()))
|
|
|
.freezeAmount(account.getFreezeAmount()).transTime(today)
|
|
.freezeAmount(account.getFreezeAmount()).transTime(today)
|
|
|
.flowType(8).type(1).bizType(6001).flowId(flow.getId()).build());
|
|
.flowType(8).type(1).bizType(6001).flowId(flow.getId()).build());
|
|
|
} else {
|
|
} else {
|
|
|
- //贷方结转
|
|
|
|
|
|
|
+ // 贷方结转
|
|
|
/**
|
|
/**
|
|
|
* 贷方结转
|
|
* 贷方结转
|
|
|
* 借:主营业务收入 (贷) -500元
|
|
* 借:主营业务收入 (贷) -500元
|
|
@@ -190,65 +191,65 @@ public class AccountServiceImpl extends AbstractService<Account> implements Acco
|
|
|
.type(9)
|
|
.type(9)
|
|
|
.build();
|
|
.build();
|
|
|
flowService.saveUseGeneratedKeys(flow);
|
|
flowService.saveUseGeneratedKeys(flow);
|
|
|
- //借:主营业务收入 (贷) -500元
|
|
|
|
|
|
|
+ // 借:主营业务收入 (贷) -500元
|
|
|
deal(AccountFlow.builder().accountId(account.getId()).amount(flow.getAmount())
|
|
deal(AccountFlow.builder().accountId(account.getId()).amount(flow.getAmount())
|
|
|
.bizId(flow.getBizNo()).aliases(innerAccount.getAliases()).transTime(today)
|
|
.bizId(flow.getBizNo()).aliases(innerAccount.getAliases()).transTime(today)
|
|
|
.balance(innerAccount.getBalance().subtract(flow.getAmount()))
|
|
.balance(innerAccount.getBalance().subtract(flow.getAmount()))
|
|
|
.freezeAmount(innerAccount.getFreezeAmount())
|
|
.freezeAmount(innerAccount.getFreezeAmount())
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
.flowType(9).type(1).bizType(6002).flowId(flow.getId()).build());
|
|
.flowType(9).type(1).bizType(6002).flowId(flow.getId()).build());
|
|
|
- //贷:本年利润 (贷) +500元
|
|
|
|
|
|
|
+ // 贷:本年利润 (贷) +500元
|
|
|
deal(AccountFlow.builder().accountId(innerAccount.getId()).amount(flow.getAmount())
|
|
deal(AccountFlow.builder().accountId(innerAccount.getId()).amount(flow.getAmount())
|
|
|
.bizId(flow.getBizNo()).aliases(account.getAliases()).transTime(today)
|
|
.bizId(flow.getBizNo()).aliases(account.getAliases()).transTime(today)
|
|
|
.balance(account.getBalance().add(flow.getAmount()))
|
|
.balance(account.getBalance().add(flow.getAmount()))
|
|
|
.freezeAmount(account.getFreezeAmount())
|
|
.freezeAmount(account.getFreezeAmount())
|
|
|
.flowType(9).type(2).bizType(6002).flowId(flow.getId()).build());
|
|
.flowType(9).type(2).bizType(6002).flowId(flow.getId()).build());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public BigDecimal sumInit(String aliases) {
|
|
public BigDecimal sumInit(String aliases) {
|
|
|
- //查询当日所有初始上日余额
|
|
|
|
|
- BigDecimal today = cAccountMapper.sumTodayInit(aliases);
|
|
|
|
|
- if (today == null){
|
|
|
|
|
|
|
+ // 查询当日所有初始上日余额
|
|
|
|
|
+ BigDecimal today = cAccountMapper.sumTodayInit(aliases);
|
|
|
|
|
+ if (today == null) {
|
|
|
today = BigDecimal.ZERO;
|
|
today = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
- //查询非当日所有初始上日余额
|
|
|
|
|
- BigDecimal befor = cAccountMapper.sumBeforInit(aliases);
|
|
|
|
|
- if (befor == null){
|
|
|
|
|
|
|
+ // 查询非当日所有初始上日余额
|
|
|
|
|
+ BigDecimal befor = cAccountMapper.sumBeforInit(aliases);
|
|
|
|
|
+ if (befor == null) {
|
|
|
befor = BigDecimal.ZERO;
|
|
befor = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
return today.add(befor);
|
|
return today.add(befor);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public BigDecimal sumEnd(String aliases) {
|
|
public BigDecimal sumEnd(String aliases) {
|
|
|
-
|
|
|
|
|
- BigDecimal today = cAccountMapper.sumTodayEnd(aliases);
|
|
|
|
|
- if (today == null){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal today = cAccountMapper.sumTodayEnd(aliases);
|
|
|
|
|
+ if (today == null) {
|
|
|
today = BigDecimal.ZERO;
|
|
today = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
- //查询非当日所有初始上日余额
|
|
|
|
|
- BigDecimal befor = cAccountMapper.sumBeforEnd(aliases);
|
|
|
|
|
- if (befor == null){
|
|
|
|
|
|
|
+ // 查询非当日所有初始上日余额
|
|
|
|
|
+ BigDecimal befor = cAccountMapper.sumBeforEnd(aliases);
|
|
|
|
|
+ if (befor == null) {
|
|
|
befor = BigDecimal.ZERO;
|
|
befor = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
return today.add(befor);
|
|
return today.add(befor);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Account getAccount(Long userId, int type) {
|
|
public Account getAccount(Long userId, int type) {
|
|
|
Condition c = new Condition(Account.class);
|
|
Condition c = new Condition(Account.class);
|
|
|
- c.createCriteria().andEqualTo("userId",userId)
|
|
|
|
|
- .andEqualTo("bizType",type);
|
|
|
|
|
|
|
+ c.createCriteria().andEqualTo("userId", userId)
|
|
|
|
|
+ .andEqualTo("bizType", type);
|
|
|
List<Account> accounts = findByCondition(c);
|
|
List<Account> accounts = findByCondition(c);
|
|
|
- if (CollUtil.isEmpty(accounts)){
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(accounts)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
return accounts.get(0);
|
|
return accounts.get(0);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|