|
@@ -1,32 +1,43 @@
|
|
|
package cn.iocoder.yudao.module.crm.controller.admin.contact;
|
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExportReqVO;
|
|
|
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
+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.dto.AdminUserRespDTO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+
|
|
|
+import javax.validation.constraints.*;
|
|
|
+import javax.validation.*;
|
|
|
+import javax.servlet.http.*;
|
|
|
+import java.util.*;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+
|
|
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
|
|
+import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
|
|
+
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
|
|
|
-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.convert.contact.ContactConvert;
|
|
|
import cn.iocoder.yudao.module.crm.service.contact.ContactService;
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
-import io.swagger.v3.oas.annotations.Parameter;
|
|
|
-import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import javax.validation.Valid;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
|
|
|
-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;
|
|
|
-
|
|
|
-@Tag(name = "管理后台 - CRM 联系人")
|
|
|
+@Tag(name = "管理后台 - crm联系人")
|
|
|
@RestController
|
|
|
@RequestMapping("/crm/contact")
|
|
|
@Validated
|
|
@@ -34,12 +45,16 @@ public class ContactController {
|
|
|
|
|
|
@Resource
|
|
|
private ContactService contactService;
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+ @Resource
|
|
|
+ private CrmCustomerService crmCustomerService;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建crm联系人")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:create')")
|
|
|
public CommonResult<Long> createContact(@Valid @RequestBody ContactCreateReqVO createReqVO) {
|
|
|
- return success(contactService.createContact(createReqVO, getLoginUserId()));
|
|
|
+ return success(contactService.createContact(createReqVO));
|
|
|
}
|
|
|
|
|
|
@PutMapping("/update")
|
|
@@ -65,7 +80,12 @@ public class ContactController {
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
|
|
public CommonResult<ContactRespVO> getContact(@RequestParam("id") Long id) {
|
|
|
ContactDO contact = contactService.getContact(id);
|
|
|
- return success(ContactConvert.INSTANCE.convert(contact));
|
|
|
+ ContactRespVO contactRespVO = ContactConvert.INSTANCE.convert(contact);
|
|
|
+ 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));
|
|
|
+ return success(contactRespVO);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/list")
|
|
@@ -76,13 +96,26 @@ public class ContactController {
|
|
|
List<ContactDO> list = contactService.getContactList(ids);
|
|
|
return success(ContactConvert.INSTANCE.convertList(list));
|
|
|
}
|
|
|
-
|
|
|
+ @GetMapping("/simpleAlllist")
|
|
|
+ @Operation(summary = "获得crm联系人列表")
|
|
|
+ @PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
|
|
+ public CommonResult<List<ContactSimpleRespVO>> simpleAlllist() {
|
|
|
+ List<ContactDO> list = contactService.allContactList();
|
|
|
+ return success(ContactConvert.INSTANCE.convertAllList(list));
|
|
|
+ }
|
|
|
@GetMapping("/page")
|
|
|
@Operation(summary = "获得crm联系人分页")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
|
|
public CommonResult<PageResult<ContactRespVO>> getContactPage(@Valid ContactPageReqVO pageVO) {
|
|
|
- PageResult<ContactDO> pageResult = contactService.getContactPage(pageVO);
|
|
|
- return success(ContactConvert.INSTANCE.convertPage(pageResult));
|
|
|
+ PageResult<ContactDO> pageData = contactService.getContactPage(pageVO);
|
|
|
+ PageResult<ContactRespVO> pageResult =ContactConvert.INSTANCE.convertPage(pageData);
|
|
|
+ //待接口实现后修改
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/export-excel")
|
|
@@ -97,12 +130,4 @@ public class ContactController {
|
|
|
ExcelUtils.write(response, "crm联系人.xls", "数据", ContactExcelVO.class, datas);
|
|
|
}
|
|
|
|
|
|
- @PutMapping("/transfer")
|
|
|
- @Operation(summary = "联系人转移")
|
|
|
- @PreAuthorize("@ss.hasPermission('crm:contact:update')")
|
|
|
- public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) {
|
|
|
- contactService.transferContact(reqVO, getLoginUserId());
|
|
|
- return success(true);
|
|
|
- }
|
|
|
-
|
|
|
}
|