[feat] 新增历史应收款管理功能

This commit is contained in:
shl 2024-08-13 15:10:23 +08:00
parent 1df906c0db
commit 92070e3c57
6 changed files with 249 additions and 82 deletions

View File

@ -24,6 +24,7 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import cn.iocoder.yudao.module.pms.controller.admin.receivableshistory.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDO;
@ -38,27 +39,11 @@ public class ReceivablesHistoryController {
@Resource
private ReceivablesHistoryService receivablesHistoryService;
@PostMapping("/create")
@Operation(summary = "创建应收款管理历史记录")
@PreAuthorize("@ss.hasPermission('pms:receivables-history:create')")
public CommonResult<Long> createReceivablesHistory(@Valid @RequestBody ReceivablesHistorySaveReqVO createReqVO) {
return success(receivablesHistoryService.createReceivablesHistory(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新应收款管理历史记录")
@PreAuthorize("@ss.hasPermission('pms:receivables-history:update')")
public CommonResult<Boolean> updateReceivablesHistory(@Valid @RequestBody ReceivablesHistorySaveReqVO updateReqVO) {
receivablesHistoryService.updateReceivablesHistory(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除应收款管理历史记录")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pms:receivables-history:delete')")
public CommonResult<Boolean> deleteReceivablesHistory(@RequestParam("id") Long id) {
receivablesHistoryService.deleteReceivablesHistory(id);
public CommonResult<Boolean> updateReceivablesHistory(Long loginUserId, @Valid @RequestBody ReceivablesHistorySaveReqVO updateReqVO) {
receivablesHistoryService.updateReceivablesHistory(getLoginUserId(), updateReqVO);
return success(true);
}
@ -67,16 +52,16 @@ public class ReceivablesHistoryController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pms:receivables-history:query')")
public CommonResult<ReceivablesHistoryRespVO> getReceivablesHistory(@RequestParam("id") Long id) {
ReceivablesHistoryDO receivablesHistory = receivablesHistoryService.getReceivablesHistory(id);
return success(BeanUtils.toBean(receivablesHistory, ReceivablesHistoryRespVO.class));
ReceivablesHistoryRespVO receivablesHistory = receivablesHistoryService.getReceivablesHistory(id);
return success(receivablesHistory);
}
@GetMapping("/page")
@Operation(summary = "获得应收款管理历史记录分页")
@PreAuthorize("@ss.hasPermission('pms:receivables-history:query')")
public CommonResult<PageResult<ReceivablesHistoryRespVO>> getReceivablesHistoryPage(@Valid ReceivablesHistoryPageReqVO pageReqVO) {
PageResult<ReceivablesHistoryDO> pageResult = receivablesHistoryService.getReceivablesHistoryPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ReceivablesHistoryRespVO.class));
PageResult<ReceivablesHistoryRespVO> pageResult = receivablesHistoryService.getReceivablesHistoryPage(pageReqVO);
return success(pageResult);
}
@GetMapping("/export-excel")
@ -86,7 +71,7 @@ public class ReceivablesHistoryController {
public void exportReceivablesHistoryExcel(@Valid ReceivablesHistoryPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ReceivablesHistoryDO> list = receivablesHistoryService.getReceivablesHistoryPage(pageReqVO).getList();
List<ReceivablesHistoryRespVO> list = receivablesHistoryService.getReceivablesHistoryPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "应收款管理历史记录.xls", "数据", ReceivablesHistoryRespVO.class,
BeanUtils.toBean(list, ReceivablesHistoryRespVO.class));

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.pms.controller.admin.receivableshistory.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@ -12,6 +14,39 @@ import com.alibaba.excel.annotation.*;
@ExcelIgnoreUnannotated
public class ReceivablesHistoryRespVO {
@Schema(description = "项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "SJ24001")
@ExcelProperty("项目编号")
private String projectCode;
@Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "规划一路道路工程勘察设计合同")
@ExcelProperty("合同名称")
private String contractName;
@Schema(description = "签订合同总额", requiredMode = Schema.RequiredMode.REQUIRED, example = "80.0000")
@ExcelProperty("签订合同总额")
private BigDecimal signedAmount;
@Schema(description = "包干/审定金额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("包干/审定金额")
private BigDecimal approvedAmount;
@Schema(description = "已完成设计阶段", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("已完成设计阶段")
private String completedDesignStage;
@Schema(description = "应收款取数", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("应收款取数")
private BigDecimal receivableAccount;
@Schema(description = "合同应收款", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("合同应收款")
private BigDecimal contractualReceivables;
@Schema(description = "应收款差额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("应收款差额")
private BigDecimal receivableDifference;
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20822")
@ExcelProperty("主键")
private Long id;

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.pms.controller.admin.receivableshistory.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import jakarta.validation.constraints.*;
@ -9,6 +12,39 @@ import jakarta.validation.constraints.*;
@Data
public class ReceivablesHistorySaveReqVO {
@Schema(description = "项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "SJ24001")
@ExcelProperty("项目编号")
private String projectCode;
@Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "规划一路道路工程勘察设计合同")
@ExcelProperty("合同名称")
private String contractName;
@Schema(description = "签订合同总额", requiredMode = Schema.RequiredMode.REQUIRED, example = "80.0000")
@ExcelProperty("签订合同总额")
private BigDecimal signedAmount;
@Schema(description = "包干/审定金额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("包干/审定金额")
private BigDecimal approvedAmount;
@Schema(description = "已完成设计阶段", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("已完成设计阶段")
private String completedDesignStage;
@Schema(description = "应收款取数", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("应收款取数")
private BigDecimal receivableAccount;
@Schema(description = "合同应收款", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("合同应收款")
private BigDecimal contractualReceivables;
@Schema(description = "应收款差额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("应收款差额")
private BigDecimal receivableDifference;
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20822")
private Long id;

View File

@ -262,26 +262,14 @@ public class ReceivablesServiceImpl implements ReceivablesService {
BigDecimal constructionStage = parseRate(receivablesDO.getConstructionStage()); // 施工配合收款比例
BigDecimal approveStage = parseRate(receivablesDO.getApproveStage()); // 审定阶段
switch (projectSchedule.getStage()) {
case "方案设计":
amount = receivableAccount.multiply(planStage);
break;
case "初步设计":
amount = receivableAccount.multiply(initialDesignStage);
break;
case "施工图":
amount = receivableAccount.multiply(constructionDrawingStage);
break;
case "施工配合":
amount = receivableAccount.multiply(constructionStage);
break;
case "竣工":
amount = receivableAccount.multiply(approveStage);
break;
default:
amount = BigDecimal.ZERO;
break;
}
amount = switch (projectSchedule.getStage()) {
case "方案设计" -> receivableAccount.multiply(planStage);
case "初步设计" -> receivableAccount.multiply(initialDesignStage);
case "施工图" -> receivableAccount.multiply(constructionDrawingStage);
case "施工配合" -> receivableAccount.multiply(constructionStage);
case "竣工" -> receivableAccount.multiply(approveStage);
default -> BigDecimal.ZERO;
};
receivablesRespVO.setContractualReceivables(amount); // 合同应收款
BigDecimal collectionAmount = parseRate(receivablesDO.getCollectionSituation());

View File

@ -14,27 +14,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
*/
public interface ReceivablesHistoryService {
/**
* 创建应收款管理历史记录
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createReceivablesHistory(@Valid ReceivablesHistorySaveReqVO createReqVO);
/**
* 更新应收款管理历史记录
*
* @param updateReqVO 更新信息
*/
void updateReceivablesHistory(@Valid ReceivablesHistorySaveReqVO updateReqVO);
/**
* 删除应收款管理历史记录
*
* @param id 编号
*/
void deleteReceivablesHistory(Long id);
void updateReceivablesHistory(Long loginUserId, @Valid ReceivablesHistorySaveReqVO updateReqVO);
/**
* 获得应收款管理历史记录
@ -42,7 +27,7 @@ public interface ReceivablesHistoryService {
* @param id 编号
* @return 应收款管理历史记录
*/
ReceivablesHistoryDO getReceivablesHistory(Long id);
ReceivablesHistoryRespVO getReceivablesHistory(Long id);
/**
* 获得应收款管理历史记录分页
@ -50,6 +35,6 @@ public interface ReceivablesHistoryService {
* @param pageReqVO 分页查询
* @return 应收款管理历史记录分页
*/
PageResult<ReceivablesHistoryDO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO);
PageResult<ReceivablesHistoryRespVO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO);
}

View File

@ -1,10 +1,19 @@
package cn.iocoder.yudao.module.pms.service.receivableshistory;
import cn.iocoder.yudao.module.cms.api.contract.ContractApi;
import cn.iocoder.yudao.module.cms.api.contract.dto.ContractRespDTO;
import cn.iocoder.yudao.module.pms.api.project.ProjectApi;
import cn.iocoder.yudao.module.pms.api.project.dto.ProjectRespDTO;
import cn.iocoder.yudao.module.pms.dal.dataobject.projectschedule.ProjectScheduleDO;
import cn.iocoder.yudao.module.pms.service.projectschedule.ProjectScheduleService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import cn.iocoder.yudao.module.pms.controller.admin.receivableshistory.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDO;
@ -15,7 +24,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pms.dal.mysql.receivableshistory.ReceivablesHistoryMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.cms.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS;
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
/**
* 应收款管理历史记录 Service 实现类
@ -29,32 +40,44 @@ public class ReceivablesHistoryServiceImpl implements ReceivablesHistoryService
@Resource
private ReceivablesHistoryMapper receivablesHistoryMapper;
@Override
public Long createReceivablesHistory(ReceivablesHistorySaveReqVO createReqVO) {
// 插入
ReceivablesHistoryDO receivablesHistory = BeanUtils.toBean(createReqVO, ReceivablesHistoryDO.class);
receivablesHistoryMapper.insert(receivablesHistory);
// 返回
return receivablesHistory.getId();
}
@Resource
private ProjectApi projectApi;
@Resource
private ContractApi contractApi;
@Resource
private AdminUserApi adminUserApi;
@Resource
private ProjectScheduleService projectScheduleService;
@Override
public void updateReceivablesHistory(ReceivablesHistorySaveReqVO updateReqVO) {
public void updateReceivablesHistory(Long loginUserId, ReceivablesHistorySaveReqVO updateReqVO) {
// 校验存在
validateReceivablesHistoryExists(updateReqVO.getId());
if (loginUserId == null) {
throw exception(USER_NOT_EXISTS);
}
Long projectId = updateReqVO.getProjectId();
Long contractId = updateReqVO.getContractId();
ProjectRespDTO project = projectApi.getProject(projectId);
ContractRespDTO contract = contractApi.getContract(contractId);
if (project == null) {
throw exception(PROJECT_NOT_EXISTS);
}
if (contract == null) {
throw exception(CONTRACT_NOT_EXISTS);
}
// 更新
ReceivablesHistoryDO updateObj = BeanUtils.toBean(updateReqVO, ReceivablesHistoryDO.class);
String userName = adminUserApi.getUser(loginUserId).getNickname();
updateObj.setUpdater(userName);
receivablesHistoryMapper.updateById(updateObj);
}
@Override
public void deleteReceivablesHistory(Long id) {
// 校验存在
validateReceivablesHistoryExists(id);
// 删除
receivablesHistoryMapper.deleteById(id);
}
private void validateReceivablesHistoryExists(Long id) {
if (receivablesHistoryMapper.selectById(id) == null) {
throw exception(RECEIVABLES_HISTORY_NOT_EXISTS);
@ -62,13 +85,128 @@ public class ReceivablesHistoryServiceImpl implements ReceivablesHistoryService
}
@Override
public ReceivablesHistoryDO getReceivablesHistory(Long id) {
return receivablesHistoryMapper.selectById(id);
public ReceivablesHistoryRespVO getReceivablesHistory(Long id) {
// 校验
if (id == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
ReceivablesHistoryDO receivablesHistoryDO = receivablesHistoryMapper.selectById(id);
if (receivablesHistoryDO == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
Long receivableId = receivablesHistoryDO.getReceivableId();
if (receivableId == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
Long projectId = receivablesHistoryDO.getProjectId();
if (projectId == null) {
throw exception(PROJECT_NOT_EXISTS);
}
Long contractId = receivablesHistoryDO.getContractId();
if (contractId == null) {
throw exception(CONTRACT_NOT_EXISTS);
}
ContractRespDTO contract = contractApi.getContract(contractId);
ProjectRespDTO project = projectApi.getProject(projectId);
ProjectScheduleDO projectSchedule = projectScheduleService.getProjectSchedule(projectId);
ReceivablesHistoryRespVO receivablesHistoryRespVO = BeanUtils.toBean(receivablesHistoryDO, ReceivablesHistoryRespVO.class);
/** 联表查询
* 1. 项目编号
* 2. 合同名称
* 3. 签订合同总额
* 4. 包干/审定金额
* 5. 已完成设计阶段
* 6. 应收款取数
* 7. 合同应收款
* 8. 应收款差额
*/
receivablesHistoryRespVO.setProjectCode(project.getCode());
receivablesHistoryRespVO.setContractName(contract.getName());
receivablesHistoryRespVO.setSignedAmount(contract.getAmount());
receivablesHistoryRespVO.setApprovedAmount(contract.getApprovedAmount());
receivablesHistoryRespVO.setCompletedDesignStage(projectSchedule.getStage());
BigDecimal receivableAccount = (contract.getApprovedAmount() == null) ? contract.getAmount() : contract.getApprovedAmount();
receivablesHistoryRespVO.setReceivableAccount(receivableAccount);
if (receivableAccount == null) {
throw exception(RECEIVABLES_CALCULATION_ERROR);
}
BigDecimal amount = BigDecimal.ZERO;
BigDecimal planStage = parseRate(receivablesHistoryDO.getPlanStage()); // 方案阶段收款比例
BigDecimal initialDesignStage = parseRate(receivablesHistoryDO.getInitialDesignStage()); // 初设阶段收款比例
BigDecimal constructionDrawingStage = parseRate(receivablesHistoryDO.getConstructionDrawingStage()); // 施工图阶段比例
BigDecimal constructionStage = parseRate(receivablesHistoryDO.getConstructionStage()); // 施工配合收款比例
BigDecimal approveStage = parseRate(receivablesHistoryDO.getApproveStage()); // 审定阶段
amount = switch (projectSchedule.getStage()) {
case "方案设计" -> receivableAccount.multiply(planStage);
case "初步设计" -> receivableAccount.multiply(initialDesignStage);
case "施工图" -> receivableAccount.multiply(constructionDrawingStage);
case "施工配合" -> receivableAccount.multiply(constructionStage);
case "竣工" -> receivableAccount.multiply(approveStage);
default -> BigDecimal.ZERO;
};
receivablesHistoryRespVO.setContractualReceivables(amount);
BigDecimal collectionAmount = parseRate(receivablesHistoryDO.getCollectionSituation());
BigDecimal differenceAmount = amount.subtract(collectionAmount);
receivablesHistoryRespVO.setReceivableDifference(differenceAmount);
return receivablesHistoryRespVO;
}
@Override
public PageResult<ReceivablesHistoryDO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO) {
return receivablesHistoryMapper.selectPage(pageReqVO);
public PageResult<ReceivablesHistoryRespVO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO) {
// 校验
if (pageReqVO == null) {
throw exception(PARAM_NOT_EXISTS);
}
Long projectId = pageReqVO.getProjectId();
ProjectRespDTO project = projectApi.getProject(projectId);
if (project == null) {
throw exception(PROJECT_NOT_EXISTS);
}
Long contractId = pageReqVO.getContractId();
ContractRespDTO contract = contractApi.getContract(contractId);
if (contract == null) {
throw exception(CONTRACT_NOT_EXISTS);
}
PageResult<ReceivablesHistoryDO> receivablesHistoryDOPageResult = receivablesHistoryMapper.selectPage(pageReqVO);
List<ReceivablesHistoryDO> pageResultList = receivablesHistoryDOPageResult.getList();
List<ReceivablesHistoryRespVO> receivablesHistoryRespVOS = new ArrayList<>();
for (ReceivablesHistoryDO receivablesHistoryDO : pageResultList) {
Long id = receivablesHistoryDO.getId();
ReceivablesHistoryRespVO receivablesHistory = getReceivablesHistory(id);
receivablesHistoryRespVOS.add(receivablesHistory);
}
PageResult<ReceivablesHistoryRespVO> pageResult = new PageResult<>();
pageResult.setList(receivablesHistoryRespVOS);
return pageResult;
}
private BigDecimal parseRate(String rateStr) {
// 将字符串转换为 BigDecimal处理可能的 null 和格式错误
try {
return (rateStr == null || rateStr.trim().isEmpty()) ? BigDecimal.ZERO : new BigDecimal(rateStr);
} catch (NumberFormatException e) {
// 如果字符串格式错误返回零
return BigDecimal.ZERO;
}
}
}