Commit 53b8e37f36236ba3789abb80807fce7381a27902
1 parent
1a93e3a1
crm: 增加联系人,基于客户的读取接口
Showing
15 changed files
with
222 additions
and
208 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.controller.admin.contact; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.lang.Assert; | |
| 4 | 5 | import cn.hutool.core.util.NumberUtil; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| ... | ... | @@ -10,10 +11,10 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 10 | 11 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 11 | 12 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; |
| 12 | 13 | import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; |
| 13 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | |
| 14 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | |
| 14 | 15 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 15 | 16 | import cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants; |
| 16 | -import cn.iocoder.yudao.module.crm.service.contact.ContactService; | |
| 17 | +import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; | |
| 17 | 18 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 18 | 19 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 19 | 20 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| ... | ... | @@ -30,7 +31,9 @@ import javax.annotation.Resource; |
| 30 | 31 | import javax.servlet.http.HttpServletResponse; |
| 31 | 32 | import javax.validation.Valid; |
| 32 | 33 | import java.io.IOException; |
| 33 | -import java.util.*; | |
| 34 | +import java.util.Collections; | |
| 35 | +import java.util.List; | |
| 36 | +import java.util.Map; | |
| 34 | 37 | import java.util.stream.Stream; |
| 35 | 38 | |
| 36 | 39 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -40,18 +43,17 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 40 | 43 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 41 | 44 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 42 | 45 | |
| 43 | -// TODO @zya:crm 所有的类,dou带 Crm 前缀,因为它的名字太通用了,可能和后续的 erp 之类的冲突 | |
| 44 | 46 | @Tag(name = "管理后台 - CRM 联系人") |
| 45 | 47 | @RestController |
| 46 | 48 | @RequestMapping("/crm/contact") |
| 47 | 49 | @Validated |
| 48 | 50 | @Slf4j |
| 49 | -public class ContactController { | |
| 51 | +public class CrmContactController { | |
| 50 | 52 | |
| 51 | 53 | @Resource |
| 52 | - private ContactService contactService; | |
| 54 | + private CrmContactService contactService; | |
| 53 | 55 | @Resource |
| 54 | - private CrmCustomerService crmCustomerService; | |
| 56 | + private CrmCustomerService customerService; | |
| 55 | 57 | |
| 56 | 58 | @Resource |
| 57 | 59 | private AdminUserApi adminUserApi; |
| ... | ... | @@ -59,14 +61,14 @@ public class ContactController { |
| 59 | 61 | @PostMapping("/create") |
| 60 | 62 | @Operation(summary = "创建联系人") |
| 61 | 63 | @PreAuthorize("@ss.hasPermission('crm:contact:create')") |
| 62 | - public CommonResult<Long> createContact(@Valid @RequestBody ContactCreateReqVO createReqVO) { | |
| 64 | + public CommonResult<Long> createContact(@Valid @RequestBody CrmContactCreateReqVO createReqVO) { | |
| 63 | 65 | return success(contactService.createContact(createReqVO, getLoginUserId())); |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | @PutMapping("/update") |
| 67 | 69 | @Operation(summary = "更新联系人") |
| 68 | 70 | @PreAuthorize("@ss.hasPermission('crm:contact:update')") |
| 69 | - public CommonResult<Boolean> updateContact(@Valid @RequestBody ContactUpdateReqVO updateReqVO) { | |
| 71 | + public CommonResult<Boolean> updateContact(@Valid @RequestBody CrmContactUpdateReqVO updateReqVO) { | |
| 70 | 72 | contactService.updateContact(updateReqVO); |
| 71 | 73 | return success(true); |
| 72 | 74 | } |
| ... | ... | @@ -84,8 +86,8 @@ public class ContactController { |
| 84 | 86 | @Operation(summary = "获得联系人") |
| 85 | 87 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 86 | 88 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| 87 | - public CommonResult<ContactRespVO> getContact(@RequestParam("id") Long id) { | |
| 88 | - ContactDO contact = contactService.getContact(id); | |
| 89 | + public CommonResult<CrmContactRespVO> getContact(@RequestParam("id") Long id) { | |
| 90 | + CrmContactDO contact = contactService.getContact(id); | |
| 89 | 91 | if (contact == null) { |
| 90 | 92 | throw exception(ErrorCodeConstants.CONTACT_NOT_EXISTS); |
| 91 | 93 | } |
| ... | ... | @@ -93,63 +95,69 @@ public class ContactController { |
| 93 | 95 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList( |
| 94 | 96 | NumberUtil.parseLong(contact.getCreator()), contact.getOwnerUserId()))); |
| 95 | 97 | // 2. 获取客户信息 |
| 96 | - List<CrmCustomerDO> customerList = crmCustomerService.getCustomerList(Collections.singletonList(contact.getCustomerId())); | |
| 98 | + List<CrmCustomerDO> customerList = customerService.getCustomerList(Collections.singletonList(contact.getCustomerId())); | |
| 97 | 99 | // 3. 直属上级 |
| 98 | - List<ContactDO> parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId())); | |
| 100 | + List<CrmContactDO> parentContactList = contactService.getContactList(Collections.singletonList(contact.getParentId())); | |
| 99 | 101 | return success(ContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); |
| 100 | 102 | } |
| 101 | 103 | |
| 102 | 104 | @GetMapping("/simple-all-list") |
| 103 | 105 | @Operation(summary = "获得联系人列表") |
| 104 | 106 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| 105 | - public CommonResult<List<ContactSimpleRespVO>> getContactList() { | |
| 106 | - List<ContactDO> list = contactService.getContactList(); | |
| 107 | + public CommonResult<List<CrmContactSimpleRespVO>> getSimpleContactList() { | |
| 108 | + List<CrmContactDO> list = contactService.getContactList(); | |
| 107 | 109 | return success(ContactConvert.INSTANCE.convertAllList(list)); |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | @GetMapping("/page") |
| 111 | 113 | @Operation(summary = "获得联系人分页") |
| 112 | 114 | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| 113 | - public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) { | |
| 114 | - PageResult<ContactDO> pageResult = contactService.getContactPage(pageVO); | |
| 115 | - if (CollUtil.isEmpty(pageResult.getList())) { | |
| 116 | - return success(PageResult.empty(pageResult.getTotal())); | |
| 117 | - } | |
| 118 | - return success(convertFieldValue2Name(pageResult)); | |
| 115 | + public CommonResult<PageResult<CrmContactRespVO>> getContactPage(@Valid CrmContactPageReqVO pageVO) { | |
| 116 | + PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO); | |
| 117 | + return success(convertDetailContactPage(pageResult)); | |
| 118 | + } | |
| 119 | + | |
| 120 | + @GetMapping("/page-by-customer") | |
| 121 | + @Operation(summary = "获得联系人分页,基于指定客户") | |
| 122 | + public CommonResult<PageResult<CrmContactRespVO>> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { | |
| 123 | + Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); | |
| 124 | + PageResult<CrmContactDO> pageResult = contactService.getContactPageByCustomer(pageVO); | |
| 125 | + return success(convertDetailContactPage(pageResult)); | |
| 119 | 126 | } |
| 120 | 127 | |
| 121 | 128 | @GetMapping("/export-excel") |
| 122 | 129 | @Operation(summary = "导出联系人 Excel") |
| 123 | 130 | @PreAuthorize("@ss.hasPermission('crm:contact:export')") |
| 124 | 131 | @OperateLog(type = EXPORT) |
| 125 | - public void exportContactExcel(@Valid ContactPageReqVO exportReqVO, | |
| 132 | + public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO, | |
| 126 | 133 | HttpServletResponse response) throws IOException { |
| 127 | 134 | 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()); | |
| 135 | + PageResult<CrmContactDO> pageResult = contactService.getContactPage(exportReqVO); | |
| 136 | + ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, | |
| 137 | + convertDetailContactPage(pageResult).getList()); | |
| 131 | 138 | } |
| 132 | 139 | |
| 133 | - // TODO 芋艿:后续会合并下, | |
| 134 | - | |
| 135 | 140 | /** |
| 136 | - * 翻译字段名称 | |
| 141 | + * 转换成详细的联系人分页,即读取关联信息 | |
| 137 | 142 | * |
| 138 | - * @param pageResult 联系人分页参数 | |
| 139 | - * @return List<ContactRespVO> | |
| 143 | + * @param pageResult 联系人分页 | |
| 144 | + * @return 详细的联系人分页 | |
| 140 | 145 | */ |
| 141 | - private PageResult<ContactRespVO> convertFieldValue2Name(PageResult<ContactDO> pageResult) { | |
| 142 | - List<ContactDO> contactDOList = pageResult.getList(); | |
| 146 | + private PageResult<CrmContactRespVO> convertDetailContactPage(PageResult<CrmContactDO> pageResult) { | |
| 147 | + List<CrmContactDO> contactList = pageResult.getList(); | |
| 148 | + if (CollUtil.isEmpty(contactList)) { | |
| 149 | + return PageResult.empty(pageResult.getTotal()); | |
| 150 | + } | |
| 143 | 151 | // 1. 获取客户列表 |
| 144 | - List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(convertSet(contactDOList, ContactDO::getCustomerId)); | |
| 152 | + List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList( | |
| 153 | + convertSet(contactList, CrmContactDO::getCustomerId)); | |
| 145 | 154 | // 2. 获取创建人、责任人列表 |
| 146 | - List<Long> userIdsList = convertListByFlatMap(contactDOList, item -> Stream.of(NumberUtils.parseLong(item.getCreator()), item.getOwnerUserId()) | |
| 147 | - .filter(Objects::nonNull)); // TODO @zyna:里面已经忽略 null 啦 | |
| 148 | - Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList); | |
| 155 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, | |
| 156 | + contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); | |
| 149 | 157 | // 3. 直属上级 |
| 150 | - Set<Long> contactIdsList = convertSet(contactDOList, ContactDO::getParentId); | |
| 151 | - List<ContactDO> contactList = contactService.getContactList(contactIdsList); | |
| 152 | - return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, contactList); | |
| 158 | + List<CrmContactDO> parentContactList = contactService.getContactList( | |
| 159 | + convertSet(contactList, CrmContactDO::getParentId)); | |
| 160 | + return ContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); | |
| 153 | 161 | } |
| 154 | 162 | |
| 155 | 163 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactBaseVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactBaseVO.java
| ... | ... | @@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ |
| 25 | 25 | */ |
| 26 | 26 | @Data |
| 27 | 27 | @ExcelIgnoreUnannotated |
| 28 | -public class ContactBaseVO { | |
| 28 | +public class CrmContactBaseVO { | |
| 29 | 29 | |
| 30 | 30 | @ExcelProperty(value = "姓名",order = 1) |
| 31 | 31 | @Schema(description = "姓名", example = "芋艿") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactCreateReqVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactCreateReqVO.java
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactPageReqVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactPageReqVO.java
| ... | ... | @@ -10,10 +10,8 @@ import lombok.ToString; |
| 10 | 10 | @Data |
| 11 | 11 | @EqualsAndHashCode(callSuper = true) |
| 12 | 12 | @ToString(callSuper = true) |
| 13 | -public class ContactPageReqVO extends PageParam { | |
| 14 | - // ●客户: | |
| 15 | - // ●姓名: | |
| 16 | - // ●手机、电话、座机、QQ、微信、邮箱 | |
| 13 | +public class CrmContactPageReqVO extends PageParam { | |
| 14 | + | |
| 17 | 15 | @Schema(description = "姓名", example = "芋艿") |
| 18 | 16 | private String name; |
| 19 | 17 | |
| ... | ... | @@ -34,4 +32,5 @@ public class ContactPageReqVO extends PageParam { |
| 34 | 32 | |
| 35 | 33 | @Schema(description = "微信", example = "zzZ98373") |
| 36 | 34 | private String wechat; |
| 35 | + | |
| 37 | 36 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactRespVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactRespVO.java
| ... | ... | @@ -11,24 +11,24 @@ import java.time.LocalDateTime; |
| 11 | 11 | @EqualsAndHashCode(callSuper = true) |
| 12 | 12 | @ToString(callSuper = true) |
| 13 | 13 | @ExcelIgnoreUnannotated |
| 14 | -public class ContactRespVO extends ContactBaseVO { | |
| 14 | +public class CrmContactRespVO extends CrmContactBaseVO { | |
| 15 | 15 | |
| 16 | 16 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 17 | 17 | private Long id; |
| 18 | 18 | |
| 19 | 19 | @Schema(description = "创建时间") |
| 20 | - @ExcelProperty(value = "创建时间",order = 8) | |
| 20 | + @ExcelProperty(value = "创建时间", order = 8) | |
| 21 | 21 | private LocalDateTime createTime; |
| 22 | 22 | |
| 23 | 23 | @Schema(description = "更新时间") |
| 24 | - @ExcelProperty(value = "更新时间",order = 8) | |
| 24 | + @ExcelProperty(value = "更新时间", order = 8) | |
| 25 | 25 | private LocalDateTime updateTime; |
| 26 | 26 | |
| 27 | 27 | @Schema(description = "创建人", example = "25682") |
| 28 | 28 | private String creator; |
| 29 | 29 | |
| 30 | 30 | @Schema(description = "创建人名字", example = "test") |
| 31 | - @ExcelProperty(value = "创建人",order = 8) | |
| 31 | + @ExcelProperty(value = "创建人", order = 8) | |
| 32 | 32 | private String creatorName; |
| 33 | 33 | |
| 34 | 34 | @ExcelProperty(value = "客户名称",order = 2) |
| ... | ... | @@ -36,14 +36,15 @@ public class ContactRespVO extends ContactBaseVO { |
| 36 | 36 | private String customerName; |
| 37 | 37 | |
| 38 | 38 | @Schema(description = "负责人", example = "test") |
| 39 | - @ExcelProperty(value = "负责人",order = 7) | |
| 39 | + @ExcelProperty(value = "负责人", order = 7) | |
| 40 | 40 | private String ownerUserName; |
| 41 | 41 | |
| 42 | - @Schema(description = "直属上级名",example = "芋头") | |
| 43 | - @ExcelProperty(value = "直属上级",order = 4) | |
| 42 | + @Schema(description = "直属上级名", example = "芋头") | |
| 43 | + @ExcelProperty(value = "直属上级", order = 4) | |
| 44 | 44 | private String parentName; |
| 45 | 45 | |
| 46 | - @Schema(description = "地区名",example = "上海上海市浦东新区") | |
| 47 | - @ExcelProperty(value = "地区",order = 5) | |
| 46 | + @Schema(description = "地区名", example = "上海上海市浦东新区") | |
| 47 | + @ExcelProperty(value = "地区", order = 5) | |
| 48 | 48 | private String areaName; |
| 49 | + | |
| 49 | 50 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactSimpleRespVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactSimpleRespVO.java
| ... | ... | @@ -4,15 +4,15 @@ import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | import lombok.ToString; |
| 6 | 6 | |
| 7 | -@Schema(description = "管理后台 - CRM 联系人 Response VO") | |
| 7 | +@Schema(description = "管理后台 - CRM 联系人的精简 Response VO") | |
| 8 | 8 | @Data |
| 9 | 9 | @ToString(callSuper = true) |
| 10 | -public class ContactSimpleRespVO { | |
| 10 | +public class CrmContactSimpleRespVO { | |
| 11 | 11 | |
| 12 | 12 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 13 | 13 | private Long id; |
| 14 | 14 | |
| 15 | 15 | @Schema(description = "姓名", example = "芋艿") |
| 16 | 16 | private String name; |
| 17 | - | |
| 17 | + | |
| 18 | 18 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/ContactUpdateReqVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactUpdateReqVO.java
| ... | ... | @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull; |
| 11 | 11 | @Data |
| 12 | 12 | @EqualsAndHashCode(callSuper = true) |
| 13 | 13 | @ToString(callSuper = true) |
| 14 | -public class ContactUpdateReqVO extends ContactBaseVO { | |
| 14 | +public class CrmContactUpdateReqVO extends CrmContactBaseVO { | |
| 15 | 15 | |
| 16 | 16 | @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") |
| 17 | 17 | @NotNull(message = "主键不能为空") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.crm.convert.contact; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; |
| 6 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | |
| 6 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | |
| 7 | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 8 | 8 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| ... | ... | @@ -20,7 +20,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 20 | 20 | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * crm联系人 Convert | |
| 23 | + * CRM 联系人 Convert | |
| 24 | 24 | * |
| 25 | 25 | * @author 芋道源码 |
| 26 | 26 | */ |
| ... | ... | @@ -29,22 +29,22 @@ public interface ContactConvert { |
| 29 | 29 | |
| 30 | 30 | ContactConvert INSTANCE = Mappers.getMapper(ContactConvert.class); |
| 31 | 31 | |
| 32 | - ContactDO convert(ContactCreateReqVO bean); | |
| 32 | + CrmContactDO convert(CrmContactCreateReqVO bean); | |
| 33 | 33 | |
| 34 | - ContactDO convert(ContactUpdateReqVO bean); | |
| 34 | + CrmContactDO convert(CrmContactUpdateReqVO bean); | |
| 35 | 35 | |
| 36 | - ContactRespVO convert(ContactDO bean); | |
| 36 | + CrmContactRespVO convert(CrmContactDO bean); | |
| 37 | 37 | |
| 38 | - List<ContactRespVO> convertList(List<ContactDO> list); | |
| 38 | + List<CrmContactRespVO> convertList(List<CrmContactDO> list); | |
| 39 | 39 | |
| 40 | - PageResult<ContactRespVO> convertPage(PageResult<ContactDO> page); | |
| 40 | + PageResult<CrmContactRespVO> convertPage(PageResult<CrmContactDO> page); | |
| 41 | 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); | |
| 42 | + default PageResult<CrmContactRespVO> convertPage(PageResult<CrmContactDO> pageResult, Map<Long, AdminUserRespDTO> userMap, | |
| 43 | + List<CrmCustomerDO> customerList, List<CrmContactDO> parentContactList) { | |
| 44 | + List<CrmContactRespVO> list = converList(pageResult.getList(), userMap, customerList, parentContactList); | |
| 45 | 45 | return convertPage(pageResult).setList(list); |
| 46 | 46 | } |
| 47 | - List<ContactSimpleRespVO> convertAllList(List<ContactDO> list); | |
| 47 | + List<CrmContactSimpleRespVO> convertAllList(List<CrmContactDO> list); | |
| 48 | 48 | |
| 49 | 49 | @Mappings({ |
| 50 | 50 | @Mapping(target = "bizId", source = "reqVO.id"), |
| ... | ... | @@ -60,21 +60,21 @@ public interface ContactConvert { |
| 60 | 60 | * @param crmCustomerDOList 客户 |
| 61 | 61 | * @return ContactRespVO |
| 62 | 62 | */ |
| 63 | - default ContactRespVO convert(ContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList, | |
| 64 | - List<ContactDO> contactList) { | |
| 65 | - ContactRespVO contactVO = convert(contactDO); | |
| 63 | + default CrmContactRespVO convert(CrmContactDO contactDO, Map<Long, AdminUserRespDTO> userMap, List<CrmCustomerDO> crmCustomerDOList, | |
| 64 | + List<CrmContactDO> contactList) { | |
| 65 | + CrmContactRespVO contactVO = convert(contactDO); | |
| 66 | 66 | setUserInfo(contactVO, userMap); |
| 67 | 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)); | |
| 68 | + Map<Long, CrmContactDO> contactMap = contactList.stream().collect(Collectors.toMap(CrmContactDO::getId, v -> v)); | |
| 69 | 69 | findAndThen(ustomerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName())); |
| 70 | 70 | findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName())); |
| 71 | 71 | return contactVO; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - default List<ContactRespVO> converList(List<ContactDO> contactList, Map<Long, AdminUserRespDTO> userMap, | |
| 75 | - List<CrmCustomerDO> customerList, List<ContactDO> parentContactList) { | |
| 76 | - List<ContactRespVO> result = convertList(contactList); | |
| 77 | - Map<Long, ContactDO> parentContactMap = convertMap(parentContactList, ContactDO::getId); | |
| 74 | + default List<CrmContactRespVO> converList(List<CrmContactDO> contactList, Map<Long, AdminUserRespDTO> userMap, | |
| 75 | + List<CrmCustomerDO> customerList, List<CrmContactDO> parentContactList) { | |
| 76 | + List<CrmContactRespVO> result = convertList(contactList); | |
| 77 | + Map<Long, CrmContactDO> parentContactMap = convertMap(parentContactList, CrmContactDO::getId); | |
| 78 | 78 | Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId); |
| 79 | 79 | result.forEach(item -> { |
| 80 | 80 | setUserInfo(item, userMap); |
| ... | ... | @@ -94,7 +94,7 @@ public interface ContactConvert { |
| 94 | 94 | * @param contactRespVO 联系人Response VO |
| 95 | 95 | * @param userMap 用户信息 map |
| 96 | 96 | */ |
| 97 | - static void setUserInfo(ContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap) { | |
| 97 | + static void setUserInfo(CrmContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap) { | |
| 98 | 98 | contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId())); |
| 99 | 99 | findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> { |
| 100 | 100 | contactRespVO.setOwnerUserName(user == null ? "" : user.getNickname()); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/ContactDO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/CrmContactDO.java
| ... | ... | @@ -21,7 +21,7 @@ import java.time.LocalDateTime; |
| 21 | 21 | @Builder |
| 22 | 22 | @NoArgsConstructor |
| 23 | 23 | @AllArgsConstructor |
| 24 | -public class ContactDO extends BaseDO { | |
| 24 | +public class CrmContactDO extends BaseDO { | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * 主键 |
| ... | ... | @@ -63,7 +63,7 @@ public class ContactDO extends BaseDO { |
| 63 | 63 | /** |
| 64 | 64 | * 直属上级 |
| 65 | 65 | * |
| 66 | - * 关联 {@link ContactDO#id} | |
| 66 | + * 关联 {@link CrmContactDO#id} | |
| 67 | 67 | */ |
| 68 | 68 | private Long parentId; |
| 69 | 69 | /** | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/ContactMapper.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.dal.mysql.contact; | |
| 2 | - | |
| 3 | -import java.util.*; | |
| 4 | - | |
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | |
| 9 | -import org.apache.ibatis.annotations.Mapper; | |
| 10 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * crm联系人 Mapper | |
| 14 | - * | |
| 15 | - * @author 芋道源码 | |
| 16 | - */ | |
| 17 | -@Mapper | |
| 18 | -public interface ContactMapper extends BaseMapperX<ContactDO> { | |
| 19 | - | |
| 20 | - default PageResult<ContactDO> selectPage(ContactPageReqVO reqVO) { | |
| 21 | - return selectPage(reqVO, new LambdaQueryWrapperX<ContactDO>() | |
| 22 | - .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) | |
| 23 | - .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) | |
| 24 | - .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) | |
| 25 | - .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) | |
| 26 | - .likeIfPresent(ContactDO::getName, reqVO.getName()) | |
| 27 | - .eqIfPresent(ContactDO::getQq, reqVO.getQq()) | |
| 28 | - .eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) | |
| 29 | - .orderByDesc(ContactDO::getId)); | |
| 30 | - } | |
| 31 | - | |
| 32 | - default List<ContactDO> selectList(ContactPageReqVO reqVO) { | |
| 33 | - return selectList(new LambdaQueryWrapperX<ContactDO>() | |
| 34 | - .eqIfPresent(ContactDO::getMobile, reqVO.getMobile()) | |
| 35 | - .eqIfPresent(ContactDO::getTelephone, reqVO.getTelephone()) | |
| 36 | - .eqIfPresent(ContactDO::getEmail, reqVO.getEmail()) | |
| 37 | - .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId()) | |
| 38 | - .likeIfPresent(ContactDO::getName, reqVO.getName()) | |
| 39 | - .eqIfPresent(ContactDO::getQq, reqVO.getQq()) | |
| 40 | - .eqIfPresent(ContactDO::getWechat, reqVO.getWechat()) | |
| 41 | - .orderByDesc(ContactDO::getId)); | |
| 42 | - } | |
| 43 | - | |
| 44 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.mysql.contact; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * CRM 联系人 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface CrmContactMapper extends BaseMapperX<CrmContactDO> { | |
| 17 | + | |
| 18 | + // TODO @puhui999:数据权限 | |
| 19 | + default PageResult<CrmContactDO> selectPage(CrmContactPageReqVO reqVO) { | |
| 20 | + return selectPage(reqVO, new LambdaQueryWrapperX<CrmContactDO>() | |
| 21 | + .eqIfPresent(CrmContactDO::getMobile, reqVO.getMobile()) | |
| 22 | + .eqIfPresent(CrmContactDO::getTelephone, reqVO.getTelephone()) | |
| 23 | + .eqIfPresent(CrmContactDO::getEmail, reqVO.getEmail()) | |
| 24 | + .eqIfPresent(CrmContactDO::getCustomerId, reqVO.getCustomerId()) | |
| 25 | + .likeIfPresent(CrmContactDO::getName, reqVO.getName()) | |
| 26 | + .eqIfPresent(CrmContactDO::getQq, reqVO.getQq()) | |
| 27 | + .eqIfPresent(CrmContactDO::getWechat, reqVO.getWechat()) | |
| 28 | + .orderByDesc(CrmContactDO::getId)); | |
| 29 | + } | |
| 30 | + | |
| 31 | + default PageResult<CrmContactDO> selectPageByCustomer(CrmContactPageReqVO pageVO) { | |
| 32 | + return selectPage(pageVO, new LambdaQueryWrapperX<CrmContactDO>() | |
| 33 | + .eq(CrmContactDO::getCustomerId, pageVO.getCustomerId()) | |
| 34 | + .likeIfPresent(CrmContactDO::getName, pageVO.getName()) | |
| 35 | + .eqIfPresent(CrmContactDO::getMobile, pageVO.getMobile()) | |
| 36 | + .eqIfPresent(CrmContactDO::getTelephone, pageVO.getTelephone()) | |
| 37 | + .eqIfPresent(CrmContactDO::getEmail, pageVO.getEmail()) | |
| 38 | + .eqIfPresent(CrmContactDO::getQq, pageVO.getQq()) | |
| 39 | + .eqIfPresent(CrmContactDO::getWechat, pageVO.getWechat()) | |
| 40 | + .orderByDesc(CrmContactDO::getId)); | |
| 41 | + } | |
| 42 | + | |
| 43 | +} | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.contact; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; | |
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | |
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; | |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | |
| 8 | +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | |
| 8 | 9 | |
| 9 | 10 | import javax.validation.Valid; |
| 10 | 11 | import java.util.Collection; |
| 11 | 12 | import java.util.List; |
| 12 | 13 | |
| 13 | 14 | /** |
| 14 | - * crm联系人 Service 接口 | |
| 15 | + * CRM 联系人 Service 接口 | |
| 15 | 16 | * |
| 16 | 17 | * @author 芋道源码 |
| 17 | 18 | */ |
| 18 | -public interface ContactService { | |
| 19 | +public interface CrmContactService { | |
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | - * 创建crm联系人 | |
| 22 | + * 创建联系人 | |
| 22 | 23 | * |
| 23 | 24 | * @param createReqVO 创建信息 |
| 24 | 25 | * @param userId 用户编号 |
| 25 | 26 | * @return 编号 |
| 26 | 27 | */ |
| 27 | - Long createContact(@Valid ContactCreateReqVO createReqVO, Long userId); | |
| 28 | + Long createContact(@Valid CrmContactCreateReqVO createReqVO, Long userId); | |
| 28 | 29 | |
| 29 | 30 | /** |
| 30 | - * 更新crm联系人 | |
| 31 | + * 更新联系人 | |
| 31 | 32 | * |
| 32 | 33 | * @param updateReqVO 更新信息 |
| 33 | 34 | */ |
| 34 | - void updateContact(@Valid ContactUpdateReqVO updateReqVO); | |
| 35 | + void updateContact(@Valid CrmContactUpdateReqVO updateReqVO); | |
| 35 | 36 | |
| 36 | 37 | /** |
| 37 | - * 删除crm联系人 | |
| 38 | + * 删除联系人 | |
| 38 | 39 | * |
| 39 | 40 | * @param id 编号 |
| 40 | 41 | */ |
| 41 | 42 | void deleteContact(Long id); |
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | - * 获得crm联系人 | |
| 45 | + * 获得联系人 | |
| 45 | 46 | * |
| 46 | 47 | * @param id 编号 |
| 47 | - * @return crm联系人 | |
| 48 | + * @return 联系人 | |
| 48 | 49 | */ |
| 49 | - ContactDO getContact(Long id); | |
| 50 | + CrmContactDO getContact(Long id); | |
| 50 | 51 | |
| 51 | 52 | /** |
| 52 | - * 获得crm联系人列表 | |
| 53 | + * 获得联系人列表 | |
| 53 | 54 | * |
| 54 | 55 | * @param ids 编号 |
| 55 | - * @return crm联系人列表 | |
| 56 | + * @return 联系人列表 | |
| 56 | 57 | */ |
| 57 | - List<ContactDO> getContactList(Collection<Long> ids); | |
| 58 | + List<CrmContactDO> getContactList(Collection<Long> ids); | |
| 58 | 59 | |
| 59 | 60 | /** |
| 60 | - * 获得crm联系人分页 | |
| 61 | + * 获得联系人分页 | |
| 62 | + * | |
| 63 | + * 数据权限:基于 {@link CrmContactDO} | |
| 61 | 64 | * |
| 62 | 65 | * @param pageReqVO 分页查询 |
| 63 | - * @return crm联系人分页 | |
| 66 | + * @return 联系人分页 | |
| 64 | 67 | */ |
| 65 | - PageResult<ContactDO> getContactPage(ContactPageReqVO pageReqVO); | |
| 68 | + PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO); | |
| 66 | 69 | |
| 67 | 70 | /** |
| 68 | - * 获得crm联系人列表, 用于 Excel 导出 | |
| 71 | + * 获得联系人分页,基于指定客户 | |
| 72 | + * | |
| 73 | + * 数据权限:基于 {@link CrmCustomerDO} 读取 | |
| 69 | 74 | * |
| 70 | - * @param exportReqVO 查询条件 | |
| 71 | - * @return crm联系人列表 | |
| 75 | + * @param pageVO 分页查询 | |
| 76 | + * @return 联系人分页 | |
| 72 | 77 | */ |
| 73 | - List<ContactDO> getContactList(ContactPageReqVO exportReqVO); | |
| 78 | + PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageVO); | |
| 74 | 79 | |
| 75 | 80 | /** |
| 76 | - * 获取所有联系人列表,只返回姓名和id | |
| 81 | + * 获取所有联系人列表 | |
| 82 | + * | |
| 77 | 83 | * @return 所有联系人列表 |
| 78 | 84 | */ |
| 79 | - List<ContactDO> getContactList(); | |
| 85 | + List<CrmContactDO> getContactList(); | |
| 86 | + | |
| 80 | 87 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java
| ... | ... | @@ -3,13 +3,13 @@ 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; | |
| 7 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactCreateReqVO; | |
| 8 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO; | |
| 9 | -import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactUpdateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBaseVO; | |
| 7 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactCreateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactUpdateReqVO; | |
| 10 | 10 | import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; |
| 11 | -import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; | |
| 12 | -import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper; | |
| 11 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; | |
| 12 | +import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper; | |
| 13 | 13 | import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission; |
| 14 | 14 | import cn.iocoder.yudao.module.crm.framework.enums.CrmBizTypeEnum; |
| 15 | 15 | import cn.iocoder.yudao.module.crm.framework.enums.CrmPermissionLevelEnum; |
| ... | ... | @@ -24,7 +24,6 @@ import org.springframework.validation.annotation.Validated; |
| 24 | 24 | import javax.annotation.Resource; |
| 25 | 25 | import java.util.Collection; |
| 26 | 26 | import java.util.List; |
| 27 | -import java.util.Optional; | |
| 28 | 27 | |
| 29 | 28 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 30 | 29 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; |
| ... | ... | @@ -32,16 +31,16 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_ |
| 32 | 31 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | - * crm联系人 Service 实现类 | |
| 34 | + * CRM 联系人 Service 实现类 | |
| 36 | 35 | * |
| 37 | 36 | * @author 芋道源码 |
| 38 | 37 | */ |
| 39 | 38 | @Service |
| 40 | 39 | @Validated |
| 41 | -public class ContactServiceImpl implements ContactService { | |
| 40 | +public class CrmContactServiceImpl implements CrmContactService { | |
| 42 | 41 | |
| 43 | 42 | @Resource |
| 44 | - private ContactMapper contactMapper; | |
| 43 | + private CrmContactMapper contactMapper; | |
| 45 | 44 | |
| 46 | 45 | @Resource |
| 47 | 46 | private CrmCustomerService customerService; |
| ... | ... | @@ -52,36 +51,53 @@ public class ContactServiceImpl implements ContactService { |
| 52 | 51 | private AdminUserApi adminUserApi; |
| 53 | 52 | |
| 54 | 53 | @Override |
| 55 | - public Long createContact(ContactCreateReqVO createReqVO, Long userId) { | |
| 56 | - //@todo | |
| 57 | - //校验 | |
| 58 | - validateDataExist(createReqVO); | |
| 59 | - // 插入 | |
| 60 | - ContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); | |
| 54 | + @Transactional(rollbackFor = Exception.class) | |
| 55 | + public Long createContact(CrmContactCreateReqVO createReqVO, Long userId) { | |
| 56 | + // 1.1 校验 | |
| 57 | + validateRelationDataExists(createReqVO); | |
| 58 | + // 1.2 插入 | |
| 59 | + CrmContactDO contact = ContactConvert.INSTANCE.convert(createReqVO); | |
| 61 | 60 | contactMapper.insert(contact); |
| 62 | 61 | |
| 63 | - // 创建数据权限 | |
| 64 | - crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CONTACTS.getType()) | |
| 65 | - .setBizId(contact.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 | |
| 66 | - | |
| 67 | - // 返回 | |
| 62 | + // 2. 创建数据权限 | |
| 63 | + crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(userId) | |
| 64 | + .setBizType(CrmBizTypeEnum.CRM_CONTACTS.getType()).setBizId(contact.getId()) | |
| 65 | + .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); | |
| 68 | 66 | return contact.getId(); |
| 69 | 67 | } |
| 70 | 68 | |
| 71 | 69 | @Override |
| 72 | - @Transactional(rollbackFor = Exception.class) | |
| 73 | 70 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 74 | - public void updateContact(ContactUpdateReqVO updateReqVO) { | |
| 75 | - // 校验存在 | |
| 71 | + public void updateContact(CrmContactUpdateReqVO updateReqVO) { | |
| 72 | + // 1. 校验存在 | |
| 76 | 73 | validateContactExists(updateReqVO.getId()); |
| 77 | - validateDataExist(updateReqVO); | |
| 78 | - // 更新 | |
| 79 | - ContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO); | |
| 74 | + validateRelationDataExists(updateReqVO); | |
| 75 | + // 2. 更新 | |
| 76 | + CrmContactDO updateObj = ContactConvert.INSTANCE.convert(updateReqVO); | |
| 80 | 77 | contactMapper.updateById(updateObj); |
| 81 | 78 | } |
| 82 | 79 | |
| 80 | + /** | |
| 81 | + * 校验关联的数据都存在 | |
| 82 | + * | |
| 83 | + * @param saveReqVO 新增/修改请求 VO | |
| 84 | + */ | |
| 85 | + private void validateRelationDataExists(CrmContactBaseVO saveReqVO){ | |
| 86 | + // 1. 校验客户 | |
| 87 | + if (saveReqVO.getCustomerId() != null && customerService.getCustomer(saveReqVO.getCustomerId()) == null) { | |
| 88 | + throw exception(CUSTOMER_NOT_EXISTS); | |
| 89 | + } | |
| 90 | + // 2. 校验负责人 | |
| 91 | + if (saveReqVO.getOwnerUserId() != null && adminUserApi.getUser(saveReqVO.getOwnerUserId()) == null) { | |
| 92 | + throw exception(USER_NOT_EXISTS); | |
| 93 | + } | |
| 94 | + // 3. 直属上级 | |
| 95 | + if (saveReqVO.getParentId() != null && contactMapper.selectById(saveReqVO.getParentId()) == null) { | |
| 96 | + throw exception(CONTACT_NOT_EXISTS); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 83 | 100 | @Override |
| 84 | - @Transactional(rollbackFor = Exception.class) | |
| 85 | 101 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#id", level = CrmPermissionLevelEnum.WRITE) |
| 86 | 102 | public void deleteContact(Long id) { |
| 87 | 103 | // 校验存在 |
| ... | ... | @@ -96,14 +112,15 @@ public class ContactServiceImpl implements ContactService { |
| 96 | 112 | } |
| 97 | 113 | } |
| 98 | 114 | |
| 115 | + // TODO 芋艿:是否要做数据权限的校验??? | |
| 99 | 116 | @Override |
| 100 | 117 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#id", level = CrmPermissionLevelEnum.READ) |
| 101 | - public ContactDO getContact(Long id) { | |
| 118 | + public CrmContactDO getContact(Long id) { | |
| 102 | 119 | return contactMapper.selectById(id); |
| 103 | 120 | } |
| 104 | 121 | |
| 105 | 122 | @Override |
| 106 | - public List<ContactDO> getContactList(Collection<Long> ids) { | |
| 123 | + public List<CrmContactDO> getContactList(Collection<Long> ids) { | |
| 107 | 124 | if (CollUtil.isEmpty(ids)) { |
| 108 | 125 | return ListUtil.empty(); |
| 109 | 126 | } |
| ... | ... | @@ -111,34 +128,20 @@ public class ContactServiceImpl implements ContactService { |
| 111 | 128 | } |
| 112 | 129 | |
| 113 | 130 | @Override |
| 114 | - public PageResult<ContactDO> getContactPage(ContactPageReqVO pageReqVO) { | |
| 131 | + public PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO) { | |
| 132 | + // TODO puhui999:后面要改成,基于数据权限的查询 | |
| 115 | 133 | return contactMapper.selectPage(pageReqVO); |
| 116 | 134 | } |
| 117 | 135 | |
| 118 | 136 | @Override |
| 119 | - public List<ContactDO> getContactList(ContactPageReqVO exportReqVO) { | |
| 120 | - return contactMapper.selectList(exportReqVO); | |
| 137 | + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageVO.customerId", level = CrmPermissionLevelEnum.READ) | |
| 138 | + public PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageVO) { | |
| 139 | + return contactMapper.selectPageByCustomer(pageVO); | |
| 121 | 140 | } |
| 122 | 141 | |
| 123 | 142 | @Override |
| 124 | - public List<ContactDO> getContactList() { | |
| 143 | + public List<CrmContactDO> getContactList() { | |
| 125 | 144 | return contactMapper.selectList(); |
| 126 | 145 | } |
| 127 | 146 | |
| 128 | - // TODO 芋艿:后面在看下这个方法; | |
| 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 | - } | |
| 143 | - | |
| 144 | 147 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/package-info.java deleted
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.service.customer; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO; |
| 5 | 6 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO; |
| ... | ... | @@ -19,10 +20,7 @@ import org.springframework.transaction.annotation.Transactional; |
| 19 | 20 | import org.springframework.validation.annotation.Validated; |
| 20 | 21 | |
| 21 | 22 | import javax.annotation.Resource; |
| 22 | -import java.util.ArrayList; | |
| 23 | -import java.util.Collection; | |
| 24 | -import java.util.List; | |
| 25 | -import java.util.Objects; | |
| 23 | +import java.util.*; | |
| 26 | 24 | |
| 27 | 25 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | 26 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| ... | ... | @@ -96,6 +94,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 96 | 94 | |
| 97 | 95 | @Override |
| 98 | 96 | public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) { |
| 97 | + if (CollUtil.isEmpty(ids)) { | |
| 98 | + return Collections.emptyList(); | |
| 99 | + } | |
| 99 | 100 | return customerMapper.selectBatchIds(ids); |
| 100 | 101 | } |
| 101 | 102 | ... | ... |