管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-03-15 5f4c969ad23c5ec9b6e16051add5c20e63f8284a
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
<?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.lf.server.mapper.show.OneMapMapper">
    <resultMap type="com.lf.server.entity.show.OneMapEntity" id="OneMapResult">
        <result property="value" column="value" />
        <result property="key" column="key" />
    </resultMap>
 
    <!--  项目类别 select * from bs.bs_project;  -->
    <select id="projectCategoryCount" resultType="java.util.Map">
        select projtype,count(*) from bs.bs_project group by projtype;
    </select>
 
    <!--  项目位置分布 select a.*,st_astext(geom) from bs.bs_project a  -->
    <select id="projectLocationCount" resultType="java.util.Map">
        select a.*,st_astext(geom) AS wkt from bs.bs_project a;
    </select>
 
    <!-- 全球 项目类别 国家维度-数量  -->
    <select id="countryDimensionCount" resultType="java.util.Map">
        select country,count(*) from bs.bs_project group by country;
    </select>
 
    <!-- 全国 项目类别 省维度-数量  -->
    <select id="provinceDimensionCount" resultType="java.util.Map">
        select province,count(*) from bs.bs_project where country like '%中国%' group by province ;
    </select>
 
    <!-- 全国 按照项自类型统计不同项目个数  -->
    <select id="countProjectTypeNumber" resultType="java.util.Map">
        select projtype,count(*) from bs.bs_project where country like '%中国%' group by projtype ;
    </select>
 
    <!--  数据统计 数据存储  -->
    <select id="dataStorageCount" resultType="java.util.Map">
        select name "名称", (select count(*) from lf.sys_meta b where b.dircode like a.code || '%') "文件数",
               (select sum(sizes) from lf.sys_meta b where b.dircode like a.code || '%') "数量(MB)"
        from lf.sys_dir a where id > 1 and pid = 0;
    </select>
 
    <!--  数据大类统计  -->
    <select id="statisticalDataCategories" resultType="java.util.Map">
        SELECT name,
               (SELECT count(b.id)
                FROM lf.sys_meta b
                WHERE dircode similar to '(' ||
        (SELECT string_agg(code,
         '|')
        FROM lf.sys_dir c
        WHERE c.name = a.name) || ')%') "count",
        (SELECT coalesce(sum(b.sizes),
            0)
        FROM lf.sys_meta b
        WHERE dircode similar to '(' ||
            (SELECT string_agg(code,
            '|')
            FROM lf.sys_dir c
            WHERE c.name = a.name) || ')%') "sizes"
        FROM lf.sys_dir a
        WHERE name IN ('基础测绘', '基础地灾', '基础勘察', '合规数据', '管理数据', '测绘(ESV)', '勘察(EGE)', '地灾(EGD)', '洞库(EGD)')
        GROUP BY  name
        ORDER BY  name;
    </select>
 
    <!--  统计数据服务类型  -->
    <select id="statisticalDataServiceType" resultType="java.util.Map">
        SELECT COUNT(*),TYPE FROM lf.sys_serve_log GROUP BY TYPE;
    </select>
 
    <!-- 登录次数统计 -->
    <select id="loginNumberStatistics" resultType="java.util.Map">
        select b.uname, count(*) from lf.sys_login a inner join lf.sys_user b on a.userid = b.id group by uname;
    </select>
 
    <!-- 数据统计 文件格式维度-文件个数 select type,count(*),count(sizes) from lf.sys_meta group by type; -->
    <select id="fileFormatCount" resultType="java.util.Map">
        select type,count(type) AS number,sum(sizes) AS capacity from lf.sys_meta group by type;
    </select>
 
    <!-- 数据统计 数据申请 select * from lf.sys_apply a inner join lf.sys_user b on a.userid = b.id; -->
    <select id="dataApplyCount" resultType="java.util.Map">
        SELECT
            count(c.name) AS number,
            c.name
        FROM
            lf.sys_apply a
                INNER JOIN lf.sys_user b ON a.userid = b.id
                INNER JOIN lf.sys_dep c ON b.depid = c.id
        GROUP BY
            c.name;
    </select>
 
    <!--  数据统计 访问统计  -->
    <select id="dataVisitCount" resultType="java.util.Map">
        select modular1,count(*) from lf.sys_operate group by modular1 order by modular1;
    </select>
 
    <!--  数据统计 下载量统计 type类型:1-Shp文件,2-专题图,3-元数据,4-业务数据,5-管道分析,6-统计报告 -->
    <!--  数据统计 select type,count(*) from lf.sys_download group by type; -->
    <select id="countDownloads" resultType="java.util.Map">
        SELECT type,
               count(*),
               case type
                   WHEN '1' THEN 'Shp文件'
                   WHEN '2' THEN '专题图'
                   WHEN '3' THEN '元数据'
                   WHEN '4' THEN '业务数据'
                   WHEN '5' THEN '管道分析'
                   WHEN '6' THEN '统计报告'
                   ELSE '0'
                   END as typename
        FROM
            lf.sys_download GROUP BY type;
    </select>
 
    <!--  统计项目显示  -->
    <select id="countProjectDisplay" resultType="java.util.Map">
        select PROJNAME,* from bs.bs_project WHERE PROJNAME IS NOT NULL;
    </select>
 
    <!--  工程巡视  -->
    <select id="countProjectTour" resultType="java.util.Map">
        SELECT st_astext(geom) AS wkt,* FROM bs.m_pipeline
        <where>
            <if test="pipename != null and pipename != ''">
                pipename = #{pipename}
            </if>
        </where>
    </select>
 
    <!--  工程巡视列表  -->
    <select id="selectProjectTour" resultType="java.util.Map">
        SELECT DISTINCT pipename  FROM bs.m_pipeline;
    </select>
 
    <!--  统计项目类型 1  -->
    <!-- select (select string_agg(code, ',') from lf.sys_dir where name = a.name) "key", name "value" from lf.sys_dir a
    where name in ('测绘(ESV)', '勘察(EGE)', '地灾(EGD)', '洞库(EGD)') group by name order by name;-->
    <select id="selectProjectType1"  resultMap="OneMapResult">
        SELECT
            (SELECT string_agg(code,
                               ',')
             FROM lf.sys_dir
             WHERE name = a.name) "key", name "value"
        FROM lf.sys_dir a
        WHERE name IN ('基础地灾', '基础勘察', '合规数据', '管理数据', '勘察(EGE)', '地灾(EGD)', '洞库(EGD)')
        GROUP BY  name
        ORDER BY  key;
    </select>
 
    <!--  统计项目类型 2  -->
    <select id="selectProjectTypeOne"   resultType="com.lf.server.entity.show.OneMapEntity">
        select * from lf.sys_meta ${endSql}
    </select>
 
    <!--  统计项目类型 2  -->
    <select id="selectProjectType2"   resultType="com.lf.server.entity.show.OneMapEntity">
        select modular1,count(*) from lf.sys_operate group by modular1 order by modular1;
    </select>
 
    <!--  查询表信息  -->
    <select id="queryTableInfo" resultType="java.util.Map">
        SELECT a.attnum,
               a.attname,
               concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod)
                                                FROM '\(.*\)')) AS type,d.description,typnotnull
        FROM pg_class c,pg_attribute a,pg_type t,pg_description d
        WHERE c.relname= '${tableName}'
          AND a.attnum>0
          AND a.attrelid=c.oid
          AND a.atttypid=t.oid
          AND d.objoid=a.attrelid
          AND d.objsubid=a.attnum;
    </select>
 
    <!--  统计计算全球管道图  -->
    <select id="countGlobalPipeMap" resultType="java.util.Map">
        SELECT projname,count(*) AS count FROM  bs.m_pipesegment group by projname ;
    </select>
 
    <!--  统计计算全国管道图  -->
    <select id="countNationalPipeMap" resultType="java.util.Map">
        SELECT projname,count(*) AS count FROM  bs.m_pipesegment group by projname ;
    </select>
 
    <!--  统计全国管网图输送介质长度  -->
    <!--select id="countZhPipeMapLenByMed" resultType="java.util.Map">
        SELECT medium AS type,count(*) AS count,sum(length)AS length FROM bs.m_pipesegment GROUP BY medium ;
    </select-->
    <select id="countZhPipeMapLenByMed" resultType="java.util.Map">
        select case medium when 'CO' then '原油' when 'RP' then '成品油' when 'GS' then '天然气' else '其它' end "type",
            count(*) "count", round(sum(ST_Length(geom)::numeric), 2) "length"
        from bs.m_pipeline
        group by medium;
    </select>
 
    <!--  统计全国站场座数、阀室、管道数量  -->
    <select id="countZhPipeStations" resultType="java.util.Map">
        select
            case medium when 'CO' then '原油' when 'RP' then '成品油' when 'GS' then '天然气' else '其它' end "输送介质",
            round(sum(st_length(geom))::numeric, 2) "总里程",
            count(*) "管道数量",
            (select count(*) from bs.m_sitepoint b inner join bs.m_pipeline c on b.pipename = c.pipename where c.medium = a.medium) "站场数量",
            (select count(*) from bs.m_valvehousepoint d inner join bs.m_pipeline e on d.pipename = e.pipename where e.medium = a.medium) "阀室数量"
        from bs.m_pipeline a
        group by medium;
    </select>
 
    <!--  按项目统计项目存储量  -->
    <select id="countStorageByProject" resultType="java.util.Map">
        with rs as (
            select a.dircode, c.dcount, c.sizes
            from lf.sys_meta a
                     inner join lf.sys_meta_down b on a.id = b.metaid
                     inner join lf.sys_download c on b.downid = c.id
        )
        select
            d.name "项目名称",
            (select count(*) from rs where rs.dircode like d.code || '%') "下载个数",
            (select coalesce(sum(rs.dcount), 0) from rs where rs.dircode like d.code || '%') "下载数量",
            (select round(coalesce(sum(rs.dcount * rs.sizes), 0)::numeric, 3) from rs where rs.dircode like d.code || '%') "数量总量(MB)"
        from lf.sys_dir d
        where pid = 0 order by d.code;
    </select>
 
    <!--  查询项目信息 select PROJNAME,* from bs.bs_project WHERE PROJNAME LIKE '${projectName}%' AND PROJNAME IS NOT NULL ; -->
    <select id="selectProjectInfo" resultType="java.util.Map">
        select PROJNAME,* from bs.bs_project WHERE dirid LIKE '${projectCode}%' AND PROJNAME IS NOT NULL ;
    </select>
 
    <select id="selectProjectInfo1" resultType="java.util.Map">
        select PROJNAME,* from bs.bs_project
        <where>
            <if test="projname != null  and projname != ''"> and projname like concat('%', #{projectName}, '%')</if>
        </where>
        AND PROJNAME IS NOT NULL ;
    </select>
 
    <!--  查询项目文件列表 -->
    <select id="selectProjectFileList" resultType="java.util.Map">
        select name, code,st_astext(b.geom) AS wkt
        from lf.sys_dir a inner join bs.bs_project b on a.code = b.dirid
        where pid = 0 and id > 1 order by code;
    </select>
 
    <select id="countProjectStorage" resultType="java.util.Map">
        select name,
               (select count(b.id) from lf.sys_meta b where dircode similar to '(' || (select string_agg(code, '|') from lf.sys_dir c where c.name = a.name) || ')%') "count",
 (select coalesce(sum(b.sizes), 0) from lf.sys_meta b where dircode similar to '(' || (select string_agg(code, '|') from lf.sys_dir c where c.name = a.name) || ')%') "sizes"
        from lf.sys_dir a
        where code like '${projectCode}%' and name in ('基础测绘', '基础地灾', '基础勘察', '合规数据', '管理数据', '测绘(ESV)', '勘察(EGE)', '地灾(EGD)', '洞库(EGD)')
        group by name
        order by name;
    </select>
 
    <!--  单个项目文件数量-->
    <select id="countProjectType" resultType="java.util.Map">
        SELECT a.type,
               count(a.type) AS number,
               coalesce( cast(sum(a.sizes) as decimal(20, 2) ), 0)  AS capacity
        FROM lf.sys_meta a
                 INNER JOIN lf.sys_dir b ON a.dircode = b.code
        WHERE a.dircode LIKE '${projectCode}%'
        GROUP BY a.type;
    </select>
 
    <!--  单个项目的下载个数、下载次数和数据量-->
    <!--  select count(*) "number", sum(c.dcount) "count", sum(c.sizes) "size"
            from lf.sys_meta a inner join lf.sys_meta_down b on a.id = b.metaid
                               inner join lf.sys_download c on b.downid = c.id
            where dircode like '${projectCode}%';  -->
    <select id="countProjectDown" resultType="java.util.Map">
        select
            d.name "项目名称",
            (select count(*) "number"
             from lf.sys_meta a inner join lf.sys_meta_down b on a.id = b.metaid
                                inner join lf.sys_download c on b.downid = c.id
             where dircode like '${projectCode}%') "下载个数",
            (select  sum(c.dcount) "count"
             from lf.sys_meta a inner join lf.sys_meta_down b on a.id = b.metaid
                                inner join lf.sys_download c on b.downid = c.id
             where dircode like '${projectCode}%') "下载数量",
            (select  sum(c.sizes) "size"
             from lf.sys_meta a inner join lf.sys_meta_down b on a.id = b.metaid
                                inner join lf.sys_download c on b.downid = c.id
             where dircode like '${projectCode}%') "数量总量(MB)"
        from lf.sys_dir d
        where pid = 0 AND d.code like '${projectCode}%'
    </select>
 
    <!-- 按大类统计 -->
    <select id="countByMajor" resultType="com.lf.server.entity.ctrl.CountEntity">
        select '测绘(ESV)' "m1", '数字线划图' "m2", '平方千米' "m3", cast( coalesce(sum(area), 0) / 1000000 as decimal(20, 2) ) "sizes" from lf.sys_line_buffer
        union all
        select '测绘(ESV)' "m1", '数字正射影像图' "m2", '平方千米' "m3", (
            select cast( coalesce(sum(b.area), 0) / 1000000 as decimal(20, 2)) from lf.sys_meta b
            inner join lf.sys_dir c on b.dircode = c.code
            where c.name = '数字正射影像图' and b.type in ('img', 'tif', 'tiff') ) "sizes"
        union all
        select '测绘(ESV)' "m1", '管线数据' "m2", '千米' "m3",
            cast( coalesce(sum( ST_Length( ST_GeographyFromText( ST_AsText(geom) ) ) ) / 1000, 0) as decimal(20, 2) ) "sizes" from bs.m_pipeline
        union all
        select '勘察(EGE)' "m1", '勘探点' "m2", '个' "m3", count(*) "sizes" from bs.s_explorationpoint
        union all
        select '勘察(EGE)' "m1", '三维地质模型' "m2", '平方千米' "m3", (
            select cast( coalesce(sum(b.area), 0) / 1000000 as decimal(20, 2))
            from lf.sys_meta b
            where b.type in ('fbx', 'ifc') ) "sizes"
        union all
        select '地灾(EGD)' "m1", '地灾点' "m2", '个' "m3", count(*) "sizes" from bd.b_geologic_hazard;
    </select>
 
    <!-- 查询中线缓冲区 -->
    <select id="selectLineBuffer" resultType="java.lang.Integer">
        select fn_line_buffer();
    </select>
 
    <!-- 根据类型查询元数据(用于计算面积) -->
    <select id="selectMetaByType" resultType="java.util.Map">
        (select a.id, a.path, 'DOM' type from lf.sys_meta a
            inner join lf.sys_dir b on a.dircode = b.code
            where a.area is null and a.type in ('img', 'tif', 'tiff') and b.name = '数字正射影像图')
        union all
        (select a.id, a.path, 'DEM' type from lf.sys_meta a
            inner join lf.sys_dir b on a.dircode = b.code
            where a.area is null and a.type in ('dem', 'tif', 'tiff') and b.name = '数字高程模型')
        union all
        (select id, path, 'OSGB' type from lf.sys_meta where area is null and type = 'osgb')
        union all
        (select id, path, 'LAS' type from lf.sys_meta where area is null and (type = 'las' or type = 'laz'))
        union all
        (select id, path, 'IFC' type from lf.sys_meta where area is null and type = 'ifc')
        union all
        (select id, path, 'FBX' type from lf.sys_meta where area is null and type = 'fbx')
    </select>
</mapper>