<?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.HoistingMapper">
    <!--表名 -->
    <sql id="tableName">
        BUS_HOISTING
    </sql>

    <!-- 字段 -->
    <sql id="Field">
        f.HOISTING_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.WORK_PLACE,
        f.TOOL_NAME,
        f.WORK_USER_DEPARTMENT_ID,
        f.WORK_USER_ID,
        f.SISUO_USER_ID,
        f.SISUO_DEPARTMENT_ID,
        f.PROJECT_MANAGER_USER_ID,
        f.PROJECT_MANAGER_DEPARTMENT_ID,
        f.PART_WEIGHT,
        f.WORK_LEVEL,
        f.WORK_CONTENT,
        f.SPECIAL_WORK,
        f.RISK_IDENTIFICATION,
        f.WORK_START_DATE,
        f.WORK_END_DATE,
        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_DEPARTMENT_ID,
        f.LEADER_USER_ID,
        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,
        f.APPLY_DEPARTMENT_ID,
        f.APPLY_USER_ID
    </sql>

    <!-- 字段用于新增 -->
    <sql id="Field2">
        HOISTING_ID,
        CORPINFO_ID,
        TASK_ID,
        STEP_ID,
        ISDELETE,
        CREATTIME,
        CREATOR,
        OPERATTIME,
        OPERATOR,
        CHECK_NO,
        WORK_PLACE,
        TOOL_NAME,
        WORK_USER_DEPARTMENT_ID,
        WORK_USER_ID,
        SISUO_USER_ID,
        SISUO_DEPARTMENT_ID,
        PROJECT_MANAGER_USER_ID,
        PROJECT_MANAGER_DEPARTMENT_ID,
        PART_WEIGHT,
        WORK_LEVEL,
        WORK_CONTENT,
        SPECIAL_WORK,
        RISK_IDENTIFICATION,
        WORK_START_DATE,
        WORK_END_DATE,
        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_DEPARTMENT_ID,
        LEADER_USER_ID,
        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,
        APPLY_DEPARTMENT_ID,
        APPLY_USER_ID
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{HOISTING_ID},
        #{CORPINFO_ID},
        #{TASK_ID},
        #{STEP_ID},
        #{ISDELETE},
        #{CREATTIME},
        #{CREATOR},
        #{OPERATTIME},
        #{OPERATOR},
        #{CHECK_NO},
        #{WORK_PLACE},
        #{TOOL_NAME},
        #{WORK_USER_DEPARTMENT_ID},
        #{WORK_USER_ID},
        #{SISUO_USER_ID},
        #{SISUO_DEPARTMENT_ID},
        #{PROJECT_MANAGER_USER_ID},
        #{PROJECT_MANAGER_DEPARTMENT_ID},
        #{PART_WEIGHT},
        #{WORK_LEVEL},
        #{WORK_CONTENT},
        #{SPECIAL_WORK},
        #{RISK_IDENTIFICATION},
        #{WORK_START_DATE},
        #{WORK_END_DATE},
        #{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_DEPARTMENT_ID},
        #{LEADER_USER_ID},
        #{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},
        #{APPLY_DEPARTMENT_ID},
        #{APPLY_USER_ID}
    </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
            HOISTING_ID = #{HOISTING_ID}
    </delete>

    <!-- 修改 -->
    <update id="edit" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        HOISTING_ID = #{HOISTING_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},
        WORK_PLACE = #{WORK_PLACE},
        TOOL_NAME = #{TOOL_NAME},
        WORK_USER_DEPARTMENT_ID = #{WORK_USER_DEPARTMENT_ID},
        WORK_USER_ID = #{WORK_USER_ID},
        SISUO_USER_ID = #{SISUO_USER_ID},
        SISUO_DEPARTMENT_ID = #{SISUO_DEPARTMENT_ID},
        PROJECT_MANAGER_USER_ID = #{PROJECT_MANAGER_USER_ID},
        PROJECT_MANAGER_DEPARTMENT_ID = #{PROJECT_MANAGER_DEPARTMENT_ID},
        PART_WEIGHT = #{PART_WEIGHT},
        WORK_LEVEL = #{WORK_LEVEL},
        WORK_CONTENT = #{WORK_CONTENT},
        SPECIAL_WORK = #{SPECIAL_WORK},
        RISK_IDENTIFICATION = #{RISK_IDENTIFICATION},
        WORK_START_DATE = #{WORK_START_DATE},
        WORK_END_DATE = #{WORK_END_DATE},
        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_DEPARTMENT_ID = #{LEADER_DEPARTMENT_ID},
        LEADER_USER_ID = #{LEADER_USER_ID},
        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},
        APPLY_DEPARTMENT_ID = #{APPLY_DEPARTMENT_ID},
        APPLY_USER_ID = #{APPLY_USER_ID}
        where
            HOISTING_ID = #{HOISTING_ID}
    </update>


    <select id="findById" parameterType="pd" resultType="pd">
        SELECT
            siso.`NAME` as SISUO_DEPARTMENT_NAME,
            sisu.`NAME` as SISUO_USER_NAME,
            f.HOISTING_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.WORK_PLACE,
            f.TOOL_NAME,
            f.WORK_USER_DEPARTMENT_ID,
            f.WORK_USER_ID,
            f.SISUO_USER_ID,
            f.SISUO_DEPARTMENT_ID,
            f.PROJECT_MANAGER_USER_ID,
            f.PROJECT_MANAGER_DEPARTMENT_ID,
            f.PART_WEIGHT,
            f.WORK_LEVEL,
            f.WORK_CONTENT,
            f.RISK_IDENTIFICATION,
            f.WORK_START_DATE,
            f.WORK_END_DATE,
            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_DEPARTMENT_ID,
            f.LEADER_USER_ID,
            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,
            f.APPLY_DEPARTMENT_ID,
            f.APPLY_USER_ID,
            IFNULL(f.SPECIAL_WORK,'无') as SPECIAL_WORK,
            appo.`NAME` as APPLY_DEPARTMENT_NAME,
            appu.`NAME` as APPLY_USER_NAME,
            woro.`NAME` as WORK_USER_DEPARTMENT_NAME,
            woru.`NAME` as WORK_USER_USER_NAME,
            cono.`NAME` as CONFESS_DEPARTMENT_NAME,
            conu.`NAME` as CONFESS_USER_NAME,
            acco.`NAME` as ACCEPT_CONFESS_DEPARTMENT_NAME,
            accu.`NAME` as ACCEPT_CONFESS_USER_NAME,
            guao.`NAME` as GUARDIAN_DEPARTMENT_NAME,
            guau.`NAME` as GUARDIAN_USER_NAME,
            confo.`NAME` as CONFIRM_DEPARTMENT_NAME,
            confu.`NAME` as CONFIRM_USER_NAME,
            leao.`NAME` as LEADER_DEPARTMENT_NAME,
            leau.`NAME` as LEADER_USER_NAME,
            audo.`NAME` as AUDIT_DEPARTMENT_NAME,
            audu.`NAME` as AUDIT_USER_NAME,
            appro.`NAME` as APPROVE_DEPARTMENT_NAME,
            appru.`NAME` as APPROVE_USER_NAME,
            acceo.`NAME` as ACCEPT_DEPARTMENT_NAME,
            acceu.`NAME` as ACCEPT_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,
            proo.`NAME` as PROJECT_MANAGER_DEPARTMENT_NAME,
            prou.`NAME` as PROJECT_MANAGER_USER_NAME
        FROM
            bus_hoisting AS f
            left join oa_department as siso on f.SISUO_DEPARTMENT_ID = siso.DEPARTMENT_ID
            left join sys_user as sisu on f.SISUO_USER_ID = sisu.USER_ID

            left join oa_department as appo on f.APPLY_DEPARTMENT_ID = appo.DEPARTMENT_ID
            left join sys_user as appu on f.APPLY_USER_ID = appu.USER_ID

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

            left join oa_department as proo on f.PROJECT_MANAGER_DEPARTMENT_ID = proo.DEPARTMENT_ID
            left join sys_user as prou on f.PROJECT_MANAGER_USER_ID = prou.USER_ID

            left join oa_department as cono on f.CONFESS_DEPARTMENT_ID = cono.DEPARTMENT_ID
            left join sys_user as conu on f.CONFESS_USER_ID = conu.USER_ID

            left join oa_department as acco on f.ACCEPT_CONFESS_DEPARTMENT_ID = acco.DEPARTMENT_ID
            left join sys_user as accu on f.ACCEPT_CONFESS_USER_ID = accu.USER_ID

            left join oa_department as guao on f.GUARDIAN_DEPARTMENT_ID = guao.DEPARTMENT_ID
            left join sys_user as guau on f.GUARDIAN_USER_ID = guau.USER_ID

            left join oa_department as confo on f.CONFIRM_DEPARTMENT_ID = confo.DEPARTMENT_ID
            left join sys_user as confu on f.CONFIRM_USER_ID = confu.USER_ID

            left join oa_department as leao on f.LEADER_DEPARTMENT_ID = leao.DEPARTMENT_ID
            left join sys_user as leau on f.LEADER_USER_ID = leau.USER_ID

            left join oa_department as audo on f.AUDIT_DEPARTMENT_ID = audo.DEPARTMENT_ID
            left join sys_user as audu on f.AUDIT_USER_ID = audu.USER_ID

            left join oa_department as appro on f.APPROVE_DEPARTMENT_ID = appro.DEPARTMENT_ID
            left join sys_user as appru on f.APPROVE_USER_ID = appru.USER_ID

            left join oa_department as acceo on f.ACCEPT_DEPARTMENT_ID = acceo.DEPARTMENT_ID
            left join sys_user as acceu on f.ACCEPT_USER_ID = acceu.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

        WHERE f.HOISTING_ID = #{HOISTING_ID}
    </select>

    <update id="editVideo" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        VIDEO_PATH = #{VIDEO_PATH}
        where
        HOISTING_ID = #{HOISTING_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
            HOISTING_ID = #{HOISTING_ID}
    </update>

    <!-- 列表 -->
    <select id="datalistPage" parameterType="page" resultType="pd">
        select
        <include refid="Field"></include>,
        siso.`NAME` as SISUO_DEPARTMENT_NAME,
        sisu.`NAME` as SISUO_USER_NAME,
        cono.`NAME` as CONFESS_DEPARTMENT_NAME,
        conu.`NAME` as CONFESS_USER_NAME,
        acco.`NAME` as ACCEPT_CONFESS_DEPARTMENT_NAME,
        accu.`NAME` as ACCEPT_CONFESS_USER_NAME,
        guao.`NAME` as GUARDIAN_DEPARTMENT_NAME,
        guau.`NAME` as GUARDIAN_USER_NAME,
        confo.`NAME` as CONFIRM_DEPARTMENT_NAME,
        confu.`NAME` as CONFIRM_USER_NAME,
        leao.`NAME` as LEADER_DEPARTMENT_NAME,
        leau.`NAME` as LEADER_USER_NAME,
        audo.`NAME` as AUDIT_DEPARTMENT_NAME,
        audu.`NAME` as AUDIT_USER_NAME,
        appro.`NAME` as APPROVE_DEPARTMENT_NAME,
        appru.`NAME` as APPROVE_USER_NAME,
        acceo.`NAME` as ACCEPT_DEPARTMENT_NAME,
        acceu.`NAME` as ACCEPT_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,
        proo.`NAME` as PROJECT_MANAGER_DEPARTMENT_NAME,
        prou.`NAME` as PROJECT_MANAGER_USER_NAME,
        woro.`NAME` as WORK_USER_DEPARTMENT_NAME,
        woru.`NAME` as WORK_USER_USER_NAME,
        appo.`NAME` as APPLY_DEPARTMENT_NAME,
        appu.`NAME` as APPLY_USER_NAME,
        log.STEP_NAME,
        log.NEXT_STEP_ID,
        log.NEXT_STEP_NAME,
        log.STATUS
        from
        <include refid="tableName"></include> f
        left join oa_department as siso on f.SISUO_DEPARTMENT_ID = siso.DEPARTMENT_ID
        left join sys_user as sisu on f.SISUO_USER_ID = sisu.USER_ID

        left join oa_department as appo on f.APPLY_DEPARTMENT_ID = appo.DEPARTMENT_ID
        left join sys_user as appu on f.APPLY_USER_ID = appu.USER_ID

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

        left join oa_department as proo on f.PROJECT_MANAGER_DEPARTMENT_ID = proo.DEPARTMENT_ID
        left join sys_user as prou on f.PROJECT_MANAGER_USER_ID = prou.USER_ID

        left join oa_department as cono on f.CONFESS_DEPARTMENT_ID = cono.DEPARTMENT_ID
        left join sys_user as conu on f.CONFESS_USER_ID = conu.USER_ID

        left join oa_department as acco on f.ACCEPT_CONFESS_DEPARTMENT_ID = acco.DEPARTMENT_ID
        left join sys_user as accu on f.ACCEPT_CONFESS_USER_ID = accu.USER_ID

        left join oa_department as guao on f.GUARDIAN_DEPARTMENT_ID = guao.DEPARTMENT_ID
        left join sys_user as guau on f.GUARDIAN_USER_ID = guau.USER_ID

        left join oa_department as confo on f.CONFIRM_DEPARTMENT_ID = confo.DEPARTMENT_ID
        left join sys_user as confu on f.CONFIRM_USER_ID = confu.USER_ID

        left join oa_department as leao on f.LEADER_DEPARTMENT_ID = leao.DEPARTMENT_ID
        left join sys_user as leau on f.LEADER_USER_ID = leau.USER_ID

        left join oa_department as audo on f.AUDIT_DEPARTMENT_ID = audo.DEPARTMENT_ID
        left join sys_user as audu on f.AUDIT_USER_ID = audu.USER_ID

        left join oa_department as appro on f.APPROVE_DEPARTMENT_ID = appro.DEPARTMENT_ID
        left join sys_user as appru on f.APPROVE_USER_ID = appru.USER_ID

        left join oa_department as acceo on f.ACCEPT_DEPARTMENT_ID = acceo.DEPARTMENT_ID
        left join sys_user as acceu on f.ACCEPT_USER_ID = acceu.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 (	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.HOISTING_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_hoisting_sign sign
                         left join bus_eightwork_step step on step.STEP_ID = sign.STEP_ID
                where sign.HOISTING_ID = f.HOISTING_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>
        <!--检索不同作业状态  WORK_STATE -1 是被打回的 -->
        <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.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_hoisting_sign sign
        left join bus_eightwork_step step on step.STEP_ID = sign.STEP_ID
        left join bus_hoisting work on work.HOISTING_ID = sign.HOISTING_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_HOISTING_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 = #{HOISTING_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_hoisting_sign sign
            left join sys_user signer on signer.USER_ID = sign.SIGN_USER_ID where sign.HOISTING_ID = #{HOISTING_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>


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

    <select id="getMapList" resultType="pd">
        select
        f.HOISTING_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.HOISTING_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>
</mapper>
