<?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.common.mapper.SecExceptionAlgorithmMapper">

    <!-- 基本的结果映射，与注解方式一致 -->
    <resultMap id="algorithmResultMap" type="com.common.entity.SecExceptionAlgorithm">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="algorithmName" column="algorithm_name" jdbcType="VARCHAR"/>
        <result property="exceptionType" column="exception_type" jdbcType="VARCHAR"/>
        <result property="dataSource" column="data_source" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="SMALLINT"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
        <result property="configInfo" column="config_info" jdbcType="VARCHAR"/>
        <result property="operatorZipUrl" column="operator_zip_url" jdbcType="VARCHAR"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="tenantId" column="tenant_id" jdbcType="VARCHAR"/>
        <result property="delFlag" column="del_flag" jdbcType="CHAR"/>
        <result property="createDept" column="create_dept" jdbcType="BIGINT"/>
        <result property="apiUrl" column="api_url" jdbcType="VARCHAR"/>
        <result property="apiMethod" column="api_method" jdbcType="VARCHAR"/>
        <result property="respUrl" column="resp_url" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 使用XML方式定义的findById方法 -->
    <select id="findById" parameterType="java.lang.Long" resultMap="algorithmResultMap">
        SELECT *
        FROM sec_exception_algorithm
        WHERE id = #{id, jdbcType=BIGINT}
    </select>

    <!-- 批量查询 -->
    <select id="findByIds" parameterType="java.util.List" resultMap="algorithmResultMap">
        SELECT *
        FROM sec_exception_algorithm
        WHERE id IN
        <foreach collection="list" item="id" open="(" separator="," close=")">
            #{id, jdbcType=BIGINT}
        </foreach>
        AND status = 1 AND del_flag = '0'
    </select>

    <!-- 条件查询 -->
    <select id="findByCondition" parameterType="java.util.Map" resultMap="algorithmResultMap">
        SELECT *
        FROM sec_exception_algorithm
        WHERE del_flag = '0'
        <if test="status != null">
            AND status = #{status, jdbcType=SMALLINT}
        </if>
        <if test="exceptionType != null and exceptionType != ''">
            AND exception_type = #{exceptionType, jdbcType=VARCHAR}
        </if>
        <if test="dataSource != null and dataSource != ''">
            AND data_source = #{dataSource, jdbcType=VARCHAR}
        </if>
        <if test="algorithmName != null and algorithmName != ''">
            AND algorithm_name LIKE CONCAT('%', #{algorithmName, jdbcType=VARCHAR}, '%')
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>