Commit 5fbb423621d75ff503d26b008dfd584c66ffd097
1 parent
33b056e6
✨ CRM:完善合同的待回款金额
Showing
5 changed files
with
58 additions
and
1 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
| ... | ... | @@ -25,6 +25,7 @@ import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; |
| 25 | 25 | import cn.iocoder.yudao.module.crm.service.contract.CrmContractService; |
| 26 | 26 | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| 27 | 27 | import cn.iocoder.yudao.module.crm.service.product.CrmProductService; |
| 28 | +import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService; | |
| 28 | 29 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 29 | 30 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| 30 | 31 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| ... | ... | @@ -40,6 +41,7 @@ import org.springframework.validation.annotation.Validated; |
| 40 | 41 | import org.springframework.web.bind.annotation.*; |
| 41 | 42 | |
| 42 | 43 | import java.io.IOException; |
| 44 | +import java.math.BigDecimal; | |
| 43 | 45 | import java.util.Collections; |
| 44 | 46 | import java.util.List; |
| 45 | 47 | import java.util.Map; |
| ... | ... | @@ -68,6 +70,8 @@ public class CrmContractController { |
| 68 | 70 | private CrmBusinessService businessService; |
| 69 | 71 | @Resource |
| 70 | 72 | private CrmProductService productService; |
| 73 | + @Resource | |
| 74 | + private CrmReceivableService receivableService; | |
| 71 | 75 | |
| 72 | 76 | @Resource |
| 73 | 77 | private AdminUserApi adminUserApi; |
| ... | ... | @@ -192,6 +196,9 @@ public class CrmContractController { |
| 192 | 196 | // 1.4 获取商机 |
| 193 | 197 | Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap( |
| 194 | 198 | convertSet(contractList, CrmContractDO::getBusinessId)); |
| 199 | + // 1.5 获得已回款金额 | |
| 200 | + Map<Long, BigDecimal> receivablePriceMap = receivableService.getReceivablePriceMapByContractId( | |
| 201 | + convertSet(contractList, CrmContractDO::getId)); | |
| 195 | 202 | // 2. 拼接数据 |
| 196 | 203 | return BeanUtils.toBean(contractList, CrmContractRespVO.class, contractVO -> { |
| 197 | 204 | // 2.1 设置客户信息 |
| ... | ... | @@ -207,6 +214,8 @@ public class CrmContractController { |
| 207 | 214 | findAndThen(contactMap, contractVO.getSignContactId(), contact -> contractVO.setSignContactName(contact.getName())); |
| 208 | 215 | // 2.4 设置商机信息 |
| 209 | 216 | findAndThen(businessMap, contractVO.getBusinessId(), business -> contractVO.setBusinessName(business.getName())); |
| 217 | + // 2.5 设置已回款金额 | |
| 218 | + contractVO.setTotalReceivablePrice(receivablePriceMap.getOrDefault(contractVO.getId(), BigDecimal.ZERO)); | |
| 210 | 219 | }); |
| 211 | 220 | } |
| 212 | 221 | |
| ... | ... | @@ -232,9 +241,16 @@ public class CrmContractController { |
| 232 | 241 | CrmContractPageReqVO pageReqVO = new CrmContractPageReqVO().setCustomerId(customerId); |
| 233 | 242 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); // 不分页 |
| 234 | 243 | PageResult<CrmContractDO> pageResult = contractService.getContractPageByCustomerId(pageReqVO); |
| 244 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 245 | + return success(Collections.emptyList()); | |
| 246 | + } | |
| 247 | + // 拼接数据 | |
| 248 | + Map<Long, BigDecimal> receivablePriceMap = receivableService.getReceivablePriceMapByContractId( | |
| 249 | + convertSet(pageResult.getList(), CrmContractDO::getId)); | |
| 235 | 250 | return success(convertList(pageResult.getList(), contract -> new CrmContractRespVO() // 只返回 id、name 等精简字段 |
| 236 | 251 | .setId(contract.getId()).setName(contract.getName()).setAuditStatus(contract.getAuditStatus()) |
| 237 | - .setTotalPrice(contract.getTotalPrice()))); // TODO @芋艿:未回款金额 | |
| 252 | + .setTotalPrice(contract.getTotalPrice()) | |
| 253 | + .setTotalReceivablePrice(receivablePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO)))); | |
| 238 | 254 | } |
| 239 | 255 | |
| 240 | 256 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractRespVO.java
| ... | ... | @@ -88,6 +88,10 @@ public class CrmContractRespVO { |
| 88 | 88 | @ExcelProperty("合同金额") |
| 89 | 89 | private BigDecimal totalPrice; |
| 90 | 90 | |
| 91 | + @Schema(description = "已回款金额", example = "5617") | |
| 92 | + @ExcelProperty("已回款金额") | |
| 93 | + private BigDecimal totalReceivablePrice; | |
| 94 | + | |
| 91 | 95 | @Schema(description = "客户签约人编号", example = "18546") |
| 92 | 96 | private Long signContactId; |
| 93 | 97 | @Schema(description = "客户签约人", example = "小豆") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.dal.mysql.receivable; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| ... | ... | @@ -11,10 +12,16 @@ import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum; |
| 11 | 12 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| 12 | 13 | import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum; |
| 13 | 14 | import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils; |
| 15 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 14 | 16 | import org.apache.ibatis.annotations.Mapper; |
| 15 | 17 | |
| 18 | +import java.math.BigDecimal; | |
| 16 | 19 | import java.util.Collection; |
| 20 | +import java.util.Collections; | |
| 17 | 21 | import java.util.List; |
| 22 | +import java.util.Map; | |
| 23 | + | |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 18 | 25 | |
| 19 | 26 | /** |
| 20 | 27 | * 回款 Mapper |
| ... | ... | @@ -71,4 +78,18 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> { |
| 71 | 78 | return selectCount(query); |
| 72 | 79 | } |
| 73 | 80 | |
| 81 | + default Map<Long, BigDecimal> selectReceivablePriceMapByContractId(Collection<Long> contractIds) { | |
| 82 | + if (CollUtil.isEmpty(contractIds)) { | |
| 83 | + return Collections.emptyMap(); | |
| 84 | + } | |
| 85 | + // SQL sum 查询 | |
| 86 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmReceivableDO>() | |
| 87 | + .select("contract_id, SUM(price) AS total_price") | |
| 88 | + .eq("audit_status", CrmAuditStatusEnum.APPROVE.getStatus()) | |
| 89 | + .groupBy("contract_id") | |
| 90 | + .in("contract_id", contractIds)); | |
| 91 | + // 获得金额 | |
| 92 | + return convertMap(result, obj -> (Long) obj.get("contract_id"), obj -> (BigDecimal) obj.get("total_price")); | |
| 93 | + } | |
| 94 | + | |
| 74 | 95 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableService.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 7 | 7 | import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO; |
| 8 | 8 | import jakarta.validation.Valid; |
| 9 | 9 | |
| 10 | +import java.math.BigDecimal; | |
| 10 | 11 | import java.util.Collection; |
| 11 | 12 | import java.util.List; |
| 12 | 13 | import java.util.Map; |
| ... | ... | @@ -113,4 +114,12 @@ public interface CrmReceivableService { |
| 113 | 114 | */ |
| 114 | 115 | Long getCheckReceivablesCount(Long userId); |
| 115 | 116 | |
| 117 | + /** | |
| 118 | + * 获得合同已回款金额 Map | |
| 119 | + * | |
| 120 | + * @param contractIds 合同编号 | |
| 121 | + * @return 回款金额 Map | |
| 122 | + */ | |
| 123 | + Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds); | |
| 124 | + | |
| 116 | 125 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/receivable/CrmReceivableServiceImpl.java
| ... | ... | @@ -35,8 +35,10 @@ import org.springframework.stereotype.Service; |
| 35 | 35 | import org.springframework.transaction.annotation.Transactional; |
| 36 | 36 | import org.springframework.validation.annotation.Validated; |
| 37 | 37 | |
| 38 | +import java.math.BigDecimal; | |
| 38 | 39 | import java.util.Collection; |
| 39 | 40 | import java.util.List; |
| 41 | +import java.util.Map; | |
| 40 | 42 | |
| 41 | 43 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 42 | 44 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| ... | ... | @@ -258,4 +260,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService { |
| 258 | 260 | return receivableMapper.selectCheckReceivablesCount(userId); |
| 259 | 261 | } |
| 260 | 262 | |
| 263 | + @Override | |
| 264 | + public Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds) { | |
| 265 | + return receivableMapper.selectReceivablePriceMapByContractId(contractIds); | |
| 266 | + } | |
| 267 | + | |
| 261 | 268 | } | ... | ... |