crm联系人review修改

This commit is contained in:
zyna 2023-11-27 23:42:04 +08:00
parent fd2af50202
commit 1580789334
8 changed files with 97 additions and 117 deletions

View File

@ -3,7 +3,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
@ -28,14 +30,13 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
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.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -49,7 +50,6 @@ public class ContactController {
@Resource @Resource
private ContactService contactService; private ContactService contactService;
// TODO @zyna模块内注入的变量不用带 crm 前缀哈
@Resource @Resource
private CrmCustomerService crmCustomerService; private CrmCustomerService crmCustomerService;
@ -115,43 +115,41 @@ public class ContactController {
if (CollUtil.isEmpty(pageResult.getList())) { if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal())); return success(PageResult.empty(pageResult.getTotal()));
} }
List<ContactRespVO> contactVOList = convertFieldValue2Name(pageResult.getList()); return success(convertFieldValue2Name(pageResult));
return success(new PageResult<>(contactVOList, pageResult.getTotal()));
} }
// TODO @zyna可以看下新的导出写法这里调整下
@GetMapping("/export-excel") @GetMapping("/export-excel")
@Operation(summary = "导出联系人 Excel") @Operation(summary = "导出联系人 Excel")
@PreAuthorize("@ss.hasPermission('crm:contact:export')") @PreAuthorize("@ss.hasPermission('crm:contact:export')")
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void exportContactExcel(@Valid ContactPageReqVO exportReqVO, public void exportContactExcel(@Valid ContactPageReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
List<ContactDO> list = contactService.getContactList(exportReqVO); exportReqVO.setPageNo(PageParam.PAGE_SIZE_NONE);
// TODO @zya可以改成直接调用 getContactPage 方法只要把 ContactPageReqVO 设置成不分页PAGE_SIZE_NONE PageResult<ContactDO> pageResult = contactService.getContactPage(exportReqVO);
// 导出 Excel PageResult<ContactRespVO> exportPage = convertFieldValue2Name(pageResult);
List<ContactRespVO> contactRespVOList = convertFieldValue2Name(list); ExcelUtils.write(response, "crm 联系人.xls", "数据", ContactRespVO.class, exportPage.getList());
ExcelUtils.write(response, "crm 联系人.xls", "数据", ContactRespVO.class, contactRespVOList);
} }
// TODO 芋艿后续会合并下 // TODO 芋艿后续会合并下
/** /**
* 翻译字段名称 * 翻译字段名称
* @param contactDOList 联系人List *
* @param pageResult 联系人分页参数
* @return List<ContactRespVO> * @return List<ContactRespVO>
*/ */
private List<ContactRespVO> convertFieldValue2Name(List<ContactDO> contactDOList){ private PageResult<ContactRespVO> convertFieldValue2Name(PageResult<ContactDO> pageResult) {
List<ContactDO> contactDOList = pageResult.getList();
// 1. 获取客户列表 // 1. 获取客户列表
// TODO @zyna简单的转换可以使用 CollectionUtils.convertSet List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(convertSet(contactDOList, ContactDO::getCustomerId));
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 = convertListByFlatMap(contactDOList, item -> Stream.of(NumberUtils.parseLong(item.getCreator()), item.getOwnerUserId())
List<Long> userIdsList = contactDOList.stream().flatMap(item-> Stream.of(Long.parseLong(item.getCreator()),item.getOwnerUserId()).distinct()).collect(Collectors.toList()); .filter(Objects::nonNull));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList); Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList);
// 3. 直属上级 // 3. 直属上级
List<Long> contactIdsList = contactDOList.stream().map(ContactDO::getParentId).distinct().collect(Collectors.toList()); Set<Long> contactIdsList = convertSet(contactDOList, ContactDO::getParentId);
List<ContactDO> contactList = contactService.getContactList(contactIdsList); List<ContactDO> contactList = contactService.getContactList(contactIdsList);
return ContactConvert.INSTANCE.converList(contactDOList,userMap,crmCustomerDOList,contactList); return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, contactList);
} }
} }

View File

@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.validation.Telephone;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -24,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成 * 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/ */
@Data @Data
@ExcelIgnoreUnannotated
public class ContactBaseVO { public class ContactBaseVO {
@ExcelProperty(value = "姓名",order = 1) @ExcelProperty(value = "姓名",order = 1)
@ -32,7 +33,6 @@ public class ContactBaseVO {
private String name; private String name;
@Schema(description = "客户编号", example = "10795") @Schema(description = "客户编号", example = "10795")
@ExcelIgnore
private Long customerId; private Long customerId;
@ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3)
@ -50,7 +50,6 @@ public class ContactBaseVO {
private Boolean master; private Boolean master;
@Schema(description = "直属上级", example = "23457") @Schema(description = "直属上级", example = "23457")
@ExcelIgnore
private Long parentId; private Long parentId;
@Schema(description = "手机号",example = "1387171766") @Schema(description = "手机号",example = "1387171766")
@ -97,11 +96,9 @@ public class ContactBaseVO {
@Schema(description = "负责人用户编号", example = "14334") @Schema(description = "负责人用户编号", example = "14334")
@NotNull(message = "负责人不能为空") @NotNull(message = "负责人不能为空")
@ExcelIgnore // TODO @zyna可以使用 ExcelIgnoreUnannotated
private Long ownerUserId; private Long ownerUserId;
@Schema(description = "地区编号", example = "20158") @Schema(description = "地区编号", example = "20158")
@ExcelIgnore
private Integer areaId; private Integer areaId;
} }

View File

@ -5,26 +5,20 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
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 @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ContactPageReqVO extends PageParam { public class ContactPageReqVO extends PageParam {
// TODO @zyna筛选条件多余的可以删除哈还有部分 example 少了可以补充下
// 客户 // 客户
// 姓名 // 姓名
// 手机电话座机QQ微信邮箱 // 手机电话座机QQ微信邮箱
@Schema(description = "姓名", example = "芋艿")
private String name;
@Schema(description = "下次联系时间") @Schema(description = "客户编号", example = "10795")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private Long customerId;
private LocalDateTime[] nextTime;
@Schema(description = "手机号", example = "13898273941") @Schema(description = "手机号", example = "13898273941")
private String mobile; private String mobile;
@ -35,45 +29,9 @@ public class ContactPageReqVO extends PageParam {
@Schema(description = "电子邮箱", example = "111@22.com") @Schema(description = "电子邮箱", example = "111@22.com")
private String email; private String email;
@Schema(description = "客户编号", example = "10795")
private Long customerId;
@Schema(description = "地址")
private String address;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] lastTime;
@Schema(description = "直属上级", example = "23457")
private Long parentId;
@Schema(description = "姓名", example = "芋艿")
private String name;
@Schema(description = "职位")
private String post;
@Schema(description = "QQ", example = "3882872") @Schema(description = "QQ", example = "3882872")
private Long qq; private Long qq;
@Schema(description = "微信", example = "zzZ98373") @Schema(description = "微信", example = "zzZ98373")
private String wechat; private String wechat;
@Schema(description = "性别")
private Integer sex;
@Schema(description = "是否关键决策人")
private Boolean master;
@Schema(description = "负责人用户编号", example = "14334")
private Long ownerUserId;
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
@ -10,18 +10,21 @@ import java.time.LocalDateTime;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
@ExcelIgnoreUnannotated
public class ContactRespVO extends ContactBaseVO { public class ContactRespVO extends ContactBaseVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167")
@ExcelIgnore
private Long id; private Long id;
@Schema(description = "创建时间") @Schema(description = "创建时间")
@ExcelProperty(value = "创建时间",order = 8) @ExcelProperty(value = "创建时间",order = 8)
private LocalDateTime createTime; private LocalDateTime createTime;
@Schema(description = "更新时间")
@ExcelProperty(value = "更新时间",order = 8)
private LocalDateTime updateTime;
@Schema(description = "创建人", example = "25682") @Schema(description = "创建人", example = "25682")
@ExcelIgnore
private String creator; private String creator;
@Schema(description = "创建人名字", example = "test") @Schema(description = "创建人名字", example = "test")

View File

@ -8,10 +8,12 @@ import lombok.ToString;
@Data @Data
@ToString(callSuper = true) @ToString(callSuper = true)
public class ContactSimpleRespVO { public class ContactSimpleRespVO {
@Schema(description = "姓名", example = "芋艿") // TODO @zynarequiredMode = Schema.RequiredMode.REQUIRED需要空一行字段的顺序改下id name 前面会更干净
private String name;
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167")
private Long id; private Long id;
@Schema(description = "姓名", example = "芋艿")
private String name;
} }

View File

@ -11,10 +11,12 @@ import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/** /**
@ -37,6 +39,11 @@ public interface ContactConvert {
PageResult<ContactRespVO> convertPage(PageResult<ContactDO> page); PageResult<ContactRespVO> convertPage(PageResult<ContactDO> page);
default PageResult<ContactRespVO> convertPage(PageResult<ContactDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) {
List<ContactRespVO> list = converList(pageResult.getList(), userMap, customerList, parentContactList);
return convertPage(pageResult).setList(list);
}
List<ContactSimpleRespVO> convertAllList(List<ContactDO> list); List<ContactSimpleRespVO> convertAllList(List<ContactDO> list);
@Mappings({ @Mappings({
@ -48,31 +55,35 @@ public interface ContactConvert {
/** /**
* 转换详情信息 * 转换详情信息
* *
* @param contactDO 联系人 * @param contactDO 联系人
* @param userMap 用户列表 * @param userMap 用户列表
* @param crmCustomerDOList 客户 * @param crmCustomerDOList 客户
* @return ContactRespVO * @return ContactRespVO
*/ */
default ContactRespVO convert(ContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList, default ContactRespVO convert(ContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList,
List<ContactDO> contactList) { List<ContactDO> contactList) {
ContactRespVO contactVO = convert(contactDO); ContactRespVO contactVO = convert(contactDO);
setUserInfo(contactVO, userMap); setUserInfo(contactVO, userMap);
Map<Long,CrmCustomerDO> ustomerMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v)); 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, ContactDO> contactMap = contactList.stream().collect(Collectors.toMap(ContactDO::getId, v -> v));
findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName())); findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName()));
findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName())); findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName()));
return contactVO; return contactVO;
} }
default List<ContactRespVO> converList(List<ContactDO> contactList, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) { default List<ContactRespVO> converList(List<ContactDO> contactList, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) {
List<ContactRespVO> result = convertList(contactList); List<ContactRespVO> result = convertList(contactList);
// TODO @zyna简单的转换可以使用 CollectionUtils.convertMap Map<Long, ContactDO> parentContactMap = convertMap(parentContactList, ContactDO::getId);
Map<Long, ContactDO> parentContactMap = parentContactList.stream().collect(Collectors.toMap(ContactDO::getId,v->v)); Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId);
Map<Long, CrmCustomerDO> customerMap = customerList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
result.forEach(item -> { result.forEach(item -> {
setUserInfo(item, userMap); setUserInfo(item, userMap);
findAndThen(customerMap,item.getCustomerId(),customer -> {item.setCustomerName(customer.getName());}); findAndThen(customerMap, item.getCustomerId(), customer -> {
findAndThen(parentContactMap,item.getParentId(),contactDO -> {item.setParentName(contactDO.getName());}); item.setCustomerName(customer.getName());
});
findAndThen(parentContactMap, item.getParentId(), contactDO -> {
item.setParentName(contactDO.getName());
});
}); });
return result; return result;
} }
@ -80,13 +91,13 @@ public interface ContactConvert {
/** /**
* 设置用户信息 * 设置用户信息
* *
* @param contactRespVO 联系人Response VO * @param contactRespVO 联系人Response VO
* @param userMap 用户信息 map * @param userMap 用户信息 map
*/ */
static void setUserInfo(ContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap){ static void setUserInfo(ContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap) {
contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId())); contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId()));
findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> { findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> {
contactRespVO.setOwnerUserName(user == null?"":user.getNickname()); contactRespVO.setOwnerUserName(user == null ? "" : user.getNickname());
}); });
findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname())); findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname()));
} }

View File

@ -19,45 +19,25 @@ public interface ContactMapper extends BaseMapperX<ContactDO> {
default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) { default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>() return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>()
.betweenIfPresent(ContactDO::getNextTime, reqVO.getNextTime())
.eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) .eqIfPresent(ContactDO::getMobile, reqVO.getMobile())
.eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone())
.eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) .eqIfPresent(ContactDO::getEmail, reqVO.getEmail())
.eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(ContactDO::getAddress, reqVO.getAddress())
.eqIfPresent(ContactDO::getRemark, reqVO.getRemark())
.betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime())
.betweenIfPresent(ContactDO::getLastTime, reqVO.getLastTime())
.eqIfPresent(ContactDO::getParentId, reqVO.getParentId())
.likeIfPresent(ContactDO::getName, reqVO.getName()) .likeIfPresent(ContactDO::getName, reqVO.getName())
.eqIfPresent(ContactDO::getPost, reqVO.getPost())
.eqIfPresent(ContactDO::getQq, reqVO.getQq()) .eqIfPresent(ContactDO::getQq, reqVO.getQq())
.eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) .eqIfPresent(ContactDO::getWechat, reqVO.getWechat())
.eqIfPresent(ContactDO::getSex, reqVO.getSex())
.eqIfPresent(ContactDO::getMaster, reqVO.getMaster())
.eqIfPresent(ContactDO::getOwnerUserId, reqVO.getOwnerUserId())
.orderByDesc(ContactDO::getId)); .orderByDesc(ContactDO::getId));
} }
default List<ContactDO> selectList(ContactPageReqVO reqVO) { default List<ContactDO> selectList(ContactPageReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ContactDO>() return selectList(new LambdaQueryWrapperX<ContactDO>()
.betweenIfPresent(ContactDO::getNextTime, reqVO.getNextTime())
.eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) .eqIfPresent(ContactDO::getMobile, reqVO.getMobile())
.eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone())
.eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) .eqIfPresent(ContactDO::getEmail, reqVO.getEmail())
.eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(ContactDO::getAddress, reqVO.getAddress())
.eqIfPresent(ContactDO::getRemark, reqVO.getRemark())
.betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime())
.betweenIfPresent(ContactDO::getLastTime, reqVO.getLastTime())
.eqIfPresent(ContactDO::getParentId, reqVO.getParentId())
.likeIfPresent(ContactDO::getName, reqVO.getName()) .likeIfPresent(ContactDO::getName, reqVO.getName())
.eqIfPresent(ContactDO::getPost, reqVO.getPost())
.eqIfPresent(ContactDO::getQq, reqVO.getQq()) .eqIfPresent(ContactDO::getQq, reqVO.getQq())
.eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) .eqIfPresent(ContactDO::getWechat, reqVO.getWechat())
.eqIfPresent(ContactDO::getSex, reqVO.getSex())
.eqIfPresent(ContactDO::getMaster, reqVO.getMaster())
.eqIfPresent(ContactDO::getOwnerUserId, reqVO.getOwnerUserId())
.orderByDesc(ContactDO::getId)); .orderByDesc(ContactDO::getId));
} }

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.crm.service.contact;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactBaseVO;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO;
@ -12,8 +13,10 @@ import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper;
import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -21,9 +24,12 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
/** /**
* crm联系人 Service 实现类 * crm联系人 Service 实现类
@ -37,11 +43,20 @@ public class ContactServiceImpl implements ContactService {
@Resource @Resource
private ContactMapper contactMapper; private ContactMapper contactMapper;
@Resource
private CrmCustomerService customerService;
@Resource
private AdminUserApi adminUserApi;
@Resource @Resource
private CrmPermissionService crmPermissionService; private CrmPermissionService crmPermissionService;
@Override // TODO @zyna新增和修改时关联字段要校验例如说 直属上级是不是真的存在 @Override
public Long createContact(ContactCreateReqVO createReqVO, Long userId) { public Long createContact(ContactCreateReqVO createReqVO, Long userId) {
//@todo
//校验
validateDataExist(createReqVO);
// 插入 // 插入
ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO);
contactMapper.insert(contact); contactMapper.insert(contact);
@ -60,6 +75,7 @@ public class ContactServiceImpl implements ContactService {
public void updateContact(ContactUpdateReqVO updateReqVO) { public void updateContact(ContactUpdateReqVO updateReqVO) {
// 校验存在 // 校验存在
validateContactExists(updateReqVO.getId()); validateContactExists(updateReqVO.getId());
validateDataExist(updateReqVO);
// 更新 // 更新
ContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO); ContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO);
contactMapper.updateById(updateObj); contactMapper.updateById(updateObj);
@ -109,4 +125,19 @@ public class ContactServiceImpl implements ContactService {
public List<ContactDO> getContactList() { public List<ContactDO> getContactList() {
return contactMapper.selectList(); return contactMapper.selectList();
} }
private void validateDataExist(ContactBaseVO contactBaseVO){
//1.校验客户
if (contactBaseVO.getCustomerId() != null) {
Optional.ofNullable(customerService.getCustomer(contactBaseVO.getCustomerId())).orElseThrow(() -> exception(CUSTOMER_NOT_EXISTS));
}
//2.校验负责人
if (contactBaseVO.getOwnerUserId() != null) {
Optional.ofNullable(adminUserApi.getUser(contactBaseVO.getOwnerUserId())).orElseThrow(() -> exception(USER_NOT_EXISTS));
}
//3.直属上级
if (contactBaseVO.getParentId() != null) {
Optional.ofNullable(contactMapper.selectById(contactBaseVO.getParentId())).orElseThrow(() -> exception(CONTACT_NOT_EXISTS));
}
}
} }