<?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.leromro.core.mapper.DeptRegionManagementMapper">
    
    <resultMap type="DeptRegionManagement" id="DeptRegionManagementResult">
        <result property="regionManagementId"    column="region_management_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="areaType"    column="area_type"    />
        <result property="pointList"    column="point_list"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="provinceCode"    column="province_code"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityCode"    column="city_code"    />
        <result property="cityName"    column="city_name"    />
        <result property="districtCode"    column="district_code"    />
        <result property="districtName"    column="district_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDeptRegionManagementVo">
        select region_management_id, dept_id, dept_name, area_type, point_list, del_flag, province_code, province_name, city_code, city_name, district_code, district_name, create_time, create_by, update_time, update_by, remark from l_dept_region_management
    </sql>

    <select id="selectDeptRegionManagementList" parameterType="DeptRegionManagement" resultMap="DeptRegionManagementResult">
        <include refid="selectDeptRegionManagementVo"/>
        <where>  
            <if test="regionManagementId != null "> and region_management_id = #{regionManagementId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="areaType != null  and areaType != ''"> and area_type = #{areaType}</if>
            <if test="pointList != null  and pointList != ''"> and point_list = #{pointList}</if>
            <if test="provinceCode != null  and provinceCode != ''"> and province_code = #{provinceCode}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityCode != null  and cityCode != ''"> and city_code = #{cityCode}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="districtCode != null  and districtCode != ''"> and district_code = #{districtCode}</if>
            <if test="districtName != null  and districtName != ''"> and district_name like concat('%', #{districtName}, '%')</if>
        </where>
    </select>
    
    <select id="selectDeptRegionManagementByRegionManagementId" parameterType="Long" resultMap="DeptRegionManagementResult">
        <include refid="selectDeptRegionManagementVo"/>
        where region_management_id = #{regionManagementId}
    </select>

    <insert id="insertDeptRegionManagement" parameterType="DeptRegionManagement">
        insert into l_dept_region_management
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="regionManagementId != null">region_management_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="areaType != null">area_type,</if>
            <if test="pointList != null">point_list,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="provinceCode != null">province_code,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="cityCode != null">city_code,</if>
            <if test="cityName != null">city_name,</if>
            <if test="districtCode != null">district_code,</if>
            <if test="districtName != null">district_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="regionManagementId != null">#{regionManagementId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="areaType != null">#{areaType},</if>
            <if test="pointList != null">#{pointList},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="provinceCode != null">#{provinceCode},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="cityCode != null">#{cityCode},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="districtCode != null">#{districtCode},</if>
            <if test="districtName != null">#{districtName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateDeptRegionManagement" parameterType="DeptRegionManagement">
        update l_dept_region_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="areaType != null">area_type = #{areaType},</if>
            <if test="pointList != null">point_list = #{pointList},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="provinceCode != null">province_code = #{provinceCode},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="cityCode != null">city_code = #{cityCode},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="districtCode != null">district_code = #{districtCode},</if>
            <if test="districtName != null">district_name = #{districtName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where region_management_id = #{regionManagementId}
    </update>

    <delete id="deleteDeptRegionManagementByRegionManagementId" parameterType="Long">
        delete from l_dept_region_management where region_management_id = #{regionManagementId}
    </delete>

    <delete id="deleteDeptRegionManagementByRegionManagementIds" parameterType="Long">
        delete from l_dept_region_management where region_management_id in 
        <foreach item="regionManagementId" collection="array" open="(" separator="," close=")">
            #{regionManagementId}
        </foreach>
    </delete>
</mapper>