Commit 69bdb2a6 authored by zhangfeng's avatar zhangfeng

feat(wealth): 优化

parent 4fc34799
......@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.wealth.service.receiptApproval.ReceiptApprovalSer
import cn.iocoder.yudao.module.wealth.service.receivable.ReceivableService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
......@@ -28,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Objects;
......@@ -258,12 +260,13 @@ public class FinanceReceiptApproveService {
if (null == receiptItemDO) {
throw exception(RECEIPT_ITEM_NOT_FOUND);
}
ReceiptItemDO updateReceiptItem = new ReceiptItemDO();
updateReceiptItem.setId(receiptItemDO.getId());
updateReceiptItem.setBmpStatus(result);
LambdaUpdateWrapper<ReceiptItemDO> updateWrapper = Wrappers.lambdaUpdate(ReceiptItemDO.class);
updateWrapper.eq(ReceiptItemDO::getId, receiptItemDO.getId());
updateWrapper.set(ReceiptItemDO::getBmpStatus, result);
if (result == BpmProcessInstanceResultEnum.APPROVE.getResult()) {
updateReceiptItem.setStatus(ReceiptItemStatusEnum.DRAFT.getValue());
receiptItemMapper.updateById(updateReceiptItem);
updateWrapper.set(ReceiptItemDO::getStatus, ReceiptItemStatusEnum.WRITE_OFF.getValue());
updateWrapper.set(ReceiptItemDO::getApprovalTime, null);
receiptItemMapper.update(null, updateWrapper);
//需要根据应收明细核销状态 变更成部分核销或者待核销
ReceiptDO updateReceipt = new ReceiptDO();
updateReceipt.setId(receiptItemDO.getReceiptId());
......@@ -281,7 +284,7 @@ public class FinanceReceiptApproveService {
for (ReceivableDO receivableDO : receivableDOS) {
ReceivableWriteOffRecordDO receivableWriteOffRecordDO = receivableService.getReceivableWriteOffRecord(receivableDO.getId(), receiptItemDO.getId());
if (null != receivableWriteOffRecordDO) {
BigDecimal writeOffCurrent = receivableWriteOffRecordDO.getWriteOffAmount().divide(receivableDO.getExchangeRate());
BigDecimal writeOffCurrent = receivableWriteOffRecordDO.getWriteOffAmount().divide(receivableDO.getExchangeRate(), 4, RoundingMode.HALF_UP);
receivableDO.setWriteOffAmount(receivableDO.getWriteOffAmount().subtract(writeOffCurrent));
}
if (receivableDO.getWriteOffAmount().compareTo(BigDecimal.ZERO) <= 0) {
......@@ -291,11 +294,11 @@ public class FinanceReceiptApproveService {
receivableService.updateBatchById(receivableDOS);
receiptService.updateReceiptItemStatus(receiptItemDO.getReceiptId());
} else if (result == BpmProcessInstanceResultEnum.REJECT.getResult()) {
updateReceiptItem.setStatus(ReceiptItemStatusEnum.WRITE_OFF.getValue());
receiptItemMapper.updateById(updateReceiptItem);
updateWrapper.set(ReceiptItemDO::getStatus, ReceiptItemStatusEnum.WRITE_OFF.getValue());
receiptItemMapper.update(null, updateWrapper);
} else if (result == BpmProcessInstanceResultEnum.CANCEL.getResult()) {
updateReceiptItem.setStatus(ReceiptItemStatusEnum.WRITE_OFF.getValue());
receiptItemMapper.updateById(updateReceiptItem);
updateWrapper.set(ReceiptItemDO::getStatus, ReceiptItemStatusEnum.WRITE_OFF.getValue());
receiptItemMapper.update(null, updateWrapper);
}
receiptService.recordLog(receiptItemDO.getReceiptId(), ReceiptLinkEnum.REJECT_BANK_RECEIPT, comment, WorkFlowEmus.FINANCE_RECEIPT_ITEM_WRITE_OFF_NO.getValue());
}
......
......@@ -1179,9 +1179,11 @@ public class ReceiptServiceImpl extends AbstractService<ReceiptMapper, ReceiptDO
receiptItemStatus = ReceiptItemStatusInReceiptEnum.PART_APPROVED;
}
}
ReceiptDO receiptDO = new ReceiptDO();
receiptDO.setId(receiptId);
receiptDO.setReceiptItemStatus(receiptItemStatus.getValue());
receiptMapper.updateById(receiptDO);
if (receiptItemStatus != null) {
ReceiptDO receiptDO = new ReceiptDO();
receiptDO.setId(receiptId);
receiptDO.setReceiptItemStatus(receiptItemStatus.getValue());
receiptMapper.updateById(receiptDO);
}
}
}
......@@ -58,6 +58,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
......@@ -278,11 +279,12 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
receivableDO.setState(1);
ReceivableWriteOffRecordDO receivableWriteOffRecordDO = receivableService.getReceivableWriteOffRecord(receivableDO.getId(), receiptItemDO.getId());
if (null != receivableWriteOffRecordDO) {
BigDecimal writeOffCurrent = receivableWriteOffRecordDO.getWriteOffAmount().divide(receivableDO.getExchangeRate());
BigDecimal writeOffCurrent = receivableWriteOffRecordDO.getWriteOffAmount().divide(receivableDO.getExchangeRate(),4, RoundingMode.HALF_UP);
receivableDO.setWriteOffAmount(receivableDO.getWriteOffAmount().add(writeOffCurrent));
}
}
receivableService.updateBatchById(receivableDOS);
receiptService.updateReceiptItemStatus(receiptItemDO.getReceiptId());
}
// 审核拒绝
else if (Objects.equals(bpmResult, BpmProcessInstanceResultEnum.REJECT.getResult())) {
......@@ -293,7 +295,6 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
receiptItemDO.setStatus(ReceiptItemStatusEnum.DRAFT.getValue());
}
receiptItemMapper.updateById(receiptItemDO);
receiptService.updateReceiptItemStatus(receiptItemDO.getReceiptId());
receiptService.recordLog(receiptItemDO.getReceiptId(), ReceiptLinkEnum.APPROVE_BANK_RECEIPT, comment, WorkFlowEmus.FINANCE_RECEIPT_ITEM_WRITE_OFF.getValue());
}
......@@ -549,7 +550,6 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
.remark(remark)
.build());
bpmProcessInstanceApi.approveTask(approvalDO.getBmpId(), "自动审批");
receiptService.recordLog(receiptItemDO.getReceiptId(), ReceiptLinkEnum.SUBMIT_BANK_RECEIPT, remark, WorkFlowEmus.FINANCE_RECEIPT_ITEM_WRITE_OFF.getValue());
receiptService.recordLog(receiptItemDO.getReceiptId(), ReceiptLinkEnum.APPROVE_BANK_RECEIPT, remark, WorkFlowEmus.FINANCE_RECEIPT_ITEM_WRITE_OFF.getValue());
}
......@@ -677,14 +677,24 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
});
throw exception(new ErrorCode(haveError ? 1004520042 : 1004520043, errorMsg.toString()));
}
// 计算每条应收明细的核销金额
ReceiptItemService proxy = (ReceiptItemService)AopContext.currentProxy();
for (ReceiptItemCreateReqVO receiptItemCreateReqVO : receiptItemCreateReqVOS) {
// 计算每条应收明细的核销金额
List<ReceivableInItemVO> listForCreateReceiptItem = receivableService.getListForCreateReceiptItem(receiptItemCreateReqVO.getReceiptId());
List<ReceivableWriteOffReqVO> receivableWriteOffList = getReceiptItemDetail(listForCreateReceiptItem, receiptItemCreateReqVO);
receiptItemCreateReqVO.setReceivableWriteOffList(receivableWriteOffList);
// 插入数据
Long receiptItemId = proxy.createReceiptItem(receiptItemCreateReqVO);
ReceiptItemDO receiptItemDO = receiptItemMapper.selectById(receiptItemId);
if (receiptItemDO.getBmpId() == null) {
this.createFinanceReceiptItemWriteOff(FinanceReceiptItemVo.builder()
.receiptId(receiptItemDO.getReceiptId())
.receiptNo(receiptItemCreateReqVO.getOrderNo())
.receiptItemId(receiptItemDO.getId())
.remark("批量导入收款明细自动提交审批")
.build());
}
}
// 插入数据
receiptItemCreateReqVOS.forEach(this::createReceiptItem);
return respVOS;
}
......@@ -836,6 +846,9 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
if (receivableDOS == null || receivableDOS.isEmpty()) {
return new ReceiptItemBatchRespVO(batchCreateReqVO.getOrderNo(), batchCreateReqVO.getPayer(), 0, "收款单不存在");
}
if (!receivableDOS.get(0).getBaseCurrencyId().equals(Long.parseLong(batchCreateReqVO.getSettleCurrency()))) {
return new ReceiptItemBatchRespVO(batchCreateReqVO.getOrderNo(), batchCreateReqVO.getPayer(), 0, "结算币种与收款单基准币种不一致");
}
Map<Long, List<ReceivableDO>> receivableCollect = receivableDOS.stream().filter(receivableDO -> receivableDO.getReceiptId() != null).collect(Collectors.groupingBy(ReceivableDO::getReceiptId));
ReceiptDO matchReceiptDO = receivableCollect.keySet().stream()
.map(receiptId -> receiptService.selectOne("id", receiptId))
......@@ -848,12 +861,14 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
// 查询订单是否存在多条银行收款数据
if (!ignoreItem) {
LambdaQueryWrapper<ReceiptItemDO> queryWrapper = Wrappers.lambdaQuery(ReceiptItemDO.class).in(ReceiptItemDO::getReceiptId, receivableCollect.keySet());
if (receiptItemMapper.selectList(queryWrapper).size() > 1) {
List<ReceiptItemDO> receiptItemDOS = receiptItemMapper.selectList(queryWrapper);
if (receiptItemDOS.size() > 1) {
return new ReceiptItemBatchRespVO(batchCreateReqVO.getOrderNo(), batchCreateReqVO.getPayer(), 1, "订单存在多条银行收款数据");
}
if (receiptItemDOS.size() == 1) {
return new ReceiptItemBatchRespVO(batchCreateReqVO.getOrderNo(), batchCreateReqVO.getPayer(), 1, "收款单已存在银行收款明细");
}
}
// TODO 结算币种需为收款单所在目的国结算币种 就是收款单的币种?
// 生成创建明细
ReceiptItemCreateReqVO receiptItemCreateReqVO = new ReceiptItemCreateReqVO();
receiptItemCreateReqVO.setReceiptId(matchReceiptDO.getId());
......@@ -866,6 +881,7 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
receiptItemCreateReqVO.setWriteOffCurrencyId(Long.parseLong(batchCreateReqVO.getSettleCurrency()));
receiptItemCreateReqVO.setWriteOffAmount(receiptItemCreateReqVO.getAmount().multiply(new BigDecimal(batchCreateReqVO.getSettleRate())));
receiptItemCreateReqVO.setRemark(batchCreateReqVO.getRemark());
receiptItemCreateReqVO.setOrderNo(orderByNo.getOrderNo());
try {
receiptItemCreateReqVO.setAmountDate(DateUtils.parseDate(batchCreateReqVO.getPayDate(), FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
} catch (Exception e) {
......@@ -883,6 +899,9 @@ public class ReceiptItemServiceImpl extends AbstractService<ReceiptItemMapper, R
if (StringUtils.isBlank(createReqVO.getPayer())) {
return new ReceiptItemBatchRespVO(createReqVO.getOrderNo(), createReqVO.getPayer(), 0, "付款人不能为空");
}
if (!"发货人".equals(createReqVO.getPayer()) && !"收货人".equals(createReqVO.getPayer())) {
return new ReceiptItemBatchRespVO(createReqVO.getOrderNo(), createReqVO.getPayer(), 0, "付款人需填写发货人或收货人");
}
if (createReqVO.getPayDate() == null) {
return new ReceiptItemBatchRespVO(createReqVO.getOrderNo(), createReqVO.getPayer(), 0, "收款日期不能为空");
}
......
......@@ -16,4 +16,6 @@ import java.util.List;
public class ReceiptItemCreateReqVO extends ReceiptItemBaseVO {
@ApiModelProperty(value = "应收核销信息")
private List<ReceivableWriteOffReqVO> receivableWriteOffList;
@ApiModelProperty(value = "订单号")
private String orderNo;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment