<?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="org.springblade.finance.mapper.IntChannelSpidMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.springblade.finance.entity.IntChannelSpid">
        <id column="CHANNELID" property="channelid" />
        <result column="ACCOUNT_STARTDATE" property="accountStartdate" />
        <result column="ACCOUNT_ENDDATE" property="accountEnddate" />
        <result column="PROVINCES" property="provinces" />
        <result column="SPID" property="spid" />
        <result column="PRICE" property="price" />
        <result column="PARTNER_INCOME" property="partnerIncome" />
        <result column="MONTHS" property="months" />
        <result column="IS_VALID" property="isValid" />
        <result column="IS_ONCE" property="isOnce" />
        <result column="PROVINCE_MONEY" property="provinceMoney" />
        <result column="NEED_DISCOUNT" property="needDiscount" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CHANNELID, ACCOUNT_STARTDATE, ACCOUNT_ENDDATE, PROVINCES, SPID, PRICE, PARTNER_INCOME, MONTHS, IS_VALID, IS_ONCE, PROVINCE_MONEY, NEED_DISCOUNT
    </sql>


    <select id="getPageByQuery" resultType="org.springblade.finance.vo.ChannelSpidVO">
      SELECT
        CHANNELID as channelId,
        CHANNELNAME as channelName,
        COMPANY as company,
        ACCOUNT_STARTDATE as accountStartDate,
        ACCOUNT_ENDDATE as accountEndDate,
        PROVINCES as provinces,
        SPID as spid,
        SPNAME as spname,
        PRICE as price,
        PARTNER_INCOME as partnerIncome,
        MONTHS as months,
        IS_VALID as isValid,
        IS_ONCE as isOnce,
        PROVINCE_MONEY as provinceMoney,
        INPUTTER as inputter,
        INPUT_TIME as inputTime,
        CHECKER as checker,
        CHECK_TIME as checkTime,
        DEAL_ACCOUNT_ID as dealAccountId,
        DATA_STARTDATE,
        CHECK_STATUS AS checkStatus
      FROM
        INT_CHANNEL_SPID_TO_CHECK
      WHERE CHECK_STATUS != 1
        <if test="asList != null and asList != ''">
            AND DEAL_ACCOUNT_ID in
            <foreach collection="asList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
      UNION ALL
      SELECT
        CHANNELID as channelId,
        CHANNELNAME as channelName,
        COMPANY as company,
        ACCOUNT_STARTDATE as accountStartDate,
        ACCOUNT_ENDDATE as accountEndDate,
        PROVINCES as provinces,
        SPID as spid,
        SPNAME as spname,
        PRICE as price,
        PARTNER_INCOME as partnerIncome,
        MONTHS as months,
        IS_VALID as isValid,
        IS_ONCE as isOnce,
        PROVINCE_MONEY as provinceMoney,
        INPUTTER as inputter,
        INPUT_TIME as inputTime,
        CHECKER as checker,
        CHECK_TIME as checkTime,
        DEAL_ACCOUNT_ID as dealAccountId,
        DATA_STARTDATE,
        1 AS checkStatus
      FROM
        V_INT_CHANNEL_SPID
      WHERE 1=1
        <if test="asList != null and asList != ''">
            AND DEAL_ACCOUNT_ID in
            <foreach collection="asList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY inputTime DESC
    </select>

</mapper>
