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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.ELECTRICITY_ID,
		f.CORPINFO_ID,
        f.TASK_ID,
        f.STEP_REASON,
        f.STEP_ID,
        f.ISDELETE,
        f.CREATTIME,
        f.CREATOR,
        f.OPERATTIME,
        f.OPERATOR,
        f.CHECK_NO,
		f.APPLY_DEPARTMENT_ID,
		f.APPLY_USER_ID,
		f.WORK_START_DATE,
		f.WORK_END_DATE,
		f.WORK_PLACE,
		f.WORK_CONTENT,
		f.SPECIAL_WORK,
		f.RISK_IDENTIFICATION,
		f.CARD_NO,
		f.ALLOW_POWER,
		f.WORK_VOLTAGE,
		f.RATED_POWER,
		f.ELECTRICITY_USER_ID,
		f.ELECTRICITY_DEPARTMENT_ID,
		f.WORK_USER_ID,
		f.WORK_DEPARTMENT_ID,
		f.ANALYZE_TIME,
		f.ISANALYZE,
		f.ANALYZE_DEPARTMENT_ID,
		f.ANALYZE_USER_ID,
		f.CONFESS_DEPARTMENT_ID,
		f.CONFESS_USER_ID,
		f.ACCEPT_CONFESS_DEPARTMENT_ID,
		f.ACCEPT_CONFESS_USER_ID,
		f.GUARDIAN_DEPARTMENT_ID,
		f.GUARDIAN_USER_ID,
		f.CONFIRM_DEPARTMENT_ID,
		f.CONFIRM_USER_ID,
		f.LEADER_CARD_NO,
		f.AUDIT_DEPARTMENT_ID,
		f.AUDIT_USER_ID,
		f.APPROVE_DEPARTMENT_ID,
		f.APPROVE_USER_ID,
		f.ACCEPT_DEPARTMENT_ID,
		f.ACCEPT_USER_ID,
		f.WORK_START_DEPARTMENT_ID,
		f.WORK_START_USER_ID,
		f.WORK_END_DEPARTMENT_ID,
		f.WORK_END_USER_ID,
		f.ACCEPT_TIME,
		f.PLS_ID,
		f.PLS_NAME,
		f.WORK_POSITION,
		f.VIDEO_PATH
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		ELECTRICITY_ID,
		CORPINFO_ID,
        TASK_ID,
        STEP_ID,
        ISDELETE,
        CREATTIME,
        CREATOR,
        OPERATTIME,
        OPERATOR,
        CHECK_NO,
		APPLY_DEPARTMENT_ID,
		APPLY_USER_ID,
		WORK_START_DATE,
		WORK_END_DATE,
		WORK_PLACE,
		WORK_CONTENT,
		SPECIAL_WORK,
		RISK_IDENTIFICATION,
		CARD_NO,
		ALLOW_POWER,
		WORK_VOLTAGE,
		RATED_POWER,
		ELECTRICITY_USER_ID,
		ELECTRICITY_DEPARTMENT_ID,
		WORK_USER_ID,
		WORK_DEPARTMENT_ID,
		ANALYZE_TIME,
		ISANALYZE,
		ANALYZE_DEPARTMENT_ID,
		ANALYZE_USER_ID,
		CONFESS_DEPARTMENT_ID,
		CONFESS_USER_ID,
		ACCEPT_CONFESS_DEPARTMENT_ID,
		ACCEPT_CONFESS_USER_ID,
		GUARDIAN_DEPARTMENT_ID,
		GUARDIAN_USER_ID,
		CONFIRM_DEPARTMENT_ID,
		CONFIRM_USER_ID,
		LEADER_CARD_NO,
		AUDIT_DEPARTMENT_ID,
		AUDIT_USER_ID,
		APPROVE_DEPARTMENT_ID,
		APPROVE_USER_ID,
		ACCEPT_DEPARTMENT_ID,
		ACCEPT_USER_ID,
		WORK_START_DEPARTMENT_ID,
		WORK_START_USER_ID,
		WORK_END_DEPARTMENT_ID,
		WORK_END_USER_ID,
		ACCEPT_TIME,
		PLS_ID,
		PLS_NAME,
		WORK_POSITION,
		VIDEO_PATH
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{ELECTRICITY_ID},
		#{CORPINFO_ID},
        #{TASK_ID},
        #{STEP_ID},
        #{ISDELETE},
        #{CREATTIME},
        #{CREATOR},
        #{OPERATTIME},
        #{OPERATOR},
        #{CHECK_NO},
		#{APPLY_DEPARTMENT_ID},
		#{APPLY_USER_ID},
		#{WORK_START_DATE},
		#{WORK_END_DATE},
		#{WORK_PLACE},
		#{WORK_CONTENT},
		#{SPECIAL_WORK},
		#{RISK_IDENTIFICATION},
		#{CARD_NO},
		#{ALLOW_POWER},
		#{WORK_VOLTAGE},
		#{RATED_POWER},
		#{ELECTRICITY_USER_ID},
		#{ELECTRICITY_DEPARTMENT_ID},
		#{WORK_USER_ID},
		#{WORK_DEPARTMENT_ID},
		#{ANALYZE_TIME},
		#{ISANALYZE},
		#{ANALYZE_DEPARTMENT_ID},
		#{ANALYZE_USER_ID},
		#{CONFESS_DEPARTMENT_ID},
		#{CONFESS_USER_ID},
		#{ACCEPT_CONFESS_DEPARTMENT_ID},
		#{ACCEPT_CONFESS_USER_ID},
		#{GUARDIAN_DEPARTMENT_ID},
		#{GUARDIAN_USER_ID},
		#{CONFIRM_DEPARTMENT_ID},
		#{CONFIRM_USER_ID},
		#{LEADER_CARD_NO},
		#{AUDIT_DEPARTMENT_ID},
		#{AUDIT_USER_ID},
		#{APPROVE_DEPARTMENT_ID},
		#{APPROVE_USER_ID},
		#{ACCEPT_DEPARTMENT_ID},
		#{ACCEPT_USER_ID},
		#{WORK_START_DEPARTMENT_ID},
		#{WORK_START_USER_ID},
		#{WORK_END_DEPARTMENT_ID},
		#{WORK_END_USER_ID},
		#{ACCEPT_TIME},
		#{PLS_ID},
		#{PLS_NAME},
		#{WORK_POSITION},
		#{VIDEO_PATH}
	</sql>

	<!-- 获取编码 -->
	<select id="getCode" parameterType="pd" resultType="pd">
		SELECT
		COUNT(1) as code
		FROM <include refid="tableName"></include> f
		WHERE f.CORPINFO_ID = #{CORPINFO_ID}
		and f.CREATTIME LIKE CONCAT(#{CREATDATE},'%')
	</select>

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

	<!-- 删除-->
	<delete id="delete" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			ELECTRICITY_ID = #{ELECTRICITY_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ELECTRICITY_ID = #{ELECTRICITY_ID},
		CORPINFO_ID = #{CORPINFO_ID},
		TASK_ID = #{TASK_ID},
		STEP_ID = #{STEP_ID},
		ISDELETE = #{ISDELETE},
		CREATTIME = #{CREATTIME},
		CREATOR = #{CREATOR},
		OPERATTIME = #{OPERATTIME},
		OPERATOR = #{OPERATOR},
		CHECK_NO = #{CHECK_NO},
		APPLY_DEPARTMENT_ID = #{APPLY_DEPARTMENT_ID},
		APPLY_USER_ID = #{APPLY_USER_ID},
		WORK_START_DATE = #{WORK_START_DATE},
		WORK_END_DATE = #{WORK_END_DATE},
		WORK_PLACE = #{WORK_PLACE},
		WORK_CONTENT = #{WORK_CONTENT},
		SPECIAL_WORK = #{SPECIAL_WORK},
		RISK_IDENTIFICATION = #{RISK_IDENTIFICATION},
		CARD_NO = #{CARD_NO},
		ALLOW_POWER = #{ALLOW_POWER},
		WORK_VOLTAGE = #{WORK_VOLTAGE},
		RATED_POWER = #{RATED_POWER},
		ELECTRICITY_USER_ID = #{ELECTRICITY_USER_ID},
		ELECTRICITY_DEPARTMENT_ID = #{ELECTRICITY_DEPARTMENT_ID},
		WORK_USER_ID = #{WORK_USER_ID},
		WORK_DEPARTMENT_ID = #{WORK_DEPARTMENT_ID},
		ANALYZE_TIME = #{ANALYZE_TIME},
		ISANALYZE = #{ISANALYZE},
		ANALYZE_DEPARTMENT_ID = #{ANALYZE_DEPARTMENT_ID},
		ANALYZE_USER_ID = #{ANALYZE_USER_ID},
		CONFESS_DEPARTMENT_ID = #{CONFESS_DEPARTMENT_ID},
		CONFESS_USER_ID = #{CONFESS_USER_ID},
		ACCEPT_CONFESS_DEPARTMENT_ID = #{ACCEPT_CONFESS_DEPARTMENT_ID},
		ACCEPT_CONFESS_USER_ID = #{ACCEPT_CONFESS_USER_ID},
		GUARDIAN_DEPARTMENT_ID = #{GUARDIAN_DEPARTMENT_ID},
		GUARDIAN_USER_ID = #{GUARDIAN_USER_ID},
		CONFIRM_DEPARTMENT_ID = #{CONFIRM_DEPARTMENT_ID},
		CONFIRM_USER_ID = #{CONFIRM_USER_ID},
		LEADER_CARD_NO = #{LEADER_CARD_NO},
		AUDIT_DEPARTMENT_ID = #{AUDIT_DEPARTMENT_ID},
		AUDIT_USER_ID = #{AUDIT_USER_ID},
		APPROVE_DEPARTMENT_ID = #{APPROVE_DEPARTMENT_ID},
		APPROVE_USER_ID = #{APPROVE_USER_ID},
		ACCEPT_DEPARTMENT_ID = #{ACCEPT_DEPARTMENT_ID},
		ACCEPT_USER_ID = #{ACCEPT_USER_ID},
		WORK_START_DEPARTMENT_ID = #{WORK_START_DEPARTMENT_ID},
		WORK_START_USER_ID = #{WORK_START_USER_ID},
		WORK_END_DEPARTMENT_ID = #{WORK_END_DEPARTMENT_ID},
		WORK_END_USER_ID = #{WORK_END_USER_ID},
		ACCEPT_TIME = #{ACCEPT_TIME},
		PLS_ID = #{PLS_ID},
		PLS_NAME = #{PLS_NAME},
		WORK_POSITION = #{WORK_POSITION},
		VIDEO_PATH = #{VIDEO_PATH}
		where
			ELECTRICITY_ID = #{ELECTRICITY_ID}
	</update>

	<update id="editGasTime" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ANALYZE_TIME = #{ANALYZE_TIME}
		where
		ELECTRICITY_ID = #{ELECTRICITY_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		f.ELECTRICITY_ID,
		f.CORPINFO_ID,
		f.TASK_ID,
		f.STEP_ID,
		f.STEP_REASON,
		f.ISDELETE,
		f.CREATTIME,
		f.CREATOR,
		f.OPERATTIME,
		f.OPERATOR,
		f.CHECK_NO,
		f.APPLY_DEPARTMENT_ID,
		f.APPLY_USER_ID,
		f.WORK_START_DATE,
		f.WORK_END_DATE,
		f.WORK_PLACE,
		f.WORK_CONTENT,
		f.RISK_IDENTIFICATION,
		f.CARD_NO,
		f.ALLOW_POWER,
		f.WORK_VOLTAGE,
		f.RATED_POWER,
		f.ELECTRICITY_USER_ID,
		f.ELECTRICITY_DEPARTMENT_ID,
		f.WORK_USER_ID,
		f.WORK_DEPARTMENT_ID,
		f.ANALYZE_TIME,
		f.ISANALYZE,
		f.ANALYZE_DEPARTMENT_ID,
		f.ANALYZE_USER_ID,
		f.CONFESS_DEPARTMENT_ID,
		f.CONFESS_USER_ID,
		f.ACCEPT_CONFESS_DEPARTMENT_ID,
		f.ACCEPT_CONFESS_USER_ID,
		f.GUARDIAN_DEPARTMENT_ID,
		f.GUARDIAN_USER_ID,
		f.CONFIRM_DEPARTMENT_ID,
		f.CONFIRM_USER_ID,
		f.LEADER_CARD_NO,
		f.AUDIT_DEPARTMENT_ID,
		f.AUDIT_USER_ID,
		f.APPROVE_DEPARTMENT_ID,
		f.APPROVE_USER_ID,
		f.ACCEPT_DEPARTMENT_ID,
		f.ACCEPT_USER_ID,
		f.WORK_START_DEPARTMENT_ID,
		f.WORK_START_USER_ID,
		f.WORK_END_DEPARTMENT_ID,
		f.WORK_END_USER_ID,
		f.ACCEPT_TIME,
		f.PLS_ID,
		f.PLS_NAME,
		f.WORK_POSITION,
		f.VIDEO_PATH,
		IFNULL(f.SPECIAL_WORK,'无') as SPECIAL_WORK,

		ad.NAME as APPLY_DEPARTMENT_NAME,
		au.NAME as APPLY_USER_NAME,

		cd.NAME as CONFIRM_DEPARTMENT_NAME,
		cu.NAME as CONFIRM_USER_NAME,

		aud.NAME as AUDIT_DEPARTMENT_NAME,
		auu.NAME as AUDIT_USER_NAME,

		apd.NAME as APPROVE_DEPARTMENT_NAME,
		apu.NAME as APPROVE_USER_NAME,

		acd.NAME as ACCEPT_DEPARTMENT_NAME,
		acu.NAME as ACCEPT_USER_NAME,

		anad.NAME as ANALYZE_DEPARTMENT_NAME,
		anau.NAME as ANALYZE_USER_NAME,

		ac.NAME as CONFESS_DEPARTMENT_NAME,
		accu.NAME as CONFESS_USER_NAME,

		aac.NAME as ACCEPT_CONFESS_DEPARTMENT_NAME,
		aacu.NAME as ACCEPT_CONFESS_USER_NAME,

		bc.NAME as GUARDIAN_DEPARTMENT_NAME,
		bcu.NAME as GUARDIAN_USER_NAME,

		woro.`NAME` as WORK_USER_DEPARTMENT_NAME,
		woru.`NAME` as WORK_USER_USER_NAME,

		stao.`NAME` as WORK_START_DEPARTMENT_NAME,
		stau.`NAME` as WORK_START_USER_NAME,

		endo.`NAME` as WORK_END_DEPARTMENT_NAME,
		endu.`NAME` as WORK_END_USER_NAME,

		eleo.`NAME` as ELECTRICITY_DEPARTMENT_NAME,
		eleu.`NAME` as ELECTRICITY_USER_NAME

		from
		<include refid="tableName"></include> f
		left join OA_DEPARTMENT bc on bc.DEPARTMENT_ID = f.GUARDIAN_DEPARTMENT_ID
		left join SYS_USER bcu on bcu.USER_ID = f.GUARDIAN_USER_ID

		left join oa_department as woro on f.WORK_DEPARTMENT_ID = woro.DEPARTMENT_ID
		left join sys_user as woru on f.WORK_USER_ID = woru.USER_ID

		left join OA_DEPARTMENT aac on aac.DEPARTMENT_ID = f.ACCEPT_CONFESS_DEPARTMENT_ID
		left join SYS_USER aacu on aacu.USER_ID = f.ACCEPT_CONFESS_USER_ID

		left join OA_DEPARTMENT ac on ac.DEPARTMENT_ID = f.CONFESS_DEPARTMENT_ID
		left join SYS_USER accu on accu.USER_ID = f.CONFESS_USER_ID

		left join OA_DEPARTMENT ad on ad.DEPARTMENT_ID = f.APPLY_DEPARTMENT_ID
		left join SYS_USER au on au.USER_ID = f.APPLY_USER_ID

		left join OA_DEPARTMENT cd on cd.DEPARTMENT_ID = f.CONFIRM_DEPARTMENT_ID
		left join SYS_USER cu on cu.USER_ID = f.CONFIRM_USER_ID

		left join OA_DEPARTMENT aud on aud.DEPARTMENT_ID = f.AUDIT_DEPARTMENT_ID
		left join SYS_USER auu on auu.USER_ID = f.AUDIT_USER_ID

		left join OA_DEPARTMENT apd on apd.DEPARTMENT_ID = f.APPROVE_DEPARTMENT_ID
		left join SYS_USER apu on apu.USER_ID = f.APPROVE_USER_ID

		left join OA_DEPARTMENT acd on acd.DEPARTMENT_ID = f.ACCEPT_DEPARTMENT_ID
		left join SYS_USER acu on acu.USER_ID = f.ACCEPT_USER_ID

		left join OA_DEPARTMENT anad on anad.DEPARTMENT_ID = f.ANALYZE_DEPARTMENT_ID
		left join SYS_USER anau on anau.USER_ID = f.ANALYZE_USER_ID

		left join oa_department as stao on f.WORK_START_DEPARTMENT_ID = stao.DEPARTMENT_ID
		left join sys_user as stau on f.WORK_START_USER_ID = stau.USER_ID

		left join oa_department as endo on f.WORK_END_DEPARTMENT_ID = endo.DEPARTMENT_ID
		left join sys_user as endu on f.WORK_END_USER_ID = endu.USER_ID

		left join oa_department as eleo on f.ELECTRICITY_DEPARTMENT_ID = eleo.DEPARTMENT_ID
		left join sys_user as eleu on f.ELECTRICITY_USER_ID = eleu.USER_ID
		where
			f.ELECTRICITY_ID = #{ELECTRICITY_ID}
	</select>

	<update id="editVideo" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		VIDEO_PATH = #{VIDEO_PATH}
		where
		ELECTRICITY_ID = #{ELECTRICITY_ID}
	</update>

	<!-- 修改 -->
	<update id="editStep" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		<if test="WORK_START_DATE != null and WORK_START_DATE != ''"><!-- 关键词检索 -->
			WORK_START_DATE = #{WORK_START_DATE},
		</if>
		<if test="STEP_REASON != null and STEP_REASON != ''"><!-- 关键词检索 -->
			STEP_REASON = #{STEP_REASON},
		</if>
		<if test="WORK_END_DATE != null and WORK_END_DATE != ''"><!-- 关键词检索 -->
			WORK_END_DATE = #{WORK_END_DATE},
		</if>
		<if test="ACCEPT_TIME != null and ACCEPT_TIME != ''"><!-- 关键词检索 -->
			ACCEPT_TIME = #{ACCEPT_TIME},
		</if>
		STEP_ID = #{STEP_ID}
		where
		ELECTRICITY_ID = #{ELECTRICITY_ID}
	</update>

	<!-- 修改位置 -->
	<update id="setPosition" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		WORK_POSITION = #{WORK_POSITION}
		where
		ELECTRICITY_ID = #{ELECTRICITY_ID}
	</update>


	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>,

		ad.NAME as APPLY_DEPARTMENT_NAME,
		au.NAME as APPLY_USER_NAME,

		cd.NAME as CONFIRM_DEPARTMENT_NAME,
		cu.NAME as CONFIRM_USER_NAME,

		aud.NAME as AUDIT_DEPARTMENT_NAME,
		auu.NAME as AUDIT_USER_NAME,

		apd.NAME as APPROVE_DEPARTMENT_NAME,
		apu.NAME as APPROVE_USER_NAME,

		acd.NAME as ACCEPT_DEPARTMENT_NAME,
		acu.NAME as ACCEPT_USER_NAME,

		anad.NAME as ANALYZE_DEPARTMENT_NAME,
		anau.NAME as ANALYZE_USER_NAME,

		ac.NAME as CONFESS_DEPARTMENT_NAME,
		accu.NAME as CONFESS_USER_NAME,

		aac.NAME as ACCEPT_CONFESS_DEPARTMENT_NAME,
		aacu.NAME as ACCEPT_CONFESS_USER_NAME,

		bc.NAME as GUARDIAN_DEPARTMENT_NAME,
		bcu.NAME as GUARDIAN_USER_NAME,

		woro.`NAME` as WORK_USER_DEPARTMENT_NAME,
		woru.`NAME` as WORK_USER_USER_NAME,

		stao.`NAME` as WORK_START_DEPARTMENT_NAME,
		stau.`NAME` as WORK_START_USER_NAME,

		endo.`NAME` as WORK_END_DEPARTMENT_NAME,
		endu.`NAME` as WORK_END_USER_NAME,

		eleo.`NAME` as ELECTRICITY_DEPARTMENT_NAME,
		eleu.`NAME` as ELECTRICITY_USER_NAME,

		log.STEP_NAME,
		flow.NEXT_STEP_ID,
		n.STEP_NAME as NEXT_STEP_NAME,
		log.STATUS
		from
		<include refid="tableName"></include> f
		left join OA_DEPARTMENT bc on bc.DEPARTMENT_ID = f.GUARDIAN_DEPARTMENT_ID
		left join SYS_USER bcu on bcu.USER_ID = f.GUARDIAN_USER_ID

		left join oa_department as woro on f.WORK_DEPARTMENT_ID = woro.DEPARTMENT_ID
		left join sys_user as woru on f.WORK_USER_ID = woru.USER_ID

		left join OA_DEPARTMENT aac on aac.DEPARTMENT_ID = f.ACCEPT_CONFESS_DEPARTMENT_ID
		left join SYS_USER aacu on aacu.USER_ID = f.ACCEPT_CONFESS_USER_ID

		left join OA_DEPARTMENT ac on ac.DEPARTMENT_ID = f.CONFESS_DEPARTMENT_ID
		left join SYS_USER accu on accu.USER_ID = f.CONFESS_USER_ID

		left join OA_DEPARTMENT ad on ad.DEPARTMENT_ID = f.APPLY_DEPARTMENT_ID
		left join SYS_USER au on au.USER_ID = f.APPLY_USER_ID

		left join OA_DEPARTMENT cd on cd.DEPARTMENT_ID = f.CONFIRM_DEPARTMENT_ID
		left join SYS_USER cu on cu.USER_ID = f.CONFIRM_USER_ID

		left join OA_DEPARTMENT aud on aud.DEPARTMENT_ID = f.AUDIT_DEPARTMENT_ID
		left join SYS_USER auu on auu.USER_ID = f.AUDIT_USER_ID

		left join OA_DEPARTMENT apd on apd.DEPARTMENT_ID = f.APPROVE_DEPARTMENT_ID
		left join SYS_USER apu on apu.USER_ID = f.APPROVE_USER_ID

		left join OA_DEPARTMENT acd on acd.DEPARTMENT_ID = f.ACCEPT_DEPARTMENT_ID
		left join SYS_USER acu on acu.USER_ID = f.ACCEPT_USER_ID

		left join OA_DEPARTMENT anad on anad.DEPARTMENT_ID = f.ANALYZE_DEPARTMENT_ID
		left join SYS_USER anau on anau.USER_ID = f.ANALYZE_USER_ID

		left join oa_department as stao on f.WORK_START_DEPARTMENT_ID = stao.DEPARTMENT_ID
		left join sys_user as stau on f.WORK_START_USER_ID = stau.USER_ID

		left join oa_department as endo on f.WORK_END_DEPARTMENT_ID = endo.DEPARTMENT_ID
		left join sys_user as endu on f.WORK_END_USER_ID = endu.USER_ID

		left join oa_department as eleo on f.ELECTRICITY_DEPARTMENT_ID = eleo.DEPARTMENT_ID
		left join sys_user as eleu on f.ELECTRICITY_USER_ID = eleu.USER_ID

		left join (	SELECT *
		FROM
		( SELECT *, row_number ( ) over ( PARTITION BY WORK_ID ORDER BY ACT_TIME DESC ) AS rn FROM vi_eightwork_flow_log ) pca
		WHERE
		pca.rn = 1) log on log.WORK_ID = f.ELECTRICITY_ID

		left join bus_eightwork_task_flow flow on flow.STEP_ID = f.STEP_ID and flow.TASK_ID = log.TASK_ID
		left join bus_eightwork_step n on n.STEP_ID = flow.NEXT_STEP_ID
		where f.ISDELETE = '0'
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and f.CHECK_NO LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<if test="pd.STEP_NAME != null and pd.STEP_NAME != ''"><!-- 关键词检索 -->
			and exists (
			select 1 from bus_electricity_sign sign
			left join bus_eightwork_step step on step.STEP_ID = sign.STEP_ID
			where sign.ELECTRICITY_ID = f.ELECTRICITY_ID
			and sign.SIGN_TIME is null
			and sign.SIGN_USER_ID = #{pd.USER_ID}
			and step.STEP_NAME = #{pd.STEP_NAME}
			and f.STEP_ID != -1
			)
		</if>
		<if test="pd.WORK_STATE == '-1'">
			and f.STEP_ID = -1
		</if>
		<if test="pd.WORK_STATE == '0'.toString()">
			and (log.NEXT_STEP_ID is null or log.NEXT_STEP_ID != 99)  and f.STEP_ID != -1
		</if>
		<if test="pd.WORK_STATE== '99'.toString()">
			and log.NEXT_STEP_ID = #{pd.STEP_ID}
		</if>
		<if test="pd.STEP_ID != null and pd.STEP_ID != '' and pd.STEP_ID == '0'.toString()">
			and log.NEXT_STEP_ID is null
		</if>
		<if test="pd.STEP_ID != null and pd.STEP_ID != '' and pd.STEP_ID != '0'.toString()"><!-- 0是查询暂存 -->
			and log.NEXT_STEP_ID = #{pd.STEP_ID} and f.STEP_ID != -1
		</if>
		<if test="pd.CREATOR != null and pd.CREATOR != ''"><!-- 关键词检索 -->
			and f.CREATOR = #{pd.CREATOR}
		</if>
		<if test="pd.GASCHECK != null and pd.GASCHECK != ''"><!-- 关键词检索 -->
			and f.STEP_ID &gt; 0 and f.STEP_ID != 15 and f.ANALYZE_USER_ID = #{pd.GASCHECK}
		</if>
		<if test="pd.APPLY_DEPARTMENT_ID != null and pd.APPLY_DEPARTMENT_ID != ''"><!-- 关键词检索 -->
			and f.APPLY_DEPARTMENT_ID = #{pd.APPLY_DEPARTMENT_ID}
		</if>
		<if test="pd.CONFIRM_DEPARTMENT_ID != null and pd.CONFIRM_DEPARTMENT_ID != ''"><!-- 关键词检索 -->
			and f.CONFIRM_DEPARTMENT_ID = #{pd.CONFIRM_DEPARTMENT_ID}
		</if>
		<if test="pd.WORK_START_DATE != null and pd.WORK_START_DATE != ''"><!-- 关键词检索 -->
			and DATE_FORMAT(f.WORK_START_DATE, '%Y-%m-%d') = #{pd.WORK_START_DATE}
		</if>
		order by f.STEP_ID,f.CREATTIME desc
	</select>


	<select id="checkWorkCount" parameterType="pd" resultType="pd" >
        select
            step.CODE,count(1) COUNT
        from
            bus_electricity_sign sign
        left join bus_eightwork_step step on step.STEP_ID = sign.STEP_ID
        left join bus_electricity work on work.ELECTRICITY_ID = sign.ELECTRICITY_ID
        where
            sign.SIGN_TIME is null
            and work.STEP_ID != '-1'
		  	and work.ISDELETE =0
        and
            sign.SIGN_USER_ID = #{USER_ID}
        group by step.CODE
    </select>

	<select id="listAllMeasures" resultType="pd">
        select
        *
        from
        BUS_ELECTRICITY_MEASURES where ISDELETE = 0
    </select>

	<select id="getFlowList" resultType="pd">
        select
        	flow.CAN_SKIP,
            flow.ACTOR_FIELD,
            step.STEP_NAME,
            user.NAME as ACT_USER_NAME,
            log.ACT_TIME,
            log.STATUS,
            cu.SIGN_USER,
            cu.FINISHED_SIGN_USER,
            cu.STEP_ID as CURRENT_STEP
        from
            bus_eightwork_task_flow flow
        left join bus_eightwork_step step on step.STEP_ID = flow.STEP_ID
        left join bus_eightwork_flow_log log on log.STEP_ID = flow.STEP_ID and
            log.WORK_ID = #{ELECTRICITY_ID}
        left join sys_user user on user.USER_ID = log.ACT_USER
        left join (select sign.STEP_ID,
            GROUP_CONCAT( if(sign.SIGN_TIME IS NULL,signer.NAME,null) ) sign_user,
            GROUP_CONCAT( if(sign.SIGN_TIME IS not NULL,signer.NAME,null) ) finished_sign_user
            from bus_electricity_sign sign
            left join sys_user signer on signer.USER_ID = sign.SIGN_USER_ID where sign.ELECTRICITY_ID = #{ELECTRICITY_ID}
            GROUP BY sign.STEP_ID) cu on cu.STEP_ID = step.STEP_ID
        where
            flow.TASK_ID = #{TASK_ID}
        and
            flow.STEP_ID != 0
        order by
            flow.ORDER_BY
    </select>

	<select id="getMapList" resultType="pd">
		select
		f.ELECTRICITY_ID,
		f.CHECK_NO,
		f.WORK_POSITION
		from
		<include refid="tableName"></include> f
		left join (select * from(select * from vi_eightwork_flow_log log having 1 order by log.ACT_TIME desc
		) tmp group by tmp.WORK_ID) log on log.WORK_ID = f.ELECTRICITY_ID
		where f.ISDELETE = '0' and f.WORK_POSITION is not null
		and f.CORPINFO_ID = #{CORPINFO_ID}
		and f.STEP_ID &gt; 0 and log.NEXT_STEP_ID != 99
	</select>


	<select id="getSpecial" resultType="pd">
		select
			${primaryKey},
		SPECIAL_WORK
		from
			${table}
		where SPECIAL_WORK like CONCAT(CONCAT('%', #{SPECIAL_WORK}),'%')
	</select>

	<update id="updateSpecial" parameterType="pd">
		update
			${table}
		set
		SPECIAL_WORK = #{SPECIAL_WORK}
		where
			${primaryKey} = #{primaryKeyVlu}
	</update>

</mapper>
