<?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.workcontent.dao.WorkContentDocumentDao">
    
	<sql id="workContentDocumentColumns">
		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.project_id AS "projectId",
		a.content_id AS "contentId",
		a.name AS "name",
		a.status AS "status",
		a.manager AS "manager",
		a.style AS "style",
		a.is_elec AS "isElec",
		a.doc_type AS "docType"
	</sql>
	
	<sql id="workContentDocumentJoins">
	</sql>
	
    
	<select id="get" resultType="WorkContentDocument" >
		SELECT 
			<include refid="workContentDocumentColumns"/>
		FROM work_content_document a
		<include refid="workContentDocumentJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentDocument" >
		SELECT 
			<include refid="workContentDocumentColumns"/>
		FROM work_content_document a
		<include refid="workContentDocumentJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="projectId != null and projectId != ''">
				AND a.project_id = #{projectId}
			</if>
			<if test="contentId != null and contentId != ''">
				AND a.content_id = #{contentId}
			</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="WorkContentDocument" >
		SELECT 
			<include refid="workContentDocumentColumns"/>
		FROM work_content_document a
		<include refid="workContentDocumentJoins"/>
		<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_content_document(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			name,
			status,
			manager,
			style,
			is_elec,
			doc_type
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{name},
			#{status},
			#{manager},
			#{style},
			#{isElec},
			#{docType}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_document SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			name = #{name},
			status = #{status},
			manager = #{manager},
			style = #{style},
			is_elec = #{isElec},
			doc_type = #{docType}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_document
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_document SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentDocument" statementType="STATEMENT">
		select * FROM work_content_document  where ${propertyName} = '${value}'
	</select>
	
</mapper>