<?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.saye.hospitalgd.mapper.quzrtz.BaseQuartzConfigMapper">
	<resultMap id="BaseResultMap" type="com.saye.hospitalgd.model.BaseQuartzConfigEntity" >
        <id column="CONFIGID" property="configId" jdbcType="VARCHAR" />
        <result column="QUARTZ_NAME" property="quartzName" jdbcType="VARCHAR" />
        <result column="QUARTZ_GROUP" property="quartzGroup" jdbcType="VARCHAR" />
        <result column="STATUS" property="status" jdbcType="VARCHAR" />     
        <result column="QUARTZ_CLASS" property="quartzClass" jdbcType="VARCHAR" />
        <result column="REMARK" property="remark" jdbcType="VARCHAR" />
        <result column="CREATEUSERID" property="createUserId" jdbcType="VARCHAR" />
        <result column="EXPRESSION" property="expression" jdbcType="VARCHAR" />
        <result column="CREATE_TIME" property="createTime" jdbcType="VARCHAR" />
        <result column="NAME" property="name" jdbcType="VARCHAR" />
    </resultMap>

	<!-- 查询所有任务 -->
    <select id="findAll" parameterType="HashMap" resultMap="BaseResultMap">
	    select bqc.CONFIGID,bqc.QUARTZ_NAME,bqc.QUARTZ_GROUP,bqc.STATUS,bqc.QUARTZ_CLASS,bqc.REMARK,bqc.CREATEUSERID,bqc.EXPRESSION,bqc.CREATE_TIME from base_quartz_config bqc
    	<where>
    		<if test="part_name!=null and part_name!=''">
				and bqc.QUARTZ_NAME like concat('%',concat(#{quartz_name},'%'))
			</if>
			<if test="part_type!=null and part_type!=''">
				and bqc.CONFIGID = #{configId}
			</if>
    	</where>
    	order by bqc.CONFIGID
    </select>
    
    <!-- 根据id查询定时任务 -->
    <select id="findEntityById" resultMap="BaseResultMap">
	    select CONFIGID,QUARTZ_NAME,QUARTZ_GROUP,STATUS,QUARTZ_CLASS,REMARK,CREATEUSERID,EXPRESSION,CREATE_TIME from base_quartz_config
	    where CONFIGID=#{id}
    </select>
    
    <!-- 更新定时任务 -->
    <update id="updateQuartzConfigByEntity" parameterType="com.saye.hospitalgd.model.BaseQuartzConfigEntity">
    	update base_quartz_config set QUARTZ_NAME=#{quartzName},QUARTZ_GROUP=#{quartzGroup},STATUS=#{status},QUARTZ_CLASS=#{quartzClass}
    	,REMARK=#{remark},CREATEUSERID=#{createUserId},EXPRESSION=#{expression}
    	where CONFIGID=#{configId}
    </update>
    
    <!-- 查询最大任务号 -->
    <select id="findMaxId" resultType="hashMap">
    	select max(CONFIGID) as id from base_quartz_config
    </select>
    
    <!-- 删除任务 -->
    <delete id="deleteQuartzConfigById">
    	delete from base_quartz_config where CONFIGID=#{id}
    </delete>
    
    <!-- 添加定时任务 -->
    <insert id="addQuartz" parameterType="hashMap">
    	insert into base_quartz_config(configid, quartz_name, status, quartz_class, remark, createuserid, expression, create_time)
   		values(#{id},#{quartzName},#{status}, #{quartz_class}, #{remark}, #{createuserid}, #{expression}, #{create_time} )
    </insert>

    <!-- 更新定时任务信息 -->
    <update id="updateQuartzConfigById">
    	update base_quartz_config set QUARTZ_NAME=#{quartzName},QUARTZ_GROUP=#{quartzGroup},QUARTZ_CLASS=#{quartzClass}
    	,REMARK=#{remark},EXPRESSION=#{expression}
    	 where CONFIGID=#{configId}
    </update>


</mapper>