xiangpei
2024-05-09 cfc61445380851d621f4dd853fe62941f9c80207
部门管理员优化
11个文件已修改
496 ■■■■■ 已修改文件
src/main/java/com/mindskip/xzs/domain/Department.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/User.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/UserDepartment.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/UpdateDeptAdminVO.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/UserMapper.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/DepartmentServiceImpl.java 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/viewmodel/admin/department/DepartmentResponseVM.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DepartmentMapper.xml 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ExamTemplatesUserCountMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UserMapper.xml 362 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/Department.java
@@ -4,6 +4,7 @@
import javax.sql.rowset.serial.SerialArray;
import java.io.Serializable;
import java.util.List;
@Data
public class Department implements Serializable {
@@ -15,7 +16,7 @@
    /**
     * 部门管理员
     */
    private Integer adminId;
    private List<Integer> adminId;
    private String deleted;
src/main/java/com/mindskip/xzs/domain/User.java
@@ -65,7 +65,7 @@
    private Date lastActiveTime;
    /**
     * 是否删除
     * 是否删除:0未删除  1删除
     */
    private Boolean deleted;
src/main/java/com/mindskip/xzs/domain/UserDepartment.java
@@ -11,5 +11,8 @@
    private Integer userId;
    private Integer departmentId;
    /**
     * 是否部门管理员
     */
    private String deptAdmin;
}
src/main/java/com/mindskip/xzs/domain/vo/UpdateDeptAdminVO.java
@@ -3,7 +3,9 @@
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
 * 修改部门管理员
@@ -23,7 +25,7 @@
    /**
     * 管理员,userId
     */
    @NotNull(message = "部门管理员不能为空")
    private Integer adminId;
    @NotEmpty(message = "部门管理员不能为空")
    private List<Integer> adminIds;
}
src/main/java/com/mindskip/xzs/repository/UserMapper.java
@@ -141,13 +141,21 @@
    /**
     * 修改部门管理员标识
     * @param id
     * @param ids
     * @param deptAdmin
     */
    void updateDeptAdmin(Integer id, String deptAdmin);
    void updateDeptAdmin(@Param("ids") List<Integer> ids, @Param("deptAdmin") String deptAdmin, @Param("deptId") Integer deptId);
    List<ExamPaperAnswer> getUserByDept(@Param("query") ExamPaperGradeQuery query);
    void setStatus(UserVO user);
    /**
     * 清除某部门的用户管理员标识
     *
     * @param userIds
     * @param deptId
     */
    void clearDeptAdmin(List<Integer> userIds, @Param("deptId") Integer deptId);
}
src/main/java/com/mindskip/xzs/service/impl/DepartmentServiceImpl.java
@@ -18,9 +18,11 @@
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService {
@@ -62,17 +64,15 @@
        if (Objects.isNull(entity)) {
            throw new RuntimeException("该部门不存在");
        }
        if (Objects.nonNull(department.getAdminId())) {
            Integer adminNum = departmentMapper.countByAdminId(department.getAdminId(), department.getId());
            if (adminNum > 0) {
                throw new RuntimeException("一个用户只能是一个单位的管理员");
            }
            if (! Objects.equals(entity.getAdminId(), department.getAdminId())) {
                // 取消原先的管理员标识
                userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue());
        if (! CollectionUtils.isEmpty(department.getAdminId())) {
            List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId());
            List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList());
            if (! CollectionUtils.isEmpty(userIds)) {
                // 先清除之前的管理员标识
                userMapper.clearDeptAdmin(userIds, entity.getId());
            }
            // 标识部门管理员
            userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue());
            userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue(), entity.getId());
        }
        Integer update = departmentMapper.update(department);
        return update;
@@ -114,24 +114,21 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAdmin(UpdateDeptAdminVO form) {
        Department entity = departmentMapper.getById(form.getId());
        if (Objects.isNull(form)) {
        if (Objects.isNull(entity)) {
            throw new RuntimeException("该部门不存在");
        }
        if (Objects.nonNull(form.getAdminId())) {
            Integer adminNum = departmentMapper.countByAdminId(form.getAdminId(), form.getId());
            if (adminNum > 0) {
                throw new RuntimeException("一个用户只能是一个单位的管理员");
            }
            if (! Objects.equals(entity.getAdminId(), form.getAdminId())) {
                // 取消原先的管理员标识
                userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue());
        if (! CollectionUtils.isEmpty(form.getAdminIds())) {
            List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId());
            List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList());
            if (! CollectionUtils.isEmpty(userIds)) {
                // 先清除之前的管理员标识
                userMapper.clearDeptAdmin(userIds, entity.getId());
            }
            // 标识部门管理员
            userMapper.updateDeptAdmin(form.getAdminId(), DeptAdminEnum.YES.getValue());
            userMapper.updateDeptAdmin(form.getAdminIds(), DeptAdminEnum.YES.getValue(), entity.getId());
        }
        entity.setAdminId(form.getAdminId());
        departmentMapper.update(entity);
    }
}
src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
@@ -519,14 +519,14 @@
            Map<Integer, Integer> multiple = new HashMap<>();
            //多选
            Map<Integer, Integer> multipleMap = list.stream()
                    .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.MultipleChoice.getCode()))
                    .filter(e -> Objects.equals(QuestionTypeEnum.MultipleChoice.getCode(), e.getQuestionType()))
                    .collect(Collectors.toMap(Question::getId, Question::getScore));
            Integer multipleSource = questionTypeVM.getMultipleChoice() * 2;
            selectRandomScores(multiple, multipleMap, questionTypeVM.getMultipleChoice(), multipleSource);
            //判断
            List<Question> collect1 = list.stream().filter(e -> e.getQuestionType().equals(QuestionTypeEnum.TrueFalse.getCode())).collect(Collectors.toList());
            List<Question> collect1 = list.stream().filter(e -> Objects.equals(e.getQuestionType(), QuestionTypeEnum.TrueFalse.getCode())).collect(Collectors.toList());
            Map<Integer, Integer> judgmentMap = collect1.stream().collect(Collectors.toMap(Question::getId, Question::getScore));
            Integer trueFalse1 = questionTypeVM.getTrueFalse();
            Integer trueFalse = trueFalse1 * 2;
@@ -536,7 +536,7 @@
            Integer radioSource = questionTypeVM.getSingleChoice() * 4;
            //单选
            Map<Integer, Integer> radioMap = list.stream()
                    .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.SingleChoice.getCode()))
                    .filter(e -> Objects.equals(e.getQuestionType(), QuestionTypeEnum.SingleChoice.getCode()))
                    .collect(Collectors.toMap(Question::getId, Question::getScore));
            selectRandomScores(multiple, radioMap, questionTypeVM.getSingleChoice(), radioSource);
src/main/java/com/mindskip/xzs/viewmodel/admin/department/DepartmentResponseVM.java
@@ -3,6 +3,8 @@
import com.mindskip.xzs.base.BasePage;
import lombok.Data;
import java.util.List;
@Data
public class DepartmentResponseVM extends BasePage {
@@ -14,7 +16,7 @@
    /**
     * 管理员
     */
    private Integer adminId;
    private String adminName;
    private List<Integer> adminIds;
    private List<String> adminNames;
}
src/main/resources/mapper/DepartmentMapper.xml
@@ -36,12 +36,9 @@
    <select id="gets" resultMap="BaseResultMap">
        SELECT
            td.id,
            td.name,
            td.admin_id as adminId,
            tu.real_name as adminName
            td.name
        FROM
            t_department td
                LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0
        WHERE
            td.deleted = 0
            <if test="deptId != null">
@@ -52,26 +49,43 @@
    <select id="getById" resultMap="BaseResultMap">
        SELECT
            td.id,
            td.name,
            td.admin_id as adminId,
            tu.real_name as adminName
            td.name
        FROM
            t_department td
                LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0
        WHERE
              td.id = #{id} AND td.deleted = 0
    </select>
    <select id="page" resultType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM"
    <resultMap id="pageResult" type="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <collection column="id" property="adminIds" ofType="integer" select="selectUserIdsByDeptId"></collection>
        <collection column="id" property="adminNames" ofType="integer" select="selectUserNamesByDeptId"></collection>
    </resultMap>
    <select id="selectUserIdsByDeptId" resultType="integer">
        SELECT
               tu.id
        FROM
             t_user_department tud
                 INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1
    </select>
    <select id="selectUserNamesByDeptId" resultType="string">
        SELECT
            tu.real_name
        FROM
            t_user_department tud
                INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1
    </select>
    <select id="page" resultMap="pageResult"
            parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM">
        SELECT
            td.id,
            td.name,
            td.admin_id as adminId,
            tu.real_name as adminName
            td.name
        FROM
             t_department td
                 LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0
        <where>
            AND td.deleted = 0
            <if test="id != null ">
src/main/resources/mapper/ExamTemplatesUserCountMapper.xml
@@ -19,15 +19,18 @@
    </insert>
    <select id="list" resultType="com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO" parameterType="com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM">
        SELECT u.exam_templates_id as id, count(*) as count, u.user_id as userId FROM `t_exam_templates_user_count` u
        left join t_exam_templates e on u.exam_templates_id = e.id
        SELECT
               e.id as id,
               count(u.user_id) as count,
               u.user_id as userId
        FROM
            t_exam_templates e
                left join `t_exam_templates_user_count` u on u.exam_templates_id = e.id <if test="userId != null">and u.user_id = #{userId}</if>
        <where>
                <if test="templatesId != null">
                    and u.exam_templates_id = #{templatesId}
                </if>
                <if test="userId != null">
                    and u.user_id = #{userId}
                </if>
                <if test="status != null">
                    and e.status = 0
                </if>
@@ -93,4 +96,4 @@
        where c.templates_id = #{id}
    </select>
</mapper>
</mapper>
src/main/resources/mapper/UserMapper.xml
@@ -250,18 +250,19 @@
  </update>
    <select id="getAllUser" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user where deleted=0
    </select>
  <select id="getAllUser" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_user where deleted=0
  </select>
  <select id="getUserByLevel" resultMap="BaseResultMap">
    select
    id,real_name
    from t_user where deleted=0 and user_level = #{userLevel}
  </select>
    <select id="getUserByLevel" resultMap="BaseResultMap">
        select id,
               real_name
        from t_user
        where deleted = 0
          and user_level = #{userLevel}
    </select>
  <select id="getUserById" resultMap="BaseResultMap">
    select
@@ -270,178 +271,191 @@
    where id=#{value} and status = 1 and deleted = 0
  </select>
  <select id="getUserByUserName" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_user
    where deleted=0  and user_name=#{value} limit 1
  </select>
    <select id="getUserByUserName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_name=#{value} limit 1
    </select>
  <select id="getUserByRealName" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_user
    where deleted=0  and real_name = #{realName}
  </select>
    <select id="getUserByRealName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and real_name = #{realName}
    </select>
  <select id="getUserByUserNamePwd" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_user
    where deleted=0  and user_name=#{username} and password=#{pwd} limit 1
  </select>
    <select id="getUserByUserNamePwd" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_name=#{username} and password=#{pwd} limit 1
    </select>
  <select id="getUserByUuid" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_user
    where deleted=0  and user_uuid=#{value,jdbcType=VARCHAR}
  </select>
    <select id="getUserByUuid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_uuid=#{value,jdbcType=VARCHAR}
    </select>
  <select id="userPageList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM t_user
    <where>
        and deleted=0
      <if test="name != null and name != ''">
        and  real_name like concat('%',#{name},'%')
      </if>
    </where>
    ORDER BY id
    <if test="offset != null and limit != null ">
      <bind name="patternAdd" value="limit*offset"/>
      limit #{limit} OFFSET #{offset}
    </if>
  </select>
    <select id="userPageList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_user
        <where>
            and deleted=0
            <if test="name != null and name != ''">
                and real_name like concat('%',#{name},'%')
            </if>
        </where>
        ORDER BY id
        <if test="offset != null and limit != null ">
            <bind name="patternAdd" value="limit*offset"/>
            limit #{limit} OFFSET #{offset}
        </if>
    </select>
  <select id="userPageCount" resultType="java.lang.Integer">
    select count(*) from t_user
    <where>
        and deleted=0
      <if test="name != null and name != ''">
        and real_name like concat('%', #{name}, '%')
      </if>
    </where>
  </select>
    <select id="userPageCount" resultType="java.lang.Integer">
        select count(*) from t_user
        <where>
            and deleted=0
            <if test="name != null and name != ''">
                and real_name like concat('%', #{name}, '%')
            </if>
        </where>
    </select>
  <select id="userPage" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.viewmodel.admin.user.UserPageRequestVM">
    SELECT
    <include refid="Base_Column_List"/>
    FROM t_user
    <where>
        and deleted=0
      <if test="userName != null and userName != ''">
        and real_name like concat('%',#{userName},'%')
      </if>
      <if test="role != null ">
        and role= #{role}
      </if>
    </where>
  </select>
    <select id="userPage" resultMap="BaseResultMap"
            parameterType="com.mindskip.xzs.viewmodel.admin.user.UserPageRequestVM">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_user
        <where>
            and deleted=0
            <if test="userName != null and userName != ''">
                and real_name like concat('%',#{userName},'%')
            </if>
            <if test="role != null ">
                and role= #{role}
            </if>
        </where>
    </select>
    <insert id="insertUser" parameterType="com.mindskip.xzs.domain.User"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_user
            (user_uuid, user_name, password, real_name, age, last_active_time)
        values (#{userUuid,jdbcType=VARCHAR}, #{userName}, #{password}, #{realName}, #{age}, #{lastActiveTime})
    </insert>
  <insert id="insertUser" parameterType="com.mindskip.xzs.domain.User"
          useGeneratedKeys="true" keyProperty="id">
        insert into t_user
        (user_uuid,user_name,password,real_name,age, last_active_time)
        values
        (#{userUuid,jdbcType=VARCHAR},#{userName},#{password},#{realName},#{age},#{lastActiveTime})
    </insert>
  <insert id="insertUsers" parameterType="java.util.List"
          useGeneratedKeys="true" keyProperty="id">
    insert into t_user
    (user_uuid,user_name,password,real_name,last_active_time,role,status,user_level,deleted)
    values
    <foreach collection="list" item="item"
             separator=",">
      (#{item.userUuid,jdbcType=VARCHAR},#{item.userName,jdbcType=VARCHAR},#{item.password,jdbcType=VARCHAR},#{item.realName,jdbcType=VARCHAR},
      #{item.lastActiveTime},#{item.role},#{item.status},#{item.userLevel},0)
    </foreach>
  </insert>
    <insert id="insertUsers" parameterType="java.util.List"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_user
        (user_uuid,user_name,password,real_name,last_active_time,role,status,user_level,deleted)
        values
        <foreach collection="list" item="item"
                 separator=",">
            (#{item.userUuid,jdbcType=VARCHAR},#{item.userName,jdbcType=VARCHAR},#{item.password,jdbcType=VARCHAR},#{item.realName,jdbcType=VARCHAR},
            #{item.lastActiveTime},#{item.role},#{item.status},#{item.userLevel},0)
        </foreach>
    </insert>
  <update id="updateUser" parameterType="com.mindskip.xzs.domain.User">
    update t_user
    <set>
      <if test="realName != null">real_name = #{realName},</if>
      <if test="age != null">age = #{age},</if>
      <if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
    </set>
    where id = #{id}
  </update>
    <update id="updateUser" parameterType="com.mindskip.xzs.domain.User">
        update t_user
        <set>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="age != null">age = #{age},</if>
            <if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
        </set>
        where id = #{id}
    </update>
  <update id="updateUsersAge">
    update t_user set age = #{age} where id in
    <foreach item="id" collection="idslist" open="(" separator=","
             close=")">
      #{id}
    </foreach>
  </update>
    <update id="updateUsersAge">
        update t_user set age = #{age} where id in
        <foreach item="id" collection="idslist" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </update>
  <delete id="deleteUsersByIds">
    delete from t_user where id in
    <foreach item="id" collection="list" open="(" separator=","
             close=")">
      #{id}
    </foreach>
  </delete>
    <delete id="deleteUsersByIds">
        delete from t_user where id in
        <foreach item="id" collection="list" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </delete>
  <select id="selectAllCount"  resultType="java.lang.Integer">
        SELECT count(*) from t_user where deleted=0
  </select>
    <select id="selectAllCount" resultType="java.lang.Integer">
        SELECT count(*)
        from t_user
        where deleted = 0
    </select>
  <select id="selectByUserName"  resultType="com.mindskip.xzs.domain.other.KeyValue">
        SELECT  id as value,user_name as name
        from t_user
        where deleted=0  and user_name like concat('%',#{value},'%')
        limit 5
  </select>
    <select id="selectByUserName" resultType="com.mindskip.xzs.domain.other.KeyValue">
        SELECT id as value,user_name as name
        from t_user
        where deleted=0
          and user_name like concat('%'
            , #{value}
            , '%')
            limit 5
    </select>
  <select id="selectByIds" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
     from t_user
     where id in
    <foreach item="id" collection="list" open="(" separator=","
             close=")">
      #{id}
    </foreach>
  </select>
    <select id="selectByIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where id in
        <foreach item="id" collection="list" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </select>
  <select id="selectByWxOpenId" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    where deleted=0  and  wx_open_id = #{wxOpenId}
    limit 1
  </select>
    <select id="selectByWxOpenId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and wx_open_id = #{wxOpenId}
        limit 1
    </select>
  <select id="selectByIdName" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    <where>
      and deleted=0  and  id = #{id}
      <if test="userName != null and userName != ''">
        and user_name like concat('%',#{userName},"%")
      </if>
    </where>
  </select>
    <select id="selectByIdName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        <where>
            and deleted=0 and id = #{id}
            <if test="userName != null and userName != ''">
                and user_name like concat('%',#{userName},"%")
            </if>
        </where>
    </select>
  <update id="updateDeptAdmin">
    UPDATE t_user SET dept_admin = #{deptAdmin} WHERE id = #{id} AND deleted = 0
    UPDATE t_user_department SET dept_admin = #{deptAdmin}
    <where>
      <if test="ids != null and ids.size > 0">
        AND user_id in
        <foreach collection="ids" open="(" separator="," close=")" item="id">
          #{id}
        </foreach>
      </if>
      AND department_id = #{deptId}
    </where>
  </update>
  <update id="setStatus">
@@ -452,24 +466,32 @@
    AND deleted = 0
  </update>
  <select id="getUserByDept" resultType="com.mindskip.xzs.domain.ExamPaperAnswer">
    SELECT
    <update id="clearDeptAdmin">
        update
            t_user_department set dept_admin = 0
        WHERE
              user_id IN <foreach collection="userIds" open="(" separator="," close=")" item="id">#{id}</foreach>
          AND dept_admin = 1 AND department_id = #{deptId}
    </update>
    <select id="getUserByDept" resultType="com.mindskip.xzs.domain.ExamPaperAnswer">
        SELECT
        tu.id as createUser, tu.real_name as userName, count(tepa.id) as counts
    FROM
         t_user tu INNER JOIN t_user_department tud ON tu.id = tud.user_id AND tu.deleted = 0
                   LEFT JOIN t_exam_paper_answer tepa ON tepa.create_user = tu.id
    <where>
      <if test="query.deptId != null">
        AND tud.department_id = #{query.deptId}
      </if>
      <if test="query.start != null and query.end != null">
        AND tepa.create_time between #{query.start} and #{query.end}
      </if>
    </where>
    group by
        FROM
        t_user tu INNER JOIN t_user_department tud ON tu.id = tud.user_id AND tu.deleted = 0
        LEFT JOIN t_exam_paper_answer tepa ON tepa.create_user = tu.id
        <where>
            <if test="query.deptId != null">
                AND tud.department_id = #{query.deptId}
            </if>
            <if test="query.start != null and query.end != null">
                AND tepa.create_time between #{query.start} and #{query.end}
            </if>
        </where>
        group by
        createUser, userName
    ORDER BY
        ORDER BY
        tu.id desc
  </select>
    </select>
</mapper>