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

This commit is contained in:
shl 2024-08-21 15:24:29 +08:00
parent 84a030dc71
commit 7c4cea094d
7 changed files with 154 additions and 110 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pms.controller.admin.receivableshistory;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDetailDO;
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.receivableshistory.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDO;
@ -38,27 +40,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);
receivablesHistoryService.updateReceivablesHistory(getLoginUserId(), updateReqVO);
return success(true);
}
@ -67,16 +53,18 @@ 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));
ReceivablesHistoryDetailDO receivablesHistoryDetail = receivablesHistoryService.getReceivablesHistoryDetail(id);
ReceivablesHistoryRespVO receivablesHistoryRespVO = new ReceivablesHistoryRespVO();
org.springframework.beans.BeanUtils.copyProperties(receivablesHistoryDetail, receivablesHistoryRespVO);
return success(receivablesHistoryRespVO);
}
@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 +74,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

@ -21,38 +21,4 @@ public class ReceivablesHistoryPageReqVO extends PageParam {
@Schema(description = "主合同id ", example = "5479")
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;
@Schema(description = "流程实体id", example = "4399")
private String processInstanceId;
@Schema(description = "流程状态", example = "1")
private String processStatus;
@Schema(description = "应收款id", example = "22335")
private Long receivableId;
@Schema(description = "版本")
private String version;
}

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,28 @@ import com.alibaba.excel.annotation.*;
@ExcelIgnoreUnannotated
public class ReceivablesHistoryRespVO {
@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, 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,28 @@ import jakarta.validation.constraints.*;
@Data
public class ReceivablesHistorySaveReqVO {
@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, example = "20822")
private Long id;

View File

@ -21,17 +21,17 @@ public interface ReceivablesHistoryMapper extends BaseMapperX<ReceivablesHistory
return selectPage(reqVO, new LambdaQueryWrapperX<ReceivablesHistoryDO>()
.eqIfPresent(ReceivablesHistoryDO::getProjectId, reqVO.getProjectId())
.eqIfPresent(ReceivablesHistoryDO::getContractId, reqVO.getContractId())
.eqIfPresent(ReceivablesHistoryDO::getPlanStage, reqVO.getPlanStage())
.eqIfPresent(ReceivablesHistoryDO::getInitialDesignStage, reqVO.getInitialDesignStage())
.eqIfPresent(ReceivablesHistoryDO::getConstructionDrawingStage, reqVO.getConstructionDrawingStage())
.eqIfPresent(ReceivablesHistoryDO::getConstructionStage, reqVO.getConstructionStage())
.eqIfPresent(ReceivablesHistoryDO::getApproveStage, reqVO.getApproveStage())
.eqIfPresent(ReceivablesHistoryDO::getCollectionSituation, reqVO.getCollectionSituation())
.betweenIfPresent(ReceivablesHistoryDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(ReceivablesHistoryDO::getProcessInstanceId, reqVO.getProcessInstanceId())
.eqIfPresent(ReceivablesHistoryDO::getProcessStatus, reqVO.getProcessStatus())
.eqIfPresent(ReceivablesHistoryDO::getReceivableId, reqVO.getReceivableId())
.eqIfPresent(ReceivablesHistoryDO::getVersion, reqVO.getVersion())
// .eqIfPresent(ReceivablesHistoryDO::getPlanStage, reqVO.getPlanStage())
// .eqIfPresent(ReceivablesHistoryDO::getInitialDesignStage, reqVO.getInitialDesignStage())
// .eqIfPresent(ReceivablesHistoryDO::getConstructionDrawingStage, reqVO.getConstructionDrawingStage())
// .eqIfPresent(ReceivablesHistoryDO::getConstructionStage, reqVO.getConstructionStage())
// .eqIfPresent(ReceivablesHistoryDO::getApproveStage, reqVO.getApproveStage())
// .eqIfPresent(ReceivablesHistoryDO::getCollectionSituation, reqVO.getCollectionSituation())
// .betweenIfPresent(ReceivablesHistoryDO::getCreateTime, reqVO.getCreateTime())
// .eqIfPresent(ReceivablesHistoryDO::getProcessInstanceId, reqVO.getProcessInstanceId())
// .eqIfPresent(ReceivablesHistoryDO::getProcessStatus, reqVO.getProcessStatus())
// .eqIfPresent(ReceivablesHistoryDO::getReceivableId, reqVO.getReceivableId())
// .eqIfPresent(ReceivablesHistoryDO::getVersion, reqVO.getVersion())
.orderByDesc(ReceivablesHistoryDO::getId));
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.pms.service.receivableshistory;
import java.util.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDetailDO;
import jakarta.validation.*;
import cn.iocoder.yudao.module.pms.controller.admin.receivableshistory.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDO;
@ -14,27 +16,14 @@ 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);
void updateReceivablesHistory(Long loginUserId, @Valid ReceivablesHistorySaveReqVO updateReqVO);
/**
* 删除应收款管理历史记录
*
* @param id 编号
*/
void deleteReceivablesHistory(Long id);
/**
* 获得应收款管理历史记录
@ -42,7 +31,7 @@ public interface ReceivablesHistoryService {
* @param id 编号
* @return 应收款管理历史记录
*/
ReceivablesHistoryDO getReceivablesHistory(Long id);
ReceivablesHistoryDetailDO getReceivablesHistoryDetail(Long id);
/**
* 获得应收款管理历史记录分页
@ -50,6 +39,6 @@ public interface ReceivablesHistoryService {
* @param pageReqVO 分页查询
* @return 应收款管理历史记录分页
*/
PageResult<ReceivablesHistoryDO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO);
PageResult<ReceivablesHistoryRespVO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO);
}

View File

@ -1,5 +1,12 @@
package cn.iocoder.yudao.module.pms.service.receivableshistory;
import cn.hutool.core.bean.BeanUtil;
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.dal.dataobject.projectschedule.ProjectScheduleDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDetailDO;
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;
@ -9,19 +16,19 @@ import java.util.*;
import cn.iocoder.yudao.module.pms.controller.admin.receivableshistory.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.receivableshistory.ReceivablesHistoryDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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.PARAM_NOT_EXISTS;
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 ReceivablesHistoryServiceImpl implements ReceivablesHistoryService {
@ -29,30 +36,85 @@ 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 AdminUserApi adminUserApi;
@Resource
private ContractApi contractApi;
@Resource
private ProjectScheduleService projectScheduleService;
@Override
public void updateReceivablesHistory(ReceivablesHistorySaveReqVO updateReqVO) {
public void updateReceivablesHistory(Long loginUserId, ReceivablesHistorySaveReqVO updateReqVO) {
// 校验存在
validateReceivablesHistoryExists(updateReqVO.getId());
projectScheduleService.validateProjectExists(updateReqVO.getProjectId());
contractApi.validContractExists(updateReqVO.getContractId());
// 更新
ReceivablesHistoryDO updateObj = BeanUtils.toBean(updateReqVO, ReceivablesHistoryDO.class);
String userName = adminUserApi.getUser(loginUserId).getNickname();
if (userName == null) {
throw exception(USER_NOT_EXISTS);
}
updateObj.setUpdater(userName);
receivablesHistoryMapper.updateById(updateObj);
}
@Override
public void deleteReceivablesHistory(Long id) {
// 校验存在
validateReceivablesHistoryExists(id);
// 删除
receivablesHistoryMapper.deleteById(id);
public ReceivablesHistoryDetailDO getReceivablesHistoryDetail(Long id) {
// 校验
if (id == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
ReceivablesHistoryDO receivablesHistoryDO = receivablesHistoryMapper.selectById(id);
if (receivablesHistoryDO == null) {
throw exception(RECEIVABLES_NOT_EXISTS);
}
Long contractId = receivablesHistoryDO.getContractId();
Long projectId = receivablesHistoryDO.getProjectId();
projectScheduleService.validateProjectExists(projectId);
contractApi.validContractExists(contractId);
ReceivablesHistoryDetailDO receivablesHistoryDetailDO = new ReceivablesHistoryDetailDO();
ProjectScheduleDO projectSchedule = projectScheduleService.getProjectSchedule(projectId);
ContractDTO contractDTO = contractApi.getContractDTO(contractId);
receivablesHistoryDetailDO.setPreStage(projectSchedule.getPreStage());
BeanUtil.copyProperties(receivablesHistoryDO,receivablesHistoryDetailDO);
BeanUtil.copyProperties(projectSchedule,receivablesHistoryDetailDO);
BeanUtil.copyProperties(contractDTO,receivablesHistoryDetailDO);
return receivablesHistoryDetailDO;
}
@Override
public PageResult<ReceivablesHistoryRespVO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO) {
// 校验
if (pageReqVO == null) {
throw exception(PARAM_NOT_EXISTS);
}
PageResult<ReceivablesHistoryDO> receivablesHistoryDOPageResult = receivablesHistoryMapper.selectPage(pageReqVO);
List<ReceivablesHistoryDO> receivablesHistoryDOList = receivablesHistoryDOPageResult.getList();
List<ReceivablesHistoryDetailDO> receivablesHistoryDetailDOList = new ArrayList<>();
for (ReceivablesHistoryDO receivablesHistoryDO : receivablesHistoryDOList) {
Long id = receivablesHistoryDO.getId();
ReceivablesHistoryDetailDO receivablesHistoryDetail = getReceivablesHistoryDetail(id);
receivablesHistoryDetailDOList.add(receivablesHistoryDetail);
}
List<ReceivablesHistoryRespVO> respVOList = BeanUtils.toBean(receivablesHistoryDetailDOList, ReceivablesHistoryRespVO.class);
PageResult<ReceivablesHistoryRespVO> pageResult = new PageResult<>();
pageResult.setList(respVOList);
return pageResult;
}
private void validateReceivablesHistoryExists(Long id) {
@ -61,14 +123,4 @@ public class ReceivablesHistoryServiceImpl implements ReceivablesHistoryService
}
}
@Override
public ReceivablesHistoryDO getReceivablesHistory(Long id) {
return receivablesHistoryMapper.selectById(id);
}
@Override
public PageResult<ReceivablesHistoryDO> getReceivablesHistoryPage(ReceivablesHistoryPageReqVO pageReqVO) {
return receivablesHistoryMapper.selectPage(pageReqVO);
}
}