From 5f612ab2f67b2c6f6894c624a7780799526d566d Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期四, 05 十一月 2026 20:20:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_business_新高电力' into dev_business_新高电力
---
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java | 102 ++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 89 insertions(+), 13 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 01b1a2d..cdfab75 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
@@ -10,6 +10,10 @@
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractAuditReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportExcelVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportRespVO;
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;
@@ -19,13 +23,15 @@
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.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.CrmContractCommandService;
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;
@@ -43,13 +49,17 @@
import java.io.IOException;
import java.math.BigDecimal;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
+import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@@ -71,6 +81,10 @@
private CrmBusinessService businessService;
@Resource
private CrmReceivableService receivableService;
+ @Resource
+ private CrmInvoiceService invoiceService;
+ @Resource
+ private CrmContractCommandService contractCommandService;
@Resource
private MdmItemApi mdmItemApi;
@@ -107,7 +121,6 @@
@GetMapping("/get")
@Operation(summary = "鑾峰緱鍚堝悓")
@Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
- @PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<CrmContractRespVO> getContract(@RequestParam("id") Long id) {
CrmContractDO contract = contractService.getContract(id);
return success(buildContractDetail(contract));
@@ -131,7 +144,6 @@
@GetMapping("/page")
@Operation(summary = "鑾峰緱鍚堝悓鍒嗛〉")
- @PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<PageResult<CrmContractRespVO>> getContractPage(@Valid CrmContractPageReqVO pageVO) {
PageResult<CrmContractDO> pageResult = contractService.getContractPage(pageVO, getLoginUserId());
return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
@@ -140,7 +152,9 @@
@GetMapping("/page-by-customer")
@Operation(summary = "鑾峰緱鍚堝悓鍒嗛〉锛屽熀浜庢寚瀹氬鎴�")
public CommonResult<PageResult<CrmContractRespVO>> getContractPageByCustomer(@Valid CrmContractPageReqVO pageVO) {
- Assert.notNull(pageVO.getCustomerId(), "瀹㈡埛缂栧彿涓嶈兘涓虹┖");
+ if (pageVO.getCustomerId() == null) {
+ throw exception0(BAD_REQUEST.getCode(), "瀹㈡埛缂栧彿涓嶈兘涓虹┖");
+ }
PageResult<CrmContractDO> pageResult = contractService.getContractPageByCustomerId(pageVO);
return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
}
@@ -148,7 +162,9 @@
@GetMapping("/page-by-business")
@Operation(summary = "鑾峰緱鍚堝悓鍒嗛〉锛屽熀浜庢寚瀹氬晢鏈�")
public CommonResult<PageResult<CrmContractRespVO>> getContractPageByBusiness(@Valid CrmContractPageReqVO pageVO) {
- Assert.notNull(pageVO.getBusinessId(), "鍟嗘満缂栧彿涓嶈兘涓虹┖");
+ if (pageVO.getBusinessId() == null) {
+ throw exception0(BAD_REQUEST.getCode(), "鍟嗘満缂栧彿涓嶈兘涓虹┖");
+ }
PageResult<CrmContractDO> pageResult = contractService.getContractPageByBusinessId(pageVO);
return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
}
@@ -160,9 +176,42 @@
public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
PageResult<CrmContractDO> pageResult = contractService.getContractPage(exportReqVO, getLoginUserId());
+ List<CrmContractRespVO> list = BeanUtils.toBean(pageResult.getList(), CrmContractRespVO.class);
+ // 璁$畻鏈洖娆鹃噾棰濄�佽浆鎹㈠鎵圭姸鎬佷负涓枃
+ 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 = "鑾峰緱瀵煎叆鍚堝悓妯℃澘")
+ public void importTemplate(HttpServletResponse response) throws IOException {
+ // 鎵嬪姩鍒涘缓瀵煎嚭 demo
+ List<CrmContractImportExcelVO> list = Arrays.asList(
+ CrmContractImportExcelVO.builder().name("绀轰緥鍚堝悓").customerName("绀轰緥瀹㈡埛")
+ .orderDate(null).startTime(null).endTime(null).discountPercent(null)
+ .totalPrice(null).depositPrice(null).contractType(null).voltageLevel(null)
+ .electricityType(null).contractCapacity(null).tariffMode(null).meterMode(null)
+ .payCycle(null).remark("").build()
+ );
+ // 杈撳嚭
+ ExcelUtils.writeTemplate(response, "鍚堝悓瀵煎叆妯℃澘.xls", "鍚堝悓鍒楄〃", CrmContractImportExcelVO.class, list);
+ }
+
+ @PostMapping("/import")
+ @Operation(summary = "瀵煎叆鍚堝悓")
+ @PreAuthorize("@ss.hasPermission('crm:contract:import')")
+ public CommonResult<CrmContractImportRespVO> importExcel(@Valid CrmContractImportReqVO importReqVO)
+ throws Exception {
+ List<CrmContractImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), CrmContractImportExcelVO.class);
+ return success(contractService.importContractList(list, importReqVO));
}
@PutMapping("/transfer")
@@ -174,11 +223,26 @@
}
@PutMapping("/submit")
- @Operation(summary = "鎻愪氦鍚堝悓瀹℃壒")
+ @Operation(summary = "鎻愪氦鍚堝悓瀹℃壒锛堟湭鎻愪氦/瀹℃牳涓嶉�氳繃鈫掑鎵逛腑锛夛紝瀹℃壒浜虹敱瀹℃壒閰嶇疆缁熶竴鎸囧畾")
+ @Parameter(name = "id", description = "鍚堝悓缂栧彿", required = true)
@PreAuthorize("@ss.hasPermission('crm:contract:update')")
public CommonResult<Boolean> submitContract(@RequestParam("id") Long id) {
- contractService.submitContract(id, getLoginUserId());
+ contractService.submitContract(id);
return success(true);
+ }
+
+ @PutMapping("/audit")
+ @Operation(summary = "瀹℃牳鍚堝悓锛堝鎵逛腑鈫掑鏍搁�氳繃/瀹℃牳涓嶉�氳繃锛夛紝浠呭鎵逛汉鏈汉鍙搷浣�")
+ @PreAuthorize("@ss.hasPermission('crm:contract:audit')")
+ public CommonResult<Boolean> auditContract(@Valid @RequestBody CrmContractAuditReqVO auditReqVO) {
+ contractService.auditContract(auditReqVO.getId(), auditReqVO.getPass(), auditReqVO.getReviewRemark());
+ return success(true);
+ }
+
+ @GetMapping("/approver-ids")
+ @Operation(summary = "鑾峰緱鍚堝悓鐨勫鎵逛汉缂栧彿闆嗗悎锛屼緵鍓嶇鍒ゆ柇鏄惁灞曠ず瀹℃牳鎸夐挳")
+ public CommonResult<Set<Long>> getApproverUserIds() {
+ return success(contractService.getContractApproverUserIds());
}
private List<CrmContractRespVO> buildContractDetailList(List<CrmContractDO> contractList) {
@@ -201,6 +265,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 璁剧疆瀹㈡埛淇℃伅
@@ -218,19 +285,26 @@
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()));
+ }
+ // 2.8 璁剧疆鎸囦护涓嬪彂鏁伴噺
+ contractVO.setCommandCount(contractCommandService.countByContractId(contractVO.getId()));
+ contractVO.setAuditStatusName(CrmAuditStatusEnum.getNameByStatus(contractVO.getAuditStatus()));
});
}
@GetMapping("/audit-count")
@Operation(summary = "鑾峰緱寰呭鏍稿悎鍚屾暟閲�")
- @PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<Long> getAuditContractCount() {
return success(contractService.getAuditContractCount(getLoginUserId()));
}
@GetMapping("/remind-count")
@Operation(summary = "鑾峰緱鍗冲皢鍒版湡锛堟彁閱掞級鐨勫悎鍚屾暟閲�")
- @PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<Long> getRemindContractCount() {
return success(contractService.getRemindContractCount(getLoginUserId()));
}
@@ -238,7 +312,6 @@
@GetMapping("/simple-list")
@Operation(summary = "鑾峰緱鍚堝悓绮剧畝鍒楄〃", description = "鍙寘鍚殑鍚堝悓锛屼富瑕佺敤浜庡墠绔殑涓嬫媺閫夐」")
@Parameter(name = "customerId", description = "瀹㈡埛缂栧彿", required = true)
- @PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<List<CrmContractRespVO>> getContractSimpleList(@RequestParam("customerId") Long customerId) {
CrmContractPageReqVO pageReqVO = new CrmContractPageReqVO().setCustomerId(customerId);
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); // 涓嶅垎椤�
@@ -249,10 +322,13 @@
// 鎷兼帴鏁版嵁
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")
--
Gitblit v1.9.3