<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.WorkShiftInfoDAO">
    <resultMap id="WorkShiftInfoMap" type="com.jpsoft.shinestar.modules.base.entity.WorkShiftInfo">
        <id property="id" column="id_"/>
        <result property="number" column="number_"/>
        <result property="name" column="name_"/>
        <result property="swipeCardCount" column="swipe_card_count"/>
        <result property="days" column="days_"/>
        <result property="workDayType" column="work_day_type"/>
        <result property="workTime" column="work_time"/>
        <result property="closingDayType" column="closing_day_type"/>
        <result property="closingTime" column="closing_time"/>
        <result property="workStartTime" column="work_start_time"/>
        <result property="workEndTime" column="work_end_time"/>
        <result property="closingStartTime" column="closing_start_time"/>
        <result property="closingEndTime" column="closing_end_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.WorkShiftInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_work_shift_info
	    (id_,number_,name_,swipe_card_count,days_,
	    work_day_type,work_time,closing_day_type,closing_time,
	    work_start_time,work_end_time,closing_start_time,closing_end_time,
	    create_by,create_time,update_by,update_time,del_flag)
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{number,jdbcType=VARCHAR}
			,#{name,jdbcType=VARCHAR}
			,#{swipeCardCount,jdbcType= NUMERIC }
			,#{days,jdbcType= NUMERIC }
			,#{workDayType,jdbcType=NUMERIC}
			,#{workTime,jdbcType=VARCHAR}
			,#{closingDayType,jdbcType=NUMERIC}
			,#{closingTime,jdbcType=VARCHAR}
			,#{workStartTime,jdbcType=VARCHAR}
			,#{workEndTime,jdbcType=VARCHAR}
			,#{closingStartTime,jdbcType=VARCHAR}
			,#{closingEndTime,jdbcType=VARCHAR}
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{delFlag,jdbcType= NUMERIC }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_work_shift_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.WorkShiftInfo">
        update base_work_shift_info
        <set>
            <if test="number!=null">
                number_=#{number,jdbcType=VARCHAR},
            </if>
            <if test="name!=null">
                name_=#{name,jdbcType=VARCHAR},
            </if>
            <if test="swipeCardCount!=null">
                swipe_card_count=#{swipeCardCount,jdbcType= NUMERIC },
            </if>
            <if test="days!=null">
                days_=#{days,jdbcType= NUMERIC },
            </if>
            <if test="workDayType!=null">
                work_day_type=#{workDayType,jdbcType=NUMERIC},
            </if>
            <if test="workTime!=null">
                work_time=#{workTime,jdbcType=VARCHAR},
            </if>
            <if test="closingDayType!=null">
                closing_day_type=#{closingDayType,jdbcType=NUMERIC},
            </if>
            <if test="closingTime!=null">
                closing_time=#{closingTime,jdbcType=VARCHAR},
            </if>
            <if test="workStartTime!=null">
                work_start_time=#{workStartTime,jdbcType=VARCHAR},
            </if>
            <if test="workEndTime!=null">
                work_end_time=#{workEndTime,jdbcType=VARCHAR},
            </if>
            <if test="closingStartTime!=null">
                closing_start_time=#{closingStartTime,jdbcType=VARCHAR},
            </if>
            <if test="closingEndTime!=null">
                closing_end_time=#{closingEndTime,jdbcType=VARCHAR},
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="WorkShiftInfoMap">
        select * from base_work_shift_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_work_shift_info where id_=#{0}
    </select>
    <select id="list" resultMap="WorkShiftInfoMap">
        select * from base_work_shift_info where del_flag = 0
    </select>
    <select id="search" parameterType="hashmap" resultMap="WorkShiftInfoMap">
        <![CDATA[
			select * from base_work_shift_info
		]]>
        <where>
            del_flag = false
            <if test="searchParams.name != null">
                and name_ like #{searchParams.name}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByCompanyId" resultMap="WorkShiftInfoMap">
        SELECT
        *
        FROM
        base_work_shift_info
        WHERE
        del_flag = FALSE
        AND id_ IN ( SELECT shift_id FROM base_work_shift_company WHERE del_flag = 0 AND company_id = #{companyId} )
        ORDER BY
        number_+0 ASC
    </select>

    <select id="findNumberById" resultType="String">
        <![CDATA[
		SELECT
			number_
		FROM
			base_work_shift_info
		WHERE
			del_flag = FALSE
			AND id_ = #{id}
			limit 1
		]]>
    </select>
    <select id="sortIdsByNumber" resultType="String">
        <![CDATA[
		SELECT
			id_
		FROM
			base_work_shift_info
		WHERE
			del_flag = FALSE
		]]>
        <foreach collection="shiftIds" index="index" item="shiftId" open="and id_ in(" separator="," close=")">
            #{shiftId}
        </foreach>
        order by number_+0
    </select>

    <select id="findByCompanyIds" resultMap="WorkShiftInfoMap">
        SELECT
        *
        FROM
        base_work_shift_info
        WHERE
        del_flag = FALSE
        AND id_ IN (
        SELECT shift_id FROM base_work_shift_company
        where del_flag = 0
        <foreach collection="companyIds" index="index" item="companyId" open="and company_id in(" separator=","
                 close=")">
            #{companyId}
        </foreach>
        )
        ORDER BY
        number_+0 ASC
    </select>
    <select id="findByNumber" parameterType="string" resultMap="WorkShiftInfoMap">
        SELECT
        *
        FROM
        base_work_shift_info
        WHERE
        number_ = #{number}
        and del_flag = 0
        limit 1
    </select>
</mapper>