管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-19 c9183fa5835268bfc15557b4bd0e0b6b333c79de
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
package com.lf.server.controller.data;
 
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.data.MetaFileEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.data.DataUploadService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
 
/**
 * 数据上传
 * @author WWW
 */
@Api(tags = "数据管理\\数据上传")
@RestController
@RequestMapping("/dataUpload")
public class DataUploadController extends BaseController {
    @Autowired
    TokenService tokenService;
 
    @Autowired
    DataUploadService dataUploadService;
 
    @SysLog()
    @ApiOperation(value = "查询目录")
    @GetMapping(value = "/selectPath")
    public ResponseMsg<String> selectPath() {
        try {
            String pathName = dataUploadService.selectPath();
 
            return success(pathName);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query")
    })
    @GetMapping(value = "/selectFiles")
    public ResponseMsg<List<MetaFileEntity>> selectFiles(String path) {
        try {
            List<MetaFileEntity> list = dataUploadService.selectFiles(path);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query")
    })
    @ResponseBody
    @PostMapping(value = "/uploadFiles")
    public ResponseMsg<Object> uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
 
            List<MetaFileEntity> list = dataUploadService.uploadData(null, path, req, res);
            if (null == list || list.isEmpty()) {
                return fail("没有找到上传文件", null);
            }
 
            return success(list.size());
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "删除文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MetaFileEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/deleteFiles")
    public ResponseMsg<Object> deleteFiles(@RequestBody List<MetaFileEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            if (null == list || list.isEmpty()) {
                return fail("没有找到文件", null);
            }
 
            int rows = dataUploadService.deleteFiles(list);
 
            return success("成功", rows);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "插入文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "元数据实体类", dataType = "MetaEntity", paramType = "body"),
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MetaFileEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/insertFiles")
    public ResponseMsg<Object> insertFiles(@RequestBody MetaEntity entity, @RequestBody List<MetaFileEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            if (null == list || list.isEmpty()) {
                return fail("没有找到文件", null);
            }
            if (null == entity) {
                return fail("元数据信息为空", null);
            }
 
            entity.setCreateTime(WebHelper.getCurrentTimestamp());
            entity.setBatch(StringHelper.YMDHMS_FORMAT.format(new Date(entity.getCreateTime().getTime())));
            entity.setCreateUser(ue.getId());
 
            int rows = dataUploadService.insertFiles(entity, list);
 
            return success("成功", rows);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
}