<?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.projectcontentinfo.dao.ProjectContentChangeDao">
    
	<sql id="projectcontentinfoColumns">
		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.parent_id AS "parent.id",
		a.parent_ids AS "parentIds",
		a.sort AS "sort",
		a.project_id AS "project.id",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		a.type AS "type",
		a.info_id AS "infoId",
		a.dict_type AS "dictType",
		a.name AS "name",
		a.link_id AS "linkId"
	</sql>
	
	<sql id="projectcontentinfoJoins">
		LEFT JOIN sys_office o ON o.id = a.office_id
		LEFT JOIN sys_office s ON s.id = a.company_id
		LEFT JOIN sys_user u ON u.id = a.create_by
	</sql>
	
    
	<select id="get" resultType="Projectcontentinfo" >
		SELECT 
			<include refid="projectcontentinfoColumns"/>
		FROM project_content_change a
		<include refid="projectcontentinfoJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByInfoId" resultType="Projectcontentinfo" >
		SELECT
		<include refid="projectcontentinfoColumns"/>
		FROM project_content_change a
		<include refid="projectcontentinfoJoins"/>
		WHERE a.info_id = #{infoId}
	</select>
	
	<select id="findList" resultType="Projectcontentinfo" >
		SELECT 
			<include refid="projectcontentinfoColumns"/>
		FROM project_content_change a
		<include refid="projectcontentinfoJoins"/>
		<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="type != null and type != ''">
				AND a.type = #{type}
			</if>
			<if test="parentIds != null and parentIds != ''">
				AND a.parent_ids = #{parentIds}
			</if>
			<if test="project != null and project.id != null and project.id != ''">
				AND a.project_id = #{project.id}
			</if>
			<if test="infoId != null and infoId != ''">
				AND a.info_id = #{infoId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.sort ASC
			</otherwise>
		</choose>
	</select>

	<select id="findAllList" resultType="Projectcontentinfo" >
		SELECT 
			<include refid="projectcontentinfoColumns"/>
		FROM project_content_change a
		<include refid="projectcontentinfoJoins"/>
		<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 project_content_change(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			parent_id,
			parent_ids,
			sort,
			project_id,
			company_id,
			office_id,
			type,
			info_id,
			dict_type,
			name,
			link_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{parent.id},
			#{parentIds},
			#{sort},
			#{project.id},
			#{companyId},
			#{officeId},
			#{type},
			#{infoId},
			#{dictType},
			#{name},
			#{linkId}
		)
	</insert>
	
	<update id="update">
		UPDATE project_content_change SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			type = #{type},
			info_id = #{infoId},
			dict_type = #{dictType},
			parent_id = #{parent.id},
			parent_ids = #{parentIds},
			sort = #{sort},
			project_id = #{project.id},
			company_id = #{companyId},
			office_id = #{officeId},
			name = #{name}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM project_content_change
		WHERE id = #{id}
	</update>
	<!--物理删除-->
	<update id="deleteChange">
		DELETE FROM project_content_change
		WHERE info_id = #{infoId} AND project_id = #{project.id}
	</update>

	<insert id="saveProjectContentDataRelevanceInfo">
		insert into project_content_data_relevance (
		  project_content_id,
		  project_content_dynamic_id
		)
		values
		  (
			#{projectContentId},
			#{projectContentDynamicId}
		  ) ;
	</insert>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE project_content_change SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Projectcontentinfo" statementType="STATEMENT">
		select * FROM project_content_change  where ${propertyName} = '${value}'
	</select>
	
</mapper>