<?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.zhyc.module.app.mapper.AppErrorLogMapper">
    
    <resultMap type="AppErrorLog" id="AppErrorLogResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="userId"    column="user_id"    />
        <result property="appVersion"    column="app_version"    />
        <result property="appCode"    column="app_code"    />
        <result property="platform"    column="platform"    />
        <result property="osVersion"    column="os_version"    />
        <result property="errorType"    column="error_type"    />
        <result property="errorCode"    column="error_code"    />
        <result property="errorMessage"    column="error_message"    />
        <result property="stackTrace"    column="stack_trace"    />
        <result property="pageUrl"    column="page_url"    />
        <result property="apiUrl"    column="api_url"    />
        <result property="apiParams"    column="api_params"    />
        <result property="networkType"    column="network_type"    />
        <result property="screenWidth"    column="screen_width"    />
        <result property="screenHeight"    column="screen_height"    />
        <result property="customData"    column="custom_data"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectAppErrorLogVo">
        select id, device_id, user_id, app_version, app_code, platform, os_version, error_type, error_code, error_message, stack_trace, page_url, api_url, api_params, network_type, screen_width, screen_height, custom_data, create_time from app_error_log
    </sql>

    <select id="selectAppErrorLogList" parameterType="AppErrorLog" resultMap="AppErrorLogResult">
        <include refid="selectAppErrorLogVo"/>
        <where>  
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="appVersion != null  and appVersion != ''"> and app_version = #{appVersion}</if>
            <if test="appCode != null "> and app_code = #{appCode}</if>
            <if test="platform != null  and platform != ''"> and platform = #{platform}</if>
            <if test="osVersion != null  and osVersion != ''"> and os_version = #{osVersion}</if>
            <if test="errorType != null  and errorType != ''"> and error_type = #{errorType}</if>
            <if test="errorCode != null  and errorCode != ''"> and error_code = #{errorCode}</if>
            <if test="errorMessage != null  and errorMessage != ''"> and error_message = #{errorMessage}</if>
            <if test="stackTrace != null  and stackTrace != ''"> and stack_trace = #{stackTrace}</if>
            <if test="pageUrl != null  and pageUrl != ''"> and page_url = #{pageUrl}</if>
            <if test="apiUrl != null  and apiUrl != ''"> and api_url = #{apiUrl}</if>
            <if test="apiParams != null  and apiParams != ''"> and api_params = #{apiParams}</if>
            <if test="networkType != null  and networkType != ''"> and network_type = #{networkType}</if>
            <if test="screenWidth != null "> and screen_width = #{screenWidth}</if>
            <if test="screenHeight != null "> and screen_height = #{screenHeight}</if>
            <if test="customData != null  and customData != ''"> and custom_data = #{customData}</if>
        </where>
    </select>
    
    <select id="selectAppErrorLogById" parameterType="Long" resultMap="AppErrorLogResult">
        <include refid="selectAppErrorLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppErrorLog" parameterType="AppErrorLog" useGeneratedKeys="true" keyProperty="id">
        insert into app_error_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="appVersion != null and appVersion != ''">app_version,</if>
            <if test="appCode != null">app_code,</if>
            <if test="platform != null">platform,</if>
            <if test="osVersion != null">os_version,</if>
            <if test="errorType != null">error_type,</if>
            <if test="errorCode != null">error_code,</if>
            <if test="errorMessage != null">error_message,</if>
            <if test="stackTrace != null">stack_trace,</if>
            <if test="pageUrl != null">page_url,</if>
            <if test="apiUrl != null">api_url,</if>
            <if test="apiParams != null">api_params,</if>
            <if test="networkType != null">network_type,</if>
            <if test="screenWidth != null">screen_width,</if>
            <if test="screenHeight != null">screen_height,</if>
            <if test="customData != null">custom_data,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="appVersion != null and appVersion != ''">#{appVersion},</if>
            <if test="appCode != null">#{appCode},</if>
            <if test="platform != null">#{platform},</if>
            <if test="osVersion != null">#{osVersion},</if>
            <if test="errorType != null">#{errorType},</if>
            <if test="errorCode != null">#{errorCode},</if>
            <if test="errorMessage != null">#{errorMessage},</if>
            <if test="stackTrace != null">#{stackTrace},</if>
            <if test="pageUrl != null">#{pageUrl},</if>
            <if test="apiUrl != null">#{apiUrl},</if>
            <if test="apiParams != null">#{apiParams},</if>
            <if test="networkType != null">#{networkType},</if>
            <if test="screenWidth != null">#{screenWidth},</if>
            <if test="screenHeight != null">#{screenHeight},</if>
            <if test="customData != null">#{customData},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateAppErrorLog" parameterType="AppErrorLog">
        update app_error_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="appVersion != null and appVersion != ''">app_version = #{appVersion},</if>
            <if test="appCode != null">app_code = #{appCode},</if>
            <if test="platform != null">platform = #{platform},</if>
            <if test="osVersion != null">os_version = #{osVersion},</if>
            <if test="errorType != null">error_type = #{errorType},</if>
            <if test="errorCode != null">error_code = #{errorCode},</if>
            <if test="errorMessage != null">error_message = #{errorMessage},</if>
            <if test="stackTrace != null">stack_trace = #{stackTrace},</if>
            <if test="pageUrl != null">page_url = #{pageUrl},</if>
            <if test="apiUrl != null">api_url = #{apiUrl},</if>
            <if test="apiParams != null">api_params = #{apiParams},</if>
            <if test="networkType != null">network_type = #{networkType},</if>
            <if test="screenWidth != null">screen_width = #{screenWidth},</if>
            <if test="screenHeight != null">screen_height = #{screenHeight},</if>
            <if test="customData != null">custom_data = #{customData},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppErrorLogById" parameterType="Long">
        delete from app_error_log where id = #{id}
    </delete>

    <delete id="deleteAppErrorLogByIds" parameterType="String">
        delete from app_error_log where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>