<?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.ruoyi.generator.mapper.front.FrontProjectTableMapper">

    <resultMap type="FrontProjectTable" id="FrontProjectTableResult">
        <id property="tableId" column="table_id" />
        <result property="projectId" column="project_id" />
        <result property="userId" column="user_id" />
        <result property="tableName" column="table_name" />
        <result property="tableComment" column="table_comment" />
        <result property="className" column="class_name" />
        <result property="moduleName" column="module_name" />
        <result property="businessName" column="business_name" />
        <result property="functionName" column="function_name" />
        <result property="tplCategory" column="tpl_category" />
        <result property="tplWebType" column="tpl_web_type" />
        <result property="options" column="options" />
        <result property="createTableSql" column="create_table_sql" />
        <result property="sort" column="sort" />
        <result property="status" column="status" />
        <result property="createTime" column="create_time" />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectFrontProjectTableVo">
        select table_id, project_id, user_id, table_name, table_comment, class_name, module_name, business_name, function_name, tpl_category, tpl_web_type, options, create_table_sql, sort, status, create_time, update_time from front_project_table
    </sql>

    <select id="selectFrontProjectTableById" parameterType="Long" resultMap="FrontProjectTableResult">
        <include refid="selectFrontProjectTableVo"/>
        where table_id = #{tableId}
    </select>

    <select id="selectTablesByProjectId" parameterType="Long" resultMap="FrontProjectTableResult">
        <include refid="selectFrontProjectTableVo"/>
        where project_id = #{projectId}
        order by sort, table_id
    </select>

    <select id="selectFrontProjectTableList" parameterType="FrontProjectTable" resultMap="FrontProjectTableResult">
        <include refid="selectFrontProjectTableVo"/>
        <where>
            <if test="projectId != null"> and project_id = #{projectId}</if>
            <if test="userId != null"> and user_id = #{userId}</if>
            <if test="tableName != null and tableName != ''"> and table_name like concat('%', #{tableName}, '%')</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <insert id="insertFrontProjectTable" parameterType="FrontProjectTable" useGeneratedKeys="true" keyProperty="tableId">
        insert into front_project_table
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="tableName != null">table_name,</if>
            <if test="tableComment != null">table_comment,</if>
            <if test="className != null">class_name,</if>
            <if test="moduleName != null">module_name,</if>
            <if test="businessName != null">business_name,</if>
            <if test="functionName != null">function_name,</if>
            <if test="tplCategory != null">tpl_category,</if>
            <if test="tplWebType != null">tpl_web_type,</if>
            <if test="options != null">options,</if>
            <if test="createTableSql != null">create_table_sql,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            create_time,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="tableName != null">#{tableName},</if>
            <if test="tableComment != null">#{tableComment},</if>
            <if test="className != null">#{className},</if>
            <if test="moduleName != null">#{moduleName},</if>
            <if test="businessName != null">#{businessName},</if>
            <if test="functionName != null">#{functionName},</if>
            <if test="tplCategory != null">#{tplCategory},</if>
            <if test="tplWebType != null">#{tplWebType},</if>
            <if test="options != null">#{options},</if>
            <if test="createTableSql != null">#{createTableSql},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
            sysdate(),
        </trim>
    </insert>

    <update id="updateFrontProjectTable" parameterType="FrontProjectTable">
        update front_project_table
        <trim prefix="SET" suffixOverrides=",">
            <if test="tableName != null">table_name = #{tableName},</if>
            <if test="tableComment != null">table_comment = #{tableComment},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="moduleName != null">module_name = #{moduleName},</if>
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="functionName != null">function_name = #{functionName},</if>
            <if test="tplCategory != null">tpl_category = #{tplCategory},</if>
            <if test="tplWebType != null">tpl_web_type = #{tplWebType},</if>
            <if test="options != null">options = #{options},</if>
            <if test="createTableSql != null">create_table_sql = #{createTableSql},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
            update_time = sysdate(),
        </trim>
        where table_id = #{tableId}
    </update>

    <delete id="deleteFrontProjectTableById" parameterType="Long">
        delete from front_project_table where table_id = #{tableId}
    </delete>

    <delete id="deleteTablesByProjectId" parameterType="Long">
        delete from front_project_table where project_id = #{projectId}
    </delete>
</mapper>
