[fix] 优化应收款管理功能

This commit is contained in:
shl
2024-08-21 11:08:52 +08:00
parent 5a6c76f8cb
commit 84a030dc71
16 changed files with 329 additions and 95 deletions

View File

@ -16,4 +16,20 @@ public class ContractDTO {
* 包干审定金额
*/
private BigDecimal approvedAmount;
/**
* 项目编号
*/
private String code;
/**
* 合同名称
*/
private String name;
/**
* 签订合同总额
*/
private BigDecimal amount;
}

View File

@ -26,10 +26,12 @@ public class ContractDetailDO extends ContractDO {
* 出图公司
*/
private String drawingCompany;
/**
* 预计公司合同总金额
*/
private BigDecimal expectedContractAmount;
/**
* 项目负责人
*/

View File

@ -32,7 +32,10 @@ public interface ErrorCodeConstants {
// ========== 项目追踪信息不存在 1_026_000_000 ==========
ErrorCode PROJECT_TRACKING_NOT_EXISTS = new ErrorCode(1_026_000_000, "项目跟踪管理不存在");
// ========== 项目追踪信息存在 1_027_000_000 ==========
// ========== 项目追踪信息存在 1_027_000_000 ==========
ErrorCode BUDGET_ALREADY_EXISTS = new ErrorCode(1_027_000_000, "预算管理已存在");
// ========== 项目追踪信息已存在 1_027_000_000 ==========
ErrorCode RECEIVABLES_ALREADY_EXISTS = new ErrorCode(1_028_000_000, "应收款管理已存在");
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pms.controller.admin.receivables;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivables.ReceivablesDetailDO;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -24,6 +25,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.receivables.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivables.ReceivablesDO;
@ -42,14 +44,14 @@ public class ReceivablesController {
@Operation(summary = "创建应收款管理")
@PreAuthorize("@ss.hasPermission('pms:receivables:create')")
public CommonResult<Long> createReceivables(@Valid @RequestBody ReceivablesSaveReqVO createReqVO) {
return success(receivablesService.createReceivables(createReqVO));
return success(receivablesService.createReceivables(getLoginUserId(), createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新应收款管理")
@PreAuthorize("@ss.hasPermission('pms:receivables:update')")
public CommonResult<Boolean> updateReceivables(@Valid @RequestBody ReceivablesSaveReqVO updateReqVO) {
receivablesService.updateReceivables(updateReqVO);
receivablesService.updateReceivables(getLoginUserId(), updateReqVO);
return success(true);
}
@ -67,16 +69,18 @@ public class ReceivablesController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pms:receivables:query')")
public CommonResult<ReceivablesRespVO> getReceivables(@RequestParam("id") Long id) {
ReceivablesDO receivables = receivablesService.getReceivables(id);
return success(BeanUtils.toBean(receivables, ReceivablesRespVO.class));
ReceivablesDetailDO receivablesDetail = receivablesService.getReceivablesDetail(id);
ReceivablesRespVO receivablesRespVO = new ReceivablesRespVO();
org.springframework.beans.BeanUtils.copyProperties(receivablesDetail, receivablesRespVO);
return success(receivablesRespVO);
}
@GetMapping("/page")
@Operation(summary = "获得应收款管理分页")
@PreAuthorize("@ss.hasPermission('pms:receivables:query')")
public CommonResult<PageResult<ReceivablesRespVO>> getReceivablesPage(@Valid ReceivablesPageReqVO pageReqVO) {
PageResult<ReceivablesDO> pageResult = receivablesService.getReceivablesPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ReceivablesRespVO.class));
PageResult<ReceivablesRespVO> pageResult = receivablesService.getReceivablesPage(pageReqVO);
return success(pageResult);
}
@GetMapping("/export-excel")
@ -86,7 +90,7 @@ public class ReceivablesController {
public void exportReceivablesExcel(@Valid ReceivablesPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ReceivablesDO> list = receivablesService.getReceivablesPage(pageReqVO).getList();
List<ReceivablesRespVO> list = receivablesService.getReceivablesPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "应收款管理.xls", "数据", ReceivablesRespVO.class,
BeanUtils.toBean(list, ReceivablesRespVO.class));

View File

@ -18,29 +18,7 @@ public class ReceivablesPageReqVO extends PageParam {
@Schema(description = "项目id")
private Long projectId;
@Schema(description = "主合同id ")
@Schema(description = "主合同id")
private Long contractId;
@Schema(description = "方案阶段比例")
private String planStage;
@Schema(description = "初设阶段比例")
private String initialDesignStage;
@Schema(description = "施工图阶段比例")
private String constructionDrawingStage;
@Schema(description = "施工配合阶段")
private String constructionStage;
@Schema(description = "审定阶段")
private String approveStage;
@Schema(description = "回款情况")
private String collectionSituation;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.pms.controller.admin.receivables.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,28 @@ import com.alibaba.excel.annotation.*;
@ExcelIgnoreUnannotated
public class ReceivablesRespVO {
@Schema(description = "项目编号", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("项目编号")
private String code;
@Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("合同名称")
private String name;
@Schema(description = "签订合同总额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("签订合同总额")
private BigDecimal amount;
@Schema(description = "审定金额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("审定金额")
private BigDecimal approvedAmount;
@Schema(description = "已完成的项目阶段", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("已完成的项目阶段")
private String preStage;
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("主键")
private Long id;

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.pms.controller.admin.receivables.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,28 @@ import jakarta.validation.constraints.*;
@Data
public class ReceivablesSaveReqVO {
@Schema(description = "项目编号", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("项目编号")
private String code;
@Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("合同名称")
private String name;
@Schema(description = "签订合同总额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("签订合同总额")
private BigDecimal amount;
@Schema(description = "审定金额", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("审定金额")
private BigDecimal approvedAmount;
@Schema(description = "已完成的项目阶段", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("已完成的项目阶段")
private String preStage;
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED)
private Long id;

View File

@ -5,12 +5,6 @@ import lombok.Data;
import java.time.LocalDateTime;
/**
* @author wyw
* @description
* @date 2024/8/14
*/
@Data
public class ProjectScheduleDetailDO extends ProjectDO {
@ -23,4 +17,5 @@ public class ProjectScheduleDetailDO extends ProjectDO {
* 外部合同商议时间
*/
private LocalDateTime exReminderTime;
}

View File

@ -9,8 +9,6 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 应收款管理 DO
*
* @author zqc
*/
@TableName("pms_receivables")
@KeySequence("pms_receivables_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pms.dal.dataobject.receivables;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ReceivablesDetailDO extends ReceivablesDO {
/**
* 项目编号
*/
private String code;
/**
* 合同名称
*/
private String name;
/**
* 签订合同总额
*/
private BigDecimal amount;
/**
* 审定金额
*/
private BigDecimal approvedAmount;
/**
* 已完成的项目阶段
*/
private String preStage;
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivables.ReceivablesDO;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ReceivablesHistoryDetailDO extends ReceivablesHistoryDO {
/**
* 项目编号
*/
private String code;
/**
* 合同名称
*/
private String name;
/**
* 签订合同总额
*/
private BigDecimal amount;
/**
* 审定金额
*/
private BigDecimal approvedAmount;
/**
* 已完成的项目阶段
*/
private String preStage;
}

View File

@ -21,13 +21,13 @@ public interface ReceivablesMapper extends BaseMapperX<ReceivablesDO> {
return selectPage(reqVO, new LambdaQueryWrapperX<ReceivablesDO>()
.eqIfPresent(ReceivablesDO::getProjectId, reqVO.getProjectId())
.eqIfPresent(ReceivablesDO::getContractId, reqVO.getContractId())
.eqIfPresent(ReceivablesDO::getPlanStage, reqVO.getPlanStage())
.eqIfPresent(ReceivablesDO::getInitialDesignStage, reqVO.getInitialDesignStage())
.eqIfPresent(ReceivablesDO::getConstructionDrawingStage, reqVO.getConstructionDrawingStage())
.eqIfPresent(ReceivablesDO::getConstructionStage, reqVO.getConstructionStage())
.eqIfPresent(ReceivablesDO::getApproveStage, reqVO.getApproveStage())
.eqIfPresent(ReceivablesDO::getCollectionSituation, reqVO.getCollectionSituation())
.betweenIfPresent(ReceivablesDO::getCreateTime, reqVO.getCreateTime())
// .eqIfPresent(ReceivablesDO::getPlanStage, reqVO.getPlanStage())
// .eqIfPresent(ReceivablesDO::getInitialDesignStage, reqVO.getInitialDesignStage())
// .eqIfPresent(ReceivablesDO::getConstructionDrawingStage, reqVO.getConstructionDrawingStage())
// .eqIfPresent(ReceivablesDO::getConstructionStage, reqVO.getConstructionStage())
// .eqIfPresent(ReceivablesDO::getApproveStage, reqVO.getApproveStage())
// .eqIfPresent(ReceivablesDO::getCollectionSituation, reqVO.getCollectionSituation())
// .betweenIfPresent(ReceivablesDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ReceivablesDO::getId));
}

View File

@ -57,6 +57,12 @@ public interface ProjectScheduleService {
*/
ProjectScheduleDO getProjectScheduleDetail(Long projectId);
/**
* 判断项目是否存在
* @param id
*/
void validateProjectExists(Long id);
}

View File

@ -80,6 +80,12 @@ public class ProjectScheduleServiceImpl implements ProjectScheduleService {
return projectScheduleDOS.get(0);
}
@Override
public void validateProjectExists(Long id) {
if (projectScheduleMapper.selectById(id) == null) {
throw exception(PROJECT_NOT_EXISTS);
}
}
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.pms.service.receivables;
import java.util.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivables.ReceivablesDetailDO;
import jakarta.validation.*;
import cn.iocoder.yudao.module.pms.controller.admin.receivables.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivables.ReceivablesDO;
@ -14,42 +16,16 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
*/
public interface ReceivablesService {
/**
* 创建应收款管理
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createReceivables(@Valid ReceivablesSaveReqVO createReqVO);
Long createReceivables(Long loginUserId, @Valid ReceivablesSaveReqVO createReqVO);
/**
* 更新应收款管理
*
* @param updateReqVO 更新信息
*/
void updateReceivables(@Valid ReceivablesSaveReqVO updateReqVO);
void updateReceivables(Long loginUserId, @Valid ReceivablesSaveReqVO updateReqVO);
/**
* 删除应收款管理
*
* @param id 编号
*/
void deleteReceivables(Long id);
/**
* 获得应收款管理
*
* @param id 编号
* @return 应收款管理
*/
ReceivablesDO getReceivables(Long id);
ReceivablesDetailDO getReceivablesDetail(Long id);
/**
* 获得应收款管理分页
*
* @param pageReqVO 分页查询
* @return 应收款管理分页
*/
PageResult<ReceivablesDO> getReceivablesPage(ReceivablesPageReqVO pageReqVO);
PageResult<ReceivablesRespVO> getReceivablesPage(ReceivablesPageReqVO pageReqVO);
void validReceivablesExists(Long id);
}

View File

@ -1,5 +1,18 @@
package cn.iocoder.yudao.module.pms.service.receivables;
import cn.hutool.core.bean.BeanUtil;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.cms.api.contract.ContractApi;
import cn.iocoder.yudao.module.cms.api.contract.dto.ContractDTO;
import cn.iocoder.yudao.module.pms.controller.admin.budget.vo.BudgetRespVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.budget.BudgetDetailDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.projectschedule.ProjectScheduleDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivables.ReceivablesDetailDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDO;
import cn.iocoder.yudao.module.pms.dal.mysql.receivableshistory.ReceivablesHistoryMapper;
import cn.iocoder.yudao.module.pms.service.projectschedule.ProjectScheduleService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -16,59 +29,178 @@ import cn.iocoder.yudao.module.pms.dal.mysql.receivables.ReceivablesMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
/**
* 应收款管理 Service 实现类
*
* @author zqc
*/
@Service
@Validated
public class ReceivablesServiceImpl implements ReceivablesService {
/**
* 应收款管理流程定义
*/
public static final String PROCESS_KEY = "receivables_init";
/**
* 版本
*/
public static String VERSION = "1";
@Resource
private ReceivablesMapper receivablesMapper;
@Resource
private AdminUserApi adminUserApi;
@Resource
private ContractApi contractApi;
@Resource
private ProjectScheduleService projectScheduleService;
@Resource
private BpmProcessInstanceApi processInstanceApi;
@Resource
private ReceivablesHistoryMapper receivablesHistoryMapper;
@Override
public Long createReceivables(ReceivablesSaveReqVO createReqVO) {
public Long createReceivables(Long loginUserId, ReceivablesSaveReqVO createReqVO) {
// 校验
String userName = adminUserApi.getUser(loginUserId).getNickname();
if (userName == null) {
throw exception(USER_NOT_EXISTS);
}
Long contractId = createReqVO.getContractId();
Long projectId = createReqVO.getProjectId();
contractApi.validContractExists(contractId);
projectScheduleService.validateProjectExists(projectId);
Long id = createReqVO.getId();
List<ReceivablesDO> receivablesList = receivablesMapper.selectList("project_id", projectId);
for (ReceivablesDO receivablesDO : receivablesList) {
if (Objects.equals(receivablesDO.getId(), id)) {
throw exception(RECEIVABLES_ALREADY_EXISTS);
}
}
// 插入
ReceivablesDO receivables = BeanUtils.toBean(createReqVO, ReceivablesDO.class);
receivables.setCreator(userName);
receivables.setUpdater(userName);
receivablesMapper.insert(receivables);
Long receivablesId = receivables.getId();
ReceivablesHistoryDO receivablesHistory = BeanUtils.toBean(receivables, ReceivablesHistoryDO.class);
// 启动流程,写入历史应收款
if (id == null) {
String processInstanceId = processInstanceApi.createProcessInstance(loginUserId,
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
.setBusinessKey(String.valueOf(receivablesId)));
// 写入工作流编号
receivablesHistoryMapper.updateById(receivablesHistory.setReceivableId(receivablesId)
.setProcessInstanceId(processInstanceId));
// 写入版本号
Long count = receivablesHistoryMapper.selectCount("project_id", projectId);
if (count < 1) {
receivablesHistory.setVersion(VERSION);
} else {
receivablesHistory.setVersion(String.valueOf(count + 1));
}
// 写入流程状态
receivablesHistory.setProcessStatus("0");
// 插入历史应收款
receivablesHistoryMapper.insert(receivablesHistory);
}
// 返回
return receivables.getId();
}
@Override
public void updateReceivables(ReceivablesSaveReqVO updateReqVO) {
public void updateReceivables(Long loginUserId, ReceivablesSaveReqVO updateReqVO) {
// 校验存在
validateReceivablesExists(updateReqVO.getId());
validReceivablesExists(updateReqVO.getId());
projectScheduleService.validateProjectExists(updateReqVO.getProjectId());
contractApi.validContractExists(updateReqVO.getContractId());
// 更新
ReceivablesDO updateObj = BeanUtils.toBean(updateReqVO, ReceivablesDO.class);
String userName = adminUserApi.getUser(loginUserId).getNickname();
if (userName == null) {
throw exception(USER_NOT_EXISTS);
}
updateObj.setUpdater(userName);
receivablesMapper.updateById(updateObj);
}
@Override
public void deleteReceivables(Long id) {
// 校验存在
validateReceivablesExists(id);
validReceivablesExists(id);
// 删除
receivablesMapper.deleteById(id);
}
private void validateReceivablesExists(Long id) {
@Override
public ReceivablesDetailDO getReceivablesDetail(Long id) {
ReceivablesDetailDO receivablesDetailDO = new ReceivablesDetailDO();
ReceivablesDO receivablesDO = receivablesMapper.selectById(id);
if (receivablesDO == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
// 校验
Long contractId = receivablesDO.getContractId();
Long projectId = receivablesDO.getProjectId();
contractApi.validContractExists(contractId);
projectScheduleService.validateProjectExists(projectId);
ProjectScheduleDO projectSchedule = projectScheduleService.getProjectSchedule(projectId);
ContractDTO contractDTO = contractApi.getContractDTO(contractId);
receivablesDetailDO.setPreStage(projectSchedule.getPreStage());
BeanUtil.copyProperties(receivablesDO, receivablesDetailDO);
BeanUtil.copyProperties(projectSchedule, receivablesDetailDO);
BeanUtil.copyProperties(contractDTO, receivablesDetailDO);
return receivablesDetailDO;
}
@Override
public PageResult<ReceivablesRespVO> getReceivablesPage(ReceivablesPageReqVO pageReqVO) {
PageResult<ReceivablesDO> receivablesDOPageResult = receivablesMapper.selectPage(pageReqVO);
List<ReceivablesDO> receivablesDOList = receivablesDOPageResult.getList();
List<ReceivablesDetailDO> receivablesDetailDOList =new ArrayList<>();
for (ReceivablesDO receivablesDO : receivablesDOList) {
Long id = receivablesDO.getId();
ReceivablesDetailDO receivablesDetail = getReceivablesDetail(id);
receivablesDetailDOList.add(receivablesDetail);
}
List<ReceivablesRespVO> respVOList = BeanUtils.toBean(receivablesDetailDOList, ReceivablesRespVO.class);
PageResult<ReceivablesRespVO> pageResult = new PageResult<>();
pageResult.setList(respVOList);
return pageResult;
}
@Override
public void validReceivablesExists(Long id) {
if (receivablesMapper.selectById(id) == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
}
@Override
public ReceivablesDO getReceivables(Long id) {
return receivablesMapper.selectById(id);
}
@Override
public PageResult<ReceivablesDO> getReceivablesPage(ReceivablesPageReqVO pageReqVO) {
return receivablesMapper.selectPage(pageReqVO);
}
}