<?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.modules.map.mapper.MapEightMapper">

	<select id="findEightsByUserIds" resultType="pd">
		SELECT
			*
		FROM
			(
				SELECT
					f.ID,
					f.WORK_NUMBER,
					f.WORK_TYPE,
					u.empNo,
					f.OPERATTIME,
					f.WORK_CONTENT
				FROM
					(
						SELECT
							f.electricity_ID ID,
							f.CHECK_NO WORK_NUMBER,
							'临时用电作业' WORK_TYPE,
							f.WORK_CONTENT,
							f.WORK_USER,
							ifnull( f.OPERATTIME, f.CREATTIME ) OPERATTIME
						FROM
							gf_electricity f
						WHERE
							f.ISDELETE = '0'
						  AND f.APPLY_STATUS != '5'
					) f
						LEFT JOIN sys_user u ON u.`NAME` = f.WORK_USER UNION ALL
				SELECT
					f.ID,
					f.WORK_NUMBER,
					f.WORK_TYPE,
					u.empNo,
					f.OPERATTIME,
					f.WORK_CONTENT
				FROM
					(
						SELECT
							f.blindboard_ID ID,
							f.CHECK_NO WORK_NUMBER,
							'盲板作业' WORK_TYPE,
							'' WORK_CONTENT,
							f.WORK_USER,
							ifnull( f.OPERATTIME, f.CREATTIME ) OPERATTIME
						FROM
							gf_blindboard f
						WHERE
							f.ISDELETE = '0'
						  AND f.APPLY_STATUS != '6'
					) f
						LEFT JOIN sys_user u ON u.`NAME` = f.WORK_USER UNION ALL
				SELECT
					f.ID,
					f.WORK_NUMBER,
					f.WORK_TYPE,
					u.empNo,
					f.OPERATTIME,
					f.WORK_CONTENT
				FROM
					(
						SELECT
							f.confinedspace_ID ID,
							f.CHECK_NO WORK_NUMBER,
							'有限空间作业' WORK_TYPE,
							f.WORK_CONTENT,
							f.WORK_USER,
							ifnull( f.OPERATTIME, f.CREATTIME ) OPERATTIME
						FROM
							gf_confinedspace f
						WHERE
							f.ISDELETE = '0'
						  AND f.APPLY_STATUS != '6'
					) f
						LEFT JOIN sys_user u ON u.`NAME` = f.WORK_USER UNION ALL
				SELECT
					f.ID,
					f.WORK_NUMBER,
					f.WORK_TYPE,
					u.empNo,
					f.OPERATTIME,
					f.WORK_CONTENT
				FROM
					(
						SELECT
							f.hoisting_ID ID,
							f.CHECK_NO WORK_NUMBER,
							'吊装作业' WORK_TYPE,
							f.WORK_CONTENT,
							f.WORK_USER,
							ifnull( f.OPERATTIME, f.CREATTIME ) OPERATTIME
						FROM
							gf_hoisting f
						WHERE
							f.ISDELETE = '0'
						  AND f.APPLY_STATUS != '6'
					) f
						LEFT JOIN sys_user u ON u.`NAME` = f.WORK_USER
			) f
		WHERE f.empNo = #{empNo}
		ORDER BY
			f.OPERATTIME DESC
	</select>

</mapper>
