<?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.bonus.material.work.mapper.SysWorkflowConfigMapper">


    <insert id="addSysWorkflowConfig">
        insert into sys_workflow_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nodeId != null">node_id,</if>
            <if test="configType != null">config_type,</if>
            <if test="configValue != null">config_value,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="roleIds != null">roleIds,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nodeId != null">#{nodeId},</if>
            <if test="configType != null">#{configType},</if>
            <if test="configValue != null">#{configValue},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="roleIds != null">#{roleIds},</if>
        </trim>

    </insert>
    <delete id="deleteSysWorkflowConfig">
        delete  from  sys_workflow_config where node_id=#{nodeId}
    </delete>

    <select id="selectConfigValueByNodeId" resultType="java.lang.String">
        select config_value from sys_workflow_config where node_id = #{nodeId}
    </select>

    <select id="selectConfigValueInfoByNodeId" resultType="com.bonus.material.work.domain.SysWorkflowConfig">
        select
            id, node_id as nodeId, config_type as configType, config_value as configValue,
            is_enable as isEnable, roleIds from sys_workflow_config
        where
            node_id = #{nodeId}
    </select>

    <select id="selectRolesByNodeId" resultType="java.lang.String">
        select roleIds from sys_workflow_config where node_id = #{nodeId}
    </select>

    <select id="selectUnitConfigValuesByTaskId" resultType="java.lang.String">
        SELECT
            GROUP_CONCAT(su.user_id) configValue
        FROM
            direct_apply_info dai
            LEFT JOIN bm_agreement_info bai ON dai.lease_agreement_id = bai.agreement_id
            LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
            LEFT JOIN data_center.dx_fb_son dfs ON dfs.`ID` = bp.external_id
            LEFT JOIN sbd_audit.sg_project_post_personnel sppp ON sppp.depart_id = dfs.`project_dept_id`
            LEFT JOIN sys_user su ON su.user_name = sppp.cno
        WHERE
            dai.id = #{taskId}
    </select>

    <select id="getImpUnit" resultType="java.lang.Integer">
        select
            imp_unit as impUnit
        from
            bm_project
        where
            pro_id = #{proId}
    </select>
</mapper>
