<?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.role.dao.impl.RoleMapperImpl">
	<resultMap id="get-entity-result" type="com.hzya.frame.sys.role.entity.Role">
		<!--主键ID -->
		<result property="id" column="id" />
		<!--名称 -->
		<result property="roleName" column="role_name" />
		<!--所属分类 -->
		<result property="category" column="category" />
		<!--编号 -->
		<result property="roleCode" column="role_code" />
		<!--固定角色、相对角色、自建角色  1：固定角色 2：相对角色 3：自建角色 -->
		<result property="roleType" column="role_type" />
		<!--单位角色/部门角色  0：集团角色 1：单位角色 2：部门角色 3：不使用 4：不使用 5：业务生成器 6：sso -->
		<result property="roleBond" column="role_bond" />
		<!--是否是基准角色  1：是 0：否 -->
		<result property="isBenchmark" column="is_benchmark" />
		<!--所属单位 -->
		<result property="orgAccountId" column="org_account_id" />
		<!--排序 -->
		<result property="sorts" column="sorts" />
		<!--是否启用 1:启用 0停用 -->
		<result property="isEnable" column="is_enable" />
		<!--是否被删除 1:删除  0:未删除 -->
		<result property="isDeleted" column="is_deleted" />
		<!--描述 -->
		<result property="description" column="description" />
		<!--内外标识 0：内部1:  外部人员  -->
		<result property="externalType" column="external_type" />
		<!--前台授权 -->
		<result property="frontAuthorization" column="front_authorization" />
		<!--选人界面 -->
		<result property="personSelectionInterface" column="person_selection_interface" />
		<!--创建人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" />
		<!--组织机构ID -->
		<result property="orgId" column="org_id" />
	</resultMap>

	<sql id="Base_Column_List">
		id,
		role_name,
		category,
		role_code,
		role_type,
		role_bond,
		is_benchmark,
		org_account_id,
		sorts,
		is_enable,
		is_deleted,
		description,
		external_type,
		front_authorization,
		person_selection_interface,
		create_user_id,
		create_time,
		modify_user_id,
		modify_time,
		sts,
		org_id
	</sql>

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

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.role.entity.Role">
		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_role
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="roleName != null and roleName !='' "> and role_name = #{roleName}</if>
			<if test="category != null and category !='' "> and category = #{category}</if>
			<if test="roleCode != null and roleCode !='' "> and role_code = #{roleCode}</if>
			<if test="roleType != null and roleType !='' "> and role_type = #{roleType}</if>
			<if test="roleBond != null and roleBond !='' "> and role_bond = #{roleBond}</if>
			<if test="isBenchmark != null and isBenchmark !='' "> and is_benchmark = #{isBenchmark}</if>
			<if test="orgAccountId != null and orgAccountId !='' "> and org_account_id = #{orgAccountId}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="isEnable != null and isEnable !='' "> and is_enable = #{isEnable}</if>
			<if test="isDeleted != null and isDeleted !='' "> and is_deleted = #{isDeleted}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="externalType != null and externalType !='' "> and external_type = #{externalType}</if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> and front_authorization = #{frontAuthorization}</if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> and person_selection_interface = #{personSelectionInterface}</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>
			<if test="orgId != null and orgId !='' "> and org_id = #{orgId}</if>
			<if test="userRoles != null and userRoles.size>0">
				and 	id in
				<foreach collection="userRoles" item="item" index="index" open="(" close=")"  separator=",">
					#{item.roleId}
				</foreach>
			</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.role.entity.Role">
		select count(1) from sys_role
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="roleName != null and roleName !='' "> and role_name = #{roleName}</if>
			<if test="category != null and category !='' "> and category = #{category}</if>
			<if test="roleCode != null and roleCode !='' "> and role_code = #{roleCode}</if>
			<if test="roleType != null and roleType !='' "> and role_type = #{roleType}</if>
			<if test="roleBond != null and roleBond !='' "> and role_bond = #{roleBond}</if>
			<if test="isBenchmark != null and isBenchmark !='' "> and is_benchmark = #{isBenchmark}</if>
			<if test="orgAccountId != null and orgAccountId !='' "> and org_account_id = #{orgAccountId}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="isEnable != null and isEnable !='' "> and is_enable = #{isEnable}</if>
			<if test="isDeleted != null and isDeleted !='' "> and is_deleted = #{isDeleted}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="externalType != null and externalType !='' "> and external_type = #{externalType}</if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> and front_authorization = #{frontAuthorization}</if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> and person_selection_interface = #{personSelectionInterface}</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>
			<if test="orgId != null and orgId !='' "> and org_id = #{orgId}</if>
		</trim>
	</select>

	<!-- 分页查询列表 采用like格式 -->
	<select id="entity_list_like" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.role.entity.Role">
		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_role
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="roleName != null and roleName !='' "> and role_name like concat('%',#{roleName},'%') </if>
			<if test="category != null and category !='' "> and category like concat('%',#{category},'%') </if>
			<if test="roleCode != null and roleCode !='' "> and role_code like concat('%',#{roleCode},'%') </if>
			<if test="roleType != null and roleType !='' "> and role_type like concat('%',#{roleType},'%') </if>
			<if test="roleBond != null and roleBond !='' "> and role_bond like concat('%',#{roleBond},'%') </if>
			<if test="isBenchmark != null and isBenchmark !='' "> and is_benchmark like concat('%',#{isBenchmark},'%') </if>
			<if test="orgAccountId != null and orgAccountId !='' "> and org_account_id like concat('%',#{orgAccountId},'%') </if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="isEnable != null and isEnable !='' "> and is_enable like concat('%',#{isEnable},'%') </if>
			<if test="isDeleted != null and isDeleted !='' "> and is_deleted like concat('%',#{isDeleted},'%') </if>
			<if test="description != null and description !='' "> and description like concat('%',#{description},'%') </if>
			<if test="externalType != null and externalType !='' "> and external_type like concat('%',#{externalType},'%') </if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> and front_authorization like concat('%',#{frontAuthorization},'%') </if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> and person_selection_interface like concat('%',#{personSelectionInterface},'%') </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>
			<if test="orgId != null and orgId !='' "> and org_id like concat('%',#{orgId},'%') </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.role.entity.Role">
		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_role
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="roleName != null and roleName !='' "> or role_name = #{roleName} </if>
			<if test="category != null and category !='' "> or category = #{category} </if>
			<if test="roleCode != null and roleCode !='' "> or role_code = #{roleCode} </if>
			<if test="roleType != null and roleType !='' "> or role_type = #{roleType} </if>
			<if test="roleBond != null and roleBond !='' "> or role_bond = #{roleBond} </if>
			<if test="isBenchmark != null and isBenchmark !='' "> or is_benchmark = #{isBenchmark} </if>
			<if test="orgAccountId != null and orgAccountId !='' "> or org_account_id = #{orgAccountId} </if>
			<if test="sorts != null "> or sorts = #{sorts}</if>
			<if test="isEnable != null and isEnable !='' "> or is_enable = #{isEnable} </if>
			<if test="isDeleted != null and isDeleted !='' "> or is_deleted = #{isDeleted} </if>
			<if test="description != null and description !='' "> or description = #{description} </if>
			<if test="externalType != null and externalType !='' "> or external_type = #{externalType} </if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> or front_authorization = #{frontAuthorization} </if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> or person_selection_interface = #{personSelectionInterface} </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>
			<if test="orgId != null and orgId !='' "> or org_id = #{orgId} </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.role.entity.Role">
		insert into sys_role(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="roleName != null and roleName !='' "> role_name, </if>
			<if test="category != null and category !='' "> category, </if>
			<if test="roleCode != null and roleCode !='' "> role_code, </if>
			<if test="roleType != null and roleType !='' "> role_type, </if>
			<if test="roleBond != null and roleBond !='' "> role_bond, </if>
			<if test="isBenchmark != null and isBenchmark !='' "> is_benchmark, </if>
			<if test="orgAccountId != null and orgAccountId !='' "> org_account_id, </if>
			<if test="sorts != null ">sorts,</if>
			<if test="isEnable != null and isEnable !='' "> is_enable, </if>
			<if test="isDeleted != null and isDeleted !='' "> is_deleted, </if>
			<if test="description != null and description !='' "> description, </if>
			<if test="externalType != null and externalType !='' "> external_type, </if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> front_authorization, </if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> person_selection_interface, </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>
			<if test="orgId != null and orgId !='' "> org_id, </if>
		</trim>
		)values
		(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> #{id}, </if>
			<if test="roleName != null and roleName !='' "> #{roleName}, </if>
			<if test="category != null and category !='' "> #{category}, </if>
			<if test="roleCode != null and roleCode !='' "> #{roleCode}, </if>
			<if test="roleType != null and roleType !='' "> #{roleType}, </if>
			<if test="roleBond != null and roleBond !='' "> #{roleBond}, </if>
			<if test="isBenchmark != null and isBenchmark !='' "> #{isBenchmark}, </if>
			<if test="orgAccountId != null and orgAccountId !='' "> #{orgAccountId}, </if>
			<if test="sorts != null ">#{sorts},</if>
			<if test="isEnable != null and isEnable !='' "> #{isEnable}, </if>
			<if test="isDeleted != null and isDeleted !='' "> #{isDeleted}, </if>
			<if test="description != null and description !='' "> #{description}, </if>
			<if test="externalType != null and externalType !='' "> #{externalType}, </if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> #{frontAuthorization}, </if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> #{personSelectionInterface}, </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>
			<if test="orgId != null and orgId !='' "> #{orgId}, </if>
		</trim>
		)
	</insert>

	<!-- 修改 -->
	<update id="entity_update" parameterType="com.hzya.frame.sys.role.entity.Role">
		update sys_role set
		<trim suffix="" suffixOverrides=",">
				<if test="roleName != null and roleName !='' "> role_name = #{roleName},</if>
				<if test="category != null and category !='' "> category = #{category},</if>
				<if test="roleCode != null and roleCode !='' "> role_code = #{roleCode},</if>
				<if test="roleType != null and roleType !='' "> role_type = #{roleType},</if>
				<if test="roleBond != null and roleBond !='' "> role_bond = #{roleBond},</if>
				<if test="isBenchmark != null and isBenchmark !='' "> is_benchmark = #{isBenchmark},</if>
				<if test="orgAccountId != null and orgAccountId !='' "> org_account_id = #{orgAccountId},</if>
				<if test="sorts != null ">sorts = #{sorts},</if>
				<if test="isEnable != null and isEnable !='' "> is_enable = #{isEnable},</if>
				<if test="isDeleted != null and isDeleted !='' "> is_deleted = #{isDeleted},</if>
				<if test="description != null and description !='' "> description = #{description},</if>
				<if test="externalType != null and externalType !='' "> external_type = #{externalType},</if>
				<if test="frontAuthorization != null and frontAuthorization !='' "> front_authorization = #{frontAuthorization},</if>
				<if test="personSelectionInterface != null and personSelectionInterface !='' "> person_selection_interface = #{personSelectionInterface},</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>
				<if test="orgId != null and orgId !='' "> org_id = #{orgId},</if>
		</trim>
		where id = #{id}
	</update>

	<!-- 逻辑删除 -->
	<update id="entity_logicDelete" parameterType="com.hzya.frame.sys.role.entity.Role">
		update sys_role 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.role.entity.Role">
		update sys_role 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="roleName != null and roleName !='' "> and role_name = #{roleName}</if>
			<if test="category != null and category !='' "> and category = #{category}</if>
			<if test="roleCode != null and roleCode !='' "> and role_code = #{roleCode}</if>
			<if test="roleType != null and roleType !='' "> and role_type = #{roleType}</if>
			<if test="roleBond != null and roleBond !='' "> and role_bond = #{roleBond}</if>
			<if test="isBenchmark != null and isBenchmark !='' "> and is_benchmark = #{isBenchmark}</if>
			<if test="orgAccountId != null and orgAccountId !='' "> and org_account_id = #{orgAccountId}</if>
			<if test="sorts != null "> and sorts = #{sorts}</if>
			<if test="isEnable != null and isEnable !='' "> and is_enable = #{isEnable}</if>
			<if test="isDeleted != null and isDeleted !='' "> and is_deleted = #{isDeleted}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="externalType != null and externalType !='' "> and external_type = #{externalType}</if>
			<if test="frontAuthorization != null and frontAuthorization !='' "> and front_authorization = #{frontAuthorization}</if>
			<if test="personSelectionInterface != null and personSelectionInterface !='' "> and person_selection_interface = #{personSelectionInterface}</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>
			<if test="orgId != null and orgId !='' "> and org_id = #{orgId}</if>
		</trim>
	</update>

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