|
|
@@ -1,6 +1,5 @@
|
|
|
package com.dk.mdm.service.mac;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.dk.common.exception.BaseBusinessException;
|
|
|
import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
import com.dk.common.infrastructure.constant.Constant;
|
|
|
@@ -14,6 +13,8 @@ import com.dk.mdm.infrastructure.convert.mac.RecPayItemConvert;
|
|
|
import com.dk.mdm.mapper.mac.AccountItemMapper;
|
|
|
import com.dk.mdm.mapper.mac.AccountMapper;
|
|
|
import com.dk.mdm.mapper.mac.RecPayItemMapper;
|
|
|
+import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
|
|
|
+import com.dk.mdm.mapper.mst.MoneyAccountMapper;
|
|
|
import com.dk.mdm.model.pojo.mac.Account;
|
|
|
import com.dk.mdm.model.pojo.mac.AccountItem;
|
|
|
import com.dk.mdm.model.pojo.mac.RecPay;
|
|
|
@@ -21,6 +22,8 @@ import com.dk.mdm.mapper.mac.RecPayMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
import com.dk.mdm.model.pojo.mac.RecPayItem;
|
|
|
+import com.dk.mdm.model.pojo.mst.MoneyAccount;
|
|
|
+import com.dk.mdm.model.pojo.mst.MoneyAccountItem;
|
|
|
import com.dk.mdm.model.query.mac.RecPayItemQuery;
|
|
|
import com.dk.mdm.model.query.mac.RecPayQuery;
|
|
|
import com.dk.mdm.model.response.mac.RecPayItemResponse;
|
|
|
@@ -28,15 +31,13 @@ import com.dk.mdm.model.response.mac.RecPayResponse;
|
|
|
import com.dk.mdm.model.vo.mac.RecPayItemVO;
|
|
|
import com.dk.mdm.model.vo.mac.RecPayVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
+import com.dk.mdm.service.mst.MoneyAccountService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
@@ -71,9 +72,18 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
private AccountItemService accountItemService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private MoneyAccountMapper moneyAccountMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private AccountItemMapper accountItemMapper;
|
|
|
|
|
|
@Autowired
|
|
|
+ private MoneyAccountService moneyAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MoneyAccountItemMapper moneyAccountItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private CommonService commonService;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -138,15 +148,29 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
AccountItem accountItem = new AccountItem();
|
|
|
accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
|
|
|
.setObjectId(recPayVO.getObjectId()).setOrgId(recPayVO.getOrgId()).setStaffId(recPayVO.getStaffId())
|
|
|
- .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItemVO.getAmtRec())
|
|
|
+ .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
|
|
|
.setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPayVO.getRpNo())
|
|
|
.setMakeStaff(recPayVO.getMakeStaff()).setCpId(recPayVO.getCpId());
|
|
|
accountItemMapper.insert(accountItem);
|
|
|
|
|
|
- // 更新收款单上的应收账款
|
|
|
+ // 更新收款单上的账款明细Id
|
|
|
RecPayItem recPayItemUpdate = new RecPayItem();
|
|
|
recPayItemUpdate.setAccItemId(accountItem.getItemId()).setRpId(recPayVO.getRpId());
|
|
|
recPayItemService.updateByUuid(recPayItemUpdate);
|
|
|
+
|
|
|
+ // 插入资金流水
|
|
|
+ MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
|
|
|
+ moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
|
|
|
+ .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtRec()).setAccDate(recPayVO.getAccDate())
|
|
|
+ .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
|
|
|
+ moneyAccountItemMapper.insert(moneyAccountItem);
|
|
|
+
|
|
|
+ // 更新资金账户
|
|
|
+ MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
|
|
|
+ MoneyAccount moneyAccountUpdate = new MoneyAccount();
|
|
|
+ moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec()))
|
|
|
+ .setMacId(moneyAccountForUpdate.getMacId());
|
|
|
+ moneyAccountService.updateByUuid(moneyAccountUpdate);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -205,15 +229,35 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
AccountItem accountItem = new AccountItem();
|
|
|
accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
|
|
|
.setObjectId(recPayVO.getObjectId()).setOrgId(recPayVO.getOrgId()).setStaffId(recPayVO.getStaffId())
|
|
|
- .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItemVO.getAmtRec())
|
|
|
+ .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
|
|
|
.setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPayVO.getRpNo())
|
|
|
.setMakeStaff(recPayVO.getMakeStaff()).setCpId(recPayVO.getCpId());
|
|
|
accountItemMapper.insert(accountItem);
|
|
|
|
|
|
- // 更新收款单上的应收账款
|
|
|
+ // 更新收款单上的账款明细Id
|
|
|
RecPayItem recPayItemUpdate = new RecPayItem();
|
|
|
recPayItemUpdate.setAccItemId(accountItem.getItemId()).setRpId(recPayVO.getRpId());
|
|
|
recPayItemService.updateByUuid(recPayItemUpdate);
|
|
|
+
|
|
|
+ // 插入资金流水
|
|
|
+ MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
|
|
|
+ moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
|
|
|
+ .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtRec()).setAccDate(recPayVO.getAccDate())
|
|
|
+ .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
|
|
|
+ moneyAccountItemMapper.insert(moneyAccountItem);
|
|
|
+
|
|
|
+ // 更新资金账户
|
|
|
+ MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
|
|
|
+
|
|
|
+ // 如果转账之后账户余额小于0,则提示资金账户余额不足,不能退款
|
|
|
+ if ((moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec())).compareTo(BigDecimal.ZERO) == -1) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ MoneyAccount moneyAccountUpdate = new MoneyAccount();
|
|
|
+ moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec()))
|
|
|
+ .setMacId(moneyAccountForUpdate.getMacId());
|
|
|
+ moneyAccountService.updateByUuid(moneyAccountUpdate);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -235,31 +279,66 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
|
public ResponseResultVO<?> update(RecPayVO recPayVO) {
|
|
|
- RecPay recPay = recPayConvert.convertToPo(recPayVO);
|
|
|
|
|
|
- //删除的
|
|
|
- List<RecPayItemVO> deleteRecPayItemVOList = recPayVO.getDeleteItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
|
|
|
- if (deleteRecPayItemVOList.size() > 0) {
|
|
|
- for (RecPayItemVO recPayItemVO : deleteRecPayItemVOList) {
|
|
|
- recPayItemMapper.deleteById(recPayItemVO.getItemId());
|
|
|
+ // 将之前的明细全部删除
|
|
|
+ List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayVO.getRpId());
|
|
|
+ // 需要重新计算的资金账户
|
|
|
+ List<String> macList = new ArrayList<>();
|
|
|
+ for (RecPayItem recPayItem : recPayItemOriginalList) {
|
|
|
+ // 删除收付款明细
|
|
|
+ recPayItemMapper.deleteById(recPayItem.getItemId());
|
|
|
+ // 删除账款明细
|
|
|
+ accountItemMapper.deleteById(recPayItem.getAccItemId());
|
|
|
+ // 删除账户流水
|
|
|
+ moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
|
|
|
+
|
|
|
+ if (!macList.contains(recPayItem.getMacId())) {
|
|
|
+ macList.add(recPayItem.getMacId());
|
|
|
}
|
|
|
}
|
|
|
- // 新增的
|
|
|
- List<RecPayItemVO> insertRecPayItemVOList = recPayVO.getItemList().stream().filter(it -> it.getItemId() == null).collect(Collectors.toList());
|
|
|
- for (RecPayItemVO recPayItemVO : insertRecPayItemVOList) {
|
|
|
+
|
|
|
+ // 新增明细
|
|
|
+ for (RecPayItemVO recPayItemVO : recPayVO.getItemList()) {
|
|
|
RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
|
|
|
- recPayItem.setRpId(recPay.getRpId()).setCpId(recPay.getCpId());
|
|
|
+ recPayItem.setRpId(recPayVO.getRpId()).setCpId(recPayVO.getCpId());
|
|
|
recPayItemMapper.insert(recPayItem);
|
|
|
+
|
|
|
+ // 插入账款明细
|
|
|
+ AccountItem accountItem = new AccountItem();
|
|
|
+ accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
|
|
|
+ .setObjectId(recPayVO.getObjectId()).setOrgId(recPayVO.getOrgId()).setStaffId(recPayVO.getStaffId())
|
|
|
+ .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
|
|
|
+ .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPayVO.getRpNo())
|
|
|
+ .setMakeStaff(recPayVO.getMakeStaff()).setCpId(recPayVO.getCpId());
|
|
|
+ accountItemMapper.insert(accountItem);
|
|
|
+
|
|
|
+ // 更新收款单上的账款明细Id
|
|
|
+ RecPayItem recPayItemUpdate = new RecPayItem();
|
|
|
+ recPayItemUpdate.setAccItemId(accountItem.getItemId()).setRpId(recPayVO.getRpId());
|
|
|
+ recPayItemService.updateByUuid(recPayItemUpdate);
|
|
|
+
|
|
|
+ // 插入资金流水
|
|
|
+ MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
|
|
|
+ moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
|
|
|
+ .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtRec()).setAccDate(recPayVO.getAccDate())
|
|
|
+ .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
|
|
|
+ moneyAccountItemMapper.insert(moneyAccountItem);
|
|
|
+
|
|
|
+ if (!macList.contains(recPayItem.getMacId())) {
|
|
|
+ macList.add(recPayItem.getMacId());
|
|
|
+ }
|
|
|
}
|
|
|
- // 编辑的
|
|
|
- List<RecPayItemVO> editRecPayItemVOList = recPayVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
|
|
|
- for (RecPayItemVO recPayItemVO : editRecPayItemVOList) {
|
|
|
- RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
|
|
|
- recPayItemService.updateByUuid(recPayItem);
|
|
|
+
|
|
|
+ // 更新总账表的总收款额和可用额
|
|
|
+ accountService.updateReceipt(recPayVO.getObjectId());
|
|
|
+ // 更新账户余额
|
|
|
+ for (String macId : macList) {
|
|
|
+ accountService.updateMac(macId);
|
|
|
}
|
|
|
-
|
|
|
- return ResponseResultUtil.success(super.update(recPay, new UpdateWrapper<RecPay>().lambda().eq(RecPay::getRpId,
|
|
|
- UUID.fromString(recPay.getRpId()))));
|
|
|
+
|
|
|
+ // 更新收款单总表
|
|
|
+ RecPay recPay = recPayConvert.convertToPo(recPayVO);
|
|
|
+ return ResponseResultUtil.success(super.updateByUuid(recPay));
|
|
|
}
|
|
|
|
|
|
/**
|