All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mapper.CurrentJobConfigMapper.xml Maven / Gradle / Ivy

The newest version!
<?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.vip.saturn.job.console.mybatis.repository.CurrentJobConfigRepository">
    <resultMap id="BaseResultMap" type="com.vip.saturn.job.console.mybatis.entity.JobConfig4DB">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="job_name" property="jobName" jdbcType="VARCHAR"/>
        <result column="job_class" property="jobClass" jdbcType="VARCHAR"/>
        <result column="sharding_total_count" property="shardingTotalCount" jdbcType="INTEGER"/>
        <result column="load_level" property="loadLevel" jdbcType="INTEGER"/>
        <result column="job_degree" property="jobDegree" jdbcType="INTEGER"/>
        <result column="enabled_report" property="enabledReport" jdbcType="BIT"/>
        <result column="local_mode" property="localMode" jdbcType="BIT"/>
        <result column="use_serial" property="useSerial" jdbcType="BIT"/>
        <result column="use_disprefer_list" property="useDispreferList" jdbcType="BIT"/>
        <result column="time_zone" property="timeZone" jdbcType="VARCHAR"/>
        <result column="cron" property="cron" jdbcType="VARCHAR"/>
        <result column="prefer_list" property="preferList" jdbcType="VARCHAR"/>
        <result column="pause_period_date" property="pausePeriodDate" jdbcType="VARCHAR"/>
        <result column="pause_period_time" property="pausePeriodTime" jdbcType="VARCHAR"/>
        <result column="sharding_item_parameters" property="shardingItemParameters" jdbcType="VARCHAR"/>
        <result column="job_parameter" property="jobParameter" jdbcType="VARCHAR"/>
        <result column="process_count_interval_seconds" property="processCountIntervalSeconds" jdbcType="INTEGER"/>
        <result column="failover" property="failover" jdbcType="BIT"/>
        <result column="dependencies" property="dependencies" jdbcType="VARCHAR"/>
        <result column="groups" property="groups" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="timeout_4_alarm_seconds" property="timeout4AlarmSeconds" jdbcType="INTEGER"/>
        <result column="timeout_seconds" property="timeoutSeconds" jdbcType="INTEGER"/>
        <result column="show_normal_log" property="showNormalLog" jdbcType="BIT"/>
        <result column="channel_name" property="channelName" jdbcType="VARCHAR"/>
        <result column="job_type" property="jobType" jdbcType="VARCHAR"/>
        <result column="queue_name" property="queueName" jdbcType="VARCHAR"/>
        <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="last_update_by" property="lastUpdateBy" jdbcType="VARCHAR"/>
        <result column="last_update_time" property="lastUpdateTime" jdbcType="TIMESTAMP"/>
        <result column="namespace" property="namespace" jdbcType="VARCHAR"/>
        <result column="zk_list" property="zkList" jdbcType="VARCHAR"/>
        <result column="is_enabled" property="enabled" jdbcType="BIT"/>
        <result column="job_mode" property="jobMode" jdbcType="VARCHAR"/>
        <result column="custom_context" property="customContext" jdbcType="VARCHAR"/>
        <result column="rerun" property="rerun" jdbcType="BIT"/>
        <result column="up_stream" property="upStream" jdbcType="VARCHAR"/>
        <result column="down_stream" property="downStream" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, job_name, job_class, sharding_total_count, load_level, job_degree, enabled_report, local_mode, use_serial,
        use_disprefer_list, time_zone, cron, prefer_list, pause_period_date, pause_period_time,
        sharding_item_parameters, job_parameter, process_count_interval_seconds,
        failover, dependencies, groups, description, timeout_4_alarm_seconds, timeout_seconds, show_normal_log,
        channel_name, job_type, queue_name, create_by, create_time, last_update_by, last_update_time,
        namespace, zk_list,is_enabled,job_mode,custom_context,rerun, up_stream, down_stream
    </sql>

    <select id="findConfigsByNamespace" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from job_config
        where namespace = #{namespace,jdbcType=VARCHAR}
    </select>

    <select id="findConfigsByNamespaceWithCondition" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from job_config
        <where>
            namespace = #{namespace,jdbcType=VARCHAR}
            <choose>
                <when test="condition.groups == null"></when>
                <when test="condition.groups == ''">
                    and (groups = #{condition.groups} or groups is NULL)
                </when>
                <otherwise>
                    and (
                        <foreach collection="condition.groups.split(',')" item="item" separator="or">
                            <if test="item != '未分组'">
                                FIND_IN_SET(#{item}, groups)
                            </if>
                            <if test="item == '未分组'">
                                (groups = '' or groups is NULL)
                            </if>
                        </foreach>
                    )
                </otherwise>
            </choose>
            <if test="condition.isEnabled != null">
                and is_enabled = #{condition.isEnabled}
            </if>
	    <if test="condition.jobType != null">
                and job_type = #{condition.jobType}
            </if>
            <choose>
                <when test="condition.jobName != null">
                    and job_name like CONCAT('%',#{condition.jobName},'%')
                </when>
                <when test="condition.description != null">
                    and description like CONCAT('%',#{condition.description},'%')
                </when>
                <when test="condition.queueName != null">
                    and queue_name like CONCAT('%',#{condition.queueName},'%')
                </when>
            </choose>
        </where>
        <if test="condition.order != null">
            order by job_name
            <if test="condition.order == 'descending'">
                desc
            </if>
        </if>
        <if test="pageable != null">
            limit #{pageable.offset}, #{pageable.pageSize}
        </if>
    </select>

    <select id="countConfigsByNamespaceWithCondition" resultType="Integer">
        select
        count(*)
        from job_config
        <where>
            namespace = #{namespace,jdbcType=VARCHAR}
            <choose>
                <when test="condition.groups == null"></when>
                <when test="condition.groups == ''">
                    and (groups = #{condition.groups} or groups is NULL)
                </when>
                <otherwise>
                    and (
                    <foreach collection="condition.groups.split(',')" item="item" separator="or">
                        <if test="item != '未分组'">
                            FIND_IN_SET(#{item}, groups)
                        </if>
                        <if test="item == '未分组'">
                            (groups = '' or groups is NULL)
                        </if>
                    </foreach>
                    )
                </otherwise>
            </choose>
            <if test="condition.isEnabled != null">
                and is_enabled = #{condition.isEnabled}
            </if>
	    <if test="condition.jobType != null">
                and job_type = #{condition.jobType}
            </if>
            <choose>
                <when test="condition.jobName != null">
                    and job_name like CONCAT('%',#{condition.jobName},'%')
                </when>
                <when test="condition.description != null">
                    and description like CONCAT('%',#{condition.description},'%')
                </when>
                <when test="condition.queueName != null">
                    and queue_name like CONCAT('%',#{condition.queueName},'%')
                </when>
            </choose>
        </where>
    </select>

    <select id="countEnabledUnSystemJobsByNamespace" resultType="Integer">
        select count(*) from job_config where namespace = #{namespace} and is_enabled = #{isEnabled}
    </select>

    <select id="findConfigNamesByNamespace" resultType="String">
        select
        job_name
        from job_config
        where namespace = #{namespace,jdbcType=VARCHAR}
    </select>

    <select id="findConfigByNamespaceAndJobName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from job_config
        where namespace = #{namespace,jdbcType=VARCHAR}
        and job_name = #{jobName,jdbcType=VARCHAR} limit 0,1
    </select>

    <select id="findConfigsByQueue" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from job_config
        where queue_name = #{queueName,jdbcType=VARCHAR}
        order by job_name
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from job_config
        where id = #{id,jdbcType=BIGINT}
    </delete>

    <delete id="deleteByNamespace" parameterType="java.lang.String">
        delete from job_config
        where namespace = #{namespace,jdbcType=VARCHAR}
    </delete>

    <insert id="insert" parameterType="com.vip.saturn.job.console.mybatis.entity.JobConfig4DB">
        insert into job_config (job_name, job_class,
        sharding_total_count, load_level, job_degree, enabled_report, local_mode, use_serial, use_disprefer_list,
        time_zone, cron, prefer_list, pause_period_date,
        pause_period_time, sharding_item_parameters,
        job_parameter, process_count_interval_seconds,
        failover, dependencies, groups, description,
        timeout_4_alarm_seconds, timeout_seconds, show_normal_log, channel_name,
        job_type, queue_name, create_by,
        create_time, last_update_by, last_update_time,
        namespace, zk_list,is_enabled,job_mode,custom_context,
        rerun, up_stream, down_stream
        )
        values (#{jobName,jdbcType=VARCHAR}, #{jobClass,jdbcType=VARCHAR},
        #{shardingTotalCount,jdbcType=INTEGER}, #{loadLevel,jdbcType=INTEGER}, #{jobDegree,jdbcType=INTEGER},
        #{enabledReport,jdbcType=BIT},
        #{localMode,jdbcType=BIT}, #{useSerial,jdbcType=BIT}, #{useDispreferList,jdbcType=BIT},
        #{timeZone,jdbcType=VARCHAR}, #{cron,jdbcType=VARCHAR},
        #{preferList,jdbcType=VARCHAR},#{pausePeriodDate,jdbcType=VARCHAR},
        #{pausePeriodTime,jdbcType=VARCHAR}, #{shardingItemParameters,jdbcType=VARCHAR},
        #{jobParameter,jdbcType=VARCHAR}, #{processCountIntervalSeconds,jdbcType=INTEGER},
        #{failover,jdbcType=BIT}, #{dependencies,jdbcType=VARCHAR}, #{groups,jdbcType=VARCHAR},
        #{description,jdbcType=VARCHAR},
        #{timeout4AlarmSeconds,jdbcType=INTEGER}, #{timeoutSeconds,jdbcType=INTEGER}, #{showNormalLog,jdbcType=BIT},
        #{channelName,jdbcType=VARCHAR},
        #{jobType,jdbcType=VARCHAR}, #{queueName,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR},
        #{createTime,jdbcType=TIMESTAMP}, #{lastUpdateBy,jdbcType=VARCHAR}, #{lastUpdateTime,jdbcType=TIMESTAMP},
        #{namespace,jdbcType=VARCHAR}, #{zkList,jdbcType=VARCHAR},#{enabled,jdbcType=BIT},#{jobMode,jdbcType=VARCHAR},
        #{customContext,jdbcType=VARCHAR}, #{rerun, jdbcType=BIT}, #{upStream,jdbcType=VARCHAR}, #{downStream,jdbcType=VARCHAR}
        )
    </insert>

    <update id="updateByPrimaryKey" parameterType="com.vip.saturn.job.console.mybatis.entity.JobConfig4DB">
        update job_config
        set job_name = #{jobName,jdbcType=VARCHAR},
        job_class = #{jobClass,jdbcType=VARCHAR},
        sharding_total_count = #{shardingTotalCount,jdbcType=INTEGER},
        load_level = #{loadLevel,jdbcType=INTEGER},
        job_degree = #{jobDegree,jdbcType=INTEGER},
        enabled_report = #{enabledReport,jdbcType=BIT},
        local_mode = #{localMode,jdbcType=BIT},
        use_serial = #{useSerial,jdbcType=BIT},
        use_disprefer_list = #{useDispreferList,jdbcType=BIT},
        time_zone = #{timeZone,jdbcType=VARCHAR},
        cron = #{cron,jdbcType=VARCHAR},
        prefer_list = #{preferList,jdbcType=VARCHAR},
        pause_period_date = #{pausePeriodDate,jdbcType=VARCHAR},
        pause_period_time = #{pausePeriodTime,jdbcType=VARCHAR},
        sharding_item_parameters = #{shardingItemParameters,jdbcType=VARCHAR},
        job_parameter = #{jobParameter,jdbcType=VARCHAR},
        process_count_interval_seconds = #{processCountIntervalSeconds,jdbcType=INTEGER},
        failover = #{failover,jdbcType=BIT},
        dependencies = #{dependencies,jdbcType=VARCHAR},
        groups = #{groups,jdbcType=VARCHAR},
        description = #{description,jdbcType=VARCHAR},
        timeout_4_alarm_seconds = #{timeout4AlarmSeconds,jdbcType=INTEGER},
        timeout_seconds = #{timeoutSeconds,jdbcType=INTEGER},
        show_normal_log = #{showNormalLog,jdbcType=BIT},
        channel_name = #{channelName,jdbcType=VARCHAR},
        job_type = #{jobType,jdbcType=VARCHAR},
        queue_name = #{queueName,jdbcType=VARCHAR},
        create_by = #{createBy,jdbcType=VARCHAR},
        create_time = #{createTime,jdbcType=TIMESTAMP},
        last_update_by = #{lastUpdateBy,jdbcType=VARCHAR},
        last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP},
        zk_list = #{zkList,jdbcType=VARCHAR},
        namespace = #{namespace,jdbcType=VARCHAR},
        is_enabled = #{enabled,jdbcType=BIT},
        job_mode = #{jobMode,jdbcType=VARCHAR},
        custom_context = #{customContext,jdbcType=VARCHAR},
        rerun = #{rerun,jdbcType=BIT},
        up_stream = #{upStream,jdbcType=VARCHAR},
        down_stream = #{downStream,jdbcType=VARCHAR}
        where id = #{id,jdbcType=BIGINT}
    </update>

    <update id="updatePreferList" parameterType="java.util.List">
        update job_config set prefer_list = #{preferList,jdbcType=VARCHAR}
        where namespace = #{namespace,jdbcType=VARCHAR} and job_name = #{jobName,jdbcType=VARCHAR}
    </update>

    <update id="updateStream" parameterType="com.vip.saturn.job.console.mybatis.entity.JobConfig4DB">
        update job_config
        set up_stream = #{upStream,jdbcType=VARCHAR},
        down_stream = #{downStream,jdbcType=VARCHAR},
        last_update_by = #{lastUpdateBy,jdbcType=VARCHAR},
        last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP}
        where namespace = #{namespace,jdbcType=VARCHAR} and job_name = #{jobName,jdbcType=VARCHAR}
    </update>

    <update id="addToGroups">
        UPDATE job_config
        SET last_update_by = #{lastUpdateBy,jdbcType=VARCHAR},
        groups =
        (
        CASE
            WHEN groups REGEXP '^${groupName},' THEN groups
            WHEN groups REGEXP ',${groupName}$' THEN groups
            WHEN groups REGEXP ',${groupName},' THEN groups
            WHEN groups IS NULL OR groups = '' THEN CONCAT(groups,'${groupName}')
            ELSE CONCAT(groups,',${groupName}')
        END
        )
        WHERE namespace = #{namespace,jdbcType=VARCHAR}
        AND job_name IN
        <foreach collection="jobNames" index="index" item="item"
                 separator="," open="(" close=")">
            #{item,jdbcType=VARCHAR}
        </foreach>
    </update>

    <update id="batchSetGroups">
        UPDATE job_config
        SET last_update_by = #{lastUpdateBy,jdbcType=VARCHAR},
        groups =
        (
        CASE
            WHEN groups REGEXP '^${groupName},' THEN RIGHT(groups, LENGTH(groups) - LENGTH('${groupName},'))
            WHEN groups REGEXP ',${groupName}$' THEN LEFT(groups, LENGTH(groups) - LENGTH(',${groupName}'))
            WHEN groups REGEXP ',${groupName},' THEN REPLACE(groups, ',${groupName},', ',')
            WHEN groups = '${groupName}' THEN ''
            ELSE groups
        END
        )
        WHERE namespace = #{namespace,jdbcType=VARCHAR}
        AND job_name IN
        <foreach collection="jobNames" index="index" item="item"
                 separator="," open="(" close=")">
            #{item,jdbcType=VARCHAR}
        </foreach>
    </update>


    <select id="findHasValidJobNamespaces" resultType="java.lang.String">
        SELECT DISTINCT
          namespace
        FROM
          job_config jc
        where EXISTS
          (SELECT
            *
          FROM
            namespace_info ni
          WHERE jc.namespace = ni.namespace)
        <if test="isEnabled != null">
            AND is_enabled = #{isEnabled}
        </if>
        <if test="jobType != null">
            AND job_type = #{jobType}
        </if>
    </select>

    <select id="findValidJobsCronConfig" resultMap="BaseResultMap">
        SELECT DISTINCT
          namespace,
          cron,
          time_zone
        FROM
          job_config jc
        WHERE is_enabled = 1
          AND cron != ''
          AND EXISTS
          (SELECT
            *
          FROM
            namespace_info ni
          WHERE jc.namespace = ni.namespace)
    </select>

</mapper>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy