WebDataServiceController.java
4.17 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
package com.lhcredit.project.webbusiness.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.project.business.apiDataService.domain.ApiDataService;
import com.lhcredit.project.business.apiDataService.domain.ApiDataTreeNode;
import com.lhcredit.project.business.apiDataService.service.IApiDataServiceService;
import com.lhcredit.project.business.apiDataServiceInfo.domain.ApiDataServiceInfo;
import com.lhcredit.project.business.apiDataServiceInfo.service.IApiDataServiceInfoService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Collections;
import java.util.List;
import static com.lhcredit.framework.web.domain.AjaxResult.success;
@Api(tags = "数据服务")
@Controller
@RequestMapping("/api-V2.0/dataService")
@RequiredArgsConstructor
public class WebDataServiceController {
@Autowired
private IApiDataServiceService apiDataServiceService;
@Autowired
private IApiDataServiceInfoService apiDataServiceInfoService;
@GetMapping("/list")
@ResponseBody
public AjaxResult list() {
List<ApiDataTreeNode> list = apiDataServiceService.selectApiDataServiceTree();
return success(list);
}
@GetMapping("/selectOne")
@ResponseBody
public AjaxResult selectOne(Integer id) {
ApiDataService apiDataService = apiDataServiceService.selectApiDataServiceOneById(id);
return success(apiDataService);
}
@RequestMapping("/xxx")
@Transactional(rollbackFor = Exception.class)
public AjaxResult xxx(String name, Integer id, Integer size) {
ExcelReader reader = ExcelUtil.getReader("C:\\Users\\lhzx\\Desktop\\2\\梳理.xlsx", size); // 指定从第二个表格开始读取
List<List<Object>> readAll = reader.read();
ApiDataService apiDataService = new ApiDataService();
List<Object> titleRow = readAll.get(0);
if (titleRow.size() > 1) {
apiDataService.setDirectory(titleRow.get(1).toString());
}
List<Object> dimensionRow = readAll.get(1);
if (dimensionRow.size() > 1) {
apiDataService.setDimension(dimensionRow.get(1).toString());
}
List<Object> titleRow1 = readAll.get(2);
if (titleRow1.size() > 2) {
apiDataService.setExample(titleRow1.get(2).toString());
}
apiDataService.setDataName(name);
apiDataService.setParentId(id);
apiDataServiceService.insertApiDataService(apiDataService);
ApiDataServiceInfo apiDataServiceInfo = new ApiDataServiceInfo();
List<Object> title = readAll.size() > 3 ? readAll.get(3) : Collections.emptyList();
List<Object> content = readAll.size() > 4 ? readAll.get(4) : Collections.emptyList();
List<Object> content1 = readAll.size() > 5 ? readAll.get(5) : Collections.emptyList();
List<Object> content2 = readAll.size() > 6 ? readAll.get(6) : Collections.emptyList();
for (int i = 0; i < title.size(); i++) {
if (i + 1 < title.size()) {
apiDataServiceInfo.setTitle(title.get(i + 1).toString());
}
if (i + 1 < content.size()) {
apiDataServiceInfo.setContent(content.get(i + 1).toString());
}
if (i + 1 < content1.size()) {
apiDataServiceInfo.setContent1(content1.get(i + 1).toString());
}
if (i + 1 < content2.size()) {
apiDataServiceInfo.setContent2(content2.get(i + 1).toString());
}
System.out.println(apiDataServiceInfo);
apiDataServiceInfo.setDataId(apiDataService.getId());
apiDataServiceInfoService.insertApiDataServiceInfo(apiDataServiceInfo);
}
System.out.println(apiDataService);
return success();
}
}