<?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.huatek.busi.mapper.RParamBasicDataMapper">

	<sql id = "Base_Column_List">
		id,
		param_value as paramValue,
		main_equ_id as mainEquId,
		remark,
		create_user as createUser,
		create_time as createTime,
		update_user as updateUser,
		update_time as updateTime,
		deleted
    </sql>

	<select id = "mainList" parameterType="com.huatek.busi.where.RParamBasicDataSelectVo" resultType="com.huatek.busi.dto.RParamBasicDataDto">
		SELECT
		A.id,
		A.param_value AS paramValue,
		A.main_equ_id AS mainEquId,
		A.remark,
		A.create_user AS createUser,
		A.create_time AS createTime,
		A.update_user AS updateUser,
		A.update_time AS updateTime,
		A.deleted,
		B.`name` as mainEquName
		FROM
		x_r_param_basic_data A
		LEFT JOIN busi_site_tree B ON A.main_equ_id = B.system_code
		WHERE
			A.deleted = 0
			AND B.`status` = 1
		<if test="paramValue != null and paramValue != '' ">
			and A.param_value like CONCAT('%', #{paramValue}, '%')
		</if>
		<if test="mainEquId != null and mainEquId != '' ">
			and A.main_equ_id = #{mainEquId}
		</if>
	</select>

	<select id = "findByParamValue" parameterType="java.lang.String" resultType="com.huatek.busi.dto.RParamBasicDataDto">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_param_basic_data
		WHERE
		deleted = 0
		<if test="paramKey != null and paramKey != '' ">
			and param_value = #{paramKey}
		</if>
	</select>

	<select id = "findBySystemCodeAndTestItem" parameterType="java.lang.String" resultType="com.huatek.busi.dto.RParamBasicDataDto">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_param_basic_data
		WHERE
		deleted = 0
		and param_value = #{testItem}
		and main_equ_id = #{systemCode}
	</select>
    <select id="testItemList" resultType="com.huatek.busi.vo.DeviceSubclassOrTestItemListVo">
		SELECT
		A.id,
		A.param_value AS value
		FROM
		x_r_param_basic_data A
		LEFT JOIN busi_site_tree B ON A.main_equ_id = B.system_code
		WHERE
		A.deleted = 0
		AND B.`status` = 1
		and B.equipment_type = #{equType}
	</select>
</mapper>