|
@@ -4,20 +4,23 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableSaveReqVO;
|
|
|
-import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivableConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
|
|
|
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
|
|
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
|
|
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
@@ -31,6 +34,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Stream;
|
|
@@ -39,6 +43,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
|
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
|
|
@@ -57,6 +62,8 @@ public class CrmReceivableController {
|
|
|
|
|
|
@Resource
|
|
|
private AdminUserApi adminUserApi;
|
|
|
+ @Resource
|
|
|
+ private DeptApi deptApi;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建回款")
|
|
@@ -96,7 +103,7 @@ public class CrmReceivableController {
|
|
|
@PreAuthorize("@ss.hasPermission('crm:receivable:query')")
|
|
|
public CommonResult<PageResult<CrmReceivableRespVO>> getReceivablePage(@Valid CrmReceivablePageReqVO pageReqVO) {
|
|
|
PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePage(pageReqVO, getLoginUserId());
|
|
|
- return success(buildReceivableDetailPage(pageResult));
|
|
|
+ return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/page-by-customer")
|
|
@@ -104,7 +111,7 @@ public class CrmReceivableController {
|
|
|
public CommonResult<PageResult<CrmReceivableRespVO>> getReceivablePageByCustomer(@Valid CrmReceivablePageReqVO pageReqVO) {
|
|
|
Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空");
|
|
|
PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePageByCustomerId(pageReqVO);
|
|
|
- return success(buildReceivableDetailPage(pageResult));
|
|
|
+ return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/export-excel")
|
|
@@ -114,33 +121,41 @@ public class CrmReceivableController {
|
|
|
public void exportReceivableExcel(@Valid CrmReceivablePageReqVO exportReqVO,
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
exportReqVO.setPageSize(PAGE_SIZE_NONE);
|
|
|
- PageResult<CrmReceivableDO> pageResult = receivableService.getReceivablePage(exportReqVO, getLoginUserId());
|
|
|
+ List<CrmReceivableDO> list = receivableService.getReceivablePage(exportReqVO, getLoginUserId()).getList();
|
|
|
// 导出 Excel
|
|
|
ExcelUtils.write(response, "回款.xls", "数据", CrmReceivableRespVO.class,
|
|
|
- buildReceivableDetailPage(pageResult).getList());
|
|
|
+ buildReceivableDetailList(list));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 构建详细的回款分页结果
|
|
|
- *
|
|
|
- * @param pageResult 简单的回款分页结果
|
|
|
- * @return 详细的回款分页结果
|
|
|
- */
|
|
|
- private PageResult<CrmReceivableRespVO> buildReceivableDetailPage(PageResult<CrmReceivableDO> pageResult) {
|
|
|
- List<CrmReceivableDO> receivableList = pageResult.getList();
|
|
|
+ private List<CrmReceivableRespVO> buildReceivableDetailList(List<CrmReceivableDO> receivableList) {
|
|
|
if (CollUtil.isEmpty(receivableList)) {
|
|
|
- return PageResult.empty(pageResult.getTotal());
|
|
|
+ return Collections.emptyList();
|
|
|
}
|
|
|
- // 1. 获取客户列表
|
|
|
- List<CrmCustomerDO> customerList = customerService.getCustomerList(
|
|
|
+ // 1.1 获取客户列表
|
|
|
+ Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap(
|
|
|
convertSet(receivableList, CrmReceivableDO::getCustomerId));
|
|
|
- // 2. 获取创建人、负责人列表
|
|
|
+ // 1.2 获取创建人、负责人列表
|
|
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(receivableList,
|
|
|
contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
|
|
|
- // 3. 获得合同列表
|
|
|
- List<CrmContractDO> contractList = contractService.getContractList(
|
|
|
+ Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
|
|
+ // 1.3 获得合同列表
|
|
|
+ Map<Long, CrmContractDO> contractMap = contractService.getContractMap(
|
|
|
convertSet(receivableList, CrmReceivableDO::getContractId));
|
|
|
- return CrmReceivableConvert.INSTANCE.convertPage(pageResult, userMap, customerList, contractList);
|
|
|
+ // 2. 拼接结果
|
|
|
+ return BeanUtils.toBean(receivableList, CrmReceivableRespVO.class, (receivableVO) -> {
|
|
|
+ // 2.1 拼接客户名称
|
|
|
+ findAndThen(customerMap, receivableVO.getCustomerId(), customer -> receivableVO.setCustomerName(customer.getName()));
|
|
|
+ // 2.2 拼接负责人、创建人名称
|
|
|
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(receivableVO.getCreator()),
|
|
|
+ user -> receivableVO.setCreatorName(user.getNickname()));
|
|
|
+ MapUtils.findAndThen(userMap, receivableVO.getOwnerUserId(), user -> {
|
|
|
+ receivableVO.setOwnerUserName(user.getNickname());
|
|
|
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> receivableVO.setOwnerUserDeptName(dept.getName()));
|
|
|
+ });
|
|
|
+ // 2.3 拼接合同信息
|
|
|
+ findAndThen(contractMap, receivableVO.getContractId(), contract ->
|
|
|
+ receivableVO.setContract(BeanUtils.toBean(contract, CrmContractRespVO.class)));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|