yangys
2025-11-18 8e944cfabb253fc2556588e308e282586043f7b0
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?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.qianwen.smartman.modules.smis.mapper.CommonGroupMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="groupResultMap" type="com.qianwen.smartman.modules.smis.entity.CommonGroup">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="full_name" property="fullName"/>
        <result column="code" property="code"/>
        <result column="group_category" property="groupCategory"/>
        <result column="sort" property="sort"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
 
    <resultMap id="groupVOResultMap" type="com.qianwen.smartman.modules.smis.vo.CommonGroupVO">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="full_name" property="fullName"/>
        <result column="group_category" property="groupCategory"/>
        <result column="sort" property="sort"/>
        <result column="remark" property="remark"/>
        <result column="has_children" property="hasChildren"/>
    </resultMap>
 
    <resultMap id="treeNodeResultMap" type="com.qianwen.core.tool.node.TreeNode">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="title" property="title"/>
        <result column="value" property="value"/>
        <result column="key" property="key"/>
        <result column="has_children" property="hasChildren"/>
    </resultMap>
 
    <delete id="removeOrgByIds">
        DELETE
        FROM
        blade_common_group
        WHERE
        group_type = 'group_organization'
        AND group_category =1
        <if test="deptIds != null and deptIds.size() > 0">
            AND id IN
            <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
                #{deptId}
            </foreach>
        </if>
    </delete>
 
    <!--物理删除组织机构-->
    <delete id="removeOrg">
        DELETE
        FROM blade_common_group
        WHERE group_type = 'group_organization'
          AND group_category = 1
    </delete>
    <!--物理删除组织机构与员工的关系-->
    <delete id="removeOrgContact">
        DELETE
        FROM blade_common_group_of_item
        WHERE group_type = 'group_organization'
          AND group_category = 1
    </delete>
 
 
    <select id="lazyList" resultMap="groupVOResultMap">
        SELECT
        common_group.* ,
        (
        SELECT
        CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
        FROM
        blade_common_group
        WHERE
        parent_id = common_group.id and is_deleted = 0
        ) AS "has_children"
        FROM
        blade_common_group common_group
        WHERE common_group.is_deleted = 0
        <if test="tenantId!=null and tenantId!=''">
            and common_group.tenant_id = #{tenantId}
        </if>
        <if test="parentId!=null">
            and common_group.parent_id = #{parentId}
        </if>
        and common_group.group_type = #{groupType}
        and common_group.group_category = #{groupCategory}
        <if test="p.name!=null and p.name!=''">
            and common_group.name like concat(concat('%', #{p.name}),'%')
        </if>
        <if test="p.fullName!=null and p.fullName!=''">
            and common_group.full_name like concat(concat('%', #{p.fullName}),'%')
        </if>
        ORDER BY common_group.sort
    </select>
 
    <select id="tree" resultMap="treeNodeResultMap">
        select id, parent_id, name as title, id as "value", id as "key" from blade_common_group where is_deleted = 0
        <if test="tenantId!=null and tenantId!=''">
            and tenant_id = #{tenantId}
        </if>
        and group_category = #{groupCategory}
        and group_type = #{groupType}
        ORDER BY sort
    </select>
 
    <select id="lazyTree" resultMap="treeNodeResultMap">
        SELECT
        common_group.id,
        common_group.parent_id,
        common_group.name AS title,
        common_group.id AS "value",
        common_group.id AS "key",
        (
        SELECT
        CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
        FROM
        blade_common_group
        WHERE
        parent_id = common_group.id and is_deleted = 0
        ) AS "has_children"
        FROM
        blade_common_group common_group
        WHERE
        common_group.parent_id = #{parentId} AND common_group.is_deleted = 0
        <if test="tenantId!=null and tenantId!=''">
            and common_group.tenant_id = #{tenantId}
        </if>
        ORDER BY common_group.sort
    </select>
 
    <select id="getGroupNames" resultType="java.lang.String">
        SELECT
        name
        FROM
        blade_common_group
        WHERE
        id IN
        <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
            #{ids}
        </foreach>
        and is_deleted = 0
    </select>
 
    <select id="getAllSubGroup" resultType="com.qianwen.smartman.modules.smis.entity.CommonGroup">
        select *
        from blade_common_group bcg1
        where code like concat((select bcg2.code
                                from blade_common_group bcg2
                                where bcg2.id = #{id}
                                  and bcg2.is_deleted = 0), '%')
          and bcg1.is_deleted = 0
          and bcg1.group_type = #{groupType}
          and bcg1.group_category = #{groupCategory}
    </select>
 
</mapper>