<?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.core.resumption.mapper.SysResumptionMapper">

    <resultMap type="com.xunmei.core.resumption.domain.SysResumption" id="SysResumptionResult">
                <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="exceptionCount" column="exception_count"/>
                <result property="formType" column="form_type"/>
                <result property="orgId" column="org_id"/>
                <result property="status" column="status"/>
                <result property="type" column="type"/>
                <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="submitTime" column="submit_time"/>
                <result property="ymdHour" column="ymd_hour"/>
                <result property="ymdMinute" column="ymd_minute"/>
                <result property="planId" column="plan_id"/>
                <result property="startTime" column="start_time"/>
                <result property="endTime" column="end_time"/>
                <result property="planStartTime" column="plan_start_time"/>
                <result property="planEndTime" column="plan_end_time"/>
                <result property="roleId" column="role_id"/>
    </resultMap>

    <sql id="selectSysResumptionVo">
        select id, create_time, modified_id, modified_name, update_time, exception_count, form_type, org_id, status, type, ymd_date, ymd_day, ymd_month, ymd_quarter, ymd_week, ymd_year, ymd_halfyear, submit_time, ymd_hour, ymd_minute, plan_id, start_time, end_time, plan_start_time, plan_end_time, role_id
        from core_resumption
    </sql>

    <select id="selectSysResumptionList" parameterType="com.xunmei.core.resumption.domain.SysResumption"
            resultMap="SysResumptionResult">
        <include refid="selectSysResumptionVo"/>
        <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="exceptionCount != null ">
                            and exception_count = #{exceptionCount}
                        </if>
                        <if test="formType != null ">
                            and form_type = #{formType}
                        </if>
                        <if test="orgId != null ">
                            and org_id = #{orgId}
                        </if>
                        <if test="status != null ">
                            and status = #{status}
                        </if>
                        <if test="type != null ">
                            and type = #{type}
                        </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="submitTime != null ">
                            and submit_time = #{submitTime}
                        </if>
                        <if test="ymdHour != null ">
                            and ymd_hour = #{ymdHour}
                        </if>
                        <if test="ymdMinute != null ">
                            and ymd_minute = #{ymdMinute}
                        </if>
                        <if test="planId != null ">
                            and plan_id = #{planId}
                        </if>
                        <if test="startTime != null ">
                            and start_time = #{startTime}
                        </if>
                        <if test="endTime != null ">
                            and end_time = #{endTime}
                        </if>
                        <if test="planStartTime != null ">
                            and plan_start_time = #{planStartTime}
                        </if>
                        <if test="planEndTime != null ">
                            and plan_end_time = #{planEndTime}
                        </if>
                        <if test="roleId != null ">
                            and role_id = #{roleId}
                        </if>
        </where>
    </select>

    <select id="selectSysResumptionById" parameterType="String"
            resultMap="SysResumptionResult">
            <include refid="selectSysResumptionVo"/>
            where id = #{id}
    </select>
    <select id="findResumptionList" resultType="com.xunmei.core.resumption.vo.WorkChangeResumptionVo">
        select a.id,b.id as planId,b.plan_exec as planExec,a.status,a.org_id as orgId
        from core_resumption a left join core_resumption_plan b on a.plan_id =b.id
        where a.ymd_year = #{year} and a.ymd_quarter=#{quarter} and a.ymd_date=#{date} and `type`=#{type} and b.plan_exec not in (4,5,6) and a.org_id in
        <foreach collection="orgIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="status!=null">
            and a.status=#{status}
        </if>

    </select>

    <insert id="insertSysResumption" parameterType="com.xunmei.core.resumption.domain.SysResumption">
        insert into core_resumption
        <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="exceptionCount != null">exception_count,
                    </if>
                    <if test="formType != null">form_type,
                    </if>
                    <if test="orgId != null">org_id,
                    </if>
                    <if test="status != null">status,
                    </if>
                    <if test="type != null">type,
                    </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="submitTime != null">submit_time,
                    </if>
                    <if test="ymdHour != null">ymd_hour,
                    </if>
                    <if test="ymdMinute != null">ymd_minute,
                    </if>
                    <if test="planId != null">plan_id,
                    </if>
                    <if test="startTime != null">start_time,
                    </if>
                    <if test="endTime != null">end_time,
                    </if>
                    <if test="planStartTime != null">plan_start_time,
                    </if>
                    <if test="planEndTime != null">plan_end_time,
                    </if>
                    <if test="roleId != null">role_id,
                    </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="exceptionCount != null">#{exceptionCount},
                    </if>
                    <if test="formType != null">#{formType},
                    </if>
                    <if test="orgId != null">#{orgId},
                    </if>
                    <if test="status != null">#{status},
                    </if>
                    <if test="type != null">#{type},
                    </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="submitTime != null">#{submitTime},
                    </if>
                    <if test="ymdHour != null">#{ymdHour},
                    </if>
                    <if test="ymdMinute != null">#{ymdMinute},
                    </if>
                    <if test="planId != null">#{planId},
                    </if>
                    <if test="startTime != null">#{startTime},
                    </if>
                    <if test="endTime != null">#{endTime},
                    </if>
                    <if test="planStartTime != null">#{planStartTime},
                    </if>
                    <if test="planEndTime != null">#{planEndTime},
                    </if>
                    <if test="roleId != null">#{roleId},
                    </if>
        </trim>
    </insert>

    <update id="updateSysResumption" parameterType="com.xunmei.core.resumption.domain.SysResumption">
        update core_resumption
        <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="exceptionCount != null">exception_count =
                        #{exceptionCount},
                    </if>
                    <if test="formType != null">form_type =
                        #{formType},
                    </if>
                    <if test="orgId != null">org_id =
                        #{orgId},
                    </if>
                    <if test="status != null">status =
                        #{status},
                    </if>
                    <if test="type != null">type =
                        #{type},
                    </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="submitTime != null">submit_time =
                        #{submitTime},
                    </if>
                    <if test="ymdHour != null">ymd_hour =
                        #{ymdHour},
                    </if>
                    <if test="ymdMinute != null">ymd_minute =
                        #{ymdMinute},
                    </if>
                    <if test="planId != null">plan_id =
                        #{planId},
                    </if>
                    <if test="startTime != null">start_time =
                        #{startTime},
                    </if>
                    <if test="endTime != null">end_time =
                        #{endTime},
                    </if>
                    <if test="planStartTime != null">plan_start_time =
                        #{planStartTime},
                    </if>
                    <if test="planEndTime != null">plan_end_time =
                        #{planEndTime},
                    </if>
                    <if test="roleId != null">role_id =
                        #{roleId},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysResumptionById" parameterType="String">
        delete
        from core_resumption where id = #{id}
    </delete>

    <delete id="deleteSysResumptionByIds" parameterType="String">
        delete from core_resumption where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteResumption">
        delete from core_resumption where ymd_year = #{year} and ymd_quarter=#{quarter} and id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>

    </delete>
</mapper>