<?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.workitempre.dao.WorkItemPreDao">
    
	<sql id="workItemPreColumns">
		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.del_flag AS "delFlag",
		a.name AS "name",
		a.inquiry_num AS "inquiryNum",
		a.item_type AS "itemType",
		a.item_source AS "itemSource",
		a.tenderee AS "tenderee",
		a.linkman AS "linkman",
		a.linkphone AS "linkphone",
		a.application_time AS "applicationTime",
		a.user_id AS "user.id",
		a.audit_time AS "auditTime",
		a.readiness_time AS "readinessTime",
		a.document_fee AS "documentFee",
		a.book_fee AS "bookFee",
		a.is_cooperation AS "isCooperation",
		a.item_status AS "itemStatus",
		a.remarks AS "remarks",
		user.name AS "user.name"
	</sql>
	
	<sql id="workItemPreJoins">
		LEFT JOIN sys_user user ON user.id = a.user_id
	</sql>
	
    
	<select id="get" resultType="WorkItemPre" >
		SELECT 
			<include refid="workItemPreColumns"/>
		FROM work_item_pre a
		<include refid="workItemPreJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkItemPre" >
		SELECT 
			<include refid="workItemPreColumns"/>
		FROM work_item_pre a
		<include refid="workItemPreJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<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="itemType != null and itemType != ''">
				AND a.item_type = #{itemType}
			</if>
			<if test="tenderee != null and tenderee != ''">
				AND a.tenderee = #{tenderee}
			</if>
			<if test="beginAuditTime != null and endAuditTime != null and beginAuditTime != '' and endAuditTime != ''">
				AND a.audit_time BETWEEN #{beginAuditTime} AND #{endAuditTime}
			</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="WorkItemPre" >
		SELECT 
			<include refid="workItemPreColumns"/>
		FROM work_item_pre a
		<include refid="workItemPreJoins"/>
		<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 work_item_pre(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			name,
			inquiry_num,
			item_type,
			item_source,
			tenderee,
			linkman,
			linkphone,
			application_time,
			user_id,
			audit_time,
			readiness_time,
			document_fee,
			book_fee,
			is_cooperation,
			item_status,
			remarks
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
			#{name},
			#{inquiryNum},
			#{itemType},
			#{itemSource},
			#{tenderee},
			#{linkman},
			#{linkphone},
			#{applicationTime},
			#{user.id},
			#{auditTime},
			#{readinessTime},
			#{documentFee},
			#{bookFee},
			#{isCooperation},
			#{itemStatus},
			#{remarks}
		)
	</insert>
	
	<update id="update">
		UPDATE work_item_pre SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			name = #{name},
			inquiry_num = #{inquiryNum},
			item_type = #{itemType},
			item_source = #{itemSource},
			tenderee = #{tenderee},
			linkman = #{linkman},
			linkphone = #{linkphone},
			application_time = #{applicationTime},
			user_id = #{user.id},
			audit_time = #{auditTime},
			readiness_time = #{readinessTime},
			document_fee = #{documentFee},
			book_fee = #{bookFee},
			is_cooperation = #{isCooperation},
			item_status = #{itemStatus},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_item_pre
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_item_pre SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkItemPre" statementType="STATEMENT">
		select * FROM work_item_pre  where ${propertyName} = '${value}'
	</select>
	
</mapper>