<?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.persagy.calendar.mapper.WorkCalendarDateMapper">
	
	<resultMap id="BaseResultMap" type="com.persagy.calendar.pojo.dto.WorkCalendarDate">
		<result column="ID" property="id" jdbcType="VARCHAR" />
		<result column="RULE_ID" property="ruleId" jdbcType="VARCHAR" />
		<result column="CALENDAR_ID" property="calendarId" jdbcType="VARCHAR" />
		<result column="GROUP_CODE" property="groupCode" jdbcType="VARCHAR" />
		<result column="PROJECT_ID" property="projectId" jdbcType="VARCHAR" />
		<result column="CALENDAR_NAME" property="calendarName" jdbcType="VARCHAR" />
		<result column="CALENDAR_DESC" property="calendarDesc" jdbcType="VARCHAR" />
		<result column="DICT_TYPE" property="dictType" jdbcType="VARCHAR" />
		<result column="DICT_CODE" property="dictCode" jdbcType="VARCHAR" />
		<result column="WORK_DATE_START" property="workDateStart" jdbcType="VARCHAR" />
		<result column="WORK_DATE_END" property="workDateEnd" jdbcType="VARCHAR" />
		<result column="WORK_DATE" property="workDate" jdbcType="VARCHAR" />
		<result column="WORK_TIME" property="workTime" jdbcType="VARCHAR" />
		<result column="CREATE_TIME" property="createTime" jdbcType="VARCHAR" />
		<result column="UPDATE_TIME" property="updateTime" jdbcType="VARCHAR" />
		<result column="UPDATE_USER" property="updateUser" jdbcType="VARCHAR" />
		<result column="CUSTOM_FLAG" property="customFlag" jdbcType="VARCHAR" />
	</resultMap>
	
	<insert id="replaceIntoCalendarDate">
		REPLACE INTO work_calendar_date
		(
			ID, RULE_ID, CALENDAR_ID, GROUP_CODE, PROJECT_ID, 
			<if test="calendarName != null and calendarName.trim().length() != 0">CALENDAR_NAME, </if>
			<if test="calendarDesc != null and calendarDesc.trim().length() != 0">CALENDAR_DESC, </if>
			<if test="dictType != null and dictType.trim().length() != 0">DICT_TYPE, </if>
			<if test="dictCode != null and dictCode.trim().length() != 0">DICT_CODE, </if>
			<if test="workDateStart != null and workDateStart.trim().length() != 0">WORK_DATE_START, </if>
			<if test="workDateEnd != null and workDateEnd.trim().length() != 0">WORK_DATE_END, </if>
			<if test="workDate != null and workDate.trim().length() != 0">WORK_DATE, </if>
			<if test="workTime != null and workTime.trim().length() != 0">WORK_TIME, </if>
			CREATE_TIME, UPDATE_TIME, UPDATE_USER, CUSTOM_FLAG
		) VALUES (
			#{id}, #{ruleId}, #{calendarId}, #{groupCode}, #{projectId}, 
			<if test="calendarName != null and calendarName.trim().length() != 0">#{calendarName}, </if>
			<if test="calendarDesc != null and calendarDesc.trim().length() != 0">#{calendarDesc}, </if>
			<if test="dictType != null and dictType.trim().length() != 0">#{dictType}, </if>
			<if test="dictCode != null and dictCode.trim().length() != 0">#{dictCode}, </if>
			<if test="workDateStart != null and workDateStart.trim().length() != 0">#{workDateStart}, </if>
			<if test="workDateEnd != null and workDateEnd.trim().length() != 0">#{workDateEnd}, </if>
			<if test="workDate != null and workDate.trim().length() != 0">#{workDate}, </if>
			<if test="workTime != null and workTime.trim().length() != 0">#{workTime}, </if>
			#{createTime}, #{updateTime}, #{updateUser}, #{customFlag}
		)
	</insert>
	
	<insert id="batchCreateCalendarDate">
		INSERT INTO work_calendar_date
		(
			ID, RULE_ID, CALENDAR_ID, GROUP_CODE, PROJECT_ID, CALENDAR_NAME, CALENDAR_DESC, DICT_TYPE, DICT_CODE, 
			WORK_DATE, WORK_TIME, CREATE_TIME, UPDATE_TIME, UPDATE_USER, CUSTOM_FLAG
		) VALUES
		<foreach collection="datas" index="index" item="data" separator="," >
		(
			#{data.id}, #{data.ruleId}, #{data.calendarId}, #{data.groupCode}, #{data.projectId}, #{data.calendarName}, 
			#{data.calendarDesc}, #{data.dictType}, #{data.dictCode}, #{data.workDate}, #{data.workTime},
			#{data.createTime}, #{data.updateTime}, #{data.updateUser}, #{data.customFlag}
		)
		</foreach>
	</insert>
</mapper>