| | |
| | | import com.example.jz.modle.entity.GroupUser; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 用户和群中间表(GroupUser)表数据库访问层 |
| | | * |
| | |
| | | @Mapper |
| | | public interface GroupUserDao extends BaseMapper<GroupUser> { |
| | | |
| | | List<Integer> selectUserList(Integer id); |
| | | } |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 报案表(Report)表服务实现类 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean audit(Report report) { |
| | | // 1. 更新报案表 |
| | | report.setStatus(1); |
| | |
| | | // 2. 更新群用户表 |
| | | Group group = groupDao.selectOne(new LambdaQueryWrapper<>(Group.class) |
| | | .eq(Group::getCauseId, report.getCauseId())); |
| | | GroupUser groupUser = new GroupUser().setGroupId(group.getId()).setUserId(report.getId()).setCtime(new Date()).setBanSpeech(0); |
| | | groupUserDao.insert(groupUser); |
| | | if (!groupUserDao.selectUserList(group.getId()).contains(report.getUserId())) { |
| | | GroupUser groupUser = new GroupUser().setGroupId(group.getId()).setUserId(report.getId()).setCtime(new Date()).setBanSpeech(0); |
| | | return groupUserDao.insert(groupUser) == 1 ? true : false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.example.jz.dao.GroupUserDao"> |
| | | |
| | | |
| | | |
| | | <select id="selectUserList" resultType="java.lang.Integer"> |
| | | SELECT |
| | | t2.user_id |
| | | FROM |
| | | `group_user` t1 |
| | | LEFT JOIN report t2 ON t1.user_id = t2.id |
| | | WHERE |
| | | t1.group_id = #{id} |
| | | </select> |
| | | |
| | | </mapper> |