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

    <resultMap type="FrontProject" id="FrontProjectResult">
        <id property="projectId" column="project_id" />
        <result property="userId" column="user_id" />
        <result property="projectName" column="project_name" />
        <result property="projectFileName" column="project_file_name" />
        <result property="packageName" column="package_name" />
        <result property="version" column="version" />
        <result property="projectDesc" column="project_desc" />
        <result property="requirementKeyword" column="requirement_keyword" />
        <result property="industryTemplate" column="industry_template" />
        <result property="frontFramework" column="front_framework" />
        <result property="backFramework" column="back_framework" />
        <result property="frontendEnabled" column="frontend_enabled" />
        <result property="generateStatus" column="generate_status" />
        <result property="previewStatus" column="preview_status" />
        <result property="appBlueprint" column="app_blueprint" />
        <result property="businessLoopPlan" column="business_loop_plan" />
        <result property="erDiagram" column="er_diagram" />
        <result property="businessBlueprint" column="business_blueprint" />
        <result property="status" column="status" />
        <result property="createTime" column="create_time" />
        <result property="updateTime" column="update_time" />
        <result property="remark" column="remark" />
    </resultMap>

    <sql id="selectFrontProjectVo">
        select project_id, user_id, project_name, project_file_name, package_name, version, project_desc, requirement_keyword, industry_template, front_framework, back_framework, frontend_enabled, generate_status, preview_status, app_blueprint, business_loop_plan, er_diagram, business_blueprint, status, create_time, update_time, remark from front_project
    </sql>

    <select id="selectFrontProjectById" parameterType="Long" resultMap="FrontProjectResult">
        <include refid="selectFrontProjectVo"/>
        where project_id = #{projectId}
    </select>

    <select id="selectFrontProjectByUserAndId" resultMap="FrontProjectResult">
        <include refid="selectFrontProjectVo"/>
        where user_id = #{userId} and project_id = #{projectId}
    </select>

    <select id="selectFrontProjectList" parameterType="FrontProject" resultMap="FrontProjectResult">
        <include refid="selectFrontProjectVo"/>
        <where>
            <if test="userId != null"> and user_id = #{userId}</if>
            <if test="projectName != null and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="industryTemplate != null and industryTemplate != ''"> and industry_template = #{industryTemplate}</if>
            <if test="generateStatus != null and generateStatus != ''"> and generate_status = #{generateStatus}</if>
            <if test="previewStatus != null and previewStatus != ''"> and preview_status = #{previewStatus}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>

    <insert id="insertFrontProject" parameterType="FrontProject" useGeneratedKeys="true" keyProperty="projectId">
        insert into front_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="projectName != null">project_name,</if>
            <if test="projectFileName != null">project_file_name,</if>
            <if test="packageName != null">package_name,</if>
            <if test="version != null">version,</if>
            <if test="projectDesc != null">project_desc,</if>
            <if test="requirementKeyword != null">requirement_keyword,</if>
            <if test="industryTemplate != null">industry_template,</if>
            <if test="frontFramework != null">front_framework,</if>
            <if test="backFramework != null">back_framework,</if>
            <if test="frontendEnabled != null">frontend_enabled,</if>
            <if test="generateStatus != null">generate_status,</if>
            <if test="previewStatus != null">preview_status,</if>
            <if test="appBlueprint != null">app_blueprint,</if>
            <if test="businessLoopPlan != null">business_loop_plan,</if>
            <if test="erDiagram != null">er_diagram,</if>
            <if test="businessBlueprint != null">business_blueprint,</if>
            <if test="status != null">status,</if>
            create_time,
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="projectFileName != null">#{projectFileName},</if>
            <if test="packageName != null">#{packageName},</if>
            <if test="version != null">#{version},</if>
            <if test="projectDesc != null">#{projectDesc},</if>
            <if test="requirementKeyword != null">#{requirementKeyword},</if>
            <if test="industryTemplate != null">#{industryTemplate},</if>
            <if test="frontFramework != null">#{frontFramework},</if>
            <if test="backFramework != null">#{backFramework},</if>
            <if test="frontendEnabled != null">#{frontendEnabled},</if>
            <if test="generateStatus != null">#{generateStatus},</if>
            <if test="previewStatus != null">#{previewStatus},</if>
            <if test="appBlueprint != null">#{appBlueprint},</if>
            <if test="businessLoopPlan != null">#{businessLoopPlan},</if>
            <if test="erDiagram != null">#{erDiagram},</if>
            <if test="businessBlueprint != null">#{businessBlueprint},</if>
            <if test="status != null">#{status},</if>
            sysdate(),
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateFrontProject" parameterType="FrontProject">
        update front_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="projectFileName != null">project_file_name = #{projectFileName},</if>
            <if test="packageName != null">package_name = #{packageName},</if>
            <if test="version != null">version = #{version},</if>
            <if test="projectDesc != null">project_desc = #{projectDesc},</if>
            <if test="requirementKeyword != null">requirement_keyword = #{requirementKeyword},</if>
            <if test="industryTemplate != null">industry_template = #{industryTemplate},</if>
            <if test="frontFramework != null">front_framework = #{frontFramework},</if>
            <if test="backFramework != null">back_framework = #{backFramework},</if>
            <if test="frontendEnabled != null">frontend_enabled = #{frontendEnabled},</if>
            <if test="generateStatus != null">generate_status = #{generateStatus},</if>
            <if test="previewStatus != null">preview_status = #{previewStatus},</if>
            <if test="appBlueprint != null">app_blueprint = #{appBlueprint},</if>
            <if test="businessLoopPlan != null">business_loop_plan = #{businessLoopPlan},</if>
            <if test="erDiagram != null">er_diagram = #{erDiagram},</if>
            <if test="businessBlueprint != null">business_blueprint = #{businessBlueprint},</if>
            <if test="status != null">status = #{status},</if>
            update_time = sysdate(),
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where project_id = #{projectId}
    </update>

    <delete id="deleteFrontProjectById" parameterType="Long">
        delete from front_project where project_id = #{projectId}
    </delete>

    <delete id="deleteFrontProjectByUserAndId">
        delete from front_project where user_id = #{userId} and project_id = #{projectId}
    </delete>
</mapper>
