<?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.yunfeiyun.agmp.pts.mapper.PtsTutorialMapper">
    
    <resultMap type="PtsTutorial" id="PtsTutorialResult">
        <result property="tutorialId"    column="tutorialId"    />
        <result property="tutorialTitle"    column="tutorialTitle"    />
        <result property="tutorialRemark"    column="tutorialRemark"    />
        <result property="tutorialCreatedate"    column="tutorialCreatedate"    />
        <result property="tutorialCreator"    column="tutorialCreator"    />
        <collection property="resList" column="tutorialId" javaType="java.util.ArrayList" ofType="SysRes" select="queryRes"/>
    </resultMap>

    <select id="queryRes" resultType="SysRes">
        select resId ,
        resBusId,
        resMediatype,
        resBiztype,
        resUrl as resLocalUrl,
        ${@com.yunfeiyun.agmp.common.constant.ResConstants$formType@QUERY.getValue()} as resFormtype,
        <choose>
            <when test="@com.yunfeiyun.agmp.common.framework.web.service.PolicyService@enabledOssCloudPolicy()==true">
                case when isNull(resOssUrl)  or resOssUrl = '' then resUrl else resOssUrl end as resUrl,
                case when !isNull(resOssUrl) and resOssUrl != '' then resOssUrl else resUrl end as resOssUrl,
            </when>
            <when test="@com.yunfeiyun.agmp.common.framework.web.service.PolicyService@enabledOssCloudPolicy()==false">
                resUrl, resUrl as resOssUrl,
            </when>
        </choose>
        resSeq,
        resCreateddate,
        resCreator
          from SysRes where resBusId = #{tutorialId}
    </select>

    <sql id="selectPtsTutorialVo">
        select tutorialId, tutorialTitle, tutorialRemark, tutorialCreatedate, tutorialCreator from PtsTutorial
    </sql>

    <select id="selectPtsTutorialList" parameterType="PtsTutorial" resultMap="PtsTutorialResult">
        <include refid="selectPtsTutorialVo"/>
        <where>  
            <if test="tutorialTitle != null  and tutorialTitle != ''"> and tutorialTitle = #{tutorialTitle}</if>
            <if test="tutorialRemark != null  and tutorialRemark != ''"> and tutorialRemark = #{tutorialRemark}</if>
            <if test="tutorialCreatedate != null  and tutorialCreatedate != ''"> and tutorialCreatedate = #{tutorialCreatedate}</if>
            <if test="tutorialCreator != null  and tutorialCreator != ''"> and tutorialCreator = #{tutorialCreator}</if>
        </where>
    </select>
    
    <select id="selectPtsTutorialByTutorialId" parameterType="PtsTutorial" resultMap="PtsTutorialResult">
        <include refid="selectPtsTutorialVo"/>
        where tutorialId = #{tutorialId}
    </select>
        
    <insert id="insertPtsTutorial" parameterType="PtsTutorial">
        insert into PtsTutorial
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tutorialId != null">tutorialId,</if>
            <if test="tutorialTitle != null">tutorialTitle,</if>
            <if test="tutorialRemark != null">tutorialRemark,</if>
            <if test="tutorialCreatedate != null">tutorialCreatedate,</if>
            <if test="tutorialCreator != null">tutorialCreator,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tutorialId != null">#{tutorialId},</if>
            <if test="tutorialTitle != null">#{tutorialTitle},</if>
            <if test="tutorialRemark != null">#{tutorialRemark},</if>
            <if test="tutorialCreatedate != null">#{tutorialCreatedate},</if>
            <if test="tutorialCreator != null">#{tutorialCreator},</if>
         </trim>
    </insert>

    <update id="updatePtsTutorial" parameterType="PtsTutorial">
        update PtsTutorial
        <trim prefix="SET" suffixOverrides=",">
            <if test="tutorialTitle != null">tutorialTitle = #{tutorialTitle},</if>
            <if test="tutorialRemark != null">tutorialRemark = #{tutorialRemark},</if>
            <if test="tutorialCreatedate != null">tutorialCreatedate = #{tutorialCreatedate},</if>
            <if test="tutorialCreator != null">tutorialCreator = #{tutorialCreator},</if>
        </trim>
        where tutorialId = #{tutorialId}
    </update>

    <delete id="deletePtsTutorialByTutorialId" parameterType="String">
        delete from PtsTutorial where tutorialId = #{tutorialId}
    </delete>

    <delete id="deletePtsTutorialByTutorialIds" parameterType="String">
        delete from PtsTutorial where tutorialId in 
        <foreach item="tutorialId" collection="array" open="(" separator="," close=")">
            #{tutorialId}
        </foreach>
    </delete>
</mapper>