提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.db.controller; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.db.entity.DatabaseInfo; |
|
4 |
import cn.stylefeng.guns.base.db.util.DbUtil; |
|
5 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
6 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
7 |
import cn.stylefeng.guns.base.db.model.params.DatabaseInfoParam; |
|
8 |
import cn.stylefeng.guns.base.db.service.DatabaseInfoService; |
|
9 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
10 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
11 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
12 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
13 |
import org.springframework.beans.factory.annotation.Autowired; |
|
14 |
import org.springframework.stereotype.Controller; |
|
15 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
16 |
import org.springframework.web.bind.annotation.RequestParam; |
|
17 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
18 |
|
|
19 |
import javax.servlet.http.HttpServletRequest; |
|
20 |
import javax.servlet.http.HttpSession; |
|
21 |
import java.util.List; |
|
22 |
import java.util.Map; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* 数据库信息表控制器 |
|
27 |
* |
|
28 |
* @author stylefeng |
|
29 |
* @Date 2019-06-15 17:05:23 |
|
30 |
*/ |
|
31 |
@Controller |
|
32 |
@RequestMapping("/databaseInfo") |
|
33 |
public class DatabaseInfoController extends BaseController { |
|
34 |
|
|
35 |
/** |
|
36 |
* session中标识已选择条件字段的key |
|
37 |
*/ |
|
38 |
public static String CONDITION_FIELDS = "CONDITION_FIELDS"; |
|
39 |
|
|
40 |
private String PREFIX = "/modular/databaseInfo"; |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private DatabaseInfoService databaseInfoService; |
|
44 |
|
|
45 |
/** |
|
46 |
* 跳转到主页面 |
|
47 |
* |
|
48 |
* @author stylefeng |
|
49 |
* @Date 2019-06-15 |
|
50 |
*/ |
|
51 |
@RequestMapping("") |
|
52 |
public String index() { |
|
53 |
return PREFIX + "/databaseInfo.html"; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* 新增页面 |
|
58 |
* |
|
59 |
* @author stylefeng |
|
60 |
* @Date 2019-06-15 |
|
61 |
*/ |
|
62 |
@RequestMapping("/add") |
|
63 |
public String add() { |
|
64 |
return PREFIX + "/databaseInfo_add.html"; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* 新增接口 |
|
69 |
* |
|
70 |
* @author stylefeng |
|
71 |
* @Date 2019-06-15 |
|
72 |
*/ |
|
73 |
@RequestMapping("/addItem") |
|
74 |
@ResponseBody |
|
75 |
public ResponseData addItem(DatabaseInfoParam databaseInfoParam) { |
|
76 |
this.databaseInfoService.add(databaseInfoParam); |
|
77 |
return ResponseData.success(); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* 编辑接口 |
|
82 |
* |
|
83 |
* @author stylefeng |
|
84 |
* @Date 2019-06-15 |
|
85 |
*/ |
|
86 |
@RequestMapping("/editItem") |
|
87 |
@ResponseBody |
|
88 |
public ResponseData editItem(DatabaseInfoParam databaseInfoParam) { |
|
89 |
//this.databaseInfoService.update(databaseInfoParam); |
|
90 |
return ResponseData.success(); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* 删除接口 |
|
95 |
* |
|
96 |
* @author stylefeng |
|
97 |
* @Date 2019-06-15 |
|
98 |
*/ |
|
99 |
@RequestMapping("/delete") |
|
100 |
@ResponseBody |
|
101 |
public ResponseData delete(DatabaseInfoParam databaseInfoParam) { |
|
102 |
this.databaseInfoService.delete(databaseInfoParam); |
|
103 |
return ResponseData.success(); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* 查询列表 |
|
108 |
* |
|
109 |
* @author stylefeng |
|
110 |
* @Date 2019-06-15 |
|
111 |
*/ |
|
112 |
@ResponseBody |
|
113 |
@RequestMapping("/list") |
|
114 |
public LayuiPageInfo list(@RequestParam(value = "condition", required = false) String condition) { |
|
115 |
DatabaseInfoParam databaseInfoParam = new DatabaseInfoParam(); |
|
116 |
databaseInfoParam.setDbName(condition); |
|
117 |
return this.databaseInfoService.findPageBySpec(databaseInfoParam); |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* 获取某个数据源下的所有表 |
|
122 |
* |
|
123 |
* @author fengshuonan |
|
124 |
* @Date 2019/1/30 2:49 PM |
|
125 |
*/ |
|
126 |
@RequestMapping("/tableList") |
|
127 |
@ResponseBody |
|
128 |
public Object tableList(Long dbId, HttpServletRequest request) { |
|
129 |
|
|
130 |
if (ToolUtil.isEmpty(dbId)) { |
|
131 |
return new LayuiPageInfo(); |
|
132 |
} |
|
133 |
|
|
134 |
//清空session中的字段条件信息 |
|
135 |
HttpSession session = request.getSession(); |
|
136 |
session.removeAttribute(CONDITION_FIELDS); |
|
137 |
|
|
138 |
try { |
|
139 |
DatabaseInfo databaseInfo = databaseInfoService.getById(dbId); |
|
140 |
List<Map<String, Object>> maps = DbUtil.selectTables(databaseInfo); |
|
141 |
Page<Map<String, Object>> objectPage = new Page<>(); |
|
142 |
objectPage.setRecords(maps); |
|
143 |
return LayuiPageFactory.createPageInfo(objectPage); |
|
144 |
} catch (Exception e) { |
|
145 |
Page<Map<String, Object>> objectPage = new Page<>(); |
|
146 |
return LayuiPageFactory.createPageInfo(objectPage); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
|