<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="User"> <select id="selectUserByNameAndPassword" resultClass="user" parameterClass="userVO" > select * from t_user where name=#username# and password=#password# </select> <resultMap class="user" id="resultUserAuthor"> <result property="id" column="userId"/> <result property="userType" column="userType"/> <result property="roleList" select="User.selectUserRoleList" column="userId"/> <result property="menuList" select="User.selectUserMenuList" column="userId"/> <result property="productKeyList" select="User.selectUserProductKeyList" column="userId"/> <result property="entityList" select="User.selectUserEntityList" column="userId"/> </resultMap> <select id="selectUserAuthor" resultMap="resultUserAuthor" parameterClass="userVO"> select id as userId, userType as userType from t_user where id=#userId# </select> <select id="selectUserRoleList" resultClass="role"> select a.* from t_role a, t_user_role b where a.id=b.roleId and b.userId=#userId# </select> <select id="selectUserMenuList" resultClass="menu"> select a.* from t_menu a, t_role_resource b,t_user_role c where a.id=b.resourceId and b.roleId=c.roleId and b.resourceType=1 and c.userId=#userId# </select> <select id="selectUserProductKeyList" resultClass="productKey"> select a.* from t_product_key a, t_role_resource b,t_user_role c where a.id=b.resourceId and b.roleId=c.roleId and b.resourceType=4 and c.userId=#userId# and a.scope = (select d.value from t_config d where d.name='serverType') </select> <select id="selectUserEntityList" resultClass="entity"> select a.* from t_entity a where a.pass=1 union select a.* from t_entity a, t_role_resource b,t_user_role c where a.id=b.resourceId and b.roleId=c.roleId and a.pass=0 and b.resourceType=2 and c.userId=#userId# </select> <select id="getRolesByUserId" resultClass="role" > select t.* from t_role t,t_user_role t1 where t.id=t1.roleId and t1.userId=#id# </select> <resultMap class="user" id="userResultMap"> <result property="id" column="id"/> <result property="name" column="name"/> <result property="password" column="password"/> <result property="status" column="status"/> <result property="userType" column="userType"/> <result property="orgId" column="orgId"/> <result property="createDate" column="createDate"/> <result property="creater" column="creater"/> </resultMap> <resultMap class="user" id="userWithRolesResultMap" extends="userResultMap"> <result property="roleList" column="id" select="User.getRolesByUserId"/> </resultMap> <select id="selectUserList" resultMap="userWithRolesResultMap" parameterClass="userVO"> select * from t_user where 1=1 <isNotEmpty property="orgId" prepend="and"> orgId=#orgId# </isNotEmpty> <isNotEmpty property="username" prepend="and"> name like concat('%', #username#, '%') </isNotEmpty> <isNotEmpty property="userId" prepend="and"> id=#userId# </isNotEmpty> </select> <!-- 新增用户 --> <insert id="insertUser" parameterClass="user"> insert into t_user (name,password,status,userDesc,userType,orgId,createDate,creater) values (#name#,#password#,#status#,#userDesc#,#userType#,#orgId#,#createDate#,#creater#) <selectKey resultClass="int" > SELECT @@IDENTITY AS ID </selectKey> </insert> <insert id="insertUserRole" parameterClass="userRole"> insert into t_user_role (roleId,userId) values (#roleId#,#userId#) <selectKey resultClass="int" > SELECT @@IDENTITY AS ID </selectKey> </insert> <update id="updateUserRole" parameterClass="userRole"> update t_user_role set userId=#userId#,roleId=#roleId# where id=#id# </update> <select id="selectUserRole" parameterClass="userRole" resultClass="userRole"> select * from t_user_role where userId=#userId# </select> <update id="updateUser" parameterClass="user"> update t_user <dynamic prepend="set"> <isNotEmpty prepend="," property="name"> `name`=#name# </isNotEmpty> <isNotEmpty prepend="," property="password"> `password`=#password# </isNotEmpty> <isNotEmpty prepend="," property="status"> `status`=#status# </isNotEmpty> <isNotEmpty prepend="," property="orgId"> `orgId`=#orgId# </isNotEmpty> <isNotEmpty prepend="," property="userType"> `userType`=#userType# </isNotEmpty> </dynamic> where id=#id# </update> <delete id="deleteUser" parameterClass="userVO"> delete from t_user where id=#userId# </delete> <select id="isExistUserName" parameterClass="user" resultClass="int"> select count(0) from t_user where name=#name# <isNotEmpty prepend="and" property="id"> `id`!=#id# </isNotEmpty> </select> </sqlMap>