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

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

View File

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

View File

@ -1,5 +1,6 @@
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.utils.AssertUtils;
import com.seer.teach.mp.app.controller.resp.AppMpAgentResp;
@ -12,7 +13,9 @@ import com.seer.teach.mp.service.IMpAgentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* App端代理商服务实现类
@ -40,11 +43,11 @@ public class AppAgentServiceImpl implements IAppAgentService {
}
@Override
public Integer getAgentIdByUserId(Integer userId) {
MpAgentEmployeeRelationEntity mpAgentEmployeeRelationEntity = mpAgentEmployeeRelationService.getOneByUserId(userId);
if (mpAgentEmployeeRelationEntity == null) {
public List<Integer> getAgentIdListByUserId(Integer userId) {
List<MpAgentEmployeeRelationEntity> mpAgentEmployeeRelations = mpAgentEmployeeRelationService.getListByUserId(userId);
if (CollectionUtil.isEmpty(mpAgentEmployeeRelations)) {
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.seer.teach.mp.entity.MpAgentEmployeeRelationEntity;
import java.util.List;
/**
* <p>
* 代理商员工关联表 服务类
@ -62,5 +64,5 @@ public interface IMpAgentEmployeeRelationService extends IService<MpAgentEmploye
* @param userId 用户ID
* @return 代理商员工关联
*/
MpAgentEmployeeRelationEntity getOneByUserId(Integer userId);
List<MpAgentEmployeeRelationEntity> getListByUserId(Integer userId);
}

View File

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