<?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.system.mapper.BasicInfoMapper">
    
    <resultMap type="BasicInfo" id="BasicInfoResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="unitName"    column="unit_name"    />
        <result property="provinceId"    column="province_id"    />
        <result property="province"    column="province"    />
        <result property="cityId"    column="city_id"    />
        <result property="city"    column="city"    />
        <result property="regionId"    column="region_id"    />
        <result property="region"    column="region"    />
        <result property="detailedAddress"    column="detailed_address"    />
        <result property="lon"    column="lon"    />
        <result property="lat"    column="lat"    />
        <result property="personName"    column="person_name"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="sex"    column="sex"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBasicInfoVo">
        select id, user_id, unit_name, province_id, province, city_id, city, region_id, region, detailed_address, lon, lat, person_name, phonenumber, sex, del_flag, create_by, create_time, update_by, update_time, remark from basic_info
    </sql>

    <select id="selectBasicInfoList" parameterType="BasicInfo" resultMap="BasicInfoResult">
        <include refid="selectBasicInfoVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="provinceId != null  and provinceId != ''"> and province_id = #{provinceId}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="cityId != null  and cityId != ''"> and city_id = #{cityId}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="regionId != null  and regionId != ''"> and region_id = #{regionId}</if>
            <if test="region != null  and region != ''"> and region = #{region}</if>
            <if test="detailedAddress != null  and detailedAddress != ''"> and detailed_address = #{detailedAddress}</if>
            <if test="lon != null  and lon != ''"> and lon = #{lon}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
        </where>
    </select>
    
    <select id="selectBasicInfoById" parameterType="Long" resultMap="BasicInfoResult">
        <include refid="selectBasicInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertBasicInfo" parameterType="BasicInfo" useGeneratedKeys="true" keyProperty="id">
        insert into basic_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="province != null">province,</if>
            <if test="cityId != null">city_id,</if>
            <if test="city != null">city,</if>
            <if test="regionId != null">region_id,</if>
            <if test="region != null">region,</if>
            <if test="detailedAddress != null">detailed_address,</if>
            <if test="lon != null">lon,</if>
            <if test="lat != null">lat,</if>
            <if test="personName != null">person_name,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="sex != null">sex,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="province != null">#{province},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="city != null">#{city},</if>
            <if test="regionId != null">#{regionId},</if>
            <if test="region != null">#{region},</if>
            <if test="detailedAddress != null">#{detailedAddress},</if>
            <if test="lon != null">#{lon},</if>
            <if test="lat != null">#{lat},</if>
            <if test="personName != null">#{personName},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="sex != null">#{sex},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBasicInfo" parameterType="BasicInfo">
        update basic_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="province != null">province = #{province},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="city != null">city = #{city},</if>
            <if test="regionId != null">region_id = #{regionId},</if>
            <if test="region != null">region = #{region},</if>
            <if test="detailedAddress != null">detailed_address = #{detailedAddress},</if>
            <if test="lon != null">lon = #{lon},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="personName != null">person_name = #{personName},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBasicInfoById" parameterType="Long">
        delete from basic_info where id = #{id}
    </delete>

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