13693261870
2025-06-24 8565bd83fcd670ec8379084d600eb97d18037d21
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
package com.terra.system.service.show;
 
import com.alibaba.fastjson.JSON;
import com.terra.system.entity.all.ResponseMsg;
import com.terra.system.entity.all.StaticData;
import com.terra.system.entity.data.DownloadEntity;
import com.terra.system.entity.show.ExportEntity;
import com.terra.system.entity.sys.UserEntity;
import com.terra.system.helper.FileHelper;
import com.terra.system.helper.PathHelper;
import com.terra.system.helper.RestHelper;
import com.terra.system.helper.StringHelper;
import com.terra.system.service.data.DownloadService;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 在线制图
 * @author WWW
 */
@Service
public class ExportService {
    @Value("${sys.exportServer}")
    private String exportServer;
 
    @Resource
    PathHelper pathHelper;
 
    @Resource
    DownloadService downloadService;
 
    /**
     * POST请求出图服务
     *
     * @param ue     用户类
     * @param entity 在线制图类
     * @return 成功
     * @throws Exception
     */
    public String post(UserEntity ue, ExportEntity entity) throws Exception {
        Map<String, Object> map = getMapData(entity);
        String url = exportServer + "/Export/Start";
 
        String str = RestHelper.postForRest(url, map);
        if (StringHelper.isEmpty(str)) {
            return null;
        }
 
        ResponseMsg<String> msg = JSON.parseObject(str, ResponseMsg.class);
        if (msg == null || msg.getCode() != StaticData.TWO_HUNDRED) {
            return null;
        }
 
        String file = pathHelper.getConfig().getDownloadPath() + File.separator + msg.getResult();
        File f = new File(file);
        if (!f.exists() && !f.isDirectory()) {
            return null;
        }
 
        DownloadEntity de = getDownloadEntity(ue, entity, file);
        int rows = downloadService.insert(de);
 
        return rows > 0 ? de.getGuid() : null;
    }
 
    /**
     * 获取Map数据
     */
    private Map<String, Object> getMapData(ExportEntity entity) {
        Map<String, Object> map = new HashMap<String, Object>(3);
 
        Field[] fields = entity.getClass().getDeclaredFields();
        for (Field field : fields) {
            try {
                if ("serialVersionUID".equals(field.getName())) {
                    continue;
                }
 
                field.setAccessible(true);
                Object obj = field.get(entity);
 
                map.put(field.getName(), obj);
            } catch (Exception ex) {
                //
            }
        }
 
        return map;
    }
 
    /**
     * 获取下载实体类
     */
    private DownloadEntity getDownloadEntity(UserEntity ue, ExportEntity entity, String file) throws Exception {
        DownloadEntity de = new DownloadEntity();
        de.setName(FileHelper.getFileName(file));
        // 1-Shp文件,2-专题图,3-元数据,4-业务数据,5-管道分析,6-统计报告,7-附件文件,8-瓦片文件
        de.setType(2);
        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
        de.setDepid(ue.getDepid());
        de.setDcount(0);
        // de.setPwd(null)
        de.setUrl(FileHelper.getRelativePath(file));
        // de.setDescr("专题图文件")
        de.setDescr(StringHelper.isEmpty(entity.getTitle()) ? "专题图文件" : entity.getTitle().trim());
        de.setGuid(FileHelper.getFileMd5(file));
        de.setCreateUser(ue.getId());
        // de.setGeom(null)
 
        return de;
    }
}