<?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.sunxung.factoring.mapper.sys.workingDayManage.WorkingDayManageMapper">
	<resultMap type="WorkingDayManage" id="workingDayManageMap">
		<id column="id" property="id"/>
		<result column="date_time" property="dateTime"/>
		<result column="is_working_day" property="workingDay"/>
		<result column="remark" property="remark"/>
		<result column="user_create" property="userCreate"/>
		<result column="user_modified" property="userModified"/>
		<result column="gmt_create" property="gmtCreate"/>
		<result column="gmt_modified" property="gmtModified"/>
		
	</resultMap>
	
	<sql id="filed">
		w.id,
		w.date_time,
		w.is_working_day,
		w.remark,
		w.user_create,
		w.user_modified,
		w.gmt_create,
		w.gmt_modified
	</sql>
	
	<select id="findByMonth" parameterType="String" resultMap="workingDayManageMap">
		select <include refid="filed" /> from working_day_manage w
		<where>
			DATE_FORMAT(w.date_time,'%y-%m')=DATE_FORMAT(#{value},'%y-%m')
		</where>
	</select>
	
	<insert id="add" parameterType="WorkingDayManage" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
		insert into working_day_manage(date_time,is_working_day,remark,user_create,user_modified)
		values(#{dateTime},#{workingDay},#{remark},#{userCreate},#{userModified})
	</insert>
	
	<update id="update" parameterType="WorkingDayManage">
		update working_day_manage w set
		w.date_time=#{dateTime},
		w.is_working_day=#{workingDay},
		w.remark=#{remark},
		w.user_modified=#{userModified}
		where w.id=#{id}
	</update>
	
	<delete id="delete" parameterType="Long">
		delete from working_day_manage where id=#{value}
	</delete>
	
	<select id="get" parameterType="Long" resultMap="workingDayManageMap">
		select <include refid="filed" /> from working_day_manage w where w.id=#{value}
	</select>
	
	<select id="getByDateTime" parameterType="Date" resultMap="workingDayManageMap">
		SELECT
			<include refid="filed" /> 
		FROM
			working_day_manage w 
		WHERE
			w.date_time = DATE_FORMAT( #{value}, '%y-%m-%d' )
	</select>
	
	<!-- 由于新增时date_time就是按照%y-%m-%d格式，故直接进行条件比较，未进行DATE_FORMAT(w.workTime,'%y-%m-%d')转换-->
	<select id="findByStartEndDate" resultMap="workingDayManageMap">
		SELECT
			<include refid="filed" /> 
		FROM
			working_day_manage w 
		WHERE
			<![CDATA[w.date_time >= DATE_FORMAT( #{start}, '%y-%m-%d' )]]>
			AND <![CDATA[w.date_time <= DATE_FORMAT( #{end}, '%y-%m-%d' )]]>
		ORDER BY w.date_time ASC
	</select>
	
	<select id="getMaxDate" resultType="Date">
		select max(date_time) from working_day_manage
	</select>
</mapper>