<?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.mcwl.resource.mapper.ModelImageMapper">
    <update id="setModelImageTop">
        UPDATE model_image
        SET is_top = #{isTop}
        WHERE id = #{id}
    </update>
    <update id="fetchModelImageSortedByTopStatus">
        SELECT is_top
        FROM model_image
        ORDER BY is_top DESC;
    </update>

    <select id="sumLikeNumber" resultType="java.lang.Long">
        SELECT sum(like_num) sum
        FROM model_image
        where user_id = #{userId}
        ORDER BY(user_id);
    </select>

    <select id="imageList" resultType="com.mcwl.resource.domain.response.ResponseModelImage">
        SELECT id,m.user_id,image_paths,like_num,nick_name,avatar
        FROM model_image as m
        LEFT JOIN sys_user as u
        on m.user_id = u.user_id
        WHERE m.del_flag = '0'
        <if test="name != null and name != ''">
            and m.title like CONCAT('%', #{name}, '%')
        </if>
        <if test="type != null and type != ''">
            and m.tags like CONCAT('%', #{type}, '%')
        </if>
    </select>

    <select id="sumImageNumber" resultType="java.lang.Long">
        SELECT count(*)
        FROM model_image
        where user_id = #{userId}
          and del_flag = 0
          and status in (1, 2)
    </select>

</mapper>
