<?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.SysWorkTimeMapper">

    <resultMap type="com.xunmei.system.api.domain.SysWorkTime" id="SysWorkTimeResult">
                <result property="id" column="id"/>
                <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="closeTime" column="close_time"/>
                <result property="isEnable" column="is_enable"/>
                <result property="openTime" column="open_time"/>
                <result property="noonbreakStart" column="noonbreak_start"/>
                <result property="noonbreakEnd" column="noonbreak_end"/>
                <result property="orgId" column="org_id"/>
                <result property="workOffTime" column="work_off_time"/>
                <result property="workTime" column="work_time"/>
                <result property="workTimeMonthId" column="work_time_month_id"/>
                <result property="ymdDate" column="ymd_date"/>
                <result property="ymdDay" column="ymd_day"/>
                <result property="ymdMonth" column="ymd_month"/>
                <result property="ymdQuarter" column="ymd_quarter"/>
                <result property="ymdWeek" column="ymd_week"/>
                <result property="ymdYear" column="ymd_year"/>
                <result property="ymdHalfyear" column="ymd_halfyear"/>
                <result property="isError" column="is_error"/>
                <result property="offDutyTime" column="off_duty_time"/>
                <result property="onDutyTime" column="on_duty_time"/>
                <result property="ymdHour" column="ymd_hour"/>
                <result property="ymdMinute" column="ymd_minute"/>
                <result property="isManual" column="is_manual"/>
    </resultMap>

    <sql id="selectSysWorkTimeVo">
        select id, create_time, modified_id, modified_name, update_time, close_time, is_enable, open_time, noonbreak_start, noonbreak_end, org_id, work_off_time, work_time, work_time_month_id, ymd_date, ymd_day, ymd_month, ymd_quarter, ymd_week, ymd_year, ymd_halfyear, is_error, off_duty_time, on_duty_time, ymd_hour, ymd_minute, is_manual
        from sys_work_time
    </sql>

    <select id="selectSysWorkTimeList" parameterType="com.xunmei.system.api.domain.SysWorkTime"
            resultMap="SysWorkTimeResult">
        <include refid="selectSysWorkTimeVo"/>
        <where>
                        <if test="modifiedId != null ">
                            and modified_id = #{modifiedId}
                        </if>
                        <if test="modifiedName != null  and modifiedName != ''">
                            and modified_name like concat('%', #{modifiedName}, '%')
                        </if>
                        <if test="closeTime != null  and closeTime != ''">
                            and close_time = #{closeTime}
                        </if>
                        <if test="isEnable != null ">
                            and is_enable = #{isEnable}
                        </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="orgId != null ">
                            and org_id = #{orgId}
                        </if>
                        <if test="workOffTime != null  and workOffTime != ''">
                            and work_off_time = #{workOffTime}
                        </if>
                        <if test="workTime != null  and workTime != ''">
                            and work_time = #{workTime}
                        </if>
                        <if test="workTimeMonthId != null  and workTimeMonthId != ''">
                            and work_time_month_id = #{workTimeMonthId}
                        </if>
                        <if test="ymdDate != null ">
                            and ymd_date = #{ymdDate}
                        </if>
                        <if test="ymdDay != null ">
                            and ymd_day = #{ymdDay}
                        </if>
                        <if test="ymdMonth != null ">
                            and ymd_month = #{ymdMonth}
                        </if>
                        <if test="ymdQuarter != null ">
                            and ymd_quarter = #{ymdQuarter}
                        </if>
                        <if test="ymdWeek != null ">
                            and ymd_week = #{ymdWeek}
                        </if>
                        <if test="ymdYear != null ">
                            and ymd_year = #{ymdYear}
                        </if>
                        <if test="ymdHalfyear != null ">
                            and ymd_halfyear = #{ymdHalfyear}
                        </if>
                        <if test="isError != null ">
                            and is_error = #{isError}
                        </if>
                        <if test="offDutyTime != null ">
                            and off_duty_time = #{offDutyTime}
                        </if>
                        <if test="onDutyTime != null ">
                            and on_duty_time = #{onDutyTime}
                        </if>
                        <if test="ymdHour != null ">
                            and ymd_hour = #{ymdHour}
                        </if>
                        <if test="ymdMinute != null ">
                            and ymd_minute = #{ymdMinute}
                        </if>
                        <if test="isManual != null ">
                            and is_manual = #{isManual}
                        </if>
        </where>
    </select>

    <select id="selectSysWorkTimeById" parameterType="String"
            resultMap="SysWorkTimeResult">
            <include refid="selectSysWorkTimeVo"/>
            where id = #{id}
    </select>
    <select id="selectByPage" resultType="com.xunmei.system.dto.SysWorkTimeDto">
        SELECT
            t.*,
            o.NAME as orgName
        FROM
            sys_work_time t
                LEFT JOIN sys_org o ON t.org_id = o.id
            ${ew.customSqlSegment}

    </select>
    <select id="findByOrgAndMonth" resultType="com.xunmei.system.api.domain.SysWorkTime">

        select *
        from sys_work_time
        where org_id = #{orgId}
          and ymd_date like concat(#{monthStr}, '%')
    </select>
    <select id="findByYmd" resultType="com.xunmei.system.api.domain.SysWorkTime">
        select * from sys_work_time where org_id in
        <foreach item="orgId" collection="orgIds" open="(" separator="," close=")">
            #{orgId}
        </foreach>

         and  ymd_date=#{date}
    </select>
    <select id="getOrgWorkTimeByMonth" resultType="com.xunmei.system.api.domain.SysWorkTime">
        select * from sys_work_time where is_manual=1 and ymd_date>=#{map.effectiveDate} and
        #{map.lastDayOfNextMonth}>=ymd_date
        and org_id in
        <foreach collection="map.orgIds" item="orgId" open="(" close=")" separator=",">
            #{orgId}
        </foreach>


    </select>
    <select id="findOrgIdsByYmd" resultType="java.lang.Long">
        select org_id from sys_work_time where ymd_date=#{data} and is_enable=1

    </select>
    <select id="findByOrgAndDate" resultType="com.xunmei.system.api.domain.SysWorkTime">
        select *
        from sys_work_time
        where org_id = #{orgId}
          and ymd_date &gt;= #{start} and  ymd_date &lt;= #{end}
    </select>

    <insert id="insertSysWorkTime" parameterType="com.xunmei.system.api.domain.SysWorkTime">
        insert into sys_work_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,
                    </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="closeTime != null">close_time,
                    </if>
                    <if test="isEnable != null">is_enable,
                    </if>
                    <if test="openTime != null">open_time,
                    </if>
                    <if test="noonbreakStart != null">noonbreak_start,
                    </if>
                    <if test="noonbreakEnd != null">noonbreak_end,
                    </if>
                    <if test="orgId != null">org_id,
                    </if>
                    <if test="workOffTime != null">work_off_time,
                    </if>
                    <if test="workTime != null">work_time,
                    </if>
                    <if test="workTimeMonthId != null">work_time_month_id,
                    </if>
                    <if test="ymdDate != null">ymd_date,
                    </if>
                    <if test="ymdDay != null">ymd_day,
                    </if>
                    <if test="ymdMonth != null">ymd_month,
                    </if>
                    <if test="ymdQuarter != null">ymd_quarter,
                    </if>
                    <if test="ymdWeek != null">ymd_week,
                    </if>
                    <if test="ymdYear != null">ymd_year,
                    </if>
                    <if test="ymdHalfyear != null">ymd_halfyear,
                    </if>
                    <if test="isError != null">is_error,
                    </if>
                    <if test="offDutyTime != null">off_duty_time,
                    </if>
                    <if test="onDutyTime != null">on_duty_time,
                    </if>
                    <if test="ymdHour != null">ymd_hour,
                    </if>
                    <if test="ymdMinute != null">ymd_minute,
                    </if>
                    <if test="isManual != null">is_manual,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},
                    </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="closeTime != null">#{closeTime},
                    </if>
                    <if test="isEnable != null">#{isEnable},
                    </if>
                    <if test="openTime != null">#{openTime},
                    </if>
                    <if test="noonbreakStart != null">#{noonbreakStart},
                    </if>
                    <if test="noonbreakEnd != null">#{noonbreakEnd},
                    </if>
                    <if test="orgId != null">#{orgId},
                    </if>
                    <if test="workOffTime != null">#{workOffTime},
                    </if>
                    <if test="workTime != null">#{workTime},
                    </if>
                    <if test="workTimeMonthId != null">#{workTimeMonthId},
                    </if>
                    <if test="ymdDate != null">#{ymdDate},
                    </if>
                    <if test="ymdDay != null">#{ymdDay},
                    </if>
                    <if test="ymdMonth != null">#{ymdMonth},
                    </if>
                    <if test="ymdQuarter != null">#{ymdQuarter},
                    </if>
                    <if test="ymdWeek != null">#{ymdWeek},
                    </if>
                    <if test="ymdYear != null">#{ymdYear},
                    </if>
                    <if test="ymdHalfyear != null">#{ymdHalfyear},
                    </if>
                    <if test="isError != null">#{isError},
                    </if>
                    <if test="offDutyTime != null">#{offDutyTime},
                    </if>
                    <if test="onDutyTime != null">#{onDutyTime},
                    </if>
                    <if test="ymdHour != null">#{ymdHour},
                    </if>
                    <if test="ymdMinute != null">#{ymdMinute},
                    </if>
                    <if test="isManual != null">#{isManual},
                    </if>
        </trim>
    </insert>

    <update id="updateSysWorkTime" parameterType="com.xunmei.system.api.domain.SysWorkTime">
        update sys_work_time
        <trim prefix="SET" suffixOverrides=",">
                    <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="closeTime != null">close_time =
                        #{closeTime},
                    </if>
                    <if test="isEnable != null">is_enable =
                        #{isEnable},
                    </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="orgId != null">org_id =
                        #{orgId},
                    </if>
                    <if test="workOffTime != null">work_off_time =
                        #{workOffTime},
                    </if>
                    <if test="workTime != null">work_time =
                        #{workTime},
                    </if>
                    <if test="workTimeMonthId != null">work_time_month_id =
                        #{workTimeMonthId},
                    </if>
                    <if test="ymdDate != null">ymd_date =
                        #{ymdDate},
                    </if>
                    <if test="ymdDay != null">ymd_day =
                        #{ymdDay},
                    </if>
                    <if test="ymdMonth != null">ymd_month =
                        #{ymdMonth},
                    </if>
                    <if test="ymdQuarter != null">ymd_quarter =
                        #{ymdQuarter},
                    </if>
                    <if test="ymdWeek != null">ymd_week =
                        #{ymdWeek},
                    </if>
                    <if test="ymdYear != null">ymd_year =
                        #{ymdYear},
                    </if>
                    <if test="ymdHalfyear != null">ymd_halfyear =
                        #{ymdHalfyear},
                    </if>
                    <if test="isError != null">is_error =
                        #{isError},
                    </if>
                    <if test="offDutyTime != null">off_duty_time =
                        #{offDutyTime},
                    </if>
                    <if test="onDutyTime != null">on_duty_time =
                        #{onDutyTime},
                    </if>
                    <if test="ymdHour != null">ymd_hour =
                        #{ymdHour},
                    </if>
                    <if test="ymdMinute != null">ymd_minute =
                        #{ymdMinute},
                    </if>
                    <if test="isManual != null">is_manual =
                        #{isManual},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysWorkTimeById" parameterType="String">
        delete
        from sys_work_time where id = #{id}
    </delete>

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