<?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.ichangzuo.system.mapper.StyleMapper">
    <!-- 提现分页列表 -->
    <select id="statRecommand" resultType="com.ichangzuo.system.model.bo.StyleRecomStatBO">
        SELECT
            timesignature,
            count(*) count
        FROM
            mc_accompany_recommand
        LEFT JOIN mc_accompany ON StyleID=accompany_id
        GROUP BY timesignature
    </select>
    <select id="countTemp" resultType="Integer">
        SELECT
            count(*)
        FROM
            mc_accompany_temp
        WHERE
            state=0
    </select>

    <select id="pageStyle_COUNT" resultType="java.lang.Long">
<!--        SELECT COUNT(*) FROM mc_accompany_recommand-->
        SELECT COUNT(*)
        FROM mc_accompany
        LEFT JOIN mc_accompany_recommand ON StyleID=accompany_id
        <where>
            <if test="queryParams.state!=null">
                <choose>
                    <when test="queryParams.state == 0">
                        AND Valid = 1
                    </when>
                    <otherwise>
                        AND state = #{queryParams.state}
                    </otherwise>
                </choose>
            </if>
            <if test="queryParams.ts != null">
                AND timesignature = #{queryParams.ts}
            </if>
            <if test="queryParams.author != null">
                AND author = #{queryParams.author}
            </if>
        </where>
    </select>

    <select id="pageStyle" resultType="com.ichangzuo.system.model.entity.Style">
        SELECT
            accompany_id,
            cost,
            score,
            IF(Valid,0,state) state,
            name,
            description,
            author,
            author_name,
            timesignature,
            tempo,
            change_time,
            score_time,
            use_count,
            sell_count
        FROM
            mc_accompany
        LEFT JOIN mc_accompany_recommand ON StyleID=accompany_id
        <where>
            <if test="queryParams.state!=null">
                <choose>
                    <when test="queryParams.state == 0">
                        AND Valid = 1
                    </when>
                    <otherwise>
                        AND state = #{queryParams.state}
                    </otherwise>
                </choose>
            </if>
            <if test="queryParams.ts != null">
                AND timesignature = #{queryParams.ts}
            </if>
            <if test="queryParams.author != null">
                AND author = #{queryParams.author}
            </if>
        </where>
        ORDER BY accompany_id DESC
    </select>
</mapper>