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,7 +3,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.NumberUtil; | 4 | import cn.hutool.core.util.NumberUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | ||
| 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 10 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; | 11 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; |
| @@ -28,14 +30,13 @@ import javax.annotation.Resource; | @@ -28,14 +30,13 @@ import javax.annotation.Resource; | ||
| 28 | import javax.servlet.http.HttpServletResponse; | 30 | import javax.servlet.http.HttpServletResponse; |
| 29 | import javax.validation.Valid; | 31 | import javax.validation.Valid; |
| 30 | import java.io.IOException; | 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 | import java.util.stream.Stream; | 34 | import java.util.stream.Stream; |
| 36 | 35 | ||
| 37 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 36 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 38 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 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 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 40 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 40 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 41 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 41 | 42 | ||
| @@ -49,7 +50,6 @@ public class ContactController { | @@ -49,7 +50,6 @@ public class ContactController { | ||
| 49 | 50 | ||
| 50 | @Resource | 51 | @Resource |
| 51 | private ContactService contactService; | 52 | private ContactService contactService; |
| 52 | - // TODO @zyna:模块内,注入的变量,不用带 crm 前缀哈 | ||
| 53 | @Resource | 53 | @Resource |
| 54 | private CrmCustomerService crmCustomerService; | 54 | private CrmCustomerService crmCustomerService; |
| 55 | 55 | ||
| @@ -115,43 +115,41 @@ public class ContactController { | @@ -115,43 +115,41 @@ public class ContactController { | ||
| 115 | if (CollUtil.isEmpty(pageResult.getList())) { | 115 | if (CollUtil.isEmpty(pageResult.getList())) { |
| 116 | return success(PageResult.empty(pageResult.getTotal())); | 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 | @GetMapping("/export-excel") | 121 | @GetMapping("/export-excel") |
| 124 | @Operation(summary = "导出联系人 Excel") | 122 | @Operation(summary = "导出联系人 Excel") |
| 125 | @PreAuthorize("@ss.hasPermission('crm:contact:export')") | 123 | @PreAuthorize("@ss.hasPermission('crm:contact:export')") |
| 126 | @OperateLog(type = EXPORT) | 124 | @OperateLog(type = EXPORT) |
| 127 | public void exportContactExcel(@Valid ContactPageReqVO exportReqVO, | 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 | // TODO 芋艿:后续会合并下, | 133 | // TODO 芋艿:后续会合并下, |
| 134 | + | ||
| 137 | /** | 135 | /** |
| 138 | * 翻译字段名称 | 136 | * 翻译字段名称 |
| 139 | - * @param contactDOList 联系人List | 137 | + * |
| 138 | + * @param pageResult 联系人分页参数 | ||
| 140 | * @return List<ContactRespVO> | 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 | // 1. 获取客户列表 | 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 | // 2. 获取创建人、责任人列表 | 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 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList); | 148 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList); |
| 151 | // 3. 直属上级 | 149 | // 3. 直属上级 |
| 152 | - List<Long> contactIdsList = contactDOList.stream().map(ContactDO::getParentId).distinct().collect(Collectors.toList()); | 150 | + Set<Long> contactIdsList = convertSet(contactDOList, ContactDO::getParentId); |
| 153 | List<ContactDO> contactList = contactService.getContactList(contactIdsList); | 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,7 +5,7 @@ import cn.iocoder.yudao.framework.common.validation.Telephone; | ||
| 5 | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | 5 | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| 6 | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | 6 | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| 7 | import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; | 7 | import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; |
| 8 | -import com.alibaba.excel.annotation.ExcelIgnore; | 8 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| 9 | import com.alibaba.excel.annotation.ExcelProperty; | 9 | import com.alibaba.excel.annotation.ExcelProperty; |
| 10 | import io.swagger.v3.oas.annotations.media.Schema; | 10 | import io.swagger.v3.oas.annotations.media.Schema; |
| 11 | import lombok.Data; | 11 | import lombok.Data; |
| @@ -24,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | @@ -24,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||
| 24 | * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | 24 | * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 |
| 25 | */ | 25 | */ |
| 26 | @Data | 26 | @Data |
| 27 | +@ExcelIgnoreUnannotated | ||
| 27 | public class ContactBaseVO { | 28 | public class ContactBaseVO { |
| 28 | 29 | ||
| 29 | @ExcelProperty(value = "姓名",order = 1) | 30 | @ExcelProperty(value = "姓名",order = 1) |
| @@ -32,7 +33,6 @@ public class ContactBaseVO { | @@ -32,7 +33,6 @@ public class ContactBaseVO { | ||
| 32 | private String name; | 33 | private String name; |
| 33 | 34 | ||
| 34 | @Schema(description = "客户编号", example = "10795") | 35 | @Schema(description = "客户编号", example = "10795") |
| 35 | - @ExcelIgnore | ||
| 36 | private Long customerId; | 36 | private Long customerId; |
| 37 | 37 | ||
| 38 | @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) | 38 | @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) |
| @@ -50,7 +50,6 @@ public class ContactBaseVO { | @@ -50,7 +50,6 @@ public class ContactBaseVO { | ||
| 50 | private Boolean master; | 50 | private Boolean master; |
| 51 | 51 | ||
| 52 | @Schema(description = "直属上级", example = "23457") | 52 | @Schema(description = "直属上级", example = "23457") |
| 53 | - @ExcelIgnore | ||
| 54 | private Long parentId; | 53 | private Long parentId; |
| 55 | 54 | ||
| 56 | @Schema(description = "手机号",example = "1387171766") | 55 | @Schema(description = "手机号",example = "1387171766") |
| @@ -97,11 +96,9 @@ public class ContactBaseVO { | @@ -97,11 +96,9 @@ public class ContactBaseVO { | ||
| 97 | 96 | ||
| 98 | @Schema(description = "负责人用户编号", example = "14334") | 97 | @Schema(description = "负责人用户编号", example = "14334") |
| 99 | @NotNull(message = "负责人不能为空") | 98 | @NotNull(message = "负责人不能为空") |
| 100 | - @ExcelIgnore // TODO @zyna:可以使用 ExcelIgnoreUnannotated | ||
| 101 | private Long ownerUserId; | 99 | private Long ownerUserId; |
| 102 | 100 | ||
| 103 | @Schema(description = "地区编号", example = "20158") | 101 | @Schema(description = "地区编号", example = "20158") |
| 104 | - @ExcelIgnore | ||
| 105 | private Integer areaId; | 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,26 +5,20 @@ import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | import lombok.Data; | 5 | import lombok.Data; |
| 6 | import lombok.EqualsAndHashCode; | 6 | import lombok.EqualsAndHashCode; |
| 7 | import lombok.ToString; | 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 | @Schema(description = "管理后台 - CRM 联系人分页 Request VO") | 9 | @Schema(description = "管理后台 - CRM 联系人分页 Request VO") |
| 15 | @Data | 10 | @Data |
| 16 | @EqualsAndHashCode(callSuper = true) | 11 | @EqualsAndHashCode(callSuper = true) |
| 17 | @ToString(callSuper = true) | 12 | @ToString(callSuper = true) |
| 18 | public class ContactPageReqVO extends PageParam { | 13 | public class ContactPageReqVO extends PageParam { |
| 19 | - | ||
| 20 | - // TODO @zyna:筛选条件(多余的可以删除哈)还有部分 example 少了,可以补充下; | ||
| 21 | // ●客户: | 14 | // ●客户: |
| 22 | // ●姓名: | 15 | // ●姓名: |
| 23 | // ●手机、电话、座机、QQ、微信、邮箱 | 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 | @Schema(description = "手机号", example = "13898273941") | 23 | @Schema(description = "手机号", example = "13898273941") |
| 30 | private String mobile; | 24 | private String mobile; |
| @@ -35,45 +29,9 @@ public class ContactPageReqVO extends PageParam { | @@ -35,45 +29,9 @@ public class ContactPageReqVO extends PageParam { | ||
| 35 | @Schema(description = "电子邮箱", example = "111@22.com") | 29 | @Schema(description = "电子邮箱", example = "111@22.com") |
| 36 | private String email; | 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 | @Schema(description = "QQ", example = "3882872") | 32 | @Schema(description = "QQ", example = "3882872") |
| 65 | private Long qq; | 33 | private Long qq; |
| 66 | 34 | ||
| 67 | @Schema(description = "微信", example = "zzZ98373") | 35 | @Schema(description = "微信", example = "zzZ98373") |
| 68 | private String wechat; | 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 | package cn.iocoder.yudao.module.crm.controller.admin.contact.vo; | 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 | import com.alibaba.excel.annotation.ExcelProperty; | 4 | import com.alibaba.excel.annotation.ExcelProperty; |
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | import lombok.*; | 6 | import lombok.*; |
| @@ -10,18 +10,21 @@ import java.time.LocalDateTime; | @@ -10,18 +10,21 @@ import java.time.LocalDateTime; | ||
| 10 | @Data | 10 | @Data |
| 11 | @EqualsAndHashCode(callSuper = true) | 11 | @EqualsAndHashCode(callSuper = true) |
| 12 | @ToString(callSuper = true) | 12 | @ToString(callSuper = true) |
| 13 | +@ExcelIgnoreUnannotated | ||
| 13 | public class ContactRespVO extends ContactBaseVO { | 14 | public class ContactRespVO extends ContactBaseVO { |
| 14 | 15 | ||
| 15 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") | 16 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 16 | - @ExcelIgnore | ||
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | @Schema(description = "创建时间") | 19 | @Schema(description = "创建时间") |
| 20 | @ExcelProperty(value = "创建时间",order = 8) | 20 | @ExcelProperty(value = "创建时间",order = 8) |
| 21 | private LocalDateTime createTime; | 21 | private LocalDateTime createTime; |
| 22 | 22 | ||
| 23 | + @Schema(description = "更新时间") | ||
| 24 | + @ExcelProperty(value = "更新时间",order = 8) | ||
| 25 | + private LocalDateTime updateTime; | ||
| 26 | + | ||
| 23 | @Schema(description = "创建人", example = "25682") | 27 | @Schema(description = "创建人", example = "25682") |
| 24 | - @ExcelIgnore | ||
| 25 | private String creator; | 28 | private String creator; |
| 26 | 29 | ||
| 27 | @Schema(description = "创建人名字", example = "test") | 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,10 +8,12 @@ import lombok.ToString; | ||
| 8 | @Data | 8 | @Data |
| 9 | @ToString(callSuper = true) | 9 | @ToString(callSuper = true) |
| 10 | public class ContactSimpleRespVO { | 10 | public class ContactSimpleRespVO { |
| 11 | - @Schema(description = "姓名", example = "芋艿") // TODO @zyna:requiredMode = Schema.RequiredMode.REQUIRED;需要空一行;字段的顺序改下,id 在 name 前面,会更干净 | ||
| 12 | - private String name; | ||
| 13 | 11 | ||
| 14 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") | 12 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 15 | private Long id; | 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,10 +11,12 @@ import org.mapstruct.Mapper; | ||
| 11 | import org.mapstruct.Mapping; | 11 | import org.mapstruct.Mapping; |
| 12 | import org.mapstruct.Mappings; | 12 | import org.mapstruct.Mappings; |
| 13 | import org.mapstruct.factory.Mappers; | 13 | import org.mapstruct.factory.Mappers; |
| 14 | + | ||
| 14 | import java.util.List; | 15 | import java.util.List; |
| 15 | import java.util.Map; | 16 | import java.util.Map; |
| 16 | import java.util.stream.Collectors; | 17 | import java.util.stream.Collectors; |
| 17 | 18 | ||
| 19 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 18 | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | 20 | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; |
| 19 | 21 | ||
| 20 | /** | 22 | /** |
| @@ -37,6 +39,11 @@ public interface ContactConvert { | @@ -37,6 +39,11 @@ public interface ContactConvert { | ||
| 37 | 39 | ||
| 38 | PageResult<ContactRespVO> convertPage(PageResult<ContactDO> page); | 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 | List<ContactSimpleRespVO> convertAllList(List<ContactDO> list); | 47 | List<ContactSimpleRespVO> convertAllList(List<ContactDO> list); |
| 41 | 48 | ||
| 42 | @Mappings({ | 49 | @Mappings({ |
| @@ -48,31 +55,35 @@ public interface ContactConvert { | @@ -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 | * @param crmCustomerDOList 客户 | 60 | * @param crmCustomerDOList 客户 |
| 54 | * @return ContactRespVO | 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 | ContactRespVO contactVO = convert(contactDO); | 65 | ContactRespVO contactVO = convert(contactDO); |
| 59 | setUserInfo(contactVO, userMap); | 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 | findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName())); | 69 | findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName())); |
| 63 | findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName())); | 70 | findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName())); |
| 64 | return contactVO; | 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 | List<ContactRespVO> result = convertList(contactList); | 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 | result.forEach(item -> { | 79 | result.forEach(item -> { |
| 73 | setUserInfo(item, userMap); | 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 | return result; | 88 | return result; |
| 78 | } | 89 | } |
| @@ -80,13 +91,13 @@ public interface ContactConvert { | @@ -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 | contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId())); | 98 | contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId())); |
| 88 | findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> { | 99 | findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> { |
| 89 | - contactRespVO.setOwnerUserName(user == null?"":user.getNickname()); | 100 | + contactRespVO.setOwnerUserName(user == null ? "" : user.getNickname()); |
| 90 | }); | 101 | }); |
| 91 | findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname())); | 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,45 +19,25 @@ public interface ContactMapper extends BaseMapperX<ContactDO> { | ||
| 19 | 19 | ||
| 20 | default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) { | 20 | default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) { |
| 21 | return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>() | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>() |
| 22 | - .betweenIfPresent(ContactDO::getNextTime, reqVO.getNextTime()) | ||
| 23 | .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) | 22 | .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) |
| 24 | .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) | 23 | .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) |
| 25 | .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) | 24 | .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) |
| 26 | .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) | 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 | .likeIfPresent(ContactDO::getName, reqVO.getName()) | 26 | .likeIfPresent(ContactDO::getName, reqVO.getName()) |
| 33 | - .eqIfPresent(ContactDO::getPost, reqVO.getPost()) | ||
| 34 | .eqIfPresent(ContactDO::getQq, reqVO.getQq()) | 27 | .eqIfPresent(ContactDO::getQq, reqVO.getQq()) |
| 35 | .eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) | 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 | .orderByDesc(ContactDO::getId)); | 29 | .orderByDesc(ContactDO::getId)); |
| 40 | } | 30 | } |
| 41 | 31 | ||
| 42 | default List<ContactDO> selectList(ContactPageReqVO reqVO) { | 32 | default List<ContactDO> selectList(ContactPageReqVO reqVO) { |
| 43 | return selectList(new LambdaQueryWrapperX<ContactDO>() | 33 | return selectList(new LambdaQueryWrapperX<ContactDO>() |
| 44 | - .betweenIfPresent(ContactDO::getNextTime, reqVO.getNextTime()) | ||
| 45 | .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) | 34 | .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) |
| 46 | .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) | 35 | .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) |
| 47 | .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) | 36 | .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) |
| 48 | .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) | 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 | .likeIfPresent(ContactDO::getName, reqVO.getName()) | 38 | .likeIfPresent(ContactDO::getName, reqVO.getName()) |
| 55 | - .eqIfPresent(ContactDO::getPost, reqVO.getPost()) | ||
| 56 | .eqIfPresent(ContactDO::getQq, reqVO.getQq()) | 39 | .eqIfPresent(ContactDO::getQq, reqVO.getQq()) |
| 57 | .eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) | 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 | .orderByDesc(ContactDO::getId)); | 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,6 +3,7 @@ package cn.iocoder.yudao.module.crm.service.contact; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.collection.ListUtil; | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactBaseVO; | ||
| 6 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; |
| 7 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; | 8 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; |
| 8 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO; | 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,8 +13,10 @@ import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper; | ||
| 12 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; | 13 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 13 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; | 14 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; |
| 14 | import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; | 15 | import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; |
| 16 | +import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | ||
| 15 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | 17 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 16 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; | 18 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| 19 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 17 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Transactional; | 21 | import org.springframework.transaction.annotation.Transactional; |
| 19 | import org.springframework.validation.annotation.Validated; | 22 | import org.springframework.validation.annotation.Validated; |
| @@ -21,9 +24,12 @@ import org.springframework.validation.annotation.Validated; | @@ -21,9 +24,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 21 | import javax.annotation.Resource; | 24 | import javax.annotation.Resource; |
| 22 | import java.util.Collection; | 25 | import java.util.Collection; |
| 23 | import java.util.List; | 26 | import java.util.List; |
| 27 | +import java.util.Optional; | ||
| 24 | 28 | ||
| 25 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 26 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; | 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 | * crm联系人 Service 实现类 | 35 | * crm联系人 Service 实现类 |
| @@ -38,10 +44,19 @@ public class ContactServiceImpl implements ContactService { | @@ -38,10 +44,19 @@ public class ContactServiceImpl implements ContactService { | ||
| 38 | private ContactMapper contactMapper; | 44 | private ContactMapper contactMapper; |
| 39 | 45 | ||
| 40 | @Resource | 46 | @Resource |
| 47 | + private CrmCustomerService customerService; | ||
| 48 | + | ||
| 49 | + @Resource | ||
| 50 | + private AdminUserApi adminUserApi; | ||
| 51 | + | ||
| 52 | + @Resource | ||
| 41 | private CrmPermissionService crmPermissionService; | 53 | private CrmPermissionService crmPermissionService; |
| 42 | 54 | ||
| 43 | - @Override // TODO @zyna:新增和修改时,关联字段要校验,例如说 直属上级,是不是真的存在; | 55 | + @Override |
| 44 | public Long createContact(ContactCreateReqVO createReqVO, Long userId) { | 56 | public Long createContact(ContactCreateReqVO createReqVO, Long userId) { |
| 57 | + //@todo | ||
| 58 | + //校验 | ||
| 59 | + validateDataExist(createReqVO); | ||
| 45 | // 插入 | 60 | // 插入 |
| 46 | ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); | 61 | ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); |
| 47 | contactMapper.insert(contact); | 62 | contactMapper.insert(contact); |
| @@ -60,6 +75,7 @@ public class ContactServiceImpl implements ContactService { | @@ -60,6 +75,7 @@ public class ContactServiceImpl implements ContactService { | ||
| 60 | public void updateContact(ContactUpdateReqVO updateReqVO) { | 75 | public void updateContact(ContactUpdateReqVO updateReqVO) { |
| 61 | // 校验存在 | 76 | // 校验存在 |
| 62 | validateContactExists(updateReqVO.getId()); | 77 | validateContactExists(updateReqVO.getId()); |
| 78 | + validateDataExist(updateReqVO); | ||
| 63 | // 更新 | 79 | // 更新 |
| 64 | ContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO); | 80 | ContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO); |
| 65 | contactMapper.updateById(updateObj); | 81 | contactMapper.updateById(updateObj); |
| @@ -109,4 +125,19 @@ public class ContactServiceImpl implements ContactService { | @@ -109,4 +125,19 @@ public class ContactServiceImpl implements ContactService { | ||
| 109 | public List<ContactDO> getContactList() { | 125 | public List<ContactDO> getContactList() { |
| 110 | return contactMapper.selectList(); | 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 | } |