<?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.project.religion.place.mapper.ReligionPlaceMapper">
    
    <resultMap type="com.ruoyi.project.religion.place.domain.ReligionPlace" id="ReligionPlaceResult">
        <id     property="placeId"          column="place_id"          />
        <result property="placeName"        column="place_name"        />
        <result property="religionType"     column="religion_type"     />
        <result property="placeCategory"    column="place_category"    />
        <result property="county"           column="county"            />
        <result property="address"          column="address"           />
        <result property="chargeName"       column="charge_name"       />
        <result property="chargePhone"      column="charge_phone"      />
        <result property="placeArea"        column="place_area"        />
        <result property="buildingArea"     column="building_area"     />
        <result property="approveOrgan"     column="approve_organ"     />
        <result property="approveTime"      column="approve_time"      />
        <result property="regOrgan"         column="reg_organ"         />
        <result property="regNo"            column="reg_no"            />
        <result property="regTime"          column="reg_time"          />
        <result property="legalQualified"   column="legal_qualified"   />
        <result property="legalTime"        column="legal_time"        />
        <result property="creditCode"       column="credit_code"       />
        <result property="longitude"        column="longitude"         />
        <result property="latitude"         column="latitude"          />
        <result property="createBy"         column="create_by"         />
        <result property="createTime"       column="create_time"       />
        <result property="updateBy"         column="update_by"         />
        <result property="updateTime"       column="update_time"       />
    </resultMap>

    <sql id="selectPlaceVo">
        select place_id, place_name, religion_type, place_category, county, address, 
               charge_name, charge_phone, place_area, building_area, approve_organ, 
               approve_time, reg_organ, reg_no, reg_time, legal_qualified, legal_time, 
               credit_code, longitude, latitude, create_by, create_time, update_by, update_time
        from religion_place
    </sql>

    <select id="selectPlaceList" parameterType="com.ruoyi.project.religion.place.domain.ReligionPlace" resultMap="ReligionPlaceResult">
        <include refid="selectPlaceVo"/>
        <where>  
            <if test="placeName != null and placeName != ''">
                AND place_name like concat('%', #{placeName}, '%')
            </if>
            <if test="religionType != null and religionType != ''">
                AND religion_type = #{religionType}
            </if>
            <if test="placeCategory != null and placeCategory != ''">
                AND place_category = #{placeCategory}
            </if>
            <if test="county != null and county != ''">
                AND county = #{county}
            </if>
            <if test="chargeName != null and chargeName != ''">
                AND charge_name like concat('%', #{chargeName}, '%')
            </if>
            <if test="chargePhone != null and chargePhone != ''">
                AND charge_phone like concat('%', #{chargePhone}, '%')
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectPlaceById" parameterType="Long" resultMap="ReligionPlaceResult">
        <include refid="selectPlaceVo"/>
        where place_id = #{placeId}
    </select>
        
    <insert id="insertPlace" parameterType="com.ruoyi.project.religion.place.domain.ReligionPlace" useGeneratedKeys="true" keyProperty="placeId">
        insert into religion_place
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="placeName != null and placeName != ''">place_name,</if>
            <if test="religionType != null and religionType != ''">religion_type,</if>
            <if test="placeCategory != null and placeCategory != ''">place_category,</if>
            <if test="county != null and county != ''">county,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="chargeName != null and chargeName != ''">charge_name,</if>
            <if test="chargePhone != null and chargePhone != ''">charge_phone,</if>
            <if test="placeArea != null">place_area,</if>
            <if test="buildingArea != null">building_area,</if>
            <if test="approveOrgan != null">approve_organ,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="regOrgan != null">reg_organ,</if>
            <if test="regNo != null">reg_no,</if>
            <if test="regTime != null">reg_time,</if>
            <if test="legalQualified != null">legal_qualified,</if>
            <if test="legalTime != null">legal_time,</if>
            <if test="creditCode != null">credit_code,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="createBy != null">create_by,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="placeName != null and placeName != ''">#{placeName},</if>
            <if test="religionType != null and religionType != ''">#{religionType},</if>
            <if test="placeCategory != null and placeCategory != ''">#{placeCategory},</if>
            <if test="county != null and county != ''">#{county},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="chargeName != null and chargeName != ''">#{chargeName},</if>
            <if test="chargePhone != null and chargePhone != ''">#{chargePhone},</if>
            <if test="placeArea != null">#{placeArea},</if>
            <if test="buildingArea != null">#{buildingArea},</if>
            <if test="approveOrgan != null">#{approveOrgan},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="regOrgan != null">#{regOrgan},</if>
            <if test="regNo != null">#{regNo},</if>
            <if test="regTime != null">#{regTime},</if>
            <if test="legalQualified != null">#{legalQualified},</if>
            <if test="legalTime != null">#{legalTime},</if>
            <if test="creditCode != null">#{creditCode},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate()
         </trim>
    </insert>

    <update id="updatePlace" parameterType="com.ruoyi.project.religion.place.domain.ReligionPlace">
        update religion_place
        <trim prefix="SET" suffixOverrides=",">
            <if test="placeName != null and placeName != ''">place_name = #{placeName},</if>
            <if test="religionType != null and religionType != ''">religion_type = #{religionType},</if>
            <if test="placeCategory != null and placeCategory != ''">place_category = #{placeCategory},</if>
            <if test="county != null and county != ''">county = #{county},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="chargeName != null and chargeName != ''">charge_name = #{chargeName},</if>
            <if test="chargePhone != null and chargePhone != ''">charge_phone = #{chargePhone},</if>
            <if test="placeArea != null">place_area = #{placeArea},</if>
            <if test="buildingArea != null">building_area = #{buildingArea},</if>
            <if test="approveOrgan != null">approve_organ = #{approveOrgan},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="regOrgan != null">reg_organ = #{regOrgan},</if>
            <if test="regNo != null">reg_no = #{regNo},</if>
            <if test="regTime != null">reg_time = #{regTime},</if>
            <if test="legalQualified != null">legal_qualified = #{legalQualified},</if>
            <if test="legalTime != null">legal_time = #{legalTime},</if>
            <if test="creditCode != null">credit_code = #{creditCode},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where place_id = #{placeId}
    </update>

    <delete id="deletePlaceById" parameterType="Long">
        delete from religion_place where place_id = #{placeId}
    </delete>

    <delete id="deletePlaceByIds" parameterType="Long">
        delete from religion_place where place_id in 
        <foreach item="placeId" collection="array" open="(" separator="," close=")">
            #{placeId}
        </foreach>
    </delete>

</mapper>

