增加代理商,活动,代理商员工关,代理商活动参与者相关功能

This commit is contained in:
Wang 2025-12-30 18:26:40 +08:00
parent 42bd6576eb
commit c0fdf7dfd1
10 changed files with 57 additions and 86 deletions

View File

@ -17,27 +17,57 @@ public class PageConverterUtils {
* 将MyBatis-Plus的IPage分页结果转换为目标分页Bean * 将MyBatis-Plus的IPage分页结果转换为目标分页Bean
* 使用示例 * 使用示例
* <code> * <code>
* IPage<GoodsEntity> iPage = goodsService.queryPageList(size, current, goods); * IPage<GoodsEntity> iPage = goodsService.queryPageList(size, current, goods);
* PageListBean<GoodsResp> result = PageConverterUtils.convertPageListBean(iPage, GoodConverter.INSTANCE::list); * PageListBean<GoodsResp> result = PageConverterUtils.convertPageListBean(iPage, GoodConverter.INSTANCE::list);
* </code> * </code>
* * <p>
* 通用分页对象转换方法 * 通用分页对象转换方法
* @param sourcePage MyBatis Plus 分页对象 *
* @param converter 数据转换函数 ( GoodConverter.INSTANCE::list) * @param sourcePage MyBatis Plus 分页对象
* @param <T> 源数据类型 * @param converter 数据转换函数 ( GoodConverter.INSTANCE::list)
* @param <T> 源数据类型
* @return PageListBean<R> 自定义分页响应对象 * @return PageListBean<R> 自定义分页响应对象
*/ */
public static <T, R> PageListBean<R> convertPageListBean( public static <T, R> PageListBean<R> convertPageListBean(
IPage<T> sourcePage, IPage<T> sourcePage,
Function<List<T>, List<R>> converter) { Function<List<T>, List<R>> converter) {
PageListBean<R> result = new PageListBean<>(); PageListBean<R> result = new PageListBean<>();
if(null == sourcePage || sourcePage.getRecords() == null || sourcePage.getRecords().isEmpty()){ if (null == sourcePage || sourcePage.getRecords() == null || sourcePage.getRecords().isEmpty()) {
return result; return result;
} }
// 应用转换函数 // 应用转换函数
result.setList(converter.apply(sourcePage.getRecords())); result.setList(converter.apply(sourcePage.getRecords()));
result.setPageSize((int) sourcePage.getSize()); result.setPageSize(sourcePage.getSize());
result.setTotalPage((int) sourcePage.getPages()); result.setTotalPage(sourcePage.getPages());
result.setTotal(sourcePage.getTotal());
return result;
}
/**
* 分页数据转换方法
* 将MyBatis-Plus的IPage分页结果转换为目标分页Bean
* 使用示例
* <code>
* IPage<GoodsEntity> iPage = goodsService.queryPageList(size, current, goods);
* PageListBean<GoodsResp> result = PageConverterUtils.convertPageList(iPage, GoodConverter.INSTANCE::one);
* </code>
* <p>
* 通用分页对象转换方法
* @param sourcePage MyBatis Plus 分页对象
* @param converter 数据转换函数 ( GoodConverter.INSTANCE::one)
* @param <T> 源数据类型
* @return PageListBean 自定义分页响应对象
*/
public static <T, R> PageListBean<R> convertPageList(
IPage<T> sourcePage,
Function<T, R> converter) {
PageListBean<R> result = new PageListBean<>();
if (null == sourcePage || sourcePage.getRecords() == null || sourcePage.getRecords().isEmpty()) {
return result;
}
result.setList(sourcePage.getRecords().stream().map(converter).toList());
result.setPageSize(sourcePage.getSize());
result.setTotalPage(sourcePage.getPages());
result.setTotal(sourcePage.getTotal()); result.setTotal(sourcePage.getTotal());
return result; return result;
} }

View File

@ -32,7 +32,7 @@ public class MpAgentActivityLogEntity extends BaseEntity {
* 操作人ID * 操作人ID
*/ */
@TableField("operator_id") @TableField("operator_id")
private Integer operatorId; private String operatorId;
/** /**
* 操作类型 * 操作类型

View File

@ -23,7 +23,7 @@ public class AdminAgentActivityLogResp {
private Integer activityId; private Integer activityId;
@Schema(description = "操作人ID") @Schema(description = "操作人ID")
private Integer operatorId; private String operatorId;
@Schema(description = "操作类型") @Schema(description = "操作类型")
private String operationType; private String operationType;

View File

@ -1,5 +1,6 @@
package com.seer.teach.mp.admin.service; package com.seer.teach.mp.admin.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
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;
@ -11,6 +12,7 @@ import com.seer.teach.mp.entity.MpAgentEntity;
import com.seer.teach.mp.service.IMpAgentService; 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.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -32,7 +34,10 @@ public class AdminAgentService {
Page<MpAgentEntity> pageParam = new Page<>(pageReq.getPageNo(), pageReq.getPageSize()); Page<MpAgentEntity> pageParam = new Page<>(pageReq.getPageNo(), pageReq.getPageSize());
MpAgentEntity query = AgentConvert.INSTANCE.convertOne(pageReq); MpAgentEntity query = AgentConvert.INSTANCE.convertOne(pageReq);
IPage<MpAgentEntity> resultPage = mpAgentService.pageList(pageParam, query); IPage<MpAgentEntity> resultPage = mpAgentService.page(pageParam, new LambdaQueryWrapper<>(MpAgentEntity.class)
.like(StringUtils.isNotBlank(query.getAgentName()), MpAgentEntity::getAgentName, query.getAgentName())
.like(StringUtils.isNotBlank(query.getContactName()), MpAgentEntity::getContactName, query.getContactName())
.like(StringUtils.isNotBlank(query.getContactPhone()), MpAgentEntity::getContactPhone, query.getContactPhone()));
return PageConverterUtils.convertPageListBean(resultPage, AgentConvert.INSTANCE::convertRespList); return PageConverterUtils.convertPageListBean(resultPage, AgentConvert.INSTANCE::convertRespList);
} }

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
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.utils.PageConverterUtils;
import com.seer.teach.mp.admin.controller.req.AgentActivityLogQueryReq; import com.seer.teach.mp.admin.controller.req.AgentActivityLogQueryReq;
import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityLogResp; import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityLogResp;
import com.seer.teach.mp.admin.service.IAdminAgentActivityLogService; import com.seer.teach.mp.admin.service.IAdminAgentActivityLogService;
@ -59,12 +60,7 @@ public class AdminAgentActivityLogServiceImpl implements IAdminAgentActivityLogS
IPage<MpAgentActivityLogEntity> result = mpAgentActivityLogService.page(page, wrapper); IPage<MpAgentActivityLogEntity> result = mpAgentActivityLogService.page(page, wrapper);
// 转换为响应对象 return PageConverterUtils.convertPageList(result, this::convertToResp);
List<AdminAgentActivityLogResp> records = result.getRecords().stream()
.map(this::convertToResp)
.toList();
return new PageListBean<>(result.getTotal(), records);
} }
@Override @Override

View File

@ -10,13 +10,9 @@ import com.seer.teach.mp.admin.controller.resp.AdminAgentActivityParticipantResp
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.IAdminAgentActivityParticipantService;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity; import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import com.seer.teach.mp.mapper.MpAgentActivityParticipantMapper;
import com.seer.teach.mp.service.IMpAgentActivityParticipantService; import com.seer.teach.mp.service.IMpAgentActivityParticipantService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/** /**
* <p> * <p>
@ -57,8 +53,7 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
// 检查是否已存在相同的活动代理商和家长记录 // 检查是否已存在相同的活动代理商和家长记录
LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, entity.getActivityId()) wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, entity.getActivityId())
.eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId()) .eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId());
.eq(MpAgentActivityParticipantEntity::getParentId, entity.getParentId());
long count = mpAgentActivityParticipantService.count(wrapper); long count = mpAgentActivityParticipantService.count(wrapper);
if (count > 0) { if (count > 0) {
@ -74,7 +69,6 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, entity.getActivityId()) wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, entity.getActivityId())
.eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId()) .eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId())
.eq(MpAgentActivityParticipantEntity::getParentId, entity.getParentId())
.ne(MpAgentActivityParticipantEntity::getId, entity.getId()); .ne(MpAgentActivityParticipantEntity::getId, entity.getId());
long count = mpAgentActivityParticipantService.count(wrapper); long count = mpAgentActivityParticipantService.count(wrapper);

View File

@ -24,6 +24,6 @@ public interface IMpAgentActivityLogService extends IService<MpAgentActivityLogE
* @param afterData 操作后数据 * @param afterData 操作后数据
* @return 操作是否成功 * @return 操作是否成功
*/ */
boolean logOperation(Integer activityId, Integer operatorId, String operationType, boolean logOperation(Integer activityId, String operatorId, String operationType,
String description, String beforeData, String afterData); String description, String beforeData, String afterData);
} }

View File

@ -1,11 +1,7 @@
package com.seer.teach.mp.service; package com.seer.teach.mp.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.seer.teach.mp.entity.MpAgentEntity; import com.seer.teach.mp.entity.MpAgentEntity;
import com.seer.teach.common.utils.PageUtils;
import java.util.Map;
/** /**
* 代理商服务接口 * 代理商服务接口

View File

@ -3,14 +3,13 @@ package com.seer.teach.mp.service.impl;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.cache.MpAgentActivityCache;
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.exception.AgentActivityErrorCodeEnum;
import com.seer.teach.mp.mapper.MpAgentActivityMapper; import com.seer.teach.mp.mapper.MpAgentActivityMapper;
import com.seer.teach.mp.service.IMpAgentActivityLogService;
import com.seer.teach.mp.service.IMpActivityService; import com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentActivityLogService;
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 lombok.extern.slf4j.Slf4j;
@ -32,14 +31,10 @@ import java.time.LocalDateTime;
public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, MpActivityEntity> implements IMpActivityService { public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, MpActivityEntity> implements IMpActivityService {
private final IMpAgentActivityParticipantService agentActivityParticipantService; private final IMpAgentActivityParticipantService agentActivityParticipantService;
private final MpAgentActivityCache agentActivityCache;
private final IMpAgentActivityLogService agentActivityLogService; private final IMpAgentActivityLogService agentActivityLogService;
@Override @Override
public boolean saveOrUpdateActivity(MpActivityEntity entity) { public boolean saveOrUpdateActivity(MpActivityEntity entity) {
// 验证活动数据
validateActivity(entity);
MpActivityEntity oldEntity = null; MpActivityEntity oldEntity = null;
String operationType = "创建"; String operationType = "创建";
@ -65,7 +60,7 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
agentActivityLogService.logOperation( agentActivityLogService.logOperation(
entity.getId(), entity.getId(),
entity.getCreatorId(), entity.getCreateBy(),
operationType, operationType,
description, description,
beforeData, beforeData,
@ -76,31 +71,11 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
return result; return result;
} }
/**
* 验证活动数据
*/
private void validateActivity(MpActivityEntity entity) {
AssertUtils.notBlank(entity.getActivityName(), AgentActivityErrorCodeEnum.ACTIVITY_ALREADY_EXISTS, "活动名称不能为空");
AssertUtils.notNull(entity.getStartTime(), AgentActivityErrorCodeEnum.INVALID_ACTIVITY_STATUS, "活动开始时间不能为空");
AssertUtils.notNull(entity.getEndTime(), AgentActivityErrorCodeEnum.INVALID_ACTIVITY_STATUS, "活动结束时间不能为空");
// 检查开始时间不能晚于结束时间
if (entity.getStartTime().isAfter(entity.getEndTime())) {
throw new com.seer.teach.mp.exception.AgentActivityException(AgentActivityErrorCodeEnum.INVALID_ACTIVITY_STATUS, "活动开始时间不能晚于结束时间");
}
// 如果是更新操作检查活动是否存在
if (entity.getId() != null) {
MpActivityEntity existing = super.getById(entity.getId());
AssertUtils.notNull(existing, AgentActivityErrorCodeEnum.ACTIVITY_NOT_FOUND, "活动不存在");
}
}
@Override @Override
public boolean deleteActivity(Integer id) { public boolean deleteActivity(Integer id) {
// 检查活动是否存在 // 检查活动是否存在
MpActivityEntity existing = super.getById(id); MpActivityEntity existing = super.getById(id);
AssertUtils.notNull(existing, AgentActivityErrorCodeEnum.ACTIVITY_NOT_FOUND, "活动不存在"); AssertUtils.notNull(existing, ResultCodeEnum.ACTIVITY_NOT_ACTIVE);
// 删除活动前先删除相关的参与记录 // 删除活动前先删除相关的参与记录
LambdaQueryWrapper<MpAgentActivityParticipantEntity> participantWrapper = LambdaQueryWrapper<MpAgentActivityParticipantEntity> participantWrapper =
@ -108,9 +83,6 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
.eq(MpAgentActivityParticipantEntity::getActivityId, id); .eq(MpAgentActivityParticipantEntity::getActivityId, id);
agentActivityParticipantService.remove(participantWrapper); agentActivityParticipantService.remove(participantWrapper);
// 删除缓存
agentActivityCache.deleteActivityById(id);
boolean result = this.removeById(id); boolean result = this.removeById(id);
// 记录操作日志 // 记录操作日志
@ -121,7 +93,7 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
agentActivityLogService.logOperation( agentActivityLogService.logOperation(
id, id,
existing.getCreatorId(), existing.getCreateBy(),
"删除", "删除",
description, description,
beforeData, beforeData,
@ -132,31 +104,9 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
return result; return result;
} }
@Override
public MpActivityEntity getById(Integer id) {
// 先从缓存获取
MpActivityEntity cached = agentActivityCache.getActivityById(id);
if (cached != null) {
return cached;
}
// 从数据库获取
MpActivityEntity entity = super.getById(id);
if (entity != null) {
// 存入缓存
agentActivityCache.setActivityById(id, entity);
}
return entity;
}
@Override @Override
public boolean saveOrUpdate(MpActivityEntity entity) { public boolean saveOrUpdate(MpActivityEntity entity) {
boolean result = super.saveOrUpdate(entity); boolean result = super.saveOrUpdate(entity);
if (result && entity.getId() != null) {
// 更新缓存
agentActivityCache.setActivityById(entity.getId(), entity);
}
return result; return result;
} }
} }

View File

@ -22,7 +22,7 @@ import org.springframework.stereotype.Service;
public class MpAgentActivityLogServiceImpl extends ServiceImpl<MpAgentActivityLogMapper, MpAgentActivityLogEntity> implements IMpAgentActivityLogService { public class MpAgentActivityLogServiceImpl extends ServiceImpl<MpAgentActivityLogMapper, MpAgentActivityLogEntity> implements IMpAgentActivityLogService {
@Override @Override
public boolean logOperation(Integer activityId, Integer operatorId, String operationType, public boolean logOperation(Integer activityId, String operatorId, String operationType,
String description, String beforeData, String afterData) { String description, String beforeData, String afterData) {
try { try {
MpAgentActivityLogEntity logEntity = new MpAgentActivityLogEntity(); MpAgentActivityLogEntity logEntity = new MpAgentActivityLogEntity();