<?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.hzs.system.base.mapper.BdFeedbackMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.base.BdFeedback">
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_ID" property="pkId"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="TYPE" property="type"/>
        <result column="IDEA" property="idea"/>
        <result column="STATUS" property="status"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CREATION_TIME,
        MODIFIED_TIME,
        DEL_FLAG,
        PK_COUNTRY,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PK_MEMBER, TYPE, IDEA
    </sql>


    <select id="selectFeedbackList" resultType="com.hzs.common.domain.system.ext.BdFeedbackExt">
        select m.member_code memberCode,
        m.member_name memberName,
        m.nick_name nickName,
        m.head_path headPath,
        f.type,
        f.status,
        f.idea,
        f.pk_id pkId,
        f.pk_country pkCountry,
        f.creation_time creationTime,
        bv.VERTEX_NAME vertexName,
        cmt.team_name teamName
        from bd_feedback f
        left join cu_member m
        on f.pk_member = m.pk_id
        left join bd_vertex bv on bv.PK_ID = m.PK_VERTEX
        left join cu_member_team cmt on m.pk_team_code = cmt.pk_id
        where f.del_flag = 0
        and f.pk_country = #{pkCountry}
        <if test="memberCode != null and memberCode != ''">
            and m.member_code like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName != ''">
            and m.member_name like #{memberName} || '%'
        </if>
        <if test="pkVertex != null">
            and m.PK_VERTEX=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            and m.PK_TEAM_CODE=#{pkTeamCode}
        </if>
        <if test="type != null">
            and f.type = #{type}
        </if>
        <if test="status != null">
            and f.status = #{status}
        </if>
        <if test="startDate != null and startDate != ''">
            and f.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != ''">
            and f.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test='isShowDay != null and isShowDay == "1"'>
            and n.creation_time >= trunc(SYSDATE - 6)
        </if>
        <if test="pkMember != null">
            and f.PK_MEMBER  = #{pkMember}
        </if>
        order by f.creation_time desc
    </select>


    <select id="selectIndexFeedbackCount" resultType="Integer">
        select count(1)
        from bd_feedback f
        where f.del_flag = 0
        and f.pk_country = #{pkCountry}
        and f.PK_MEMBER  = #{pkMember}
    </select>

    <update id="deleteById">
        update bd_feedback f
           set f.del_flag = 1, f.modified_time = sysdate, f.pk_modified = #{pkModified}
        where f.pk_id = #{pkId}
    </update>


    <select id="showFeedbackVOById" resultType="com.hzs.common.domain.system.ext.BdFeedbackExt">
        select m.member_code   memberCode,
               m.member_name   memberName,
               m.nick_name     nickName,
               m.head_path     headPath,
               f.type,
               f.status,
               f.idea,
               f.pk_id pkId,
               f.pk_country pkCountry,
               f.creation_time creationTime
          from bd_feedback f
          left join cu_member m
            on f.pk_member = m.pk_id
         where f.del_flag = 0
           and f.pk_id = #{pkId}
    </select>
</mapper>
