<?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.mca.map.mapper.FieldDataMapper">
	
	<resultMap id="fieldDataMap" type="fieldDataVO">
		<result column="id" property="id" />
		<result column="userid" property="userid" />
		<result column="save_date" property="save_date" />
		<result column="data_path" property="data_path" />
		<result column="layer_id" property="layer_id" />
		<result column="field_data" property="field_data" />
		<result column="region" property="region" />
		<result column="description" property="description" />
		<result column="status" property="status" />
		<result column="err_note" property="err_note" />
		<collection property="userVO" resultMap="userVO"></collection>
	</resultMap>
	
	<resultMap id="userVO" type="userVO">
		<result column="userid" property="userid" />
		<result column="name" property="name" />
		<result column="company" property="company" />
		<result column="email" property="email" />
		<result column="phonenum" property="phonenum" />
	</resultMap>

	<select id="selectFieldDataList" parameterType="fieldDataSearchVO" resultMap="fieldDataMap" >
		SELECT
			a.id,
			b.name,
		    b.company,
		    a.save_date,
		    a.region,
		    a.status
		FROM
			map_field_data a LEFT JOIN t_user b ON a.userid=b.userid
		WHERE 1=1


		<if test='searchKeyword != null and searchKeyword != ""'>
			<choose>
				<when test='searchCondition eq "all"'>
					AND (a.region LIKE CONCAT('%',#{searchKeyword},'%')
					OR b.name LIKE CONCAT('%',#{searchKeyword},'%')
					OR b.company LIKE CONCAT('%',#{searchKeyword},'%'))
				</when>
				<otherwise>
					AND ${searchCondition} LIKE CONCAT('%',#{searchKeyword},'%')
				</otherwise>
			</choose>
		</if>

		ORDER BY id DESC
		LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
	</select>
	
	<select id="selectFieldDataCnt" resultType="int">
		SELECT
			COUNT(*)
		FROM
			map_field_data
		WHERE 1 = 1
	</select>
	
	<select id="selectFieldData" parameterType="String" resultType="fieldDataVO">
		SELECT
		id,
		userid,
		save_date,
		data_path,
		layer_id,
		field_data,
		region,
		description,
		status,
		err_note
		FROM
			map_field_data
		WHERE id = #{id}
	</select>
</mapper>