|
|
|
|
@ -1,121 +1,144 @@
|
|
|
|
|
package com.rabbiter.association.service.impl;
|
|
|
|
|
|
|
|
|
|
// 导入MyBatis Plus的QueryWrapper,用于构建查询条件
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
// 导入MyBatis Plus的分页插件
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
// 导入服务接口
|
|
|
|
|
// 导入Spring的注解,用于声明服务和自动注入
|
|
|
|
|
import com.rabbiter.association.service.ApplyLogsService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
// 导入Spring的注解,用于声明事务
|
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
// 导入DAO接口
|
|
|
|
|
import com.rabbiter.association.dao.MembersDao;
|
|
|
|
|
import com.rabbiter.association.dao.TeamsDao;
|
|
|
|
|
import com.rabbiter.association.dao.ApplyLogsDao;
|
|
|
|
|
// 导入实体类
|
|
|
|
|
import com.rabbiter.association.entity.Members;
|
|
|
|
|
import com.rabbiter.association.entity.Teams;
|
|
|
|
|
import com.rabbiter.association.msg.PageData;
|
|
|
|
|
import com.rabbiter.association.entity.ApplyLogs;
|
|
|
|
|
import com.rabbiter.association.dao.ApplyLogsDao;
|
|
|
|
|
// 导入自定义的分页数据类
|
|
|
|
|
import com.rabbiter.association.msg.PageData;
|
|
|
|
|
// 导入工具类
|
|
|
|
|
import com.rabbiter.association.utils.DateUtils;
|
|
|
|
|
import com.rabbiter.association.utils.IDUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Service("applyLogsService")
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ApplyLogsService的服务实现类。
|
|
|
|
|
*/
|
|
|
|
|
@Service("applyLogsService") // 声明该类为applyLogsService的实现
|
|
|
|
|
public class ApplyLogsServiceImpl implements ApplyLogsService {
|
|
|
|
|
|
|
|
|
|
// 自动注入MembersDao
|
|
|
|
|
@Autowired
|
|
|
|
|
private MembersDao membersDao;
|
|
|
|
|
|
|
|
|
|
// 自动注入ApplyLogsDao
|
|
|
|
|
@Autowired
|
|
|
|
|
private ApplyLogsDao applyLogsDao;
|
|
|
|
|
|
|
|
|
|
// 自动注入TeamsDao
|
|
|
|
|
@Autowired
|
|
|
|
|
private TeamsDao teamsDao;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加申请记录。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
@Transactional // 声明事务,确保操作的原子性
|
|
|
|
|
public void add(ApplyLogs applyLogs) {
|
|
|
|
|
|
|
|
|
|
applyLogsDao.insert(applyLogs);
|
|
|
|
|
applyLogsDao.insert(applyLogs); // 插入申请记录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新申请记录。
|
|
|
|
|
* 如果申请通过,则创建成员记录并更新团队人数。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
@Transactional // 声明事务
|
|
|
|
|
public void update(ApplyLogs applyLogs) {
|
|
|
|
|
|
|
|
|
|
if(applyLogs.getStatus() != null && applyLogs.getStatus() == 1){
|
|
|
|
|
|
|
|
|
|
Members member = new Members();
|
|
|
|
|
member.setId(IDUtils.makeIDByCurrent());
|
|
|
|
|
member.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
member.setUserId(applyLogs.getUserId());
|
|
|
|
|
member.setTeamId(applyLogs.getTeamId());
|
|
|
|
|
|
|
|
|
|
membersDao.insert(member);
|
|
|
|
|
|
|
|
|
|
Teams teams = teamsDao.selectById(applyLogs.getTeamId());
|
|
|
|
|
teams.setTotal(teams.getTotal() + 1);
|
|
|
|
|
teamsDao.updateById(teams);
|
|
|
|
|
if(applyLogs.getStatus() != null && applyLogs.getStatus() == 1){ // 如果申请通过
|
|
|
|
|
Members member = new Members(); // 创建成员记录
|
|
|
|
|
member.setId(IDUtils.makeIDByCurrent()); // 生成成员ID
|
|
|
|
|
member.setCreateTime(DateUtils.getNowDate()); // 设置创建时间
|
|
|
|
|
member.setUserId(applyLogs.getUserId()); // 设置用户ID
|
|
|
|
|
member.setTeamId(applyLogs.getTeamId()); // 设置团队ID
|
|
|
|
|
|
|
|
|
|
membersDao.insert(member); // 插入成员记录
|
|
|
|
|
|
|
|
|
|
Teams teams = teamsDao.selectById(applyLogs.getTeamId()); // 根据ID查询团队
|
|
|
|
|
teams.setTotal(teams.getTotal() + 1); // 增加团队人数
|
|
|
|
|
teamsDao.updateById(teams); // 更新团队信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyLogsDao.updateById(applyLogs);
|
|
|
|
|
applyLogsDao.updateById(applyLogs); // 更新申请记录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除申请记录。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
@Transactional // 声明事务
|
|
|
|
|
public void delete(ApplyLogs applyLogs) {
|
|
|
|
|
|
|
|
|
|
applyLogsDao.deleteById(applyLogs);
|
|
|
|
|
applyLogsDao.deleteById(applyLogs); // 根据ID删除申请记录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查用户是否已对团队提交申请。
|
|
|
|
|
* 如果未提交申请返回true,否则返回false。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) // 声明只读事务
|
|
|
|
|
public Boolean isApply(String userId, String teamId){
|
|
|
|
|
QueryWrapper<ApplyLogs> qw = new QueryWrapper<>(); // 创建查询条件构造器
|
|
|
|
|
qw.eq("user_id", userId).eq("team_id", teamId).eq("status", 0); // 添加查询条件
|
|
|
|
|
|
|
|
|
|
QueryWrapper<ApplyLogs> qw = new QueryWrapper<ApplyLogs>();
|
|
|
|
|
qw.eq("user_id", userId);
|
|
|
|
|
qw.eq("team_id", teamId);
|
|
|
|
|
qw.eq("status", 0);
|
|
|
|
|
|
|
|
|
|
return applyLogsDao.selectCount(qw) <= 0;
|
|
|
|
|
return applyLogsDao.selectCount(qw) <= 0; // 查询符合条件的记录数,如果为0则未申请
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID获取单个申请记录。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) // 声明只读事务
|
|
|
|
|
public ApplyLogs getOne(String id) {
|
|
|
|
|
|
|
|
|
|
ApplyLogs applyLogs = applyLogsDao.selectById(id);
|
|
|
|
|
|
|
|
|
|
return applyLogs;
|
|
|
|
|
return applyLogsDao.selectById(id); // 根据ID查询申请记录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取管理员分页的申请记录信息。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) // 声明只读事务
|
|
|
|
|
public PageData getManPageInfo(Long pageIndex, Long pageSize, String userId, String teamName, String userName) {
|
|
|
|
|
Page<Map<String, Object>> page = applyLogsDao.qryManPageInfo(new Page<>(pageIndex, pageSize), userId, teamName, userName); // 分页查询
|
|
|
|
|
|
|
|
|
|
Page<Map<String, Object>> page =
|
|
|
|
|
applyLogsDao.qryManPageInfo(new Page<Map<String, Object>>(pageIndex, pageSize), userId, teamName, userName);
|
|
|
|
|
|
|
|
|
|
return parsePage(page);
|
|
|
|
|
return parsePage(page); // 转换分页结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取普通用户分页的申请记录信息。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
|
|
|
|
|
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) // 声明只读事务
|
|
|
|
|
public PageData getPageInfo(Long pageIndex, Long pageSize, String userId, String teamName, String userName) {
|
|
|
|
|
Page<Map<String, Object>> page = applyLogsDao.qryPageInfo(new Page<>(pageIndex, pageSize), userId, teamName, userName); // 分页查询
|
|
|
|
|
|
|
|
|
|
Page<Map<String, Object>> page =
|
|
|
|
|
applyLogsDao.qryPageInfo(new Page<Map<String, Object>>(pageIndex, pageSize), userId, teamName, userName);
|
|
|
|
|
|
|
|
|
|
return parsePage(page);
|
|
|
|
|
return parsePage(page); // 转换分页结果
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 转化分页查询的结果
|
|
|
|
|
* 将MyBatis Plus的分页结果转换为自定义的PageData对象。
|
|
|
|
|
*/
|
|
|
|
|
public PageData parsePage(Page<Map<String, Object>> p) {
|
|
|
|
|
PageData pageData = new PageData(p.getCurrent(), p.getSize(), p.getTotal(), p.getRecords()); // 创建PageData对象
|
|
|
|
|
|
|
|
|
|
PageData pageData = new PageData(p.getCurrent(), p.getSize(), p.getTotal(), p.getRecords());
|
|
|
|
|
|
|
|
|
|
return pageData;
|
|
|
|
|
return pageData; // 返回转换后的分页数据
|
|
|
|
|
}
|
|
|
|
|
}
|