<?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.goafanti.common.dao.WorkingHoursMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.WorkingHours">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="start" jdbcType="VARCHAR" property="start" />
    <result column="rest_start" jdbcType="VARCHAR" property="restStart" />
    <result column="rest_end" jdbcType="VARCHAR" property="restEnd" />
    <result column="end" jdbcType="VARCHAR" property="end" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="min_hours" jdbcType="DOUBLE" property="minHours" />
  </resultMap>
  <sql id="Base_Column_List">
    id, `name`, `type`, `start`, rest_start, rest_end, `end`, create_time, min_hours
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from working_hours
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from working_hours
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.WorkingHours" useGeneratedKeys="true">
    insert into working_hours (`name`, `type`, `start`,
      rest_start, rest_end, `end`,
      create_time, min_hours)
    values (#{name,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{start,jdbcType=VARCHAR},
      #{restStart,jdbcType=VARCHAR}, #{restEnd,jdbcType=VARCHAR}, #{end,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP}, #{minHours,jdbcType=DOUBLE})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.WorkingHours" useGeneratedKeys="true">
    insert into working_hours
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="name != null">
        `name`,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="start != null">
        `start`,
      </if>
      <if test="restStart != null">
        rest_start,
      </if>
      <if test="restEnd != null">
        rest_end,
      </if>
      <if test="end != null">
        `end`,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="minHours != null">
        min_hours,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="start != null">
        #{start,jdbcType=VARCHAR},
      </if>
      <if test="restStart != null">
        #{restStart,jdbcType=VARCHAR},
      </if>
      <if test="restEnd != null">
        #{restEnd,jdbcType=VARCHAR},
      </if>
      <if test="end != null">
        #{end,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="minHours != null">
        #{minHours,jdbcType=DOUBLE},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.WorkingHours">
    update working_hours
    <set>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=INTEGER},
      </if>
      <if test="start != null">
        `start` = #{start,jdbcType=VARCHAR},
      </if>
      <if test="restStart != null">
        rest_start = #{restStart,jdbcType=VARCHAR},
      </if>
      <if test="restEnd != null">
        rest_end = #{restEnd,jdbcType=VARCHAR},
      </if>
      <if test="end != null">
        `end` = #{end,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="minHours != null">
        min_hours = #{minHours,jdbcType=DOUBLE},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.WorkingHours">
    update working_hours
    set `name` = #{name,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=INTEGER},
      `start` = #{start,jdbcType=VARCHAR},
      rest_start = #{restStart,jdbcType=VARCHAR},
      rest_end = #{restEnd,jdbcType=VARCHAR},
      `end` = #{end,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      min_hours = #{minHours,jdbcType=DOUBLE}
    where id = #{id,jdbcType=INTEGER}
  </update>

    <select id="selectList" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from working_hours
  </select>

  <select id="selectBydepId"  resultType="com.goafanti.common.model.WorkingHours">
    select
    a.id,a.name,a.`type`, a.`start`, a.rest_start restStart, a.rest_end restEnd, a.`end`, a.create_time createTime,
    a.min_hours minHours
    from department d  left join working_hours a on d.working_hours_type =a.type
    where d.id = #{depId}
  </select>
  <select id="getTypeCount" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
  from working_hours where type= #{type}
  </select>

  <select id="getDepTypeCount" resultType="java.lang.Integer">
  select
    count(*)
    from department d  left join working_hours a on d.working_hours_type =a.type
    where a.id= #{id}
  </select>
</mapper>
