<?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.FrontProjectColumnMapper">

    <resultMap type="FrontProjectColumn" id="FrontProjectColumnResult">
        <id property="columnId" column="column_id" />
        <result property="tableId" column="table_id" />
        <result property="projectId" column="project_id" />
        <result property="columnName" column="column_name" />
        <result property="columnComment" column="column_comment" />
        <result property="columnType" column="column_type" />
        <result property="javaType" column="java_type" />
        <result property="javaField" column="java_field" />
        <result property="isPk" column="is_pk" />
        <result property="isIncrement" column="is_increment" />
        <result property="isRequired" column="is_required" />
        <result property="isInsert" column="is_insert" />
        <result property="isEdit" column="is_edit" />
        <result property="isList" column="is_list" />
        <result property="isQuery" column="is_query" />
        <result property="queryType" column="query_type" />
        <result property="htmlType" column="html_type" />
        <result property="dictType" column="dict_type" />
        <result property="defaultValue" column="default_value" />
        <result property="sort" column="sort" />
        <result property="createTime" column="create_time" />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectFrontProjectColumnVo">
        select column_id, table_id, project_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, default_value, sort, create_time, update_time from front_project_column
    </sql>

    <select id="selectFrontProjectColumnById" parameterType="Long" resultMap="FrontProjectColumnResult">
        <include refid="selectFrontProjectColumnVo"/>
        where column_id = #{columnId}
    </select>

    <select id="selectColumnsByTableId" parameterType="Long" resultMap="FrontProjectColumnResult">
        <include refid="selectFrontProjectColumnVo"/>
        where table_id = #{tableId}
        order by sort, column_id
    </select>

    <select id="selectFrontProjectColumnList" parameterType="FrontProjectColumn" resultMap="FrontProjectColumnResult">
        <include refid="selectFrontProjectColumnVo"/>
        <where>
            <if test="tableId != null"> and table_id = #{tableId}</if>
            <if test="projectId != null"> and project_id = #{projectId}</if>
            <if test="columnName != null and columnName != ''"> and column_name like concat('%', #{columnName}, '%')</if>
        </where>
    </select>

    <insert id="insertFrontProjectColumn" parameterType="FrontProjectColumn" useGeneratedKeys="true" keyProperty="columnId">
        insert into front_project_column
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tableId != null">table_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="columnName != null">column_name,</if>
            <if test="columnComment != null">column_comment,</if>
            <if test="columnType != null">column_type,</if>
            <if test="javaType != null">java_type,</if>
            <if test="javaField != null">java_field,</if>
            <if test="isPk != null">is_pk,</if>
            <if test="isIncrement != null">is_increment,</if>
            <if test="isRequired != null">is_required,</if>
            <if test="isInsert != null">is_insert,</if>
            <if test="isEdit != null">is_edit,</if>
            <if test="isList != null">is_list,</if>
            <if test="isQuery != null">is_query,</if>
            <if test="queryType != null">query_type,</if>
            <if test="htmlType != null">html_type,</if>
            <if test="dictType != null">dict_type,</if>
            <if test="defaultValue != null">default_value,</if>
            <if test="sort != null">sort,</if>
            create_time,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tableId != null">#{tableId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="columnName != null">#{columnName},</if>
            <if test="columnComment != null">#{columnComment},</if>
            <if test="columnType != null">#{columnType},</if>
            <if test="javaType != null">#{javaType},</if>
            <if test="javaField != null">#{javaField},</if>
            <if test="isPk != null">#{isPk},</if>
            <if test="isIncrement != null">#{isIncrement},</if>
            <if test="isRequired != null">#{isRequired},</if>
            <if test="isInsert != null">#{isInsert},</if>
            <if test="isEdit != null">#{isEdit},</if>
            <if test="isList != null">#{isList},</if>
            <if test="isQuery != null">#{isQuery},</if>
            <if test="queryType != null">#{queryType},</if>
            <if test="htmlType != null">#{htmlType},</if>
            <if test="dictType != null">#{dictType},</if>
            <if test="defaultValue != null">#{defaultValue},</if>
            <if test="sort != null">#{sort},</if>
            sysdate(),
        </trim>
    </insert>

    <update id="updateFrontProjectColumn" parameterType="FrontProjectColumn">
        update front_project_column
        <trim prefix="SET" suffixOverrides=",">
            <if test="columnName != null">column_name = #{columnName},</if>
            <if test="columnComment != null">column_comment = #{columnComment},</if>
            <if test="columnType != null">column_type = #{columnType},</if>
            <if test="javaType != null">java_type = #{javaType},</if>
            <if test="javaField != null">java_field = #{javaField},</if>
            <if test="isPk != null">is_pk = #{isPk},</if>
            <if test="isIncrement != null">is_increment = #{isIncrement},</if>
            <if test="isRequired != null">is_required = #{isRequired},</if>
            <if test="isInsert != null">is_insert = #{isInsert},</if>
            <if test="isEdit != null">is_edit = #{isEdit},</if>
            <if test="isList != null">is_list = #{isList},</if>
            <if test="isQuery != null">is_query = #{isQuery},</if>
            <if test="queryType != null">query_type = #{queryType},</if>
            <if test="htmlType != null">html_type = #{htmlType},</if>
            <if test="dictType != null">dict_type = #{dictType},</if>
            <if test="defaultValue != null">default_value = #{defaultValue},</if>
            <if test="sort != null">sort = #{sort},</if>
            update_time = sysdate(),
        </trim>
        where column_id = #{columnId}
    </update>

    <delete id="deleteFrontProjectColumnById" parameterType="Long">
        delete from front_project_column where column_id = #{columnId}
    </delete>

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