|
@@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExpor
|
|
|
import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
+import cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants;
|
|
|
import cn.iocoder.yudao.module.crm.service.contact.ContactService;
|
|
|
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
@@ -19,6 +20,7 @@ import com.google.common.collect.Lists;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -26,12 +28,13 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
@@ -41,6 +44,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
|
|
@RestController
|
|
|
@RequestMapping("/crm/contact")
|
|
|
@Validated
|
|
|
+@Slf4j
|
|
|
public class ContactController {
|
|
|
|
|
|
@Resource
|
|
@@ -82,23 +86,25 @@ public class ContactController {
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
|
|
public CommonResult<ContactRespVO> getContact(@RequestParam("id") Long id) {
|
|
|
ContactDO contact = contactService.getContact(id);
|
|
|
- // TODO @zyna:需要考虑 null 的情况;
|
|
|
- ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact);
|
|
|
- // TODO @zyna:可以把数据读完后,convert 统一交给 ContactConvert,让 controller 更简洁;而 convert 专门去做一些转换逻辑
|
|
|
+ if(contact == null){
|
|
|
+ throw exception(ErrorCodeConstants.CONTACT_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ //1.获取用户名
|
|
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(
|
|
|
- NumberUtil.parseLong(contact.getCreator()))));
|
|
|
- contactRespVO.setCreatorName(Optional.ofNullable(userMap.get(NumberUtil.parseLong(contact.getCreator()))).map(AdminUserRespDTO::getNickname).orElse(null));
|
|
|
- contactRespVO.setCustomerName(Optional.ofNullable(crmCustomerService.getCustomer(contact.getCustomerId())).map(CrmCustomerDO::getName).orElse(null));
|
|
|
+ NumberUtil.parseLong(contact.getCreator()),contact.getOwnerUserId())));
|
|
|
+ //2.获取客户信息
|
|
|
+ List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(Collections.singletonList(contact.getCustomerId()));
|
|
|
+ //3.直属上级
|
|
|
+ List<ContactDO> contactList = contactService.getContactList(Collections.singletonList(contact.getParentId()));
|
|
|
+ ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact,userMap,crmCustomerDOList,contactList);
|
|
|
return success(contactRespVO);
|
|
|
}
|
|
|
-
|
|
|
- // TODO @zyna:url 使用中划线噢;然后,单词的拼写也要注意呀,AllList 是不是更好呀;
|
|
|
- @GetMapping("/simpleAlllist")
|
|
|
+ @GetMapping("/simple-all-list")
|
|
|
@Operation(summary = "获得联系人列表")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
|
|
public CommonResult<List<ContactSimpleRespVO>> simpleAlllist() {
|
|
|
// TODO @zyna:方法名改成,getContactList;方法命名,要动名词,get 动词;all 可以去掉,因为没条件,自然是全部
|
|
|
- List<ContactDO> list = contactService.allContactList();
|
|
|
+ List<ContactDO> list = contactService.getContactList();
|
|
|
return success(ContactConvert.INSTANCE.convertAllList(list));
|
|
|
}
|
|
|
|
|
@@ -107,16 +113,10 @@ public class ContactController {
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
|
|
public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) {
|
|
|
PageResult<ContactDO> pageData = contactService.getContactPage(pageVO);
|
|
|
- PageResult<ContactRespVO> pageResult =ContactConvert.INSTANCE.convertPage(pageData);
|
|
|
- // TODO @zyna:需要考虑 null 的情况;
|
|
|
- // TODO @zyna:可以把数据读完后,convert 统一交给 ContactConvert,让 controller 更简洁;而 convert 专门去做一些转换逻辑
|
|
|
- //待接口实现后修改
|
|
|
- List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(new CrmCustomerExportReqVO());
|
|
|
- Map<Long,CrmCustomerDO> crmCustomerDOMap = crmCustomerDOList.stream().collect(Collectors.toMap(CrmCustomerDO::getId,v->v));
|
|
|
- pageResult.getList().forEach(item -> {
|
|
|
- item.setCustomerName(Optional.ofNullable(crmCustomerDOMap.get(item.getCustomerId())).map(CrmCustomerDO::getName).orElse(null));
|
|
|
- });
|
|
|
- return success(pageResult);
|
|
|
+ List<ContactRespVO> contactRespVOList = convertFieldValue2Name(pageData.getList());
|
|
|
+ PageResult<ContactRespVO> pageDataReturn = ContactConvert.INSTANCE.convertPage(pageData);
|
|
|
+ pageDataReturn.setList(contactRespVOList);
|
|
|
+ return success(pageDataReturn);
|
|
|
}
|
|
|
|
|
|
// TODO @zyna:可以看下新的导出写法,这里调整下
|
|
@@ -124,12 +124,30 @@ public class ContactController {
|
|
|
@Operation(summary = "导出联系人 Excel")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:export')")
|
|
|
@OperateLog(type = EXPORT)
|
|
|
- public void exportContactExcel(@Valid ContactExportReqVO exportReqVO,
|
|
|
+ public void exportContactExcel(@Valid ContactPageReqVO exportReqVO,
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
List<ContactDO> list = contactService.getContactList(exportReqVO);
|
|
|
// 导出 Excel
|
|
|
- List<ContactExcelVO> datas = ContactConvert.INSTANCE.convertList02(list);
|
|
|
- ExcelUtils.write(response, "crm联系人.xls", "数据", ContactExcelVO.class, datas);
|
|
|
+ List<ContactRespVO> contactRespVOList = convertFieldValue2Name(list);
|
|
|
+ ExcelUtils.write(response, "crm联系人.xls", "数据", ContactRespVO.class, contactRespVOList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 翻译字段名称
|
|
|
+ * @param contactDOList 联系人List
|
|
|
+ * @return List<ContactRespVO>
|
|
|
+ */
|
|
|
+ private List<ContactRespVO> convertFieldValue2Name(List<ContactDO> contactDOList){
|
|
|
+ //1.获取客户列表
|
|
|
+ List<Long> customerIdList = contactDOList.stream().map(ContactDO::getCustomerId).distinct().collect(Collectors.toList());
|
|
|
+ List<CrmCustomerDO> crmCustomerDOList = crmCustomerService.getCustomerList(customerIdList);
|
|
|
+ //2.获取创建人、责任人列表
|
|
|
+ List<Long> userIdsList = contactDOList.stream().flatMap(item-> Stream.of(Long.parseLong(item.getCreator()),item.getOwnerUserId()).distinct()).collect(Collectors.toList());
|
|
|
+ Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIdsList);
|
|
|
+ //3.直属上级
|
|
|
+ List<Long> contactIdsList = contactDOList.stream().map(ContactDO::getParentId).distinct().collect(Collectors.toList());
|
|
|
+ List<ContactDO> contactList = contactService.getContactList(contactIdsList);
|
|
|
+ List<ContactRespVO> pageResult =ContactConvert.INSTANCE.converList(contactDOList,userMap,crmCustomerDOList,contactList);
|
|
|
+ return pageResult;
|
|
|
+ }
|
|
|
}
|