<?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.roleModule.dao.impl.RoleModuleMapperImpl">
	<resultMap id="get-entity-result" type="com.hzya.frame.sys.roleModule.entity.RoleModule">
		<!--唯一标识码 -->
		<result property="id" column="id" />
		<!--角色id -->
		<result property="roleId" column="role_id" />
		<!--模块ID -->
		<result property="modularId" column="modular_id" />
		<!--菜单 -->
		<result property="moduleId" column="module_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" />
		<!--组织机构ID -->
		<result property="orgId" column="org_id" />
	</resultMap>

	<sql id="Base_Column_List">
		id,
		role_id,
		modular_id,
		module_id,
		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_module where id = #{ id } and sts='Y'
	</select>

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.roleModule.entity.RoleModule">
		select
		<include refid="Base_Column_List" />
		from sys_role_module
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="roleId != null and roleId !='' "> and role_id = #{roleId}</if>
			<if test="modularId != null and modularId !='' "> and modular_id = #{modularId}</if>
			<if test="moduleId != null and moduleId !='' "> and module_id = #{moduleId}</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>

	<!-- 查询 采用==查询 -->
	<select id="getByUserId" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.roleModule.entity.RoleModule">
		SELECT
		<include refid="Base_Column_List" />
		FROM
		sys_role_module
		WHERE sts = 'Y' and role_id in (
		SELECT
		role_id
		FROM
		sys_user_role
		WHERE
		sts = 'Y' and
		user_id = #{userId}
		)
	</select>

	<!-- 查询符合条件的数量 -->
	<select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.sys.roleModule.entity.RoleModule">
		select count(1) from sys_role_module
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="roleId != null and roleId !='' "> and role_id = #{roleId}</if>
			<if test="modularId != null and modularId !='' "> and modular_id = #{modularId}</if>
			<if test="moduleId != null and moduleId !='' "> and module_id = #{moduleId}</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.roleModule.entity.RoleModule">
		select
		<include refid="Base_Column_List" />
		from sys_role_module
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="roleId != null and roleId !='' "> and role_id like concat('%',#{roleId},'%') </if>
			<if test="modularId != null and modularId !='' "> and modular_id like concat('%',#{modularId},'%') </if>
			<if test="moduleId != null and moduleId !='' "> and module_id like concat('%',#{moduleId},'%') </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>
	</select>

	<!-- 查询列表 字段采用or格式 -->
	<select id="entity_list_or" resultMap="get-entity-result" parameterType="com.hzya.frame.sys.roleModule.entity.RoleModule">
		select
		<include refid="Base_Column_List" />
		from sys_role_module
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="roleId != null and roleId !='' "> or role_id = #{roleId} </if>
			<if test="modularId != null and modularId !='' "> or modular_id = #{modularId} </if>
			<if test="moduleId != null and moduleId !='' "> or module_id = #{moduleId} </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>
	</select>
	<!-- 新增 -->
	<insert id="entity_insert" parameterType="com.hzya.frame.sys.roleModule.entity.RoleModule">
		insert into sys_role_module(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="roleId != null and roleId !='' "> role_id, </if>
			<if test="modularId != null and modularId !='' "> modular_id, </if>
			<if test="moduleId != null and moduleId !='' "> module_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>
			<if test="orgId != null and orgId !='' "> org_id, </if>
		</trim>
		)values
		(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> #{id}, </if>
			<if test="roleId != null and roleId !='' "> #{roleId}, </if>
			<if test="modularId != null and modularId !='' "> #{modularId}, </if>
			<if test="moduleId != null and moduleId !='' "> #{moduleId}, </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.roleModule.entity.RoleModule">
		update sys_role_module set
		<trim suffix="" suffixOverrides=",">
				<if test="roleId != null and roleId !='' "> role_id = #{roleId},</if>
				<if test="modularId != null and modularId !='' "> modular_id = #{modularId},</if>
				<if test="moduleId != null and moduleId !='' "> module_id = #{moduleId},</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.roleModule.entity.RoleModule">
		update sys_role_module 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.roleModule.entity.RoleModule">
		update sys_role_module 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="roleId != null and roleId !='' "> and role_id = #{roleId}</if>
			<if test="modularId != null and modularId !='' "> and modular_id = #{modularId}</if>
			<if test="moduleId != null and moduleId !='' "> and module_id = #{moduleId}</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="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.roleModule.entity.RoleModule">
		delete from sys_role_module where id =#{id}
	</delete>
</mapper>
