package com.tofly.xrtygis.custom.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.xrtygis.custom.entity.message.SendMessage;
import com.tofly.xrtygis.entity.vo.UserWaterMeterInfoVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * @author 20126
 */
public interface SendMessageMapper {
    /**
     * 判断当前消息内容是否包含特殊字符
     * @param msg
     * @return
     */
    @Select("select count(1) from SMS_IMPRESSIONSTR@YXDBLINK t where t.value like '%' || #{msg} || '%'")
    Integer checkSpecialCharacters(@Param("msg") String msg);

    /**
     * 插入消息
     * @param sendMessage
     * @return
     */
    @Insert({"insert into SMS_MESSAGE@YXDBLINK(id,yhbh,yhxm,yhdz,lsh,lxdh, txlx,txnr,scsj,fszt,s_lock) values(#{id}, #{yhbh},#{yhxm},#{yhdz},#{lsh},#{lxdh}, #{txlx}, #{txnr}, #{scsj}, #{fszt}, #{sLock})"})
    Integer saveMessage(SendMessage sendMessage);


    @Select("SELECT count(1) allNum ,nvl(SUM ( CASE WHEN fszt = '2' THEN 1 ELSE 0 END ),0) faildNum " +
            "FROM SMS_MESSAGE@YXDBLINK " +
            "WHERE txlx = '4'")
    Map<String,Long> getNoteNum();
    /**
     * 查询消息列表
     * @param page
     * @param state
     * @param inputContent
     * @param start
     * @param end
     * @return
     */
    @Select({"<script>","SELECT lsh,yhbh,yhxm,yhdz,lxdh,txlx,txnr,scsj,fszt " +
            "FROM SMS_MESSAGE@YXDBLINK " +
            "WHERE txlx = '4' " +
            "<if test='state != null and state.trim() != \"\" '> " +
            "  and  fszt = #{state} " +
            "</if> "+
            "<if test='start != null and end != null'> " +
            "   and scsj between #{start} and #{end} " +
            "</if>" +
            "<if test='inputContent != null and inputContent.trim() != \"\" '> " +
            "  and  txnr like '%' || #{inputContent} || '%' " +
            "</if> " ,
            "</script>"})
    Page<SendMessage> getMessagePage(Page page, @Param("state") String state, @Param("inputContent")String inputContent, @Param("start")Date start,@Param("end")Date end);

    /**
     * 根据用户编号列表 查询营销用户列表信息
     * @param yhbhs
     * @return
     */
    @Select({"<script>",
            "select YHBH     userCode, " +
            "YHXM     userName, " +
            "YHDZ     userAddress, " +
            "LXDH     contactNumber " +
            "FROM yh_khjbxx@YXDBLINK " +
            "where 1=1" +
            "<if test='yhbhs != null and yhbhs != \"\" '> " +
                    "and YHBH in " +
            "  <foreach item=\"nodeCodestr\" collection=\"yhbhs.split(',')\" open=\"(\" separator=\",\" close=\")\">\n" +
            "                #{nodeCodestr}\n" +
            "  </foreach>"+
            " </if> ",
            "</script>"})
    List<UserWaterMeterInfoVo> getYxUserList(@Param("yhbhs") String yhbhs);
}
