<?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.project.system.mapper.ByTeacherJbxxMapper">
    
    <resultMap type="ByTeacherJbxx" id="ByTeacherJbxxResult">
        <result property="id"    column="id"    />
        <result property="userid"    column="userid"    />
        <result property="zjhm"    column="zjhm"    />
        <result property="csrq"    column="csrq"    />
        <result property="byyx"    column="byyx"    />
        <result property="zy"    column="zy"    />
        <result property="xl"    column="xl"    />
        <result property="xw"    column="xw"    />
        <result property="cjgzrq"    column="cjgzrq"    />
        <result property="zgzs"    column="zgzs"    />
        <result property="createuserid"    column="createuserid"    />
        <result property="createtime"    column="createtime"    />
        <association property="user"    column="user_id" javaType="SysUser" resultMap="SysUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="SysUserResult">
        <id     property="userId"       column="user_id"      />
        <result property="deptId"       column="dept_id"      />
        <result property="userName"     column="user_name"    />
        <result property="nickName"     column="nick_name"    />
        <result property="email"        column="email"        />
        <result property="phonenumber"  column="phonenumber"  />
        <result property="sex"          column="sex"          />
        <result property="avatar"       column="avatar"       />
        <result property="password"     column="password"     />
        <result property="status"       column="status"       />
        <result property="delFlag"      column="del_flag"     />
        <result property="loginIp"      column="login_ip"     />
        <result property="loginDate"    column="login_date"   />
        <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"       />
    </resultMap>

    <sql id="selectByTeacherJbxxVo">
        select t.id, t.userid, t.zjhm, t.csrq, t.byyx, t.zy, t.xl, t.xw, t.cjgzrq, t.zgzs, t.createuserid, t.createtime,
        u.user_id, u.nick_name, u.status as user_status
        from by_teacher_jbxx t
            right join sys_user u on t.userid = u.user_id
    </sql>

    <select id="selectByTeacherJbxxList" parameterType="ByTeacherJbxx" resultMap="ByTeacherJbxxResult">
        select t.id, t.userid, t.zjhm, t.csrq, t.byyx, t.zy, t.xl, t.xw, t.cjgzrq, t.zgzs, t.createuserid, t.createtime,
        u.user_id, u.nick_name,u.dept_id,u.del_flag
        from by_teacher_jbxx t
        left join sys_user u on t.userid = u.user_id
        where u.del_flag='0'
        <if test="userid != null "> and userid = #{userid}</if>
        <if test="zjhm != null  and zjhm != ''"> and zjhm = #{zjhm}</if>
        <if test="csrq != null "> and csrq = #{csrq}</if>
        <if test="byyx != null  and byyx != ''"> and byyx = #{byyx}</if>
        <if test="zy != null  and zy != ''"> and zy = #{zy}</if>
        <if test="xl != null  and xl != ''"> and xl = #{xl}</if>
        <if test="xw != null  and xw != ''"> and xw = #{xw}</if>
        <if test="cjgzrq != null "> and cjgzrq = #{cjgzrq}</if>
        <if test="zgzs != null  and zgzs != ''"> and zgzs = #{zgzs}</if>
        <if test="createuserid != null "> and createuserid = #{createuserid}</if>
        <if test="createtime != null "> and createtime = #{createtime}</if>

        <!-- 数据范围过滤 -->
        ${dataScope}
    </select>

    <select id="selectByTeacherJbGroupXw" parameterType="ByTeacherJbxx" resultMap="ByTeacherJbxxResult">
        select (CASE WHEN (select dict_label from sys_dict_data where dict_type='sys_jsxl' and dict_value=t.xl ) is null THEN '未设置' ELSE (select dict_label from sys_dict_data where dict_type='sys_jsxl' and dict_value=t.xl ) END )xl,count(*) byyx
        from by_teacher_jbxx t
        left join sys_user u on t.userid = u.user_id
        where u.del_flag='0'

        <!-- 数据范围过滤 -->
        ${dataScope}

        group by t.xl
    </select>
    
    <select id="selectByTeacherJbxxById" parameterType="Long" resultMap="ByTeacherJbxxResult">
        <include refid="selectByTeacherJbxxVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertByTeacherJbxx" parameterType="ByTeacherJbxx" useGeneratedKeys="true" keyProperty="id">
        insert into by_teacher_jbxx
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userid != null ">userid,</if>
            <if test="zjhm != null  and zjhm != ''">zjhm,</if>
            <if test="csrq != null ">csrq,</if>
            <if test="byyx != null  and byyx != ''">byyx,</if>
            <if test="zy != null  and zy != ''">zy,</if>
            <if test="xl != null  and xl != ''">xl,</if>
            <if test="xw != null  and xw != ''">xw,</if>
            <if test="cjgzrq != null ">cjgzrq,</if>
            <if test="zgzs != null  and zgzs != ''">zgzs,</if>
            <if test="createuserid != null ">createuserid,</if>
            <if test="createtime != null ">createtime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userid != null ">#{userid},</if>
            <if test="zjhm != null  and zjhm != ''">#{zjhm},</if>
            <if test="csrq != null ">#{csrq},</if>
            <if test="byyx != null  and byyx != ''">#{byyx},</if>
            <if test="zy != null  and zy != ''">#{zy},</if>
            <if test="xl != null  and xl != ''">#{xl},</if>
            <if test="xw != null  and xw != ''">#{xw},</if>
            <if test="cjgzrq != null ">#{cjgzrq},</if>
            <if test="zgzs != null  and zgzs != ''">#{zgzs},</if>
            <if test="createuserid != null ">#{createuserid},</if>
            <if test="createtime != null ">#{createtime},</if>
         </trim>
    </insert>

    <update id="updateByTeacherJbxx" parameterType="ByTeacherJbxx">
        update by_teacher_jbxx
        <trim prefix="SET" suffixOverrides=",">
            <if test="userid != null ">userid = #{userid},</if>
            <if test="zjhm != null  and zjhm != ''">zjhm = #{zjhm},</if>
            <if test="csrq != null ">csrq = #{csrq},</if>
            <if test="byyx != null  and byyx != ''">byyx = #{byyx},</if>
            <if test="zy != null  and zy != ''">zy = #{zy},</if>
            <if test="xl != null  and xl != ''">xl = #{xl},</if>
            <if test="xw != null  and xw != ''">xw = #{xw},</if>
            <if test="cjgzrq != null ">cjgzrq = #{cjgzrq},</if>
            <if test="zgzs != null  and zgzs != ''">zgzs = #{zgzs},</if>
            <if test="createuserid != null ">createuserid = #{createuserid},</if>
            <if test="createtime != null ">createtime = #{createtime},</if>
        </trim>
        where id = #{id}
    </update>



    <update id="deleteByTeacherJbxxById" parameterType="Long">
        update by_teacher_jbxx
        set zjhm=null, csrq=null, byyx=null, zy=null, xl=null, xw=null, cjgzrq=null, zgzs=null, createuserid=null
        where id = #{id}
    </update>

    <update id="deleteByTeacherJbxxByIds" parameterType="String">
        update by_teacher_jbxx
        set zjhm=null, csrq=null, byyx=null, zy=null, xl=null, xw=null, cjgzrq=null, zgzs=null, createuserid=null
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>