zhoufan vor 2 Jahren
Ursprung
Commit
3418c8fe6e

+ 23 - 5
webapidemo-api/src/main/java/com/example/controller/HomeController.java

@@ -1,5 +1,6 @@
1 1
 package com.example.controller;
2 2
 
3
+import com.alibaba.fastjson2.JSON;
3 4
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 5
 import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
5 6
 import com.example.entity.database.system.User;
@@ -20,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
20 21
 import org.springframework.web.multipart.MultipartFile;
21 22
 
22 23
 import javax.servlet.http.HttpServletResponse;
24
+import java.io.IOException;
25
+import java.io.PrintWriter;
23 26
 import java.util.*;
24 27
 import java.util.stream.Collectors;
25 28
 
@@ -46,7 +49,7 @@ public class HomeController extends BaseController {
46 49
     }
47 50
 
48 51
     @ApiOperation("导出Excel")
49
-    @GetMapping("/exportExcel")
52
+    @GetMapping("/exportexcel")
50 53
     public void ExportExcel(HttpServletResponse response) {
51 54
         List<User> list = userService.getList();
52 55
         ExcelHelper<User> excel = new ExcelHelper<>(User.class);
@@ -54,7 +57,7 @@ public class HomeController extends BaseController {
54 57
     }
55 58
 
56 59
     @ApiOperation("导入Excel")
57
-    @PostMapping("/importExcel")
60
+    @PostMapping("/importexcel")
58 61
     public AjaxResult importExcel(@RequestPart MultipartFile file) throws Exception {
59 62
         ExcelHelper<User> excel = new ExcelHelper<>(User.class);
60 63
         List<User> list = excel.importExcel(file.getInputStream());
@@ -152,13 +155,28 @@ public class HomeController extends BaseController {
152 155
     }
153 156
 
154 157
     @ApiOperation("代码生成")
155
-    @GetMapping("/GetCode")
158
+    @GetMapping("/getcode")
156 159
     public void GetCode(HttpServletResponse response, CodeInput input) {
157 160
         Map<String, Object> table = SqlRunner.db().selectOne("select table_name,table_comment from information_schema.tables"
158
-                + " where table_schema = (select database()) AND table_name ='" + input.getTableName() + "' ");
161
+                + " where table_schema = (select database()) AND table_name = {0} ",input.getTableName());
162
+        if (table == null) {
163
+            Map map = new HashMap();
164
+            map.put("state", "error");
165
+            map.put("message", "此表不存在");
166
+
167
+            try {
168
+                PrintWriter out = response.getWriter();
169
+                out.write(JSON.toJSONString(map));
170
+                out.flush();
171
+                out.close();
172
+            } catch (IOException ex) {
173
+                throw new RuntimeException(ex);
174
+            }
175
+            return;
176
+        }
159 177
         List<Map<String, Object>> columns = SqlRunner.db().selectList("select column_name,data_type,column_type,is_nullable,"
160 178
                 + "column_key,column_comment from information_schema.columns where table_schema = (select database()) "
161
-                + "and table_name = '" + input.getTableName() + "' order by ordinal_position");
179
+                + "and table_name = {0} order by ordinal_position",input.getTableName());
162 180
         CodeHelper.GetCode(response, table, columns, input.getPackageName(), input.getControllerName());
163 181
     }
164 182
 }

+ 12 - 0
webapidemo-api/src/main/java/com/example/filter/LogAspect.java

@@ -2,6 +2,7 @@ package com.example.filter;
2 2
 
3 3
 import com.alibaba.fastjson2.JSON;
4 4
 import com.example.entity.database.system.OperLog;
5
+import com.example.entity.view.system.UserView;
5 6
 import com.example.service.system.IOperLogService;
6 7
 import com.example.util.annotation.Log;
7 8
 import com.example.util.helper.*;
@@ -14,6 +15,8 @@ import org.aspectj.lang.annotation.Before;
14 15
 import org.springframework.beans.factory.annotation.Autowired;
15 16
 import org.springframework.core.NamedThreadLocal;
16 17
 import org.springframework.stereotype.Component;
18
+import org.springframework.web.context.request.RequestContextHolder;
19
+
17 20
 import javax.servlet.http.HttpServletRequest;
18 21
 import javax.servlet.http.HttpServletResponse;
19 22
 import java.util.Date;
@@ -110,6 +113,15 @@ public class LogAspect {
110 113
                 }
111 114
                 // 设置消耗时间
112 115
                 operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
116
+
117
+                //设置账号和部门
118
+                try {
119
+                    UserView user = (UserView) ServletHelper.getRequestAttributes().getAttribute("CurrentUser", 0);
120
+                    operLog.setOperName(user.getUserName());
121
+                    operLog.setDeptName(user.getDept().getDeptName());
122
+                } catch (Exception ex) {
123
+                }
124
+
113 125
                 // 保存数据库
114 126
                 AsyncHelper.instance().execute(new TimerTask() {
115 127
                     @Override

+ 1 - 1
webapidemo-util/src/main/java/com/example/util/helper/ExcelHelper.java

@@ -302,7 +302,7 @@ public class ExcelHelper<T> {
302 302
             cellStyle.setBorderLeft(BorderStyle.THIN);
303 303
             cellStyle.setBorderRight(BorderStyle.THIN);
304 304
 
305
-            int limit=6000;
305
+            int limit=60000;
306 306
             int rowindex=0;
307 307
             int total = list.size();
308 308
             for (int i = 0; i < total; i++) {