<?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="org.springblade.manager.mapper.WbsFormElementMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="wbsFormElementResultMap" type="org.springblade.manager.entity.WbsFormElement">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="f_id" property="fId"/>
        <result column="e_key" property="eKey"/>
        <result column="e_name" property="eName"/>
        <result column="e_type" property="eType"/>
        <result column="e_length" property="eLength"/>
        <result column="e_allow_deviation" property="eAllowDeviation"/>
        <result column="e_inspection_method" property="eInspectionMethod"/>
        <result column="remark" property="remark"/>
    </resultMap>


    <update id="createTable">
        create table ${newTableName} (
        `id` bigint(20) NOT NULL,
         ${sqlStr}
         PRIMARY KEY (`id`) USING BTREE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    </update>
    <update id="alterAddFiled">
        alter table ${tableName} add ${sqlStr}
    </update>

    <update id="deleteTableFiled">
        alter table ${tableName} drop column ${eKey}
    </update>

    <update id="updateFiledType">
        ALTER TABLE ${initTableName} MODIFY ${eKey} ${eType}(${eLength})
    </update>

    <update id="updateSortById">
        UPDATE m_wbs_tree
        SET sort = #{sort}
        WHERE id = #{id}
        AND type = 2
        AND status = 1
        AND is_deleted = 0
    </update>


    <select id="selectWbsFormElementPage" resultMap="wbsFormElementResultMap">
        select * from m_wbs_form_element where is_deleted = 0
    </select>
    <select id="judgeFiled" resultType="Integer">
     select count(*) from information_schema.columns where table_name = &quot;${tableName}&quot; and column_name = &quot;${eKey}&quot;
    </select>

    <select id="selectWbsTreeTableListByParentId" resultType="org.springblade.manager.dto.WbsFormElementDTO2">
        SELECT id,dept_name AS "deptName",sort
        FROM m_wbs_tree
        WHERE parent_id = #{parentId}
        AND status = 1
        AND is_deleted = 0
        AND type = 2
        ORDER BY sort
    </select>
    <select id="selectDetailById" resultType="org.springblade.manager.vo.WbsFormElementVO">
        SELECT
        *,
        (SELECT concat(dept_name,"_",t.e_name) FROM m_wbs_tree WHERE id = t.f_id) AS "tableElementKey"
        FROM m_wbs_form_element t WHERE t.id = #{id} AND status = 1 AND is_deleted = 0
    </select>

</mapper>
