|
@@ -1,13 +1,20 @@
|
|
|
package cn.iocoder.yudao.module.crm.controller.admin.contract;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
|
|
|
import cn.iocoder.yudao.module.crm.convert.contract.ContractConvert;
|
|
|
-import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
|
|
|
-import cn.iocoder.yudao.module.crm.service.contract.ContractService;
|
|
|
+import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
|
|
|
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
|
|
+import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
|
|
+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 io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
@@ -20,8 +27,12 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
|
|
@@ -29,22 +40,27 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
|
|
@RestController
|
|
|
@RequestMapping("/crm/contract")
|
|
|
@Validated
|
|
|
-public class ContractController {
|
|
|
+public class CrmContractController {
|
|
|
|
|
|
@Resource
|
|
|
- private ContractService contractService;
|
|
|
+ private CrmContractService contractService;
|
|
|
+ @Resource
|
|
|
+ private CrmCustomerService customerService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建合同")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contract:create')")
|
|
|
- public CommonResult<Long> createContract(@Valid @RequestBody ContractCreateReqVO createReqVO) {
|
|
|
+ public CommonResult<Long> createContract(@Valid @RequestBody CrmContractCreateReqVO createReqVO) {
|
|
|
return success(contractService.createContract(createReqVO, getLoginUserId()));
|
|
|
}
|
|
|
|
|
|
@PutMapping("/update")
|
|
|
@Operation(summary = "更新合同")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contract:update')")
|
|
|
- public CommonResult<Boolean> updateContract(@Valid @RequestBody ContractUpdateReqVO updateReqVO) {
|
|
|
+ public CommonResult<Boolean> updateContract(@Valid @RequestBody CrmContractUpdateReqVO updateReqVO) {
|
|
|
contractService.updateContract(updateReqVO);
|
|
|
return success(true);
|
|
|
}
|
|
@@ -63,28 +79,56 @@ public class ContractController {
|
|
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contract:query')")
|
|
|
public CommonResult<ContractRespVO> getContract(@RequestParam("id") Long id) {
|
|
|
- ContractDO contract = contractService.getContract(id);
|
|
|
+ CrmContractDO contract = contractService.getContract(id);
|
|
|
return success(ContractConvert.INSTANCE.convert(contract));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/page")
|
|
|
@Operation(summary = "获得合同分页")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contract:query')")
|
|
|
- public CommonResult<PageResult<ContractRespVO>> getContractPage(@Valid ContractPageReqVO pageVO) {
|
|
|
- PageResult<ContractDO> pageResult = contractService.getContractPage(pageVO);
|
|
|
- return success(ContractConvert.INSTANCE.convertPage(pageResult));
|
|
|
+ public CommonResult<PageResult<ContractRespVO>> getContractPage(@Valid CrmContractPageReqVO pageVO) {
|
|
|
+ PageResult<CrmContractDO> pageResult = contractService.getContractPage(pageVO);
|
|
|
+ return success(convertDetailContractPage(pageResult));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/page-by-customer")
|
|
|
+ @Operation(summary = "获得联系人分页,基于指定客户")
|
|
|
+ public CommonResult<PageResult<ContractRespVO>> getContractPageByCustomer(@Valid CrmContractPageReqVO pageVO) {
|
|
|
+ Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空");
|
|
|
+ PageResult<CrmContractDO> pageResult = contractService.getContractPageByCustomer(pageVO);
|
|
|
+ return success(convertDetailContractPage(pageResult));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/export-excel")
|
|
|
@Operation(summary = "导出合同 Excel")
|
|
|
@PreAuthorize("@ss.hasPermission('crm:contract:export')")
|
|
|
@OperateLog(type = EXPORT)
|
|
|
- public void exportContractExcel(@Valid ContractExportReqVO exportReqVO,
|
|
|
+ public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
- List<ContractDO> list = contractService.getContractList(exportReqVO);
|
|
|
+ PageResult<CrmContractDO> pageResult = contractService.getContractPage(exportReqVO);
|
|
|
// 导出 Excel
|
|
|
- List<ContractExcelVO> datas = ContractConvert.INSTANCE.convertList02(list);
|
|
|
- ExcelUtils.write(response, "合同.xls", "数据", ContractExcelVO.class, datas);
|
|
|
+ ExcelUtils.write(response, "合同.xls", "数据", CrmContractExcelVO.class,
|
|
|
+ ContractConvert.INSTANCE.convertList02(pageResult.getList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换成详细的联系人分页,即读取关联信息
|
|
|
+ *
|
|
|
+ * @param pageResult 联系人分页
|
|
|
+ * @return 详细的联系人分页
|
|
|
+ */
|
|
|
+ private PageResult<ContractRespVO> convertDetailContractPage(PageResult<CrmContractDO> pageResult) {
|
|
|
+ List<CrmContractDO> contactList = pageResult.getList();
|
|
|
+ if (CollUtil.isEmpty(contactList)) {
|
|
|
+ return PageResult.empty(pageResult.getTotal());
|
|
|
+ }
|
|
|
+ // 1. 获取客户列表
|
|
|
+ List<CrmCustomerDO> customerList = customerService.getCustomerList(
|
|
|
+ convertSet(contactList, CrmContractDO::getCustomerId));
|
|
|
+ // 2. 获取创建人、负责人列表
|
|
|
+ Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList,
|
|
|
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
|
|
|
+ return ContractConvert.INSTANCE.convertPage(pageResult, userMap, customerList);
|
|
|
}
|
|
|
|
|
|
@PutMapping("/transfer")
|