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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.TASK_ID,
		f.TASK_NAME
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		TASK_ID,
		TASK_NAME
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{TASK_ID},
		#{TASK_NAME}
	</sql>

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

	<select id="checkWorkCount" parameterType="pd" resultType="pd" >
		select (select count(1) COUNT from bus_hotwork_sign sign
		 left join bus_hotwork work on work.HOTWORK_ID = sign.HOTWORK_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) HOTWORK_COUNT,
		(select count(1) COUNT from bus_confinedspace_sign sign
		 left join bus_confinedspace work on work.CONFINEDSPACE_ID = sign.CONFINEDSPACE_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1'and work.ISDELETE =0 ) CONFINEDSPACE_COUNT,
		 (select count(1) COUNT from bus_highwork_sign sign
		 left join bus_highwork work on work.HIGHWORK_ID = sign.HIGHWORK_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) HIGHWORK_COUNT,
		(select count(1) COUNT from bus_electricity_sign sign
		 left join bus_electricity work on work.ELECTRICITY_ID = sign.ELECTRICITY_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) ELECTRICITY_COUNT,
		 (select count(1) COUNT from bus_breakground_sign sign
		 left join bus_breakground work on work.BREAKGROUND_ID = sign.BREAKGROUND_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) BREAKGROUND_COUNT,
		 (select count(1) COUNT from bus_hoisting_sign sign
		 left join bus_hoisting work on work.HOISTING_ID = sign.HOISTING_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) HOISTING_COUNT,
		  (select count(1) COUNT from bus_cutroad_sign sign
		 left join bus_cutroad work on work.CUTROAD_ID = sign.CUTROAD_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) OPEN_CIRCUIT_COUNT,
		 		  (select count(1) COUNT from bus_blindboard_sign sign
		 left join bus_blindboard work on work.BLINDBOARD_ID = sign.BLINDBOARD_ID
		 where sign.SIGN_TIME is null and sign.SIGN_USER_ID = #{USER_ID} and work.STEP_ID != '-1' and work.ISDELETE =0 ) BLIND_BOARD_COUNT
	</select>

</mapper>
