<?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.tofly.xrtygis.mapper.TfMsgPersonManageMapper">

  <resultMap id="tfMsgPersonManageMap" type="com.tofly.xrtygis.entity.TfMsgPersonManage">
                <id property="id" column="ID"/>
                      <result property="msgPushId" column="MSG_PUSH_ID"/>
                      <result property="userId" column="USER_ID"/>
                      <result property="userName" column="USER_NAME"/>
                      <result property="phone" column="PHONE"/>
                      <result property="callResult" column="CALL_RESULT"/>
      <association property="tfMsgPushManage"  column="MSG_PUSH_ID" select="getTfMsgPushManage" ></association>
      <association property="callResultName"  column="CALL_RESULT" select="getCallResultName" ></association>
  </resultMap>

    <select id="getMsgPersonInfoList" resultType="com.tofly.xrtygis.entity.vo.TfMsgPersonManageVo">
        SELECT b.ID,
        b.CONTENT,
        b.CONTENT_TYPE,
        decode(b.CONTENT_TYPE,'1','天气','2','保健护理','3','疾病防护') contentTypeName,
        b.EDIT_PERSON,
        b.MSG_TYPE,
        decode(b.MSG_TYPE,'1','语音','2','短信') msgTypeName,
        b.IS_SEND_NOW,
        decode(b.IS_SEND_NOW,'0','否','1','是') isSendNowName,
        b.SEND_TIME,
        b.SEND_STATUS,
        decode(b.SEND_STATUS,'0','未发送','1','已发送') sendStatusName,
        a.PHONE,
        a.ID AS msgPersonId,
        a.USER_ID,
        a.USER_NAME,
        a.CALL_RESULT
        FROM TF_MSG_PERSON_MANAGE a
        LEFT JOIN TF_MSG_PUSH_MANAGE b ON a.MSG_PUSH_ID = b.ID
        WHERE
            1=1
        <if test="hasCallResult != null and hasCallResult.trim() != '' and hasCallResult.equals('0')">
            and a.CALL_RESULT is NULL
        </if>
        <if test="hasCallResult != null and hasCallResult.trim() != '' and hasCallResult.equals('1')">
            and a.CALL_RESULT is NOT NULL
        </if>
        <if test="sendStatus != null and sendStatus.trim() != ''">
            and b.SEND_STATUS = #{sendStatus}
        </if>
        <if test="msgType != null and msgType.trim() != ''">
            and b.MSG_TYPE = #{msgType}
        </if>
        ORDER BY b.SEND_TIME
    </select>

    <select id="getTfMsgPushManage" resultType="com.tofly.xrtygis.entity.TfMsgPushManage">
        SELECT * FROM TF_MSG_PUSH_MANAGE WHERE ID = #{msgPushId}
    </select>

    <select id="getCallResultName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =60100
          AND
            CCODE = #{callResult}
    </select>

                                
</mapper>
