<?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.xunmei.system.mapper.SysAreaCheckMapper">

    <resultMap type="com.xunmei.system.domain.SysAreaCheck" id="SysAreaCheckResult">
                <result property="id" column="id"/>
                <result property="checkName" column="check_name"/>
                <result property="areaId" column="area_id"/>
                <result property="orgId" column="org_id"/>
                <result property="createTime" column="create_time"/>
                <result property="updateTime" column="update_time"/>
                <result property="updateId" column="update_id"/>
                <result property="createBy" column="create_by"/>
                <result property="delFlag" column="del_flag"/>
                <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectSysAreaCheckVo">
        select id, check_name, area_id, org_id, create_time, update_time, update_id, create_by, del_flag, update_by
        from sys_area_check
    </sql>

    <select id="selectSysAreaCheckList" parameterType="com.xunmei.system.domain.SysAreaCheck"
            resultMap="SysAreaCheckResult">
        <include refid="selectSysAreaCheckVo"/>
        <where>
                        <if test="checkName != null  and checkName != ''">
                            and check_name like concat('%', #{checkName}, '%')
                        </if>
                        <if test="areaId != null ">
                            and area_id = #{areaId}
                        </if>
                        <if test="orgId != null ">
                            and org_id = #{orgId}
                        </if>
                        <if test="updateId != null  and updateId != ''">
                            and update_id = #{updateId}
                        </if>
                        <if test="delFlag !=null and delFlag !=''">
                            and del_flag=#{delFlag}
                        </if>
        </where>
    </select>

    <select id="selectSysAreaCheckById" parameterType="Long"
            resultMap="SysAreaCheckResult">
            <include refid="selectSysAreaCheckVo"/>
            where id = #{id}
    </select>
    <select id="selectByPage" resultType="com.xunmei.system.domain.vo.SysAreaCheckVO">
        SELECT
            sa.`name` AS areaName,
            so.`name`
        FROM
            sys_area_check sac
                LEFT JOIN sys_area sa ON sa.id = sac.area_id
                LEFT JOIN sys_org so ON so.id = sac.org_id
        WHERE
            sac.id = #{id}

    </select>


    <insert id="insertSysAreaCheck" parameterType="com.xunmei.system.domain.SysAreaCheck"            useGeneratedKeys="true" keyProperty="id">
        insert into sys_area_check
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="checkName != null">check_name,
                    </if>
                    <if test="areaId != null">area_id,
                    </if>
                    <if test="orgId != null">org_id,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
                    <if test="updateId != null">update_id,
                    </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="delFlag != null">del_flag,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="checkName != null">#{checkName},
                    </if>
                    <if test="areaId != null">#{areaId},
                    </if>
                    <if test="orgId != null">#{orgId},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
                    <if test="updateId != null">#{updateId},
                    </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="delFlag != null">#{delFlag},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
        </trim>
    </insert>

    <update id="updateSysAreaCheck" parameterType="com.xunmei.system.domain.SysAreaCheck">
        update sys_area_check
        <trim prefix="SET" suffixOverrides=",">
                    <if test="checkName != null">check_name =
                        #{checkName},
                    </if>
                    <if test="areaId != null">area_id =
                        #{areaId},
                    </if>
                    <if test="orgId != null">org_id =
                        #{orgId},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
                    <if test="updateId != null">update_id =
                        #{updateId},
                    </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="delFlag != null">del_flag =
                        #{delFlag},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysAreaCheckById" parameterType="Long">
        delete
        from sys_area_check where id = #{id}
    </delete>

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