Parcourir la source

多次打款问题处理

yzc il y a 1 an
Parent
commit
bf3922838e

+ 22 - 2
hx-account/src/main/java/com/fjhx/account/entity/account/po/AccountPaymentRecords.java

@@ -6,6 +6,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * <p>
@@ -26,9 +27,28 @@ public class AccountPaymentRecords extends BasePo {
     private Long accountPaymentId;
 
     /**
+     * 打款账户id
+     */
+    private Long accountManagementId;
+    /**
+     * 币种
+     */
+    private String currency;
+    /**
      * 打款金额
      */
-    private BigDecimal
-            amount;
+    private BigDecimal amount;
+    /**
+     * 打款时间
+     */
+    private Date expensesTime;
+    /**
+     * 是否往来
+     */
+    private Integer isTransaction;
+    /**
+     * 摘要
+     */
+    private String remark;
 
 }

+ 5 - 0
hx-account/src/main/java/com/fjhx/account/entity/account/po/AccountRunningWater.java

@@ -105,4 +105,9 @@ public class AccountRunningWater extends BasePo {
     @TableField(exist = false)
     private Integer count;
 
+    /**
+     * 打款记录id
+     */
+    private Long accountPaymentRecordsId;
+
 }

+ 21 - 12
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountPaymentServiceImpl.java

@@ -136,19 +136,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());
             }
 
@@ -158,6 +158,7 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
 
     /**
      * 打款功能
+     *
      * @param accountPaymentDto
      */
     @Override
@@ -197,12 +198,19 @@ public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper,
         }
         //赋值已打款金额
         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.setRemark(accountPaymentDto.getRemark());
         accountPaymentRecordsService.save(accountPaymentRecords);
 
         // 赋值变更金额
@@ -214,10 +222,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
@@ -233,20 +241,21 @@ 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");
         accountRunningWaterService.save(accountRunningWater);

+ 37 - 23
hx-account/src/main/java/com/fjhx/account/service/write/impl/WriteOffRecordsServiceImpl.java

@@ -5,17 +5,13 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-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.write.dto.WriteOffRecordsDto;
 import com.fjhx.account.entity.write.dto.WriteOffRecordsSelectDto;
 import com.fjhx.account.entity.write.po.WriteOffRecords;
 import com.fjhx.account.entity.write.vo.WriteOffRecordsVo;
 import com.fjhx.account.mapper.write.WriteOffRecordsMapper;
-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.write.WriteOffRecordsService;
 import com.fjhx.common.service.corporation.CorporationService;
 import com.fjhx.common.utils.Assert;
@@ -26,6 +22,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;
 
 
@@ -47,6 +44,10 @@ public class WriteOffRecordsServiceImpl extends ServiceImpl<WriteOffRecordsMappe
     private AccountRemainderService accountRemainderService;
     @Autowired
     private AccountRunningWaterService accountRunningWaterService;
+    @Autowired
+    private AccountPaymentRecordsService accountPaymentRecordsService;
+    @Autowired
+    private AccountManagementService accountManagementService;
 
     @Override
     public Page<WriteOffRecordsVo> getPage(WriteOffRecordsSelectDto dto) {
@@ -73,28 +74,41 @@ public class WriteOffRecordsServiceImpl extends ServiceImpl<WriteOffRecordsMappe
         Assert.notEmpty(accountPayment, "查询不到打款信息");
         //修改打款状态为未打款
         accountPayment.setStatus("20");
+        //清空已打款金额
+        accountPayment.setAmount(BigDecimal.ZERO);
         accountPaymentService.updateById(accountPayment);
-        //清理历史附件
-        ObsFileUtil.removeFile(accountPayment.getId());
-        //赋值之前的打款时间
+
+        //赋值最后一次打款时间
         writeOffRecordsDto.setAccountPaymentDate(accountPayment.getExpensesTime());
         this.save(writeOffRecordsDto);
-        //根据币种回滚余额
-        AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
-                .eq(AccountRemainder::getAccountManagementId, accountPayment.getAccountManagementId())
-                .eq(AccountRemainder::getCurrency, accountPayment.getCurrency()));
-        // 如果不存在这条数据则返回币种不存在
-        if (ObjectUtil.isEmpty(accountRemainder)) {
-            throw new ServiceException("该账户不存在此币种,请前往资金账户添加");
-        }
-        accountRemainderService.update(q -> q
-                .eq(AccountRemainder::getId, accountRemainder.getId())
-                .setSql("remainder = remainder + " + accountPayment.getAmount())
+
+        List<AccountPaymentRecords> accountPaymentRecordsList = accountPaymentRecordsService.list(
+                q -> q.eq(AccountPaymentRecords::getAccountPaymentId, accountPayment.getId())
         );
+        for (AccountPaymentRecords accountPaymentRecords : accountPaymentRecordsList) {
+            //清理历史附件
+            ObsFileUtil.removeFile(accountPaymentRecords.getId());
+            AccountManagement accountManagement = accountManagementService.getById(accountPaymentRecords.getAccountManagementId());
+            if (ObjectUtil.isEmpty(accountManagement)) {
+                throw new ServiceException("资金账户不存在:" + accountPaymentRecords.getAccountManagementId());
+            }
+            //根据币种回滚余额
+            AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
+                    .eq(AccountRemainder::getAccountManagementId, accountPaymentRecords.getAccountManagementId())
+                    .eq(AccountRemainder::getCurrency, accountPaymentRecords.getCurrency()));
+            // 如果不存在这条数据则返回币种不存在
+            if (ObjectUtil.isEmpty(accountRemainder)) {
+                String format = String.format("账户%s不存在币种(%s),请前往资金账户添加", accountManagement.getName(), accountPaymentRecords.getCurrency());
+                throw new ServiceException(format);
+            }
+            accountRemainderService.update(q -> q
+                    .eq(AccountRemainder::getId, accountRemainder.getId())
+                    .setSql("remainder = remainder + " + accountPaymentRecords.getAmount())
+            );
+        }
         //删除打款对应的流水
-        AccountRunningWater accountRunningWater = accountRunningWaterService.getOne(q -> q.eq(AccountRunningWater::getBusinessId, accountPayment.getId()));
-        Assert.notEmpty(accountRunningWater, "查询不到打款流水信息");
-        accountRunningWaterService.removeById(accountRunningWater);
+        List<AccountRunningWater> accountRunningWaterList = accountRunningWaterService.list(q -> q.eq(AccountRunningWater::getBusinessId, accountPayment.getId()));
+        Assert.notEmpty(accountRunningWaterList, "查询不到打款流水信息");
     }
 
 }

+ 1 - 0
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -293,6 +293,7 @@
                  LEFT JOIN bytesailing_account.account_management am
                            ON arw.account_management_id = am.id AND am.del_flag = 0
         WHERE c.id = #{contractId}
+        group by arfd.id
         UNION ALL
         SELECT arw.id,
                arw.create_time,