<?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.PunchCardDetailsMapper" >
  <resultMap id="BaseResultMap" type="cn.timer.api.bean.kqgl.PunchCardDetails" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="userid" property="userid" jdbcType="INTEGER" />
    <result column="data" property="data" jdbcType="VARCHAR" />
    <result column="sbdk1" property="sbdk1" jdbcType="BIGINT" />
    <result column="sbdk1jg" property="sbdk1jg" jdbcType="INTEGER" />
    <result column="xbdk1" property="xbdk1" jdbcType="BIGINT" />
    <result column="xbdk1jg" property="xbdk1jg" jdbcType="INTEGER" />
    <result column="sbdk2" property="sbdk2" jdbcType="BIGINT" />
    <result column="sbdk2jg" property="sbdk2jg" jdbcType="INTEGER" />
    <result column="xbdk2" property="xbdk2" jdbcType="BIGINT" />
    <result column="xbdk2jg" property="xbdk2jg" jdbcType="INTEGER" />
    <result column="sbdk3" property="sbdk3" jdbcType="BIGINT" />
    <result column="sbdk3jg" property="sbdk3jg" jdbcType="INTEGER" />
    <result column="xbdk3" property="xbdk3" jdbcType="BIGINT" />
    <result column="xbdk3jg" property="xbdk3jg" jdbcType="INTEGER" />
    <result column="ydkcs" property="ydkcs" jdbcType="INTEGER" />
    <result column="gzsc" property="gzsc" jdbcType="DOUBLE" />
    <result column="qyid" property="qyid" jdbcType="INTEGER" />
    <result column="dksj" property="dksj" jdbcType="BIGINT" />
    
    <result column="dept" property="dept" jdbcType="VARCHAR" />
    <result column="post" property="post" jdbcType="VARCHAR" />
    
    <result column="username" property="username" jdbcType="VARCHAR" />
    <result column="attdate" property="attdate" jdbcType="VARCHAR" />
	<result column="bcname" property="bcname" jdbcType="VARCHAR" />
	<result column="bcsbdk1" property="bcsbdk1" jdbcType="VARCHAR" />
	<result column="bcxbdk1" property="bcxbdk1" jdbcType="VARCHAR" />
	<result column="bcsbdk2" property="bcsbdk2" jdbcType="VARCHAR" />
	<result column="bcxbdk2" property="bcxbdk2" jdbcType="VARCHAR" />
	<result column="bcsbdk3" property="bcsbdk3" jdbcType="VARCHAR" />
	<result column="bcxbdk3" property="bcxbdk3" jdbcType="VARCHAR" />
	
  </resultMap>
  <sql id="Base_Column_List" >
    id, userid, data, sbdk1, sbdk1jg, xbdk1, xbdk1jg, sbdk2, sbdk2jg, xbdk2, xbdk2jg, 
    sbdk3, sbdk3jg, xbdk3, xbdk3jg, ydkcs, gzsc, qyid, dksj
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from kqgl_asso_dkmx
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from kqgl_asso_dkmx
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="cn.timer.api.bean.kqgl.PunchCardDetails" useGeneratedKeys="true" keyProperty="id">
    insert into kqgl_asso_dkmx ( userid, data, 
      sbdk1, sbdk1jg, xbdk1, 
      xbdk1jg, sbdk2, sbdk2jg, 
      xbdk2, xbdk2jg, sbdk3, 
      sbdk3jg, xbdk3, xbdk3jg, 
      ydkcs, gzsc, qyid, dksj
      )
    values (#{userid,jdbcType=INTEGER}, #{data,jdbcType=VARCHAR}, 
      #{sbdk1,jdbcType=BIGINT}, #{sbdk1jg,jdbcType=INTEGER}, #{xbdk1,jdbcType=BIGINT}, 
      #{xbdk1jg,jdbcType=INTEGER}, #{sbdk2,jdbcType=BIGINT}, #{sbdk2jg,jdbcType=INTEGER}, 
      #{xbdk2,jdbcType=BIGINT}, #{xbdk2jg,jdbcType=INTEGER}, #{sbdk3,jdbcType=BIGINT}, 
      #{sbdk3jg,jdbcType=INTEGER}, #{xbdk3,jdbcType=BIGINT}, #{xbdk3jg,jdbcType=INTEGER}, 
      #{ydkcs,jdbcType=INTEGER}, #{gzsc,jdbcType=DOUBLE}, #{qyid,jdbcType=INTEGER}, #{dksj,jdbcType=BIGINT}
      )
  </insert>
  <insert id="insertSelective" parameterType="cn.timer.api.bean.kqgl.PunchCardDetails" useGeneratedKeys="true" keyProperty="id">
    insert into kqgl_asso_dkmx
    <trim prefix="(" suffix=")" suffixOverrides="," >
      
      <if test="userid != null" >
        userid,
      </if>
      <if test="data != null" >
        data,
      </if>
      <if test="sbdk1 != null" >
        sbdk1,
      </if>
      <if test="sbdk1jg != null" >
        sbdk1jg,
      </if>
      <if test="xbdk1 != null" >
        xbdk1,
      </if>
      <if test="xbdk1jg != null" >
        xbdk1jg,
      </if>
      <if test="sbdk2 != null" >
        sbdk2,
      </if>
      <if test="sbdk2jg != null" >
        sbdk2jg,
      </if>
      <if test="xbdk2 != null" >
        xbdk2,
      </if>
      <if test="xbdk2jg != null" >
        xbdk2jg,
      </if>
      <if test="sbdk3 != null" >
        sbdk3,
      </if>
      <if test="sbdk3jg != null" >
        sbdk3jg,
      </if>
      <if test="xbdk3 != null" >
        xbdk3,
      </if>
      <if test="xbdk3jg != null" >
        xbdk3jg,
      </if>
      <if test="ydkcs != null" >
        ydkcs,
      </if>
      <if test="gzsc != null" >
        gzsc,
      </if>
      <if test="qyid != null" >
        qyid,
      </if>
      <if test="dksj != null" >
        dksj,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      
      <if test="userid != null" >
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="data != null" >
        #{data,jdbcType=VARCHAR},
      </if>
      <if test="sbdk1 != null" >
        #{sbdk1,jdbcType=BIGINT},
      </if>
      <if test="sbdk1jg != null" >
        #{sbdk1jg,jdbcType=INTEGER},
      </if>
      <if test="xbdk1 != null" >
        #{xbdk1,jdbcType=BIGINT},
      </if>
      <if test="xbdk1jg != null" >
        #{xbdk1jg,jdbcType=INTEGER},
      </if>
      <if test="sbdk2 != null" >
        #{sbdk2,jdbcType=BIGINT},
      </if>
      <if test="sbdk2jg != null" >
        #{sbdk2jg,jdbcType=INTEGER},
      </if>
      <if test="xbdk2 != null" >
        #{xbdk2,jdbcType=BIGINT},
      </if>
      <if test="xbdk2jg != null" >
        #{xbdk2jg,jdbcType=INTEGER},
      </if>
      <if test="sbdk3 != null" >
        #{sbdk3,jdbcType=BIGINT},
      </if>
      <if test="sbdk3jg != null" >
        #{sbdk3jg,jdbcType=INTEGER},
      </if>
      <if test="xbdk3 != null" >
        #{xbdk3,jdbcType=BIGINT},
      </if>
      <if test="xbdk3jg != null" >
        #{xbdk3jg,jdbcType=INTEGER},
      </if>
      <if test="ydkcs != null" >
        #{ydkcs,jdbcType=INTEGER},
      </if>
      <if test="gzsc != null" >
        #{gzsc,jdbcType=DOUBLE},
      </if>
      <if test="qyid != null" >
        #{qyid,jdbcType=INTEGER},
      </if>
      <if test="dksj != null" >
        #{dksj,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.timer.api.bean.kqgl.PunchCardDetails" >
    update kqgl_asso_dkmx
    <set >
      <if test="userid != null" >
        userid = #{userid,jdbcType=INTEGER},
      </if>
      <if test="data != null" >
        data = #{data,jdbcType=VARCHAR},
      </if>
      <if test="sbdk1 != null" >
        sbdk1 = #{sbdk1,jdbcType=BIGINT},
      </if>
      <if test="sbdk1jg != null" >
        sbdk1jg = #{sbdk1jg,jdbcType=INTEGER},
      </if>
      <if test="xbdk1 != null" >
        xbdk1 = #{xbdk1,jdbcType=BIGINT},
      </if>
      <if test="xbdk1jg != null" >
        xbdk1jg = #{xbdk1jg,jdbcType=INTEGER},
      </if>
      <if test="sbdk2 != null" >
        sbdk2 = #{sbdk2,jdbcType=BIGINT},
      </if>
      <if test="sbdk2jg != null" >
        sbdk2jg = #{sbdk2jg,jdbcType=INTEGER},
      </if>
      <if test="xbdk2 != null" >
        xbdk2 = #{xbdk2,jdbcType=BIGINT},
      </if>
      <if test="xbdk2jg != null" >
        xbdk2jg = #{xbdk2jg,jdbcType=INTEGER},
      </if>
      <if test="sbdk3 != null" >
        sbdk3 = #{sbdk3,jdbcType=BIGINT},
      </if>
      <if test="sbdk3jg != null" >
        sbdk3jg = #{sbdk3jg,jdbcType=INTEGER},
      </if>
      <if test="xbdk3 != null" >
        xbdk3 = #{xbdk3,jdbcType=BIGINT},
      </if>
      <if test="xbdk3jg != null" >
        xbdk3jg = #{xbdk3jg,jdbcType=INTEGER},
      </if>
      <if test="ydkcs != null" >
        ydkcs = #{ydkcs,jdbcType=INTEGER},
      </if>
      <if test="gzsc != null" >
        gzsc = #{gzsc,jdbcType=DOUBLE},
      </if>
      <if test="qyid != null" >
        qyid = #{qyid,jdbcType=INTEGER},
      </if>
      <if test="dksj != null" >
        dksj = #{dksj,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.timer.api.bean.kqgl.PunchCardDetails" >
    update kqgl_asso_dkmx
    set userid = #{userid,jdbcType=INTEGER},
      data = #{data,jdbcType=VARCHAR},
      sbdk1 = #{sbdk1,jdbcType=BIGINT},
      sbdk1jg = #{sbdk1jg,jdbcType=INTEGER},
      xbdk1 = #{xbdk1,jdbcType=BIGINT},
      xbdk1jg = #{xbdk1jg,jdbcType=INTEGER},
      sbdk2 = #{sbdk2,jdbcType=BIGINT},
      sbdk2jg = #{sbdk2jg,jdbcType=INTEGER},
      xbdk2 = #{xbdk2,jdbcType=BIGINT},
      xbdk2jg = #{xbdk2jg,jdbcType=INTEGER},
      sbdk3 = #{sbdk3,jdbcType=BIGINT},
      sbdk3jg = #{sbdk3jg,jdbcType=INTEGER},
      xbdk3 = #{xbdk3,jdbcType=BIGINT},
      xbdk3jg = #{xbdk3jg,jdbcType=INTEGER},
      ydkcs = #{ydkcs,jdbcType=INTEGER},
      gzsc = #{gzsc,jdbcType=DOUBLE},
      qyid = #{qyid,jdbcType=INTEGER},
      dksj = #{dksj,jdbcType=BIGINT}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <update id="ModifyPunchDetails" parameterType="cn.timer.api.bean.kqgl.PunchCardDetails" >
    update kqgl_asso_dkmx
    set sbdk1 = #{sbdk1,jdbcType=BIGINT},
      sbdk1jg = #{sbdk1jg,jdbcType=INTEGER},
      xbdk1 = #{xbdk1,jdbcType=BIGINT},
      xbdk1jg = #{xbdk1jg,jdbcType=INTEGER},
      sbdk2 = #{sbdk2,jdbcType=BIGINT},
      sbdk2jg = #{sbdk2jg,jdbcType=INTEGER},
      xbdk2 = #{xbdk2,jdbcType=BIGINT},
      xbdk2jg = #{xbdk2jg,jdbcType=INTEGER},
      sbdk3 = #{sbdk3,jdbcType=BIGINT},
      sbdk3jg = #{sbdk3jg,jdbcType=INTEGER},
      xbdk3 = #{xbdk3,jdbcType=BIGINT},
      xbdk3jg = #{xbdk3jg,jdbcType=INTEGER},
      ydkcs = #{ydkcs,jdbcType=INTEGER},
      gzsc = #{gzsc,jdbcType=DOUBLE}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <select id="selectAttendanceDays" resultMap="BaseResultMap">
  		select * from kqgl_asso_dkmx dkmx
		where dkmx.userid = #{userid,jdbcType=INTEGER}
		and dkmx.dksj &gt;= #{start,jdbcType=BIGINT}
		and dkmx.dksj &lt;= #{end,jdbcType=BIGINT}
		and dkmx.qyid = #{qyid,jdbcType=INTEGER}
  </select>
  
  <select id="SingleAttendanceDays" resultMap="BaseResultMap">
  		select * from kqgl_asso_dkmx dkmx
		where dkmx.userid = #{userid,jdbcType=INTEGER}
		and dkmx.dksj &gt;= #{start,jdbcType=BIGINT}
		and dkmx.dksj &lt;= #{end,jdbcType=BIGINT}
  </select>
  
  <select id="SelectAttendanceDetails" resultMap="BaseResultMap">
  		select DISTINCT info.`name` as username , 
			dkjl.attdate, 
			bcsz.`name` as bcname,
			bcsz.sbdk1 as bcsbdk1,
			bcsz.xbdk1 as bcxbdk1,
			bcsz.sbdk2 as bcsbdk2,
			bcsz.xbdk2 as bcxbdk2,
			bcsz.sbdk3 as bcsbdk3,
			bcsz.xbdk3 as bcxbdk3,
			bmgw.dept,
			 bmgw.post,
			dkmx.* 
		from kqgl_asso_dkmx dkmx 
		LEFT JOIN yggl_main_emp as info on info.emp_num = dkmx.userid and info.org_code = #{qyid,jdbcType=INTEGER}
		LEFT JOIN (select m.name as post,um.name as dept,m.id as mid
				 from zzgl_bmgw_m m 
				 left join zzgl_bmgw_m um on um.id = m.up_id  
			) as bmgw on bmgw.mid = info.bmgw_id
		LEFT JOIN kqgl_asso_dkjl as dkjl on dkjl.dkmxid = dkmx.id
		LEFT JOIN kqgl_asso_bcsz as bcsz on bcsz.id = dkjl.bcid
		where dkmx.qyid = #{qyid,jdbcType=INTEGER}
		and dkmx.dksj &gt;= #{start,jdbcType=BIGINT}
		and dkmx.dksj &lt;= #{end,jdbcType=BIGINT}
  </select>
  
  <select id="QueryAttendanceDetails" resultMap="BaseResultMap">
  		select DISTINCT info.`name` as username , 
			dkjl.attdate, 
			bcsz.`name` as bcname,
			bcsz.sbdk1 as bcsbdk1,
			bcsz.xbdk1 as bcxbdk1,
			bcsz.sbdk2 as bcsbdk2,
			bcsz.xbdk2 as bcxbdk2,
			bcsz.sbdk3 as bcsbdk3,
			bcsz.xbdk3 as bcxbdk3,
			bmgw.dept,
			 bmgw.post,
			dkmx.* 
		from kqgl_asso_dkmx dkmx 
		LEFT JOIN yggl_main_emp as info on info.emp_num = dkmx.userid and info.org_code = #{qyid,jdbcType=INTEGER}
		LEFT JOIN (select m.name as post,um.name as dept,m.id as mid
				 from zzgl_bmgw_m m 
				 left join zzgl_bmgw_m um on um.id = m.up_id  
			) as bmgw on bmgw.mid = info.bmgw_id
		LEFT JOIN kqgl_asso_dkjl as dkjl on dkjl.dkmxid = dkmx.id
		LEFT JOIN kqgl_asso_bcsz as bcsz on bcsz.id = dkjl.bcid
		where dkmx.qyid = #{qyid,jdbcType=INTEGER}
		<if test="start != ''" >
			and dkmx.dksj &gt;= #{start,jdbcType=VARCHAR}
		</if>
		<if test="end != ''" >
			and dkmx.dksj &lt;= #{end,jdbcType=VARCHAR}
		</if>
		<if test="text != ''" >
			and (info.`name` like CONCAT('%',#{text,jdbcType=VARCHAR},'%') or dkmx.userid = #{text,jdbcType=VARCHAR})
		</if>
		
  </select>
  
  <select id="selectWorkingHours" resultType="java.lang.Integer" >
  	select IFNULL(SUM(dkmx.gzsc),0) from kqgl_asso_dkmx dkmx 
	where dkmx.userid = #{userid,jdbcType=INTEGER}
	and dkmx.dksj &gt;= #{start,jdbcType=VARCHAR}
	and dkmx.dksj &lt;= #{end,jdbcType=VARCHAR}
  </select>
  
  <select id="selectNoScheduling" resultMap="BaseResultMap">
	  select * from kqgl_asso_dkmx dkmx
		where dkmx.id in (select dkjl.dkmxid from kqgl_asso_dkjl dkjl
		where dkjl.attime &gt;= #{start,jdbcType=VARCHAR}
		and dkjl.attime &lt;= #{end,jdbcType=VARCHAR}
		and dkjl.user_id = #{userid,jdbcType=INTEGER}
		and dkjl.bcid = 0
		GROUP BY dkjl.dkmxid);
  </select>
  
</mapper>