调整收付款问题
This commit is contained in:
+5
-2
@@ -80,8 +80,11 @@ public class InvoiceApplicationController extends BladeController {
|
|||||||
@GetMapping("/settlement-candidates")
|
@GetMapping("/settlement-candidates")
|
||||||
@ApiOperationSupport(order = 3)
|
@ApiOperationSupport(order = 3)
|
||||||
@Operation(summary = "可开票正式结算单")
|
@Operation(summary = "可开票正式结算单")
|
||||||
public R<List<Map<String, Object>>> settlementCandidates(@RequestParam(required = false) String keyword) {
|
public R<IPage<Map<String, Object>>> settlementCandidates(Query query,
|
||||||
return R.data(invoiceApplicationService.settlementCandidates(keyword));
|
@RequestParam(required = false) String keyword,
|
||||||
|
@RequestParam(required = false) String contractCategory) {
|
||||||
|
return R.data(invoiceApplicationService.settlementCandidates(
|
||||||
|
Condition.getPage(query), keyword, contractCategory));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/settlement-details")
|
@GetMapping("/settlement-details")
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ import java.util.Map;
|
|||||||
public interface IInvoiceApplicationService extends BaseService<InvoiceApplication> {
|
public interface IInvoiceApplicationService extends BaseService<InvoiceApplication> {
|
||||||
IPage<InvoiceApplicationVO> selectPage(IPage<InvoiceApplication> page, InvoiceApplicationVO query);
|
IPage<InvoiceApplicationVO> selectPage(IPage<InvoiceApplication> page, InvoiceApplicationVO query);
|
||||||
InvoiceApplicationVO detail(Long id);
|
InvoiceApplicationVO detail(Long id);
|
||||||
List<Map<String, Object>> settlementCandidates(String keyword);
|
IPage<Map<String, Object>> settlementCandidates(IPage<?> page, String keyword, String contractCategory);
|
||||||
List<FormalSettlementDetail> settlementDetails(String settlementIds);
|
List<FormalSettlementDetail> settlementDetails(String settlementIds);
|
||||||
Map<String, Object> receiverInformation(String settlementIds);
|
Map<String, Object> receiverInformation(String settlementIds);
|
||||||
Long saveDraft(InvoiceApplicationSaveRequest request);
|
Long saveDraft(InvoiceApplicationSaveRequest request);
|
||||||
|
|||||||
+78
-20
@@ -28,6 +28,7 @@ package org.springblade.transport.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||||
@@ -37,6 +38,7 @@ import org.springblade.core.tool.utils.Func;
|
|||||||
import org.springblade.transport.mapper.CustomerArchiveMapper;
|
import org.springblade.transport.mapper.CustomerArchiveMapper;
|
||||||
import org.springblade.transport.mapper.CustomerContactMapper;
|
import org.springblade.transport.mapper.CustomerContactMapper;
|
||||||
import org.springblade.transport.mapper.CustomerInvoiceInfoMapper;
|
import org.springblade.transport.mapper.CustomerInvoiceInfoMapper;
|
||||||
|
import org.springblade.transport.mapper.ContractManageMapper;
|
||||||
import org.springblade.transport.mapper.FormalSettlementDetailMapper;
|
import org.springblade.transport.mapper.FormalSettlementDetailMapper;
|
||||||
import org.springblade.transport.mapper.FormalSettlementMapper;
|
import org.springblade.transport.mapper.FormalSettlementMapper;
|
||||||
import org.springblade.transport.mapper.InvoiceApplicationDetailMapper;
|
import org.springblade.transport.mapper.InvoiceApplicationDetailMapper;
|
||||||
@@ -50,6 +52,7 @@ import org.springblade.transport.pojo.dto.InvoiceApplicationStatusRequest;
|
|||||||
import org.springblade.transport.pojo.entity.CustomerArchive;
|
import org.springblade.transport.pojo.entity.CustomerArchive;
|
||||||
import org.springblade.transport.pojo.entity.CustomerContact;
|
import org.springblade.transport.pojo.entity.CustomerContact;
|
||||||
import org.springblade.transport.pojo.entity.CustomerInvoiceInfo;
|
import org.springblade.transport.pojo.entity.CustomerInvoiceInfo;
|
||||||
|
import org.springblade.transport.pojo.entity.ContractManage;
|
||||||
import org.springblade.transport.pojo.entity.FormalSettlement;
|
import org.springblade.transport.pojo.entity.FormalSettlement;
|
||||||
import org.springblade.transport.pojo.entity.FormalSettlementDetail;
|
import org.springblade.transport.pojo.entity.FormalSettlementDetail;
|
||||||
import org.springblade.transport.pojo.entity.InvoiceApplication;
|
import org.springblade.transport.pojo.entity.InvoiceApplication;
|
||||||
@@ -102,6 +105,7 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
|||||||
private final InvoiceApplicationRecordMapper recordMapper;
|
private final InvoiceApplicationRecordMapper recordMapper;
|
||||||
private final FormalSettlementMapper formalSettlementMapper;
|
private final FormalSettlementMapper formalSettlementMapper;
|
||||||
private final FormalSettlementDetailMapper formalSettlementDetailMapper;
|
private final FormalSettlementDetailMapper formalSettlementDetailMapper;
|
||||||
|
private final ContractManageMapper contractManageMapper;
|
||||||
private final CustomerArchiveMapper customerArchiveMapper;
|
private final CustomerArchiveMapper customerArchiveMapper;
|
||||||
private final CustomerInvoiceInfoMapper customerInvoiceInfoMapper;
|
private final CustomerInvoiceInfoMapper customerInvoiceInfoMapper;
|
||||||
private final CustomerContactMapper customerContactMapper;
|
private final CustomerContactMapper customerContactMapper;
|
||||||
@@ -142,33 +146,87 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> settlementCandidates(String keyword) {
|
public IPage<Map<String, Object>> settlementCandidates(IPage<?> page, String keyword,
|
||||||
|
String contractCategory) {
|
||||||
|
List<Long> contractIds = Func.isEmpty(contractCategory) ? List.of()
|
||||||
|
: contractManageMapper.selectList(Wrappers.<ContractManage>lambdaQuery()
|
||||||
|
.select(ContractManage::getId)
|
||||||
|
.eq(ContractManage::getContractCategory, contractCategory)
|
||||||
|
.eq(ContractManage::getIsDeleted, 0))
|
||||||
|
.stream().map(ContractManage::getId).toList();
|
||||||
|
if (Func.isNotEmpty(contractCategory) && contractIds.isEmpty()) {
|
||||||
|
return new Page<>(page.getCurrent(), page.getSize(), 0);
|
||||||
|
}
|
||||||
List<FormalSettlement> settlements = formalSettlementMapper.selectList(Wrappers.<FormalSettlement>lambdaQuery()
|
List<FormalSettlement> settlements = formalSettlementMapper.selectList(Wrappers.<FormalSettlement>lambdaQuery()
|
||||||
.eq(FormalSettlement::getSettlementType, "payable")
|
.eq(FormalSettlement::getSettlementType, "payable")
|
||||||
.eq(FormalSettlement::getApprovalStatus, APPROVED)
|
.eq(FormalSettlement::getApprovalStatus, APPROVED)
|
||||||
.eq(FormalSettlement::getStatus, 1)
|
.eq(FormalSettlement::getStatus, 1)
|
||||||
|
.in(Func.isNotEmpty(contractCategory), FormalSettlement::getContractId, contractIds)
|
||||||
.and(Func.isNotEmpty(keyword), wrapper -> wrapper.like(FormalSettlement::getFormalSettlementNo, keyword)
|
.and(Func.isNotEmpty(keyword), wrapper -> wrapper.like(FormalSettlement::getFormalSettlementNo, keyword)
|
||||||
.or().like(FormalSettlement::getProjectName, keyword)
|
.or().like(FormalSettlement::getProjectName, keyword)
|
||||||
.or().like(FormalSettlement::getContractName, keyword))
|
.or().like(FormalSettlement::getContractName, keyword))
|
||||||
.orderByDesc(FormalSettlement::getCreateTime).last("limit 200"));
|
.orderByDesc(FormalSettlement::getCreateTime));
|
||||||
return settlements.stream().map(settlement -> {
|
Map<Long, BigDecimal> availableAmounts = candidateAvailableAmounts(settlements);
|
||||||
BigDecimal available = availableAmount(settlement, null);
|
List<Map<String, Object>> candidates = settlements.stream()
|
||||||
Map<String, Object> row = new LinkedHashMap<>();
|
.map(settlement -> settlementCandidateMap(settlement,
|
||||||
row.put("id", settlement.getId());
|
availableAmounts.getOrDefault(settlement.getId(), BigDecimal.ZERO)))
|
||||||
row.put("formalSettlementNo", settlement.getFormalSettlementNo());
|
.filter(row -> ((BigDecimal) row.get("availableInvoiceAmount")).compareTo(BigDecimal.ZERO) > 0)
|
||||||
row.put("projectId", settlement.getProjectId());
|
.toList();
|
||||||
row.put("projectName", settlement.getProjectName());
|
long current = Math.max(page.getCurrent(), 1);
|
||||||
row.put("deptId", settlement.getDeptId());
|
long size = Math.max(page.getSize(), 1);
|
||||||
row.put("deptName", settlement.getDeptName());
|
long offset = Math.min((current - 1) * size, candidates.size());
|
||||||
row.put("contractId", settlement.getContractId());
|
long end = Math.min(offset + size, candidates.size());
|
||||||
row.put("contractNo", settlement.getContractNo());
|
Page<Map<String, Object>> result = new Page<>(current, size, candidates.size());
|
||||||
row.put("contractName", settlement.getContractName());
|
result.setRecords(candidates.subList((int) offset, (int) end));
|
||||||
row.put("issuerName", settlement.getPayeeName());
|
return result;
|
||||||
row.put("receiverName", settlement.getPayerName());
|
}
|
||||||
row.put("settlementAmount", money(settlement.getSettlementAmount()));
|
|
||||||
row.put("availableInvoiceAmount", available);
|
private Map<Long, BigDecimal> candidateAvailableAmounts(List<FormalSettlement> settlements) {
|
||||||
return row;
|
if (settlements.isEmpty()) return Map.of();
|
||||||
}).filter(row -> ((BigDecimal) row.get("availableInvoiceAmount")).compareTo(BigDecimal.ZERO) > 0).toList();
|
List<Long> settlementIds = settlements.stream().map(FormalSettlement::getId).toList();
|
||||||
|
List<InvoiceApplicationSettlement> relations = settlementRelationMapper.selectList(
|
||||||
|
Wrappers.<InvoiceApplicationSettlement>lambdaQuery()
|
||||||
|
.in(InvoiceApplicationSettlement::getFormalSettlementId, settlementIds));
|
||||||
|
if (relations.isEmpty()) {
|
||||||
|
return settlements.stream().collect(Collectors.toMap(FormalSettlement::getId,
|
||||||
|
settlement -> money(settlement.getSettlementAmount()), (first, duplicate) -> first,
|
||||||
|
LinkedHashMap::new));
|
||||||
|
}
|
||||||
|
Map<Long, InvoiceApplication> applications = listByIds(relations.stream()
|
||||||
|
.map(InvoiceApplicationSettlement::getInvoiceApplicationId).distinct().toList()).stream()
|
||||||
|
.collect(Collectors.toMap(InvoiceApplication::getId, Function.identity()));
|
||||||
|
Map<Long, BigDecimal> allocatedAmounts = relations.stream()
|
||||||
|
.filter(relation -> {
|
||||||
|
InvoiceApplication application = applications.get(relation.getInvoiceApplicationId());
|
||||||
|
return application != null && !VOIDED.equals(application.getApprovalStatus())
|
||||||
|
&& !Objects.equals(application.getIsDeleted(), 1);
|
||||||
|
})
|
||||||
|
.collect(Collectors.groupingBy(InvoiceApplicationSettlement::getFormalSettlementId,
|
||||||
|
Collectors.reducing(BigDecimal.ZERO,
|
||||||
|
relation -> money(relation.getAllocatedInvoiceAmount()), BigDecimal::add)));
|
||||||
|
return settlements.stream().collect(Collectors.toMap(FormalSettlement::getId,
|
||||||
|
settlement -> money(settlement.getSettlementAmount())
|
||||||
|
.subtract(allocatedAmounts.getOrDefault(settlement.getId(), BigDecimal.ZERO))
|
||||||
|
.max(BigDecimal.ZERO),
|
||||||
|
(first, duplicate) -> first, LinkedHashMap::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> settlementCandidateMap(FormalSettlement settlement, BigDecimal available) {
|
||||||
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
|
row.put("id", settlement.getId());
|
||||||
|
row.put("formalSettlementNo", settlement.getFormalSettlementNo());
|
||||||
|
row.put("projectId", settlement.getProjectId());
|
||||||
|
row.put("projectName", settlement.getProjectName());
|
||||||
|
row.put("deptId", settlement.getDeptId());
|
||||||
|
row.put("deptName", settlement.getDeptName());
|
||||||
|
row.put("contractId", settlement.getContractId());
|
||||||
|
row.put("contractNo", settlement.getContractNo());
|
||||||
|
row.put("contractName", settlement.getContractName());
|
||||||
|
row.put("issuerName", settlement.getPayeeName());
|
||||||
|
row.put("receiverName", settlement.getPayerName());
|
||||||
|
row.put("settlementAmount", money(settlement.getSettlementAmount()));
|
||||||
|
row.put("availableInvoiceAmount", available);
|
||||||
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user