Commit 332eb30b6c9feca37be612a5bb9424e9b3573804

Authored by YunaiV
1 parent 91c17902

✨ CRM:完善回款列表

yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java
... ... @@ -4,20 +4,23 @@ import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
5 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
7 8 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
8 9 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
9 10 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
10 11 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  12 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
11 13 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO;
12 14 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
13 15 import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableSaveReqVO;
14   -import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivableConvert;
15 16 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
16 17 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
17 18 import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
18 19 import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
19 20 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
20 21 import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
  22 +import cn.iocoder.yudao.module.system.api.dept.DeptApi;
  23 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
21 24 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
22 25 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
23 26 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -31,6 +34,7 @@ import org.springframework.validation.annotation.Validated;
31 34 import org.springframework.web.bind.annotation.*;
32 35  
33 36 import java.io.IOException;
  37 +import java.util.Collections;
34 38 import java.util.List;
35 39 import java.util.Map;
36 40 import java.util.stream.Stream;
... ... @@ -39,6 +43,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
39 43 import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
40 44 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
41 45 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  46 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
42 47 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
43 48 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
44 49  
... ... @@ -57,6 +62,8 @@ public class CrmReceivableController {
57 62  
58 63 @Resource
59 64 private AdminUserApi adminUserApi;
  65 + @Resource
  66 + private DeptApi deptApi;
60 67  
61 68 @PostMapping("/create")
62 69 @Operation(summary = "创建回款")
... ... @@ -96,7 +103,7 @@ public class CrmReceivableController {
96 103 @PreAuthorize("@ss.hasPermission('crm:receivable:query')")
97 104 public CommonResult<PageResult<CrmReceivableRespVO>> getReceivablePage(@Valid CrmReceivablePageReqVO pageReqVO) {
98 105 PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePage(pageReqVO, getLoginUserId());
99   - return success(buildReceivableDetailPage(pageResult));
  106 + return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
100 107 }
101 108  
102 109 @GetMapping("/page-by-customer")
... ... @@ -104,7 +111,7 @@ public class CrmReceivableController {
104 111 public CommonResult<PageResult<CrmReceivableRespVO>> getReceivablePageByCustomer(@Valid CrmReceivablePageReqVO pageReqVO) {
105 112 Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空");
106 113 PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePageByCustomerId(pageReqVO);
107   - return success(buildReceivableDetailPage(pageResult));
  114 + return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
108 115 }
109 116  
110 117 @GetMapping("/export-excel")
... ... @@ -114,33 +121,41 @@ public class CrmReceivableController {
114 121 public void exportReceivableExcel(@Valid CrmReceivablePageReqVO exportReqVO,
115 122 HttpServletResponse response) throws IOException {
116 123 exportReqVO.setPageSize(PAGE_SIZE_NONE);
117   - PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePage(exportReqVO, getLoginUserId());
  124 + List<CrmReceivableDO> list = receivableService.getReceivablePage(exportReqVO, getLoginUserId()).getList();
118 125 // 导出 Excel
119 126 ExcelUtils.write(response, "回款.xls", "数据", CrmReceivableRespVO.class,
120   - buildReceivableDetailPage(pageResult).getList());
  127 + buildReceivableDetailList(list));
121 128 }
122 129  
123   - /**
124   - * 构建详细的回款分页结果
125   - *
126   - * @param pageResult 简单的回款分页结果
127   - * @return 详细的回款分页结果
128   - */
129   - private PageResult<CrmReceivableRespVO> buildReceivableDetailPage(PageResult<CrmReceivableDO> pageResult) {
130   - List<CrmReceivableDO> receivableList = pageResult.getList();
  130 + private List<CrmReceivableRespVO> buildReceivableDetailList(List<CrmReceivableDO> receivableList) {
131 131 if (CollUtil.isEmpty(receivableList)) {
132   - return PageResult.empty(pageResult.getTotal());
  132 + return Collections.emptyList();
133 133 }
134   - // 1. 获取客户列表
135   - List<CrmCustomerDO> customerList = customerService.getCustomerList(
  134 + // 1.1 获取客户列表
  135 + Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap(
136 136 convertSet(receivableList, CrmReceivableDO::getCustomerId));
137   - // 2. 获取创建人、负责人列表
  137 + // 1.2 获取创建人、负责人列表
138 138 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(receivableList,
139 139 contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
140   - // 3. 获得合同列表
141   - List<CrmContractDO> contractList = contractService.getContractList(
  140 + Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
  141 + // 1.3 获得合同列表
  142 + Map<Long, CrmContractDO> contractMap = contractService.getContractMap(
142 143 convertSet(receivableList, CrmReceivableDO::getContractId));
143   - return CrmReceivableConvert.INSTANCE.convertPage(pageResult, userMap, customerList, contractList);
  144 + // 2. 拼接结果
  145 + return BeanUtils.toBean(receivableList, CrmReceivableRespVO.class, (receivableVO) -> {
  146 + // 2.1 拼接客户名称
  147 + findAndThen(customerMap, receivableVO.getCustomerId(), customer -> receivableVO.setCustomerName(customer.getName()));
  148 + // 2.2 拼接负责人、创建人名称
  149 + MapUtils.findAndThen(userMap, NumberUtils.parseLong(receivableVO.getCreator()),
  150 + user -> receivableVO.setCreatorName(user.getNickname()));
  151 + MapUtils.findAndThen(userMap, receivableVO.getOwnerUserId(), user -> {
  152 + receivableVO.setOwnerUserName(user.getNickname());
  153 + MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> receivableVO.setOwnerUserDeptName(dept.getName()));
  154 + });
  155 + // 2.3 拼接合同信息
  156 + findAndThen(contractMap, receivableVO.getContractId(), contract ->
  157 + receivableVO.setContract(BeanUtils.toBean(contract, CrmContractRespVO.class)));
  158 + });
144 159 }
145 160  
146 161  
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/vo/receivable/CrmReceivableRespVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable;
2 2  
  3 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
  4 +import com.alibaba.excel.annotation.ExcelProperty;
3 5 import io.swagger.v3.oas.annotations.media.Schema;
4 6 import lombok.Data;
5 7  
... ... @@ -31,12 +33,23 @@ public class CrmReceivableRespVO {
31 33  
32 34 @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
33 35 private Long customerId;
  36 + @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
  37 + private String customerName;
34 38  
35 39 @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
36 40 private Long contractId;
  41 + @Schema(description = "合同信息")
  42 + private CrmContractRespVO contract;
37 43  
38   - @Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  44 + @Schema(description = "负责人的用户编号", example = "25682")
  45 + @ExcelProperty("负责人的用户编号")
39 46 private Long ownerUserId;
  47 + @Schema(description = "负责人名字", example = "25682")
  48 + @ExcelProperty("负责人名字")
  49 + private String ownerUserName;
  50 + @Schema(description = "负责人部门")
  51 + @ExcelProperty("负责人部门")
  52 + private String ownerUserDeptName;
40 53  
41 54 @Schema(description = "备注", example = "备注")
42 55 private String remark;
... ... @@ -44,21 +57,11 @@ public class CrmReceivableRespVO {
44 57 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
45 58 private LocalDateTime createTime;
46 59  
47   - @Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
48   - private String customerName;
49   -
50 60 @Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
51 61 private Integer auditStatus;
52 62  
53   - @Schema(description = "合同编号", example = "Q110")
54   - private String contractNo;
55   -
56   - @Schema(description = "负责人", example = "test")
57   - private String ownerUserName;
58   -
59 63 @Schema(description = "创建人", example = "25682")
60 64 private String creator;
61   -
62 65 @Schema(description = "创建人名字", example = "test")
63 66 private String creatorName;
64 67  
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/receivable/CrmReceivableConvert.java deleted
1   -package cn.iocoder.yudao.module.crm.convert.receivable;
2   -
3   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5   -import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
6   -import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
7   -import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
8   -import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
9   -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
10   -import org.mapstruct.Mapper;
11   -import org.mapstruct.factory.Mappers;
12   -
13   -import java.util.List;
14   -import java.util.Map;
15   -
16   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
17   -import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
18   -
19   -/**
20   - * 回款 Convert
21   - *
22   - * @author 赤焰
23   - */
24   -@Mapper
25   -public interface CrmReceivableConvert {
26   -
27   - CrmReceivableConvert INSTANCE = Mappers.getMapper(CrmReceivableConvert.class);
28   -
29   - default PageResult<CrmReceivableRespVO> convertPage(PageResult<CrmReceivableDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
30   - List<CrmCustomerDO> customerList, List<CrmContractDO> contractList) {
31   - PageResult<CrmReceivableRespVO> voPageResult = BeanUtils.toBean(pageResult, CrmReceivableRespVO.class);
32   - // 拼接关联字段
33   - Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId);
34   - Map<Long, CrmContractDO> contractMap = convertMap(contractList, CrmContractDO::getId);
35   - voPageResult.getList().forEach(receivable -> {
36   - findAndThen(userMap, receivable.getOwnerUserId(), user -> receivable.setOwnerUserName(user.getNickname()));
37   - findAndThen(userMap, Long.parseLong(receivable.getCreator()), user -> receivable.setCreatorName(user.getNickname()));
38   - findAndThen(customerMap, receivable.getCustomerId(), customer -> receivable.setCustomerName(customer.getName()));
39   - findAndThen(contractMap, receivable.getContractId(), contract -> receivable.setContractNo(contract.getNo()));
40   - });
41   - return voPageResult;
42   - }
43   -
44   -}