<?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.xunmei.system.mapper.SysWorkTimeSetMapper">

    <resultMap type="com.xunmei.system.domain.SysWorkTimeSet" id="SysWorkTimeSetResult">
                <result property="id" column="id"/>
                <result property="orgId" column="org_id"/>
                <result property="orgName" column="org_name"/>
                <result property="monthEnable" column="month_enable"/>
                <result property="monday" column="monday"/>
                <result property="tuesday" column="tuesday"/>
                <result property="wednesday" column="wednesday"/>
                <result property="thursday" column="thursday"/>
                <result property="friday" column="friday"/>
                <result property="saturday" column="saturday"/>
                <result property="sunday" column="sunday"/>
                <result property="workTime" column="work_time"/>
                <result property="openTime" column="open_time"/>
                <result property="noonbreakStart" column="noonbreak_start"/>
                <result property="noonbreakEnd" column="noonbreak_end"/>
                <result property="closeTime" column="close_time"/>
                <result property="workOffTime" column="work_off_time"/>
                <result property="createTime" column="create_time"/>
                <result property="modifiedId" column="modified_id"/>
                <result property="modifiedName" column="modified_name"/>
                <result property="updateTime" column="update_time"/>
                <result property="year" column="year"/>
                <result property="deleted" column="deleted"/>
                <result property="effectiveDate" column="effective_date"/>
    </resultMap>

    <sql id="selectSysWorkTimeSetVo">
        select id, org_id, org_name, month_enable, monday, tuesday, wednesday, thursday, friday, saturday, sunday, work_time, open_time, noonbreak_start, noonbreak_end, close_time, work_off_time, create_time, modified_id, modified_name, update_time, year, deleted, effective_date
        from sys_work_time_set
    </sql>

    <select id="selectSysWorkTimeSetList" parameterType="com.xunmei.system.domain.SysWorkTimeSet"
            resultMap="SysWorkTimeSetResult">
        <include refid="selectSysWorkTimeSetVo"/>
        <where>
                        <if test="orgId != null ">
                            and org_id = #{orgId}
                        </if>
                        <if test="orgName != null  and orgName != ''">
                            and org_name like concat('%', #{orgName}, '%')
                        </if>
                        <if test="monthEnable != null ">
                            and month_enable = #{monthEnable}
                        </if>
                        <if test="monday != null ">
                            and monday = #{monday}
                        </if>
                        <if test="tuesday != null ">
                            and tuesday = #{tuesday}
                        </if>
                        <if test="wednesday != null ">
                            and wednesday = #{wednesday}
                        </if>
                        <if test="thursday != null ">
                            and thursday = #{thursday}
                        </if>
                        <if test="friday != null ">
                            and friday = #{friday}
                        </if>
                        <if test="saturday != null ">
                            and saturday = #{saturday}
                        </if>
                        <if test="sunday != null ">
                            and sunday = #{sunday}
                        </if>
                        <if test="workTime != null  and workTime != ''">
                            and work_time = #{workTime}
                        </if>
                        <if test="openTime != null  and openTime != ''">
                            and open_time = #{openTime}
                        </if>
                        <if test="noonbreakStart != null  and noonbreakStart != ''">
                            and noonbreak_start = #{noonbreakStart}
                        </if>
                        <if test="noonbreakEnd != null  and noonbreakEnd != ''">
                            and noonbreak_end = #{noonbreakEnd}
                        </if>
                        <if test="closeTime != null  and closeTime != ''">
                            and close_time = #{closeTime}
                        </if>
                        <if test="workOffTime != null  and workOffTime != ''">
                            and work_off_time = #{workOffTime}
                        </if>
                        <if test="modifiedId != null ">
                            and modified_id = #{modifiedId}
                        </if>
                        <if test="modifiedName != null  and modifiedName != ''">
                            and modified_name like concat('%', #{modifiedName}, '%')
                        </if>
                        <if test="year != null ">
                            and year = #{year}
                        </if>
                        <if test="deleted != null ">
                            and deleted = #{deleted}
                        </if>
                        <if test="effectiveDate != null ">
                            and effective_date = #{effectiveDate}
                        </if>
        </where>
    </select>

    <select id="selectSysWorkTimeSetById" parameterType="Long"
            resultMap="SysWorkTimeSetResult">
            <include refid="selectSysWorkTimeSetVo"/>
            where id = #{id}
    </select>
    <select id="selectByPage" resultType="com.xunmei.system.domain.SysWorkTimeSet">

select  * from sys_work_time_set

    </select>
    <select id="findWorkTimeForOrgIdsAndErrectiveDate" resultType="com.xunmei.system.domain.SysWorkTimeSet">

        select s.* from sys_work_time_set s where s.org_id in
        <foreach item="orgId" collection="orgIds" open="(" separator="," close=")">
            #{orgId}
        </foreach>
         and s.effective_date = #{effectiveDate} and s.deleted = false

    </select>
    <select id="checkData" resultType="java.lang.Integer">

        select count(*) from sys_work_time a
        where a.is_manual=1
        <if test="request.orgIds!=null and request.orgIds.size()>0">
            and a.org_id in
            <foreach collection="request.orgIds" item="orgId" open="(" close=")" separator=",">
                #{orgId}
            </foreach>
        </if>
        <if test="request.effectiveDate!=null">
            and ymd_date &gt;= #{request.effectiveDate}
        </if>
    </select>
    <select id="selectWorkTimeSetList" resultType="com.xunmei.system.domain.SysWorkTimeSet">
        select a.*,b.name as orgName from sys_work_time_set a left join sys_org b on a.org_id=b.id where a.deleted=0 and
        a.org_id in
        <foreach collection="request.orgIds" item="orgId" open="(" close=")" separator=",">
            #{orgId}
        </foreach>


    </select>


    <insert id="insertSysWorkTimeSet" parameterType="com.xunmei.system.domain.SysWorkTimeSet"            useGeneratedKeys="true" keyProperty="id">
        insert into sys_work_time_set
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="orgId != null">org_id,
                    </if>
                    <if test="orgName != null">org_name,
                    </if>
                    <if test="monthEnable != null">month_enable,
                    </if>
                    <if test="monday != null">monday,
                    </if>
                    <if test="tuesday != null">tuesday,
                    </if>
                    <if test="wednesday != null">wednesday,
                    </if>
                    <if test="thursday != null">thursday,
                    </if>
                    <if test="friday != null">friday,
                    </if>
                    <if test="saturday != null">saturday,
                    </if>
                    <if test="sunday != null">sunday,
                    </if>
                    <if test="workTime != null">work_time,
                    </if>
                    <if test="openTime != null">open_time,
                    </if>
                    <if test="noonbreakStart != null">noonbreak_start,
                    </if>
                    <if test="noonbreakEnd != null">noonbreak_end,
                    </if>
                    <if test="closeTime != null">close_time,
                    </if>
                    <if test="workOffTime != null">work_off_time,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="modifiedId != null">modified_id,
                    </if>
                    <if test="modifiedName != null">modified_name,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
                    <if test="year != null">year,
                    </if>
                    <if test="deleted != null">deleted,
                    </if>
                    <if test="effectiveDate != null">effective_date,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="orgId != null">#{orgId},
                    </if>
                    <if test="orgName != null">#{orgName},
                    </if>
                    <if test="monthEnable != null">#{monthEnable},
                    </if>
                    <if test="monday != null">#{monday},
                    </if>
                    <if test="tuesday != null">#{tuesday},
                    </if>
                    <if test="wednesday != null">#{wednesday},
                    </if>
                    <if test="thursday != null">#{thursday},
                    </if>
                    <if test="friday != null">#{friday},
                    </if>
                    <if test="saturday != null">#{saturday},
                    </if>
                    <if test="sunday != null">#{sunday},
                    </if>
                    <if test="workTime != null">#{workTime},
                    </if>
                    <if test="openTime != null">#{openTime},
                    </if>
                    <if test="noonbreakStart != null">#{noonbreakStart},
                    </if>
                    <if test="noonbreakEnd != null">#{noonbreakEnd},
                    </if>
                    <if test="closeTime != null">#{closeTime},
                    </if>
                    <if test="workOffTime != null">#{workOffTime},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="modifiedId != null">#{modifiedId},
                    </if>
                    <if test="modifiedName != null">#{modifiedName},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
                    <if test="year != null">#{year},
                    </if>
                    <if test="deleted != null">#{deleted},
                    </if>
                    <if test="effectiveDate != null">#{effectiveDate},
                    </if>
        </trim>
    </insert>

    <update id="updateSysWorkTimeSet" parameterType="com.xunmei.system.domain.SysWorkTimeSet">
        update sys_work_time_set
        <trim prefix="SET" suffixOverrides=",">
                    <if test="orgId != null">org_id =
                        #{orgId},
                    </if>
                    <if test="orgName != null">org_name =
                        #{orgName},
                    </if>
                    <if test="monthEnable != null">month_enable =
                        #{monthEnable},
                    </if>
                    <if test="monday != null">monday =
                        #{monday},
                    </if>
                    <if test="tuesday != null">tuesday =
                        #{tuesday},
                    </if>
                    <if test="wednesday != null">wednesday =
                        #{wednesday},
                    </if>
                    <if test="thursday != null">thursday =
                        #{thursday},
                    </if>
                    <if test="friday != null">friday =
                        #{friday},
                    </if>
                    <if test="saturday != null">saturday =
                        #{saturday},
                    </if>
                    <if test="sunday != null">sunday =
                        #{sunday},
                    </if>
                    <if test="workTime != null">work_time =
                        #{workTime},
                    </if>
                    <if test="openTime != null">open_time =
                        #{openTime},
                    </if>
                    <if test="noonbreakStart != null">noonbreak_start =
                        #{noonbreakStart},
                    </if>
                    <if test="noonbreakEnd != null">noonbreak_end =
                        #{noonbreakEnd},
                    </if>
                    <if test="closeTime != null">close_time =
                        #{closeTime},
                    </if>
                    <if test="workOffTime != null">work_off_time =
                        #{workOffTime},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="modifiedId != null">modified_id =
                        #{modifiedId},
                    </if>
                    <if test="modifiedName != null">modified_name =
                        #{modifiedName},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
                    <if test="year != null">year =
                        #{year},
                    </if>
                    <if test="deleted != null">deleted =
                        #{deleted},
                    </if>
                    <if test="effectiveDate != null">effective_date =
                        #{effectiveDate},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysWorkTimeSetById" parameterType="Long">
        delete
        from sys_work_time_set where id = #{id}
    </delete>

    <delete id="deleteSysWorkTimeSetByIds" parameterType="String">
        delete from sys_work_time_set where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>