<?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="cn.timer.api.dao.kqgl.SpecialDateMapper" >
  <resultMap id="BaseResultMap" type="cn.timer.api.bean.kqgl.SpecialDate" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="kqzid" property="kqzid" jdbcType="INTEGER" />
    <result column="tsrq" property="tsrq" jdbcType="VARCHAR" />
    <result column="bcid" property="bcid" jdbcType="INTEGER" />
    <result column="lusj_time" property="lusjTime" jdbcType="BIGINT" />
    <result column="luryid" property="luryid" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="legalday" property="legalday" jdbcType="INTEGER" />
    
    <result column="bcname" property="bcname" jdbcType="VARCHAR" />
    <result column="sbdk1" property="sbdk1" jdbcType="VARCHAR" />
    <result column="xbdk1" property="xbdk1" jdbcType="VARCHAR" />
    <result column="sbdk2" property="sbdk2" jdbcType="VARCHAR" />
    <result column="xbdk2" property="xbdk2" jdbcType="VARCHAR" />
    <result column="sbdk3" property="sbdk3" jdbcType="VARCHAR" />
    <result column="xbdk3" property="xbdk3" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, kqzid, tsrq, bcid, lusj_time, luryid, type
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from kqgl_asso_teshu
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from kqgl_asso_teshu
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="cn.timer.api.bean.kqgl.SpecialDate" >
    insert into kqgl_asso_teshu (id, kqzid, tsrq, 
      bcid, lusj_time, luryid, 
      type)
    values (#{id,jdbcType=INTEGER}, #{kqzid,jdbcType=INTEGER}, #{tsrq,jdbcType=VARCHAR}, 
      #{bcid,jdbcType=INTEGER}, #{lusjTime,jdbcType=BIGINT}, #{luryid,jdbcType=INTEGER}, 
      #{type,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="cn.timer.api.bean.kqgl.SpecialDate" >
    insert into kqgl_asso_teshu
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="kqzid != null" >
        kqzid,
      </if>
      <if test="tsrq != null" >
        tsrq,
      </if>
      <if test="bcid != null" >
        bcid,
      </if>
      <if test="lusjTime != null" >
        lusj_time,
      </if>
      <if test="luryid != null" >
        luryid,
      </if>
      <if test="type != null" >
        type,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="kqzid != null" >
        #{kqzid,jdbcType=INTEGER},
      </if>
      <if test="tsrq != null" >
        #{tsrq,jdbcType=VARCHAR},
      </if>
      <if test="bcid != null" >
        #{bcid,jdbcType=INTEGER},
      </if>
      <if test="lusjTime != null" >
        #{lusjTime,jdbcType=BIGINT},
      </if>
      <if test="luryid != null" >
        #{luryid,jdbcType=INTEGER},
      </if>
      <if test="type != null" >
        #{type,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.timer.api.bean.kqgl.SpecialDate" >
    update kqgl_asso_teshu
    <set >
      <if test="kqzid != null" >
        kqzid = #{kqzid,jdbcType=INTEGER},
      </if>
      <if test="tsrq != null" >
        tsrq = #{tsrq,jdbcType=VARCHAR},
      </if>
      <if test="bcid != null" >
        bcid = #{bcid,jdbcType=INTEGER},
      </if>
      <if test="lusjTime != null" >
        lusj_time = #{lusjTime,jdbcType=BIGINT},
      </if>
      <if test="luryid != null" >
        luryid = #{luryid,jdbcType=INTEGER},
      </if>
      <if test="type != null" >
        type = #{type,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.timer.api.bean.kqgl.SpecialDate" >
    update kqgl_asso_teshu
    set kqzid = #{kqzid,jdbcType=INTEGER},
      tsrq = #{tsrq,jdbcType=VARCHAR},
      bcid = #{bcid,jdbcType=INTEGER},
      lusj_time = #{lusjTime,jdbcType=BIGINT},
      luryid = #{luryid,jdbcType=INTEGER},
      type = #{type,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <insert id="insertKqglAssoTeshuList" parameterType="java.util.List" >
	    insert into kqgl_asso_teshu (kqzid, tsrq, bcid, lusj_time, luryid, type,legalday)
	    <foreach collection="list" item="item" index="index" open="values " close="" separator=",">
	   	(
	      <if test="item.kqzid != null" >
	        #{item.kqzid,jdbcType=INTEGER},
	      </if>
	      <if test="item.tsrq != null" >
	        #{item.tsrq,jdbcType=VARCHAR},
	      </if>
	      <if test="item.bcid != null" >
	        #{item.bcid,jdbcType=INTEGER},
	      </if>
	      <if test="item.lusjTime != null" >
	        #{item.lusjTime,jdbcType=BIGINT},
	      </if>
	      <if test="item.luryid != null" >
	        #{item.luryid,jdbcType=INTEGER},
	      </if>
	      <if test="item.type != null" >
	        #{item.type,jdbcType=INTEGER},
	      </if>
	      <if test="item.legalday != null" >
	        #{item.legalday,jdbcType=INTEGER}
	      </if>
	      )
	    </foreach>
   </insert>
  
  <delete id="deleteByPrimaryBykqzid" parameterType="java.lang.Integer" >
    delete from kqgl_asso_teshu
    where kqzid = #{kqzid,jdbcType=INTEGER}
  </delete>
  
   <select id="selectSpecialDatesByKqzid" resultMap="BaseResultMap">
    select teshu.*,bcsz.`name` bcname,bcsz.sbdk1,bcsz.xbdk1,bcsz.sbdk2,bcsz.xbdk2,bcsz.sbdk3,bcsz.xbdk3
	 from kqgl_asso_teshu teshu
	LEFT JOIN kqgl_asso_bcsz as bcsz on bcsz.id = teshu.bcid
	where teshu.kqzid = #{kqzid,jdbcType=INTEGER}
  </select>
  
  <select id="RestSpecialDatessetByKqzid" resultMap="BaseResultMap">
  		select * from kqgl_asso_teshu teshu
			where teshu.kqzid = #{kqzid}
			and teshu.bcid = 0 
  </select>
  <select id="ShouldSpecialDatessetByKqzid" resultMap="BaseResultMap">
  		select * from kqgl_asso_teshu teshu
			where teshu.kqzid = #{kqzid}
			and teshu.bcid != 0 
  </select>
  
  <select id="SpecialDateTroubleshooting" resultMap="BaseResultMap">
  		select * from kqgl_asso_teshu teshu
			where teshu.kqzid = #{kqzid,jdbcType=INTEGER}
			and teshu.tsrq = #{tsrq,jdbcType=VARCHAR}
			and teshu.bcid != 0
  </select>
  
  <select id="SpecialDateSpecialDayOff" resultMap="BaseResultMap">
  		select * from kqgl_asso_teshu teshu
			where teshu.kqzid = #{kqzid,jdbcType=INTEGER}
			and teshu.tsrq = #{tsrq,jdbcType=VARCHAR}
			and teshu.bcid = 0
  </select>
  
</mapper>