<?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.workcommunicaterecord.dao.WorkCommunicateContentDao">
    
	<sql id="workCommunicateContentColumns">
		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.content_number AS "contentNumber",
		a.content_date AS "contentDate",
		a.content_detail AS "contentDetail",
		a.content_way AS "contentWay",
		a.content_feedback AS "contentFeedback",
		a.communicate_id AS "communicateId"
	</sql>
	
	<sql id="workCommunicateContentJoins">
	</sql>
	
    
	<select id="get" resultType="WorkCommunicateContent" >
		SELECT 
			<include refid="workCommunicateContentColumns"/>
		FROM work_communicate_content a
		<include refid="workCommunicateContentJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkCommunicateContent" >
		SELECT 
			<include refid="workCommunicateContentColumns"/>
		FROM work_communicate_content a
		<include refid="workCommunicateContentJoins"/>
		<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>
	
	<select id="findAllList" resultType="WorkCommunicateContent" >
		SELECT 
			<include refid="workCommunicateContentColumns"/>
		FROM work_communicate_content a
		<include refid="workCommunicateContentJoins"/>
		<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_communicate_content(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			content_number,
			content_date,
			content_detail,
			content_way,
			content_feedback,
			communicate_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{contentNumber},
			#{contentDate},
			#{contentDetail},
			#{contentWay},
			#{contentFeedback},
			#{communicateId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_communicate_content SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			content_number = #{contentNumber},
			content_date = #{contentDate},
			content_detail = #{contentDetail},
			content_way = #{contentWay},
			content_feedback = #{contentFeedback},
			communicate_id = #{communicateId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_communicate_content
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_communicate_content SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkCommunicateContent" statementType="STATEMENT">
		select * FROM work_communicate_content  where ${propertyName} = '${value}'
	</select>

	<!-- 获取沟通内容列表 -->
	<select id="findListByCommunicateId" resultType="WorkCommunicateContent" >
		SELECT
		<include refid="workCommunicateContentColumns"/>
		FROM work_communicate_content a
		<include refid="workCommunicateContentJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			and a.communicate_id = #{communicateId}
		</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>
	<!-- 删除关联所有文件 -->
	<delete id="deleteByProId">
		DELETE FROM work_communicate_content
		WHERE communicate_id = #{communicateId}
	</delete>
</mapper>