<?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.platform.mapper.ImageVersionDao">

    <resultMap type="com.ruoyi.platform.domain.ImageVersion" id="ImageVersionMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="imageId" column="image_id" jdbcType="INTEGER"/>
        <result property="version" column="version" jdbcType="VARCHAR"/>
        <result property="url" column="url" jdbcType="VARCHAR"/>
        <result property="tagName" column="tag_name" jdbcType="VARCHAR"/>
        <result property="fileSize" column="file_size" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
    </resultMap>

    <!--根据模型id返回版本列表-->
    <select id="queryByImageId" resultMap="ImageVersionMap">
        select *
        from image_version
        where image_id = #{imageId} and state = 1
    </select>

    <!--查询单个-->
    <select id="queryById" resultMap="ImageVersionMap">
        select *
        from image_version
        where id = #{id} and state = 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="ImageVersionMap">
        select *
        from image_version
        <where>
            state = 1
            <if test="imageVersion.id != null">
                and id = #{imageVersion.id}
            </if>
            <if test="imageVersion.imageId != null">
                and image_id = #{imageVersion.imageId}
            </if>
            <if test="imageVersion.version != null and imageVersion.version != ''">
                and version = #{imageVersion.version}
            </if>
            <if test="imageVersion.url != null and imageVersion.url != ''">
                and url = #{imageVersion.url}
            </if>
            <if test="imageVersion.tagName != null and imageVersion.tagName != ''">
                and tag_name = #{imageVersion.tagName}
            </if>
            <if test="imageVersion.fileSize != null and imageVersion.fileSize != ''">
                and file_size = #{imageVersion.fileSize}
            </if>
            <if test="imageVersion.status != null and imageVersion.status != ''">
                and status = #{imageVersion.status}
            </if>
            <if test="imageVersion.createBy != null and imageVersion.createBy != ''">
                and create_by = #{imageVersion.createBy}
            </if>
            <if test="imageVersion.createTime != null">
                and create_time = #{imageVersion.createTime}
            </if>
            <if test="imageVersion.updateBy != null and imageVersion.updateBy != ''">
                and update_by = #{imageVersion.updateBy}
            </if>
            <if test="imageVersion.updateTime != null">
                and update_time = #{imageVersion.updateTime}
            </if>
            <if test="imageVersion.state != null">
                and state = #{imageVersion.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from image_version
        <where>
            state = 1
            <if test="imageVersion.id != null">
                and id = #{imageVersion.id}
            </if>
            <if test="imageVersion.imageId != null">
                and image_id = #{imageVersion.imageId}
            </if>
            <if test="imageVersion.version != null and imageVersion.version != ''">
                and version = #{imageVersion.version}
            </if>
            <if test="imageVersion.url != null and imageVersion.url != ''">
                and url = #{imageVersion.url}
            </if>
            <if test="imageVersion.tagName != null and imageVersion.tagName != ''">
                and tag_name = #{imageVersion.tagName}
            </if>
            <if test="imageVersion.fileSize != null and imageVersion.fileSize != ''">
                and file_size = #{imageVersion.fileSize}
            </if>
            <if test="imageVersion.status != null and imageVersion.status != ''">
                and status = #{imageVersion.status}
            </if>
            <if test="imageVersion.createBy != null and imageVersion.createBy != ''">
                and create_by = #{imageVersion.createBy}
            </if>
            <if test="imageVersion.createTime != null">
                and create_time = #{imageVersion.createTime}
            </if>
            <if test="imageVersion.updateBy != null and imageVersion.updateBy != ''">
                and update_by = #{imageVersion.updateBy}
            </if>
            <if test="imageVersion.updateTime != null">
                and update_time = #{imageVersion.updateTime}
            </if>
            <if test="imageVersion.state != null">
                and state = #{imageVersion.state}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into image_version(image_id, version, url, tag_name, file_size, status, create_by, create_time, update_by, update_time, state)
        values (#{imageVersion.imageId}, #{imageVersion.version}, #{imageVersion.url}, #{imageVersion.tagName}, #{imageVersion.fileSize}, #{imageVersion.status}, #{imageVersion.createBy}, #{imageVersion.createTime}, #{imageVersion.updateBy}, #{imageVersion.updateTime}, #{imageVersion.state})
    </insert>


    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into image_version(image_id,version,url,tag_name,file_size,status,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.imageId}#{entity.version}#{entity.url}#{entity.tagName}#{entity.fileSize}#{entity.status}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into image_version(image_id,version,url,tag_name,file_size,status,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.imageId}#{entity.version}#{entity.url}#{entity.tagName}#{entity.fileSize}#{entity.status}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
        on duplicate key update
image_id = values(image_id)version = values(version)url = values(url)tag_name = values(tag_name)file_size = values(file_size)status = values(status)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update image_version
        <set>
            <if test="imageVersion.imageId != null">
                image_id = #{imageVersion.imageId},
            </if>
            <if test="imageVersion.version != null and imageVersion.version != ''">
                version = #{imageVersion.version},
            </if>
            <if test="imageVersion.url != null and imageVersion.url != ''">
                url = #{imageVersion.url},
            </if>
            <if test="imageVersion.tagName != null and imageVersion.tagName != ''">
                tag_name = #{imageVersion.tagName},
            </if>
            <if test="imageVersion.fileSize != null and imageVersion.fileSize != ''">
                file_size = #{imageVersion.fileSize},
            </if>
            <if test="imageVersion.status != null and imageVersion.status != ''">
                status = #{imageVersion.status},
            </if>
            <if test="imageVersion.createBy != null and imageVersion.createBy != ''">
                create_by = #{imageVersion.createBy},
            </if>
            <if test="imageVersion.createTime != null">
                create_time = #{imageVersion.createTime},
            </if>
            <if test="imageVersion.updateBy != null and imageVersion.updateBy != ''">
                update_by = #{imageVersion.updateBy},
            </if>
            <if test="imageVersion.updateTime != null">
                update_time = #{imageVersion.updateTime},
            </if>
            <if test="imageVersion.state != null">
                state = #{imageVersion.state},
            </if>
        </set>
        where id = #{imageVersion.id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from image_version where id = #{id}
    </delete>

</mapper>

