优化当前登录用户和代理商的关系

This commit is contained in:
Wang 2026-01-16 11:55:21 +08:00
parent 624d20283e
commit 08e7ab4150
6 changed files with 26 additions and 22 deletions

View File

@ -2,6 +2,8 @@ package com.seer.teach.mp.app.service;
import com.seer.teach.mp.app.controller.resp.AppMpAgentResp; import com.seer.teach.mp.app.controller.resp.AppMpAgentResp;
import java.util.List;
/** /**
* App端代理商服务接口 * App端代理商服务接口
*/ */
@ -21,5 +23,5 @@ public interface IAppAgentService {
* @param userId 用户ID * @param userId 用户ID
* @return 代理商ID * @return 代理商ID
*/ */
Integer getAgentIdByUserId(Integer userId); List<Integer> getAgentIdListByUserId(Integer userId);
} }

View File

@ -1,5 +1,6 @@
package com.seer.teach.mp.app.service.impl; package com.seer.teach.mp.app.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seer.teach.common.PageListBean; import com.seer.teach.common.PageListBean;
@ -17,7 +18,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -38,12 +38,11 @@ public class AppAgentActivityParentInfoServiceImpl implements IAppAgentActivityP
@Override @Override
public List<AgentActivityParentInfoResp> getParentsByActivityAndAgent(Integer activityId, Integer agentId,Integer userId) { public List<AgentActivityParentInfoResp> getParentsByActivityAndAgent(Integer activityId, Integer agentId,Integer userId) {
var userAgentId = appAgentService.getAgentIdByUserId(userId); var userAgentIds = appAgentService.getAgentIdListByUserId(userId);
if (Objects.isNull(userAgentId)) { if (CollectionUtil.isEmpty(userAgentIds)) {
return List.of(); return List.of();
} }
log.info("getParentsByActivityAndAgent userAgentId:{}", userAgentId); if(!userAgentIds.contains(agentId)){
if(userAgentId.intValue() != agentId){
throw new CommonException(ResultCodeEnum.RELATION_NOT_FOUND); throw new CommonException(ResultCodeEnum.RELATION_NOT_FOUND);
} }
LambdaQueryWrapper<MpActivityInfoCollectionEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MpActivityInfoCollectionEntity> queryWrapper = new LambdaQueryWrapper<>();
@ -61,12 +60,11 @@ public class AppAgentActivityParentInfoServiceImpl implements IAppAgentActivityP
@Override @Override
public PageListBean<AgentActivityParentInfoResp> getParentsByActivityAndAgent(Integer userId,AgentActivityParentQueryReq queryReq) { public PageListBean<AgentActivityParentInfoResp> getParentsByActivityAndAgent(Integer userId,AgentActivityParentQueryReq queryReq) {
var userAgentId = appAgentService.getAgentIdByUserId(userId); var userAgentIds = appAgentService.getAgentIdListByUserId(userId);
if (Objects.isNull(userAgentId)) { if (CollectionUtil.isEmpty(userAgentIds)) {
return new PageListBean<>(); return new PageListBean<>();
} }
log.info("userAgentId:{}", userAgentId); if(!userAgentIds.contains(queryReq.getAgentId())){
if(userAgentId.intValue() != queryReq.getAgentId()){
throw new CommonException(ResultCodeEnum.RELATION_NOT_FOUND); throw new CommonException(ResultCodeEnum.RELATION_NOT_FOUND);
} }
// 创建分页对象 // 创建分页对象
@ -75,7 +73,7 @@ public class AppAgentActivityParentInfoServiceImpl implements IAppAgentActivityP
// 构建查询条件 // 构建查询条件
LambdaQueryWrapper<MpActivityInfoCollectionEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MpActivityInfoCollectionEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MpActivityInfoCollectionEntity::getActivityId, queryReq.getActivityId()) queryWrapper.eq(MpActivityInfoCollectionEntity::getActivityId, queryReq.getActivityId())
.eq(MpActivityInfoCollectionEntity::getAgentId, userAgentId); .eq(MpActivityInfoCollectionEntity::getAgentId, queryReq.getAgentId());
// 执行分页查询 // 执行分页查询
Page<MpActivityInfoCollectionEntity> pageResult = activityInfoCollectionService.page(page, queryWrapper); Page<MpActivityInfoCollectionEntity> pageResult = activityInfoCollectionService.page(page, queryWrapper);

View File

@ -56,12 +56,11 @@ public class AppAgentActivityParticipantServiceImpl implements IAppAgentActivity
@Override @Override
public List<AgentActivityParticipantResp> getParticipantsByActivityAndAgent(Integer agentId, Integer userId) { public List<AgentActivityParticipantResp> getParticipantsByActivityAndAgent(Integer agentId, Integer userId) {
var userAgentId = appAgentService.getAgentIdByUserId(userId); var userAgentIds = appAgentService.getAgentIdListByUserId(userId);
if (Objects.isNull(userAgentId)) { if (CollectionUtil.isEmpty(userAgentIds)) {
return List.of(); return List.of();
} }
log.info("userAgentId:{}", userAgentId); if(!userAgentIds.contains(agentId) ){
if(userAgentId.intValue() != agentId){
throw new CommonException(ResultCodeEnum.RELATION_NOT_FOUND); throw new CommonException(ResultCodeEnum.RELATION_NOT_FOUND);
} }
var participants = agentActivityParticipantService.getListByAgentId(agentId); var participants = agentActivityParticipantService.getListByAgentId(agentId);

View File

@ -1,5 +1,6 @@
package com.seer.teach.mp.app.service.impl; package com.seer.teach.mp.app.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.seer.teach.common.enums.ResultCodeEnum; import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.utils.AssertUtils; import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.mp.app.controller.resp.AppMpAgentResp; import com.seer.teach.mp.app.controller.resp.AppMpAgentResp;
@ -12,7 +13,9 @@ import com.seer.teach.mp.service.IMpAgentService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* App端代理商服务实现类 * App端代理商服务实现类
@ -40,11 +43,11 @@ public class AppAgentServiceImpl implements IAppAgentService {
} }
@Override @Override
public Integer getAgentIdByUserId(Integer userId) { public List<Integer> getAgentIdListByUserId(Integer userId) {
MpAgentEmployeeRelationEntity mpAgentEmployeeRelationEntity = mpAgentEmployeeRelationService.getOneByUserId(userId); List<MpAgentEmployeeRelationEntity> mpAgentEmployeeRelations = mpAgentEmployeeRelationService.getListByUserId(userId);
if (mpAgentEmployeeRelationEntity == null) { if (CollectionUtil.isEmpty(mpAgentEmployeeRelations)) {
return null; return null;
} }
return mpAgentEmployeeRelationEntity.getAgentId(); return mpAgentEmployeeRelations.stream().map(MpAgentEmployeeRelationEntity::getAgentId).collect(Collectors.toList());
} }
} }

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.seer.teach.mp.entity.MpAgentEmployeeRelationEntity; import com.seer.teach.mp.entity.MpAgentEmployeeRelationEntity;
import java.util.List;
/** /**
* <p> * <p>
* 代理商员工关联表 服务类 * 代理商员工关联表 服务类
@ -62,5 +64,5 @@ public interface IMpAgentEmployeeRelationService extends IService<MpAgentEmploye
* @param userId 用户ID * @param userId 用户ID
* @return 代理商员工关联 * @return 代理商员工关联
*/ */
MpAgentEmployeeRelationEntity getOneByUserId(Integer userId); List<MpAgentEmployeeRelationEntity> getListByUserId(Integer userId);
} }

View File

@ -95,7 +95,7 @@ public class MpAgentEmployeeRelationServiceImpl extends ServiceImpl<MpAgentEmplo
} }
@Override @Override
public MpAgentEmployeeRelationEntity getOneByUserId(Integer userId) { public List<MpAgentEmployeeRelationEntity> getListByUserId(Integer userId) {
return super.getOne(new LambdaQueryWrapper<>(MpAgentEmployeeRelationEntity.class).eq(MpAgentEmployeeRelationEntity::getEmployeeUserId, userId)); return super.list(new LambdaQueryWrapper<>(MpAgentEmployeeRelationEntity.class).eq(MpAgentEmployeeRelationEntity::getEmployeeUserId, userId));
} }
} }