| | |
| | | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| | | import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; |
| | | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| | | import cn.iocoder.yudao.module.crm.enums.quotation.CrmSaleQuotationStatusEnum; |
| | | import cn.iocoder.yudao.module.crm.service.quotation.CrmSaleQuotationDocumentRenderer; |
| | | import cn.iocoder.yudao.module.crm.service.quotation.CrmSaleQuotationService; |
| | | import cn.iocoder.yudao.module.system.service.companyconfig.SystemCompanyConfigService; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.SALE_QUOTATION_EXPORT_FAIL_NOT_APPROVE; |
| | | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.SALE_QUOTATION_NOT_EXISTS; |
| | | |
| | | @Tag(name = "管理后台 - CRM 销售报价单") |
| | | @RestController |
| | |
| | | private CrmBusinessService businessService; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | @Resource |
| | | private SystemCompanyConfigService companyConfigService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建销售报价单") |
| | |
| | | ExcelUtils.write(response, "销售报价单.xls", "数据", CrmSaleQuotationRespVO.class, list); |
| | | } |
| | | |
| | | @GetMapping("/export-word") |
| | | @Operation(summary = "导出销售报价单 Word(带电子章)") |
| | | @Parameter(name = "id", description = "报价单编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('crm:sale-quotation:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void exportSaleQuotationWord(@RequestParam("id") Long id, |
| | | HttpServletResponse response) throws IOException { |
| | | CrmSaleQuotationDO saleQuotation = saleQuotationService.getSaleQuotation(id); |
| | | if (saleQuotation == null) { |
| | | throw exception(SALE_QUOTATION_NOT_EXISTS); |
| | | } |
| | | if (!CrmSaleQuotationStatusEnum.APPROVE.getStatus().equals(saleQuotation.getStatus()) |
| | | && !CrmSaleQuotationStatusEnum.CONVERTED.getStatus().equals(saleQuotation.getStatus())) { |
| | | CrmSaleQuotationStatusEnum current = CrmSaleQuotationStatusEnum.getByStatus(saleQuotation.getStatus()); |
| | | throw exception(SALE_QUOTATION_EXPORT_FAIL_NOT_APPROVE, saleQuotation.getNo(), |
| | | current != null ? current.getName() : String.valueOf(saleQuotation.getStatus())); |
| | | } |
| | | CrmSaleQuotationRespVO respVO = buildSaleQuotationRespVO(saleQuotation, |
| | | saleQuotationService.getSaleQuotationProductListByQuotationId(id)); |
| | | var companyConfig = companyConfigService.getCompanyConfig(); |
| | | String companyName = companyConfig != null ? companyConfig.getCompanyName() : null; |
| | | byte[] content = CrmSaleQuotationDocumentRenderer.render(respVO, companyName); |
| | | |
| | | String filename = "报价单-" + saleQuotation.getNo() |
| | | + (respVO.getCustomerName() != null ? "-" + respVO.getCustomerName() : "") + ".docx"; |
| | | String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8).replace("+", "%20"); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
| | | response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encoded); |
| | | response.getOutputStream().write(content); |
| | | } |
| | | |
| | | @PutMapping("/submit") |
| | | @Operation(summary = "提交销售报价审批") |
| | | @Parameter(name = "id", description = "报价单编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('crm:sale-quotation:update')") |
| | | public CommonResult<Boolean> submitSaleQuotation(@RequestParam("id") Long id, |
| | | @RequestParam(value = "processDefinitionKey", required = false) String processDefinitionKey) { |
| | | saleQuotationService.submitSaleQuotation(id, processDefinitionKey, getLoginUserId()); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/approve-process-list") |
| | | @Operation(summary = "获取销售报价审批流程列表") |
| | | public CommonResult<List<Map<String, Object>>> getSaleQuotationApproveProcessList() { |
| | | return success(saleQuotationService.getSaleQuotationApproveProcessDefinitionList()); |
| | | } |
| | | |
| | | @PostMapping("/convert-contract") |
| | | @Operation(summary = "转为合同") |
| | | @Parameter(name = "id", description = "报价单编号", required = true) |