<?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.yeejoin.amos.boot.module.common.api.mapper.KeySiteMapper">

	<select id="getPageList" resultType="com.yeejoin.amos.boot.module.common.api.dto.KeySiteDto">
		SELECT
		c.`name` as name,
		c.belong_id as belongId,
		cou.biz_org_name as belongName,
		c.building_id as buildingId,
		c.building_name as buildingName,
		c.address_desc as addressDesc,
		c.building_area as buildingArea,
		c.building_height as buildingHeight,
		c.fire_endurance_rate as fireEnduranceRate,
		c.use_nature as useNature,
		c.charge_person AS chargePerson,
		c.sequence_nbr AS sequenceNbr,
		c.charge_person_id AS chargePersonId,
		c.key_prevention_reason AS keyPreventionReason,
		c.fire_facilities_info AS fireFacilitiesInfo,
		c.fire_prevention_flag AS firePreventionFlag,
		c.hazard AS hazard,
		c.safety_management_measures AS safetyManagementMeasures,
		c.preventive_measures AS preventiveMeasures,
		c.remark AS remark,
		c.is_delete AS isDelete,
		c.rec_user_id AS recUserId,
		c.rec_user_name AS recUserName,
		c.rec_date AS recDate,
		c.fire_endurance_rate_name as fireEnduranceRateName,
		c.use_nature_name as useNatureName
		FROM
		cb_key_site c
		left join cb_org_usr cou on c.belong_id =cou.sequence_nbr
		where c.is_delete=FALSE
		<if test="name != null and name != ''">
			AND c.`name` like concat('%',#{name}, '%')
		</if>
		<if test="buildingId != null and buildingId != -1">
			AND c.`building_id`= #{buildingId}
		</if>
		<if test="fireEnduranceRate != null and fireEnduranceRate != ''">
			AND c.`fire_endurance_rate`= #{fireEnduranceRate}
		</if>
		<if test="useNature != null and useNature != ''">
			AND c.`use_nature`= #{useNature}
		</if>
		<if test="fireFacilitiesInfo != null and fireFacilitiesInfo != ''">
			AND c.`fire_facilities_info`= #{fireFacilitiesInfo}
		</if>
		<if test="belongId != null and belongId!='-1' and belongId != -1">
			AND c.`belong_id`= #{belongId}
		</if>
		order by c.rec_date desc
	</select>
	
	<select id="getSequenceNbr" resultType="com.yeejoin.amos.boot.module.common.api.dto.KeySiteDto">
		SELECT c.`name`                     as name,
			   c.belong_id                  as belongId,
			   cou.biz_org_name             as belongName,
			   c.building_id                as buildingId,
			   c.building_name              as buildingName,
			   c.address_desc               as addressDesc,
			   c.building_area              as buildingArea,
			   c.building_height            as buildingHeight,
			   c.fire_endurance_rate        as fireEnduranceRate,
			   c.use_nature                 as useNature,
			   c.charge_person              AS chargePerson,
			   c.sequence_nbr               AS sequenceNbr,
			   c.charge_person_id           AS chargePersonId,
			   c.key_prevention_reason      AS keyPreventionReason,
			   c.fire_facilities_info       AS fireFacilitiesInfo,
			   c.fire_prevention_flag       AS firePreventionFlag,
			   c.hazard                     AS hazard,
			   c.safety_management_measures AS safetyManagementMeasures,
			   c.preventive_measures        AS preventiveMeasures,
			   c.remark                     AS remark,
			   c.is_delete                  AS isDelete,
			   c.rec_user_id                AS recUserId,
			   c.rec_user_name              AS recUserName,
			   c.rec_date                   AS recDate,
			   c.fire_endurance_rate_name   as fireEnduranceRateName,
			   c.use_nature_name            as useNatureName
		FROM cb_key_site c
				 left join cb_org_usr cou on c.belong_id = cou.sequence_nbr
		where c.sequence_nbr = #{sequenceNbr}
		  and c.is_delete = FALSE;
	</select>
		
	<select id="getKeySiteList" resultType="com.yeejoin.amos.boot.module.common.api.dto.KeySiteDto">
		SELECT c.`name`                     as name,
			   c.belong_id                  as belongId,
			   cou.biz_org_name             as belongName,
			   c.building_id                as buildingId,
			   c.building_name              as buildingName,
			   c.address_desc               as addressDesc,
			   c.building_area              as buildingArea,
			   c.building_height            as buildingHeight,
			   c.fire_endurance_rate        as fireEnduranceRate,
			   c.use_nature                 as useNature,
			   c.charge_person              AS chargePerson,
			   c.sequence_nbr               AS sequenceNbr,
			   c.charge_person_id           AS chargePersonId,
			   c.key_prevention_reason      AS keyPreventionReason,
			   c.fire_facilities_info       AS fireFacilitiesInfo,
			   c.fire_prevention_flag       AS firePreventionFlag,
			   c.hazard                     AS hazard,
			   c.safety_management_measures AS safetyManagementMeasures,
			   c.preventive_measures        AS preventiveMeasures,
			   c.remark                     AS remark,
			   c.is_delete                  AS isDelete,
			   c.rec_user_id                AS recUserId,
			   c.rec_user_name              AS recUserName,
			   c.rec_date                   AS recDate,
			   c.fire_endurance_rate_name   as fireEnduranceRateName,
			   c.use_nature_name            as useNatureName
		FROM cb_key_site c
				 left join cb_org_usr cou on c.belong_id = cou.sequence_nbr
		where c.is_delete = FALSE;
	</select>


	<select id="getAddress" resultType="string">
		SELECT
		c.address_desc
		FROM cb_key_site c
		where c.is_delete = FALSE
		and
		c.address_desc like concat ('%',#{address},'%');
	</select>
</mapper>
