<?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.constructionunit.mapper.ConstructionUnitMapper">

	<sql id="constructionUnitColumns">
		a.id AS "id",
		a.yearofevaluation AS "yearOfEvaluation",
		a.unitname AS "unitName",
		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"
	</sql>

	<sql id="constructionUnitJoins">

	</sql>


	<select id="get" resultType="ConstructionUnit" >
		SELECT
			<include refid="constructionUnitColumns"/>
		FROM lishu_construction_unit a
		<include refid="constructionUnitJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getYearName" resultType="ConstructionUnit" >
		SELECT
		<include refid="constructionUnitColumns"/>
		FROM lishu_construction_unit a
		WHERE a.yearOfEvaluation = #{yearOfEvaluation} and a.unitName = #{unitName}
	</select>

	<select id="findList" resultType="ConstructionUnit" >
		SELECT
			<include refid="constructionUnitColumns"/>
		FROM lishu_construction_unit a
		<include refid="constructionUnitJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="yearOfEvaluation!= null and yearOfEvaluation != ''">
				and a.yearOfEvaluation =#{yearOfEvaluation}
			</if>
			<if test="unitName!= null and unitName != ''">
				AND a.unitName LIKE
				<if test="_databaseId == 'postgre'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'oracle'">'%'||#{unitName}||'%'</if>
				<if test="_databaseId == 'mssql'">'%'+#{unitName}+'%'</if>
				<if test="_databaseId == 'mysql'">concat('%',#{unitName},'%')</if>
			</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="ConstructionUnit" >
		SELECT
			<include refid="constructionUnitColumns"/>
		FROM lishu_construction_unit a
		<include refid="constructionUnitJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</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 lishu_construction_unit(
			id,
			yearofevaluation,
			unitname,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{yearOfEvaluation},
			#{unitName},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	<insert id="insertList">
		INSERT INTO lishu_construction_unit(
			id,
			yearofevaluation,
			unitname,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES
		<foreach collection="list" item="item" index="index" separator=",">
			 (
				 #{item.id},
				 #{item.yearOfEvaluation},
				 #{item.unitName},
				 #{item.createBy.id},
				 #{item.createDate},
				 #{item.updateBy.id},
				 #{item.updateDate},
				 #{item.remarks},
				 #{item.delFlag}
			 )
		</foreach>
	</insert>

	<update id="update">
		UPDATE lishu_construction_unit SET
			yearofevaluation = #{yearOfEvaluation},
			unitname = #{unitName},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>


	<!--物理删除-->
	<update id="delete">
		DELETE FROM lishu_construction_unit
		WHERE id = #{id}
	</update>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE lishu_construction_unit SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>


	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="ConstructionUnit" statementType="STATEMENT">
		select * FROM lishu_construction_unit  where ${propertyName} = '${value}'
	</select>
	<select id="findListByYearName" resultType="ConstructionUnit">
		SELECT
		<include refid="constructionUnitColumns"/>
		FROM lishu_construction_unit a
		<where>
			a.yearOfEvaluation = #{yearOfEvaluation}
			and a.unitName in(
			<foreach collection="list" index="index" item="item" separator=",">
				#{item.unitName}
			</foreach>
			)
		</where>
	</select>

</mapper>