-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonController.java
More file actions
198 lines (185 loc) · 6.18 KB
/
Copy pathCommonController.java
File metadata and controls
198 lines (185 loc) · 6.18 KB
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
package com.tlcsdm.gen.controller;
import cn.smallbun.screw.core.engine.EngineFileType;
import com.tlcsdm.common.annotation.Log;
import com.tlcsdm.gen.base.BaseUtils;
import com.tlcsdm.gen.enums.*;
import com.tlcsdm.gen.util.cache.SimpleCache;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 通用模块
*
* @author: TangLiang
* @date: 2021/6/21 9:03
* @since: 1.0
*/
@RestController
@RequiredArgsConstructor
public class CommonController {
/**
* 目录
*/
@GetMapping("/")
public ModelAndView index() {
return new ModelAndView("pages/index");
}
/**
* 获取DataBaseType的数据
*/
@GetMapping("selectDataBaseType")
@Log(title = "通用模块", operateType = "获取数据库驱动名称")
public Map<String, Object> selectDataBaseType() {
List<Map<String, Object>> list = SimpleCache.get(SimpleCache.DATABASETYPE);
if (list == null) {
list = new ArrayList<>();
for (DataBaseType dataBaseType : DataBaseType.values()) {
if (DataBaseType.UNKNOW == dataBaseType) {
continue;
}
Map<String, Object> result = new HashMap<>(4);
result.put("CODE_", dataBaseType.getTypeName());
result.put("NAME_", dataBaseType.toString());
list.add(result);
}
SimpleCache.put(SimpleCache.DATABASETYPE, list);
}
return BaseUtils.success(list);
}
/**
* 获取GenProcedureModelType的数据
*/
@GetMapping("selectGenProcedureModelType")
@Log(title = "通用模块", operateType = "获取存储过程模板名称")
public Map<String, Object> selectGenProcedureModelType() {
List<Map<String, Object>> list = SimpleCache.get(SimpleCache.GENPROCEDUREMODELTYPE);
if (list == null) {
list = new ArrayList<>();
for (GenProcedureModelType genProcedureModelType : GenProcedureModelType.values()) {
if (genProcedureModelType.getStatus() == 0) {
continue;
}
Map<String, Object> result = new HashMap<>(4);
result.put("CODE_", genProcedureModelType.getCode());
result.put("NAME_", genProcedureModelType.getDesc());
list.add(result);
}
SimpleCache.put(SimpleCache.GENPROCEDUREMODELTYPE, list);
}
return BaseUtils.success(list);
}
/**
* 获取GenCodeModelType的数据
*/
@GetMapping("selectGenCodeModelType")
@Log(title = "通用模块", operateType = "获取后台代码模板名称")
public Map<String, Object> selectGenCodeModelType() {
List<Map<String, Object>> list = SimpleCache.get(SimpleCache.GENCODEMODELTYPE);
if (list == null) {
list = new ArrayList<>();
for (GenCodeModelType genCodeModelType : GenCodeModelType.values()) {
if (genCodeModelType.getStatus() == 0) {
continue;
}
Map<String, Object> result = new HashMap<>(4);
result.put("CODE_", genCodeModelType.getCode());
result.put("NAME_", genCodeModelType.getDesc());
list.add(result);
}
SimpleCache.put(SimpleCache.GENCODEMODELTYPE, list);
}
return BaseUtils.success(list);
}
/**
* 获取NameConventType的数据
*/
@GetMapping("selectNameConventType")
@Log(title = "通用模块", operateType = "获取命名规范")
public Map<String, Object> selectNameConventType() {
List<Map<String, Object>> list = SimpleCache.get(SimpleCache.NAMECONVENTTYPE);
if (list == null) {
list = new ArrayList<>();
for (NameConventType nameConventType : NameConventType.values()) {
if (nameConventType.getStatus() == 0) {
continue;
}
Map<String, Object> result = new HashMap<>(4);
result.put("CODE_", nameConventType.getCode());
result.put("NAME_", nameConventType.getDesc());
list.add(result);
}
SimpleCache.put(SimpleCache.NAMECONVENTTYPE, list);
}
return BaseUtils.success(list);
}
/**
* 获取JavaClass的数据
*/
@GetMapping("selectJavaClass")
@Log(title = "通用模块", operateType = "获取数据库对应java类信息")
public Map<String, Object> selectJavaClass() {
List<Map<String, Object>> list = SimpleCache.get(SimpleCache.JAVACLASS);
if (list == null) {
list = new ArrayList<>();
for (JavaClass javaClass : JavaClass.values()) {
Map<String, Object> result = new HashMap<>(4);
result.put("CODE_", javaClass.getCode());
result.put("NAME_", javaClass.toString());
list.add(result);
}
SimpleCache.put(SimpleCache.JAVACLASS, list);
}
return BaseUtils.success(list);
}
/**
* 获取EngineFileType的数据
*/
@GetMapping("selectEngineFileType")
@Log(title = "通用模块", operateType = "获取数据库文档类型信息")
public Map<String, Object> selectEngineFileType() {
List<Map<String, Object>> list = SimpleCache.get(SimpleCache.ENGINEFILETYPE);
if (list == null) {
list = new ArrayList<>();
for (EngineFileType engineFileType : EngineFileType.values()) {
Map<String, Object> result = new HashMap<>(4);
result.put("CODE_", engineFileType.toString());
result.put("NAME_", engineFileType.getDesc());
list.add(result);
}
SimpleCache.put(SimpleCache.ENGINEFILETYPE, list);
}
return BaseUtils.success(list);
}
/**
* 获取file文件夹下的文件
*/
@GetMapping("downloadFile/{fileName}")
@Log(title = "通用模块", operateType = "获取静态文件")
public void downloadFile(@PathVariable String fileName, HttpServletRequest request, HttpServletResponse response)
throws IOException {
// 为空返回
if (StringUtils.isEmpty(fileName) || "favicon.ico".equals(fileName)) {
return;
}
Resource resource = new ClassPathResource("file/" + fileName);
if (!resource.exists()) {
throw new FileNotFoundException("文件未找到");
}
InputStream inputStream = resource.getInputStream();
BaseUtils.download(inputStream, fileName, request, response);
}
}