longz
2026-06-10 1f4fd950f6aa0dd8f865f63daeb2303efb3f8d76
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
<?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.stylefeng.guns.modular.system.dao.SysUserCompanyScopeMapper">
 
    <select id="selectScopesByUserId" resultType="map">
        SELECT s.*, c.name AS companyName, d.simplename AS deptName,
        (SELECT GROUP_CONCAT(r.name) FROM sys_role r WHERE FIND_IN_SET(r.id, s.roleid)) AS roleName
        FROM sys_user_company_scope s
        LEFT JOIN t_company c ON c.id = s.companyId
        LEFT JOIN sys_dept d ON d.id = s.deptid
        WHERE s.userId = #{userId}
          AND s.status = 1
        ORDER BY s.isDefault ASC, s.id ASC
    </select>
 
    <select id="selectActiveScope" resultType="com.stylefeng.guns.modular.system.model.SysUserCompanyScope">
        SELECT *
        FROM sys_user_company_scope
        WHERE userId = #{userId}
          AND status = 1
        <if test="companyId != null">
          AND companyId = #{companyId}
        </if>
        ORDER BY isDefault ASC, id ASC
        LIMIT 1
    </select>
 
    <select id="countScopesByUserId" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM sys_user_company_scope
        WHERE userId = #{userId}
          AND status = 1
    </select>
 
    <update id="clearDefault">
        UPDATE sys_user_company_scope
        SET isDefault = 2, updateTime = NOW()
        WHERE userId = #{userId}
          AND status = 1
    </update>
 
    <delete id="deleteByUserId">
        DELETE FROM sys_user_company_scope WHERE userId = #{userId}
    </delete>
</mapper>