广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
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
<?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">
<!-- 
 * @title: 客户组织信息表
 * @description: 自定义sql,请自行实现业务逻辑
 * @company: hugeinfo
 * @author: liyj
 * @time:2024-10-17 16:41:35
 * @version 1.0.0
-->
<mapper namespace="cn.huge.module.ctuser.dao.mapper.CtUnitMapper">
    <!-- 结果集 -->
    <resultMap id="dataResult" type="cn.huge.module.ctuser.domain.po.CtUnit">
            <result property="id" column="id"/>
            <result property="level" column="level"/>
            <result property="parentId" column="parent_id"/>
            <result property="unitGrade" column="unit_grade"/>
            <result property="unitName" column="unit_name"/>
            <result property="unitType" column="unit_type"/>
            <result property="unitCode" column="unit_code"/>
            <result property="unitDes" column="unit_des"/>
            <result property="dutyName" column="duty_name"/>
            <result property="dutyMobile" column="duty_mobile"/>
            <result property="dutyIdcard" column="duty_idcard"/>
            <result property="joinWay" column="join_way"/>
            <result property="prov" column="prov"/>
            <result property="provName" column="prov_name"/>
            <result property="city" column="city"/>
            <result property="cityName" column="city_name"/>
            <result property="area" column="area"/>
            <result property="areaName" column="area_name"/>
            <result property="road" column="road"/>
            <result property="roadName" column="road_name"/>
            <result property="village" column="village"/>
            <result property="villageName" column="village_name"/>
            <result property="addr" column="addr"/>
            <result property="lng" column="lng"/>
            <result property="lat" column="lat"/>
            <result property="goodField" column="good_field"/>
            <result property="goodFieldName" column="good_field_name"/>
            <result property="canField" column="can_field"/>
            <result property="canFieldName" column="can_field_name"/>
            <result property="findStatus" column="find_status"/>
            <result property="dispStatus" column="disp_status"/>
            <result property="deleteStatus" column="delete_status"/>
            <result property="custId" column="cust_id"/>
            <result property="createTime" column="create_time"/>
            <result property="updateTime" column="update_time"/>
            <result property="postalCode" column="postal_code"/>
            <result property="telephone" column="telephone"/>
            <result property="workTimeWeek" column="work_time_week"/>
            <result property="workTimeAm" column="work_time_am"/>
            <result property="workTimePm" column="work_time_pm"/>
            <result property="unitFun" column="unit_fun"/>
            <result property="courtStatus" column="court_status"/>
    </resultMap>
    <!-- 表 -->
    <sql id='table-name'>dyh_ct_unit</sql>
    <!-- 字段 -->
    <sql id="column-part">
        id,
        level,
        parent_id,
        unit_grade,
        unit_name,
        unit_type,
        unit_code,
        unit_des,
        duty_name,
        duty_mobile,
        duty_idcard,
        join_way,
        prov,
        prov_name,
        city,
        city_name,
        area,
        area_name,
        road,
        road_name,
        village,
        village_name,
        addr,
        lng,
        lat,
        good_field,
        good_field_name,
        can_field,
        can_field_name,
        find_status,
        disp_status,
        delete_status,
        cust_id,
        create_time,
        update_time,
        postal_code,
        telephone,
        work_time_week,
        work_time_am,
        work_time_pm,
        unit_fun,
        court_status
    </sql>
    <!-- 更新实体字段 -->
    <sql id="set-part">
            <if test="entity.level != null">level = #{entity.level},</if>
            <if test="entity.parentId != null">parent_id = #{entity.parentId},</if>
            <if test="entity.unitGrade != null">unit_grade = #{entity.unitGrade},</if>
            <if test="entity.unitName != null">unit_name = #{entity.unitName},</if>
            <if test="entity.unitType != null">unit_type = #{entity.unitType},</if>
            <if test="entity.unitCode != null">unit_code = #{entity.unitCode},</if>
            <if test="entity.unitDes != null">unit_des = #{entity.unitDes},</if>
            <if test="entity.dutyName != null">duty_name = #{entity.dutyName},</if>
            <if test="entity.dutyMobile != null">duty_mobile = #{entity.dutyMobile},</if>
            <if test="entity.dutyIdcard != null">duty_idcard = #{entity.dutyIdcard},</if>
            <if test="entity.joinWay != null">join_way = #{entity.joinWay},</if>
            <if test="entity.prov != null">prov = #{entity.prov},</if>
            <if test="entity.provName != null">prov_name = #{entity.provName},</if>
            <if test="entity.city != null">city = #{entity.city},</if>
            <if test="entity.cityName != null">city_name = #{entity.cityName},</if>
            <if test="entity.area != null">area = #{entity.area},</if>
            <if test="entity.areaName != null">area_name = #{entity.areaName},</if>
            <if test="entity.road != null">road = #{entity.road},</if>
            <if test="entity.roadName != null">road_name = #{entity.roadName},</if>
            <if test="entity.village != null">village = #{entity.village},</if>
            <if test="entity.villageName != null">village_name = #{entity.villageName},</if>
            <if test="entity.addr != null">addr = #{entity.addr},</if>
            <if test="entity.lng != null">lng = #{entity.lng},</if>
            <if test="entity.lat != null">lat = #{entity.lat},</if>
            <if test="entity.goodField != null">good_field = #{entity.goodField},</if>
            <if test="entity.goodFieldName != null">good_field_name = #{entity.goodFieldName},</if>
            <if test="entity.canField != null">can_field = #{entity.canField},</if>
            <if test="entity.canFieldName != null">can_field_name = #{entity.canFieldName},</if>
            <if test="entity.findStatus != null">find_status = #{entity.findStatus},</if>
            <if test="entity.dispStatus != null">disp_status = #{entity.dispStatus},</if>
            <if test="entity.deleteStatus != null">delete_status = #{entity.deleteStatus},</if>
            <if test="entity.custId != null">cust_id = #{entity.custId},</if>
            <if test="entity.createTime != null">create_time = #{entity.createTime},</if>
            <if test="entity.updateTime != null">update_time = #{entity.updateTime},</if>
            <if test="entity.postalCode != null">postal_code = #{entity.postalCode},</if>
            <if test="entity.telephone != null">telephone = #{entity.telephone},</if>
            <if test="entity.workTimeWeek != null">work_time_week = #{entity.workTimeWeek},</if>
            <if test="entity.workTimeAm != null">work_time_am = #{entity.workTimeAm},</if>
            <if test="entity.workTimePm != null">work_time_pm = #{entity.workTimePm},</if>
            <if test="entity.unitFun != null">unit_fun = #{entity.unitFun},</if>
            <if test="entity.courtStatus != null">court_status = #{entity.courtStatus}</if>
    </sql>
    <!-- 条件 -->
    <sql id="where-part">
        <if test="terms != null">
            <where>
                <if test="terms.id != null and terms.id !=''">
                    and id = #{terms.id}
                </if>
                <if test="terms.level != null and terms.level !=''">
                    and level = #{terms.level}
                </if>
                <if test="terms.parentId != null and terms.parentId !=''">
                    and parent_id = #{terms.parentId}
                </if>
                <if test="terms.unitGrade != null and terms.unitGrade !=''">
                    and unit_grade = #{terms.unitGrade}
                </if>
                <if test="terms.unitName != null and terms.unitName !=''">
                    and unit_name = #{terms.unitName}
                </if>
                <if test="terms.unitType != null and terms.unitType !=''">
                    and unit_type = #{terms.unitType}
                </if>
                <if test="terms.unitCode != null and terms.unitCode !=''">
                    and unit_code = #{terms.unitCode}
                </if>
                <if test="terms.unitDes != null and terms.unitDes !=''">
                    and unit_des = #{terms.unitDes}
                </if>
                <if test="terms.dutyName != null and terms.dutyName !=''">
                    and duty_name = #{terms.dutyName}
                </if>
                <if test="terms.dutyMobile != null and terms.dutyMobile !=''">
                    and duty_mobile = #{terms.dutyMobile}
                </if>
                <if test="terms.dutyIdcard != null and terms.dutyIdcard !=''">
                    and duty_idcard = #{terms.dutyIdcard}
                </if>
                <if test="terms.joinWay != null and terms.joinWay !=''">
                    and join_way = #{terms.joinWay}
                </if>
                <if test="terms.prov != null and terms.prov !=''">
                    and prov = #{terms.prov}
                </if>
                <if test="terms.provName != null and terms.provName !=''">
                    and prov_name = #{terms.provName}
                </if>
                <if test="terms.city != null and terms.city !=''">
                    and city = #{terms.city}
                </if>
                <if test="terms.cityName != null and terms.cityName !=''">
                    and city_name = #{terms.cityName}
                </if>
                <if test="terms.area != null and terms.area !=''">
                    and area = #{terms.area}
                </if>
                <if test="terms.areaName != null and terms.areaName !=''">
                    and area_name = #{terms.areaName}
                </if>
                <if test="terms.road != null and terms.road !=''">
                    and road = #{terms.road}
                </if>
                <if test="terms.roadName != null and terms.roadName !=''">
                    and road_name = #{terms.roadName}
                </if>
                <if test="terms.village != null and terms.village !=''">
                    and village = #{terms.village}
                </if>
                <if test="terms.villageName != null and terms.villageName !=''">
                    and village_name = #{terms.villageName}
                </if>
                <if test="terms.addr != null and terms.addr !=''">
                    and addr = #{terms.addr}
                </if>
                <if test="terms.lng != null and terms.lng !=''">
                    and lng = #{terms.lng}
                </if>
                <if test="terms.lat != null and terms.lat !=''">
                    and lat = #{terms.lat}
                </if>
                <if test="terms.goodField != null and terms.goodField !=''">
                    and good_field = #{terms.goodField}
                </if>
                <if test="terms.goodFieldName != null and terms.goodFieldName !=''">
                    and good_field_name = #{terms.goodFieldName}
                </if>
                <if test="terms.canField != null and terms.canField !=''">
                    and can_field = #{terms.canField}
                </if>
                <if test="terms.canFieldName != null and terms.canFieldName !=''">
                    and can_field_name = #{terms.canFieldName}
                </if>
                <if test="terms.findStatus != null and terms.findStatus !=''">
                    and find_status = #{terms.findStatus}
                </if>
                <if test="terms.dispStatus != null and terms.dispStatus !=''">
                    and disp_status = #{terms.dispStatus}
                </if>
                <if test="terms.deleteStatus = null and terms.deleteStatus =''">
                    and delete_status = 0
                </if>
                <if test="terms.deleteStatus != null and terms.deleteStatus !=''">
                    and delete_status = #{terms.deleteStatus}
                </if>
                <if test="terms.custId != null and terms.custId !=''">
                    and cust_id = #{terms.custId}
                </if>
                <if test="terms.createTime != null and terms.createTime !=''">
                    and DATE_FORMAT(create_time,'%Y-%m-%d') = #{terms.createTime}
                </if>
                <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                    and (DATE_FORMAT(create_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.createStart}
                        and DATE_FORMAT(create_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.createEnd})
                </if>
                <if test="terms.updateTime != null and terms.updateTime !=''">
                    and DATE_FORMAT(update_time,'%Y-%m-%d') = #{terms.updateTime}
                </if>
                <if test="terms.updateStart != null and terms.updateStart !='' and terms.updateEnd != null and terms.updateEnd !=''">
                    and (DATE_FORMAT(update_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.updateStart}
                        and DATE_FORMAT(update_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.updateEnd})
                </if>
                <if test="terms.postalCode != null and terms.postalCode !=''">
                    and postal_code = #{terms.postalCode}
                </if>
                <if test="terms.telephone != null and terms.telephone !=''">
                    and telephone = #{terms.telephone}
                </if>
                <if test="terms.workTimeWeek != null and terms.workTimeWeek !=''">
                    and work_time_week = #{terms.workTimeWeek}
                </if>
                <if test="terms.workTimeAm != null and terms.workTimeAm !=''">
                    and work_time_am = #{terms.workTimeAm}
                </if>
                <if test="terms.workTimePm != null and terms.workTimePm !=''">
                    and work_time_pm = #{terms.workTimePm}
                </if>
                <if test="terms.unitFun != null and terms.unitFun !=''">
                    and unit_fun = #{terms.unitFun}
                </if>
                <if test="terms.courtStatus != null and terms.courtStatus !=''">
                    and court_status = #{terms.courtStatus}
                </if>
            </where>
        </if>
    </sql>
    <!-- 更新对象 -->
    <update id="updateCtUnit">
        update
        <include refid="table-name"/>
        <set>
            <include refid="set-part"/>
        </set>
        <where>
            id = #{entity.id}
        </where>
    </update>
    <!-- 条件更新对象 -->
    <update id="updateCtUnitTerms">
        update
        <include refid="table-name"/>
        <set>
            <include refid="set-part"/>
        </set>
        <include refid="where-part"/>
    </update>
    <!--  根据编号物理删除  -->
    <delete id="deleteCtUnit">
        delete from
        <include refid="table-name" />
        where id = #{id}
    </delete>
    <!--  根据条件查询  -->
    <select id="listTerms" resultMap="dataResult">
        select
        <include refid="column-part"/>
        from
        <include refid="table-name" />
        <include refid="where-part"/>
    </select>
    <!--  根据条件统计  -->
    <select id="countTerms" resultType="java.lang.Long">
        select
        COUNT(1)
        from
        <include refid="table-name" />
        <include refid="where-part"/>
    </select>
    <!--  根据条件分页查询  -->
    <select id="pageTerms" resultMap="dataResult">
        SELECT
        <include refid="column-part"/>
        FROM
        <include refid="table-name" />
        <include refid="where-part"/>
        <if test="page.sort != null">
            <foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
                isnull(${s.property}), ${s.property} ${s.direction}
            </foreach>
        </if>
        <if test="page.sort == null">
            order by isnull(create_time), create_time desc
        </if>
        limit #{page.offset}, #{page.size}
    </select>
 
    <!--  更新对象  -->
    <update id="updateTerms">
        update
        <include refid="table-name"/>
        <set>
            <include refid="set-part"/>
        </set>
        WHERE
        id = #{entity.id}
    </update>
 
    <!--  更新调度规则指标目标组织名称  -->
    <update id="updateDispNormCauseTargetUnitName">
        update dyh_disp_norm_cause
        set target_unit_name = #{unitName}
        where target_unit_id = #{unitId}
    </update>
 
    <!-- 查询某一单位下下一级所有管辖单位-->
    <select id="listAllChild" resultMap="dataResult">
        WITH RECURSIVE unit_hierarchy(id, parent_id, name) AS (
        -- 锚成员 (起始点)
        SELECT
        id ,
        parent_id,
        unit_name
        FROM
        dyh_ct_unit
        WHERE
        id = #{unitId}
 
        UNION ALL
 
        -- 递归成员
        SELECT
        u.id,
        u.parent_id,
        u.unit_name
        FROM
        dyh_ct_unit u
        JOIN
        unit_hierarchy h ON u.parent_id = h.id where u.delete_status = 0
        )
        SELECT
        id AS id,
        parent_id AS parent_id,
        name AS unit_name
        FROM
        unit_hierarchy;
    </select>
 
    <!--  根据条件分页查询  -->
    <select id="selectUnitByGridId" resultMap="dataResult">
        SELECT
            t1.*
        FROM dyh_ct_unit t1 left join dyh_th_grid_unit t2 on t1.id = t2.dyh_unit_id
        where t2.third_unit_id = #{gridUnitId} limit 1
    </select>
 
    <!-- SelectTermDTO结果集 -->
    <resultMap id="selectTermDTO" type="cn.huge.base.common.dto.SelectTermDTO">
        <result property="label" column="label"/>
        <result property="value" column="value"/>
        <result property="parentId" column="parentId"/>
    </resultMap>
    <!--  查询所有单位的树形结构  -->
    <select id="listUnitSelectTerm" resultMap="selectTermDTO">
        SELECT id AS value, unit_name AS label, parent_id AS parentId
        FROM dyh_ct_unit
        WHERE delete_status = 0
    </select>
 
    <!--  查询法院结构  -->
    <select id="listCourt" resultMap="selectTermDTO">
        SELECT
        id AS value,
        unit_name AS label
        FROM
        <include refid="table-name" />
        WHERE
        unit_type = '104'
        AND delete_status = 0
<!--        <if test="terms.city != null and terms.city !=''">-->
<!--            and city = #{terms.city}-->
<!--        </if>-->
        <if test="terms.area != null and terms.area !=''">
            and area = #{terms.area}
        </if>
    </select>
</mapper>