<?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.zcxk.process.dao.UserActionDescMapper">
    <!--auto generated Code-->
    <resultMap id="BaseResultMap" type="com.zcxk.process.entity.UserActionDesc">
        <result column="id" property="id" jdbcType="INTEGER"/>
        <result column="action_name" property="actionName" jdbcType="VARCHAR"/>
        <result column="result_key" property="resultKey" jdbcType="VARCHAR"/>
        <result column="show_type" property="showType" jdbcType="VARCHAR"/>
        <result column="content_type" property="contentType" jdbcType="VARCHAR"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
        <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
        <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
        <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--auto generated Code-->
    <sql id="Base_Column_List">
        id,
        action_name,
        result_key,
        show_type,
        content_type,
        content,
        status,
        create_by,
        date_create,
        update_by,
        date_update
    </sql>

    <!--auto generated Code-->
    <insert id="insert" useGeneratedKeys="true" keyProperty="userActionDesc.id">
        INSERT INTO sc_user_action_desc (
        id,
        action_name,
        show_type,
        content_type,
        content,
        status,
        create_by,
        date_create,
        update_by,
        date_update
        ) VALUES (
        #{userActionDesc.id,jdbcType=INTEGER},
        #{userActionDesc.actionName,jdbcType=VARCHAR},
        #{userActionDesc.showType,jdbcType=VARCHAR},
        #{userActionDesc.contentType,jdbcType=VARCHAR},
        #{userActionDesc.content,jdbcType=VARCHAR},
        #{userActionDesc.status,jdbcType=INTEGER},
        #{userActionDesc.createBy,jdbcType=VARCHAR},
        #{userActionDesc.dateCreate,jdbcType=TIMESTAMP},
        #{userActionDesc.updateBy,jdbcType=VARCHAR},
        #{userActionDesc.dateUpdate,jdbcType=TIMESTAMP}
        )
    </insert>

    <!--auto generated Code-->
    <insert id="insertSelective" useGeneratedKeys="true" keyProperty="userActionDesc.id">
        INSERT INTO sc_user_action_desc
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userActionDesc.id!=null">id,</if>
            <if test="userActionDesc.actionName!=null">action_name,</if>
            <if test="userActionDesc.showType!=null">show_type,</if>
            <if test="userActionDesc.contentType!=null">content_type,</if>
            <if test="userActionDesc.content!=null">content,</if>
            <if test="userActionDesc.status!=null">status,</if>
            <if test="userActionDesc.createBy!=null">create_by,</if>
            <if test="userActionDesc.dateCreate!=null">date_create,</if>
            <if test="userActionDesc.updateBy!=null">update_by,</if>
            <if test="userActionDesc.dateUpdate!=null">date_update,</if>
        </trim>
        VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userActionDesc.id!=null">#{userActionDesc.id,jdbcType=INTEGER},
            </if>
            <if test="userActionDesc.actionName!=null">#{userActionDesc.actionName,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.showType!=null">#{userActionDesc.showType,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.contentType!=null">#{userActionDesc.contentType,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.content!=null">#{userActionDesc.content,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.status!=null">#{userActionDesc.status,jdbcType=INTEGER},
            </if>
            <if test="userActionDesc.createBy!=null">#{userActionDesc.createBy,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.dateCreate!=null">#{userActionDesc.dateCreate,jdbcType=TIMESTAMP},
            </if>
            <if test="userActionDesc.updateBy!=null">#{userActionDesc.updateBy,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.dateUpdate!=null">#{userActionDesc.dateUpdate,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>

    <!--auto generated Code-->
    <insert id="insertList">
        INSERT INTO sc_user_action_desc (
        id,
        action_name,
        show_type,
        content_type,
        content,
        status,
        create_by,
        date_create,
        update_by,
        date_update
        )VALUES
        <foreach collection="userActionDescs" item="userActionDesc" index="index" separator=",">
            (
            #{userActionDesc.id,jdbcType=INTEGER},
            #{userActionDesc.actionName,jdbcType=VARCHAR},
            #{userActionDesc.showType,jdbcType=VARCHAR},
            #{userActionDesc.contentType,jdbcType=VARCHAR},
            #{userActionDesc.content,jdbcType=VARCHAR},
            #{userActionDesc.status,jdbcType=INTEGER},
            #{userActionDesc.createBy,jdbcType=VARCHAR},
            #{userActionDesc.dateCreate,jdbcType=TIMESTAMP},
            #{userActionDesc.updateBy,jdbcType=VARCHAR},
            #{userActionDesc.dateUpdate,jdbcType=TIMESTAMP}
            )
        </foreach>
    </insert>

    <!--auto generated Code-->
    <update id="updateByPrimaryKeySelective">
        UPDATE sc_user_action_desc
        <set>
            <if test="userActionDesc.actionName != null">action_name= #{userActionDesc.actionName,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.showType != null">show_type= #{userActionDesc.showType,jdbcType=VARCHAR},</if>
            <if test="userActionDesc.contentType != null">content_type=
                #{userActionDesc.contentType,jdbcType=VARCHAR},
            </if>
            <if test="userActionDesc.content != null">content= #{userActionDesc.content,jdbcType=VARCHAR},</if>
            <if test="userActionDesc.status != null">status= #{userActionDesc.status,jdbcType=INTEGER},</if>
            <if test="userActionDesc.createBy != null">create_by= #{userActionDesc.createBy,jdbcType=VARCHAR},</if>
            <if test="userActionDesc.dateCreate != null">date_create= #{userActionDesc.dateCreate,jdbcType=TIMESTAMP},
            </if>
            <if test="userActionDesc.updateBy != null">update_by= #{userActionDesc.updateBy,jdbcType=VARCHAR},</if>
            <if test="userActionDesc.dateUpdate != null">date_update= #{userActionDesc.dateUpdate,jdbcType=TIMESTAMP}
            </if>
        </set>
        WHERE id = #{userActionDesc.id,jdbcType=INTEGER}
    </update>
    <select id="queryUserActionWithForm" resultType="com.zcxk.process.entity.UserActionDesc">
        SELECT
        ua.id as id,
        ua.action_value as action_value,
        ua.result_key as result_key ,
        ua.action_name as action_name,
        ua.show_type as show_type,
        ua.content_type,
        CASE
        WHEN content_type = 'dynamic' THEN
        (
        SELECT
        group_concat( config_value, ':', config_name )
        FROM
        sc_config_t
        WHERE
        parent_id = ua.relation_config_id
        GROUP BY
        parent_id
        )
        WHEN content_type = 'constant' THEN
        ua.content ELSE ''
        END as content
        FROM
        sc_form_action fa
        LEFT JOIN sc_user_action_desc ua ON ( fa.action_id = ua.id AND ua.STATUS = 1 )
        WHERE fa.status = 1
        and fa.form_id = #{formId}
    </select>
</mapper>

