<?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.chinaitop.depot.intelligent.ventilation.mapper.TJobMapper" >
  <resultMap id="BaseResultMap" type="com.chinaitop.depot.intelligent.ventilation.model.TJob" >
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="task_number" property="taskNumber" jdbcType="VARCHAR" />
    <result column="task_start_time" property="taskStartTime" jdbcType="TIMESTAMP" />
    <result column="task_end_time" property="taskEndTime" jdbcType="TIMESTAMP" />
    <result column="task_state" property="taskState" jdbcType="INTEGER" />
    <result column="aeration_plan_number" property="aerationPlanNumber" jdbcType="VARCHAR" />
    <result column="creator" property="creator" jdbcType="VARCHAR" />
    <result column="creation_time" property="creationTime" jdbcType="TIMESTAMP" />
    <result column="operator" property="operator" jdbcType="VARCHAR" />
    <result column="org_id" property="orgId" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    id, task_number, task_start_time, task_end_time, task_state, aeration_plan_number, 
    creator, creation_time, operator, org_id
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.intelligent.ventilation.model.TJobExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_job
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.chinaitop.depot.intelligent.ventilation.model.TJobExample" >
    delete from t_job
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.chinaitop.depot.intelligent.ventilation.model.TJob" >
    insert into t_job (id, task_number, task_start_time, 
      task_end_time, task_state, aeration_plan_number, 
      creator, creation_time, operator, 
      org_id)
    values (#{id,jdbcType=VARCHAR}, #{taskNumber,jdbcType=VARCHAR}, #{taskStartTime,jdbcType=TIMESTAMP}, 
      #{taskEndTime,jdbcType=TIMESTAMP}, #{taskState,jdbcType=INTEGER}, #{aerationPlanNumber,jdbcType=VARCHAR}, 
      #{creator,jdbcType=VARCHAR}, #{creationTime,jdbcType=TIMESTAMP}, #{operator,jdbcType=VARCHAR}, 
      #{orgId,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.chinaitop.depot.intelligent.ventilation.model.TJob" >
    insert into t_job
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="taskNumber != null" >
        task_number,
      </if>
      <if test="taskStartTime != null" >
        task_start_time,
      </if>
      <if test="taskEndTime != null" >
        task_end_time,
      </if>
      <if test="taskState != null" >
        task_state,
      </if>
      <if test="aerationPlanNumber != null" >
        aeration_plan_number,
      </if>
      <if test="creator != null" >
        creator,
      </if>
      <if test="creationTime != null" >
        creation_time,
      </if>
      <if test="operator != null" >
        operator,
      </if>
      <if test="orgId != null" >
        org_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="taskNumber != null" >
        #{taskNumber,jdbcType=VARCHAR},
      </if>
      <if test="taskStartTime != null" >
        #{taskStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="taskEndTime != null" >
        #{taskEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="taskState != null" >
        #{taskState,jdbcType=INTEGER},
      </if>
      <if test="aerationPlanNumber != null" >
        #{aerationPlanNumber,jdbcType=VARCHAR},
      </if>
      <if test="creator != null" >
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="creationTime != null" >
        #{creationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="operator != null" >
        #{operator,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        #{orgId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.chinaitop.depot.intelligent.ventilation.model.TJobExample" resultType="java.lang.Integer" >
    select count(*) from t_job
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update t_job
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.taskNumber != null" >
        task_number = #{record.taskNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.taskStartTime != null" >
        task_start_time = #{record.taskStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.taskEndTime != null" >
        task_end_time = #{record.taskEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.taskState != null" >
        task_state = #{record.taskState,jdbcType=INTEGER},
      </if>
      <if test="record.aerationPlanNumber != null" >
        aeration_plan_number = #{record.aerationPlanNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.creator != null" >
        creator = #{record.creator,jdbcType=VARCHAR},
      </if>
      <if test="record.creationTime != null" >
        creation_time = #{record.creationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.operator != null" >
        operator = #{record.operator,jdbcType=VARCHAR},
      </if>
      <if test="record.orgId != null" >
        org_id = #{record.orgId,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update t_job
    set id = #{record.id,jdbcType=VARCHAR},
      task_number = #{record.taskNumber,jdbcType=VARCHAR},
      task_start_time = #{record.taskStartTime,jdbcType=TIMESTAMP},
      task_end_time = #{record.taskEndTime,jdbcType=TIMESTAMP},
      task_state = #{record.taskState,jdbcType=INTEGER},
      aeration_plan_number = #{record.aerationPlanNumber,jdbcType=VARCHAR},
      creator = #{record.creator,jdbcType=VARCHAR},
      creation_time = #{record.creationTime,jdbcType=TIMESTAMP},
      operator = #{record.operator,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=INTEGER}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  
  
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_job
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  
  <update id="updateByKey" parameterType="com.chinaitop.depot.intelligent.ventilation.model.TJob" >
    update t_job
    <set >
      <if test="taskNumber != null" >
        task_number = #{taskNumber,jdbcType=VARCHAR},
      </if>
      <if test="taskStartTime != null" >
       task_start_time = #{taskStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="taskEndTime != null" >
        task_end_time = #{taskEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="taskState != null" >
        task_state = #{taskState,jdbcType=INTEGER},
      </if>
      <if test="aerationPlanNumber != null" >
        aeration_plan_number = #{aerationPlanNumber,jdbcType=VARCHAR},
      </if>
      <if test="creator != null" >
        creator = #{creator,jdbcType=VARCHAR},
      </if>
      <if test="creationTime != null" >
        creation_time = #{creationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="operator != null" >
       operator = #{operator,jdbcType=VARCHAR}
      </if>
    </set>
    where aeration_plan_number = #{aerationPlanNumber,jdbcType=VARCHAR}
  </update>
  
  
  <select id="getJobTime" parameterType="java.lang.String" resultMap="BaseResultMap">
	  	SELECT
		<include refid="Base_Column_List" />
	FROM
		t_job
	WHERE
		aeration_plan_number IN(
			SELECT
				areation_plan_number
			FROM
				t_job_application
			WHERE
				v_cf_code = #{vCfCode,jdbcType=VARCHAR}
		)
	ORDER BY
		task_end_time DESC
  </select>
  
  <!-- 根据id查询信息 -->
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_job
    where id = #{id,jdbcType=VARCHAR}
  </select>
</mapper>