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