crm:code review 联系人

This commit is contained in:
YunaiV 2023-11-27 20:28:18 +08:00
parent 16084d468d
commit 455f8e49fb
11 changed files with 84 additions and 92 deletions

View File

@ -1,30 +1,3 @@
SET NAMES utf8mb4;
-- `ruoyi-vue-pro`.crm_contact definition
CREATE TABLE `crm_contact` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '联系人名称',
`next_time` datetime DEFAULT NULL COMMENT '下次联系时间',
`mobile` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '手机号',
`telephone` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '电话',
`email` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '电子邮箱',
`post` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '职务',
`customer_id` bigint(20) DEFAULT NULL COMMENT '客户编号',
`address` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址',
`remark` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '备注',
`creator` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '创建人',
`owner_user_id` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '负责人用户编号',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间',
`last_time` timestamp NULL DEFAULT NULL COMMENT '最后跟进时间',
`updater` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '更新人',
`deleted` bit(1) NOT NULL DEFAULT b'0',
`tenant_id` bigint(20) DEFAULT NULL,
`parent_id` bigint(20) DEFAULT NULL COMMENT '直系上属',
`qq` int(11) DEFAULT NULL,
`wechat` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sex` int(11) DEFAULT NULL COMMENT '性别',
`master` bit(1) DEFAULT NULL COMMENT '是否关键决策人',
`area_id` bigint(20) DEFAULT NULL COMMENT '地区',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='CRM 联系人';

View File

@ -86,24 +86,23 @@ public class ContactController {
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<ContactRespVO> getContact(@RequestParam("id") Long id) {
ContactDO contact = contactService.getContact(id);
if(contact == null){
if (contact == null) {
throw exception(ErrorCodeConstants.CONTACT_NOT_EXISTS);
}
//1.获取用户名
// 1. 获取用户名
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(
NumberUtil.parseLong(contact.getCreator()),contact.getOwnerUserId())));
//2.获取客户信息
List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(Collections.singletonList(contact.getCustomerId()));
//3.直属上级
List<ContactDO> contactList = contactService.getContactList(Collections.singletonList(contact.getParentId()));
ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact,userMap,crmCustomerDOList,contactList);
return success(contactRespVO);
NumberUtil.parseLong(contact.getCreator()), contact.getOwnerUserId())));
// 2. 获取客户信息
List<CrmCustomerDO> customerList = crmCustomerService.getCustomerList(Collections.singletonList(contact.getCustomerId()));
// 3. 直属上级
List<ContactDO> parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId()));
return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList));
}
@GetMapping("/simple-all-list")
@Operation(summary = "获得联系人列表")
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<List<ContactSimpleRespVO>> simpleAlllist() {
// TODO @zyna方法名改成getContactList方法命名要动名词get 动词all 可以去掉因为没条件自然是全部
public CommonResult<List<ContactSimpleRespVO>> getContactList() {
List<ContactDO> list = contactService.getContactList();
return success(ContactConvert.INSTANCE.convertAllList(list));
}
@ -112,11 +111,12 @@ public class ContactController {
@Operation(summary = "获得联系人分页")
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) {
PageResult<ContactDO> pageData = contactService.getContactPage(pageVO);
List<ContactRespVO> contactRespVOList = convertFieldValue2Name(pageData.getList());
PageResult<ContactRespVO> pageDataReturn = ContactConvert.INSTANCE.convertPage(pageData);
pageDataReturn.setList(contactRespVOList);
return success(pageDataReturn);
PageResult<ContactDO> pageResult = contactService.getContactPage(pageVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
List<ContactRespVO> contactVOList = convertFieldValue2Name(pageResult.getList());
return success(new PageResult<>(contactVOList, pageResult.getTotal()));
}
// TODO @zyna可以看下新的导出写法这里调整下
@ -127,27 +127,31 @@ public class ContactController {
public void exportContactExcel(@Valid ContactPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ContactDO> list = contactService.getContactList(exportReqVO);
// TODO @zya可以改成直接调用 getContactPage 方法只要把 ContactPageReqVO 设置成不分页PAGE_SIZE_NONE
// 导出 Excel
List<ContactRespVO> contactRespVOList = convertFieldValue2Name(list);
ExcelUtils.write(response, "crm联系人.xls", "数据", ContactRespVO.class, contactRespVOList);
ExcelUtils.write(response, "crm 联系人.xls", "数据", ContactRespVO.class, contactRespVOList);
}
// TODO 芋艿后续会合并下
/**
* 翻译字段名称
* @param contactDOList 联系人List
* @return List<ContactRespVO>
*/
private List<ContactRespVO> convertFieldValue2Name(List<ContactDO> contactDOList){
//1.获取客户列表
// 1. 获取客户列表
// TODO @zyna简单的转换可以使用 CollectionUtils.convertSet
List<Long> customerIdList = contactDOList.stream().map(ContactDO::getCustomerId).distinct().collect(Collectors.toList());
List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(customerIdList);
//2.获取创建人责任人列表
// 2. 获取创建人责任人列表
// TODO @zyna简单的转换可以使用 CollectionUtils.convertSetByFlatMap
List<Long> userIdsList = contactDOList.stream().flatMap(item-> Stream.of(Long.parseLong(item.getCreator()),item.getOwnerUserId()).distinct()).collect(Collectors.toList());
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList);
//3.直属上级
// 3. 直属上级
List<Long> contactIdsList = contactDOList.stream().map(ContactDO::getParentId).distinct().collect(Collectors.toList());
List<ContactDO> contactList = contactService.getContactList(contactIdsList);
List<ContactRespVO> pageResult =ContactConvert.INSTANCE.converList(contactDOList,userMap,crmCustomerDOList,contactList);
return pageResult;
return ContactConvert.INSTANCE.converList(contactDOList,userMap,crmCustomerDOList,contactList);
}
}

View File

@ -4,11 +4,11 @@ import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.framework.common.validation.Telephone;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.skywalking.apm.toolkit.trace.IgnoredException;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Email;
@ -35,25 +35,24 @@ public class ContactBaseVO {
@ExcelIgnore
private Long customerId;
@ExcelProperty(value = "性别",converter = DictConvert.class ,order = 3)
@ExcelProperty(value = "性别", converter = DictConvert.class, order = 3)
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_SEX)
@Schema(description = "性别")
private Integer sex;
@Schema(description = "职位")
@ExcelProperty(value = "职位",order = 3)
@ExcelProperty(value = "职位", order = 3)
private String post;
@Schema(description = "是否关键决策人")
@ExcelProperty(value = "是否关键决策人",converter = DictConvert.class,order = 3)
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.INFRA_BOOLEAN_STRING)
@ExcelProperty(value = "是否关键决策人", converter = DictConvert.class, order = 3)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean master;
@Schema(description = "直属上级", example = "23457")
@ExcelIgnore
private Long parentId;
@Schema(description = "手机号",example = "1387171766")
@Mobile
@ExcelProperty(value = "手机号",order = 4)
@ -98,7 +97,7 @@ public class ContactBaseVO {
@Schema(description = "负责人用户编号", example = "14334")
@NotNull(message = "负责人不能为空")
@ExcelIgnore
@ExcelIgnore // TODO @zyna可以使用 ExcelIgnoreUnannotated
private Long ownerUserId;
@Schema(description = "地区编号", example = "20158")

View File

@ -11,13 +11,13 @@ import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - crm联系人分页 Request VO")
@Schema(description = "管理后台 - CRM 联系人分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ContactPageReqVO extends PageParam {
// TODO @zyna筛选条件
// TODO @zyna筛选条件多余的可以删除哈还有部分 example 少了可以补充下
// 客户
// 姓名
// 手机电话座机QQ微信邮箱
@ -26,13 +26,13 @@ public class ContactPageReqVO extends PageParam {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] nextTime;
@Schema(description = "手机号",example = "13898273941")
@Schema(description = "手机号", example = "13898273941")
private String mobile;
@Schema(description = "电话",example = "021-383773")
@Schema(description = "电话", example = "021-383773")
private String telephone;
@Schema(description = "电子邮箱",example = "111@22.com")
@Schema(description = "电子邮箱", example = "111@22.com")
private String email;
@Schema(description = "客户编号", example = "10795")
@ -61,10 +61,10 @@ public class ContactPageReqVO extends PageParam {
@Schema(description = "职位")
private String post;
@Schema(description = "QQ",example = "3882872")
@Schema(description = "QQ", example = "3882872")
private Long qq;
@Schema(description = "微信",example = "zzZ98373")
@Schema(description = "微信", example = "zzZ98373")
private String wechat;
@Schema(description = "性别")

View File

@ -172,6 +172,8 @@ public class CrmCustomerController {
customerService.receiveCustomer(ids, ownerUserId);
return success(true);
}
// TODO 芋艿这个接口要调整下
@GetMapping("/query-all-list")
@Operation(summary = "查询客户列表")
@PreAuthorize("@ss.hasPermission('crm:customer:all')")
@ -180,4 +182,5 @@ public class CrmCustomerController {
List<CrmCustomerQueryAllRespVO> data = CrmCustomerConvert.INSTANCE.convertQueryAll(crmCustomerDOList);
return success(data);
}
}

View File

@ -3,13 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
// TODO 芋艿这块要统一下
@Schema(description = "管理后台 - CRM 全部客户 Response VO")
@Data
public class CrmCustomerQueryAllRespVO{
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private String name;
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
private Long id;
@Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private String name;
}

View File

@ -46,7 +46,8 @@ public interface ContactConvert {
CrmPermissionTransferReqBO convert(CrmContactTransferReqVO reqVO, Long userId);
/**
* 详情信息
* 转换详情信息
*
* @param contactDO 联系人
* @param userMap 用户列表
* @param crmCustomerDOList 客户
@ -54,26 +55,28 @@ public interface ContactConvert {
*/
default ContactRespVO convert(ContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList,
List<ContactDO> contactList) {
ContactRespVO contactRespVO = convert(contactDO);
setUserInfo(contactRespVO,userMap);
Map<Long,CrmCustomerDO> crmCustomerDOMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
Map<Long,ContactDO> contactDOMap = contactList.stream().collect(Collectors.toMap(ContactDO::getId,v->v));
findAndThen(crmCustomerDOMap,contactDO.getCustomerId(),customer -> {contactRespVO.setCustomerName(customer.getName());});
findAndThen(contactDOMap,contactDO.getParentId(),contactDOInner -> {contactRespVO.setParentName(contactDOInner.getName());});
return contactRespVO;
}
default List<ContactRespVO> converList(List<ContactDO> contactDOList, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> crmCustomerDOList , List<ContactDO> contactList){
List<ContactRespVO> result = convertList(contactDOList);
ContactRespVO contactVO = convert(contactDO);
setUserInfo(contactVO, userMap);
Map<Long,CrmCustomerDO> ustomerMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
Map<Long,ContactDO> contactMap = contactList.stream().collect(Collectors.toMap(ContactDO::getId,v->v));
Map<Long,CrmCustomerDO> customerMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName()));
findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName()));
return contactVO;
}
default List<ContactRespVO> converList(List<ContactDO> contactList, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) {
List<ContactRespVO> result = convertList(contactList);
// TODO @zyna简单的转换可以使用 CollectionUtils.convertMap
Map<Long, ContactDO> parentContactMap = parentContactList.stream().collect(Collectors.toMap(ContactDO::getId,v->v));
Map<Long, CrmCustomerDO> customerMap = customerList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
result.forEach(item -> {
setUserInfo(item, userMap);
findAndThen(customerMap,item.getCustomerId(),customer -> {item.setCustomerName(customer.getName());});
findAndThen(contactMap,item.getParentId(),contactDO -> {item.setParentName(contactDO.getName());});
findAndThen(parentContactMap,item.getParentId(),contactDO -> {item.setParentName(contactDO.getName());});
});
return result;
}
/**
* 设置用户信息
*
@ -87,4 +90,5 @@ public interface ContactConvert {
});
findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname()));
}
}

View File

@ -72,9 +72,7 @@ public interface CrmCustomerConvert {
default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
Map<Long, DeptRespDTO> deptMap) {
PageResult<CrmCustomerRespVO> result = convertPage(pageResult);
result.getList().forEach(item -> {
setUserInfo(item, userMap, deptMap);
});
result.getList().forEach(item -> setUserInfo(item, userMap, deptMap));
return result;
}
@ -82,6 +80,6 @@ public interface CrmCustomerConvert {
CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO);
CrmCustomerQueryAllRespVO convertQueryAll(CrmCustomerDO crmCustomerDO);
List<CrmCustomerQueryAllRespVO> convertQueryAll(List<CrmCustomerDO> crmCustomerDO);
}

View File

@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@ -23,6 +22,7 @@ import java.time.LocalDateTime;
@NoArgsConstructor
@AllArgsConstructor
public class ContactDO extends BaseDO {
/**
* 主键
*/
@ -61,7 +61,9 @@ public class ContactDO extends BaseDO {
*/
private LocalDateTime lastTime;
/**
* 直属上级 @link ContactDO#id
* 直属上级
*
* 关联 {@link ContactDO#id}
*/
private Long parentId;
/**
@ -82,7 +84,8 @@ public class ContactDO extends BaseDO {
private String wechat;
/**
* 性别
* @See 字典配置
*
* 枚举 {@link cn.iocoder.yudao.module.system.enums.common.SexEnum}
*/
private Integer sex;
/**
@ -91,8 +94,16 @@ public class ContactDO extends BaseDO {
private Boolean master;
/**
* 负责人用户编号
*
* 关联 AdminUserDO id 字段
*/
private Long ownerUserId;
/**
* 所在地
*
* 关联 {@link cn.iocoder.yudao.framework.ip.core.Area#getId()} 字段
*/
private Integer areaId;
}

View File

@ -56,7 +56,7 @@ public class ContactServiceImpl implements ContactService {
@Override
@Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS,bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
public void updateContact(ContactUpdateReqVO updateReqVO) {
// 校验存在
validateContactExists(updateReqVO.getId());
@ -67,7 +67,7 @@ public class ContactServiceImpl implements ContactService {
@Override
@Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS,bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
public void deleteContact(Long id) {
// 校验存在
validateContactExists(id);
@ -82,7 +82,7 @@ public class ContactServiceImpl implements ContactService {
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS,bizId = "#id", level = CrmPermissionLevelEnum.READ)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#id", level = CrmPermissionLevelEnum.READ)
public ContactDO getContact(Long id) {
return contactMapper.selectById(id);
}

View File

@ -26,6 +26,4 @@ public interface DictTypeConstants {
String SMS_SEND_STATUS = "system_sms_send_status"; // 短信发送状态
String SMS_RECEIVE_STATUS = "system_sms_receive_status"; // 短信接收状态
String INFRA_BOOLEAN_STRING = "infra_boolean_string"; // boolean字典
}