VideoMapper.xml 6.72 KB
<?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.sincere.student.mapper.VideoMapper">

    <resultMap id="VideoMap" type="com.sincere.student.model.Video">
        <id column="id" property="id"/>
        <result column="university_id" property="universityId"/>
        <result column="column_type" property="columnType"/>
        <result column="video_url" property="videoUrl"/>
        <result column="sort" property="sort"/>
        <result column="create_time" property="createTime"/>
        <result column="name" property="name"/>
        <result column="code" property="code"/>
        <result column="status" property="status"/>
        <result column="logo_url" property="imgUrl"/>
        <result column="duration" property="duration"/>
        <result column="cover_url" property="coverUrl"/>
        <result column="video_name" property="videoName"/>
        <result column="read_number" property="readNumber"/>
        <result column="columnTypeString" property="columnTypeString"/>

    </resultMap>

    <update id="updateRead" parameterType="java.lang.Integer">
        update university_video set read_number = read_number + 1 where id= #{id}
    </update>

    <select id="getById" parameterType="java.lang.Integer" resultMap="VideoMap">
        select * from university_video where id = #{id}
    </select>

    <select id="countSort" resultMap="VideoMap">
        select * from university_video where
        <choose>
            <when test="flag ==1">
                sort >= #{sort}
            </when>
            <when test="flag ==2">
                sort >= #{sort} and id != #{id}
            </when>
        </choose>
        order by sort asc
    </select>

    <select id="getUniversityListCount" parameterType="com.sincere.student.dto.VideoSearchDto"
            resultType="java.lang.Integer">
        select count( distinct (v.university_id)) from university_video v join university_info info on v.university_id =
        info.id
        <where>
            <if test="columnType != 0">
                and v.column_type = #{columnType}
            </if>
            <if test="columnType == 0">
                and 1 = 1
            </if>
            <if test="universityId != 0">
                and info.id = #{universityId}
            </if>
            <if test="status == 1">
                and status = 1
            </if>
            <if test="status != 1">
                and 1 = 1
            </if>
        </where>
    </select>

    <select id="getUniversityList" parameterType="com.sincere.student.dto.VideoSearchDto" resultMap="VideoMap">
        select distinct v.university_id ,v.read_number, info.name,info.code ,info.logo_url from university_video v join
        university_info info on v.university_id = info.id
        <where>
            <if test="columnType != 0">
                and v.column_type = #{columnType}
            </if>
            <if test="universityId != 0">
                and info.id = #{universityId}
            </if>
            <if test="status == 1">
                and status = 1
            </if>
            <if test="status != 1">
                and 1 = 1
            </if>
        </where>
        order by v.sort
    </select>

    <select id="getListCount" parameterType="com.sincere.student.dto.VideoSearchDto" resultType="java.lang.Integer">
        select count(0) from university_video v join university_info info on v.university_id = info.id
        <where>
            <if test="columnType != 0">
                and v.column_type = #{columnType}
            </if>
            <if test="columnType == 0">
                and 1 = 1
            </if>
            <if test="universityName != null and universityName != ''">
                and info.name like #{universityName}
            </if>
            <if test="universityId != 0">
                and info.id = #{universityId}
            </if>
            <if test="status == 1">
                and status = 1
            </if>
            <if test="status != 1">
                and 1 = 1
            </if>
        </where>
    </select>

    <select id="getList" parameterType="com.sincere.student.dto.VideoSearchDto" resultMap="VideoMap">
        select v.*,info.name,info.code ,info.logo_url , university_column_type.name as columnTypeString from
        university_video v join university_info info on v.university_id = info.id
        left join university_column_type on v.column_type = university_column_type.id
        <where>
            <if test="columnType != 0">
                and v.column_type = #{columnType}
            </if>
            <if test="universityId != 0">
                and info.id = #{universityId}
            </if>
            <if test="universityName != null and universityName != ''">
                and info.name like #{universityName}
            </if>
            <if test="status == 1">
                and status = 1
            </if>
            <if test="status != 1">
                and 1 = 1
            </if>
        </where>
        order by v.sort
    </select>

    <insert id="create" parameterType="com.sincere.student.model.Video" useGeneratedKeys="true" keyProperty="id">
        insert into university_video
        (column_type,university_id,sort,video_url,create_time,status,duration,cover_url,video_name,read_number)
        values
        (#{columnType},#{universityId},#{sort},#{videoUrl},GETDATE(),#{status},#{duration},#{coverUrl},#{videoName},#{readNumber})
    </insert>

    <delete id="delete" parameterType="java.lang.Integer">
        delete university_video where id = #{id}
    </delete>

    <update id="update" parameterType="com.sincere.student.model.Video">
        update university_video
        <trim prefix="set" suffixOverrides=",">
            <if test="videoUrl!=null and videoUrl != ''">
                video_url=#{videoUrl},
            </if>
            <if test="videoName!=null and videoName != ''">
                video_name=#{videoName},
            </if>
            <if test="duration!=null and duration != ''">
                duration=#{duration},
            </if>
            <if test="coverUrl!=null and coverUrl != ''">
                cover_url=#{coverUrl},
            </if>
            <if test="columnType!=0">
                column_type=#{columnType},
            </if>
            <if test="universityId!=0">
                university_id=#{universityId},
            </if>
            <if test="sort!=0">
                sort=#{sort},
            </if>
            <if test="status!=-1">
                status=#{status},
            </if>
            <if test="readNumber!=-1">
                read_number=#{readNumber},
            </if>
        </trim>
        where id = #{id}
    </update>
</mapper>