|
@@ -7,8 +7,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
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.business.vo.business.*;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.business.vo.status.CrmBusinessStatusQueryVO;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.business.vo.type.CrmBusinessStatusTypeQueryVO;
|
|
|
import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO;
|
|
@@ -30,12 +28,10 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
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.convertSet;
|
|
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
|
|
@@ -47,16 +43,14 @@ public class CrmBusinessController {
|
|
|
|
|
|
@Resource
|
|
|
private CrmBusinessService businessService;
|
|
|
-
|
|
|
@Resource
|
|
|
private CrmCustomerService customerService;
|
|
|
-
|
|
|
@Resource
|
|
|
private CrmBusinessStatusTypeService businessStatusTypeService;
|
|
|
-
|
|
|
@Resource
|
|
|
private CrmBusinessStatusService businessStatusService;
|
|
|
|
|
|
+ // TODO @商机待定:CrmBusinessCreateReqVO、CrmBusinessUpdateReqVO、CrmBusinessRespVO 按照新的 VO 规范
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建商机")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:business:create')")
|
|
@@ -95,27 +89,7 @@ public class CrmBusinessController {
|
|
|
@PreAuthorize("@ss.hasPermission('crm:business:query')")
|
|
|
public CommonResult<PageResult<CrmBusinessRespVO>> getBusinessPage(@Valid CrmBusinessPageReqVO pageVO) {
|
|
|
PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(pageVO, getLoginUserId());
|
|
|
- if (CollUtil.isEmpty(pageResult.getList())) {
|
|
|
- return success(PageResult.empty(pageResult.getTotal()));
|
|
|
- }
|
|
|
- // 处理客户名称回显
|
|
|
- // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈;
|
|
|
- Set<Long> customerIds = pageResult.getList().stream()
|
|
|
- .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds, getLoginUserId());
|
|
|
- // 处理商机状态类型名称回显
|
|
|
- Set<Long> statusTypeIds = pageResult.getList().stream()
|
|
|
- .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- CrmBusinessStatusTypeQueryVO queryStatusTypeVO = new CrmBusinessStatusTypeQueryVO();
|
|
|
- queryStatusTypeVO.setIdList(statusTypeIds);
|
|
|
- List<CrmBusinessStatusTypeDO> statusTypeList = businessStatusTypeService.selectList(queryStatusTypeVO);
|
|
|
- // 处理商机状态名称回显
|
|
|
- Set<Long> statusIds = pageResult.getList().stream()
|
|
|
- .map(CrmBusinessDO::getStatusId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- CrmBusinessStatusQueryVO queryVO = new CrmBusinessStatusQueryVO();
|
|
|
- queryVO.setIdList(statusIds);
|
|
|
- List<CrmBusinessStatusDO> statusList = businessStatusService.selectList(queryVO);
|
|
|
- return success(CrmBusinessConvert.INSTANCE.convertPage(pageResult, customerList, statusTypeList, statusList));
|
|
|
+ return success(buildBusinessDetailPageResult(pageResult));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/page-by-customer")
|
|
@@ -123,24 +97,15 @@ public class CrmBusinessController {
|
|
|
public CommonResult<PageResult<CrmBusinessRespVO>> getBusinessPageByCustomer(@Valid CrmBusinessPageReqVO pageReqVO) {
|
|
|
Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空");
|
|
|
PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPageByCustomerId(pageReqVO);
|
|
|
- // 处理客户名称回显
|
|
|
- // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈;
|
|
|
- Set<Long> customerIds = pageResult.getList().stream()
|
|
|
- .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds, getLoginUserId());
|
|
|
- // 处理商机状态类型名称回显
|
|
|
- Set<Long> statusTypeIds = pageResult.getList().stream()
|
|
|
- .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- CrmBusinessStatusTypeQueryVO queryStatusTypeVO = new CrmBusinessStatusTypeQueryVO();
|
|
|
- queryStatusTypeVO.setIdList(statusTypeIds);
|
|
|
- List<CrmBusinessStatusTypeDO> statusTypeList = businessStatusTypeService.selectList(queryStatusTypeVO);
|
|
|
- // 处理商机状态名称回显
|
|
|
- Set<Long> statusIds = pageResult.getList().stream()
|
|
|
- .map(CrmBusinessDO::getStatusId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- CrmBusinessStatusQueryVO queryVO = new CrmBusinessStatusQueryVO();
|
|
|
- queryVO.setIdList(statusIds);
|
|
|
- List<CrmBusinessStatusDO> statusList = businessStatusService.selectList(queryVO);
|
|
|
- return success(CrmBusinessConvert.INSTANCE.convertPage(pageResult, customerList, statusTypeList, statusList));
|
|
|
+ return success(buildBusinessDetailPageResult(pageResult));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/page-by-contact")
|
|
|
+ @Operation(summary = "获得联系人的商机分页")
|
|
|
+ @PreAuthorize("@ss.hasPermission('crm:business:query')")
|
|
|
+ public CommonResult<PageResult<CrmBusinessRespVO>> getBusinessContactPage(@Valid CrmBusinessPageReqVO pageReqVO) {
|
|
|
+ PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPageByContact(pageReqVO);
|
|
|
+ return success(buildBusinessDetailPageResult(pageResult));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/export-excel")
|
|
@@ -152,8 +117,27 @@ public class CrmBusinessController {
|
|
|
exportReqVO.setPageSize(PAGE_SIZE_NONE);
|
|
|
PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(exportReqVO, getLoginUserId());
|
|
|
// 导出 Excel
|
|
|
- ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessExcelVO.class,
|
|
|
- CrmBusinessConvert.INSTANCE.convertList02(pageResult.getList()));
|
|
|
+ ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessRespVO.class,
|
|
|
+ buildBusinessDetailPageResult(pageResult).getList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建详细的商机分页结果
|
|
|
+ *
|
|
|
+ * @param pageResult 简单的商机分页结果
|
|
|
+ * @return 详细的商机分页结果
|
|
|
+ */
|
|
|
+ private PageResult<CrmBusinessRespVO> buildBusinessDetailPageResult(PageResult<CrmBusinessDO> pageResult) {
|
|
|
+ if (CollUtil.isEmpty(pageResult.getList())) {
|
|
|
+ return PageResult.empty(pageResult.getTotal());
|
|
|
+ }
|
|
|
+ List<CrmBusinessStatusTypeDO> statusTypeList = businessStatusTypeService.getBusinessStatusTypeList(
|
|
|
+ convertSet(pageResult.getList(), CrmBusinessDO::getStatusTypeId));
|
|
|
+ List<CrmBusinessStatusDO> statusList = businessStatusService.getBusinessStatusList(
|
|
|
+ convertSet(pageResult.getList(), CrmBusinessDO::getStatusId));
|
|
|
+ List<CrmCustomerDO> customerList = customerService.getCustomerList(
|
|
|
+ convertSet(pageResult.getList(), CrmBusinessDO::getCustomerId));
|
|
|
+ return CrmBusinessConvert.INSTANCE.convertPage(pageResult, customerList, statusTypeList, statusList);
|
|
|
}
|
|
|
|
|
|
@PutMapping("/transfer")
|