<?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.hzya.frame.sys.org.dao.impl.OrgMapperImpl">
	<resultMap id="get-entity-result" type="com.hzya.frame.sys.org.entity.Org">
		<!--唯一标识码 -->
		<result property="id" column="id" />
		<!--组织机构编码 -->
		<result property="orgCode" column="org_code" />
		<!--组织机构名称 -->
		<result property="orgName" column="org_name" />
		<!--类型：1、集团，2、公司，3、部门 -->
		<result property="orgType" column="org_type" />
		<!--label -->
		<result property="label" column="label" />
		<!--排序号 -->
		<result property="sorts" column="sorts" />
		<!--组织机构层级 -->
		<result property="lvl" column="lvl" />
		<!--上级组织机构ID -->
		<result property="upId" column="up_id" />
		<!--创建人id -->
		<result property="createUserId" column="create_user_id" />
		<!--创建时间 -->
		<result property="createTime" column="create_time" />
		<!--修改人id -->
		<result property="modifyUserId" column="modify_user_id" />
		<!--修改时间 -->
		<result property="modifyTime" column="modify_time" />
		<!--状态(Y正常N删除) -->
		<result property="sts" column="sts" />
	</resultMap>

	<sql id="Base_Column_List">
		id,
		org_code,
		org_name,
		org_type,
		label,
		sorts,
		lvl,
		up_id,
		create_user_id,
		create_time,
		modify_user_id,
		modify_time,
		sts
	</sql>

	<!--通过ID获取数据 -->
	<select id="entity_get" resultMap="get-entity-result">
		select
		<include refid="Base_Column_List" />
		from sys_org where id = #{ id } and sts='Y'
	</select>

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.org.entity.Org">
		select
		<if test="viewFiledList != null and viewFiledList.size>0">
			<foreach collection="viewFiledList" item="item" index="index" separator=",">
				${item.datebaseName}
			</foreach>
		</if>
		<if test="viewFiledList == null or viewFiledList.size == 0">
			<include refid="Base_Column_List" />
		</if>
		from sys_org
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="orgCode != null and orgCode !='' "> and org_code = #{orgCode}</if>
			<if test="orgName != null and orgName !='' "> and org_name = #{orgName}</if>
			<if test="orgType != null and orgType !='' "> and org_type = #{orgType}</if>
			<if test="label != null and label !='' "> and label = #{label}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="lvl != null "> and lvl = #{lvl}</if>
			<if test="upId != null and upId !='' "> and up_id = #{upId}</if>
			<if test="createUserId != null and createUserId !='' "> and create_user_id = #{createUserId}</if>
			<if test="createTime != null "> and create_time = #{createTime}</if>
			<if test="modifyUserId != null and modifyUserId !='' "> and modify_user_id = #{modifyUserId}</if>
			<if test="modifyTime != null "> and modify_time = #{modifyTime}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
		</trim>
		<if test=" sort == null or sort =='' "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
	</select>

	<!-- 查询符合条件的数量 -->
	<select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.sys.org.entity.Org">
		select count(1) from sys_org
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="orgCode != null and orgCode !='' "> and org_code = #{orgCode}</if>
			<if test="orgName != null and orgName !='' "> and org_name = #{orgName}</if>
			<if test="orgType != null and orgType !='' "> and org_type = #{orgType}</if>
			<if test="label != null and label !='' "> and label = #{label}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="lvl != null "> and lvl = #{lvl}</if>
			<if test="upId != null and upId !='' "> and up_id = #{upId}</if>
			<if test="createUserId != null and createUserId !='' "> and create_user_id = #{createUserId}</if>
			<if test="createTime != null "> and create_time = #{createTime}</if>
			<if test="modifyUserId != null and modifyUserId !='' "> and modify_user_id = #{modifyUserId}</if>
			<if test="modifyTime != null "> and modify_time = #{modifyTime}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
		</trim>
	</select>

	<!-- 分页查询列表 采用like格式 -->
	<select id="entity_list_like" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.org.entity.Org">
		select
		<if test="viewFiledList != null and viewFiledList.size>0">
			<foreach collection="viewFiledList" item="item" index="index" separator=",">
				${item.datebaseName}
			</foreach>
		</if>
		<if test="viewFiledList == null or viewFiledList.size == 0">
			<include refid="Base_Column_List" />
		</if>
		from sys_org
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="orgCode != null and orgCode !='' "> and org_code like concat('%',#{orgCode},'%') </if>
			<if test="orgName != null and orgName !='' "> and org_name like concat('%',#{orgName},'%') </if>
			<if test="orgType != null and orgType !='' "> and org_type like concat('%',#{orgType},'%') </if>
			<if test="label != null and label !='' "> and label like concat('%',#{label},'%') </if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="lvl != null "> and lvl = #{lvl}</if>
			<if test="upId != null and upId !='' "> and up_id like concat('%',#{upId},'%') </if>
			<if test="createUserId != null and createUserId !='' "> and create_user_id like concat('%',#{createUserId},'%') </if>
			<if test="createTime != null and createTime !='' "> and create_time like concat('%',#{createTime},'%') </if>
			<if test="modifyUserId != null and modifyUserId !='' "> and modify_user_id like concat('%',#{modifyUserId},'%') </if>
			<if test="modifyTime != null and modifyTime !='' "> and modify_time like concat('%',#{modifyTime},'%') </if>
			<if test="sts != null and sts !='' "> and sts like concat('%',#{sts},'%') </if>
		</trim>
		<if test=" sort == null or sort =='' "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by  ${sort} ${order}</if>
	</select>

	<!-- 查询列表 字段采用or格式 -->
	<select id="entity_list_or" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.org.entity.Org">
		select
		<if test="viewFiledList != null and viewFiledList.size>0">
			<foreach collection="viewFiledList" item="item" index="index" separator=",">
				${item.datebaseName}
			</foreach>
		</if>
		<if test="viewFiledList == null or viewFiledList.size == 0">
			<include refid="Base_Column_List" />
		</if>
		from sys_org
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="orgCode != null and orgCode !='' "> or org_code = #{orgCode} </if>
			<if test="orgName != null and orgName !='' "> or org_name = #{orgName} </if>
			<if test="orgType != null and orgType !='' "> or org_type = #{orgType} </if>
			<if test="label != null and label !='' "> or label = #{label} </if>
			<if test="sorts != null "> or sorts = #{sorts}</if>
			<if test="lvl != null "> or lvl = #{lvl}</if>
			<if test="upId != null and upId !='' "> or up_id = #{upId} </if>
			<if test="createUserId != null and createUserId !='' "> or create_user_id = #{createUserId} </if>
			<if test="createTime != null and createTime !='' "> or create_time = #{createTime} </if>
			<if test="modifyUserId != null and modifyUserId !='' "> or modify_user_id = #{modifyUserId} </if>
			<if test="modifyTime != null and modifyTime !='' "> or modify_time = #{modifyTime} </if>
			<if test="sts != null and sts !='' "> or sts = #{sts} </if>
		</trim>
		<if test=" sort == null or sort =='' "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by  ${sort} ${order}</if>
	</select>
	<!-- 新增 -->
	<insert id="entity_insert" parameterType="com.hzya.frame.sys.org.entity.Org">
		insert into sys_org(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="orgCode != null and orgCode !='' "> org_code, </if>
			<if test="orgName != null and orgName !='' "> org_name, </if>
			<if test="orgType != null and orgType !='' "> org_type, </if>
			<if test="label != null and label !='' "> label, </if>
			<if test="sorts != null ">sorts,</if>
			<if test="lvl != null ">lvl,</if>
			<if test="upId != null and upId !='' "> up_id, </if>
			<if test="createUserId != null and createUserId !='' "> create_user_id, </if>
			<if test="createTime != null ">create_time,</if>
			<if test="modifyUserId != null and modifyUserId !='' "> modify_user_id, </if>
			<if test="modifyTime != null ">modify_time,</if>
			<if test="sts != null and sts !='' "> sts, </if>
		</trim>
		)values
		(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> #{id}, </if>
			<if test="orgCode != null and orgCode !='' "> #{orgCode}, </if>
			<if test="orgName != null and orgName !='' "> #{orgName}, </if>
			<if test="orgType != null and orgType !='' "> #{orgType}, </if>
			<if test="label != null and label !='' "> #{label}, </if>
			<if test="sorts != null ">#{sorts},</if>
			<if test="lvl != null ">#{lvl},</if>
			<if test="upId != null and upId !='' "> #{upId}, </if>
			<if test="createUserId != null and createUserId !='' "> #{createUserId}, </if>
			<if test="createTime != null ">#{createTime},</if>
			<if test="modifyUserId != null and modifyUserId !='' "> #{modifyUserId}, </if>
			<if test="modifyTime != null ">#{modifyTime},</if>
			<if test="sts != null and sts !='' "> #{sts}, </if>
		</trim>
		)
	</insert>

	<!-- 修改 -->
	<update id="entity_update" parameterType="com.hzya.frame.sys.org.entity.Org">
		update sys_org set
		<trim suffix="" suffixOverrides=",">
				<if test="orgCode != null and orgCode !='' "> org_code = #{orgCode},</if>
				<if test="orgName != null and orgName !='' "> org_name = #{orgName},</if>
				<if test="orgType != null and orgType !='' "> org_type = #{orgType},</if>
				<if test=" label != null and label !='' "> label = #{label},</if>
				<if test="sorts != null ">sorts = #{sorts},</if>
				<if test="lvl != null ">lvl = #{lvl},</if>
				<if test="upId != null and upId !='' "> up_id = #{upId},</if>
				<if test="createUserId != null and createUserId !='' "> create_user_id = #{createUserId},</if>
				<if test="createTime != null ">create_time = #{createTime},</if>
				<if test="modifyUserId != null and modifyUserId !='' "> modify_user_id = #{modifyUserId},</if>
				<if test="modifyTime != null ">modify_time = #{modifyTime},</if>
				<if test="sts != null and sts !='' "> sts = #{sts},</if>
		</trim>
		where id = #{id}
	</update>

	<!-- 逻辑删除 -->
	<update id="entity_logicDelete" parameterType="com.hzya.frame.sys.org.entity.Org">
		update sys_org set
		sts='N',modify_time = now(),modify_user_id = #{modifyUserId} where
		id = #{id}
	</update>

	<!-- 逻辑删除多条件 -->
	<update id="entity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sys.org.entity.Org">
		update sys_org set
		sts='N',modify_time = now(),modify_user_id = #{modifyUserId}
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="orgCode != null and orgCode !='' "> and org_code = #{orgCode}</if>
			<if test="orgName != null and orgName !='' "> and org_name = #{orgName}</if>
			<if test="orgType != null and orgType !='' "> and org_type = #{orgType}</if>
			<if test="label != null and label !='' "> and label = #{label}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="lvl != null "> and lvl = #{lvl}</if>
			<if test="upId != null and upId !='' "> and up_id = #{upId}</if>
			<if test="createUserId != null and createUserId !='' "> and create_user_id = #{createUserId}</if>
			<if test="createTime != null and createTime !='' "> and create_time = #{createTime}</if>
			<if test="modifyUserId != null and modifyUserId !='' "> and modify_user_id = #{modifyUserId}</if>
			<if test="modifyTime != null and modifyTime !='' "> and modify_time = #{modifyTime}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
		</trim>
	</update>

	<!-- 物理删除 -->
	<delete id="entity_delete" parameterType="com.hzya.frame.sys.org.entity.Org">
		delete from sys_org where id =#{id}
	</delete>
</mapper>
