Commit 591bc367377198bf1f67b8813ec6e8f50dc5d7d1
Committed by
Gitee
!763 crm联系人review修改
Merge pull request !763 from zyna/feature/crm
Showing
8 changed files
with
97 additions
and
117 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java
| ... | ... | @@ -3,7 +3,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.NumberUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | |
| 7 | 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | 10 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | 11 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; |
| ... | ... | @@ -28,14 +30,13 @@ import javax.annotation.Resource; |
| 28 | 30 | import javax.servlet.http.HttpServletResponse; |
| 29 | 31 | import javax.validation.Valid; |
| 30 | 32 | import java.io.IOException; |
| 31 | -import java.util.Collections; | |
| 32 | -import java.util.List; | |
| 33 | -import java.util.Map; | |
| 34 | -import java.util.stream.Collectors; | |
| 33 | +import java.util.*; | |
| 35 | 34 | import java.util.stream.Stream; |
| 36 | 35 | |
| 37 | 36 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 38 | 37 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 38 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; | |
| 39 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 39 | 40 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 40 | 41 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 41 | 42 | |
| ... | ... | @@ -49,7 +50,6 @@ public class ContactController { |
| 49 | 50 | |
| 50 | 51 | @Resource |
| 51 | 52 | private ContactService contactService; |
| 52 | - // TODO @zyna:模块内,注入的变量,不用带 crm 前缀哈 | |
| 53 | 53 | @Resource |
| 54 | 54 | private CrmCustomerService crmCustomerService; |
| 55 | 55 | |
| ... | ... | @@ -115,43 +115,41 @@ public class ContactController { |
| 115 | 115 | if (CollUtil.isEmpty(pageResult.getList())) { |
| 116 | 116 | return success(PageResult.empty(pageResult.getTotal())); |
| 117 | 117 | } |
| 118 | - List<ContactRespVO> contactVOList = convertFieldValue2Name(pageResult.getList()); | |
| 119 | - return success(new PageResult<>(contactVOList, pageResult.getTotal())); | |
| 118 | + return success(convertFieldValue2Name(pageResult)); | |
| 120 | 119 | } |
| 121 | 120 | |
| 122 | - // TODO @zyna:可以看下新的导出写法,这里调整下 | |
| 123 | 121 | @GetMapping("/export-excel") |
| 124 | 122 | @Operation(summary = "导出联系人 Excel") |
| 125 | 123 | @PreAuthorize("@ss.hasPermission('crm:contact:export')") |
| 126 | 124 | @OperateLog(type = EXPORT) |
| 127 | 125 | public void exportContactExcel(@Valid ContactPageReqVO exportReqVO, |
| 128 | - HttpServletResponse response) throws IOException { | |
| 129 | - List<ContactDO> list = contactService.getContactList(exportReqVO); | |
| 130 | - // TODO @zya:可以改成直接调用 getContactPage 方法;只要把 ContactPageReqVO 设置成不分页,PAGE_SIZE_NONE | |
| 131 | - // 导出 Excel | |
| 132 | - List<ContactRespVO> contactRespVOList = convertFieldValue2Name(list); | |
| 133 | - ExcelUtils.write(response, "crm 联系人.xls", "数据", ContactRespVO.class, contactRespVOList); | |
| 126 | + HttpServletResponse response) throws IOException { | |
| 127 | + exportReqVO.setPageNo(PageParam.PAGE_SIZE_NONE); | |
| 128 | + PageResult<ContactDO> pageResult = contactService.getContactPage(exportReqVO); | |
| 129 | + PageResult<ContactRespVO> exportPage = convertFieldValue2Name(pageResult); | |
| 130 | + ExcelUtils.write(response, "crm 联系人.xls", "数据", ContactRespVO.class, exportPage.getList()); | |
| 134 | 131 | } |
| 135 | 132 | |
| 136 | 133 | // TODO 芋艿:后续会合并下, |
| 134 | + | |
| 137 | 135 | /** |
| 138 | 136 | * 翻译字段名称 |
| 139 | - * @param contactDOList 联系人List | |
| 137 | + * | |
| 138 | + * @param pageResult 联系人分页参数 | |
| 140 | 139 | * @return List<ContactRespVO> |
| 141 | 140 | */ |
| 142 | - private List<ContactRespVO> convertFieldValue2Name(List<ContactDO> contactDOList){ | |
| 141 | + private PageResult<ContactRespVO> convertFieldValue2Name(PageResult<ContactDO> pageResult) { | |
| 142 | + List<ContactDO> contactDOList = pageResult.getList(); | |
| 143 | 143 | // 1. 获取客户列表 |
| 144 | - // TODO @zyna:简单的转换,可以使用 CollectionUtils.convertSet | |
| 145 | - List<Long> customerIdList = contactDOList.stream().map(ContactDO::getCustomerId).distinct().collect(Collectors.toList()); | |
| 146 | - List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(customerIdList); | |
| 144 | + List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(convertSet(contactDOList, ContactDO::getCustomerId)); | |
| 147 | 145 | // 2. 获取创建人、责任人列表 |
| 148 | - // TODO @zyna:简单的转换,可以使用 CollectionUtils.convertSetByFlatMap | |
| 149 | - List<Long> userIdsList = contactDOList.stream().flatMap(item-> Stream.of(Long.parseLong(item.getCreator()),item.getOwnerUserId()).distinct()).collect(Collectors.toList()); | |
| 146 | + List<Long> userIdsList = convertListByFlatMap(contactDOList, item -> Stream.of(NumberUtils.parseLong(item.getCreator()), item.getOwnerUserId()) | |
| 147 | + .filter(Objects::nonNull)); | |
| 150 | 148 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList); |
| 151 | 149 | // 3. 直属上级 |
| 152 | - List<Long> contactIdsList = contactDOList.stream().map(ContactDO::getParentId).distinct().collect(Collectors.toList()); | |
| 150 | + Set<Long> contactIdsList = convertSet(contactDOList, ContactDO::getParentId); | |
| 153 | 151 | List<ContactDO> contactList = contactService.getContactList(contactIdsList); |
| 154 | - return ContactConvert.INSTANCE.converList(contactDOList,userMap,crmCustomerDOList,contactList); | |
| 152 | + return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, contactList); | |
| 155 | 153 | } |
| 156 | 154 | |
| 157 | 155 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactBaseVO.java
| ... | ... | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.validation.Telephone; |
| 5 | 5 | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| 6 | 6 | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| 7 | 7 | import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; |
| 8 | -import com.alibaba.excel.annotation.ExcelIgnore; | |
| 8 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 9 | 9 | import com.alibaba.excel.annotation.ExcelProperty; |
| 10 | 10 | import io.swagger.v3.oas.annotations.media.Schema; |
| 11 | 11 | import lombok.Data; |
| ... | ... | @@ -24,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ |
| 24 | 24 | * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 |
| 25 | 25 | */ |
| 26 | 26 | @Data |
| 27 | +@ExcelIgnoreUnannotated | |
| 27 | 28 | public class ContactBaseVO { |
| 28 | 29 | |
| 29 | 30 | @ExcelProperty(value = "姓名",order = 1) |
| ... | ... | @@ -32,7 +33,6 @@ public class ContactBaseVO { |
| 32 | 33 | private String name; |
| 33 | 34 | |
| 34 | 35 | @Schema(description = "客户编号", example = "10795") |
| 35 | - @ExcelIgnore | |
| 36 | 36 | private Long customerId; |
| 37 | 37 | |
| 38 | 38 | @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) |
| ... | ... | @@ -50,7 +50,6 @@ public class ContactBaseVO { |
| 50 | 50 | private Boolean master; |
| 51 | 51 | |
| 52 | 52 | @Schema(description = "直属上级", example = "23457") |
| 53 | - @ExcelIgnore | |
| 54 | 53 | private Long parentId; |
| 55 | 54 | |
| 56 | 55 | @Schema(description = "手机号",example = "1387171766") |
| ... | ... | @@ -97,11 +96,9 @@ public class ContactBaseVO { |
| 97 | 96 | |
| 98 | 97 | @Schema(description = "负责人用户编号", example = "14334") |
| 99 | 98 | @NotNull(message = "负责人不能为空") |
| 100 | - @ExcelIgnore // TODO @zyna:可以使用 ExcelIgnoreUnannotated | |
| 101 | 99 | private Long ownerUserId; |
| 102 | 100 | |
| 103 | 101 | @Schema(description = "地区编号", example = "20158") |
| 104 | - @ExcelIgnore | |
| 105 | 102 | private Integer areaId; |
| 106 | 103 | |
| 107 | 104 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactPageReqVO.java
| ... | ... | @@ -5,26 +5,20 @@ import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 5 | import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| 7 | 7 | import lombok.ToString; |
| 8 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | - | |
| 10 | -import java.time.LocalDateTime; | |
| 11 | - | |
| 12 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | 8 | |
| 14 | 9 | @Schema(description = "管理后台 - CRM 联系人分页 Request VO") |
| 15 | 10 | @Data |
| 16 | 11 | @EqualsAndHashCode(callSuper = true) |
| 17 | 12 | @ToString(callSuper = true) |
| 18 | 13 | public class ContactPageReqVO extends PageParam { |
| 19 | - | |
| 20 | - // TODO @zyna:筛选条件(多余的可以删除哈)还有部分 example 少了,可以补充下; | |
| 21 | 14 | // ●客户: |
| 22 | 15 | // ●姓名: |
| 23 | 16 | // ●手机、电话、座机、QQ、微信、邮箱 |
| 17 | + @Schema(description = "姓名", example = "芋艿") | |
| 18 | + private String name; | |
| 24 | 19 | |
| 25 | - @Schema(description = "下次联系时间") | |
| 26 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 27 | - private LocalDateTime[] nextTime; | |
| 20 | + @Schema(description = "客户编号", example = "10795") | |
| 21 | + private Long customerId; | |
| 28 | 22 | |
| 29 | 23 | @Schema(description = "手机号", example = "13898273941") |
| 30 | 24 | private String mobile; |
| ... | ... | @@ -35,45 +29,9 @@ public class ContactPageReqVO extends PageParam { |
| 35 | 29 | @Schema(description = "电子邮箱", example = "111@22.com") |
| 36 | 30 | private String email; |
| 37 | 31 | |
| 38 | - @Schema(description = "客户编号", example = "10795") | |
| 39 | - private Long customerId; | |
| 40 | - | |
| 41 | - @Schema(description = "地址") | |
| 42 | - private String address; | |
| 43 | - | |
| 44 | - @Schema(description = "备注", example = "你说的对") | |
| 45 | - private String remark; | |
| 46 | - | |
| 47 | - @Schema(description = "创建时间") | |
| 48 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 49 | - private LocalDateTime[] createTime; | |
| 50 | - | |
| 51 | - @Schema(description = "最后跟进时间") | |
| 52 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 53 | - private LocalDateTime[] lastTime; | |
| 54 | - | |
| 55 | - @Schema(description = "直属上级", example = "23457") | |
| 56 | - private Long parentId; | |
| 57 | - | |
| 58 | - @Schema(description = "姓名", example = "芋艿") | |
| 59 | - private String name; | |
| 60 | - | |
| 61 | - @Schema(description = "职位") | |
| 62 | - private String post; | |
| 63 | - | |
| 64 | 32 | @Schema(description = "QQ", example = "3882872") |
| 65 | 33 | private Long qq; |
| 66 | 34 | |
| 67 | 35 | @Schema(description = "微信", example = "zzZ98373") |
| 68 | 36 | private String wechat; |
| 69 | - | |
| 70 | - @Schema(description = "性别") | |
| 71 | - private Integer sex; | |
| 72 | - | |
| 73 | - @Schema(description = "是否关键决策人") | |
| 74 | - private Boolean master; | |
| 75 | - | |
| 76 | - @Schema(description = "负责人用户编号", example = "14334") | |
| 77 | - private Long ownerUserId; | |
| 78 | - | |
| 79 | 37 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; |
| 2 | 2 | |
| 3 | -import com.alibaba.excel.annotation.ExcelIgnore; | |
| 3 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 4 | 4 | import com.alibaba.excel.annotation.ExcelProperty; |
| 5 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 6 | import lombok.*; |
| ... | ... | @@ -10,18 +10,21 @@ import java.time.LocalDateTime; |
| 10 | 10 | @Data |
| 11 | 11 | @EqualsAndHashCode(callSuper = true) |
| 12 | 12 | @ToString(callSuper = true) |
| 13 | +@ExcelIgnoreUnannotated | |
| 13 | 14 | public class ContactRespVO extends ContactBaseVO { |
| 14 | 15 | |
| 15 | 16 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 16 | - @ExcelIgnore | |
| 17 | 17 | private Long id; |
| 18 | 18 | |
| 19 | 19 | @Schema(description = "创建时间") |
| 20 | 20 | @ExcelProperty(value = "创建时间",order = 8) |
| 21 | 21 | private LocalDateTime createTime; |
| 22 | 22 | |
| 23 | + @Schema(description = "更新时间") | |
| 24 | + @ExcelProperty(value = "更新时间",order = 8) | |
| 25 | + private LocalDateTime updateTime; | |
| 26 | + | |
| 23 | 27 | @Schema(description = "创建人", example = "25682") |
| 24 | - @ExcelIgnore | |
| 25 | 28 | private String creator; |
| 26 | 29 | |
| 27 | 30 | @Schema(description = "创建人名字", example = "test") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactSimpleRespVO.java
| ... | ... | @@ -8,10 +8,12 @@ import lombok.ToString; |
| 8 | 8 | @Data |
| 9 | 9 | @ToString(callSuper = true) |
| 10 | 10 | public class ContactSimpleRespVO { |
| 11 | - @Schema(description = "姓名", example = "芋艿") // TODO @zyna:requiredMode = Schema.RequiredMode.REQUIRED;需要空一行;字段的顺序改下,id 在 name 前面,会更干净 | |
| 12 | - private String name; | |
| 13 | 11 | |
| 14 | 12 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 15 | 13 | private Long id; |
| 16 | 14 | |
| 15 | + @Schema(description = "姓名", example = "芋艿") | |
| 16 | + private String name; | |
| 17 | + | |
| 18 | + | |
| 17 | 19 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java
| ... | ... | @@ -11,10 +11,12 @@ import org.mapstruct.Mapper; |
| 11 | 11 | import org.mapstruct.Mapping; |
| 12 | 12 | import org.mapstruct.Mappings; |
| 13 | 13 | import org.mapstruct.factory.Mappers; |
| 14 | + | |
| 14 | 15 | import java.util.List; |
| 15 | 16 | import java.util.Map; |
| 16 | 17 | import java.util.stream.Collectors; |
| 17 | 18 | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 18 | 20 | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; |
| 19 | 21 | |
| 20 | 22 | /** |
| ... | ... | @@ -37,6 +39,11 @@ public interface ContactConvert { |
| 37 | 39 | |
| 38 | 40 | PageResult<ContactRespVO> convertPage(PageResult<ContactDO> page); |
| 39 | 41 | |
| 42 | + default PageResult<ContactRespVO> convertPage(PageResult<ContactDO> pageResult, Map<Long, AdminUserRespDTO> userMap, | |
| 43 | + List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) { | |
| 44 | + List<ContactRespVO> list = converList(pageResult.getList(), userMap, customerList, parentContactList); | |
| 45 | + return convertPage(pageResult).setList(list); | |
| 46 | + } | |
| 40 | 47 | List<ContactSimpleRespVO> convertAllList(List<ContactDO> list); |
| 41 | 48 | |
| 42 | 49 | @Mappings({ |
| ... | ... | @@ -48,31 +55,35 @@ public interface ContactConvert { |
| 48 | 55 | /** |
| 49 | 56 | * 转换详情信息 |
| 50 | 57 | * |
| 51 | - * @param contactDO 联系人 | |
| 52 | - * @param userMap 用户列表 | |
| 58 | + * @param contactDO 联系人 | |
| 59 | + * @param userMap 用户列表 | |
| 53 | 60 | * @param crmCustomerDOList 客户 |
| 54 | 61 | * @return ContactRespVO |
| 55 | 62 | */ |
| 56 | - default ContactRespVO convert(ContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList, | |
| 57 | - List<ContactDO> contactList) { | |
| 63 | + default ContactRespVO convert(ContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList, | |
| 64 | + List<ContactDO> contactList) { | |
| 58 | 65 | ContactRespVO contactVO = convert(contactDO); |
| 59 | 66 | setUserInfo(contactVO, userMap); |
| 60 | - Map<Long,CrmCustomerDO> ustomerMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v)); | |
| 61 | - Map<Long,ContactDO> contactMap = contactList.stream().collect(Collectors.toMap(ContactDO::getId,v->v)); | |
| 67 | + Map<Long, CrmCustomerDO> ustomerMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId, v -> v)); | |
| 68 | + Map<Long, ContactDO> contactMap = contactList.stream().collect(Collectors.toMap(ContactDO::getId, v -> v)); | |
| 62 | 69 | findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName())); |
| 63 | 70 | findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName())); |
| 64 | 71 | return contactVO; |
| 65 | 72 | } |
| 66 | - default List<ContactRespVO> converList(List<ContactDO> contactList, Map<Long, AdminUserRespDTO> userMap, | |
| 67 | - List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) { | |
| 73 | + | |
| 74 | + default List<ContactRespVO> converList(List<ContactDO> contactList, Map<Long, AdminUserRespDTO> userMap, | |
| 75 | + List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) { | |
| 68 | 76 | List<ContactRespVO> result = convertList(contactList); |
| 69 | - // TODO @zyna:简单的转换,可以使用 CollectionUtils.convertMap | |
| 70 | - Map<Long, ContactDO> parentContactMap = parentContactList.stream().collect(Collectors.toMap(ContactDO::getId,v->v)); | |
| 71 | - Map<Long, CrmCustomerDO> customerMap = customerList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v)); | |
| 77 | + Map<Long, ContactDO> parentContactMap = convertMap(parentContactList, ContactDO::getId); | |
| 78 | + Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId); | |
| 72 | 79 | result.forEach(item -> { |
| 73 | 80 | setUserInfo(item, userMap); |
| 74 | - findAndThen(customerMap,item.getCustomerId(),customer -> {item.setCustomerName(customer.getName());}); | |
| 75 | - findAndThen(parentContactMap,item.getParentId(),contactDO -> {item.setParentName(contactDO.getName());}); | |
| 81 | + findAndThen(customerMap, item.getCustomerId(), customer -> { | |
| 82 | + item.setCustomerName(customer.getName()); | |
| 83 | + }); | |
| 84 | + findAndThen(parentContactMap, item.getParentId(), contactDO -> { | |
| 85 | + item.setParentName(contactDO.getName()); | |
| 86 | + }); | |
| 76 | 87 | }); |
| 77 | 88 | return result; |
| 78 | 89 | } |
| ... | ... | @@ -80,13 +91,13 @@ public interface ContactConvert { |
| 80 | 91 | /** |
| 81 | 92 | * 设置用户信息 |
| 82 | 93 | * |
| 83 | - * @param contactRespVO 联系人Response VO | |
| 84 | - * @param userMap 用户信息 map | |
| 94 | + * @param contactRespVO 联系人Response VO | |
| 95 | + * @param userMap 用户信息 map | |
| 85 | 96 | */ |
| 86 | - static void setUserInfo(ContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap){ | |
| 97 | + static void setUserInfo(ContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap) { | |
| 87 | 98 | contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId())); |
| 88 | 99 | findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> { |
| 89 | - contactRespVO.setOwnerUserName(user == null?"":user.getNickname()); | |
| 100 | + contactRespVO.setOwnerUserName(user == null ? "" : user.getNickname()); | |
| 90 | 101 | }); |
| 91 | 102 | findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname())); |
| 92 | 103 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/ContactMapper.java
| ... | ... | @@ -19,45 +19,25 @@ public interface ContactMapper extends BaseMapperX<ContactDO> { |
| 19 | 19 | |
| 20 | 20 | default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) { |
| 21 | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>() |
| 22 | - .betweenIfPresent(ContactDO::getNextTime, reqVO.getNextTime()) | |
| 23 | 22 | .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) |
| 24 | 23 | .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) |
| 25 | 24 | .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) |
| 26 | 25 | .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) |
| 27 | - .eqIfPresent(ContactDO::getAddress, reqVO.getAddress()) | |
| 28 | - .eqIfPresent(ContactDO::getRemark, reqVO.getRemark()) | |
| 29 | - .betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime()) | |
| 30 | - .betweenIfPresent(ContactDO::getLastTime, reqVO.getLastTime()) | |
| 31 | - .eqIfPresent(ContactDO::getParentId, reqVO.getParentId()) | |
| 32 | 26 | .likeIfPresent(ContactDO::getName, reqVO.getName()) |
| 33 | - .eqIfPresent(ContactDO::getPost, reqVO.getPost()) | |
| 34 | 27 | .eqIfPresent(ContactDO::getQq, reqVO.getQq()) |
| 35 | 28 | .eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) |
| 36 | - .eqIfPresent(ContactDO::getSex, reqVO.getSex()) | |
| 37 | - .eqIfPresent(ContactDO::getMaster, reqVO.getMaster()) | |
| 38 | - .eqIfPresent(ContactDO::getOwnerUserId, reqVO.getOwnerUserId()) | |
| 39 | 29 | .orderByDesc(ContactDO::getId)); |
| 40 | 30 | } |
| 41 | 31 | |
| 42 | 32 | default List<ContactDO> selectList(ContactPageReqVO reqVO) { |
| 43 | 33 | return selectList(new LambdaQueryWrapperX<ContactDO>() |
| 44 | - .betweenIfPresent(ContactDO::getNextTime, reqVO.getNextTime()) | |
| 45 | 34 | .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) |
| 46 | 35 | .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) |
| 47 | 36 | .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) |
| 48 | 37 | .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) |
| 49 | - .eqIfPresent(ContactDO::getAddress, reqVO.getAddress()) | |
| 50 | - .eqIfPresent(ContactDO::getRemark, reqVO.getRemark()) | |
| 51 | - .betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime()) | |
| 52 | - .betweenIfPresent(ContactDO::getLastTime, reqVO.getLastTime()) | |
| 53 | - .eqIfPresent(ContactDO::getParentId, reqVO.getParentId()) | |
| 54 | 38 | .likeIfPresent(ContactDO::getName, reqVO.getName()) |
| 55 | - .eqIfPresent(ContactDO::getPost, reqVO.getPost()) | |
| 56 | 39 | .eqIfPresent(ContactDO::getQq, reqVO.getQq()) |
| 57 | 40 | .eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) |
| 58 | - .eqIfPresent(ContactDO::getSex, reqVO.getSex()) | |
| 59 | - .eqIfPresent(ContactDO::getMaster, reqVO.getMaster()) | |
| 60 | - .eqIfPresent(ContactDO::getOwnerUserId, reqVO.getOwnerUserId()) | |
| 61 | 41 | .orderByDesc(ContactDO::getId)); |
| 62 | 42 | } |
| 63 | 43 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.crm.service.contact; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactBaseVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; |
| 8 | 9 | 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; |
| 12 | 13 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 13 | 14 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; |
| 14 | 15 | import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; |
| 16 | +import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | |
| 15 | 17 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 16 | 18 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 19 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 17 | 20 | import org.springframework.stereotype.Service; |
| 18 | 21 | import org.springframework.transaction.annotation.Transactional; |
| 19 | 22 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -21,9 +24,12 @@ import org.springframework.validation.annotation.Validated; |
| 21 | 24 | import javax.annotation.Resource; |
| 22 | 25 | import java.util.Collection; |
| 23 | 26 | import java.util.List; |
| 27 | +import java.util.Optional; | |
| 24 | 28 | |
| 25 | 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 26 | 30 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; |
| 31 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS; | |
| 32 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; | |
| 27 | 33 | |
| 28 | 34 | /** |
| 29 | 35 | * crm联系人 Service 实现类 |
| ... | ... | @@ -38,10 +44,19 @@ public class ContactServiceImpl implements ContactService { |
| 38 | 44 | private ContactMapper contactMapper; |
| 39 | 45 | |
| 40 | 46 | @Resource |
| 47 | + private CrmCustomerService customerService; | |
| 48 | + | |
| 49 | + @Resource | |
| 50 | + private AdminUserApi adminUserApi; | |
| 51 | + | |
| 52 | + @Resource | |
| 41 | 53 | private CrmPermissionService crmPermissionService; |
| 42 | 54 | |
| 43 | - @Override // TODO @zyna:新增和修改时,关联字段要校验,例如说 直属上级,是不是真的存在; | |
| 55 | + @Override | |
| 44 | 56 | public Long createContact(ContactCreateReqVO createReqVO, Long userId) { |
| 57 | + //@todo | |
| 58 | + //校验 | |
| 59 | + validateDataExist(createReqVO); | |
| 45 | 60 | // 插入 |
| 46 | 61 | ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); |
| 47 | 62 | contactMapper.insert(contact); |
| ... | ... | @@ -60,6 +75,7 @@ public class ContactServiceImpl implements ContactService { |
| 60 | 75 | public void updateContact(ContactUpdateReqVO updateReqVO) { |
| 61 | 76 | // 校验存在 |
| 62 | 77 | validateContactExists(updateReqVO.getId()); |
| 78 | + validateDataExist(updateReqVO); | |
| 63 | 79 | // 更新 |
| 64 | 80 | ContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO); |
| 65 | 81 | contactMapper.updateById(updateObj); |
| ... | ... | @@ -109,4 +125,19 @@ public class ContactServiceImpl implements ContactService { |
| 109 | 125 | public List<ContactDO> getContactList() { |
| 110 | 126 | return contactMapper.selectList(); |
| 111 | 127 | } |
| 128 | + | |
| 129 | + private void validateDataExist(ContactBaseVO contactBaseVO){ | |
| 130 | + //1.校验客户 | |
| 131 | + if (contactBaseVO.getCustomerId() != null) { | |
| 132 | + Optional.ofNullable(customerService.getCustomer(contactBaseVO.getCustomerId())).orElseThrow(() -> exception(CUSTOMER_NOT_EXISTS)); | |
| 133 | + } | |
| 134 | + //2.校验负责人 | |
| 135 | + if (contactBaseVO.getOwnerUserId() != null) { | |
| 136 | + Optional.ofNullable(adminUserApi.getUser(contactBaseVO.getOwnerUserId())).orElseThrow(() -> exception(USER_NOT_EXISTS)); | |
| 137 | + } | |
| 138 | + //3.直属上级 | |
| 139 | + if (contactBaseVO.getParentId() != null) { | |
| 140 | + Optional.ofNullable(contactMapper.selectById(contactBaseVO.getParentId())).orElseThrow(() -> exception(CONTACT_NOT_EXISTS)); | |
| 141 | + } | |
| 142 | + } | |
| 112 | 143 | } | ... | ... |