管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-12-20 f31782b273aeb8752b25d5467502e8ea38e083c7
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
package com.lf.server.service.show;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.mapper.all.GeomBaseMapper;
import com.lf.server.service.all.BaseQueryService;
import com.lf.server.service.data.DownloadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 资料馆
 * @author WWW
 */
@Service
public class DataLibService {
    @Autowired
    PathHelper pathHelper;
 
    @Autowired
    BaseQueryService baseQueryService;
 
    @Autowired
    DownloadService downloadService;
 
    /**
     * 创建Zip包
     */
    public String createZipFile(UserEntity ue, List<String> entities, String wkt, String pwd) {
        Map<String, List<?>> map = queryData(entities, wkt);
        if (map.size() == 0) {
            return null;
        }
 
        //String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        //String tempPath = pathHelper.getTempPath(tempName);
        //String filePath = tempPath + File.separator + tempName + ".gdb";
 
        String filePath = "D:\\LF\\temp\\20221219202706\\20221219202705.gdb";
        File file = new File(filePath);
        if (!file.exists() || !file.isDirectory()) {
            file.mkdirs();
        }
 
        filePath = "D:\\LF\\temp\\20221219202706\\2022.gdb";
        if (file.exists() && file.isDirectory()) {
            FileHelper.deleteDir(filePath);
        }
        GdbHelper.createGdb(filePath, map);
 
        return null;
    }
 
    /**
     * 查询数据
     */
    private Map<String, List<?>> queryData(List<String> entities, String wkt) {
        Map<String, List<?>> map = new HashMap<>(5);
        for (String enity : entities) {
            try {
                GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(enity);
                if (null == baseMapper) {
                    continue;
                }
 
                QueryWrapper wrapper = createWrapper(baseMapper, wkt);
                List<?> list = baseMapper.selectList(wrapper);
                if (null == list || list.size() == 0) {
                    continue;
                }
 
                if (!map.containsKey(enity)) {
                    map.put(enity, list);
                }
            } catch (Exception ex) {
                //
            }
        }
 
        return map;
    }
 
    /**
     * 创建QueryWrapper
     */
    private QueryWrapper createWrapper(GeomBaseMapper baseMapper, String wkt) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.select("ST_AsText(geom) as geom, *");
        Integer srid = baseQueryService.getSrid(baseMapper);
        wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", wkt, srid));
 
        return wrapper;
    }
}