From 8c65f898ed6e5b0c7a94c792c4562f6ec831dccd Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期六, 07 十一月 2026 08:50:53 +0800
Subject: [PATCH] feat: 完善质检、生产、销售、财务与人事模块并接入审批流程
---
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java | 135 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 123 insertions(+), 12 deletions(-)
diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
index 542f3e0..0d039ed 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
@@ -13,9 +13,14 @@
import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationProductDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
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;
@@ -36,6 +41,8 @@
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;
@@ -45,7 +52,10 @@
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
@@ -67,7 +77,11 @@
@Resource
private CrmCustomerService customerService;
@Resource
+ private CrmBusinessService businessService;
+ @Resource
private StorageAttachmentApi storageAttachmentApi;
+ @Resource
+ private SystemCompanyConfigService companyConfigService;
@PostMapping("/create")
@Operation(summary = "鍒涘缓閿�鍞姤浠峰崟")
@@ -86,17 +100,30 @@
@DeleteMapping("/delete")
@Operation(summary = "鍒犻櫎閿�鍞姤浠峰崟")
- @Parameter(name = "ids", description = "缂栧彿鏁扮粍", required = true)
+ @Parameter(name = "id", description = "鍗曚釜缂栧彿", required = false)
+ @Parameter(name = "ids", description = "缂栧彿鏁扮粍", required = false)
@PreAuthorize("@ss.hasPermission('crm:sale-quotation:delete')")
- public CommonResult<Boolean> deleteSaleQuotation(@RequestParam("ids") List<Long> ids) {
- saleQuotationService.deleteSaleQuotation(ids);
+ public CommonResult<Boolean> deleteSaleQuotation(
+ @RequestParam(value = "id", required = false) Long id,
+ @RequestParam(value = "ids", required = false) List<Long> ids) {
+ // 鏀寔鍗曚釜id鎴栧涓猧ds
+ List<Long> deleteIds = new java.util.ArrayList<>();
+ if (id != null) {
+ deleteIds.add(id);
+ }
+ if (ids != null && !ids.isEmpty()) {
+ deleteIds.addAll(ids);
+ }
+ if (deleteIds.isEmpty()) {
+ throw new IllegalArgumentException("璇锋眰鍙傛暟缂哄け:id 鎴� ids");
+ }
+ saleQuotationService.deleteSaleQuotation(deleteIds);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "鑾峰緱閿�鍞姤浠峰崟")
@Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
- @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
public CommonResult<CrmSaleQuotationRespVO> getSaleQuotation(@RequestParam("id") Long id) {
CrmSaleQuotationDO saleQuotation = saleQuotationService.getSaleQuotation(id);
if (saleQuotation == null) {
@@ -108,7 +135,6 @@
@GetMapping("/page")
@Operation(summary = "鑾峰緱閿�鍞姤浠峰崟鍒嗛〉")
- @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
public CommonResult<PageResult<CrmSaleQuotationRespVO>> getSaleQuotationPage(@Valid CrmSaleQuotationPageReqVO pageReqVO) {
PageResult<CrmSaleQuotationDO> pageResult = saleQuotationService.getSaleQuotationPage(pageReqVO, getLoginUserId());
return success(buildSaleQuotationRespVOPageResult(pageResult));
@@ -116,7 +142,6 @@
@GetMapping("/page-by-customer")
@Operation(summary = "鑾峰緱閿�鍞姤浠峰崟鍒嗛〉锛堝熀浜庡鎴凤級")
- @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
public CommonResult<PageResult<CrmSaleQuotationRespVO>> getSaleQuotationPageByCustomerId(@Valid CrmSaleQuotationPageReqVO pageReqVO) {
PageResult<CrmSaleQuotationDO> pageResult = saleQuotationService.getSaleQuotationPageByCustomerId(pageReqVO);
return success(buildSaleQuotationRespVOPageResult(pageResult));
@@ -124,7 +149,6 @@
@GetMapping("/page-by-business")
@Operation(summary = "鑾峰緱閿�鍞姤浠峰崟鍒嗛〉锛堝熀浜庡晢鏈猴級")
- @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
public CommonResult<PageResult<CrmSaleQuotationRespVO>> getSaleQuotationPageByBusinessId(@Valid CrmSaleQuotationPageReqVO pageReqVO) {
PageResult<CrmSaleQuotationDO> pageResult = saleQuotationService.getSaleQuotationPageByBusinessId(pageReqVO);
return success(buildSaleQuotationRespVOPageResult(pageResult));
@@ -142,6 +166,53 @@
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)
@@ -157,9 +228,14 @@
// 1. 鏋勫缓鐗╂枡鏄庣粏
if (CollUtil.isNotEmpty(productList)) {
Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(convertSet(productList, CrmSaleQuotationProductDO::getItemId));
+ java.util.Set<Long> unitIds = new java.util.HashSet<>(convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId));
+ itemMap.values().forEach(item -> {
+ if (item.getUnitMeasureId2() != null) {
+ unitIds.add(item.getUnitMeasureId2());
+ }
+ });
Map<Long, MdmUnitMeasureRespDTO> unitMap = convertMap(
- mdmUnitMeasureApi.getUnitMeasureList(
- convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId)).getCheckedData(),
+ mdmUnitMeasureApi.getUnitMeasureList(unitIds).getCheckedData(),
MdmUnitMeasureRespDTO::getId);
respVO.setItems(BeanUtils.toBean(productList, CrmSaleQuotationRespVO.Item.class, item -> {
MdmItemRespDTO mdmItem = itemMap.get(item.getItemId());
@@ -167,8 +243,13 @@
item.setItemCode(mdmItem.getCode());
item.setItemName(mdmItem.getName());
item.setItemBarCode(mdmItem.getBarCode());
+ item.setItemSpecification(mdmItem.getSpecification());
+ item.setItemUnitId2(mdmItem.getUnitMeasureId2());
+ item.setItemUnitId3(mdmItem.getUnitMeasureId3());
}
MapUtils.findAndThen(unitMap, item.getItemUnitId(), unit -> item.setItemUnitName(unit.getName()));
+ MapUtils.findAndThen(unitMap, item.getItemUnitId2(), unit -> item.setItemUnitName2(unit.getName()));
+ MapUtils.findAndThen(unitMap, item.getItemUnitId3(), unit -> item.setItemUnitName3(unit.getName()));
}));
}
// 2. 濉厖瀹㈡埛鍚嶇О
@@ -176,6 +257,13 @@
CrmCustomerDO customer = customerService.getCustomer(saleQuotation.getCustomerId());
if (customer != null) {
respVO.setCustomerName(customer.getName());
+ }
+ }
+ // 2.1 濉厖鍟嗘満鍚嶇О
+ if (saleQuotation.getBusinessId() != null) {
+ CrmBusinessDO business = businessService.getBusiness(saleQuotation.getBusinessId());
+ if (business != null) {
+ respVO.setBusinessName(business.getName());
}
}
// 3. 濉厖鍏宠仈淇℃伅
@@ -195,6 +283,15 @@
Map<Long, List<CrmSaleQuotationProductDO>> productMap = convertMultiMap(productList, CrmSaleQuotationProductDO::getQuotationId);
// 1.2 鐗╂枡淇℃伅
Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(convertSet(productList, CrmSaleQuotationProductDO::getItemId));
+ java.util.Set<Long> unitIds = new java.util.HashSet<>(convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId));
+ itemMap.values().forEach(item -> {
+ if (item.getUnitMeasureId2() != null) {
+ unitIds.add(item.getUnitMeasureId2());
+ }
+ });
+ Map<Long, MdmUnitMeasureRespDTO> unitMap = convertMap(
+ mdmUnitMeasureApi.getUnitMeasureList(unitIds).getCheckedData(),
+ MdmUnitMeasureRespDTO::getId);
// 1.3 瀹㈡埛淇℃伅
Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap(
convertSet(pageResult.getList(), CrmSaleQuotationDO::getCustomerId));
@@ -204,15 +301,29 @@
// 1.5 閮ㄩ棬淇℃伅
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
convertSet(pageResult.getList(), CrmSaleQuotationDO::getOwnerUserId));
+ // 1.6 鍟嗘満淇℃伅锛堣繃婊� null锛宐usinessId 涓哄彲閫夊瓧娈碉級
+ Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap(
+ convertSet(pageResult.getList(), CrmSaleQuotationDO::getBusinessId, vo -> vo.getBusinessId() != null));
// 2. 寮�濮嬫嫾鎺�
return BeanUtils.toBean(pageResult, CrmSaleQuotationRespVO.class, vo -> {
vo.setItems(BeanUtils.toBean(productMap.get(vo.getId()), CrmSaleQuotationRespVO.Item.class,
- item -> MapUtils.findAndThen(itemMap, item.getItemId(), mdmItem -> item.setItemCode(mdmItem.getCode())
- .setItemName(mdmItem.getName()).setItemBarCode(mdmItem.getBarCode()))));
+ item -> {
+ MapUtils.findAndThen(itemMap, item.getItemId(), mdmItem -> item
+ .setItemCode(mdmItem.getCode())
+ .setItemName(mdmItem.getName())
+ .setItemBarCode(mdmItem.getBarCode())
+ .setItemSpecification(mdmItem.getSpecification())
+ .setItemUnitId2(mdmItem.getUnitMeasureId2())
+ .setItemUnitId3(mdmItem.getUnitMeasureId3()));
+ MapUtils.findAndThen(unitMap, item.getItemUnitId(), unit -> item.setItemUnitName(unit.getName()));
+ MapUtils.findAndThen(unitMap, item.getItemUnitId2(), unit -> item.setItemUnitName2(unit.getName()));
+ MapUtils.findAndThen(unitMap, item.getItemUnitId3(), unit -> item.setItemUnitName3(unit.getName()));
+ }));
MapUtils.findAndThen(customerMap, vo.getCustomerId(), customer -> vo.setCustomerName(customer.getName()));
MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
MapUtils.findAndThen(deptMap, vo.getOwnerUserId(), dept -> vo.setOwnerUserDeptName(dept.getName()));
+ MapUtils.findAndThen(businessMap, vo.getBusinessId(), business -> vo.setBusinessName(business.getName()));
});
}
@@ -243,4 +354,4 @@
}
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.3