<?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.workcontractinfo.dao.WorkContractAnnexDao">
    
	<sql id="workContractAnnexColumns">
		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.name AS "name",
		a.url AS "url",
		a.contract_id AS "contractId。id",
		u.name AS "createBy.name"
	</sql>
	
	<sql id="workContractAnnexJoins">
		LEFT JOIN work_contract_info b ON b.id = a.contract_id
		LEFT JOIN sys_user u on u.id = a.create_by
	</sql>
	
    
	<select id="get" resultType="WorkContractAnnex" >
		SELECT 
			<include refid="workContractAnnexColumns"/>
		FROM work_contract_annex a
		<include refid="workContractAnnexJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContractAnnex" >
		SELECT 
			<include refid="workContractAnnexColumns"/>
		FROM work_contract_annex a
		<include refid="workContractAnnexJoins"/>
		<where>
			
			<if test="name != null and name != ''">
				AND a.name LIKE 
					<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="contractId != null and contractId != ''">
				AND a.contract_id = #{contractId.id}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.create_date ASC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="WorkContractAnnex" >
		SELECT 
			<include refid="workContractAnnexColumns"/>
		FROM work_contract_annex a
		<include refid="workContractAnnexJoins"/>
		<where>
			
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.create_date ASC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO work_contract_annex(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			name,
			url,
			contract_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{name},
			#{url},
			#{contractId.id}
		)
	</insert>
	
	<update id="update">
		UPDATE work_contract_annex SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			name = #{name},
			url = #{url},
			contract_id = #{contractId.id}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_contract_annex
		<choose>
			<when test="id !=null and id != ''">
				WHERE id = #{id}
			</when>
			<otherwise>
				WHERE contract_id = #{contractId.id}
			</otherwise>
		</choose>
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_contract_annex SET 
			del_flag = #{DEL_FLAG_DELETE}
		<choose>
			<when test="id !=null and id != ''">
				WHERE id = #{id}
			</when>
			<otherwise>
				WHERE contract_id = #{contractId.id}
			</otherwise>
		</choose>
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContractAnnex" statementType="STATEMENT">
		select * FROM work_contract_annex  where ${propertyName} = '${value}'
	</select>
	
</mapper>