package cn.iocoder.yudao.module.crm.dal.mysql.business; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.funnel.CrmStatisticsFunnelReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; import java.util.List; /** * 商机 Mapper * * @author ljlleo */ @Mapper public interface CrmBusinessMapper extends BaseMapperX { default int updateOwnerUserIdById(Long id, Long ownerUserId) { return update(new LambdaUpdateWrapper() .eq(CrmBusinessDO::getId, id) .set(CrmBusinessDO::getOwnerUserId, ownerUserId)); } default PageResult selectPageByCustomerId(CrmBusinessPageReqVO pageReqVO) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eq(CrmBusinessDO::getCustomerId, pageReqVO.getCustomerId()) // 指定客户编号 .likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName()) .orderByDesc(CrmBusinessDO::getId)); } default PageResult selectPageByContactId(CrmBusinessPageReqVO pageReqVO, Collection businessIds) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .in(CrmBusinessDO::getId, businessIds) // 指定商机编号 .likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName()) .orderByDesc(CrmBusinessDO::getId)); } default PageResult selectPage(CrmBusinessPageReqVO pageReqVO, Long userId) { MPJLambdaWrapperX query = new MPJLambdaWrapperX<>(); // 拼接数据权限的查询条件 CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(), CrmBusinessDO::getId, userId, pageReqVO.getSceneType()); // 拼接自身的查询条件 query.selectAll(CrmBusinessDO.class) .likeIfPresent(CrmBusinessDO::getName, pageReqVO.getName()) .orderByDesc(CrmBusinessDO::getId); return selectJoinPage(pageReqVO, CrmBusinessDO.class, query); } default Long selectCountByStatusTypeId(Long statusTypeId) { return selectCount(CrmBusinessDO::getStatusTypeId, statusTypeId); } default List selectListByCustomerIdOwnerUserId(Long customerId, Long ownerUserId) { return selectList(new LambdaQueryWrapperX() .eq(CrmBusinessDO::getCustomerId, customerId) .eq(CrmBusinessDO::getOwnerUserId, ownerUserId)); } default PageResult selectPage(CrmStatisticsFunnelReqVO pageVO) { return selectPage(pageVO, new LambdaQueryWrapperX() .in(CrmBusinessDO::getOwnerUserId, pageVO.getUserIds()) .betweenIfPresent(CrmBusinessDO::getCreateTime, pageVO.getTimes())); } }