You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

682 lines
22 KiB
XML

<?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.manage.dao.Power_UserMapper">
<resultMap id="BaseResultMap" type="com.manage.vo.Power_UserVo">
<id column="user_id" jdbcType="INTEGER" property="userId" />
<result column="user_name" jdbcType="VARCHAR" property="userName" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="user_pwd" jdbcType="VARCHAR" property="userPwd" />
<result column="user_sex" jdbcType="INTEGER" property="userSex" />
<result column="user_age" jdbcType="INTEGER" property="userAge" />
<result column="user_tel" jdbcType="VARCHAR" property="userTel" />
<result column="user_email" jdbcType="VARCHAR" property="userEmail" />
<result column="user_position" jdbcType="VARCHAR" property="userPosition" />
<result column="role_id" jdbcType="INTEGER" property="roleId" />
<result column="dept_id" jdbcType="VARCHAR" property="deptId" />
<result column="effective" jdbcType="INTEGER" property="effective" />
<result column="create_date" jdbcType="CHAR" property="createDate" />
<result column="creater" jdbcType="VARCHAR" property="creater" />
<result column="update_date" jdbcType="CHAR" property="updateDate" />
<result column="updater" jdbcType="VARCHAR" property="updater" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="role_name" jdbcType="VARCHAR" property="roleName" />
<result column="dict_id" jdbcType="INTEGER" property="dictId" />
</resultMap>
<resultMap id="BaseResultMapVo" type="com.manage.vo.User">
<id column="user_id" jdbcType="INTEGER" property="userId" />
<result column="user_name" jdbcType="VARCHAR" property="userName" />
<result column="role_id" jdbcType="INTEGER" property="roleId" />
<result column="role_name" jdbcType="VARCHAR" property="roleName" />
<result column="dept_code" jdbcType="VARCHAR" property="deptCode" />
</resultMap>
<sql id="Base_Column_List">
user_id, user_name,name, user_pwd, user_sex, user_age, user_tel, user_email, user_position,
role_id, dept_id, effective, create_date, creater, update_date, updater, remark
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from power_user
where user_id = #{userId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from power_user
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.manage.entity.Power_User">
insert into power_user (user_id, user_name,name, user_pwd,
user_sex, user_age, user_tel,
user_email, user_position, role_id,
dept_id, effective, create_date,
creater, update_date, updater,
remark)
values (#{userId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},
#{userPwd,jdbcType=VARCHAR},
#{userSex,jdbcType=INTEGER}, #{userAge,jdbcType=INTEGER}, #{userTel,jdbcType=VARCHAR},
#{userEmail,jdbcType=VARCHAR}, #{userPosition,jdbcType=VARCHAR}, #{roleId,jdbcType=INTEGER},
#{deptId,jdbcType=VARCHAR}, #{effective,jdbcType=INTEGER}, #{createDate,jdbcType=CHAR},
#{creater,jdbcType=VARCHAR}, #{updateDate,jdbcType=CHAR}, #{updater,jdbcType=VARCHAR},
#{remark,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.manage.entity.Power_User">
insert into power_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">
user_id,
</if>
<if test="userName != null">
user_name,
</if>
<if test="name != null">
name,
</if>
<if test="userPwd != null">
user_pwd,
</if>
<if test="userSex != null">
user_sex,
</if>
<if test="userAge != null">
user_age,
</if>
<if test="userTel != null">
user_tel,
</if>
<if test="userEmail != null">
user_email,
</if>
<if test="userPosition != null">
user_position,
</if>
<if test="roleId != null">
role_id,
</if>
<if test="deptId != null">
dept_id,
</if>
<if test="effective != null">
effective,
</if>
<if test="createDate != null">
create_date,
</if>
<if test="creater != null">
creater,
</if>
<if test="updateDate != null">
update_date,
</if>
<if test="updater != null">
updater,
</if>
<if test="remark != null">
remark,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="userName != null">
#{userName,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="userPwd != null">
#{userPwd,jdbcType=VARCHAR},
</if>
<if test="userSex != null">
#{userSex,jdbcType=INTEGER},
</if>
<if test="userAge != null">
#{userAge,jdbcType=INTEGER},
</if>
<if test="userTel != null">
#{userTel,jdbcType=VARCHAR},
</if>
<if test="userEmail != null">
#{userEmail,jdbcType=VARCHAR},
</if>
<if test="userPosition != null">
#{userPosition,jdbcType=VARCHAR},
</if>
<if test="roleId != null">
#{roleId,jdbcType=INTEGER},
</if>
<if test="deptId != null">
#{deptId,jdbcType=VARCHAR},
</if>
<if test="effective != null">
#{effective,jdbcType=INTEGER},
</if>
<if test="createDate != null">
#{createDate,jdbcType=CHAR},
</if>
<if test="creater != null">
#{creater,jdbcType=VARCHAR},
</if>
<if test="updateDate != null">
#{updateDate,jdbcType=CHAR},
</if>
<if test="updater != null">
#{updater,jdbcType=VARCHAR},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.manage.entity.Power_User">
update power_user
<set>
<if test="userName != null and userName != ''">
user_name = #{userName,jdbcType=VARCHAR},
</if>
name = #{name,jdbcType=VARCHAR},
<if test="userPwd != null and userPwd != ''">
user_pwd = #{userPwd,jdbcType=VARCHAR},
</if>
<if test="userSex != null">
user_sex = #{userSex,jdbcType=INTEGER},
</if>
user_age = #{userAge,jdbcType=INTEGER},
user_tel = #{userTel,jdbcType=VARCHAR},
user_email = #{userEmail,jdbcType=VARCHAR},
user_position = #{userPosition,jdbcType=VARCHAR},
<if test="roleId != null">
role_id = #{roleId,jdbcType=INTEGER},
</if>
<if test="deptId != null and deptId != ''">
dept_id = #{deptId,jdbcType=VARCHAR},
</if>
<if test="effective != null">
effective = #{effective,jdbcType=INTEGER},
</if>
<if test="createDate != null and createDate != ''">
create_date = #{createDate,jdbcType=CHAR},
</if>
<if test="creater != null and creater != ''">
creater = #{creater,jdbcType=VARCHAR},
</if>
<if test="updateDate != null and updateDate != ''">
update_date = #{updateDate,jdbcType=CHAR},
</if>
<if test="updater != null and updater != ''">
updater = #{updater,jdbcType=VARCHAR},
</if>
remark = #{remark,jdbcType=VARCHAR},
</set>
where user_id = #{userId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.manage.entity.Power_User">
update power_user
set user_name = #{userName,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
user_pwd = #{userPwd,jdbcType=VARCHAR},
user_sex = #{userSex,jdbcType=INTEGER},
user_age = #{userAge,jdbcType=INTEGER},
user_tel = #{userTel,jdbcType=VARCHAR},
user_email = #{userEmail,jdbcType=VARCHAR},
user_position = #{userPosition,jdbcType=VARCHAR},
role_id = #{roleId,jdbcType=INTEGER},
dept_id = #{deptId,jdbcType=VARCHAR},
effective = #{effective,jdbcType=INTEGER},
create_date = #{createDate,jdbcType=CHAR},
creater = #{creater,jdbcType=VARCHAR},
update_date = #{updateDate,jdbcType=CHAR},
updater = #{updater,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR}
where user_id = #{userId,jdbcType=INTEGER}
</update>
<!--2019-4-16 ljx -->
<select id="findPowerUserByUserNameAndUserPwd" parameterType="com.manage.entity.Power_User" resultType="com.manage.vo.Power_UserVo">
SELECT
user_id,
user_name,
NAME,
user_sex,
user_age,
user_tel,
power_user.role_id,
power_user.dept_id,
power_user.effective,
power_user.create_date,
power_user.creater,
power_user.update_date,
power_user.updater,
power_user.remark,
GROUP_CONCAT(power_dept.dept_name) powerDepts
FROM
power_user
LEFT JOIN power_dept ON FIND_IN_SET(
power_dept.dept_id,
power_user.dept_id
)
where power_user.effective = #{effective,jdbcType=INTEGER} and user_name = #{userName,jdbcType=VARCHAR} and user_pwd = #{userPwd,jdbcType=VARCHAR}
</select>
<!--2019-07-31 zengwenhe -->
<select id="checkUserName" resultMap="BaseResultMap" parameterType="java.lang.String">
SELECT
user_id,role_id
FROM
power_user
WHERE
user_name = #{userName}
</select>
<!--2019-4-22 ljx -->
<select id="validUserRoleMenu" resultType="java.lang.Integer">
select count(*) from power_role_menu rm
where rm.role_id in ( select ur.role_id from power_user ur WHERE ur.user_id = #{userId,jdbcType=INTEGER} )
and rm.menu_id in ( select m.menu_id from power_menu m WHERE m.menu_url LIKE #{menuUrl,jdbcType=VARCHAR} )
</select>
<!--2019-4-22 ljx -->
<select id="findSomeByMore" resultMap="BaseResultMap">
SELECT
power_user.user_id,
power_user.user_name,
power_user.name,
power_user.user_sex,
power_user.user_age,
power_user.user_tel,
power_user.user_email,
power_user.user_position,
power_user.effective,
power_user.creater,
power_user.create_date,
power_user.updater,
power_user.update_date,
power_role.role_name,
GROUP_CONCAT(power_dept.dept_name) powerDepts
FROM
power_user
LEFT JOIN
power_role
ON power_user.role_id = power_role.role_id
LEFT JOIN
power_dept ON FIND_IN_SET(power_dept.dept_id,power_user.dept_id)
<where>
<if test="userId != null">
user_id IN (
SELECT
power_user_dict.user_id
FROM
power_user_dict
LEFT JOIN
power_user_dict power_user_dict1 ON power_user_dict.dict_id = power_user_dict1.dict_id
WHERE
power_user_dict1.user_id = ${userId}
AND power_user.role_id != 0
<if test="roleId!=null and roleId!=-100 and roleId != 0">
AND power_user.role_id != -100
</if>
)
</if>
<if test="name!=null and name!=''">
and power_user.name LIKE '%${name}%'
</if>
<if test="userName!=null and userName!=''">
and power_user.user_name LIKE '%${userName}%'
</if>
<if test="userEmail!=null and userEmail!=''">
and power_user.user_email LIKE '%${userEmail}%'
</if>
<if test="effective!=null">
and power_user.effective=${effective}
</if>
<if test="deptId!=null and deptId!=''">
and FIND_IN_SET(#{deptId},power_user.dept_id)
</if>
<if test="searchRoleId!=null">
and power_user.role_id = ${searchRoleId}
</if>
<if test="checks != null and checks != ''">
and power_user.user_id IN (${checks})
</if>
and power_user.user_name != 'admin'
</where>
GROUP BY power_user.user_id
ORDER BY create_date DESC,user_id DESC
<if test="offset != null and limit != null">
LIMIT #{offset},#{limit}
</if>
</select>
<!--2019-4-22 ly -->
<select id="validUserMenu" resultType="java.lang.Integer">
select count(*) from power_user_menu um
where um.menu_id in(select m.menu_id from power_menu m WHERE m.menu_url LIKE #{menuUrl,jdbcType=VARCHAR} )
and um.user_id = #{userId,jdbcType=INTEGER} and flag = #{flag,jdbcType=INTEGER}
</select>
<select id="getTotal" resultType="int">
SELECT
count(1)
FROM
power_user
LEFT JOIN
power_role
ON power_user.role_id = power_role.role_id
<where>
<if test="userId != null">
user_id IN (
SELECT
power_user_dict.user_id
FROM
power_user_dict
LEFT JOIN
power_user_dict power_user_dict1 ON power_user_dict.dict_id = power_user_dict1.dict_id
WHERE
power_user_dict1.user_id = ${userId}
AND power_user.role_id != 0
<if test="roleId!=null and roleId!=-100 and roleId != 0">
AND power_user.role_id != -100
</if>
)
</if>
<if test="name!=null and name!=''">
and power_user.name LIKE '%${name}%'
</if>
<if test="userName!=null and userName!=''">
and power_user.user_name LIKE '%${userName}%'
</if>
<if test="userEmail!=null and userEmail!=''">
and power_user.user_email LIKE '%${userEmail}%'
</if>
<if test="effective!=null">
and power_user.effective=${effective}
</if>
<if test="deptId!=null and deptId!=''">
and FIND_IN_SET(#{deptId},power_user.dept_id)
</if>
<if test="searchRoleId!=null">
and power_user.role_id = ${searchRoleId}
</if>
and power_user.user_name != 'admin'
</where>
</select>
<!--2019-04-29zengwh-->
<!--根据科室id查询所有用户集合-->
<select id="selectAllByDeptId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT DISTINCT
a.*, b.role_name
FROM
(
SELECT
user_id,
user_name,
user_tel,
dept_id,
role_id
FROM
power_user
WHERE
effective = 1
AND FIND_IN_SET(${deptId}, dept_id)
AND role_id != 0
AND role_id != -100
<if test="userName != null and userName != ''">
AND user_name != #{userName}
</if>
) a
LEFT JOIN power_role b ON a.role_id = b.role_id
</select>
<!--2019-08-13zengwh-->
<!--权限系统的用户-->
<select id="selectAllBySysRole" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT
a.*, b.role_name roleName
FROM
(
SELECT DISTINCT
USER .user_id userId,
USER .user_name userName,
USER .user_tel userTel,
USER .dept_id deptId,
USER .role_id
FROM
power_user USER
LEFT JOIN power_dept dept ON FIND_IN_SET(dept.dept_id, USER .dept_id)
AND dept.effective = 1
AND dept.dict_id = ${dictId}
WHERE
USER .role_id = - 100
) a
LEFT JOIN power_role b ON a.role_id = b.role_id
</select>
<!--根据角色id和系统id查询所有用户集合-->
<select id="selectAllByRoleIdAndDictId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT
a.*, b.role_name roleName
FROM
(
SELECT DISTINCT
user.user_id userId,
user.user_name userName,
user.user_tel userTel,
user.dept_id deptId,
user.role_id
FROM
power_user user,
power_dept dept
WHERE
FIND_IN_SET(dept.dept_id,user.dept_id)
AND dept.effective = 1
AND user.role_id = ${roleId}
AND dept.dict_id = ${dictId}
) a
LEFT JOIN power_role b ON a.role_id = b.role_id
</select>
<!--2019-5-14 ljx -->
<select id="validPassword" resultType="java.lang.Integer">
select count(*)
from power_user u
where u.user_pwd = #{userPwd,jdbcType=VARCHAR}
AND u.user_id = #{userId,jdbcType=INTEGER}
</select>
<!--2019-5-14 ljx -->
<update id="updatePassword">
update power_user u
<set>
u.user_pwd = #{userPwd,jdbcType=VARCHAR},
updater = #{updater,jdbcType=VARCHAR},
update_date = #{updateDate,jdbcType=CHAR}
</set>
where user_id = #{userId,jdbcType=INTEGER}
</update>
<!--2019-08-16 zengwenhe -->
<select id="selectAllBySysId" resultMap="BaseResultMap">
SELECT
power_user.user_id,
power_user.user_name,
power_user.user_tel,
power_role.role_id,
power_role.role_name
FROM
power_user
LEFT JOIN power_user_dict ON power_user.user_id = power_user_dict.user_id
LEFT JOIN power_role ON power_user.role_id = power_role.role_id
AND power_role.effective = 1
WHERE
power_user.effective = 1
AND power_user_dict.dict_id = ${hospitalId}
AND power_user.role_id != 0
<if test="userName != null and userName != ''">
AND power_user.user_name != #{userName}
</if>
</select>
<!--根据通知类别id查询所属系统用户集合-->
<select id="selectUserListByNoticeTypeId" resultMap="BaseResultMap">
SELECT
power_user.user_id,
power_user.user_name
FROM
power_notice
LEFT JOIN power_sys_dict ON power_notice.notice_type_flag = power_sys_dict.sys_flag
<if test="hospitalId != null">
AND power_sys_dict.parent_id = #{hospitalId}
</if>
LEFT JOIN power_user ON power_sys_dict.dept_id IN (power_user.dept_id) AND power_user.effective = 1
WHERE
power_notice.notice_id = ${noticeTypeId}
AND power_user.user_id IS NOT NULL
AND power_user.role_id != 0
AND power_user.effective = 1
</select>
<!--删除角色用户角色id置空-->
<update id="updateUserRoleIdByRoleId" parameterType="java.lang.Integer">
UPDATE
power_user
SET
role_id = NULL
WHERE
role_id = ${roleId}
</update>
<select id="selectHospitalIdByUserId" resultType="java.lang.Integer">
select dict_id from power_user_dict where user_id = ${userId}
</select>
<select id="selectUsersBySysFlagAndHospitalId" resultMap="BaseResultMap">
SELECT
user_id
FROM
power_user
INNER JOIN (
SELECT
dept_id
FROM
power_sys_dict
WHERE
sys_flag = #{sysFlag}
<if test="hospitalId != null">
AND parent_id = ${hospitalId}
</if>
) dept ON FIND_IN_SET(
dept.dept_id,
power_user.dept_id
)
group by user_id
</select>
<select id="selectUserIdAndUserNameList" resultMap="BaseResultMapVo">
SELECT
power_user_dict.user_id,
power_user.user_name,
power_user.role_id,
power_user.dept_id,
power_user.dept_code,
power_role.role_name,
name
FROM
power_user_dict
INNER JOIN power_user ON power_user_dict.user_id = power_user.user_id AND power_user.effective = 1 AND power_user.role_id != 0
LEFT JOIN power_role ON power_user.role_id = power_role.role_id AND power_role.effective = 1
<if test="userId != null and userId != ''">
WHERE
dict_id = (
SELECT
dict_id
FROM
power_user_dict
WHERE
user_id = #{userId}
)
</if>
</select>
<!--查询各表无效数-->
<select id="selectEffectiveCount" resultType="java.lang.Integer">
SELECT (
(SELECT count(1) FROM power_dept WHERE effective = 0) +
(SELECT count(1) FROM power_menu WHERE effective = 0) +
(SELECT count(1) FROM power_role WHERE effective = 0) +
(SELECT count(1) FROM power_sys_dict WHERE dict_status = 0) +
(SELECT count(1) FROM power_user WHERE effective = 0) +
(SELECT count(1) FROM power_user WHERE effective = 0)
) count
</select>
<!--全查非admin-->
<select id="selectAllNotAdmin" resultMap="BaseResultMapVo">
SELECT user_id,user_name FROM power_user WHERE effective = 1 AND role_id != 0
</select>
<!--批量插入-->
<insert id="SimpleInsert" parameterType="java.util.List">
INSERT INTO power_user(
user_id,
user_name,
name,
user_pwd,
user_sex,
user_age,
user_tel,
user_email,
user_position,
role_id,
dept_id,
effective,
create_date,
creater,
update_date,
updater,
remark
)
VALUES
<foreach collection ="list" item="item" index= "index" separator =",">
(
#{item.userId,jdbcType=INTEGER},
#{item.userName,jdbcType=VARCHAR},
#{item.name,jdbcType=VARCHAR},
#{item.userPwd,jdbcType=VARCHAR},
#{item.userSex,jdbcType=INTEGER},
#{item.userAge,jdbcType=INTEGER},
#{item.userTel,jdbcType=VARCHAR},
#{item.userEmail,jdbcType=VARCHAR},
#{item.userPosition,jdbcType=VARCHAR},
#{item.roleId,jdbcType=INTEGER},
#{item.deptId,jdbcType=VARCHAR},
#{item.effective,jdbcType=INTEGER},
#{item.createDate,jdbcType=CHAR},
#{item.creater,jdbcType=VARCHAR},
#{item.updateDate,jdbcType=CHAR},
#{item.updater,jdbcType=VARCHAR},
#{item.remark,jdbcType=VARCHAR}
)
</foreach >
</insert>
<!--根据用户名和备注获取用户信息-->
<select id="findPowerUserByUserNameAndRemark" resultMap="BaseResultMap">
select * from power_user where user_name = #{userName} and remark = #{remark}
</select>
<!--根据医院id查询用户集合-->
<select id="getUserTreeByHospitalId" resultMap="BaseResultMap">
SELECT
power_user.user_id,
power_user.user_name,
power_user.user_tel
FROM
power_user_dict
inner JOIN
power_user
ON power_user_dict.user_id = power_user.user_id
WHERE
power_user.role_id != -100
AND
power_user_dict.dict_id = #{hospitalId}
</select>
<!--根据科室id查询用户集合-->
<select id="getUserTreeByDeptId" resultMap="BaseResultMap">
SELECT
power_user.user_id,
power_user.user_name,
power_user.user_tel
FROM
power_user
WHERE
FIND_IN_SET(#{deptId},dept_id)
</select>
</mapper>