|
@@ -11,20 +11,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.account.entity.account.dto.AccountPaymentDto;
|
|
|
import com.fjhx.account.entity.account.dto.AccountRequestFundsSelectDto;
|
|
|
import com.fjhx.account.entity.account.enums.PaymentStatusEnum;
|
|
|
-import com.fjhx.account.entity.account.po.AccountManagement;
|
|
|
-import com.fjhx.account.entity.account.po.AccountPayment;
|
|
|
-import com.fjhx.account.entity.account.po.AccountRemainder;
|
|
|
-import com.fjhx.account.entity.account.po.AccountRunningWater;
|
|
|
+import com.fjhx.account.entity.account.po.*;
|
|
|
import com.fjhx.account.entity.account.vo.AccountPaymentVo;
|
|
|
import com.fjhx.account.entity.transaction.po.Transaction;
|
|
|
import com.fjhx.account.mapper.account.AccountPaymentMapper;
|
|
|
-import com.fjhx.account.service.account.AccountManagementService;
|
|
|
-import com.fjhx.account.service.account.AccountPaymentService;
|
|
|
-import com.fjhx.account.service.account.AccountRemainderService;
|
|
|
-import com.fjhx.account.service.account.AccountRunningWaterService;
|
|
|
+import com.fjhx.account.service.account.*;
|
|
|
import com.fjhx.account.service.transaction.TransactionService;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.service.corporation.CorporationService;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
@@ -33,6 +28,7 @@ import com.ruoyi.system.utils.UserUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -66,6 +62,8 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
|
|
|
@Autowired
|
|
|
private TransactionService transactionService;
|
|
|
+ @Autowired
|
|
|
+ private AccountPaymentRecordsService accountPaymentRecordsService;
|
|
|
|
|
|
@Override
|
|
|
public Page<AccountPaymentVo> getPage(AccountRequestFundsSelectDto dto) {
|
|
@@ -139,19 +137,19 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
AccountPayment AccountPayment = baseMapper.detail(id);
|
|
|
AccountPaymentVo result = BeanUtil.toBean(AccountPayment, AccountPaymentVo.class);
|
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(result.getAccountManagementId())){
|
|
|
+ if (ObjectUtil.isNotEmpty(result.getAccountManagementId())) {
|
|
|
//查询实际打款的付款账户名称;
|
|
|
AccountManagement accountManagement = accountManagementService.getById(result.getAccountManagementId());
|
|
|
- if (ObjectUtil.isNotEmpty(accountManagement)){
|
|
|
+ if (ObjectUtil.isNotEmpty(accountManagement)) {
|
|
|
result.setAccountManagementName(accountManagement.getName());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(result.getBusinessManagementId())){
|
|
|
+ if (ObjectUtil.isNotEmpty(result.getBusinessManagementId())) {
|
|
|
//查询业务中选中的付款账户名称;
|
|
|
AccountManagement accountManagement = accountManagementService.getById(result.getBusinessManagementId());
|
|
|
- if (ObjectUtil.isNotEmpty(accountManagement)){
|
|
|
+ if (ObjectUtil.isNotEmpty(accountManagement)) {
|
|
|
result.setBusinessManagementName(accountManagement.getName());
|
|
|
}
|
|
|
|
|
@@ -161,11 +159,13 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
|
|
|
/**
|
|
|
* 打款功能
|
|
|
+ *
|
|
|
* @param accountPaymentDto
|
|
|
*/
|
|
|
@Override
|
|
|
@DSTransactional
|
|
|
- public void add(AccountPaymentDto accountPaymentDto) {
|
|
|
+ public synchronized void add(AccountPaymentDto accountPaymentDto) {
|
|
|
+ Assert.notEmpty(accountPaymentDto.getId(), "打款id不能为空");
|
|
|
|
|
|
AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
|
|
|
.eq(AccountRemainder::getAccountManagementId, accountPaymentDto.getAccountManagementId())
|
|
@@ -181,9 +181,39 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
throw new ServiceException("账户余额不足");
|
|
|
}
|
|
|
|
|
|
- // TODO 只要发起就是已打款(后期可能要修改)
|
|
|
- accountPaymentDto.setStatus(PaymentStatusEnum.REJECT.getKey());
|
|
|
- updateById(accountPaymentDto);
|
|
|
+ //刷新打款信息
|
|
|
+ AccountPayment oldAccountPayment = this.getById(accountPaymentDto.getId());
|
|
|
+ //如果是未打款把已打款金额改成0(修复旧数据)
|
|
|
+ if (oldAccountPayment.getStatus().equals(PaymentStatusEnum.UNDER_REVIEW.getKey())) {
|
|
|
+ oldAccountPayment.setAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ BigDecimal add = oldAccountPayment.getAmount().add(accountPaymentDto.getAmount());
|
|
|
+ if (add.compareTo(oldAccountPayment.getIncomeAmount()) > 0) {
|
|
|
+ throw new ServiceException("打款金额不能大于待打款金额");
|
|
|
+ }
|
|
|
+ //修改打款状态
|
|
|
+ if (add.compareTo(oldAccountPayment.getIncomeAmount()) >= 0) {
|
|
|
+ oldAccountPayment.setStatus(PaymentStatusEnum.REJECT.getKey());
|
|
|
+ } else {
|
|
|
+ oldAccountPayment.setStatus(PaymentStatusEnum.PARTIAL.getKey());
|
|
|
+ }
|
|
|
+ //赋值已打款金额
|
|
|
+ oldAccountPayment.setAmount(add);
|
|
|
+ //赋值最后一次打款时间、
|
|
|
+ oldAccountPayment.setExpensesTime(accountPaymentDto.getExpensesTime());
|
|
|
+ updateById(oldAccountPayment);
|
|
|
+
|
|
|
+ //创建打款记录
|
|
|
+ AccountPaymentRecords accountPaymentRecords = new AccountPaymentRecords();
|
|
|
+ accountPaymentRecords.setAccountPaymentId(accountPaymentDto.getId());
|
|
|
+ accountPaymentRecords.setAmount(accountPaymentDto.getAmount());
|
|
|
+
|
|
|
+ accountPaymentRecords.setAccountManagementId(accountPaymentDto.getAccountManagementId());
|
|
|
+ accountPaymentRecords.setCurrency(accountPaymentDto.getCurrency());
|
|
|
+ accountPaymentRecords.setExpensesTime(accountPaymentDto.getExpensesTime());
|
|
|
+ accountPaymentRecords.setIsTransaction(accountPaymentDto.getIsTransaction());
|
|
|
+ accountPaymentRecords.setRemark(accountPaymentDto.getRemark());
|
|
|
+ accountPaymentRecordsService.save(accountPaymentRecords);
|
|
|
|
|
|
// 赋值变更金额
|
|
|
accountRemainder.setChangeRemainder(accountPaymentDto.getAmount());
|
|
@@ -194,10 +224,10 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
accountRemainderService.updateById(accountRemainder);
|
|
|
|
|
|
// 添加附件信息
|
|
|
- ObsFileUtil.saveFile(accountPaymentDto.getFileList(), accountPaymentDto.getId());
|
|
|
+ ObsFileUtil.saveFile(accountPaymentDto.getFileList(), accountPaymentRecords.getId());
|
|
|
|
|
|
// 添加资金流水表的数据
|
|
|
- addAccountRunningWater(accountPaymentDto);
|
|
|
+ addAccountRunningWater(accountPaymentDto, accountPaymentRecords);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -213,25 +243,27 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
/**
|
|
|
* 添加资金流水表的数据
|
|
|
*/
|
|
|
- private void addAccountRunningWater(AccountPaymentDto accountPaymentDto){
|
|
|
+ private void addAccountRunningWater(AccountPaymentDto accountPaymentDto, AccountPaymentRecords accountPaymentRecords) {
|
|
|
|
|
|
AccountRunningWater accountRunningWater = new AccountRunningWater();
|
|
|
- accountRunningWater.setAccountManagementId(accountPaymentDto.getAccountManagementId());
|
|
|
+ accountRunningWater.setAccountManagementId(accountPaymentRecords.getAccountManagementId());
|
|
|
//打款的状态都是支出
|
|
|
accountRunningWater.setStatus("20");
|
|
|
- accountRunningWater.setAmount(accountPaymentDto.getAmount());
|
|
|
- accountRunningWater.setCurrency(accountPaymentDto.getCurrency());
|
|
|
+ accountRunningWater.setAmount(accountPaymentRecords.getAmount());
|
|
|
+ accountRunningWater.setCurrency(accountPaymentRecords.getCurrency());
|
|
|
accountRunningWater.setOpeningBank(accountPaymentDto.getOpeningBank());
|
|
|
accountRunningWater.setAccountOpening(accountPaymentDto.getAccountOpening());
|
|
|
accountRunningWater.setName(accountPaymentDto.getName());
|
|
|
- accountRunningWater.setTransactionTime(accountPaymentDto.getExpensesTime());
|
|
|
- accountRunningWater.setRemarks(accountPaymentDto.getRemark());
|
|
|
+ accountRunningWater.setTransactionTime(accountPaymentRecords.getExpensesTime());
|
|
|
+ accountRunningWater.setRemarks(accountPaymentRecords.getRemark());
|
|
|
accountRunningWater.setBusinessId(accountPaymentDto.getId());
|
|
|
+ accountRunningWater.setAccountPaymentRecordsId(accountPaymentRecords.getId());
|
|
|
//添加流水类型
|
|
|
accountRunningWater.setType("10");
|
|
|
//赋值是否往来
|
|
|
accountRunningWater.setIsTransaction(accountPaymentDto.getIsTransaction());
|
|
|
accountRunningWater.setTransactionDeptId(accountPaymentDto.getTransactionDeptId());
|
|
|
+ accountRunningWater.setDeptType(accountRunningWater.getDeptType());
|
|
|
accountRunningWaterService.save(accountRunningWater);
|
|
|
|
|
|
//如果是往来
|
|
@@ -246,6 +278,14 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
|
|
|
transaction.setAccountId(accountRunningWater.getAccountManagementId());
|
|
|
transaction.setRemark(accountRunningWater.getRemarks());
|
|
|
transaction.setAccountRunningWaterId(accountRunningWater.getId());
|
|
|
+
|
|
|
+ Assert.notEmpty(accountPaymentDto.getDeptType(), "往来单位类型不能为空");
|
|
|
+ transaction.setDeptType(accountPaymentDto.getDeptType());
|
|
|
+
|
|
|
+ //赋值归属公司
|
|
|
+ AccountManagement accountManagement = accountManagementService.getById(accountPaymentRecords.getAccountManagementId());
|
|
|
+ transaction.setCorporationId(accountManagement.getCorporationId());
|
|
|
+
|
|
|
transactionService.save(transaction);
|
|
|
}
|
|
|
|