<?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.zcloud.mapper.datasource.eightwork.ElectricityToMeasuresMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_ELECTRICITYTOMEASURES
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		SYS_DICTIONARIES
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		f.ELECTRICITY_ID,
		f.BUS_ELECTRICITY_MEASURES_ID,
		f.STATUS,
		f.ELECTRICITYTOMEASURES_ID,
		f.CONFIRM_ID,
		f.SIGN_PATH,
	    f.SIGN_TIME,
		f.IMG_PATH
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		ELECTRICITY_ID,
		BUS_ELECTRICITY_MEASURES_ID,
		STATUS,
		ELECTRICITYTOMEASURES_ID,
		CONFIRM_ID,
	    SIGN_PATH,
	    SIGN_TIME,
		IMG_PATH
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{ELECTRICITY_ID},
		#{BUS_ELECTRICITY_MEASURES_ID},
		#{STATUS},
		#{ELECTRICITYTOMEASURES_ID},
		#{CONFIRM_ID},
		#{SIGN_PATH},
		#{SIGN_TIME},
		#{IMG_PATH}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<insert id="saveBatch" parameterType="pd">
		insert into
		<include refid="tableName"></include>
		(
			ELECTRICITY_ID,
			BUS_ELECTRICITY_MEASURES_ID,
			ELECTRICITYTOMEASURES_ID,
			CONFIRM_ID
		) values
		<foreach collection="list" item="item" index="index" separator="," >
			(
		    	#{item.ELECTRICITY_ID},
		    	#{item.BUS_ELECTRICITY_MEASURES_ID},
		    	#{item.ELECTRICITYTOMEASURES_ID},
		    	#{item.CONFIRM_ID}
			)
		</foreach>
	</insert>

	<!-- 删除-->
	<delete id="delete" parameterType="pd">
		delete from
		<include refid="tableName"></include>
		where
		ELECTRICITY_ID = #{ELECTRICITY_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			STATUS = #{STATUS},
		    SIGN_PATH = #{SIGN_PATH},
			IMG_PATH = #{IMG_PATH},
			SIGN_TIME = #{SIGN_TIME}
		where
			ELECTRICITYTOMEASURES_ID = #{ELECTRICITYTOMEASURES_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where
			f.ELECTRICITYTOMEASURES_ID = #{ELECTRICITYTOMEASURES_ID}
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
	</select>

	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			ELECTRICITYTOMEASURES_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>


	<select id="listAllMeasuresForSign" parameterType="pd" resultType="pd">
		select
			f.ELECTRICITYTOMEASURES_ID,
			m.*
		from
		<include refid="tableName"></include> f
		left join bus_electricity_measures m on f.BUS_ELECTRICITY_MEASURES_ID = m.BUS_ELECTRICITY_MEASURES_ID
		where
		f.ELECTRICITY_ID = #{ELECTRICITY_ID} and f.CONFIRM_ID = #{CONFIRM_ID}
	</select>

	<select id="listSignFinishMeasures" parameterType="pd" resultType="pd">
		select
			<include refid="Field"></include>,
		    m.*
		from
		<include refid="tableName"></include> f
		left join bus_electricity_measures m on f.BUS_ELECTRICITY_MEASURES_ID = m.BUS_ELECTRICITY_MEASURES_ID
		where
		f.ELECTRICITY_ID = #{ELECTRICITY_ID}
	</select>

</mapper>
