mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 09:30:05 +08:00
✨ CRM:完善回款列表
This commit is contained in:
parent
91c179029f
commit
332eb30b6c
@ -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)));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@ -31,12 +33,23 @@ public class CrmReceivableRespVO {
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Long customerId;
|
||||
@Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Long contractId;
|
||||
@Schema(description = "合同信息")
|
||||
private CrmContractRespVO contract;
|
||||
|
||||
@Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@Schema(description = "负责人的用户编号", example = "25682")
|
||||
@ExcelProperty("负责人的用户编号")
|
||||
private Long ownerUserId;
|
||||
@Schema(description = "负责人名字", example = "25682")
|
||||
@ExcelProperty("负责人名字")
|
||||
private String ownerUserName;
|
||||
@Schema(description = "负责人部门")
|
||||
@ExcelProperty("负责人部门")
|
||||
private String ownerUserDeptName;
|
||||
|
||||
@Schema(description = "备注", example = "备注")
|
||||
private String remark;
|
||||
@ -44,21 +57,11 @@ public class CrmReceivableRespVO {
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
private Integer auditStatus;
|
||||
|
||||
@Schema(description = "合同编号", example = "Q110")
|
||||
private String contractNo;
|
||||
|
||||
@Schema(description = "负责人", example = "test")
|
||||
private String ownerUserName;
|
||||
|
||||
@Schema(description = "创建人", example = "25682")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "创建人名字", example = "test")
|
||||
private String creatorName;
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.convert.receivable;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
|
||||
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.system.api.user.dto.AdminUserRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||
|
||||
/**
|
||||
* 回款 Convert
|
||||
*
|
||||
* @author 赤焰
|
||||
*/
|
||||
@Mapper
|
||||
public interface CrmReceivableConvert {
|
||||
|
||||
CrmReceivableConvert INSTANCE = Mappers.getMapper(CrmReceivableConvert.class);
|
||||
|
||||
default PageResult<CrmReceivableRespVO> convertPage(PageResult<CrmReceivableDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
|
||||
List<CrmCustomerDO> customerList, List<CrmContractDO> contractList) {
|
||||
PageResult<CrmReceivableRespVO> voPageResult = BeanUtils.toBean(pageResult, CrmReceivableRespVO.class);
|
||||
// 拼接关联字段
|
||||
Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId);
|
||||
Map<Long, CrmContractDO> contractMap = convertMap(contractList, CrmContractDO::getId);
|
||||
voPageResult.getList().forEach(receivable -> {
|
||||
findAndThen(userMap, receivable.getOwnerUserId(), user -> receivable.setOwnerUserName(user.getNickname()));
|
||||
findAndThen(userMap, Long.parseLong(receivable.getCreator()), user -> receivable.setCreatorName(user.getNickname()));
|
||||
findAndThen(customerMap, receivable.getCustomerId(), customer -> receivable.setCustomerName(customer.getName()));
|
||||
findAndThen(contractMap, receivable.getContractId(), contract -> receivable.setContractNo(contract.getNo()));
|
||||
});
|
||||
return voPageResult;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user