管道基础大数据平台系统开发-【后端】-Server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?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.lf.server.mapper.sys.UserMapper">
    <resultMap id="resultMap" type="com.lf.server.entity.sys.UserEntity">
        <id property="id" column="id"></id>
        <result property="natives" column="native"></result>
        <result property="createUser" column="create_user"></result>
        <result property="createTime" column="create_time"></result>
        <result property="updateUser" column="update_user"></result>
        <result property="updateTime" column="update_time"></result>
    </resultMap>
 
    <select id="selectCount" resultType="java.lang.Integer" parameterType="java.lang.String">
        select count(*) from lf.sys_user
        <where>
            <if test="uname != null">
                uname like #{uname}
            </if>
        </where>
    </select>
 
    <select id="selectByPage" resultMap="resultMap" resultType="com.lf.server.entity.sys.UserEntity">
        select a.*,fn_rec_query(a.depid, 'dep') depName from lf.sys_user a
        <where>
            <if test="uname != null">
                uname like #{uname}
            </if>
        </where>
        order by a.id
        limit #{limit} offset #{offset}
    </select>
 
    <select id="selectCountForRole" resultType="java.lang.Integer" parameterType="java.lang.String">
        select count(a.*) from lf.sys_user a
        <where>
            not exists (select b.id from lf.sys_role_user b where b.userid = a.id
            <if test="roleid != null">
                and b.roleid = #{roleid}
            </if>
            )
            <if test="uname != null">
                and a.uname like #{uname}
            </if>
            <if test="depid != null">
                and a.depid = ANY(fn_rec_array(#{depid}, 'dep'))
            </if>
        </where>
    </select>
 
    <select id="selectByPageForRole" resultMap="resultMap" resultType="com.lf.server.entity.sys.UserEntity">
        select a.*,fn_rec_query(a.depid, 'dep') depName from lf.sys_user a
        <where>
            not exists (select b.id from lf.sys_role_user b where b.userid = a.id
            <if test="roleid != null">
                and b.roleid = #{roleid}
            </if>
            )
            <if test="uname != null">
                and a.uname like #{uname}
            </if>
            <if test="depid != null">
                and a.depid = ANY(fn_rec_array(#{depid}, 'dep'))
            </if>
        </where>
        order by a.id
        limit #{limit} offset #{offset}
    </select>
 
    <select id="selectUserAll" resultMap="resultMap" resultType="com.lf.server.entity.sys.UserEntity">
        select a.*, fn_rec_query(a.depid, 'dep') depName from lf.sys_user a order by a.id
    </select>
 
    <select id="selectUser" resultMap="resultMap" resultType="com.lf.server.entity.sys.UserEntity">
        select a.*, fn_rec_query(a.depid, 'dep') depName from lf.sys_user a where a.id = #{id}
    </select>
 
    <select id="selectByUid" resultMap="resultMap" resultType="com.lf.server.entity.sys.UserEntity">
        select * from lf.sys_user where uid = #{uid}
    </select>
 
    <select id="selectByToken" resultType="com.lf.server.entity.sys.UserEntity">
        select * from lf.sys_user where id = (
          select create_user from lf.sys_token where token=#{token} and expire > now() limit 1)
    </select>
 
    <insert id="insertUser" parameterType="com.lf.server.entity.sys.UserEntity">
       insert into lf.sys_user
       (depid,uid,uname,pwd,salt,sex,native,contact,job,email,addr,edu,idcard,status,create_user,create_time,bak)
       values
       (#{depid},#{uid},#{uname},#{pwd},#{salt},#{sex},#{natives},#{contact},#{job},#{email},#{addr},#{edu},#{idcard},
       #{status},#{createUser},now(),#{bak})
    </insert>
 
    <insert id="insertUsers">
       insert into lf.sys_user
        (depid,uid,uname,pwd,salt,sex,native,contact,job,email,addr,edu,idcard,status,create_user,create_time,bak)
       values
        <foreach collection="list"   item="item" index="index" separator=","  >
            (#{item.depid},#{item.uid},#{item.uname},#{item.pwd},#{item.salt},#{item.sex},#{item.natives},#{item.contact},#{item.job},
            #{item.email},#{item.addr},#{item.edu},#{item.idcard},#{item.status},#{item.createUser}, now(),#{item.bak})
        </foreach>
    </insert>
 
    <delete id="deleteUser">
        delete from lf.sys_user where id = #{id}
    </delete>
 
    <delete id="deleteUsers">
        delete from lf.sys_user where id in
        <foreach item="id" collection="ids" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <update id="updateUsers">
    update lf.sys_user set depid=#{depid},uid=#{uid},uname=#{uname},pwd=#{pwd},salt=#{salt},sex=#{sex},native=#{natives},contact=#{contact},job=#{job},email=#{email},
    addr=#{addr},edu=#{edu},idcard=#{idcard},status=#{status},update_user=#{updateUser},update_time=now(),bak=#{bak} where id=#{id}
    </update>
 
    <update id="updateUsersPwd">
        update lf.sys_user set pwd=#{pwd},update_user=#{updateUser},update_time=now() where id in
        <foreach item="id" collection="ids" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>