<?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.platform.mapper.CodeConfigDao">

    <insert id="insert">
        insert into code_config(code_repo_name, code_repo_vis, git_url, git_branch, verify_mode, git_user_name, git_password,ssh_key, create_by, create_time, update_by, update_time)
        values(#{codeConfig.codeRepoName}, #{codeConfig.codeRepoVis}, #{codeConfig.gitUrl}, #{codeConfig.gitBranch}, #{codeConfig.verifyMode}, #{codeConfig.gitUserName}, #{codeConfig.gitPassword},
               #{codeConfig.sshKey}, #{codeConfig.createBy}, #{codeConfig.createTime}, #{codeConfig.updateBy}, #{codeConfig.updateTime})
    </insert>

    <update id="update">
        update code_config
        <set>
            <if test="codeConfig.codeRepoName != null and codeConfig.codeRepoName != ''">
                code_repo_name = #{codeConfig.codeRepoName},
            </if>
            <if test="codeConfig.codeRepoVis != null">
                code_repo_vis = #{codeConfig.codeRepoVis},
            </if>
            <if test="codeConfig.gitUrl != null">
                git_url = #{codeConfig.gitUrl},
            </if>
            <if test="codeConfig.gitBranch != null and codeConfig.gitBranch != ''">
                git_branch = #{codeConfig.gitBranch},
            </if>
            verify_mode = #{codeConfig.verifyMode},
            git_user_name = #{codeConfig.gitUserName},
            git_password = #{codeConfig.gitPassword},
            ssh_key = #{codeConfig.sshKey},
            <if test="codeConfig.createBy != null and codeConfig.createBy != ''">
                create_by = #{codeConfig.createBy},
            </if>
            <if test="codeConfig.createTime != null">
                create_time = #{codeConfig.createTime},
            </if>
            <if test="codeConfig.updateBy != null and codeConfig.updateBy != ''">
                update_by = #{codeConfig.updateBy},
            </if>
            <if test="codeConfig.state != null">
                state = #{codeConfig.state},
            </if>
            update_time = sysdate()
        </set>
        where id = #{codeConfig.id}
    </update>


    <select id="count" resultType="java.lang.Long">
        select count(1)
        from code_config
        <include refid="common_condition"></include>
    </select>

    <select id="queryAllByLimit" resultType="com.ruoyi.platform.domain.CodeConfig">
        select * from code_config
        <include refid="common_condition"></include>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <select id="queryById" resultType="com.ruoyi.platform.domain.CodeConfig">
        select *
        from code_config
        where id = #{id}
          and state = 1
    </select>

    <sql id="common_condition">
        <where>
            state = 1
            <if test="codeConfig.id != null">
                and id = #{codeConfig.id}
            </if>
            <if test="codeConfig.codeRepoName != null and codeConfig.codeRepoName != ''">
                and code_repo_name LIKE CONCAT('%', #{codeConfig.codeRepoName}, '%')
            </if>
            <if test="codeConfig.codeRepoVis != null">
                and code_repo_vis = #{codeConfig.codeRepoVis}
            </if>
            <if test="codeConfig.gitUrl != null">
                and git_url = #{codeConfig.gitUrl}
            </if>
            <if test="codeConfig.gitBranch != null and codeConfig.gitBranch != ''">
                and git_branch = #{codeConfig.gitBranch}
            </if>
            <if test="codeConfig.verifyMode != null">
                and verify_mode = #{codeConfig.verifyMode}
            </if>
            <if test="codeConfig.gitUserName != null and codeConfig.gitUserName != ''">
                and git_user_name = #{codeConfig.gitUserName}
            </if>
            <if test="codeConfig.createBy != null and codeConfig.createBy != ''">
                and create_by = #{codeConfig.createBy}
            </if>
            <if test="codeConfig.createTime != null">
                and create_time = #{codeConfig.createTime}
            </if>
            <if test="codeConfig.updateBy != null and codeConfig.updateBy != ''">
                and update_by = #{codeConfig.updateBy}
            </if>
            <if test="codeConfig.updateTime != null">
                and update_time = #{codeConfig.updateTime}
            </if>
        </where>
    </sql>
</mapper>