<?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.ruoyi.system.mapper.CjStudentMapper">
|
|
<resultMap type="CjStudent" id="CjStudentResult">
|
<result property="studentId" column="student_id" />
|
<result property="classId" column="class_id" />
|
<result property="studentNo" column="student_no" />
|
<result property="name" column="name" />
|
<result property="gender" column="gender" />
|
<result property="phone" column="phone" />
|
<result property="status" column="status" />
|
<result property="delFlag" column="del_flag" />
|
<result property="createBy" column="create_by" />
|
<result property="createTime" column="create_time" />
|
<result property="updateBy" column="update_by" />
|
<result property="updateTime" column="update_time" />
|
<result property="remark" column="remark" />
|
<result property="pwdResetFlag" column="pwd_reset_flag" />
|
<result property="registerTime" column="register_time" />
|
<result property="loginDate" column="login_date" />
|
<result property="activated" column="activated" />
|
</resultMap>
|
|
<!-- 注意:不查询 password 列(登录校验走 selectPasswordByStudentId);activated 由 password 是否为空派生 -->
|
<sql id="selectCjStudentVo">
|
select student_id, class_id, student_no, name, gender, phone, status, del_flag, create_by, create_time, update_by, update_time, remark,
|
pwd_reset_flag, register_time, login_date,
|
case when password is null or password = '' then '0' else '1' end as activated
|
from cj_student
|
</sql>
|
|
<select id="selectCjStudentList" parameterType="CjStudent" resultMap="CjStudentResult">
|
<include refid="selectCjStudentVo"/>
|
<where>
|
<if test="classId != null "> and class_id = #{classId}</if>
|
<if test="classIds != null and classIds.size() > 0"> and class_id in
|
<foreach collection="classIds" item="cid" open="(" separator="," close=")">#{cid}</foreach>
|
</if>
|
<!-- 按专业整查:cj_student->cj_class.major_id -->
|
<if test="majorId != null">
|
and exists (select 1 from cj_class _cl where _cl.class_id = cj_student.class_id and _cl.major_id = #{majorId})
|
</if>
|
<!-- 按学院整查:cj_student->cj_class.major_id->cj_major.college_id(cj_class 无 college_id 列) -->
|
<if test="collegeId != null">
|
and exists (select 1 from cj_class _cl join cj_major _m on _m.major_id = _cl.major_id where _cl.class_id = cj_student.class_id and _m.college_id = #{collegeId})
|
</if>
|
<if test="studentNo != null and studentNo != ''"> and student_no = #{studentNo}</if>
|
<!-- 搜索框走模糊匹配(支持学号局部);判重/精确查找仍用 studentNo -->
|
<if test="studentNoLike != null and studentNoLike != ''"> and student_no like concat('%', #{studentNoLike}, '%')</if>
|
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
<if test="gender != null and gender != ''"> and gender = #{gender}</if>
|
<if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
|
<if test="status != null and status != ''"> and status = #{status}</if>
|
<!-- 账号状态筛选:0未激活 1正常 2待改密(V2:扫班级码注册建档) -->
|
<if test="accountState != null and accountState == '0'.toString()"> and (password is null or password = '')</if>
|
<if test="accountState != null and accountState == '1'.toString()"> and password is not null and password != '' and (pwd_reset_flag is null or pwd_reset_flag != '1')</if>
|
<if test="accountState != null and accountState == '2'.toString()"> and password is not null and password != '' and pwd_reset_flag = '1'</if>
|
<!-- 旧参数:仅按是否激活过滤(保留兼容) -->
|
<if test="activated != null and activated != ''"> and (case when password is null or password = '' then '0' else '1' end) = #{activated}</if>
|
</where>
|
</select>
|
|
<select id="selectCjStudentByStudentId" parameterType="Long" resultMap="CjStudentResult">
|
<include refid="selectCjStudentVo"/>
|
where student_id = #{studentId}
|
</select>
|
|
<insert id="insertCjStudent" parameterType="CjStudent" useGeneratedKeys="true" keyProperty="studentId">
|
insert into cj_student
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="classId != null">class_id,</if>
|
<if test="studentNo != null and studentNo != ''">student_no,</if>
|
<if test="name != null and name != ''">name,</if>
|
<if test="gender != null">gender,</if>
|
<if test="phone != null">phone,</if>
|
<if test="status != null">status,</if>
|
<if test="delFlag != null">del_flag,</if>
|
<if test="createBy != null">create_by,</if>
|
<if test="createTime != null">create_time,</if>
|
<if test="updateBy != null">update_by,</if>
|
<if test="updateTime != null">update_time,</if>
|
<if test="remark != null">remark,</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<if test="classId != null">#{classId},</if>
|
<if test="studentNo != null and studentNo != ''">#{studentNo},</if>
|
<if test="name != null and name != ''">#{name},</if>
|
<if test="gender != null">#{gender},</if>
|
<if test="phone != null">#{phone},</if>
|
<if test="status != null">#{status},</if>
|
<if test="delFlag != null">#{delFlag},</if>
|
<if test="createBy != null">#{createBy},</if>
|
<if test="createTime != null">#{createTime},</if>
|
<if test="updateBy != null">#{updateBy},</if>
|
<if test="updateTime != null">#{updateTime},</if>
|
<if test="remark != null">#{remark},</if>
|
</trim>
|
</insert>
|
|
<update id="updateCjStudent" parameterType="CjStudent">
|
update cj_student
|
<trim prefix="SET" suffixOverrides=",">
|
<if test="classId != null">class_id = #{classId},</if>
|
<if test="studentNo != null and studentNo != ''">student_no = #{studentNo},</if>
|
<if test="name != null and name != ''">name = #{name},</if>
|
<if test="gender != null">gender = #{gender},</if>
|
<if test="phone != null">phone = #{phone},</if>
|
<if test="status != null">status = #{status},</if>
|
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
<if test="createBy != null">create_by = #{createBy},</if>
|
<if test="createTime != null">create_time = #{createTime},</if>
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
<if test="remark != null">remark = #{remark},</if>
|
</trim>
|
where student_id = #{studentId}
|
</update>
|
|
<delete id="deleteCjStudentByStudentId" parameterType="Long">
|
delete from cj_student where student_id = #{studentId}
|
</delete>
|
|
<delete id="deleteCjStudentByStudentIds" parameterType="String">
|
delete from cj_student where student_id in
|
<foreach item="studentId" collection="array" open="(" separator="," close=")">
|
#{studentId}
|
</foreach>
|
</delete>
|
|
<select id="countByClassIds" resultType="int">
|
select count(1) from cj_student where class_id in
|
<foreach item="classId" collection="array" open="(" separator="," close=")">
|
#{classId}
|
</foreach>
|
</select>
|
|
<select id="selectPasswordByStudentId" parameterType="Long" resultType="String">
|
select password from cj_student where student_id = #{studentId} and del_flag = '0'
|
</select>
|
|
<update id="updateStudentPassword">
|
update cj_student
|
set password = #{password},
|
pwd_reset_flag = #{pwdResetFlag},
|
<if test="registerTime != null">register_time = #{registerTime},</if>
|
update_time = now()
|
where student_id = #{studentId} and del_flag = '0'
|
</update>
|
|
<update id="updateStudentLoginDate">
|
update cj_student set login_date = #{loginDate} where student_id = #{studentId}
|
</update>
|
|
<!-- 工作台:按班级统计在册/已激活学生数;classIds 空=全校。activated = 密码已设(扫班码注册建档) -->
|
<select id="classStudentStats" resultType="java.util.Map">
|
select class_id, count(*) as total,
|
sum(case when password is not null and password != '' then 1 else 0 end) as activated
|
from cj_student
|
where del_flag = '0' and status = '0'
|
<if test="classIds != null and classIds.length > 0">
|
and class_id in
|
<foreach item="cid" collection="classIds" open="(" separator="," close=")">#{cid}</foreach>
|
</if>
|
group by class_id
|
</select>
|
|
<!-- 工作台:全校按学院聚合班级数/学生数/已激活数(cj_class 无 college_id,经 cj_major 回溯) -->
|
<select id="collegeStudentStats" resultType="java.util.Map">
|
select co.college_id, co.college_name,
|
count(distinct cl.class_id) as class_count,
|
count(s.student_id) as student_count,
|
sum(case when s.password is not null and s.password != '' then 1 else 0 end) as activated_count
|
from cj_college co
|
join cj_major m on m.college_id = co.college_id and m.del_flag = '0'
|
join cj_class cl on cl.major_id = m.major_id and cl.del_flag = '0'
|
left join cj_student s on s.class_id = cl.class_id and s.del_flag = '0' and s.status = '0'
|
where co.del_flag = '0'
|
group by co.college_id, co.college_name
|
order by co.college_id
|
</select>
|
</mapper>
|