|
@@ -1,13 +1,22 @@
|
|
|
package cn.iocoder.yudao.module.crm.controller.admin.clue;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
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.clue.vo.*;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
|
|
|
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
import cn.iocoder.yudao.module.crm.service.clue.CrmClueService;
|
|
|
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
|
|
+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;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
@@ -19,10 +28,15 @@ 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;
|
|
|
|
|
|
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.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
|
|
@@ -34,6 +48,13 @@ public class CrmClueController {
|
|
|
|
|
|
@Resource
|
|
|
private CrmClueService clueService;
|
|
|
+ @Resource
|
|
|
+ private CrmCustomerService customerService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+ @Resource
|
|
|
+ private DeptApi deptApi;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建线索")
|
|
@@ -73,7 +94,7 @@ public class CrmClueController {
|
|
|
@PreAuthorize("@ss.hasPermission('crm:clue:query')")
|
|
|
public CommonResult<PageResult<CrmClueRespVO>> getCluePage(@Valid CrmCluePageReqVO pageVO) {
|
|
|
PageResult<CrmClueDO> pageResult = clueService.getCluePage(pageVO, getLoginUserId());
|
|
|
- return success(BeanUtils.toBean(pageResult, CrmClueRespVO.class));
|
|
|
+ return success(new PageResult<>(buildClueDetailList(pageResult.getList()), pageResult.getTotal()));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/export-excel")
|
|
@@ -84,8 +105,32 @@ public class CrmClueController {
|
|
|
pageReqVO.setPageSize(PAGE_SIZE_NONE);
|
|
|
List<CrmClueDO> list = clueService.getCluePage(pageReqVO, getLoginUserId()).getList();
|
|
|
// 导出 Excel
|
|
|
- List<CrmClueRespVO> datas = BeanUtils.toBean(list, CrmClueRespVO.class);
|
|
|
- ExcelUtils.write(response, "线索.xls", "数据", CrmClueRespVO.class, datas);
|
|
|
+ ExcelUtils.write(response, "线索.xls", "数据", CrmClueRespVO.class, buildClueDetailList(list));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CrmClueRespVO> buildClueDetailList(List<CrmClueDO> list) {
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 1.1 获取客户列表
|
|
|
+ Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap(
|
|
|
+ convertSet(list, CrmClueDO::getCustomerId));
|
|
|
+ // 1.2 获取创建人、负责人列表
|
|
|
+ Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(list,
|
|
|
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
|
|
|
+ Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
|
|
+ // 2. 转换成 VO
|
|
|
+ return BeanUtils.toBean(list, CrmClueRespVO.class, clueVO -> {
|
|
|
+ // 2.1 设置客户名称
|
|
|
+ MapUtils.findAndThen(customerMap, clueVO.getCustomerId(), customer -> clueVO.setCustomerName(customer.getName()));
|
|
|
+ // 2.2 设置创建人、负责人名称
|
|
|
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(clueVO.getCreator()),
|
|
|
+ user -> clueVO.setCreatorName(user.getNickname()));
|
|
|
+ MapUtils.findAndThen(userMap, clueVO.getOwnerUserId(), user -> {
|
|
|
+ clueVO.setOwnerUserName(user.getNickname());
|
|
|
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> clueVO.setOwnerUserDeptName(dept.getName()));
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@PutMapping("/transfer")
|