forked from gzzfw/backEnd/gz-dyh

huangh
2024-10-28 411ebc9c06c2f987b4d8deb2a9a1496ab39b55ea
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
<?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: wangwh
 * @time:2024-08-27 10:00:57
 * @version 1.0.0
-->
<mapper namespace="cn.huge.module.analysis.dao.mapper.AnalysisMapper">
    <!-- 条件 -->
    <sql id="statisticsAVG-wherePart">
        <if test="terms != null">
            <if test="terms.queProv != null and terms.queProv !=''">
                and t1.que_prov = #{terms.queProv}
            </if>
            <if test="terms.queCity != null and terms.queCity !=''">
                and t1.que_city = #{terms.queCity}
            </if>
            <if test="terms.queArea != null and terms.queArea !=''">
                and t1.que_area = #{terms.queArea}
            </if>
            <if test="terms.queRoad != null and terms.queRoad !=''">
                and t1.que_road = #{terms.queRoad}
            </if>
            <if test="terms.queVillage != null and terms.queVillage !=''">
                and t1.que_village = #{terms.queVillage}
            </if>
            <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                and (DATE_FORMAT(t2.create_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.createStart}
                and DATE_FORMAT(t2.create_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.createEnd})
            </if>
            <if test="terms.handleStart != null and terms.handleStart !='' and terms.handleEnd != null and terms.handleEnd !=''">
                and (DATE_FORMAT(t2.handle_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.handleStart}
                and DATE_FORMAT(t2.handle_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.handleEnd})
            </if>
            <if test="terms.queVillage != null and terms.queVillage !=''">
                and t1.que_village = #{terms.queVillage}
            </if>
            <if test="terms.mediType != null and terms.mediType !=''">
                and medi_type = #{terms.mediType}
            </if>
            <if test="terms.caseTypeFirst != null and terms.caseTypeFirst !=''">
                and case_type_first = #{terms.caseTypeFirst}
            </if>
        </if>
    </sql>
 
    <!--  统计任务平均时长  -->
    <select id="statisticsAVG" resultType="java.lang.Long">
        select AVG(case when (t2.node_id = 'ZJ_DFP' or t2.node_id = 'QJ_DFP' or t2.node_id = 'SJ_DFP' or t2.node_id = 'DFP') then count(usetime_hour) end) as fp,
               AVG(case when (t2.node_id = 'ZJ_DSL' or t2.node_id = 'QJ_DSL' or t2.node_id = 'SJ_DSL' or t2.node_id = 'DSL') then usetime_hour end) as sl,
               AVG(case when (t2.node_id = 'BLFK' and t2.status = '2') then usetime_hour end) as sl,
               count(case when (t2.node_id = 'ZJ_DFP' or t2.node_id = 'QJ_DFP' or t2.node_id = 'SJ_DFP' or t2.node_id = 'DFP') and t2.overtime_status = 1 then overtime_hour end) as fpcs,
               count(case when (t2.node_id = 'ZJ_DSL' or t2.node_id = 'QJ_DSL' or t2.node_id = 'SJ_DSL' or t2.node_id = 'DSL') and t2.overtime_status = 1 then overtime_hour end) as slcs
        from dyh_case_info t1 left join dyh_case_task t2 on t1.id = t2.case_id
        where
            t2.status = 2
        <include refid="statisticsAVG-wherePart"/>
    </select>
 
    <!-- 条件 -->
    <sql id="statisticsApplyAVG-wherePart">
        <if test="terms.queProv != null and terms.queProv !=''">
            and t1.que_prov = #{terms.queProv}
        </if>
        <if test="terms.queCity != null and terms.queCity !=''">
            and t1.que_city = #{terms.queCity}
        </if>
        <if test="terms.queArea != null and terms.queArea !=''">
            and t1.que_area = #{terms.queArea}
        </if>
        <if test="terms.queRoad != null and terms.queRoad !=''">
            and t1.que_road = #{terms.queRoad}
        </if>
        <if test="terms.queVillage != null and terms.queVillage !=''">
            and t1.que_village = #{terms.queVillage}
        </if>
        <if test="terms.queVillage != null and terms.queVillage !=''">
            and t1.que_village = #{terms.queVillage}
        </if>
        <if test="terms.mediType != null and terms.mediType !=''">
            and t1.medi_type = #{terms.mediType}
        </if>
        <if test="terms.caseTypeFirst != null and terms.caseTypeFirst !=''">
            and t1.case_type_first = #{terms.caseTypeFirst}
        </if>
    </sql>
 
    <!--  统计审批平均时长  -->
    <select id="statisticsApplyAVG" resultType="java.lang.Long">
        select select avg(usetime_hour)
        form
        (
        select usetime_hour
        from dyh_case_info t1 left join dyh_case_appear t2 on t1.id = t2.case_id
        where t2.apply_status = 1
        <if test="terms != null">
            <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                and (DATE_FORMAT(t2.appear_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.createStart}
                and DATE_FORMAT(t2.appear_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.createEnd})
            </if>
            <if test="terms.handleStart != null and terms.handleStart !='' and terms.handleEnd != null and terms.handleEnd !=''">
                and (DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.handleStart}
                and DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.handleEnd})
            </if>
            <include refid="statisticsApplyAVG-wherePart"/>
        </if>
        union all
        select usetime_hour
        from dyh_case_info t1 left join dyh_case_assist_apply t2 on t1.id = t2.case_id
        where t2.apply_status = 1
        <if test="terms != null">
            <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                and (DATE_FORMAT(t2.apply_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.createStart}
                and DATE_FORMAT(t2.apply_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.createEnd})
            </if>
            <if test="terms.handleStart != null and terms.handleStart !='' and terms.handleEnd != null and terms.handleEnd !=''">
                and (DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.handleStart}
                and DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.handleEnd})
            </if>
            <include refid="statisticsApplyAVG-wherePart"/>
        </if>
        union all
        select usetime_hour
        from dyh_case_info t1 left join dyh_case_return t2 on t1.id = t2.case_id
        where t2.return_status = 1
        <if test="terms != null">
            <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                and (DATE_FORMAT(t2.return_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.createStart}
                and DATE_FORMAT(t2.return_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.createEnd})
            </if>
            <if test="terms.handleStart != null and terms.handleStart !='' and terms.handleEnd != null and terms.handleEnd !=''">
                and (DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.handleStart}
                and DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.handleEnd})
            </if>
            <include refid="statisticsApplyAVG-wherePart"/>
        </if>
        union all
        select usetime_hour
        from dyh_case_info t1 left join dyh_case_windup_apply t2 on t1.id = t2.case_id
        where t2.apply_status = 1
        <if test="terms != null">
            <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                and (DATE_FORMAT(t2.apply_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.createStart}
                and DATE_FORMAT(t2.apply_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.createEnd})
            </if>
            <if test="terms.handleStart != null and terms.handleStart !='' and terms.handleEnd != null and terms.handleEnd !=''">
                and (DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.handleStart}
                and DATE_FORMAT(t2.audit_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.handleEnd})
            </if>
            <include refid="statisticsApplyAVG-wherePart"/>
        </if>
        )
    </select>
 
    <!-- 条件 -->
    <sql id="statisticsSuperviseAVG-wherePart">
        t2.sup_status = 1
        <if test="terms.queProv != null and terms.queProv !=''">
            and t1.que_prov = #{terms.queProv}
        </if>
        <if test="terms.queCity != null and terms.queCity !=''">
            and t1.que_city = #{terms.queCity}
        </if>
        <if test="terms.queArea != null and terms.queArea !=''">
            and t1.que_area = #{terms.queArea}
        </if>
        <if test="terms.queRoad != null and terms.queRoad !=''">
            and t1.que_road = #{terms.queRoad}
        </if>
        <if test="terms.queVillage != null and terms.queVillage !=''">
            and t1.que_village = #{terms.queVillage}
        </if>
        <if test="terms.queVillage != null and terms.queVillage !=''">
            and t1.que_village = #{terms.queVillage}
        </if>
        <if test="terms.mediType != null and terms.mediType !=''">
            and t1.medi_type = #{terms.mediType}
        </if>
        <if test="terms.caseTypeFirst != null and terms.caseTypeFirst !=''">
            and t1.case_type_first = #{terms.caseTypeFirst}
        </if>
        <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
            and (DATE_FORMAT(t2.sup_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.createStart}
            and DATE_FORMAT(t2.sup_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.createEnd})
        </if>
        <if test="terms.handleStart != null and terms.handleStart !='' and terms.handleEnd != null and terms.handleEnd !=''">
            and (DATE_FORMAT(t2.reply_time,'%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{terms.handleStart}
            and DATE_FORMAT(t2.reply_time,'%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{terms.handleEnd})
        </if>
    </sql>
 
    <!--  统计督办平均时长  -->
    <select id="statisticsSuperviseAVG" resultType="java.lang.Long">
        select usetime_hour
        from dyh_case_info t1 left join dyh_case_supervise t2 on t1.id = t2.case_id
        <include refid="statisticsSuperviseAVG-wherePart"/>
    </select>
 
    <!--  统计重复来访案件数量  -->
    <select id="countRepeatedCases" resultType="cn.huge.module.analysis.domain.dto.CountRepeateDto" parameterType="cn.huge.module.analysis.domain.vo.CountRepeateVo">
        WITH RepeatedPersons AS (
        SELECT true_name, mobile, certi_no
        FROM gzdyh_test.dyh_case_person
        WHERE per_type = '15_020008-1'
        AND per_class = '09_01001-1'
        AND certi_type = '09_00015-1'
        GROUP BY true_name, mobile, certi_no
        HAVING COUNT(*) > 1
        ),
        MinCaseIds AS (
        SELECT rp.true_name, rp.mobile, rp.certi_no, MIN(p.case_id) as min_case_id
        FROM RepeatedPersons rp
        JOIN gzdyh_test.dyh_case_person p ON rp.true_name = p.true_name AND rp.mobile = p.mobile AND rp.certi_no = p.certi_no
        GROUP BY rp.true_name, rp.mobile, rp.certi_no
        ),
        FilteredCases AS (
        SELECT p.case_id
        FROM gzdyh_test.dyh_case_person p
        JOIN RepeatedPersons rp ON p.true_name = rp.true_name AND p.mobile = rp.mobile AND p.certi_no = rp.certi_no
        JOIN MinCaseIds mci ON rp.true_name = mci.true_name AND rp.mobile = mci.mobile AND rp.certi_no = mci.certi_no
        WHERE p.case_id != mci.min_case_id
        )
        SELECT
        <if test="groupByCaseType != null and groupByCaseType != ''">
            case_type_first_name as groupByType,
        </if>
        <if test="groupByArea != null and groupByArea != ''">
            area_name as groupByType,
        </if>
        <if test="groupByRoad != null and groupByRoad != ''">
            road_name as groupByType,
        </if>
        <if test="groupByTime != null and groupByTime != ''">
            <if test="groupByTime == 'day'">
                DATE_FORMAT(ci.create_time, '%Y-%m-%d') as groupByType,
            </if>
            <if test="groupByTime == 'month'">
                DATE_FORMAT(ci.create_time, '%Y-%m') as groupByType,
            </if>
            <if test="groupByTime == 'year'">
                DATE_FORMAT(ci.create_time, '%Y') as groupByType,
            </if>
        </if>
        COUNT(DISTINCT fc.case_id) as repeatCount
        FROM FilteredCases fc
        JOIN gzdyh_test.dyh_case_info ci ON fc.case_id = ci.id
        JOIN gzdyh_test.dyh_case_info_unfold cui ON ci.id = cui.id
        JOIN gzdyh_test.dyh_ct_unit unit ON cui.mediate_unit_id = unit.id
        WHERE 1=1
        <if test="createTimeStart != null and createTimeStart != '' and createTimeEnd != null and createTimeEnd != ''">
            AND ci.create_time BETWEEN #{createTimeStart} AND #{createTimeEnd}
        </if>
        <if test="queCity != null and queCity != ''">
            AND unit.city = #{queCity}
        </if>
        <if test="queArea != null and queArea != ''">
            AND unit.area = #{queArea}
        </if>
        <if test="queRoad != null and queRoad != ''">
            AND unit.road = #{queRoad}
        </if>
        <if test="groupByCaseType != null and groupByCaseType != ''">
            GROUP BY case_type_first_name
        </if>
        <if test="groupByArea != null and groupByArea != ''">
            GROUP BY area_name
        </if>
        <if test="groupByRoad != null and groupByRoad != ''">
            GROUP BY road_name
        </if>
        <if test="groupByTime != null and groupByTime != ''">
            GROUP BY  groupByType
        </if>
    </select>
 
</mapper>