liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<?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.cloud.user.dao.SysOrganizationDao">
  <resultMap id="BaseResultMap" type="com.cloud.model.sys.SysOrganization">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="orgId" jdbcType="INTEGER" property="orgId" />
    <result column="parentId" jdbcType="INTEGER" property="parentId" />
    <result column="headquartersId" jdbcType="INTEGER" property="headquartersId" />
    <result column="areaId" jdbcType="INTEGER" property="areaId" />
    <result column="parentIds" jdbcType="VARCHAR" property="parentIds" />
    <result column="parentJson" jdbcType="VARCHAR" property="parentJson" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="master" jdbcType="VARCHAR" property="master" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="webUrl" jdbcType="VARCHAR" property="webUrl" />
    <result column="partack" jdbcType="VARCHAR" property="partack" />
    <result column="enabled" jdbcType="VARCHAR" property="enabled" />
    <result column="delFlag" jdbcType="VARCHAR" property="delFlag" />
    <result column="createTime" jdbcType="TIMESTAMP" property="createTime" />
    <result column="updateTime" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="revJson" jdbcType="CHAR" property="revJson" />
  </resultMap>
 
  <resultMap id="BaseMessageMap" type="com.cloud.model.sys.SysOrganization">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="orgId" jdbcType="INTEGER" property="orgId" />
    <result column="parentId" jdbcType="INTEGER" property="parentId" />
    <result column="headquartersId" jdbcType="INTEGER" property="headquartersId" />
    <result column="areaId" jdbcType="INTEGER" property="areaId" />
    <result column="parentIds" jdbcType="VARCHAR" property="parentIds" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="master" jdbcType="VARCHAR" property="master" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="webUrl" jdbcType="VARCHAR" property="webUrl" />
    <result column="partack" jdbcType="VARCHAR" property="partack" />
    <result column="revJson" jdbcType="CHAR" property="revJson" />
  </resultMap>
 
  <resultMap id="BaseIdMap" type="com.cloud.model.sys.SysOrganization">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="orgId" jdbcType="INTEGER" property="orgId" />
    <result column="parentId" jdbcType="INTEGER" property="parentId" />
    <result column="headquartersId" jdbcType="INTEGER" property="headquartersId" />
    <result column="areaId" jdbcType="INTEGER" property="areaId" />
    <result column="parentIds" jdbcType="VARCHAR" property="parentIds" />
    <result column="revJson" jdbcType="CHAR" property="revJson" />
  </resultMap>
 
 
  <select id="findAll" resultType="com.cloud.model.sys.SysOrganization">
      select * from sys_organization t where delFlag = '0'
      <if test="type != null and type != ''">
        and type  &lt; #{type}
      </if>
      order by t.sort
  </select>
 
  <!---默认查全部-->
  <sql id="Base_Column_List">
    id, orgId, parentId, headquartersId, areaId, parentIds, parentJson, name, sort, 
    type, address, master, phone, webUrl, partack, enabled, delFlag, createTime, updateTime,revJson
  </sql>
 
  <!---查基本信息-->
  <sql id="Base_Message_List">
    id, orgId, parentId, headquartersId, areaId, parentIds, name, sort,
    type, address, master, phone, webUrl, partack,revJson
  </sql>
 
  <!---查基本ID信息-->
  <sql id="Base_ID_List">
    id, orgId, parentId, headquartersId, areaId, parentIds,revJson
  </sql>
 
  <select id="findById" parameterType="java.util.Map" resultType="com.cloud.model.sys.SysOrganization">
    select
    <include refid="Base_Column_List" />
    from sys_organization
    where id = #{id,jdbcType=INTEGER}
      <if test="orgId != null and orgId != ''">
          and orgId = #{orgId}
      </if>
  </select>
 
  <!--机构逻辑删除-->
  <update id="deleteOrg">
    UPDATE sys_organization SET delFlag = '1' WHERE parentIds like concat('%,', #{id}, ',%')
    <if test="orgId != null and orgId != ''">
      and orgId = #{orgId}
    </if>
  </update>
 
  <insert id="save" parameterType="com.cloud.model.sys.SysOrganization"  keyProperty="id" useGeneratedKeys="true">
    insert into sys_organization (orgId, parentId, headquartersId,
      areaId, parentIds, parentJson, 
      name, sort, type, address, 
      master, phone, webUrl, 
      partack, enabled, delFlag, 
      createTime, updateTime,revJson)
    values (#{orgId,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{headquartersId,jdbcType=INTEGER}, 
      #{areaId,jdbcType=INTEGER}, #{parentIds,jdbcType=VARCHAR}, #{parentJson,jdbcType=VARCHAR}, 
      #{name,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, 
      #{master,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{webUrl,jdbcType=VARCHAR}, 
      #{partack,jdbcType=VARCHAR}, #{enabled,jdbcType=VARCHAR}, #{delFlag,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},#{revJson,jdbcType=VARCHAR})
  </insert>
  <insert id="saveSelective" parameterType="com.cloud.model.sys.SysOrganization" >
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into sys_organization
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orgId != null">
        orgId,
      </if>
      <if test="parentId != null">
        parentId,
      </if>
      <if test="headquartersId != null">
        headquartersId,
      </if>
      <if test="areaId != null">
        areaId,
      </if>
      <if test="parentIds != null">
        parentIds,
      </if>
      <if test="parentJson != null">
        parentJson,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="sort != null">
        sort,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="address != null">
        address,
      </if>
      <if test="master != null">
        master,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="webUrl != null">
        webUrl,
      </if>
      <if test="partack != null">
        partack,
      </if>
      <if test="enabled != null">
        enabled,
      </if>
      <if test="delFlag != null">
        delFlag,
      </if>
      <if test="createTime != null">
        createTime,
      </if>
      <if test="updateTime != null">
        updateTime,
      </if>
      <if test="revJson != null">
        revJson,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orgId != null">
        #{orgId,jdbcType=INTEGER},
      </if>
      <if test="parentId != null">
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="headquartersId != null">
        #{headquartersId,jdbcType=INTEGER},
      </if>
      <if test="areaId != null">
        #{areaId,jdbcType=INTEGER},
      </if>
      <if test="parentIds != null">
        #{parentIds,jdbcType=VARCHAR},
      </if>
      <if test="parentJson != null">
        #{parentJson,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="master != null">
        #{master,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="webUrl != null">
        #{webUrl,jdbcType=VARCHAR},
      </if>
      <if test="partack != null">
        #{partack,jdbcType=VARCHAR},
      </if>
      <if test="enabled != null">
        #{enabled,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="revJson != null">
        #{revJson,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="update" parameterType="com.cloud.model.sys.SysOrganization">
    update sys_organization
    <set>
      <if test="orgId != null">
        orgId = #{orgId,jdbcType=INTEGER},
      </if>
      <if test="parentId != null">
        parentId = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="headquartersId != null">
        headquartersId = #{headquartersId,jdbcType=INTEGER},
      </if>
      <if test="areaId != null">
        areaId = #{areaId,jdbcType=INTEGER},
      </if>
      <if test="parentIds != null">
        parentIds = #{parentIds,jdbcType=VARCHAR},
      </if>
      <if test="parentJson != null">
        parentJson = #{parentJson,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="master != null">
        master = #{master,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="webUrl != null">
        webUrl = #{webUrl,jdbcType=VARCHAR},
      </if>
      <if test="partack != null">
        partack = #{partack,jdbcType=VARCHAR},
      </if>
      <if test="enabled != null">
        enabled = #{enabled,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null">
        delFlag = #{delFlag,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        createTime = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        updateTime = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="revJson != null">
        revJson = #{revJson,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
      <if test="orgId != null">
            and orgId=#{orgId}
      </if>
  </update>
 
    <sql id="where">
        <where>
            <if test="orgId != null and orgId != ''">
                orgId = #{orgId,jdbcType=INTEGER},
            </if>
            <if test="parentId != null and parentId != ''">
                parentId = #{parentId,jdbcType=INTEGER},
            </if>
            <if test="headquartersId != null and headquartersId != ''">
                headquartersId = #{headquartersId,jdbcType=INTEGER},
            </if>
            <if test="areaId != null and areaId != ''">
                areaId = #{areaId,jdbcType=INTEGER},
            </if>
            <if test="name != null and name != ''">
                name like concat('%', #{name}, '%'),
            </if>
            <if test="type != null and type != ''">
                type = #{type,jdbcType=VARCHAR},
            </if>
            <if test="partack != null and partack != ''">
                partack = #{partack,jdbcType=VARCHAR},
            </if>
            <if test="enabled != null and enabled != ''" >
                enabled = #{enabled,jdbcType=VARCHAR},
            </if>
            <if test="delFlag != null">
                delFlag = #{delFlag,jdbcType=VARCHAR},
            </if>
        </where>
    </sql>
    <select id="findPageByParams" resultType="com.cloud.model.sys.SysOrganization">
        select * from sys_organization t
        <include refid="where" />
        order by t.id desc
        <if test="start != null and start >= 0 and length != null and length > 0">
            limit #{start}, #{length}
        </if>
    </select>
    <select id="count" resultType="int">
        select count(*) from sys_organization t
        <include refid="where" />
    </select>
 
 
    <!--findCurentParentIds查找组织机构的父集集合-->
    <select id="findCurentParentIds" resultType="String">
      select parentIds from sys_organization where id = #{currentId} and delFlag = '0' /*wp 2018-12-08添加 删除不查*/
      <if test="orgId != null and orgId != ''">
        and orgId = #{orgId}
      </if>
    </select>
 
    <!--查找上级第一个机构(机构类型)-->
    <select id="findUpById" resultMap="BaseMessageMap">
        SELECT
              <include refid="Base_Message_List" />
        FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%') AND t.partack = #{partack}
        ORDER BY parentIds DESC limit 1
    </select>
 
    <!--查找上级第一个指定的机构类型-->
    <select id="findUpByType" resultMap="BaseMessageMap">
        SELECT
              <include refid="Base_Message_List" />
        FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%') AND t.type = #{type}
              <if test="orgId != null and orgId != ''">
                 and orgId = #{orgId}
             </if>
    </select>
 
  <!--查找下级的指定类型的所有机构-->
  <select id="findDownByType" resultMap="BaseMessageMap">
      SELECT
            <include refid="Base_Message_List" />
      FROM sys_organization WHERE parentIds LIKE '%${parentIds}%' and delFlag = '0' /*wp 2018-12-08添加 删除不查*/
          <if test="type != '' and type != null">
            AND type = #{type}
          </if>
           <if test="orgId != null and orgId != ''">
             and orgId = #{orgId}
           </if>
      order by name asc
  </select>            <!-- 王鹏 和金尔松 修改 排序 -->
 
  <!--查找下级的指定类型的所有机构id集合-->
  <select id="findDownByOffIds" resultType="int">
    SELECT
      id
    FROM sys_organization WHERE parentIds LIKE '%${parentIds}%'
    <if test="type != '' and type != null">
      AND type = #{type}
    </if>
    <if test="orgId != null and orgId != ''">
      and orgId = #{orgId}
    </if>
  </select>
 
  <select id="findCheckSchool" resultType="map">
    SELECT id,name,address,revJson
    FROM sys_organization WHERE delFlag = 0 and parentIds LIKE '%${parentIds}%' AND
    type in <foreach collection="type" item="typeId" open="(" separator="," close=")">
                  #{typeId}
             </foreach>
    <if test="searchName != null and searchName != ''">
      and name like '%${searchName}%'
    </if>
    ORDER BY name DESC
  </select>
 
  <!---->
  <select id="finCurentOrgs" resultType="String">
    SELECT
      name
    FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%')
      <if test="orgId != null and orgId != ''">
      and orgId = #{orgId}
      </if>
      ORDER  by TYPE
  </select>
 
  <!--根据orgId 得到所有父节点的name,按照指定分隔符分隔-->
  <select id="getParentNames" resultType="String">
    SELECT
    GROUP_CONCAT(name SEPARATOR #{separator})
    FROM sys_organization t WHERE #{parentIds} LIKE CONCAT('',parentIds,'%')
    <if test="orgId != null and orgId != ''">
      and orgId = #{orgId}
    </if>
    and delFlag = 0 and enabled = 0
  </select>
 
 
 
  <select id="findHeadquarters" resultType="com.cloud.model.sys.SysOrganization">
    select
    <include refid="Base_Column_List" />
    from sys_organization t
    <if test="type != null and type != ''">
      where type = #{type}
    </if>
    <if test="currentId != null and currentId != ''">
      and parentIds like concat('%,',#{currentId},',%')
    </if>
  </select>
 
  <select id="findSubOrg" resultType="com.cloud.model.sys.SysOrganization">
    select
    <include refid="Base_Column_List" />
    from sys_organization where headquartersId = #{headId}
    <if test="isSelf == false and type != null and type != ''" >
      and type != #{type}
    </if>
  </select>
 
  <!--验证此部门是否是班级-->
  <select id="isImportStudentClass" resultType="boolean" parameterType="map">
    select type = #{type} from sys_organization where id = #{officeId}
  </select>
 
  <!--验证此部门是否是学校或者部门-->
  <select id="isisImportTeacherOffice" resultType="map" parameterType="map">
    select type = #{schoolValue} as isSchool,type = #{compactValue} as isCompact from sys_organization where id = #{officeId}
  </select>
 
  <!--查找部门名称-->
  <select id="findCompactName" resultType="String">
    select name from sys_organization where id = #{officeId}
  </select>
 
  <select id="findOrgIds" resultType="java.lang.Integer" parameterType="map">
    select id from sys_organization where #{parentIds} LIKE CONCAT('',parentIds,'%')
    AND type in <foreach collection="types" open="(" separator="," close=")" item="value">
                        #{value}
                  </foreach>
  </select>
 
  <select id="findOrgName" parameterType="Integer" resultType="String">
    SELECT name from sys_organization WHERE delFlag = '0' and id = #{id}
  </select>
  <!--新建组织机构时查询当前机构下是否有重名机构-->
  <select id="isRepeatOrgName" resultType="Integer">
    SELECT count(*) from sys_organization WHERE parentId = #{parentId} and name = #{name}  and  delFlag = '0'
  </select>
 
</mapper>