13693261870
昨天 542a030a93de7dbc39e185d4ce355c5894e3cd5b
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
package com.terra.system.controller.show;
 
import com.terra.common.annotation.SysLog;
import com.terra.common.controller.all.BaseController;
import com.terra.common.entity.all.HttpStatus;
import com.terra.common.entity.all.ResponseMsg;
import com.terra.system.entity.data.DownloadEntity;
import com.terra.system.entity.show.ExportEntity;
import com.terra.system.entity.sys.UserEntity;
import com.terra.common.helper.StringHelper;
import com.terra.common.helper.WebHelper;
import com.terra.system.service.data.DownloadService;
import com.terra.system.service.show.ExportService;
import com.terra.system.service.sys.DownlogService;
import com.terra.system.service.sys.TokenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import javax.annotation.Resource;
 
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * 在线制图
 * @author WWW
 */
@Tag(name = "综合展示\\在线制图")
@RestController
@RequestMapping("/export")
public class ExportController  extends BaseController {
    @Resource
    TokenService tokenService;
 
    @Resource
    ExportService exportService;
 
    @Resource
    DownlogService downlogService;
 
    @Resource
    DownloadService downloadService;
 
    @SysLog()
    @Operation(summary = "分页查询下载文件")
    @Parameters({
            @Parameter(name = "name", description = "名称", in = ParameterIn.QUERY, example = ""),
            @Parameter(name = "pageSize", description = "每页条数", in = ParameterIn.QUERY, example = "10"),
            @Parameter(name = "pageIndex", description = "分页数(从1开始)", in = ParameterIn.QUERY, example = "1")
    })
    @GetMapping(value = "/selectByPage")
    public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
 
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
 
            int count = downloadService.selectCountForUser(ue.getId(), "2", name);
            if (count == 0) {
                return success(0, null);
            }
            List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getId(), "2", name, pageSize, pageSize * (pageIndex - 1));
 
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "新建出图")
    @Parameters({
            @Parameter(name = "entity", description = "在线制图实体类")
    })
    @ResponseBody
    @PostMapping(value = "/insertMap", produces = "application/json; charset=UTF-8")
    public ResponseMsg<String> insertMap(@RequestBody ExportEntity entity, HttpServletRequest req) {
        try {
            boolean flag = entity.getXmin() == 0 && entity.getYmin() == 0 && entity.getXmax() == 0 && entity.getYmax() == 0;
            if (StringHelper.isEmpty(entity.getLayers()) || StringHelper.isEmpty(entity.getToken()) || flag) {
                return fail("参数不完整");
            }
 
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录");
            }
 
            String str = exportService.post(ue, entity);
            if (StringHelper.isNull(str)) {
                return fail("出图失败");
            }
 
            return success("出图成功", str);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "下载出图")
    @Parameters({
            @Parameter(name = "guid", description = "文件GUID", in = ParameterIn.QUERY)
    })
    @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
    public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (StringHelper.isEmpty(guid)) {
                WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "找不到文件ID", res);
                return;
            }
 
            DownloadEntity de = downloadService.selectByGuid(guid);
            if (null == de) {
                WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res);
                return;
            }
 
            UserEntity ue = tokenService.getCurrentUser(req);
            downlogService.updateInfos(ue, de, req);
 
            String filePath = downloadService.getDownloadFilePath(de);
            WebHelper.download(filePath, de.getName(), res);
        } catch (Exception ex) {
            WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res);
        }
    }
}