<?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="org.springblade.system.mapper.ArchivedSettingMapper">
	<insert id="addArchivedSetting">
		INSERT INTO da_ky_archived_setting
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="archivedType != null and archivedType != ''">
				archived_type,
			</if>
			<if test="cycle != null and cycle != ''">
				cycle,
			</if>
			<if test="time != null and time != ''">
				`time`,
			</if>
			<if test="weekOfDay != null and weekOfDay != ''">
				week_of_day,
			</if>
			<if test="useStatus != null and useStatus != ''">
				use_status,
			</if>
			<if test="cronStr != null and cronStr != ''">
				cron_str,
			</if>
			<if test="monthDay != null and monthDay != ''">
				month_day,
			</if>
		</trim>
		<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
			<if test="archivedType != null and archivedType != ''">
				#{archivedType},
			</if>
			<if test="cycle != null and cycle != ''">
				#{cycle},
			</if>
			<if test="time != null and time != ''">
				#{time},
			</if>
			<if test="weekOfDay != null and weekOfDay != ''">
				#{weekOfDay},
			</if>
			<if test="useStatus != null and useStatus != ''">
				#{useStatus},
			</if>
			<if test="cronStr != null and cronStr != ''">
				#{cronStr},
			</if>
			<if test="monthDay != null and monthDay != ''">
				#{monthDay},
			</if>
		</trim>
	</insert>
	<update id="updateArchivedSetting">
		UPDATE da_ky_archived_setting
		<set>
			<if test="archivedType != null and archivedType != ''">
				archived_type = #{archivedType},
			</if>
			<if test="cycle != null and cycle != ''">
				cycle = #{cycle},
			</if>
			<if test="time != null and time != ''">
				`time` = #{time},
			</if>
			<if test="weekOfDay != null and weekOfDay != ''">
				week_of_day = #{weekOfDay},
			</if>
			<if test="useStatus != null and useStatus != ''">
				use_status = #{useStatus},
			</if>
			<if test="cronStr != null and cronStr != ''">
				cron_str = #{cronStr},
			</if>
			<if test="monthDay != null and monthDay != ''">
				month_day = #{monthDay},
			</if>
		</set>
		WHERE id = #{id}
	</update>
	<update id="updatecronExpression">
		UPDATE da_ky_sys_job
		SET cron_expression = #{cronStr}
		    where
			invoke_target = CASE
			WHEN #{archivedType} = '1' THEN 'archivedSetting.regularly'
			WHEN #{archivedType} = '2' THEN 'archivedSetting.noRegularly'
			ELSE invoke_target END
	</update>

	<select id="getArchivedSetting" resultType="org.springblade.system.domain.ArchivedSettingDto">
		SELECT
			id,
			archived_type AS archivedType,
			cycle,
			`time`,
			week_of_day AS weekOfDay,
			create_time AS createTime,
			update_time AS updateTime,
			use_status AS useStatus,
			cron_str AS cronStr,
			month_day AS monthDay
		FROM da_ky_archived_setting
	</select>
</mapper>
