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

	<sql id="Base_Column_List">
		id,
		site_id as siteId,
		main_equ_id as mainEquId,
		main_equ_name as mainEquName,
		equ_little_type as equLittleType,
		equ_little_id as equLittleId,
		equipment_type as equipmentType,
		ref_id as refId,
		create_user as createUser,
		create_time as createTime,
		update_user as updateUser,
		update_time as updateTime,
		deleted
	</sql>

	<select id="findRMasterDataByEquType" parameterType="java.lang.String" resultType="com.huatek.busi.entity.RMasterData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_master_data
		WHERE
		deleted = 0
		AND equipment_type = #{eqType}
	</select>

	<select id="findRDlDataByEquType" parameterType="java.lang.String" resultType="com.huatek.busi.entity.RMasterData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_cable_data
		WHERE
		deleted = 0
		AND equipment_type = #{eqType}
	</select>

	<select id="findRKggDataByEquType" parameterType="java.lang.String" resultType="com.huatek.busi.entity.RMasterData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_switchgear_data
		WHERE
		deleted = 0
		AND equipment_type = #{eqType}
	</select>

	<select id="findRBlqDataByEquType" parameterType="java.lang.String" resultType="com.huatek.busi.entity.RMasterData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_arrester_data
		WHERE
		deleted = 0
		AND equipment_type = #{eqType}
	</select>

	<select id="findRGenDataByEquType" parameterType="java.lang.String" resultType="com.huatek.busi.entity.RMasterData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_generator_data
		WHERE
		deleted = 0
		AND equipment_type = #{eqType}
	</select>

	<update id="updateByRefIdsAndEquType">
		UPDATE x_r_master_data
		SET deleted = 1
		WHERE
			ref_id IN
		<foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
			#{refId, jdbcType=VARCHAR}
		</foreach>
		AND equipment_type = #{equType}
	</update>

	<update id="updateByIdAndEquType" parameterType="java.lang.String">
		UPDATE x_r_master_data
		SET deleted = 1
		WHERE
			ref_id = #{refId}
		AND equipment_type = #{eqType}
	</update>

	<update id="updateKggByRefIdsAndEquType">
		UPDATE x_r_switchgear_data
		SET deleted = 1
		WHERE
		ref_id IN
		<foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
			#{refId, jdbcType=VARCHAR}
		</foreach>
		AND equipment_type = #{equType}
	</update>

	<update id="updateKggByIdAndEquType" parameterType="java.lang.String">
		UPDATE x_r_switchgear_data
		SET deleted = 1
		WHERE
			ref_id = #{refId}
		AND equipment_type = #{eqType}
	</update>

	<update id="updateDlByRefIdsAndEquType">
		UPDATE x_r_cable_data
		SET deleted = 1
		WHERE
		ref_id IN
		<foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
			#{refId, jdbcType=VARCHAR}
		</foreach>
		AND equipment_type = #{equType}
	</update>

	<update id="updateDlByIdAndEquType" parameterType="java.lang.String">
		UPDATE x_r_cable_data
		SET deleted = 1
		WHERE
			ref_id = #{refId}
		AND equipment_type = #{eqType}
	</update>

	<update id="updateGenByRefIdsAndEquType">
		UPDATE x_r_generator_data
		SET deleted = 1
		WHERE
		ref_id IN
		<foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
			#{refId, jdbcType=VARCHAR}
		</foreach>
		AND equipment_type = #{equType}
	</update>

	<update id="updateGenByIdAndEquType" parameterType="java.lang.String">
		UPDATE x_r_generator_data
		SET deleted = 1
		WHERE
			ref_id = #{refId}
		AND equipment_type = #{eqType}
	</update>

	<update id="updateBlqByRefIdsAndEquType">
		UPDATE x_r_arrester_data
		SET deleted = 1
		WHERE
		ref_id IN
		<foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
			#{refId, jdbcType=VARCHAR}
		</foreach>
		AND equipment_type = #{equType}
	</update>

	<update id="updateBlqByIdAndEquType" parameterType="java.lang.String">
		UPDATE x_r_arrester_data
		SET deleted = 1
		WHERE
			ref_id = #{refId}
		AND equipment_type = #{eqType}
	</update>

	<update id="update">
		UPDATE x_r_master_data
		SET deleted = 1
		WHERE
			id = #{mId}
		AND equipment_type = #{eqType}
	</update>

	<select id="findRMasterByWhere" parameterType="java.util.Map" resultType="com.huatek.busi.entity.RMasterData">
		SELECT
			<include refid="Base_Column_List"/>
		FROM
			x_r_master_data
		WHERE
			site_id = #{siteId}
		AND main_equ_id = #{mvaId}
		AND main_equ_name = #{mvaName}
		AND equ_little_type = #{dCode}
		AND equ_little_id = #{equId}
		AND sheet_name = #{sheetName}
		AND equipment_type = #{eqType}
		AND ref_id = #{refId}
		AND deleted = #{deleted}
	</select>

	<select id="findRBlqByWhere" parameterType="java.util.Map" resultType="com.huatek.busi.entity.RBlqData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_arrester_data
		WHERE
		site_id = #{siteId}
		AND main_equ_id = #{mvaId}
		AND main_equ_name = #{mvaName}
		AND equ_little_type = #{dCode}
		AND equ_little_id = #{equId}
		AND sheet_name = #{sheetName}
		AND equipment_type = #{eqType}
		AND ref_id = #{refId}
		AND deleted = #{deleted}
	</select>

	<select id="findRDlByWhere" parameterType="java.util.Map" resultType="com.huatek.busi.entity.RDlData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_cable_data
		WHERE
		site_id = #{siteId}
		AND main_equ_id = #{mvaId}
		AND main_equ_name = #{mvaName}
		AND equ_little_type = #{dCode}
		AND equ_little_id = #{equId}
		AND sheet_name = #{sheetName}
		AND equipment_type = #{eqType}
		AND ref_id = #{refId}
		AND deleted = #{deleted}
	</select>

	<select id="findRKggByWhere" parameterType="java.util.Map" resultType="com.huatek.busi.entity.RKggData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_switchgear_data
		WHERE
		site_id = #{siteId}
		AND main_equ_id = #{mvaId}
		AND main_equ_name = #{mvaName}
		AND equ_little_type = #{dCode}
		AND equ_little_id = #{equId}
		AND sheet_name = #{sheetName}
		AND equipment_type = #{eqType}
		AND ref_id = #{refId}
		AND deleted = #{deleted}
	</select>

	<select id="findRGenByWhere" parameterType="java.util.Map" resultType="com.huatek.busi.entity.RGenData">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		x_r_generator_data
		WHERE
		site_id = #{siteId}
		AND main_equ_id = #{mvaId}
		AND main_equ_name = #{mvaName}
		AND equ_little_type = #{dCode}
		AND equ_little_id = #{equId}
		AND sheet_name = #{sheetName}
		AND equipment_type = #{eqType}
		AND ref_id = #{refId}
		AND deleted = #{deleted}
	</select>
    <select id="deviceSubclassList" resultType="com.huatek.busi.vo.DeviceSubclassOrTestItemListVo">
		select id,sheet_name as value from x_r_master_data where deleted = 0 and equipment_type = #{equType} group by sheet_name
	</select>
</mapper>
