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

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

@ -20,8 +20,9 @@ public class PageConverterUtils {
* IPage<GoodsEntity> iPage = goodsService.queryPageList(size, current, goods);
* PageListBean<GoodsResp> result = PageConverterUtils.convertPageListBean(iPage, GoodConverter.INSTANCE::list);
* </code>
*
* <p>
* 通用分页对象转换方法
*
* @param sourcePage MyBatis Plus 分页对象
* @param converter 数据转换函数 ( GoodConverter.INSTANCE::list)
* @param <T> 源数据类型
@ -36,8 +37,37 @@ public class PageConverterUtils {
}
// 应用转换函数
result.setList(converter.apply(sourcePage.getRecords()));
result.setPageSize((int) sourcePage.getSize());
result.setTotalPage((int) sourcePage.getPages());
result.setPageSize(sourcePage.getSize());
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());
return result;
}

View File

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

View File

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

View File

@ -1,5 +1,6 @@
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.extension.plugins.pagination.Page;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@ -32,7 +34,10 @@ public class AdminAgentService {
Page<MpAgentEntity> pageParam = new Page<>(pageReq.getPageNo(), pageReq.getPageSize());
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);
}

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.extension.plugins.pagination.Page;
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.resp.AdminAgentActivityLogResp;
import com.seer.teach.mp.admin.service.IAdminAgentActivityLogService;
@ -59,12 +60,7 @@ public class AdminAgentActivityLogServiceImpl implements IAdminAgentActivityLogS
IPage<MpAgentActivityLogEntity> result = mpAgentActivityLogService.page(page, wrapper);
// 转换为响应对象
List<AdminAgentActivityLogResp> records = result.getRecords().stream()
.map(this::convertToResp)
.toList();
return new PageListBean<>(result.getTotal(), records);
return PageConverterUtils.convertPageList(result, this::convertToResp);
}
@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.service.IAdminAgentActivityParticipantService;
import com.seer.teach.mp.entity.MpAgentActivityParticipantEntity;
import com.seer.teach.mp.mapper.MpAgentActivityParticipantMapper;
import com.seer.teach.mp.service.IMpAgentActivityParticipantService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/**
* <p>
@ -57,8 +53,7 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
// 检查是否已存在相同的活动代理商和家长记录
LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, entity.getActivityId())
.eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId())
.eq(MpAgentActivityParticipantEntity::getParentId, entity.getParentId());
.eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId());
long count = mpAgentActivityParticipantService.count(wrapper);
if (count > 0) {
@ -74,7 +69,6 @@ public class AdminAgentActivityParticipantServiceImpl implements IAdminAgentActi
LambdaQueryWrapper<MpAgentActivityParticipantEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MpAgentActivityParticipantEntity::getActivityId, entity.getActivityId())
.eq(MpAgentActivityParticipantEntity::getAgentId, entity.getAgentId())
.eq(MpAgentActivityParticipantEntity::getParentId, entity.getParentId())
.ne(MpAgentActivityParticipantEntity::getId, entity.getId());
long count = mpAgentActivityParticipantService.count(wrapper);

View File

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

View File

@ -1,11 +1,7 @@
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.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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.mp.cache.MpAgentActivityCache;
import com.seer.teach.mp.entity.MpActivityEntity;
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.service.IMpAgentActivityLogService;
import com.seer.teach.mp.service.IMpActivityService;
import com.seer.teach.mp.service.IMpAgentActivityLogService;
import com.seer.teach.mp.service.IMpAgentActivityParticipantService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -32,14 +31,10 @@ import java.time.LocalDateTime;
public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, MpActivityEntity> implements IMpActivityService {
private final IMpAgentActivityParticipantService agentActivityParticipantService;
private final MpAgentActivityCache agentActivityCache;
private final IMpAgentActivityLogService agentActivityLogService;
@Override
public boolean saveOrUpdateActivity(MpActivityEntity entity) {
// 验证活动数据
validateActivity(entity);
MpActivityEntity oldEntity = null;
String operationType = "创建";
@ -65,7 +60,7 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
agentActivityLogService.logOperation(
entity.getId(),
entity.getCreatorId(),
entity.getCreateBy(),
operationType,
description,
beforeData,
@ -76,31 +71,11 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
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
public boolean deleteActivity(Integer id) {
// 检查活动是否存在
MpActivityEntity existing = super.getById(id);
AssertUtils.notNull(existing, AgentActivityErrorCodeEnum.ACTIVITY_NOT_FOUND, "活动不存在");
AssertUtils.notNull(existing, ResultCodeEnum.ACTIVITY_NOT_ACTIVE);
// 删除活动前先删除相关的参与记录
LambdaQueryWrapper<MpAgentActivityParticipantEntity> participantWrapper =
@ -108,9 +83,6 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
.eq(MpAgentActivityParticipantEntity::getActivityId, id);
agentActivityParticipantService.remove(participantWrapper);
// 删除缓存
agentActivityCache.deleteActivityById(id);
boolean result = this.removeById(id);
// 记录操作日志
@ -121,7 +93,7 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
agentActivityLogService.logOperation(
id,
existing.getCreatorId(),
existing.getCreateBy(),
"删除",
description,
beforeData,
@ -132,31 +104,9 @@ public class MpActivityServiceImpl extends ServiceImpl<MpAgentActivityMapper, Mp
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
public boolean saveOrUpdate(MpActivityEntity entity) {
boolean result = super.saveOrUpdate(entity);
if (result && entity.getId() != null) {
// 更新缓存
agentActivityCache.setActivityById(entity.getId(), entity);
}
return result;
}
}

View File

@ -22,7 +22,7 @@ import org.springframework.stereotype.Service;
public class MpAgentActivityLogServiceImpl extends ServiceImpl<MpAgentActivityLogMapper, MpAgentActivityLogEntity> implements IMpAgentActivityLogService {
@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) {
try {
MpAgentActivityLogEntity logEntity = new MpAgentActivityLogEntity();