<?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.gic.haoban.manage.service.dao.mapper.TabQywxErrorLogMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.TabQywxErrorLog" id="TabQywxErrorLogMap">
        <result property="id" column="id" />
        <result property="wxEnterpriseId" column="wx_enterprise_id" />
        <result property="member_id" column="memberId"/>
        <result property="external_user_id" column="externalUserId" />
        <result property="scenario" column="scenario" />
        <result property="errorContent" column="error_content" />
        <result property="weworkErrorUrl" column="wework_error_url" />
        <result property="traceId" column="trace_id" />
        <result property="qywxErrorType" column="qywx_error_type" />
        <result property="createTime" column="create_time"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, wx_enterprise_id, member_id , external_user_id ,scenario, error_content, trace_id, qywx_error_type, create_time
   </sql>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.gic.haoban.manage.service.entity.TabQywxErrorLog">
        INSERT INTO tab_qywx_error_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id,
            </if>
            <if test="memberId != null and memberId != ''">
                member_id,
            </if>
            <if test="externalUserId != null and externalUserId != ''">
                external_user_id,
            </if>
            <if test="scenario != null and scenario != ''">
                scenario,
            </if>
            <if test="errorContent != null and errorContent != ''">
                error_content,
            </if>
            <if test="traceId != null and traceId != ''">
                trace_id,
            </if>
            <if test="qywxErrorType != null">
                qywx_error_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                #{wxEnterpriseId},
            </if>
            <if test="memberId != null and memberId != ''">
                #{memberId},
            </if>
            <if test="externalUserId != null and externalUserId != ''">
                #{externalUserId},
            </if>
            <if test="scenario != null and scenario != ''">
                #{scenario},
            </if>
            <if test="errorContent != null and errorContent != ''">
                #{errorContent},
            </if>
            <if test="traceId != null and traceId != ''">
                #{traceId},
            </if>
            <if test="qywxErrorType != null">
                #{qywxErrorType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
        </trim>
    </insert>


    <!--通过实体作为筛选条件查询-->
    <select id="queryListByPage" parameterType="com.gic.haoban.manage.api.dto.qdto.QywxErrorLogListQDTO"
            resultMap="TabQywxErrorLogMap">
        select
        <include refid="Base_Column_List"/>
        from tab_qywx_error_log
        <where>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="scenario != null and scenario != ''">
                and (  member_id = #{scenario}  or external_user_id = #{scenario} )
            </if>
            <if test="qywxErrorType != null">
                and qywx_error_type = #{qywxErrorType}
            </if>
            <if test="startDate != null">
                and create_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and create_time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
        order by create_time desc
    </select>

</mapper>