<?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.axzo.msg.center.dal.mapper.MNSBatchMessageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.axzo.msg.center.domain.entity.MNSBatchMessage">
        <id column="id" property="id" />
        <result column="request_no" property="requestNo" />
        <result column="batch_no" property="batchNo" />
        <result column="app_no" property="appNo" />
        <result column="template_no" property="templateNo" />
        <result column="channel_template_no" property="channelTemplateNo" />
        <result column="message_order_no" property="messageOrderNo" />
        <result column="sms_content" property="smsContent" />
        <result column="channel_code" property="channelCode" />
        <result column="batch_size" property="batchSize" />
        <result column="success_count" property="successCount" />
        <result column="fail_count" property="failCount" />
        <result column="send_type" property="sendType" />
        <result column="status" property="status" />
        <result column="submit_success_num" property="submitSuccessNum" />
        <result column="submit_fail_num" property="submitFailNum" />
        <result column="channel_msg_id" property="channelMsgId" />
        <result column="channel_return_code" property="channelReturnCode" />
        <result column="channel_error_msg" property="channelErrorMsg" />
        <result column="create_at" property="createAt" />
        <result column="update_at" property="updateAt" />
        <result column="is_delete" property="isDelete" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, request_no, batch_no, app_no, template_no, channel_template_no, message_order_no, sms_content, batch_size, success_count, fail_count, send_type, status, submit_success_num, submit_fail_num, channel_msg_id, channel_code, channel_return_code, channel_error_msg, create_at, update_at, is_delete
    </sql>
  <select id="getStatisticsMessageInfo"
    resultType="cn.axzo.msg.center.domain.dto.BatchMessageStatisticsResponseDto">

      select
        sum(fail_count) as failCount,
        sum(success_count) as successCount,
        sum(fail_count) + sum(success_count) as totalCount
      from batch_message
      where app_no = #{appNo}
      and request_no = #{requestNo}
      and is_delete = 0
      group by app_no,request_no
  </select>

  <select id="getByChannelMsgIdAndLock" resultType="cn.axzo.msg.center.domain.entity.MNSBatchMessage">
      select *
      from batch_message
      where channel_msg_id = #{msgId}
      and is_delete = 0
      for update
  </select>

</mapper>
