<?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.jeeplus.modules.alterinfo.dao.AlterInfoDao">
    
	<sql id="alterInfoColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.reason AS "reason",
		a.type AS "type",
		a.before_id AS "beforeId",
		a.style AS "style"
	</sql>
	
	<sql id="alterInfoJoins">
	</sql>

	<select id="getByContractInfo" resultType="AlterInfo" parameterType="com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo">
		SELECT 
			<include refid="alterInfoColumns"/>
		FROM alter_info a
		WHERE a.del_flag = '0'
			AND a.type = '1'
			AND a.style = '1'
			AND a.before_id = #{id}
	</select>
    
	<select id="get" resultType="AlterInfo" >
		SELECT 
			<include refid="alterInfoColumns"/>
		FROM alter_info a
		<include refid="alterInfoJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="AlterInfo" >
		SELECT 
			<include refid="alterInfoColumns"/>
		FROM alter_info a
		<include refid="alterInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="type != null and type != ''">
				AND a.type = #{type}
			</if>
			<if test="style != null and style != ''">
				AND a.style = #{style}
			</if>
			<if test="beforeId != null and beforeId != ''">
				AND a.before_id = #{beforeId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="AlterInfo" >
		SELECT 
			<include refid="alterInfoColumns"/>
		FROM alter_info a
		<include refid="alterInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO alter_info(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			reason,
			type,
			before_id,
			style
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{reason},
			#{type},
			#{beforeId},
			#{style}
		)
	</insert>
	
	<update id="update">
		UPDATE alter_info SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			reason = #{reason},
			type = #{type},
			before_id = #{beforeId},
			style = #{style}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM alter_info
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE alter_info SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="AlterInfo" statementType="STATEMENT">
		select * FROM alter_info  where ${propertyName} = '${value}'
	</select>
	
</mapper>