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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.HOTWORK_ID,
		f.BUS_HOTWORK_MEASURES_ID,
		f.STATUS,
		f.ANSWER1,
		f.ANSWER2,
		f.ANSWER3,
		f.ANSWER4,
		f.HOTWORKTOMEASURES_ID,
		f.CONFIRM_ID,
		f.SIGN_PATH,
	    f.SIGN_TIME,
		f.IMG_PATH
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		HOTWORK_ID,
		BUS_HOTWORK_MEASURES_ID,
		STATUS,
		ANSWER1,
		ANSWER2,
		ANSWER3,
		ANSWER4,
		HOTWORKTOMEASURES_ID,
		CONFIRM_ID,
	    SIGN_PATH,
		IMG_PATH
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{HOTWORK_ID},
		#{BUS_HOTWORK_MEASURES_ID},
		#{STATUS},
		#{ANSWER1},
		#{ANSWER2},
		#{ANSWER3},
		#{ANSWER4},
		#{HOTWORKTOMEASURES_ID},
		#{CONFIRM_ID},
		#{SIGN_PATH},
		#{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>
		(
			HOTWORK_ID,
			BUS_HOTWORK_MEASURES_ID,
			HOTWORKTOMEASURES_ID,
			CONFIRM_ID
		) values
		<foreach collection="list" item="item" index="index" separator="," >
			(
		    	#{item.HOTWORK_ID},
		    	#{item.BUS_HOTWORK_MEASURES_ID},
		    	#{item.HOTWORKTOMEASURES_ID},
		    	#{item.CONFIRM_ID}
			)
		</foreach>
	</insert>

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

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

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where
			f.HOTWORKTOMEASURES_ID = #{HOTWORKTOMEASURES_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
			HOTWORKTOMEASURES_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.HOTWORKTOMEASURES_ID,
			m.*
		from
		<include refid="tableName"></include> f
		left join bus_hotwork_measures m on f.BUS_HOTWORK_MEASURES_ID = m.BUS_HOTWORK_MEASURES_ID
		where
		f.HOTWORK_ID = #{HOTWORK_ID} and f.CONFIRM_ID = #{CONFIRM_ID}
	</select>

	<select id="listSignFinishMeasures" parameterType="pd" resultType="pd">
		select
		f.HOTWORK_ID,
		f.BUS_HOTWORK_MEASURES_ID,
		f.STATUS,
		IFNULL(f.ANSWER1,0) as ANSWER1,
		IFNULL(f.ANSWER2,0) as ANSWER2,
		IFNULL(f.ANSWER3,0) as ANSWER3,
		IFNULL(f.ANSWER4,0) as ANSWER4,
		f.HOTWORKTOMEASURES_ID,
		f.CONFIRM_ID,
		f.SIGN_PATH,
		f.SIGN_TIME,
		f.IMG_PATH,
		m.*
		from
		<include refid="tableName"></include> f
		left join bus_hotwork_measures m on f.BUS_HOTWORK_MEASURES_ID = m.BUS_HOTWORK_MEASURES_ID
		where
		f.HOTWORK_ID = #{HOTWORK_ID}
	</select>

</mapper>
