<?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.ai.da.mapper.primary.UserLikeGroupMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ai.da.mapper.primary.entity.UserLikeGroup">
        <id column="id" property="id" />
        <result column="account_id" property="accountId" />
        <result column="collection_id" property="collectionId" />
        <result column="name" property="name" />
        <result column="create_date" property="createDate" />
        <result column="update_date" property="updateDate" />
    </resultMap>

    <insert id="insertUserLikeGroup" parameterType="com.ai.da.mapper.primary.entity.UserLikeGroup" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
        insert into t_user_like_group
            (account_id,collection_id,`name`,create_date,update_date, original, project_id)
        values(
                  #{accountId},
                  #{collectionId},
                  #{name},
                  #{createDate},
                  #{updateDate},
                  #{original},
                  #{projectId});
    </insert>

    <select id="getMoreThan50UserLikeAccount" resultMap="BaseResultMap">
        SELECT d.account_id
        FROM t_design_item_detail d
                 JOIN t_user_like ul ON d.design_item_id = ul.design_item_id
                 JOIN t_user_like_group ulg ON ul.user_like_group_id = ulg.id
        WHERE ulg.account_id != -1
        GROUP BY d.account_id
        ORDER BY COUNT(*) DESC
        ;
    </select>
</mapper>
