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

	<resultMap id="BaseResultMap" type="com.persagy.calendar.pojo.dto.WorkCalendar">
		<result column="ID" property="id" 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="CREATE_TIME" property="createTime" jdbcType="VARCHAR" />
		<result column="UPDATE_TIME" property="updateTime" jdbcType="VARCHAR" />
		<result column="UPDATE_USER" property="updateUser" jdbcType="VARCHAR" />
		<result column="DEL_FLAG" property="delFlag" jdbcType="VARCHAR" />
		
		<result column="OBJECT_ID" property="objectId" jdbcType="VARCHAR" />
	</resultMap>
	
	<sql id="Base_Where_Sql">
		<where>
			<if test="groupCode != null and groupCode.trim().length() != 0" >AND GROUP_CODE = #{groupCode}</if>
			<if test="id != null and id.trim().length() != 0" >AND ID = #{id}</if>
			<if test="projectId != null and projectId.trim().length() != 0" >AND PROJECT_ID = #{projectId}</if>
			<if test="calendarName != null and calendarName.trim().length() != 0" >AND CALENDAR_NAME LIKE CONCAT('%', #{calendarName}, '%')</if>
			<if test="delFlag != null and delFlag.trim().length() != 0" >AND DEL_FLAG = #{delFlag}</if>
		</where>
	</sql>
	
	<select id="queryCalendarObjectList" resultMap="BaseResultMap">
		SELECT M.*, N.OBJECT_ID FROM 
			(SELECT GROUP_CODE, ID, CALENDAR_NAME, PROJECT_ID, CALENDAR_DESC FROM work_calendar 
			<include refid="Base_Where_Sql"></include>) M 
		LEFT JOIN work_calendar_object N ON M.ID = N.CALENDAR_ID
	</select>
	
</mapper>