<?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.example.mapper.AuditsMapper">

    <sql id="Base_Column_List">
        id,store_address,idcard,business_license,reason,pics_url,camera_url,store_id,keeper_name,state
    </sql>

    <select id="selectAll" resultType="com.example.entity.Audits">
        select
        <include refid="Base_Column_List" />
        from audits
        <where>
            <if test="id != null"> and id = #{id}</if>
            <if test="storeAddress != null"> and store_address like concat('%', #{storeAddress}, '%')</if>
            <if test="idcard != null"> and idcard like concat('%', #{idcard}, '%')</if>
            <if test="businessLicense != null"> and business_license like concat('%', #{businessLicense}, '%')</if>
            <if test="reason != null"> and reason like concat('%', #{reason}, '%')</if>
            <if test="picsUrl != null"> and pics_url like concat('%', #{picsUrl}, '%')</if>
            <if test="cameraUrl != null"> and camera_url like concat('%', #{cameraUrl}, '%')</if>
            <if test="storeId != null"> and store_id = #{storeId}</if>
            <if test="keeperName != null"> and keeper_name like concat('%', #{keeperName}, '%')</if>
            <if test="state != null"> and state like concat('%', #{state}, '%')</if>
        </where>
        order by id desc
    </select>

    <select id="selectById" resultType="com.example.entity.Audits">
        select
        <include refid="Base_Column_List" />
        from audits
        where id = #{id}
    </select>

    <delete id="deleteById">
        delete from audits
        where  id = #{id}
    </delete>

    <insert id="insert" parameterType="com.example.entity.Audits" useGeneratedKeys="true">
        insert into audits
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="storeAddress != null">store_address,</if>
            <if test="idcard != null">idcard,</if>
            <if test="businessLicense != null">business_license,</if>
            <if test="reason != null">reason,</if>
            <if test="picsUrl != null">pics_url,</if>
            <if test="cameraUrl != null">camera_url,</if>
            <if test="storeId != null">store_id,</if>
            <if test="keeperName != null">keeper_name,</if>
            <if test="state != null">state,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="storeAddress != null">#{storeAddress},</if>
            <if test="idcard != null">#{idcard},</if>
            <if test="businessLicense != null">#{businessLicense},</if>
            <if test="reason != null">#{reason},</if>
            <if test="picsUrl != null">#{picsUrl},</if>
            <if test="cameraUrl != null">#{cameraUrl},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="keeperName != null">#{keeperName},</if>
            <if test="state != null">#{state},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.example.entity.Audits">
        update audits
        <set>
            <if test="storeAddress != null">
                store_address = #{storeAddress},
            </if>
            <if test="idcard != null">
                idcard = #{idcard},
            </if>
            <if test="businessLicense != null">
                business_license = #{businessLicense},
            </if>
            <if test="reason != null">
                reason = #{reason},
            </if>
            <if test="picsUrl != null">
                pics_url = #{picsUrl},
            </if>
            <if test="cameraUrl != null">
                camera_url = #{cameraUrl},
            </if>
            <if test="storeId != null">
                store_id = #{storeId},
            </if>
            <if test="keeperName != null">
                keeper_name = #{keeperName},
            </if>
            <if test="state != null">
                state = #{state},
            </if>
        </set>
        where id = #{id} 
    </update>

</mapper>