<?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.ruoyi.ems.mapper.AreaMapper">
    
    <resultMap type="com.ruoyi.ems.domain.Area" id="AdmServiceAreaResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="areaName"    column="area_name"    />
        <result property="serviceStar"    column="service_star"    />
        <result property="city"    column="city"    />
        <result property="highway"    column="highway"    />
        <result property="direction"    column="direction"    />
        <result property="address"    column="address"    />
        <result property="attrOrg"    column="attr_org"    />
        <result property="mgrOrg"    column="mgr_org"    />
        <result property="openDate"    column="open_date"    />
        <result property="landArea"    column="land_area"    />
        <result property="floorArea"    column="floor_area"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
    </resultMap>

    <sql id="selectAreaVo">
        select id, area_code, area_name, service_star, city, highway, direction, address, attr_org, mgr_org, open_date, land_area, floor_area, longitude, latitude from adm_service_area
    </sql>

    <select id="selectAreaList" parameterType="com.ruoyi.ems.domain.Area" resultMap="AdmServiceAreaResult">
        <include refid="selectAreaVo"/>
        <where>  
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="serviceStar != null "> and service_star = #{serviceStar}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="highway != null  and highway != ''"> and highway = #{highway}</if>
            <if test="direction != null  and direction != ''"> and direction = #{direction}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="attrOrg != null  and attrOrg != ''"> and attr_org = #{attrOrg}</if>
            <if test="mgrOrg != null  and mgrOrg != ''"> and mgr_org = #{mgrOrg}</if>
            <if test="openDate != null "> and open_date = #{openDate}</if>
            <if test="landArea != null "> and land_area = #{landArea}</if>
            <if test="floorArea != null "> and floor_area = #{floorArea}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
        </where>
    </select>
    
    <select id="selectAreaById" parameterType="Long" resultMap="AdmServiceAreaResult">
        <include refid="selectAreaVo"/>
        where `id` = #{id}
    </select>

    <select id="selectAreaByCode" parameterType="String" resultMap="AdmServiceAreaResult">
        <include refid="selectAreaVo"/>
        where area_code = #{code}
    </select>
        
    <insert id="insertArea" parameterType="com.ruoyi.ems.domain.Area" useGeneratedKeys="true" keyProperty="id">
        insert into adm_service_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="areaName != null and areaName != ''">area_name,</if>
            <if test="serviceStar != null">service_star,</if>
            <if test="city != null">city,</if>
            <if test="highway != null">highway,</if>
            <if test="direction != null">direction,</if>
            <if test="address != null">address,</if>
            <if test="attrOrg != null">attr_org,</if>
            <if test="mgrOrg != null">mgr_org,</if>
            <if test="openDate != null">open_date,</if>
            <if test="landArea != null">land_area,</if>
            <if test="floorArea != null">floor_area,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="areaName != null and areaName != ''">#{areaName},</if>
            <if test="serviceStar != null">#{serviceStar},</if>
            <if test="city != null">#{city},</if>
            <if test="highway != null">#{highway},</if>
            <if test="direction != null">#{direction},</if>
            <if test="address != null">#{address},</if>
            <if test="attrOrg != null">#{attrOrg},</if>
            <if test="mgrOrg != null">#{mgrOrg},</if>
            <if test="openDate != null">#{openDate},</if>
            <if test="landArea != null">#{landArea},</if>
            <if test="floorArea != null">#{floorArea},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
         </trim>
    </insert>

    <update id="updateArea" parameterType="com.ruoyi.ems.domain.Area">
        update adm_service_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
            <if test="serviceStar != null">service_star = #{serviceStar},</if>
            <if test="city != null">city = #{city},</if>
            <if test="highway != null">highway = #{highway},</if>
            <if test="direction != null">direction = #{direction},</if>
            <if test="address != null">address = #{address},</if>
            <if test="attrOrg != null">attr_org = #{attrOrg},</if>
            <if test="mgrOrg != null">mgr_org = #{mgrOrg},</if>
            <if test="openDate != null">open_date = #{openDate},</if>
            <if test="landArea != null">land_area = #{landArea},</if>
            <if test="floorArea != null">floor_area = #{floorArea},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAreaById" parameterType="Long">
        delete from adm_service_area where id = #{id}
    </delete>

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