<?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.usky.rule.mapper.RuleEngineCronMapper">
    <resultMap id="Base" type="com.usky.rule.domain.RuleEngineCron">
        <id column="id" property="id"/>
        <result column="rule_engine_id" property="ruleEngineId"/>
        <result column="cron" property="cron"/>
        <result column="updated_by" property="updatedBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="created_by" property="createdBy"/>
        <result column="create_time" property="createTime"/>
        <result column="tenant_id" property="tenantId"/>
    </resultMap>
    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO rule_engine_cron (rule_engine_id, cron, created_by, create_time, updated_by, update_time, tenant_id)
        VALUES (#{ruleEngineId}, #{cron}, #{createdBy}, NOW(), #{updatedBy}, NOW(), #{tenantId})
    </insert>
    <delete id="deleteByRuleEngineId">DELETE FROM rule_engine_cron WHERE rule_engine_id = #{ruleEngineId}</delete>
    <select id="selectByRuleEngineId" resultMap="Base">SELECT * FROM rule_engine_cron WHERE rule_engine_id = #{ruleEngineId}</select>

    <resultMap id="TurnedOnCronVO" type="com.usky.rule.vo.RuleEngineCronVO">
        <id column="id" property="id"/>
        <result column="rule_engine_id" property="ruleEngineId"/>
        <result column="cron" property="cron"/>
        <result column="project_id" property="projectId"/>
        <result column="space_id" property="spaceId"/>
        <result column="name" property="ruleEngineName"/>
        <result column="detail" property="detail"/>
    </resultMap>
    <select id="getTurnedOnCron" resultMap="TurnedOnCronVO">
        SELECT rec.id, rec.rule_engine_id, rec.cron, re.project_id, re.space_id, re.name, re.detail
        FROM rule_engine_cron rec
        JOIN (SELECT id, name, detail, project_id, space_id FROM rule_engine WHERE status = 1) re ON rec.rule_engine_id = re.id
    </select>
</mapper>
