<?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="cn.pluss.platform.mapper.MakeMoneyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.MakeMoney">
        <id column="id" property="id"/>
        <result column="billId" property="billId"/>
        <result column="createTime" property="createTime"/>
        <result column="merchantId" property="merchantId"/>
        <result column="planAmount" property="planAmount"/>
        <result column="suspendAmount" property="suspendAmount"/>
        <result column="realAmount" property="realAmount"/>
        <result column="state" property="state"/>
        <result column="failReason" property="failReason"/>
        <result column="remark" property="remark"/>
        <result column="recreateFlag" property="recreateFlag"/>
        <result column="settType" property="settType"/>
        <result column="settDate" property="settDate"/>
        <result column="tag" property="tag"/>
        <result column="bankretTime" property="bankretTime"/>
        <result column="bankAccount" property="bankAccount"/>
        <result column="bankHolder" property="bankHolder"/>
        <result column="readStatus" property="readStatus"/>
    </resultMap>

    <select id="selectPage" resultMap="BaseResultMap">
        SELECT mm.id,
               mm.billId,
               mm.createTime,
               mm.merchantId,
               mm.planAmount,
               mm.suspendAmount,
               mm.realAmount,
               mm.state,
               mm.failReason,
               mm.remark,
               mm.recreateFlag,
               mm.settType,
               mm.settDate,
               mm.tag,
               DATE_FORMAT(mm.bankretTime, '%Y-%m-%d %H:%i:%s') bankretTime,
               mm.bankAccount,
               mm.bankHolder,
               IF(nrr.id IS NULL, 0, 1) readStatus
        FROM tb_pluss_make_money mm
                 LEFT JOIN tb_pluss_notice_read_record nrr
                           ON mm.id = nrr.noticeId AND nrr.type = 1 ${ew.customSqlSegment}
    </select>

    <select id="getCountNowDateSettleAmt" parameterType="java.lang.String" resultType="java.math.BigDecimal">
        SELECT IFNULL(sum(planAmount), 0)
        FROM tb_pluss_make_money
        where merchantId = #{merchantId}
          and `state` in (0, 1)
          AND DATE_FORMAT(createTime, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
    </select>
</mapper>
