<?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="ink.wgink.module.activiti.dao.oa.INodeButtonDao">

    <resultMap id="nodeButtonDTO" type="ink.wgink.module.activiti.pojo.dtos.oa.NodeButtonDTO">
        <id column="node_button_id" property="nodeButtonId"/>
        <result column="deployment_id" property="deploymentId"/>
        <result column="form_id" property="formId"/>
        <result column="node_index" property="nodeIndex"/>
        <result column="node_id" property="nodeId"/>
        <result column="btn_attachment" property="btnAttachment"/>
        <result column="btn_go_back" property="btnGoBack"/>
        <result column="btn_forced_end" property="btnForcedEnd"/>
        <result column="btn_print" property="btnPrint"/>
        <result column="btn_cc" property="btnCc"/>
        <result column="btn_transfer" property="btnTransfer"/>
    </resultMap>

    <!-- 建表 -->
    <update id="createTable">
        CREATE TABLE IF NOT EXISTS `oa_node_button` (
            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
            `node_button_id` char(36) DEFAULT NULL COMMENT '主键',
            `model_id` char(36) DEFAULT NULL COMMENT '模型ID',
            `model_version` int(1) DEFAULT NULL COMMENT '模型版本',
            `deployment_id` char(36) DEFAULT NULL COMMENT '部署ID',
            `form_id` char(36) DEFAULT NULL COMMENT '表单ID',
            `node_id` char(60) DEFAULT NULL COMMENT '节点ID',
            `node_index` int(11) DEFAULT NULL COMMENT '节点下标',
            `btn_attachment` int(1) DEFAULT '0' COMMENT '附件上传按钮',
            `btn_go_back` int(1) DEFAULT '0' COMMENT '回退按钮',
            `btn_forced_end` int(1) DEFAULT '0' COMMENT '强制结束按钮',
            `btn_print` int(1) DEFAULT '0' COMMENT '打印按钮',
            `btn_cc` int(1) DEFAULT '0' COMMENT '抄送按钮',
            `btn_transfer` int(1) DEFAULT '0' COMMENT '转交按钮',
            PRIMARY KEY (`id`),
            UNIQUE KEY `node_button_id` (`node_button_id`),
            KEY `model_id` (`model_id`,`model_version`),
            KEY `deployment_id` (`deployment_id`),
            KEY `form_id` (`form_id`),
            KEY `node_id` (`node_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='节点按钮';
    </update>

    <!-- 新增 -->
    <insert id="save" parameterType="map">
        INSERT INTO oa_node_button(
            node_button_id,
            model_id,
            model_version,
            form_id,
            node_id,
            node_index,
            btn_attachment,
            btn_go_back,
            btn_forced_end,
            btn_print,
            btn_cc,
            btn_transfer
        ) VALUES(
            #{nodeButtonId},
            #{modelId},
            #{modelVersion},
            #{formId},
            #{nodeId},
            #{nodeIndex},
            #{btnAttachment},
            #{btnGoBack},
            #{btnForcedEnd},
            #{btnPrint},
            #{btnCc},
            #{btnTransfer}
        )
    </insert>

    <!-- 删除 -->
    <delete id="delete" parameterType="map">
        DELETE FROM
            oa_node_button
        WHERE
            model_id = #{modelId}
        AND
            model_version = #{modelVersion}
        <if test="formId != null and formId != ''">
        AND
            form_id = #{formId}
        </if>
        <if test="nodeId != null and nodeId != ''">
        AND
            node_id = #{nodeId}
        </if>
    </delete>

    <!-- 更新 -->
    <update id="update" parameterType="map">
        UPDATE
            oa_node_button
        SET
        <if test="btnAttachment != null">
            btn_attachment = #{btnAttachment},
        </if>
        <if test="btnGoBack != null">
            btn_go_back = #{btnGoBack},
        </if>
        <if test="btnForcedEnd != null">
            btn_forced_end = #{btnForcedEnd},
        </if>
        <if test="btnPrint != null">
            btn_print = #{btnPrint},
        </if>
        <if test="btnCc != null">
            btn_cc = #{btnCc},
        </if>
        <if test="btnTransfer != null">
            btn_transfer = #{btnTransfer},
        </if>
            node_button_id = #{nodeButtonId}
        WHERE
        node_button_id = #{nodeButtonId}
    </update>

    <!-- 更新部署ID -->
    <update id="updateDeploymentId" parameterType="map">
        UPDATE
            oa_node_button
        SET
            deployment_id = #{deploymentId}
        WHERE
            model_id = #{modelId}
        AND
            model_version = #{modelVersion}
    </update>

    <!-- 删除部署ID -->
    <update id="deleteDeploymentId" parameterType="java.lang.String">
        UPDATE
            oa_node_button
        SET
            deployment_id = NULL
        WHERE
            deployment_id = #{_parameter}
    </update>

    <!-- 详情 -->
    <select id="get" parameterType="map" resultMap="nodeButtonDTO">
        SELECT
            node_button_id,
            model_id,
            model_version,
            form_id,
            node_id,
            node_index,
            btn_attachment,
            btn_go_back,
            btn_forced_end,
            btn_print,
            btn_cc,
            btn_transfer
        FROM
            oa_node_button
        WHERE
            deployment_id = #{deploymentId}
        AND
            node_id = #{nodeId}
    </select>


</mapper>