<?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.m2pool.pool.mapper.NoticeMapper">
    <insert id="addNoticeEmail">
        insert into notice_info(
            ma_id,
            email,
            <if test="vo.remark != null and vo.remark != ''">remark,</if>
            create_time
        ) values(
            #{vo.maId},
            #{vo.email},
            <if test="vo.remark != null and vo.remark != ''">#{vo.remark},</if>
            sysdate()
        )
    </insert>

    <update id="updateInfo">
        update notice_info
        set
            remark = #{vo.remark}
        where id = #{vo.id}
    </update>

    <delete id="deleteNoticeInfoById">
        delete from notice_info where id=#{vo.id} and ma_id=#{maId}
    </delete>


    <select id="getNoticeEmailListByMaId" resultType="com.m2pool.pool.dto.NoticeListDto">
        select
            n.id,
            n.email,
            n.remark
        from
            notice_info n
            left join user_miner_account u on n.ma_id = u.id
        where
            u.user=#{user}
            and n.ma_id=#{vo.maId}
    </select>

    <select id="checkIdAndMa" resultType="java.lang.Boolean">
        select
            count(*)
        from
            notice_info n
            left join user_miner_account u on n.ma_id = u.id
        where
            u.user=#{user}
            and n.id=#{id}
    </select>

    <select id="getMaIdByIdAndUser" resultType="java.lang.Long">
        select
            n.ma_id
        from
            notice_info n
            left join user_miner_account u on n.ma_id = u.id
        where
            u.user=#{user}
            and n.id=#{id}
    </select>

    <select id="getNoticeEmailCountByMaId" resultType="java.lang.Integer">
        select count(*) from notice_info where ma_id=#{maId}
    </select>

    <select id="checkEmailIfExist" resultType="java.lang.Boolean">
         select
            count(*)
        from
            notice_info
        where
            ma_id=#{maId}
            and email=#{email}
    </select>
    <select id="getNoticeEmailListByMinerAndCoin" resultType="com.m2pool.pool.dto.NoticeMinerCoinListDto">
        select
            n.email email,
            u.id as maId,
            u.miner_user miner
        from
            notice_info n
            left join user_miner_account u on n.ma_id=u.id
        where
            u.miner_user in
            <foreach collection="list" index="index" open="(" separator="," close=")" item="miner">
                #{miner.user}
            </foreach>
            and coin=#{coin}
    </select>


</mapper>


