Newer
Older
mcms / ms-basic / src / main / java / net / mingsoft / basic / dao / IManagerDao.xml
StephanieGitHub on 16 Dec 2020 8 KB first commit
<?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" >
<!-- 管理员持久化层XML配置继承IManagerDao -->
<mapper namespace="net.mingsoft.basic.dao.IManagerDao">
	<sql id="column_list">
		MANAGER_ID,MANAGER_NAME,MANAGER_NICKNAME,MANAGER_PASSWORD,MANAGER_ROLEID,MANAGER_PEOPLEID,MANAGER_TIME,MANAGER_ADMIN
	</sql>

	<sql id="all_column_list">
		m.MANAGER_ID,m.MANAGER_NAME,m.MANAGER_NICKNAME,m.MANAGER_PASSWORD,m.MANAGER_ROLEID,m.MANAGER_PEOPLEID,m.MANAGER_TIME,m.MANAGER_ADMIN,
		r.ROLE_NAME
	</sql>

	<!-- 管理员表字段与评论实体属性对应,供返回实体信息时使用 -->
	<resultMap id="resultMap" type="net.mingsoft.basic.entity.ManagerEntity">
		<id column="MANAGER_ID" property="managerId" />
		<result column="MANAGER_NAME" property="managerName" />
		<result column="MANAGER_NICKNAME" property="managerNickName" />
		<result column="MANAGER_PASSWORD" property="managerPassword" />
		<result column="MANAGER_ROLEID" property="managerRoleID" />
		<result column="MANAGER_PEOPLEID" property="managerPeopleID" />
		<result column="MANAGER_ADMIN" property="managerAdmin" />
		<result column="MANAGER_TIME" property="managerTime" />
		<result column="ROLE_NAME" property="roleName" />
	</resultMap>

	<!-- 管理员表字段与评论实体属性对应,供返回实体信息时使用 -->
	<resultMap id="resultMapAll" type="java.util.HashMap">
		<id column="MANAGER_ID" property="managerId" />
		<result column="MANAGER_NAME" property="managerName" />
		<result column="MANAGER_NICKNAME" property="managerNickName" />
		<result column="MANAGER_PASSWORD" property="managerPassword" />
		<result column="MANAGER_ROLEID" property="managerRoleID" />
		<result column="MANAGER_PEOPLEID" property="managerPeopleID" />
		<result column="MANAGER_TIME" property="managerTime" />
		<result column="ROLE_NAME" property="roleName" />
	</resultMap>

	<!-- 查询此时登录的管理员的子管理员列表开始 -->
	<select id="queryAllChildManager" resultMap="resultMap" parameterType="int">
		select * from manager m
		left join role r on m.MANAGER_ROLEID = r.ROLE_ID
		where MANAGER_ROLEID in
		(select ROLE_ID from role where ROLE_MANAGERID = #{managerId})
		order by MANAGER_ID DESC
	</select>
	<!-- 查询此时登录的管理员的子管理员列表开始  -->

	<sql id="insertColumns">
		<if test="managerName != null and managerName != ''">MANAGER_NAME,</if>
		<if test="managerNickName != null and managerNickName != ''">MANAGER_NICKNAME,</if>
		<if test="managerAdmin != null and managerAdmin != ''">MANAGER_ADMIN,</if>
		<if test="managerPassword != null and managerPassword != ''">MANAGER_PASSWORD,</if>
		<if test="managerRoleID &gt; 0">MANAGER_ROLEID,</if>
		<if test="managerPeopleID &gt; 0">MANAGER_PEOPLEID,</if>
		<if test="managerTime != null">MANAGER_TIME,</if>
	</sql>

	<sql id="insertValues">
		<if test="managerName != null and managerName != ''">#{managerName},</if>
		<if test="managerNickName != null and managerNickName != ''">#{managerNickName},</if>
		<if test="managerAdmin != null and managerAdmin != ''">#{managerAdmin},</if>
		<if test="managerPassword != null and managerPassword != ''">#{managerPassword},</if>
		<if test="managerRoleID &gt; 0">#{managerRoleID},</if>
		<if test="managerPeopleID &gt; 0">#{managerPeopleID},</if>
		<if test="managerTime != null">#{managerTime},</if>
	</sql>
	<!-- mysql或sqlServer增加管理员开始 -->
	<insert id="saveEntity" parameterType="net.mingsoft.basic.entity.ManagerEntity"  useGeneratedKeys="true" keyProperty="managerId" >
		 insert into manager
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<include refid="insertColumns"></include>
		</trim>
		<!-- 注入控制层字段 -->
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<include refid="insertValues"></include>
		</trim>
	</insert>
	<!-- mysql或sqlServer增加管理员结束 -->

	<!-- oracle增加管理员开始 -->
	<insert id="saveEntity" parameterType="net.mingsoft.basic.entity.ManagerEntity"  useGeneratedKeys="false" databaseId="oracle">
		<selectKey resultType="Integer"  keyProperty="managerId" order="BEFORE">
			select seq_manager_id.nextval as managerId from dual
		</selectKey>
		insert into manager
		<trim prefix="(" suffix=")" suffixOverrides=",">
			MANAGER_ID,
			<include refid="insertColumns"></include>
		</trim>
		<!-- 注入控制层字段 -->
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			#{managerId},
			<include refid="insertValues"></include>
		</trim>
	</insert>
	<!-- oracle增加管理员结束 -->

	<!-- 删除管理员开始 -->
	<delete id="deleteEntity" parameterType="int">
		delete from manager where MANAGER_ID = #{managerId}
	</delete>
	<!-- 删除管理员结束 -->

	<!--批量删除-->
	<delete id="delete" >
		delete from manager
		<where>
			 MANAGER_ID  in <foreach collection="ids" item="item" index="index"
			open="(" separator="," close=")">#{item}</foreach>
		</where>
	</delete>

	<!-- 查询管理员开始 -->
	<select id="getEntity" resultMap="resultMap" parameterType="int">
		select
			<include refid="column_list"/>
		  		from manager where MANAGER_ID=#{managerId}
	</select>
	<!-- 查询管理员结束 -->

	<!--根据实体获取-->
	<sql id="getManagerWhere">
		<if test="managerName != null and managerName != ''"> and MANAGER_NAME=#{managerName} </if>
	    <if test="managerNickName != null and managerNickName != ''"> and MANAGER_NICKNAME=#{managerNickName} </if>
	    <if test="managerPassword != null and managerPassword != ''"> and MANAGER_PASSWORD=#{managerPassword} </if>
		<if test="managerAdmin != null and managerAdmin != ''">and MANAGER_ADMIN=#{managerAdmin}</if>
	    <if test="managerRoleID &gt; 0"> and MANAGER_ROLEID=#{managerRoleID} </if>
	    <if test="managerPeopleID &gt; 0"> and MANAGER_PEOPLEID=#{managerPeopleID} </if>
	    <if test="managerTime != null"> and MANAGER_TIME=#{managerTime} </if>
	    <if test="managerSystemSkinId &gt; 0"> and MANAGER_SYSTEM_SKIN_ID=#{managerSystemSkinId} </if>
	</sql>
	<!-- mysql 查询实体 -->
	<select id="getByEntity" resultMap="resultMap" parameterType="net.mingsoft.basic.entity.ManagerEntity" databaseId="mysql">
		select * from manager
		<where>
			<include refid="getManagerWhere"></include>
		</where>
		limit 0,1
	</select>
	<!-- oracle 查询实体 -->
	<select id="getByEntity" resultMap="resultMap" parameterType="net.mingsoft.basic.entity.ManagerEntity" databaseId="oracle">
		select * from manager
		<where>
			<include refid="getManagerWhere"></include>
			and rownum=1
		</where>
	</select>
	<!-- SqlServer 查询实体 -->
	<select id="getByEntity" resultMap="resultMap" parameterType="net.mingsoft.basic.entity.ManagerEntity" databaseId="sqlServer">
		select top(1) * from manager
		<where>
			<include refid="getManagerWhere"></include>
		</where>
	</select>
	<!-- 更新管理员开始 -->
	<update id="updateEntity" parameterType="net.mingsoft.basic.entity.ManagerEntity">
		update manager
		<set>
			<if test="managerName != null">MANAGER_NAME=#{managerName},</if>
			<if test="managerNickName != null">MANAGER_NICKNAME=#{managerNickName},</if>
			<if test="managerAdmin != null and managerAdmin != ''"> MANAGER_ADMIN=#{managerAdmin},</if>
			<if test="managerPassword != null and managerPassword != ''">MANAGER_PASSWORD=#{managerPassword},</if>
			<if test="managerRoleID != null and managerRoleID &gt; 0">MANAGER_ROLEID=#{managerRoleID},</if>
			<if test="managerPeopleID != null and managerPeopleID &gt; 0">MANAGER_PEOPLEID=#{managerPeopleID},</if>
		</set>
		where MANAGER_ID = #{managerId}
	</update>
	<!-- 更新管理员结束 -->

	<!-- 修改用户登录密码开始 -->
	<update id="updateUserPasswordByUserName" parameterType="net.mingsoft.basic.entity.ManagerEntity">
		update manager
		<set>
			<if test="managerPassword != null">MANAGER_PASSWORD=#{managerPassword}</if>
		</set>
		where MANAGER_NAME = #{managerName}
	</update>
	<!-- 修改用户登录密码结束 -->

	<!--查询全部-->
	<select id="queryAll" resultMap="resultMap">
		select * from manager order by MANAGER_ID desc
	</select>
	<!--条件查询-->
	<select id="query" resultMap="resultMap">
		select * from manager
		<where>
				<if test="managerName != null and managerName != ''"> and MANAGER_NAME=#{managerName} </if>
				<if test="managerNickName != null and managerNickName != ''"> and MANAGER_NICKNAME=#{managerNickName} </if>
			<if test="managerAdmin != null and managerAdmin != ''">and MANAGER_ADMIN=#{managerAdmin}</if>
				<if test="managerPassword != null and managerPassword != ''"> and MANAGER_PASSWORD=#{managerPassword} </if>
				<if test="managerRoleID &gt; 0"> and MANAGER_ROLEID=#{managerRoleID} </if>
				<if test="managerPeopleID &gt; 0"> and MANAGER_PEOPLEID=#{managerPeopleID} </if>
				<if test="managerSystemSkinId &gt; 0"> and MANAGER_SYSTEM_SKIN_ID=#{managerSystemSkinId} </if>
		</where>
		order by MANAGER_ID desc
	</select>

</mapper>