From 67d3ab41f4989faf4db5f7f95f56b8595dd8eb3b Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期五, 11 九月 2026 09:39:44 +0800
Subject: [PATCH] feat(crm/erp): 新增采购申请、合同管理 Excel 导入(含菜单权限 SQL)
---
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java | 98 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 84 insertions(+), 14 deletions(-)
diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
index b9fd295..ff5e1c6 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
@@ -13,18 +13,22 @@
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportExcelVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractTransferReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractProductDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
-import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
+import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
+import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
-import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
+import cn.iocoder.yudao.module.crm.service.invoice.CrmInvoiceService;
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
@@ -39,9 +43,11 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.math.BigDecimal;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -69,9 +75,12 @@
@Resource
private CrmBusinessService businessService;
@Resource
- private CrmProductService productService;
- @Resource
private CrmReceivableService receivableService;
+ @Resource
+ private CrmInvoiceService invoiceService;
+
+ @Resource
+ private MdmItemApi mdmItemApi;
@Resource
private AdminUserApi adminUserApi;
@@ -118,12 +127,12 @@
CrmContractRespVO contractVO = buildContractDetailList(singletonList(contract)).get(0);
// 鎷兼帴浜у搧椤�
List<CrmContractProductDO> businessProducts = contractService.getContractProductListByContractId(contractVO.getId());
- Map<Long, CrmProductDO> productMap = productService.getProductMap(
- convertSet(businessProducts, CrmContractProductDO::getProductId));
+ Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(
+ convertSet(businessProducts, CrmContractProductDO::getItemId));
contractVO.setProducts(BeanUtils.toBean(businessProducts, CrmContractRespVO.Product.class, businessProductVO ->
- MapUtils.findAndThen(productMap, businessProductVO.getProductId(),
- product -> businessProductVO.setProductName(product.getName())
- .setProductNo(product.getNo()).setProductUnit(product.getUnit()))));
+ MapUtils.findAndThen(itemMap, businessProductVO.getItemId(),
+ item -> businessProductVO.setItemCode(item.getCode())
+ .setItemName(item.getName()).setItemBarCode(item.getBarCode()))));
return contractVO;
}
@@ -158,9 +167,42 @@
public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
PageResult<CrmContractDO> pageResult = contractService.getContractPage(exportReqVO, getLoginUserId());
+ // 鎷兼帴瀹㈡埛銆佸晢鏈恒�佺绾︿汉銆佸洖娆鹃噾棰濈瓑鍏宠仈淇℃伅
+ List<CrmContractRespVO> list = buildContractDetailList(pageResult.getList());
+ // 璁$畻鏈洖娆鹃噾棰濄�佽浆鎹㈠鎵圭姸鎬佷负涓枃
+ list.forEach(vo -> {
+ if (vo.getTotalPrice() != null && vo.getTotalReceivablePrice() != null) {
+ vo.setUnReceivablePrice(vo.getTotalPrice().subtract(vo.getTotalReceivablePrice()));
+ }
+ if (vo.getAuditStatus() != null) {
+ vo.setAuditStatusName(CrmAuditStatusEnum.getNameByStatus(vo.getAuditStatus()));
+ }
+ });
// 瀵煎嚭 Excel
- ExcelUtils.write(response, "鍚堝悓.xls", "鏁版嵁", CrmContractRespVO.class,
- BeanUtils.toBean(pageResult.getList(), CrmContractRespVO.class));
+ ExcelUtils.write(response, "鍚堝悓.xls", "鏁版嵁", CrmContractRespVO.class, list);
+ }
+
+ @GetMapping("/get-import-template")
+ @Operation(summary = "鑾峰緱瀵煎叆鍚堝悓妯℃澘")
+ @PreAuthorize("@ss.hasPermission('crm:contract:import')")
+ public void importTemplate(HttpServletResponse response) throws IOException {
+ List<CrmContractImportExcelVO> list = Collections.singletonList(
+ CrmContractImportExcelVO.builder()
+ .no("HT20260101000001").name("绀轰緥鍚堝悓").customerName("绀轰緥瀹㈡埛")
+ .orderDate("2026-01-01 10:00:00").startTime("2026-01-01").endTime("2026-12-31")
+ .discountPercent(new BigDecimal("0")).depositPrice(new BigDecimal("0"))
+ .productCode("ITEM001").productName("绀轰緥浜у搧A")
+ .count(100).contractPrice(new BigDecimal("20.00")).remark("绀轰緥鏁版嵁锛屽鍏ュ墠璇锋浛鎹�")
+ .build());
+ ExcelUtils.write(response, "鍚堝悓瀵煎叆妯℃澘.xls", "鍚堝悓", CrmContractImportExcelVO.class, list);
+ }
+
+ @PostMapping("/import")
+ @Operation(summary = "瀵煎叆鍚堝悓")
+ @PreAuthorize("@ss.hasPermission('crm:contract:import')")
+ public CommonResult<CrmContractImportRespVO> importContractExcel(@RequestParam("file") MultipartFile file) throws Exception {
+ List<CrmContractImportExcelVO> list = ExcelUtils.read(file, CrmContractImportExcelVO.class);
+ return success(contractService.importContractList(list));
}
@PutMapping("/transfer")
@@ -174,9 +216,17 @@
@PutMapping("/submit")
@Operation(summary = "鎻愪氦鍚堝悓瀹℃壒")
@PreAuthorize("@ss.hasPermission('crm:contract:update')")
- public CommonResult<Boolean> submitContract(@RequestParam("id") Long id) {
- contractService.submitContract(id, getLoginUserId());
+ public CommonResult<Boolean> submitContract(@RequestParam("id") Long id,
+ @RequestParam("processDefinitionKey") String processDefinitionKey) {
+ contractService.submitContract(id, processDefinitionKey, getLoginUserId());
return success(true);
+ }
+
+ @GetMapping("/approve-process-list")
+ @Operation(summary = "鑾峰彇鍚堝悓瀹℃壒娴佺▼鍒楄〃")
+ @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+ public CommonResult<List<Map<String, Object>>> getContractApproveProcessList() {
+ return success(contractService.getContractApproveProcessDefinitionList());
}
private List<CrmContractRespVO> buildContractDetailList(List<CrmContractDO> contractList) {
@@ -199,6 +249,9 @@
// 1.5 鑾峰緱宸插洖娆鹃噾棰�
Map<Long, BigDecimal> receivablePriceMap = receivableService.getReceivablePriceMapByContractId(
convertSet(contractList, CrmContractDO::getId));
+ // 1.6 鑾峰緱宸插紑绁ㄩ噾棰濓紙瀹℃壒閫氳繃 + 瀹℃壒涓紝涓庡紑绁ㄩ槻瓒呮牎楠屽彛寰勪竴鑷达級
+ Map<Long, BigDecimal> invoicePriceMap = invoiceService.getInvoicePriceMapByContractId(
+ convertSet(contractList, CrmContractDO::getId));
// 2. 鎷兼帴鏁版嵁
return BeanUtils.toBean(contractList, CrmContractRespVO.class, contractVO -> {
// 2.1 璁剧疆瀹㈡埛淇℃伅
@@ -216,6 +269,12 @@
findAndThen(businessMap, contractVO.getBusinessId(), business -> contractVO.setBusinessName(business.getName()));
// 2.5 璁剧疆宸插洖娆鹃噾棰�
contractVO.setTotalReceivablePrice(receivablePriceMap.getOrDefault(contractVO.getId(), BigDecimal.ZERO));
+ // 2.6 璁剧疆宸插紑绁ㄩ噾棰�
+ contractVO.setTotalInvoicePrice(invoicePriceMap.getOrDefault(contractVO.getId(), BigDecimal.ZERO));
+ // 2.7 璁剧疆鏈紑绁ㄩ噾棰�
+ if (contractVO.getTotalPrice() != null && contractVO.getTotalInvoicePrice() != null) {
+ contractVO.setUnInvoicePrice(contractVO.getTotalPrice().subtract(contractVO.getTotalInvoicePrice()));
+ }
});
}
@@ -247,10 +306,21 @@
// 鎷兼帴鏁版嵁
Map<Long, BigDecimal> receivablePriceMap = receivableService.getReceivablePriceMapByContractId(
convertSet(pageResult.getList(), CrmContractDO::getId));
+ Map<Long, BigDecimal> invoicePriceMap = invoiceService.getInvoicePriceMapByContractId(
+ convertSet(pageResult.getList(), CrmContractDO::getId));
return success(convertList(pageResult.getList(), contract -> new CrmContractRespVO() // 鍙繑鍥� id銆乶ame 绛夌簿绠�瀛楁
.setId(contract.getId()).setName(contract.getName()).setAuditStatus(contract.getAuditStatus())
.setTotalPrice(contract.getTotalPrice())
- .setTotalReceivablePrice(receivablePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))));
+ .setTotalReceivablePrice(receivablePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))
+ .setTotalInvoicePrice(invoicePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))));
+ }
+
+ @PostMapping("/generate-sale-order")
+ @Operation(summary = "鏍规嵁鍚堝悓鐢熸垚閿�鍞鍗�")
+ @Parameter(name = "id", description = "鍚堝悓缂栧彿", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:contract:update')")
+ public CommonResult<Long> generateSaleOrder(@RequestParam("id") Long id) {
+ return success(contractService.generateSaleOrder(id, getLoginUserId()));
}
}
--
Gitblit v1.9.3