<?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.PtsLinkMapper">
    
    <resultMap type="PtsLink" id="PtsLinkResult">
        <result property="linkId"    column="linkId"    />
        <result property="linkName"    column="linkName"    />
        <result property="linkSeq"    column="linkSeq"    />
        <result property="linkPath"    column="linkPath"    />
        <result property="linkQuery"    column="linkQuery"    />
        <result property="linkOpentype"    column="linkOpentype"    />
        <result property="linkVisiblestatus"    column="linkVisiblestatus"    />
        <result property="linkType"    column="linkType"    />
        <result property="linkIcon"    column="linkIcon"    />
        <result property="linkCreator"    column="linkCreator"    />
        <result property="linkCreateddate"    column="linkCreateddate"    />
        <result property="linkModifier"    column="linkModifier"    />
        <result property="linkModifieddate"    column="linkModifieddate"    />
        <result property="linkRemark"    column="linkRemark"    />
        <collection property="resList" column="linkId" 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 = #{linkId}
    </select>

    <sql id="selectPtsLinkVo">
        select linkId, linkName, linkSeq, linkPath, linkQuery, linkOpentype, linkVisiblestatus, linkType, linkIcon, linkCreator, linkCreateddate, linkModifier, linkModifieddate, linkRemark from PtsLink
    </sql>

    <select id="selectPtsLinkList" parameterType="PtsLink" resultMap="PtsLinkResult">
        <include refid="selectPtsLinkVo"/>
        <where>
            <if test="linkName != null  and linkName != ''"> and linkName like concat('%', #{linkName}, '%')</if>
            <if test="linkSeq != null "> and linkSeq = #{linkSeq}</if>
            <if test="linkPath != null  and linkPath != ''"> and linkPath = #{linkPath}</if>
            <if test="linkQuery != null  and linkQuery != ''"> and linkQuery = #{linkQuery}</if>
            <if test="linkOpentype != null  and linkOpentype != ''"> and linkOpentype = #{linkOpentype}</if>
            <if test="linkVisiblestatus != null  and linkVisiblestatus != ''"> and linkVisiblestatus = #{linkVisiblestatus}</if>
            <if test="linkType != null  and linkType != ''"> and linkType = #{linkType}</if>
            <if test="linkIcon != null  and linkIcon != ''"> and linkIcon = #{linkIcon}</if>
            <if test="linkCreator != null  and linkCreator != ''"> and linkCreator = #{linkCreator}</if>
            <if test="linkCreateddate != null  and linkCreateddate != ''"> and linkCreateddate = #{linkCreateddate}</if>
            <if test="linkModifier != null  and linkModifier != ''"> and linkModifier = #{linkModifier}</if>
            <if test="linkModifieddate != null  and linkModifieddate != ''"> and linkModifieddate = #{linkModifieddate}</if>
            <if test="linkRemark != null  and linkRemark != ''"> and linkRemark = #{linkRemark}</if>
        </where>
        ORDER BY  linkSeq  ASC

    </select>
    
    <select id="selectPtsLinkByLinkId" parameterType="String" resultMap="PtsLinkResult">
        <include refid="selectPtsLinkVo"/>
        where linkId = #{linkId}
    </select>
        
    <insert id="insertPtsLink" parameterType="PtsLink">
        insert into PtsLink
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="linkId != null">linkId,</if>
            <if test="linkName != null">linkName,</if>
            <if test="linkSeq != null">linkSeq,</if>
            <if test="linkPath != null">linkPath,</if>
            <if test="linkQuery != null">linkQuery,</if>
            <if test="linkOpentype != null">linkOpentype,</if>
            <if test="linkVisiblestatus != null">linkVisiblestatus,</if>
            <if test="linkType != null">linkType,</if>
            <if test="linkIcon != null">linkIcon,</if>
            <if test="linkCreator != null">linkCreator,</if>
            <if test="linkCreateddate != null">linkCreateddate,</if>
            <if test="linkModifier != null">linkModifier,</if>
            <if test="linkModifieddate != null">linkModifieddate,</if>
            <if test="linkRemark != null">linkRemark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="linkId != null">#{linkId},</if>
            <if test="linkName != null">#{linkName},</if>
            <if test="linkSeq != null">#{linkSeq},</if>
            <if test="linkPath != null">#{linkPath},</if>
            <if test="linkQuery != null">#{linkQuery},</if>
            <if test="linkOpentype != null">#{linkOpentype},</if>
            <if test="linkVisiblestatus != null">#{linkVisiblestatus},</if>
            <if test="linkType != null">#{linkType},</if>
            <if test="linkIcon != null">#{linkIcon},</if>
            <if test="linkCreator != null">#{linkCreator},</if>
            <if test="linkCreateddate != null">#{linkCreateddate},</if>
            <if test="linkModifier != null">#{linkModifier},</if>
            <if test="linkModifieddate != null">#{linkModifieddate},</if>
            <if test="linkRemark != null">#{linkRemark},</if>
         </trim>
    </insert>

    <update id="updatePtsLink" parameterType="PtsLink">
        update PtsLink
        <trim prefix="SET" suffixOverrides=",">
            <if test="linkName != null">linkName = #{linkName},</if>
            <if test="linkSeq != null">linkSeq = #{linkSeq},</if>
            <if test="linkPath != null">linkPath = #{linkPath},</if>
            <if test="linkQuery != null">linkQuery = #{linkQuery},</if>
            <if test="linkOpentype != null">linkOpentype = #{linkOpentype},</if>
            <if test="linkVisiblestatus != null">linkVisiblestatus = #{linkVisiblestatus},</if>
            <if test="linkType != null">linkType = #{linkType},</if>
            <if test="linkIcon != null">linkIcon = #{linkIcon},</if>
            <if test="linkCreator != null">linkCreator = #{linkCreator},</if>
            <if test="linkCreateddate != null">linkCreateddate = #{linkCreateddate},</if>
            <if test="linkModifier != null">linkModifier = #{linkModifier},</if>
            <if test="linkModifieddate != null">linkModifieddate = #{linkModifieddate},</if>
            <if test="linkRemark != null">linkRemark = #{linkRemark},</if>
        </trim>
        where linkId = #{linkId}
    </update>

    <delete id="deletePtsLinkByLinkId" parameterType="String">
        delete from PtsLink where linkId = #{linkId}
    </delete>

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