| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得联系人") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| | | public CommonResult<CrmContactRespVO> getContact(@RequestParam("id") Long id) { |
| | | CrmContactDO contact = contactService.getContact(id); |
| | | return success(buildContactDetail(contact)); |
| | |
| | | |
| | | @GetMapping("/simple-all-list") |
| | | @Operation(summary = "获得联系人的精简列表") |
| | | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| | | public CommonResult<List<CrmContactRespVO>> getSimpleContactList() { |
| | | List<CrmContactDO> list = contactService.getContactList(getLoginUserId()); |
| | | return success(convertList(list, contact -> // 只返回 id、name 字段 |
| | |
| | | .setCustomerId(contact.getCustomerId()))); |
| | | } |
| | | |
| | | @GetMapping("/list-by-customer") |
| | | @Operation(summary = "获得联系人列表,基于指定客户") |
| | | @Parameter(name = "customerId", description = "客户编号", required = true) |
| | | public CommonResult<List<CrmContactRespVO>> getContactListByCustomer(@RequestParam("customerId") Long customerId) { |
| | | List<CrmContactDO> list = contactService.getContactListByCustomerId(customerId); |
| | | return success(convertList(list, contact -> // 只返回 id、name 字段 |
| | | new CrmContactRespVO().setId(contact.getId()).setName(contact.getName()) |
| | | .setCustomerId(contact.getCustomerId()))); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得联系人分页") |
| | | @PreAuthorize("@ss.hasPermission('crm:contact:query')") |
| | | public CommonResult<PageResult<CrmContactRespVO>> getContactPage(@Valid CrmContactPageReqVO pageVO) { |
| | | PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO, getLoginUserId()); |
| | | return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal())); |
| | |
| | | ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, buildContactDetailList(list)); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得导入联系人模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 手动创建导出 demo |
| | | List<CrmContactImportExcelVO> list = Arrays.asList( |
| | | CrmContactImportExcelVO.builder().name("示例联系人").customerName("示例客户") |
| | | .mobile("13800138000").telephone("").email("").wechat("").post("").remark("").build() |
| | | ); |
| | | // 输出 |
| | | ExcelUtils.write(response, "联系人导入模板.xls", "联系人列表", CrmContactImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入联系人") |
| | | @PreAuthorize("@ss.hasPermission('crm:contact:import')") |
| | | public CommonResult<CrmContactImportRespVO> importExcel(@Valid CrmContactImportReqVO importReqVO) |
| | | throws Exception { |
| | | List<CrmContactImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), CrmContactImportExcelVO.class); |
| | | return success(contactService.importContactList(list, importReqVO)); |
| | | } |
| | | |
| | | private List<CrmContactRespVO> buildContactDetailList(List<CrmContactDO> contactList) { |
| | | if (CollUtil.isEmpty(contactList)) { |
| | | return Collections.emptyList(); |