| | |
| | | package cn.iocoder.yudao.module.crm.dal.mysql.contract; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.LocalDateTimeUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| | |
| | | import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | |
| | | } |
| | | |
| | | default PageResult<CrmContractDO> selectPage(CrmContractPageReqVO pageReqVO, Long userId, CrmContractConfigDO config) { |
| | | return selectPage(pageReqVO, userId, config, null); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询(带客户权限过滤) |
| | | * |
| | | * @param pageReqVO 查询条件 |
| | | * @param userId 用户ID |
| | | * @param config 合同配置 |
| | | * @param permittedCustomerIds 有权限的客户ID列表(null表示不限制) |
| | | */ |
| | | default PageResult<CrmContractDO> selectPage(CrmContractPageReqVO pageReqVO, Long userId, CrmContractConfigDO config, List<Long> permittedCustomerIds) { |
| | | MPJLambdaWrapperX<CrmContractDO> query = new MPJLambdaWrapperX<>(); |
| | | // 拼接数据权限的查询条件 |
| | | CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTRACT.getType(), |
| | |
| | | .eqIfPresent(CrmContractDO::getBusinessId, pageReqVO.getBusinessId()) |
| | | .eqIfPresent(CrmContractDO::getAuditStatus, pageReqVO.getAuditStatus()) |
| | | .orderByDesc(CrmContractDO::getId); |
| | | |
| | | // 客户权限过滤 |
| | | if (permittedCustomerIds != null) { |
| | | if (CollUtil.isEmpty(permittedCustomerIds)) { |
| | | return PageResult.empty(); |
| | | } |
| | | query.in(CrmContractDO::getCustomerId, permittedCustomerIds); |
| | | } |
| | | |
| | | // Backlog: 即将到期的合同 |
| | | LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now()); |
| | |
| | | .eq(CrmContractDO::getOwnerUserId, ownerUserId)); |
| | | } |
| | | |
| | | default CrmContractDO selectByBusinessId(Long businessId) { |
| | | return selectOne(CrmContractDO::getBusinessId, businessId); |
| | | } |
| | | |
| | | default CrmContractDO selectByOrderId(Long orderId) { |
| | | return selectOne(CrmContractDO::getOrderId, orderId); |
| | | } |
| | | |
| | | default List<CrmContractDO> selectListByCustomerId(Long customerId) { |
| | | return selectList(CrmContractDO::getCustomerId, customerId); |
| | | } |
| | | |
| | | // ========== 统计方法 ========== |
| | | |
| | | default Long selectTodayCount() { |
| | | LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now()); |
| | | LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(LocalDateTime.now()); |
| | | return selectCount(new LambdaQueryWrapperX<CrmContractDO>() |
| | | .between(CrmContractDO::getCreateTime, beginOfToday, endOfToday)); |
| | | } |
| | | |
| | | default BigDecimal selectTotalPriceSum() { |
| | | LambdaQueryWrapperX<CrmContractDO> query = new LambdaQueryWrapperX<>(); |
| | | query.select(CrmContractDO::getTotalPrice); |
| | | List<CrmContractDO> list = selectList(query); |
| | | return list.stream() |
| | | .map(CrmContractDO::getTotalPrice) |
| | | .filter(p -> p != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | |
| | | default Long selectApproveCount() { |
| | | return selectCount(CrmContractDO::getAuditStatus, CrmAuditStatusEnum.APPROVE.getStatus()); |
| | | } |
| | | |
| | | default BigDecimal selectApprovePriceSum() { |
| | | LambdaQueryWrapperX<CrmContractDO> query = new LambdaQueryWrapperX<>(); |
| | | query.eq(CrmContractDO::getAuditStatus, CrmAuditStatusEnum.APPROVE.getStatus()) |
| | | .select(CrmContractDO::getTotalPrice); |
| | | List<CrmContractDO> list = selectList(query); |
| | | return list.stream() |
| | | .map(CrmContractDO::getTotalPrice) |
| | | .filter(p -> p != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | |
| | | default Long selectProcessCount() { |
| | | return selectCount(CrmContractDO::getAuditStatus, CrmAuditStatusEnum.PROCESS.getStatus()); |
| | | } |
| | | |
| | | default List<Long> selectOwnerUserIds() { |
| | | LambdaQueryWrapperX<CrmContractDO> query = new LambdaQueryWrapperX<>(); |
| | | query.select(CrmContractDO::getOwnerUserId).isNotNull(CrmContractDO::getOwnerUserId); |
| | | List<CrmContractDO> list = selectList(query); |
| | | return list.stream().map(CrmContractDO::getOwnerUserId).distinct().toList(); |
| | | } |
| | | |
| | | default Long selectCountByOwnerUserId(Long ownerUserId) { |
| | | return selectCount(CrmContractDO::getOwnerUserId, ownerUserId); |
| | | } |
| | | |
| | | default BigDecimal selectPriceSumByOwnerUserId(Long ownerUserId) { |
| | | LambdaQueryWrapperX<CrmContractDO> query = new LambdaQueryWrapperX<>(); |
| | | query.eq(CrmContractDO::getOwnerUserId, ownerUserId).select(CrmContractDO::getTotalPrice); |
| | | List<CrmContractDO> list = selectList(query); |
| | | return list.stream() |
| | | .map(CrmContractDO::getTotalPrice) |
| | | .filter(p -> p != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | |
| | | } |