<?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="im.zhaojun.zfile.module.link.mapper.ShortLinkMapper">
    <resultMap id="BaseResultMap" type="im.zhaojun.zfile.module.link.model.entity.ShortLink">
        <!--@mbg.generated-->
        <!--@Table short_link-->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="short_key" jdbcType="VARCHAR" property="shortKey"/>
        <result column="url" jdbcType="LONGVARCHAR" property="url"/>
        <result column="create_date" jdbcType="DATE" property="createDate"/>
        <result column="storage_id" jdbcType="INTEGER" property="storageId"/>
        <result column="expire_date" jdbcType="DATE" property="expireDate"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id, short_key, url, create_date, storage_id, expire_date
    </sql>

    <update id="updateUrlStorageId">
        update short_link set url = replace(url, #{updateSubPath}, #{newSubPath})
    </update>

<!--auto generated by MybatisCodeHelper on 2021-07-15-->
    <select id="findByKey" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from short_link
        where `short_key`=#{key,jdbcType=VARCHAR}
    </select>

<!--auto generated by MybatisCodeHelper on 2021-07-15-->
    <select id="findByStorageIdAndUrl" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from short_link
        where url=#{url,jdbcType=LONGVARCHAR} and storage_id=#{storageId,jdbcType=INTEGER} limit 1
    </select>

    <delete id="deleteByStorageId">
        delete from short_link where storage_id = #{storageId}
    </delete>

</mapper>