dev-chenjiajian #1

Merged
ChenJiaJian merged 8 commits from dev-chenjiajian into master 2026-01-17 16:31:39 +08:00
25 changed files with 232 additions and 159 deletions
Showing only changes of commit 3580e833a0 - Show all commits

View File

@ -1,7 +1,6 @@
package com.seer.teach.mp.admin.controller; package com.seer.teach.mp.admin.controller;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.PageListBean; import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean; import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint; import com.seer.teach.common.annotation.LogPrint;
@ -9,26 +8,30 @@ import com.seer.teach.mp.admin.controller.req.MpActivityQueryReq;
import com.seer.teach.mp.admin.controller.req.MpActivityReq; import com.seer.teach.mp.admin.controller.req.MpActivityReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityResp; import com.seer.teach.mp.admin.controller.resp.AdminActivityResp;
import com.seer.teach.mp.admin.service.IAdminActivityService; import com.seer.teach.mp.admin.service.IAdminActivityService;
import com.seer.teach.mp.entity.MpAgentEntity;
import com.seer.teach.mp.service.IMpAgentService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@LogPrint @LogPrint
@RequiredArgsConstructor @RequiredArgsConstructor
@RestController @RestController
@Tag(name = "管理端 - 活动") @Tag(name = "管理端 - 活动")
@RequestMapping("/mp/agent/activity") @RequestMapping("/mp/activity")
public class AdminActivityController { public class AdminActivityController {
private final IAdminActivityService agentActivityService; private final IAdminActivityService agentActivityService;
private final IMpAgentService mpAgentService;
@Operation(summary = "活动列表") @Operation(summary = "活动列表")
@PostMapping("/page-list") @PostMapping("/page-list")
@SaCheckPermission("mp:admin:agent:activity:list") @SaCheckPermission("mp:admin:agent:activity:list")
@ -46,25 +49,22 @@ public class AdminActivityController {
@Operation(summary = "删除活动") @Operation(summary = "删除活动")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@SaCheckPermission("mp:admin:agent:activity:delete") @SaCheckPermission("mp:admin:agent:activity:delete")
public ResultBean<Boolean> delete(@PathVariable Integer id) { public ResultBean<Boolean> delete(@PathVariable("id") Integer id) {
return ResultBean.success(agentActivityService.deleteActivity(id)); return ResultBean.success(agentActivityService.deleteActivity(id));
} }
@Operation(summary = "详情") @Operation(summary = "详情")
@GetMapping("/{id}") @GetMapping("/{id}")
@SaCheckPermission("mp:admin:agent:activity:get") @SaCheckPermission("mp:admin:agent:activity:get")
public ResultBean<AdminActivityResp> get(@PathVariable Integer id) { public ResultBean<AdminActivityResp> get(@PathVariable("id") Integer id) {
AdminActivityResp result = agentActivityService.getById(id); AdminActivityResp result = agentActivityService.getById(id);
return ResultBean.success(result); return ResultBean.success(result);
} }
@Operation(summary = "获取活动二维码") @Operation(summary = "查询代理商没有参与的活动列表")
@GetMapping("/{activityId}/qrcode") @GetMapping("/agent/{agentId}")
@SaCheckPermission("mp:admin:agent:activity:qrcode") @SaCheckPermission("mp:admin:agent:activity:list")
public ResultBean<String> getQrCode(@PathVariable("activityId") Integer activityId, @RequestParam("appId") String appId) { public ResultBean<List<AdminActivityResp>> getAgentActivities(@PathVariable("agentId") Integer agentId) {
Integer userId = StpUtil.getLoginIdAsInt(); return ResultBean.success(agentActivityService.getAgentActivities(agentId));
MpAgentEntity one = mpAgentService.lambdaQuery().eq(MpAgentEntity::getContactUserId, userId).one();
Integer agentId = one.getId();
return ResultBean.success(agentActivityService.getQrCode(agentId, activityId, appId));
} }
} }

View File

@ -1,13 +1,14 @@
package com.seer.teach.mp.admin.controller; package com.seer.teach.mp.admin.controller;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.PageListBean; import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean; import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint; import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantQueryReq; import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantQueryReq;
import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantReq; import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantReq;
import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityParticipantResp; import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityParticipantResp;
import com.seer.teach.mp.admin.service.IAdminAgentActivityParticipantService; import com.seer.teach.mp.admin.service.IAdminAgentActivityRelationService;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity; import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import com.seer.teach.mp.service.IMpActivityService; import com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentService; import com.seer.teach.mp.service.IMpAgentService;
@ -15,7 +16,15 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@ -24,9 +33,9 @@ import java.util.List;
@RestController @RestController
@Tag(name = "管理端 - 代理商活动参与记录") @Tag(name = "管理端 - 代理商活动参与记录")
@RequestMapping("/mp/agent/activity/participant") @RequestMapping("/mp/agent/activity/participant")
public class AdminAgentActivityParticipantController { public class AdminAgentActivityRelationController {
private final IAdminAgentActivityParticipantService adminAgentActivityParticipantService; private final IAdminAgentActivityRelationService adminAgentActivityParticipantService;
private final IMpAgentService mpAgentService; private final IMpAgentService mpAgentService;
@ -67,16 +76,12 @@ public class AdminAgentActivityParticipantController {
return ResultBean.success(adminAgentActivityParticipantService.deleteById(ids)); return ResultBean.success(adminAgentActivityParticipantService.deleteById(ids));
} }
@Operation(summary = "获取活动二维码")
@Operation(summary = "查询代理商名称") @GetMapping("/{activityId}/{agentId}/qrcode")
@GetMapping("/agent-name") @SaCheckPermission("mp:admin:agent:activity:qrcode")
public ResultBean<List<String>> getAgentName() { public ResultBean<String> getQrCode(@PathVariable("activityId") Integer activityId,@PathVariable("agentId") Integer agentId, @RequestParam("appId") String appId) {
return ResultBean.success(mpAgentService.getAgentName()); Integer userId = StpUtil.getLoginIdAsInt();
return ResultBean.success(adminAgentActivityParticipantService.getQrCode(agentId, activityId, appId,userId));
} }
@Operation(summary = "查询活动名称")
@GetMapping("/activity-name")
public ResultBean<List<String>> getActivityName() {
return ResultBean.success(mpActivityService.getActivityName());
}
} }

View File

@ -27,4 +27,7 @@ public class AgentActivityParticipantQueryReq {
@Schema(description = "代理商名称") @Schema(description = "代理商名称")
private String agentName; private String agentName;
@Schema(description = "代理商ID")
private Integer agentId;
} }

View File

@ -2,6 +2,7 @@ package com.seer.teach.mp.admin.controller.req;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@Data @Data
@ -12,7 +13,15 @@ public class AgentActivityParticipantReq {
@NotBlank(message = "代理商名称不能为空") @NotBlank(message = "代理商名称不能为空")
private String agentName; private String agentName;
@Schema(description = "代理商ID")
@NotNull(message = "代理商ID不能为空")
private Integer agentId;
@Schema(description = "活动名称") @Schema(description = "活动名称")
@NotBlank(message = "活动名称不能为空") @NotBlank(message = "活动名称不能为空")
private String activityName; private String activityName;
@Schema(description = "活动ID")
@NotNull(message = "活动ID不能为空")
private Integer activityId;
} }

View File

@ -17,6 +17,11 @@ public interface AdminAgentActivityParticipantConvert {
List<AdminAgentActivityParticipantResp> convertToRespList(List<MpAgentActivityParticipantEntity> entity); List<AdminAgentActivityParticipantResp> convertToRespList(List<MpAgentActivityParticipantEntity> entity);
/**
* 转换为实体
*
* @param entity
* @return
*/
MpAgentActivityParticipantEntity convertToEntity(AgentActivityParticipantReq entity); MpAgentActivityParticipantEntity convertToEntity(AgentActivityParticipantReq entity);
} }

View File

@ -5,6 +5,8 @@ import com.seer.teach.mp.admin.controller.req.MpActivityQueryReq;
import com.seer.teach.mp.admin.controller.req.MpActivityReq; import com.seer.teach.mp.admin.controller.req.MpActivityReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityResp; import com.seer.teach.mp.admin.controller.resp.AdminActivityResp;
import java.util.List;
/** /**
* <p> * <p>
* 管理端代理商活动服务类 * 管理端代理商活动服务类
@ -48,11 +50,10 @@ public interface IAdminActivityService {
AdminActivityResp getById(Integer id); AdminActivityResp getById(Integer id);
/** /**
* 获取活动二维码 * 根据代理商ID获取其参与的活动列表
*
* @param agentId 代理商ID * @param agentId 代理商ID
* @param activityId 活动ID * @return 活动列表
* @param appId 微信公众号ID
* @return 活动二维码
*/ */
String getQrCode(Integer agentId, Integer activityId, String appId); List<AdminActivityResp> getAgentActivities(Integer agentId);
} }

View File

@ -16,7 +16,7 @@ import java.util.List;
* @author * @author
* @since 2025-12-30 * @since 2025-12-30
*/ */
public interface IAdminAgentActivityParticipantService { public interface IAdminAgentActivityRelationService {
/** /**
* 分页查询代理商活动参与记录列表管理端 * 分页查询代理商活动参与记录列表管理端
@ -57,4 +57,15 @@ public interface IAdminAgentActivityParticipantService {
* @return 操作是否成功 * @return 操作是否成功
*/ */
Boolean deleteById(List<Integer> ids); Boolean deleteById(List<Integer> ids);
/**
* 获取活动二维码
*
* @param agentId 代理商ID
* @param activityId 活动ID
* @param appId 微信公众号appId
* @param userId 用户ID
* @return 二维码地址
*/
String getQrCode(Integer agentId, Integer activityId, String appId, Integer userId);
} }

View File

@ -3,26 +3,23 @@ package com.seer.teach.mp.admin.service.impl;
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;
import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.exception.CommonException;
import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.common.utils.PageConverterUtils; import com.seer.teach.common.utils.PageConverterUtils;
import com.seer.teach.mp.admin.controller.req.AgentGenerateQrCodeReq;
import com.seer.teach.mp.admin.controller.req.MpActivityQueryReq; import com.seer.teach.mp.admin.controller.req.MpActivityQueryReq;
import com.seer.teach.mp.admin.controller.req.MpActivityReq; import com.seer.teach.mp.admin.controller.req.MpActivityReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityResp; import com.seer.teach.mp.admin.controller.resp.AdminActivityResp;
import com.seer.teach.mp.admin.controller.resp.AdminAgentQrCodeResp;
import com.seer.teach.mp.admin.convert.AdminActivityConvert; import com.seer.teach.mp.admin.convert.AdminActivityConvert;
import com.seer.teach.mp.admin.service.AdminOfficialQrCodeService;
import com.seer.teach.mp.admin.service.IAdminActivityService; import com.seer.teach.mp.admin.service.IAdminActivityService;
import com.seer.teach.mp.entity.MpActivityEntity; import com.seer.teach.mp.entity.MpActivityEntity;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity; import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import com.seer.teach.mp.service.IMpActivityService; import com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentActivityParticipantService; import com.seer.teach.mp.service.IMpAgentActivityParticipantService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@ -33,6 +30,7 @@ import java.util.Objects;
* @author Lingma * @author Lingma
* @since 2025-12-30 * @since 2025-12-30
*/ */
@Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class AdminActivityServiceImpl implements IAdminActivityService { public class AdminActivityServiceImpl implements IAdminActivityService {
@ -41,8 +39,6 @@ public class AdminActivityServiceImpl implements IAdminActivityService {
private final IMpAgentActivityParticipantService agentActivityParticipantService; private final IMpAgentActivityParticipantService agentActivityParticipantService;
private final AdminOfficialQrCodeService officialQrCodeService;
@Override @Override
public PageListBean<AdminActivityResp> pageList(MpActivityQueryReq query) { public PageListBean<AdminActivityResp> pageList(MpActivityQueryReq query) {
Page<MpActivityEntity> page = new Page<>(query.getPageNo(), query.getPageSize()); Page<MpActivityEntity> page = new Page<>(query.getPageNo(), query.getPageSize());
@ -70,25 +66,25 @@ public class AdminActivityServiceImpl implements IAdminActivityService {
} }
@Override @Override
public String getQrCode(Integer agentId, Integer activityId, String appId) { public List<AdminActivityResp> getAgentActivities(Integer agentId) {
MpActivityEntity activity = agentActivityService.getById(activityId); List<MpActivityEntity> result = new ArrayList<>();
AssertUtils.notNull(activity, ResultCodeEnum.INVALID_ACTIVITY); // 先查询代理商参与的所有活动ID
var participants = agentActivityParticipantService.getListByAgentId(agentId);
if (activity.getStatus() != 1) { if (participants.isEmpty()) {
throw new CommonException(ResultCodeEnum.INVALID_ACTIVITY); log.info("没有代理商参与活动");
result.addAll(agentActivityService.list());
}else{
var activityIds = participants.stream()
.map(MpAgentActivityParticipantEntity::getActivityId)
.distinct()
.toList();
// 查询这些活动的详细信息
var wrapper = new LambdaQueryWrapper<MpActivityEntity>()
.notIn(MpActivityEntity::getId, activityIds)
.orderByDesc(MpActivityEntity::getCreateTime);
List<MpActivityEntity> activitys = agentActivityService.list(wrapper);
result.addAll(activitys);
} }
MpAgentActivityParticipantEntity relation = agentActivityParticipantService.getParticipantsByActivityAndAgent(activityId, agentId); return AdminActivityConvert.INSTANCE.convertToRespList(result);
AssertUtils.notNull(relation, ResultCodeEnum.INVALID_ACTIVITY);
if (StringUtils.isNotBlank(relation.getQrCodeUrl())) {
return relation.getQrCodeUrl();
}
AgentGenerateQrCodeReq req = new AgentGenerateQrCodeReq();
req.setSceneStr("agentId=" + agentId + "&activityId=" + activityId);
req.setAppId(appId);
req.setType(2);
AdminAgentQrCodeResp QrCodeResp = officialQrCodeService.generateQrCode(req);
relation.setQrCodeUrl(QrCodeResp.getQrCodeUrl());
agentActivityParticipantService.updateById(relation);
return QrCodeResp.getQrCodeUrl();
} }
} }

View File

@ -3,12 +3,18 @@ package com.seer.teach.mp.admin.service.impl;
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;
import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.exception.CommonException;
import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.common.utils.PageConverterUtils; import com.seer.teach.common.utils.PageConverterUtils;
import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantQueryReq; import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantQueryReq;
import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantReq; import com.seer.teach.mp.admin.controller.req.AgentActivityParticipantReq;
import com.seer.teach.mp.admin.controller.req.AgentGenerateQrCodeReq;
import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityParticipantResp; import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityParticipantResp;
import com.seer.teach.mp.admin.controller.resp.AdminAgentQrCodeResp;
import com.seer.teach.mp.admin.convert.AdminAgentActivityParticipantConvert; import com.seer.teach.mp.admin.convert.AdminAgentActivityParticipantConvert;
import com.seer.teach.mp.admin.service.IAdminAgentActivityParticipantService; import com.seer.teach.mp.admin.service.AdminOfficialQrCodeService;
import com.seer.teach.mp.admin.service.IAdminAgentActivityRelationService;
import com.seer.teach.mp.entity.MpActivityEntity; import com.seer.teach.mp.entity.MpActivityEntity;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity; import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import com.seer.teach.mp.entity.MpAgentEntity; import com.seer.teach.mp.entity.MpAgentEntity;
@ -16,6 +22,7 @@ import com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentActivityParticipantService; import com.seer.teach.mp.service.IMpAgentActivityParticipantService;
import com.seer.teach.mp.service.IMpAgentService; import com.seer.teach.mp.service.IMpAgentService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -30,7 +37,7 @@ import java.util.List;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActivityParticipantService { public class AdminAgentActivityRelationServiceImpl implements IAdminAgentActivityRelationService {
private final IMpAgentActivityParticipantService mpAgentActivityParticipantService; private final IMpAgentActivityParticipantService mpAgentActivityParticipantService;
@ -38,6 +45,8 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
private final IMpActivityService mpActivityService; private final IMpActivityService mpActivityService;
private final AdminOfficialQrCodeService officialQrCodeService;
@Override @Override
public PageListBean<AdminAgentActivityParticipantResp> pageList(AgentActivityParticipantQueryReq query) { public PageListBean<AdminAgentActivityParticipantResp> pageList(AgentActivityParticipantQueryReq query) {
Page<MpAgentActivityParticipantEntity> page = new Page<>(query.getPageNum(), query.getPageSize()); Page<MpAgentActivityParticipantEntity> page = new Page<>(query.getPageNum(), query.getPageSize());
@ -51,27 +60,26 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
if (query.getAgentName() != null) { if (query.getAgentName() != null) {
wrapper.like(MpAgentActivityParticipantEntity::getAgentName, query.getAgentName()); wrapper.like(MpAgentActivityParticipantEntity::getAgentName, query.getAgentName());
} }
if (query.getAgentId() != null) {
wrapper.eq(MpAgentActivityParticipantEntity::getAgentId, query.getAgentId());
}
Page<MpAgentActivityParticipantEntity> result = mpAgentActivityParticipantService.page(page, wrapper); Page<MpAgentActivityParticipantEntity> result = mpAgentActivityParticipantService.page(page, wrapper);
return PageConverterUtils.convertPageListBean(result, AdminAgentActivityParticipantConvert.INSTANCE::convertToRespList); return PageConverterUtils.convertPageListBean(result, AdminAgentActivityParticipantConvert.INSTANCE::convertToRespList);
} }
@Override @Override
public boolean saveParticipant(AgentActivityParticipantReq entity) { public boolean saveParticipant(AgentActivityParticipantReq req) {
// 检查是否已存在相同的活动代理商和家长记录 // 检查是否已存在相同的活动代理商和家长记录
LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MpAgentActivityParticipantEntity::getActivityName, entity.getActivityName()) wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, req.getActivityId())
.eq(MpAgentActivityParticipantEntity::getAgentName, entity.getAgentName()); .eq(MpAgentActivityParticipantEntity::getAgentId, req.getAgentId());
long count = mpAgentActivityParticipantService.count(wrapper); long count = mpAgentActivityParticipantService.count(wrapper);
if (count > 0) { if (count > 0) {
throw new RuntimeException("该代理商活动参与记录已存在"); throw new RuntimeException("该代理商活动参与记录已存在");
} }
Integer agentId = mpAgentService.lambdaQuery().eq(MpAgentEntity::getAgentName, entity.getAgentName()).one().getId(); MpAgentActivityParticipantEntity result = AdminAgentActivityParticipantConvert.INSTANCE.convertToEntity(req);
Integer activityId = mpActivityService.lambdaQuery().eq(MpActivityEntity::getActivityName, entity.getActivityName()).one().getId();
MpAgentActivityParticipantEntity result = AdminAgentActivityParticipantConvert.INSTANCE.convertToEntity(entity);
result.setActivityId(activityId);
result.setAgentId(agentId);
return mpAgentActivityParticipantService.save(result); return mpAgentActivityParticipantService.save(result);
} }
@ -108,4 +116,27 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
return mpAgentActivityParticipantService.removeByIds(ids); return mpAgentActivityParticipantService.removeByIds(ids);
} }
@Override
public String getQrCode(Integer agentId, Integer activityId, String appId, Integer userId) {
MpActivityEntity activity = mpActivityService.getById(activityId);
AssertUtils.notNull(activity, ResultCodeEnum.INVALID_ACTIVITY);
if (activity.getStatus() != 1) {
throw new CommonException(ResultCodeEnum.INVALID_ACTIVITY);
}
MpAgentActivityParticipantEntity relation = mpAgentActivityParticipantService.getParticipantsByActivityAndAgent(activityId, agentId);
AssertUtils.notNull(relation, ResultCodeEnum.INVALID_ACTIVITY);
if (StringUtils.isNotBlank(relation.getQrCodeUrl())) {
return relation.getQrCodeUrl();
}
AgentGenerateQrCodeReq req = new AgentGenerateQrCodeReq();
req.setSceneStr("agentId=" + agentId + "&activityId=" + activityId);
req.setAppId(appId);
req.setType(2);
AdminAgentQrCodeResp QrCodeResp = officialQrCodeService.generateQrCode(req);
relation.setQrCodeUrl(QrCodeResp.getQrCodeUrl());
mpAgentActivityParticipantService.updateById(relation);
return QrCodeResp.getQrCodeUrl();
}
} }

View File

@ -7,7 +7,7 @@ import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation; import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation; import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint; import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.app.controller.req.AppAgentActivityQueryReq; import com.seer.teach.mp.app.controller.req.AppActivityQueryReq;
import com.seer.teach.mp.app.controller.resp.AppActivityResp; import com.seer.teach.mp.app.controller.resp.AppActivityResp;
import com.seer.teach.mp.app.service.IAppActivityService; import com.seer.teach.mp.app.service.IAppActivityService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -41,7 +41,7 @@ public class AppMpActivityController {
@Operation(summary = "活动列表") @Operation(summary = "活动列表")
@GetMapping("/page-list") @GetMapping("/page-list")
@SaCheckPermission("mp:app:agent:activity:list") @SaCheckPermission("mp:app:agent:activity:list")
public ResultBean<PageListBean<AppActivityResp>> pageList(AppAgentActivityQueryReq query) { public ResultBean<PageListBean<AppActivityResp>> pageList(AppActivityQueryReq query) {
Integer userId = StpUtil.getLoginIdAsInt(); Integer userId = StpUtil.getLoginIdAsInt();
return ResultBean.success(agentActivityService.pageList(query,userId)); return ResultBean.success(agentActivityService.pageList(query,userId));
} }
@ -53,11 +53,4 @@ public class AppMpActivityController {
return ResultBean.success(agentActivityService.getById(id)); return ResultBean.success(agentActivityService.getById(id));
} }
@Operation(summary = "活动二维码")
@GetMapping("/{agentId}/{activityId}/qrcode")
@SaCheckPermission("mp:app:agent:activity:qrcode")
public ResultBean<String> getQrCode(@PathVariable("agentId") Integer agentId, @PathVariable("activityId") Integer activityId, @RequestParam("appId") String appId) {
Integer userId = StpUtil.getLoginIdAsInt();
return ResultBean.success(agentActivityService.getQrCode(userId,agentId,activityId,appId));
}
} }

View File

@ -4,9 +4,9 @@ import com.seer.teach.common.request.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@Schema(name = "AppAgentActivityQueryReq", description = "代理商活动查询请求参数") @Schema(name = "AppActivityQueryReq", description = "代理商活动查询请求参数")
@Data @Data
public class AppAgentActivityQueryReq extends PageRequest { public class AppActivityQueryReq extends PageRequest {
@Schema(description = "活动名称") @Schema(description = "活动名称")
private String activityName; private String activityName;

View File

@ -30,4 +30,8 @@ public class AppMpAgentResp {
@Schema(description = "是否是代理商联系人") @Schema(description = "是否是代理商联系人")
private Boolean isContactPerson; private Boolean isContactPerson;
}
@Schema(description = "是否有多个代理商")
private Boolean hasMultipleAgents;
}

View File

@ -1,6 +1,6 @@
package com.seer.teach.mp.app.convert; package com.seer.teach.mp.app.convert;
import com.seer.teach.mp.app.controller.req.AppAgentActivityQueryReq; import com.seer.teach.mp.app.controller.req.AppActivityQueryReq;
import com.seer.teach.mp.app.controller.resp.AppActivityResp; import com.seer.teach.mp.app.controller.resp.AppActivityResp;
import com.seer.teach.mp.entity.MpActivityEntity; import com.seer.teach.mp.entity.MpActivityEntity;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
@ -14,7 +14,7 @@ public interface AppAgentActivityConvert {
AppAgentActivityConvert INSTANCE = Mappers.getMapper(AppAgentActivityConvert.class); AppAgentActivityConvert INSTANCE = Mappers.getMapper(AppAgentActivityConvert.class);
MpActivityEntity convert(AppAgentActivityQueryReq req); MpActivityEntity convert(AppActivityQueryReq req);
@Mapping(target = "createTime", dateFormat = "yyyy-MM-dd HH:mm:ss") @Mapping(target = "createTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
@Mapping(target = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss") @Mapping(target = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss")

View File

@ -1,8 +1,8 @@
package com.seer.teach.mp.app.service; package com.seer.teach.mp.app.service;
import com.seer.teach.common.PageListBean; import com.seer.teach.common.PageListBean;
import com.seer.teach.mp.app.controller.req.AppActivityQueryReq;
import com.seer.teach.mp.app.controller.resp.AppActivityResp; import com.seer.teach.mp.app.controller.resp.AppActivityResp;
import com.seer.teach.mp.app.controller.req.AppAgentActivityQueryReq;
/** /**
* <p> * <p>
@ -21,7 +21,7 @@ public interface IAppActivityService {
* @param agentId 代理商ID * @param agentId 代理商ID
* @return 代理商活动分页列表 * @return 代理商活动分页列表
*/ */
PageListBean<AppActivityResp> pageList(AppAgentActivityQueryReq query, Integer agentId); PageListBean<AppActivityResp> pageList(AppActivityQueryReq query, Integer agentId);
/** /**
* 根据ID获取活动详情 * 根据ID获取活动详情
@ -31,13 +31,4 @@ public interface IAppActivityService {
*/ */
AppActivityResp getById(Integer id); AppActivityResp getById(Integer id);
/**
* 获取活动二维码
*
* @param userId 用户ID
* @param agentId 代理商ID
* @param activityId 活动ID
* @return 活动二维码
*/
String getQrCode(Integer userId,Integer agentId,Integer activityId,String appId);
} }

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

@ -9,7 +9,7 @@ import com.seer.teach.common.enums.ResultCodeEnum;
import com.seer.teach.common.exception.CommonException; import com.seer.teach.common.exception.CommonException;
import com.seer.teach.common.utils.AssertUtils; import com.seer.teach.common.utils.AssertUtils;
import com.seer.teach.common.utils.PageConverterUtils; import com.seer.teach.common.utils.PageConverterUtils;
import com.seer.teach.mp.app.controller.req.AppAgentActivityQueryReq; import com.seer.teach.mp.app.controller.req.AppActivityQueryReq;
import com.seer.teach.mp.app.controller.req.MpGenerateQrCodeReq; import com.seer.teach.mp.app.controller.req.MpGenerateQrCodeReq;
import com.seer.teach.mp.app.controller.resp.AppActivityResp; import com.seer.teach.mp.app.controller.resp.AppActivityResp;
import com.seer.teach.mp.app.controller.resp.MpQrCodeResp; import com.seer.teach.mp.app.controller.resp.MpQrCodeResp;
@ -20,7 +20,6 @@ import com.seer.teach.mp.entity.MpActivityEntity;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity; import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import com.seer.teach.mp.service.IMpActivityService; import com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentActivityParticipantService; import com.seer.teach.mp.service.IMpAgentActivityParticipantService;
import com.seer.teach.mp.service.IMpAgentService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -48,7 +47,7 @@ public class AppActivityServiceImpl implements IAppActivityService {
private final IMpAgentActivityParticipantService agentActivityParticipantService; private final IMpAgentActivityParticipantService agentActivityParticipantService;
@Override @Override
public PageListBean<AppActivityResp> pageList(AppAgentActivityQueryReq query, Integer agentId) { public PageListBean<AppActivityResp> pageList(AppActivityQueryReq query, Integer agentId) {
log.info("查询参数:{}", query); log.info("查询参数:{}", query);
IPage<MpActivityEntity> page = new Page<>(query.getPageNo(), query.getPageSize()); IPage<MpActivityEntity> page = new Page<>(query.getPageNo(), query.getPageSize());
var pageResult = activityService.page(page, new LambdaQueryWrapper<>(MpActivityEntity.class) var pageResult = activityService.page(page, new LambdaQueryWrapper<>(MpActivityEntity.class)
@ -66,27 +65,4 @@ public class AppActivityServiceImpl implements IAppActivityService {
MpActivityEntity entity = activityService.getById(id); MpActivityEntity entity = activityService.getById(id);
return AppAgentActivityConvert.INSTANCE.convertToResp(entity); return AppAgentActivityConvert.INSTANCE.convertToResp(entity);
} }
@Override
public String getQrCode(Integer userId,Integer agentId,Integer activityId,String appId) {
MpActivityEntity activity = activityService.getById(activityId);
AssertUtils.notNull(activity, ResultCodeEnum.INVALID_ACTIVITY);
if(activity.getStatus() != 1){
throw new CommonException(ResultCodeEnum.INVALID_ACTIVITY);
}
MpAgentActivityParticipantEntity relation = agentActivityParticipantService.getParticipantsByActivityAndAgent(activityId, agentId);
AssertUtils.notNull(relation, ResultCodeEnum.INVALID_ACTIVITY);
if(StringUtils.isNotBlank(relation.getQrCodeUrl())){
return relation.getQrCodeUrl();
}
MpGenerateQrCodeReq req = new MpGenerateQrCodeReq();
req.setSceneStr("agentId=" + agentId + "&activityId=" + activityId);
req.setAppId(appId);
req.setType(2);
MpQrCodeResp mpQrCodeResp = officialQrCodeService.generateQrCode(req);
relation.setQrCodeUrl(mpQrCodeResp.getQrCodeUrl());
agentActivityParticipantService.updateById(relation);
return mpQrCodeResp.getQrCodeUrl();
}
} }

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;
@ -10,9 +11,14 @@ import com.seer.teach.mp.entity.MpAgentEntity;
import com.seer.teach.mp.service.IMpAgentEmployeeRelationService; import com.seer.teach.mp.service.IMpAgentEmployeeRelationService;
import com.seer.teach.mp.service.IMpAgentService; import com.seer.teach.mp.service.IMpAgentService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* App端代理商服务实现类 * App端代理商服务实现类
@ -26,25 +32,38 @@ public class AppAgentServiceImpl implements IAppAgentService {
@Override @Override
public AppMpAgentResp getAgentRespByUserId(Integer userId) { public AppMpAgentResp getAgentRespByUserId(Integer userId) {
MpAgentEntity one = mpAgentService.lambdaQuery().eq(MpAgentEntity::getContactUserId, userId).one(); List<MpAgentEntity> agents = mpAgentService.getListByUserId(userId);
AssertUtils.notNull(one, ResultCodeEnum.AGENT_NOT_FOUND); AssertUtils.notEmpty(agents, ResultCodeEnum.AGENT_NOT_FOUND);
Integer agentId = one.getId();
MpAgentEntity agentEntity = mpAgentService.getAgentById(agentId); MpAgentEntity agentEntity = null;
if (Objects.isNull(agentEntity)) { boolean hasContactPerson = false;
return null; for (MpAgentEntity agent : agents) {
if (Objects.nonNull(agent.getContactUserId()) && agent.getContactUserId().equals(userId)) {
agentEntity = agent;
hasContactPerson = true;
break;
}
}
// 如果没找到对应的联系人则取第一个代理商
if (agentEntity == null) {
agentEntity = agents.get(0);
} }
AppMpAgentResp appMpAgentResp = AppAgentConvert.INSTANCE.entityToResp(agentEntity); AppMpAgentResp appMpAgentResp = AppAgentConvert.INSTANCE.entityToResp(agentEntity);
Boolean isContactPerson = Objects.nonNull(agentEntity.getContactUserId()) && agentEntity.getContactUserId().equals(userId); appMpAgentResp.setIsContactPerson(hasContactPerson);
appMpAgentResp.setIsContactPerson(isContactPerson); appMpAgentResp.setHasMultipleAgents(agents.size() > 1);
return appMpAgentResp; return appMpAgentResp;
} }
@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; List<MpAgentEntity> mpAgentEntities = mpAgentService.lambdaQuery().eq(MpAgentEntity::getContactUserId, userId).list();
if (CollectionUtil.isEmpty(mpAgentEntities)) {
return Collections.emptyList();
}
return mpAgentEntities.stream().map(MpAgentEntity::getId).collect(Collectors.toList());
} }
return mpAgentEmployeeRelationEntity.getAgentId(); return mpAgentEmployeeRelations.stream().map(MpAgentEmployeeRelationEntity::getAgentId).collect(Collectors.toList());
} }
} }

View File

@ -38,5 +38,5 @@ public interface IMpAgentActivityParticipantService extends IService<MpAgentActi
* @param activityId 活动ID * @param activityId 活动ID
* @return 参与记录列表 * @return 参与记录列表
*/ */
List<MpAgentActivityParticipantEntity> getOneByActivityId(Integer activityId); List<MpAgentActivityParticipantEntity> getListByActivityId(Integer activityId);
} }

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

@ -48,4 +48,11 @@ public interface IMpAgentService extends IService<MpAgentEntity> {
* @return 代理商数量 * @return 代理商数量
*/ */
long getCountByPhone(String phone); long getCountByPhone(String phone);
/**
* 根据用户ID获取代理商列表
* @param userId 用户ID
* @return 代理商列表
*/
List<MpAgentEntity> getListByUserId(Integer userId);
} }

View File

@ -44,7 +44,7 @@ public class MpAgentActivityParticipantServiceImpl extends ServiceImpl<MpAgentAc
} }
@Override @Override
public List<MpAgentActivityParticipantEntity> getOneByActivityId(Integer activityId) { public List<MpAgentActivityParticipantEntity> getListByActivityId(Integer activityId) {
return super.list(new LambdaQueryWrapper<MpAgentActivityParticipantEntity>().eq(MpAgentActivityParticipantEntity::getActivityId, activityId)); return super.list(new LambdaQueryWrapper<MpAgentActivityParticipantEntity>().eq(MpAgentActivityParticipantEntity::getActivityId, activityId));
} }
} }

View File

@ -95,7 +95,8 @@ 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>()
.eq(MpAgentEmployeeRelationEntity::getEmployeeUserId, userId));
} }
} }

View File

@ -1,9 +1,12 @@
package com.seer.teach.mp.service.impl; package com.seer.teach.mp.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.common.enums.RoleEnum; import com.seer.teach.common.enums.RoleEnum;
import com.seer.teach.mp.entity.MpAgentEmployeeRelationEntity;
import com.seer.teach.mp.entity.MpAgentEntity; import com.seer.teach.mp.entity.MpAgentEntity;
import com.seer.teach.mp.mapper.MpAgentMapper; import com.seer.teach.mp.mapper.MpAgentMapper;
import com.seer.teach.mp.service.IMpAgentEmployeeRelationService;
import com.seer.teach.mp.service.IMpAgentService; import com.seer.teach.mp.service.IMpAgentService;
import com.seer.teach.user.api.UserInfoServiceApi; import com.seer.teach.user.api.UserInfoServiceApi;
import com.seer.teach.user.api.dto.UserInfoDTO; import com.seer.teach.user.api.dto.UserInfoDTO;
@ -13,6 +16,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 代理商服务实现类 * 代理商服务实现类
@ -23,6 +28,7 @@ import java.util.List;
public class MpAgentServiceImpl extends ServiceImpl<MpAgentMapper, MpAgentEntity> implements IMpAgentService { public class MpAgentServiceImpl extends ServiceImpl<MpAgentMapper, MpAgentEntity> implements IMpAgentService {
private final UserInfoServiceApi userInfoServiceApi; private final UserInfoServiceApi userInfoServiceApi;
private final IMpAgentEmployeeRelationService mpAgentEmployeeRelationService;
@Override @Override
public MpAgentEntity getAgentById(Integer id) { public MpAgentEntity getAgentById(Integer id) {
@ -69,4 +75,18 @@ public class MpAgentServiceImpl extends ServiceImpl<MpAgentMapper, MpAgentEntity
public long getCountByPhone(String phone) { public long getCountByPhone(String phone) {
return this.lambdaQuery().eq(MpAgentEntity::getContactPhone, phone).count(); return this.lambdaQuery().eq(MpAgentEntity::getContactPhone, phone).count();
} }
@Override
public List<MpAgentEntity> getListByUserId(Integer userId) {
List<MpAgentEntity> list = this.lambdaQuery().eq(MpAgentEntity::getContactUserId, userId).list();
if(CollectionUtil.isEmpty(list)){
List<MpAgentEmployeeRelationEntity> relationEntities = mpAgentEmployeeRelationService.getListByUserId(userId);
if(CollectionUtil.isNotEmpty(relationEntities)){
Set<Integer> agentIds = relationEntities.stream().map(MpAgentEmployeeRelationEntity::getAgentId).collect(Collectors.toSet());
return this.lambdaQuery().in(MpAgentEntity::getId, agentIds).list();
}
return List.of();
}
return list;
}
} }