commit | author | age
|
a18bfa
|
1 |
package cn.autoform.web.controller.datasource; |
Z |
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
import org.springframework.web.bind.annotation.RequestBody; |
|
10 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
11 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
12 |
import org.springframework.web.bind.annotation.RestController; |
|
13 |
|
|
14 |
import cn.autoform.db.entity.DBConnectionManagerEntity; |
|
15 |
import cn.autoform.db.entity.FieldPropertyEntity; |
|
16 |
import cn.autoform.db.entity.FormdatsourceEntity; |
|
17 |
import cn.autoform.fw.exception.RestResult; |
|
18 |
import cn.autoform.fw.service.DatabaseMetaDateService; |
|
19 |
import cn.autoform.fw.utility.RestResultGenerator; |
|
20 |
import cn.autoform.web.service.datasource.DatasourceService; |
|
21 |
|
|
22 |
/** |
|
23 |
* 数据源信息管理 |
|
24 |
* @author liumy |
|
25 |
* |
|
26 |
* @param <T> |
|
27 |
*/ |
|
28 |
@RestController |
|
29 |
public class DatasourceController<T> { |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private DatasourceService datasourceService = null; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private DatabaseMetaDateService databaseMetaDateService = null; |
|
36 |
|
|
37 |
/** |
|
38 |
* 初期化 |
|
39 |
* |
|
40 |
* @param tenantID |
|
41 |
* 租户ID |
|
42 |
* @param formid |
|
43 |
* 表单ID |
|
44 |
* @return 表单数据源 |
|
45 |
*/ |
|
46 |
@RequestMapping(value = "${requset.datasource01}", method = RequestMethod.GET) |
|
47 |
public RestResult<List<FormdatsourceEntity>> getFormdatsourceListService(String tenantID, String formID) { |
|
48 |
|
|
49 |
List<FormdatsourceEntity> rsList = datasourceService.getFormdatsourceList(tenantID, formID); |
|
50 |
return RestResultGenerator.genSuccessResult(rsList); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* 新增一条数据源 |
|
55 |
* |
|
56 |
* @param tenantID |
|
57 |
* @param formID |
|
58 |
* @param dataSourceName |
|
59 |
* @param databaseName |
|
60 |
* @param datasource |
|
61 |
* @param createUser |
|
62 |
* @return |
|
63 |
*/ |
|
64 |
@RequestMapping(value = "${requset.datasource02}", method = RequestMethod.POST) |
|
65 |
public RestResult<String> createFormdatsourceService(@RequestBody FormdatsourceEntity formdatsource) { |
|
66 |
|
|
67 |
int nRs = datasourceService.createFormdatsource(formdatsource); |
|
68 |
return RestResultGenerator.genSuccessResult(String.valueOf(nRs)); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* 删除一条数据源 |
|
73 |
* |
|
74 |
* @param tenantID |
|
75 |
* @param formID |
|
76 |
* @param dataSourceName |
|
77 |
* @return |
|
78 |
*/ |
|
79 |
@RequestMapping(value = "${requset.datasource03}", method = RequestMethod.GET) |
|
80 |
public RestResult<String> deleteFormdatsourceService(String tenantID, String formID, String dataSourceName) { |
|
81 |
int nRs = datasourceService.deleteFormdatsource(tenantID, formID, dataSourceName); |
|
82 |
return RestResultGenerator.genSuccessResult(String.valueOf(nRs)); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* 数据连接名取得 |
|
87 |
* |
|
88 |
* @param tenantID |
|
89 |
* @return |
|
90 |
*/ |
|
91 |
@RequestMapping(value = "${requset.datasource04}", method = RequestMethod.GET) |
|
92 |
public RestResult<List<String>> getDataConnectionNameService(String tenantID) { |
|
93 |
List<String> rsList = datasourceService.getDataConnectionName(tenantID); |
|
94 |
return RestResultGenerator.genSuccessResult(rsList); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* 数据源详细取得 |
|
99 |
* |
|
100 |
* @param tenantID |
|
101 |
* @param dataConnectionName |
|
102 |
* @return |
|
103 |
* @throws Exception |
|
104 |
*/ |
|
105 |
@RequestMapping(value = "${requset.datasource05}", method = RequestMethod.GET) |
|
106 |
public RestResult<List<String>> getDatasourceListService(String tenantID, String dataConnectionName) { |
|
107 |
System.out.println(tenantID); |
|
108 |
List<String> rsList = databaseMetaDateService.getDatabaseTableName(tenantID, dataConnectionName); |
|
109 |
|
|
110 |
return RestResultGenerator.genSuccessResult(rsList); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* 数据库詳細JSON取得(表单设计用) |
|
115 |
* |
|
116 |
* @param datasource |
|
117 |
* @param tenantID |
|
118 |
* @param dataConnectionName |
|
119 |
* @return |
|
120 |
* @throws Exception |
|
121 |
*/ |
|
122 |
@RequestMapping(value = "${requset.datasource06}", method = RequestMethod.GET) |
|
123 |
public RestResult<List<Map<String,List<String>>>> getDatasourceColumnsNameService(String formID, String tenantID) { |
|
124 |
|
|
125 |
List<Map<String,List<String>>> rsList = new ArrayList<Map<String,List<String>>>(); |
|
126 |
// 当前表单下所有数据源取得 |
|
127 |
List<FormdatsourceEntity> listDataSource = datasourceService.getFormdatsourceList(tenantID, formID); |
|
128 |
for(FormdatsourceEntity formdatsource : listDataSource) { |
|
129 |
// 数据源名 |
|
130 |
String datasourceName = formdatsource.getDataSourceName(); |
|
131 |
// 数据库名 |
|
132 |
String databaseName = formdatsource.getDatabaseName(); |
|
133 |
// 已选择的数据表名 |
|
134 |
String tableName = formdatsource.getDatasource(); |
|
135 |
// 获取所有列名List |
|
136 |
List<String> listColumns = databaseMetaDateService.getDatabaseColumnsName(tenantID, databaseName, tableName); |
|
137 |
|
|
138 |
Map<String,List<String>> mpTableMap = new HashMap<String,List<String>>(); |
|
139 |
|
|
140 |
mpTableMap.put(datasourceName, listColumns); |
|
141 |
|
|
142 |
rsList.add(mpTableMap); |
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
return RestResultGenerator.genSuccessResult(rsList); |
|
147 |
|
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* 新增一条数据连接 |
|
152 |
* |
|
153 |
* @param dBConnectionManagerEntity |
|
154 |
* @return |
|
155 |
*/ |
|
156 |
@RequestMapping(value = "${requset.datasource07}", method = RequestMethod.POST) |
|
157 |
public RestResult<String> createDBconnectionService( |
|
158 |
@RequestBody DBConnectionManagerEntity dBConnectionManagerEntity) { |
|
159 |
int nRs = datasourceService.createDBconnection(dBConnectionManagerEntity); |
|
160 |
|
|
161 |
return RestResultGenerator.genSuccessResult(String.valueOf(nRs)); |
|
162 |
} |
|
163 |
|
|
164 |
// @RequestMapping(value = "${requset.datasource08}", method = RequestMethod.GET) |
|
165 |
// public RestResult<Map<String,List<String>>> getDatasourceColumnsValueService1(String tenantID, String formID, String dataSourceName, String columnNames) { |
|
166 |
// |
|
167 |
// List<FormdatsourceEntity> listDataSource = datasourceService.getDatasource(tenantID, formID, dataSourceName); |
|
168 |
// Map<String,List<String>> mpColumnInfo = new HashMap<String,List<String>>(); |
|
169 |
// |
|
170 |
// FormdatsourceEntity formdatsource = listDataSource.get(0); |
|
171 |
// |
|
172 |
// String[] arrColumns = columnNames.split(","); |
|
173 |
// |
|
174 |
// for(String column : arrColumns) { |
|
175 |
//// |
|
176 |
//// List<String> listColumnValue = databaseMetaDateService.getColumnsInfo(formdatsource, column); |
|
177 |
//// mpColumnInfo.put(column, listColumnValue); |
|
178 |
// |
|
179 |
// } |
|
180 |
// |
|
181 |
// return RestResultGenerator.genSuccessResult(mpColumnInfo); |
|
182 |
// } |
|
183 |
|
|
184 |
/** |
|
185 |
* 获取列详细值 |
|
186 |
* @param tenantID 租户 |
|
187 |
* @param databaseName 数据连接名 |
|
188 |
* @param datasource 表名 |
|
189 |
* @param columnNames 列名 |
|
190 |
* @return |
|
191 |
* @throws Exception |
|
192 |
*/ |
|
193 |
@RequestMapping(value = "${requset.datasource08}", method = RequestMethod.GET) |
|
194 |
public RestResult<Map<String,List<String>>> getDatasourceColumnsValueService(String tenantID, String databaseName, String datasource, String columnNames) { |
|
195 |
|
|
196 |
String[] arrColumns = columnNames.split(","); |
|
197 |
Map<String,List<String>> mpColumnInfo = new HashMap<String,List<String>>(); |
|
198 |
|
|
199 |
for(String column : arrColumns) { |
|
200 |
|
|
201 |
List<String> listColumnValue = databaseMetaDateService.getColumnsInfo(tenantID,databaseName, datasource,column); |
|
202 |
mpColumnInfo.put(column, listColumnValue); |
|
203 |
|
|
204 |
} |
|
205 |
|
|
206 |
return RestResultGenerator.genSuccessResult(mpColumnInfo); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* 获取当前表单数据源详细信息 |
|
211 |
* @param tenantID |
|
212 |
* @param formID |
|
213 |
* @return |
|
214 |
* @throws Exception |
|
215 |
*/ |
|
216 |
@RequestMapping(value = "${requset.datasource09}", method = RequestMethod.GET) |
|
217 |
public RestResult<List<Map<String, List<Map<String,List<Map<String,List<String>>>>>>>> getDatasourceInfoService(String tenantID, String formID){ |
|
218 |
// 当前表单下所有数据源取得 |
|
219 |
List<FormdatsourceEntity> listDataSource = datasourceService.getFormdatsourceList(tenantID, formID); |
|
220 |
|
|
221 |
List<Map<String, List<Map<String,List<Map<String,List<String>>>>>>> rsList = new ArrayList<Map<String, List<Map<String,List<Map<String,List<String>>>>>>>(); |
|
222 |
|
|
223 |
for(FormdatsourceEntity formdatsource : listDataSource) { |
|
224 |
// 数据源名 |
|
225 |
String datasourceName = formdatsource.getDataSourceName(); |
|
226 |
// 数据库名 |
|
227 |
String databaseName = formdatsource.getDatabaseName(); |
|
228 |
// 已选择的数据表名 |
|
229 |
String tableName = formdatsource.getDatasource(); |
|
230 |
|
|
231 |
Map<String,List<String>> mpColumn = databaseMetaDateService.getDatabaseColumnsInfo(tenantID, databaseName, tableName); |
|
232 |
|
|
233 |
List<Map<String,List<String>>> listColumnInfo = new ArrayList<Map<String,List<String>>>(); |
|
234 |
|
|
235 |
listColumnInfo.add(mpColumn); |
|
236 |
|
|
237 |
Map<String,List<Map<String,List<String>>>> mpTable = new HashMap<String,List<Map<String,List<String>>>>(); |
|
238 |
|
|
239 |
mpTable.put(tableName, listColumnInfo); |
|
240 |
|
|
241 |
List<Map<String,List<Map<String,List<String>>>>> listTables = new ArrayList<Map<String,List<Map<String,List<String>>>>>(); |
|
242 |
|
|
243 |
listTables.add(mpTable); |
|
244 |
|
|
245 |
Map<String, List<Map<String,List<Map<String,List<String>>>>>> mpDatabase = new HashMap<String, List<Map<String,List<Map<String,List<String>>>>>>(); |
|
246 |
|
|
247 |
mpDatabase.put(datasourceName, listTables); |
|
248 |
rsList.add(mpDatabase); |
|
249 |
} |
|
250 |
|
|
251 |
|
|
252 |
return RestResultGenerator.genSuccessResult(rsList); |
|
253 |
} |
|
254 |
|
|
255 |
/** |
|
256 |
* 字段数据源取得服务(发布用) |
|
257 |
* @param tenantID |
|
258 |
* @param formID |
|
259 |
* @return |
|
260 |
*/ |
|
261 |
@RequestMapping(value = "${requset.datasource10}", method = RequestMethod.GET) |
|
262 |
public RestResult<List<Map<String,Map<String,String>>>> getFieldDatasourceInfoService(String tenantID, String formID ) { |
|
263 |
|
|
264 |
List<Map<String,Map<String,String>>> rsList = new ArrayList<Map<String,Map<String,String>>>(); |
|
265 |
// 取得当前表单字段属性datasourcetype为dataSource的所有字段信息 datasource textcolumn valuecolumn namecolumn |
|
266 |
// 设定数据源的字段column取得 |
|
267 |
List<FieldPropertyEntity> listFieldProper = datasourceService.getColumnNum(tenantID, formID); |
|
268 |
for(FieldPropertyEntity fieldProperty : listFieldProper) { |
|
269 |
|
|
270 |
// |
|
271 |
int columnOrderNum = fieldProperty.getColumnOrderNum(); |
|
272 |
|
|
273 |
// 别名取得 |
|
274 |
String fieldKey = datasourceService.getFieldkeyList(tenantID, formID, columnOrderNum).get(0).getFieldKey(); |
|
275 |
|
|
276 |
// 数据源名 |
|
277 |
String datasource = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "datasource").get(0).getValue(); |
|
278 |
// 列1名 |
|
279 |
String textcolumn = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "textcolumn").get(0).getValue(); |
|
280 |
// 列2名 |
|
281 |
String valuecolumn = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "valuecolumn").get(0).getValue(); |
|
282 |
// 列3 |
|
283 |
String namecolumn = ""; |
|
284 |
if(!datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "namecolumn").isEmpty()) { |
|
285 |
namecolumn = datasourceService.getFieldPropertyList(tenantID, formID, columnOrderNum, "namecolumn").get(0).getValue(); |
|
286 |
} |
|
287 |
|
|
288 |
Map<String,String> mpFieldInfo = new HashMap<String,String>(); |
|
289 |
|
|
290 |
mpFieldInfo.put("datasource", datasource); |
|
291 |
|
|
292 |
mpFieldInfo.put("textcolumn", textcolumn); |
|
293 |
|
|
294 |
mpFieldInfo.put("valuecolumn", valuecolumn); |
|
295 |
|
|
296 |
mpFieldInfo.put("namecolumn", namecolumn); |
|
297 |
|
|
298 |
Map<String,Map<String,String>> mpField = new HashMap<String,Map<String,String>>(); |
|
299 |
|
|
300 |
mpField.put(fieldKey, mpFieldInfo); |
|
301 |
|
|
302 |
rsList.add(mpField); |
|
303 |
} |
|
304 |
|
|
305 |
return RestResultGenerator.genSuccessResult(rsList); |
|
306 |
} |
|
307 |
} |