瀏覽代碼

修改日志

zhoufan 2 年之前
父節點
當前提交
3418c8fe6e

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

1
 package com.example.controller;
1
 package com.example.controller;
2
 
2
 
3
+import com.alibaba.fastjson2.JSON;
3
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
 import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
5
 import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
5
 import com.example.entity.database.system.User;
6
 import com.example.entity.database.system.User;
20
 import org.springframework.web.multipart.MultipartFile;
21
 import org.springframework.web.multipart.MultipartFile;
21
 
22
 
22
 import javax.servlet.http.HttpServletResponse;
23
 import javax.servlet.http.HttpServletResponse;
24
+import java.io.IOException;
25
+import java.io.PrintWriter;
23
 import java.util.*;
26
 import java.util.*;
24
 import java.util.stream.Collectors;
27
 import java.util.stream.Collectors;
25
 
28
 
46
     }
49
     }
47
 
50
 
48
     @ApiOperation("导出Excel")
51
     @ApiOperation("导出Excel")
49
-    @GetMapping("/exportExcel")
52
+    @GetMapping("/exportexcel")
50
     public void ExportExcel(HttpServletResponse response) {
53
     public void ExportExcel(HttpServletResponse response) {
51
         List<User> list = userService.getList();
54
         List<User> list = userService.getList();
52
         ExcelHelper<User> excel = new ExcelHelper<>(User.class);
55
         ExcelHelper<User> excel = new ExcelHelper<>(User.class);
54
     }
57
     }
55
 
58
 
56
     @ApiOperation("导入Excel")
59
     @ApiOperation("导入Excel")
57
-    @PostMapping("/importExcel")
60
+    @PostMapping("/importexcel")
58
     public AjaxResult importExcel(@RequestPart MultipartFile file) throws Exception {
61
     public AjaxResult importExcel(@RequestPart MultipartFile file) throws Exception {
59
         ExcelHelper<User> excel = new ExcelHelper<>(User.class);
62
         ExcelHelper<User> excel = new ExcelHelper<>(User.class);
60
         List<User> list = excel.importExcel(file.getInputStream());
63
         List<User> list = excel.importExcel(file.getInputStream());
152
     }
155
     }
153
 
156
 
154
     @ApiOperation("代码生成")
157
     @ApiOperation("代码生成")
155
-    @GetMapping("/GetCode")
158
+    @GetMapping("/getcode")
156
     public void GetCode(HttpServletResponse response, CodeInput input) {
159
     public void GetCode(HttpServletResponse response, CodeInput input) {
157
         Map<String, Object> table = SqlRunner.db().selectOne("select table_name,table_comment from information_schema.tables"
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
         List<Map<String, Object>> columns = SqlRunner.db().selectList("select column_name,data_type,column_type,is_nullable,"
177
         List<Map<String, Object>> columns = SqlRunner.db().selectList("select column_name,data_type,column_type,is_nullable,"
160
                 + "column_key,column_comment from information_schema.columns where table_schema = (select database()) "
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
         CodeHelper.GetCode(response, table, columns, input.getPackageName(), input.getControllerName());
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
 
2
 
3
 import com.alibaba.fastjson2.JSON;
3
 import com.alibaba.fastjson2.JSON;
4
 import com.example.entity.database.system.OperLog;
4
 import com.example.entity.database.system.OperLog;
5
+import com.example.entity.view.system.UserView;
5
 import com.example.service.system.IOperLogService;
6
 import com.example.service.system.IOperLogService;
6
 import com.example.util.annotation.Log;
7
 import com.example.util.annotation.Log;
7
 import com.example.util.helper.*;
8
 import com.example.util.helper.*;
14
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.core.NamedThreadLocal;
16
 import org.springframework.core.NamedThreadLocal;
16
 import org.springframework.stereotype.Component;
17
 import org.springframework.stereotype.Component;
18
+import org.springframework.web.context.request.RequestContextHolder;
19
+
17
 import javax.servlet.http.HttpServletRequest;
20
 import javax.servlet.http.HttpServletRequest;
18
 import javax.servlet.http.HttpServletResponse;
21
 import javax.servlet.http.HttpServletResponse;
19
 import java.util.Date;
22
 import java.util.Date;
110
                 }
113
                 }
111
                 // 设置消耗时间
114
                 // 设置消耗时间
112
                 operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
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
                 AsyncHelper.instance().execute(new TimerTask() {
126
                 AsyncHelper.instance().execute(new TimerTask() {
115
                     @Override
127
                     @Override

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

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