<?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.RParamAttrBasicDataMapper">

	<sql id = "Base_Column_List">
		id,
		p_id as pId,
		dis_param_value as disParamValue,
		unit,
		assess_field_rule as assessFieldRule,
		remark,
		create_user as createUser,
		create_time as createTime,
		update_user as updateUser,
		update_time as updateTime,
		deleted
	</sql>

	<select id = "getRParamAttrBasicDataByPId" parameterType = "java.lang.String" resultType = "com.huatek.busi.entity.RParamAttrBasicData">
		SELECT
			<include refid="Base_Column_List"/>
		FROM
			x_r_param_attr_basic_data
		WHERE
			deleted = #{deleted}
		AND p_id = #{id}
	</select>

	<update id = "updateByPId">
		UPDATE x_r_param_attr_basic_data
		SET deleted = #{deleted}
		WHERE
			p_id = #{pId}
	</update>

	<select id = "findChildList" parameterType = "com.huatek.busi.where.RParamAttrBasicDataSelectVo" resultType = "com.huatek.busi.dto.RParamAttrBasicDataDto">
		SELECT
			A.id,
			A.p_id AS pId,
			A.dis_param_value AS disParamValue,
			A.unit,
			A.assess_field_rule as assessFieldRule,
			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.dname
		FROM
			x_r_param_attr_basic_data A
		LEFT JOIN sys_dictionnaire_detail B ON A.unit = B.dcode
		LEFT JOIN sys_dictionnaire C ON B.pid = C.`id`
		WHERE
			A.deleted = 0
		AND B.deleted = 0
		AND C.deleted = 0
		AND C.`code` = 'IEC_O_UNIT'
		and A.p_id = #{pId}
		<if test="disParamValue != null and disParamValue != '' ">
			and A.dis_param_value like CONCAT('%', #{disParamValue}, '%')
		</if>
	</select>

	<select id="findByPIdAndDisParam" parameterType="java.lang.String" resultType="com.huatek.busi.dto.RParamAttrBasicDataDto">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_param_attr_basic_data
		WHERE
		deleted = 0
		<if test="pId != null and pId != '' ">
			and p_id = #{pId}
		</if>
		<if test="disParamValue != null and disParamValue != '' ">
			and dis_param_value = #{disParamValue}
		</if>
	</select>

	<select id="findRParamAttrBasicData" parameterType="java.lang.String" resultType="com.huatek.busi.entity.RParamAttrBasicData">
		SELECT
			*
		FROM
			x_r_param_attr_basic_data A
		LEFT JOIN x_r_param_basic_data B ON A.p_id = B.id
		WHERE
			A.deleted = 0
		AND B.deleted = 0
		AND B.param_value = #{testItem}
		AND A.dis_param_value = #{offlineParam}
		and B.main_equ_id = #{mainEquId}
	</select>

	<select id="findMaxAssessFieldRule" resultType="java.lang.Long">
		SELECT
			MAX(
				CONVERT (assess_field_rule, UNSIGNED)
			) AS assessFieldRule
		FROM
			x_r_param_attr_basic_data
		WHERE
			deleted = 0
	</select>
</mapper>
