|
@@ -5,12 +5,14 @@ import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
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.date.LocalDateTimeUtils;
|
|
|
+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.ip.core.utils.AreaUtils;
|
|
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
|
|
|
-import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
|
|
|
import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
|
|
@@ -22,11 +24,11 @@ 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.Parameters;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jakarta.validation.Valid;
|
|
|
-import org.mapstruct.ap.internal.util.Collections;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -45,6 +47,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
|
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_POOL_CONFIG_NOT_EXISTS_OR_DISABLED;
|
|
|
+import static java.util.Collections.singletonList;
|
|
|
|
|
|
@Tag(name = "管理后台 - CRM 客户")
|
|
|
@RestController
|
|
@@ -77,6 +80,18 @@ public class CrmCustomerController {
|
|
|
return success(true);
|
|
|
}
|
|
|
|
|
|
+ @PutMapping("/update-deal-status")
|
|
|
+ @Operation(summary = "更新客户的成交状态")
|
|
|
+ @Parameters({
|
|
|
+ @Parameter(name = "id", description = "客户编号", required = true),
|
|
|
+ @Parameter(name = "dealStatus", description = "成交状态", required = true)
|
|
|
+ })
|
|
|
+ public CommonResult<Boolean> updateCustomerDealStatus(@RequestParam("id") Long id,
|
|
|
+ @RequestParam("dealStatus") Boolean dealStatus) {
|
|
|
+ customerService.updateCustomerDealStatus(id, dealStatus);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
@DeleteMapping("/delete")
|
|
|
@Operation(summary = "删除客户")
|
|
|
@Parameter(name = "id", description = "客户编号", required = true)
|
|
@@ -93,14 +108,15 @@ public class CrmCustomerController {
|
|
|
public CommonResult<CrmCustomerRespVO> getCustomer(@RequestParam("id") Long id) {
|
|
|
// 1. 获取客户
|
|
|
CrmCustomerDO customer = customerService.getCustomer(id);
|
|
|
+ // 2. 拼接数据
|
|
|
+ return success(buildCustomerDetail(customer));
|
|
|
+ }
|
|
|
+
|
|
|
+ public CrmCustomerRespVO buildCustomerDetail(CrmCustomerDO customer) {
|
|
|
if (customer == null) {
|
|
|
- return success(null);
|
|
|
+ return null;
|
|
|
}
|
|
|
- // 2. 拼接数据
|
|
|
- Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
|
|
- Collections.asSet(Long.valueOf(customer.getCreator()), customer.getOwnerUserId()));
|
|
|
- Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
|
|
- return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
|
|
|
+ return buildCustomerDetailList(singletonList(customer)).get(0);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/page")
|
|
@@ -112,16 +128,38 @@ public class CrmCustomerController {
|
|
|
if (CollUtil.isEmpty(pageResult.getList())) {
|
|
|
return success(PageResult.empty(pageResult.getTotal()));
|
|
|
}
|
|
|
-
|
|
|
// 2. 拼接数据
|
|
|
- Map<Long, Long> poolDayMap = Boolean.TRUE.equals(pageVO.getPool()) ? null :
|
|
|
- getPoolDayMap(pageResult.getList()); // 客户界面,需要查看距离进入公海的时间
|
|
|
- Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
|
|
- convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId())));
|
|
|
+ return success(new PageResult<>(buildCustomerDetailList(pageResult.getList()), pageResult.getTotal()));
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<CrmCustomerRespVO> buildCustomerDetailList(List<CrmCustomerDO> list) {
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return java.util.Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 1.1 获取创建人、负责人列表
|
|
|
+ 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));
|
|
|
- return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap));
|
|
|
+ // 1.2 获取距离进入公海的时间
|
|
|
+ Map<Long, Long> poolDayMap = getPoolDayMap(list);
|
|
|
+ // 2. 转换成 VO
|
|
|
+ return BeanUtils.toBean(list, CrmCustomerRespVO.class, customerVO -> {
|
|
|
+ customerVO.setAreaName(AreaUtils.format(customerVO.getAreaId()));
|
|
|
+ // 2.1 设置创建人、负责人名称
|
|
|
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(customerVO.getCreator()),
|
|
|
+ user -> customerVO.setCreatorName(user.getNickname()));
|
|
|
+ MapUtils.findAndThen(userMap, customerVO.getOwnerUserId(), user -> {
|
|
|
+ customerVO.setOwnerUserName(user.getNickname());
|
|
|
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> customerVO.setOwnerUserDeptName(dept.getName()));
|
|
|
+ });
|
|
|
+ // 2.2 设置距离进入公海的时间
|
|
|
+ if (customerVO.getOwnerUserId() != null) {
|
|
|
+ customerVO.setPoolDay(poolDayMap.get(customerVO.getId()));
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ // TODO @芋艿:需要 review 下
|
|
|
@GetMapping("/put-in-pool-remind-page")
|
|
|
@Operation(summary = "获得待进入公海客户分页")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:customer:query')")
|
|
@@ -141,12 +179,7 @@ public class CrmCustomerController {
|
|
|
}
|
|
|
|
|
|
// 2. 拼接数据
|
|
|
- // TODO @芋艿:合并 getCustomerPage 和 getPutInPoolRemindCustomerPage 的后置处理;
|
|
|
- Map<Long, Long> poolDayMap = getPoolDayMap(pageResult.getList()); // 客户界面,需要查看距离进入公海的时间
|
|
|
- Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
|
|
- convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId())));
|
|
|
- Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
|
|
- return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap));
|
|
|
+ return success(new PageResult<>(buildCustomerDetailList(pageResult.getList()), pageResult.getTotal()));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/put-in-pool-remind-count")
|
|
@@ -182,22 +215,26 @@ public class CrmCustomerController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取距离进入公海的时间
|
|
|
+ * 获取距离进入公海的时间 Map
|
|
|
*
|
|
|
- * @param customerList 客户列表
|
|
|
- * @return Map<key 客户编号, value 距离进入公海的时间>
|
|
|
+ * @param list 客户列表
|
|
|
+ * @return key 客户编号, value 距离进入公海的时间
|
|
|
*/
|
|
|
- private Map<Long, Long> getPoolDayMap(List<CrmCustomerDO> customerList) {
|
|
|
+ private Map<Long, Long> getPoolDayMap(List<CrmCustomerDO> list) {
|
|
|
CrmCustomerPoolConfigDO poolConfig = customerPoolConfigService.getCustomerPoolConfig();
|
|
|
if (poolConfig == null || !poolConfig.getEnabled()) {
|
|
|
return MapUtil.empty();
|
|
|
}
|
|
|
- return convertMap(customerList, CrmCustomerDO::getId, customer -> {
|
|
|
+ return convertMap(list, CrmCustomerDO::getId, customer -> {
|
|
|
+ // TODO 芋艿:这样计算,貌似有点问题
|
|
|
// 1.1 未成交放入公海天数
|
|
|
long dealExpireDay = 0;
|
|
|
if (!customer.getDealStatus()) {
|
|
|
dealExpireDay = poolConfig.getDealExpireDays() - LocalDateTimeUtils.between(customer.getCreateTime());
|
|
|
}
|
|
|
+ if (dealExpireDay < 0) {
|
|
|
+ dealExpireDay = 0;
|
|
|
+ }
|
|
|
// 1.2 未跟进放入公海天数
|
|
|
LocalDateTime lastTime = ObjUtil.defaultIfNull(customer.getContactLastTime(), customer.getCreateTime());
|
|
|
long contactExpireDay = poolConfig.getContactExpireDays() - LocalDateTimeUtils.between(lastTime);
|
|
@@ -230,7 +267,7 @@ public class CrmCustomerController {
|
|
|
List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
|
|
|
// 导出 Excel
|
|
|
ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerRespVO.class,
|
|
|
- BeanUtils.toBean(list, CrmCustomerRespVO.class));
|
|
|
+ buildCustomerDetailList(list));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/get-import-template")
|
|
@@ -238,12 +275,12 @@ public class CrmCustomerController {
|
|
|
public void importTemplate(HttpServletResponse response) throws IOException {
|
|
|
// 手动创建导出 demo
|
|
|
List<CrmCustomerImportExcelVO> list = Arrays.asList(
|
|
|
- CrmCustomerImportExcelVO.builder().name("芋道").industryId(1).level(1).source(1).mobile("15601691300").telephone("")
|
|
|
- .qq("").wechat("").email("yunai@iocoder.cn").description("").remark("")
|
|
|
- .areaId(null).detailAddress("").build(),
|
|
|
- CrmCustomerImportExcelVO.builder().name("源码").industryId(1).level(1).source(1).mobile("15601691300").telephone("")
|
|
|
- .qq("").wechat("").email("yunai@iocoder.cn").description("").remark("")
|
|
|
- .areaId(null).detailAddress("").build()
|
|
|
+ CrmCustomerImportExcelVO.builder().name("芋道").industryId(1).level(1).source(1)
|
|
|
+ .mobile("15601691300").telephone("").qq("").wechat("").email("yunai@iocoder.cn")
|
|
|
+ .areaId(null).detailAddress("").remark("").build(),
|
|
|
+ CrmCustomerImportExcelVO.builder().name("源码").industryId(1).level(1).source(1)
|
|
|
+ .mobile("15601691300").telephone("").qq("").wechat("").email("yunai@iocoder.cn")
|
|
|
+ .areaId(null).detailAddress("").remark("").build()
|
|
|
);
|
|
|
// 输出
|
|
|
ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list);
|