electromagnetic-data-new/electrmangnetic/src/main/resources/sqlmapper/UserMapper.xml

177 lines
7.2 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.electromagnetic.industry.software.manage.mapper.UserMapper">
<resultMap id="UserResultMap" type="com.electromagnetic.industry.software.manage.pojo.models.User">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="user_name" jdbcType="VARCHAR" property="userName"/>
<result column="work_number" jdbcType="VARCHAR" property="workNumber"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="user_dept" jdbcType="VARCHAR" property="userDept"/>
<result column="user_title" jdbcType="VARCHAR" property="userTitle"/>
<result column="user_account" jdbcType="VARCHAR" property="userAccount"/>
<result column="user_pwd" jdbcType="VARCHAR" property="userPwd"/>
<result column="join_time" jdbcType="TIMESTAMP" property="joinTime"/>
<result column="is_published" jdbcType="TINYINT" property="isPublished"/>
<result column="is_activated" jdbcType="TINYINT" property="isActivated"/>
<result column="salt" jdbcType="VARCHAR" property="salt"/>
<result column="user_status" jdbcType="VARCHAR" property="userStatus"/>
<result column="internship_end_date" jdbcType="DATE" property="internshipEndDate"/>
<result column="admin_type" jdbcType="VARCHAR" property="adminType"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
<result column="effect_flag" jdbcType="TINYINT" property="effectFlag"/>
</resultMap>
<sql id="selectUserVo">
select id,
user_name,
work_number,
mobile,
user_dept,
user_title,
user_account,
user_pwd,
join_time,
is_published,
is_activated,
salt,
user_status,
internship_end_date,
admin_type,
created_time,
created_by,
updated_by,
updated_time,
effect_flag
from ed_users
</sql>
<select id="search" parameterType="com.electromagnetic.industry.software.manage.pojo.other.SearchKeyWords"
resultMap="UserResultMap">
SELECT *
FROM ed_users
<where>
<!-- 条件 1按用户名或工号搜索 -->
<if test="keyWord != null and keyWord != ''">
(user_name LIKE CONCAT('%', #{keyWord}, '%') OR work_number LIKE CONCAT('%', #{keyWord}, '%'))
</if>
<!-- 条件 2按用户状态搜索 -->
<if test="userStatus != null and userStatus != ''">
<choose>
<when test="userStatus != 'all'">
AND user_status = #{userStatus}
</when>
</choose>
</if>
<!-- 条件 3按发布状态搜索 -->
<if test="isPublished != null and isPublished != ''">
<choose>
<when test="isPublished != 'all'">
AND is_published = CAST(#{isPublished} AS SIGNED)
</when>
</choose>
</if>
<!-- 条件 4按激活状态搜索 -->
<if test="isActivated != null and isActivated != ''">
<choose>
<when test="isActivated != 'all'">
AND is_activated = CAST(#{isActivated} AS SIGNED)
</when>
</choose>
</if>
and effect_flag=1
</where>
<!-- 动态排序条件 -->
<choose>
<when test="gmtCreate == 'asc' or gmtCreate == 'desc'">
ORDER BY created_time ${gmtCreate}
</when>
<when test="joinTime == 'asc' or joinTime == 'desc'">
ORDER BY join_time ${joinTime}
</when>
<when test="internEndDate == 'asc' or internEndDate == 'desc'">
ORDER BY internship_end_date ${internEndDate}
</when>
</choose>
LIMIT #{pageSize} OFFSET #{pageIndex}
</select>
<select id="getTotalCount" parameterType="com.electromagnetic.industry.software.manage.pojo.other.SearchKeyWords"
resultType="Integer">
SELECT COUNT(*)
FROM ed_users
<where>
<!-- 条件 1按用户名或工号搜索 -->
<if test="keyWord != null and keyWord != ''">
(user_name LIKE CONCAT('%', #{keyWord}, '%') OR work_number LIKE CONCAT('%', #{keyWord}, '%'))
</if>
<!-- 条件 2按用户状态搜索 -->
<if test="userStatus != null and userStatus != ''">
<choose>
<when test="userStatus != 'all'">
AND user_status = #{userStatus}
</when>
</choose>
</if>
<!-- 条件 3按发布状态搜索 -->
<if test="isPublished != null and isPublished != ''">
<choose>
<when test="isPublished != 'all'">
AND is_published = #{isPublished}
</when>
</choose>
</if>
<!-- 条件 4按激活状态搜索 -->
<if test="isActivated != null and isActivated != ''">
<choose>
<when test="isActivated != 'all'">
AND is_activated = CAST(#{isActivated} AS SIGNED)
</when>
</choose>
</if>
and effect_flag=1
</where>
<!-- 动态排序条件 -->
<choose>
<when test="gmtCreate == 'asc' or gmtCreate == 'desc'">
ORDER BY created_time ${gmtCreate}
</when>
<when test="joinTime == 'asc' or joinTime == 'desc'">
ORDER BY join_time ${joinTime}
</when>
<when test="internEndDate == 'asc' or internEndDate == 'desc'">
ORDER BY internship_end_date ${internEndDate}
</when>
</choose>
</select>
<select id="selectUserByWorkNumber" parameterType="String" resultMap="UserResultMap">
<include refid="selectUserVo"/>
where work_number = #{workNumber}
</select>
<select id="getSingleUser" parameterType="String" resultMap="UserResultMap">
<include refid="selectUserVo"/>
where id = #{userId}
</select>
<select id="selectUserRoles" parameterType="String" resultType="String">
select r.role_name
from ed_role r
where r.role_id in (select ur.role_id
from ed_users u
left join ed_user_role ur on u.id = ur.user_id
where u.id = #{userId})
</select>
</mapper>