Skip to content

Commit 900ca22

Browse files
committed
代码优化
1 parent a9e12b5 commit 900ca22

26 files changed

Lines changed: 156 additions & 159 deletions

File tree

eladmin-generator/src/main/java/me/zhengjie/rest/GenConfigController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public GenConfigController(GenConfigService genConfigService) {
2626

2727
@ApiOperation("查询")
2828
@GetMapping(value = "/{tableName}")
29-
public ResponseEntity get(@PathVariable String tableName){
29+
public ResponseEntity<Object> get(@PathVariable String tableName){
3030
return new ResponseEntity<>(genConfigService.find(tableName), HttpStatus.OK);
3131
}
3232

3333
@ApiOperation("修改")
3434
@PutMapping
35-
public ResponseEntity emailConfig(@Validated @RequestBody GenConfig genConfig){
35+
public ResponseEntity<Object> emailConfig(@Validated @RequestBody GenConfig genConfig){
3636
return new ResponseEntity<>(genConfigService.update(genConfig.getTableName(), genConfig),HttpStatus.OK);
3737
}
3838
}

eladmin-generator/src/main/java/me/zhengjie/rest/GeneratorController.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public GeneratorController(GeneratorService generatorService, GenConfigService g
3838

3939
@ApiOperation("查询数据库数据")
4040
@GetMapping(value = "/tables/all")
41-
public ResponseEntity getTables(){
41+
public ResponseEntity<Object> getTables(){
4242
return new ResponseEntity<>(generatorService.getTables(), HttpStatus.OK);
4343
}
4444

4545
@ApiOperation("查询数据库数据")
4646
@GetMapping(value = "/tables")
47-
public ResponseEntity getTables(@RequestParam(defaultValue = "") String name,
47+
public ResponseEntity<Object> getTables(@RequestParam(defaultValue = "") String name,
4848
@RequestParam(defaultValue = "0")Integer page,
4949
@RequestParam(defaultValue = "10")Integer size){
5050
int[] startEnd = PageUtil.transToStartEnd(page+1, size);
@@ -53,7 +53,7 @@ public ResponseEntity getTables(@RequestParam(defaultValue = "") String name,
5353

5454
@ApiOperation("查询字段数据")
5555
@GetMapping(value = "/columns")
56-
public ResponseEntity getTables(@RequestParam String tableName){
56+
public ResponseEntity<Object> getTables(@RequestParam String tableName){
5757
List<ColumnInfo> columnInfos = generatorService.getColumns(tableName);
5858
// 异步同步表信息
5959
generatorService.sync(columnInfos);
@@ -62,14 +62,14 @@ public ResponseEntity getTables(@RequestParam String tableName){
6262

6363
@ApiOperation("保存字段数据")
6464
@PutMapping
65-
public ResponseEntity save(@RequestBody List<ColumnInfo> columnInfos){
65+
public ResponseEntity<HttpStatus> save(@RequestBody List<ColumnInfo> columnInfos){
6666
generatorService.save(columnInfos);
67-
return new ResponseEntity(HttpStatus.OK);
67+
return new ResponseEntity<>(HttpStatus.OK);
6868
}
6969

7070
@ApiOperation("生成代码")
7171
@PostMapping(value = "/{tableName}/{type}")
72-
public ResponseEntity generator(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){
72+
public ResponseEntity<Object> generator(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){
7373
if(!generatorEnabled && type == 0){
7474
throw new BadRequestException("此环境不允许生成代码,请选择预览或者下载查看!");
7575
}
@@ -84,6 +84,6 @@ public ResponseEntity generator(@PathVariable String tableName, @PathVariable In
8484
break;
8585
default: throw new BadRequestException("没有这个选项");
8686
}
87-
return new ResponseEntity(HttpStatus.OK);
87+
return new ResponseEntity<>(HttpStatus.OK);
8888
}
8989
}

eladmin-generator/src/main/java/me/zhengjie/service/GeneratorService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public interface GeneratorService {
6161
* @param columns 字段信息
6262
* @return /
6363
*/
64-
ResponseEntity preview(GenConfig genConfig, List<ColumnInfo> columns);
64+
ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns);
6565

6666
/**
6767
* 打包下载
6868
* @param genConfig 配置信息
6969
* @param columns 字段信息
70-
* @param request
71-
* @param response
70+
* @param request /
71+
* @param response /
7272
*/
7373
void download(GenConfig genConfig, List<ColumnInfo> columns, HttpServletRequest request, HttpServletResponse response);
7474
}

eladmin-logging/src/main/java/me/zhengjie/repository/LogRepository.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
2727

2828
/**
2929
* 根据日志类型删除信息
30-
* @param logType
30+
* @param logType 日志类型
3131
*/
3232
@Query(nativeQuery = true,value = "delete from log where log_type = ?1")
3333
@Modifying
34-
@Transactional
3534
void deleteByLogType(String logType);
3635
}

eladmin-logging/src/main/java/me/zhengjie/rest/LogController.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.springframework.http.ResponseEntity;
1212
import org.springframework.security.access.prepost.PreAuthorize;
1313
import org.springframework.web.bind.annotation.*;
14-
1514
import javax.servlet.http.HttpServletResponse;
1615
import java.io.IOException;
1716

@@ -50,14 +49,14 @@ public void errorDownload(HttpServletResponse response, LogQueryCriteria criteri
5049
@GetMapping
5150
@ApiOperation("日志查询")
5251
@PreAuthorize("@el.check()")
53-
public ResponseEntity getLogs(LogQueryCriteria criteria, Pageable pageable){
52+
public ResponseEntity<Object> getLogs(LogQueryCriteria criteria, Pageable pageable){
5453
criteria.setLogType("INFO");
5554
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
5655
}
5756

5857
@GetMapping(value = "/user")
5958
@ApiOperation("用户日志查询")
60-
public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
59+
public ResponseEntity<Object> getUserLogs(LogQueryCriteria criteria, Pageable pageable){
6160
criteria.setLogType("INFO");
6261
criteria.setBlurry(SecurityUtils.getUsername());
6362
return new ResponseEntity<>(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
@@ -66,32 +65,32 @@ public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
6665
@GetMapping(value = "/error")
6766
@ApiOperation("错误日志查询")
6867
@PreAuthorize("@el.check()")
69-
public ResponseEntity getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
68+
public ResponseEntity<Object> getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
7069
criteria.setLogType("ERROR");
7170
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
7271
}
7372

7473
@GetMapping(value = "/error/{id}")
7574
@ApiOperation("日志异常详情查询")
7675
@PreAuthorize("@el.check()")
77-
public ResponseEntity getErrorLogs(@PathVariable Long id){
76+
public ResponseEntity<Object> getErrorLogs(@PathVariable Long id){
7877
return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
7978
}
8079
@DeleteMapping(value = "/del/error")
8180
@Log("删除所有ERROR日志")
8281
@ApiOperation("删除所有ERROR日志")
8382
@PreAuthorize("@el.check()")
84-
public ResponseEntity delAllByError(){
83+
public ResponseEntity<Object> delAllByError(){
8584
logService.delAllByError();
86-
return new ResponseEntity(HttpStatus.OK);
85+
return new ResponseEntity<>(HttpStatus.OK);
8786
}
8887

8988
@DeleteMapping(value = "/del/info")
9089
@Log("删除所有INFO日志")
9190
@ApiOperation("删除所有INFO日志")
9291
@PreAuthorize("@el.check()")
93-
public ResponseEntity delAllByInfo(){
92+
public ResponseEntity<Object> delAllByInfo(){
9493
logService.delAllByInfo();
95-
return new ResponseEntity(HttpStatus.OK);
94+
return new ResponseEntity<>(HttpStatus.OK);
9695
}
9796
}

eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ private void sleep(int second) {
183183
private void backupApp(ExecuteShellUtil executeShellUtil, String ip, String fileSavePath, String appName, String backupPath, Long id) {
184184
String deployDate = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
185185
StringBuilder sb = new StringBuilder();
186-
if (!backupPath.endsWith(FILE_SEPARATOR)&&!backupPath.endsWith("\\")) {
186+
String endsWith = "\\";
187+
if (!backupPath.endsWith(FILE_SEPARATOR)&&!backupPath.endsWith(endsWith)) {
187188
backupPath += FILE_SEPARATOR;
188189
}
189190
backupPath += appName + FILE_SEPARATOR + deployDate + "\n";
@@ -259,8 +260,7 @@ public String serverStatus(Deploy resources) {
259260
}
260261

261262
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDto appDTO) {
262-
StringBuilder sb = new StringBuilder("find ").append(appDTO.getDeployPath()).append(" -name ").append(appDTO.getName());
263-
String result = executeShellUtil.executeForResult(sb.toString());
263+
String result = executeShellUtil.executeForResult("find " + appDTO.getDeployPath() + " -name " + appDTO.getName());
264264
return result.indexOf("/tcp:")>0;
265265
}
266266

eladmin-system/src/main/java/me/zhengjie/modules/monitor/rest/ServerController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ public ServerController(ServerService serverService) {
3232
@Log("查询服务监控")
3333
@ApiOperation("查询服务监控")
3434
@PreAuthorize("@el.check('server:list')")
35-
public ResponseEntity getServers(ServerQueryCriteria criteria, Pageable pageable){
35+
public ResponseEntity<Object> getServers(ServerQueryCriteria criteria, Pageable pageable){
3636
return new ResponseEntity<>(serverService.queryAll(criteria,pageable),HttpStatus.OK);
3737
}
3838

3939
@PostMapping
4040
@Log("新增服务监控")
4141
@ApiOperation("新增服务监控")
4242
@PreAuthorize("@el.check('server:add')")
43-
public ResponseEntity create(@Validated @RequestBody Server resources){
43+
public ResponseEntity<Object> create(@Validated @RequestBody Server resources){
4444
return new ResponseEntity<>(serverService.create(resources),HttpStatus.CREATED);
4545
}
4646

4747
@PutMapping
4848
@Log("修改服务监控")
4949
@ApiOperation("修改服务监控")
5050
@PreAuthorize("@el.check('server:edit')")
51-
public ResponseEntity update(@Validated @RequestBody Server resources){
51+
public ResponseEntity<Object> update(@Validated @RequestBody Server resources){
5252
serverService.update(resources);
53-
return new ResponseEntity(HttpStatus.NO_CONTENT);
53+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
5454
}
5555

5656
@DeleteMapping(value = "/{id}")

eladmin-system/src/main/java/me/zhengjie/modules/monitor/rest/VisitsController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ public VisitsController(VisitsService visitsService) {
2828

2929
@PostMapping
3030
@ApiOperation("创建访问记录")
31-
public ResponseEntity create(){
31+
public ResponseEntity<Object> create(){
3232
visitsService.count(RequestHolder.getHttpServletRequest());
33-
return new ResponseEntity(HttpStatus.CREATED);
33+
return new ResponseEntity<>(HttpStatus.CREATED);
3434
}
3535

3636
@GetMapping
3737
@ApiOperation("查询")
38-
public ResponseEntity get(){
38+
public ResponseEntity<Object> get(){
3939
return new ResponseEntity<>(visitsService.get(),HttpStatus.OK);
4040
}
4141

4242
@GetMapping(value = "/chartData")
4343
@ApiOperation("查询图表数据")
44-
public ResponseEntity getChartData(){
44+
public ResponseEntity<Object> getChartData(){
4545
return new ResponseEntity<>(visitsService.getChartData(),HttpStatus.OK);
4646
}
4747
}

eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public QuartzJobController(QuartzJobService quartzJobService) {
4040
@ApiOperation("查询定时任务")
4141
@GetMapping
4242
@PreAuthorize("@el.check('timing:list')")
43-
public ResponseEntity getJobs(JobQueryCriteria criteria, Pageable pageable){
43+
public ResponseEntity<Object> getJobs(JobQueryCriteria criteria, Pageable pageable){
4444
return new ResponseEntity<>(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK);
4545
}
4646

@@ -63,15 +63,15 @@ public void downloadLog(HttpServletResponse response, JobQueryCriteria criteria)
6363
@ApiOperation("查询任务执行日志")
6464
@GetMapping(value = "/logs")
6565
@PreAuthorize("@el.check('timing:list')")
66-
public ResponseEntity getJobLogs(JobQueryCriteria criteria, Pageable pageable){
66+
public ResponseEntity<Object> getJobLogs(JobQueryCriteria criteria, Pageable pageable){
6767
return new ResponseEntity<>(quartzJobService.queryAllLog(criteria,pageable), HttpStatus.OK);
6868
}
6969

7070
@Log("新增定时任务")
7171
@ApiOperation("新增定时任务")
7272
@PostMapping
7373
@PreAuthorize("@el.check('timing:add')")
74-
public ResponseEntity create(@Validated @RequestBody QuartzJob resources){
74+
public ResponseEntity<Object> create(@Validated @RequestBody QuartzJob resources){
7575
if (resources.getId() != null) {
7676
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
7777
}
@@ -82,35 +82,35 @@ public ResponseEntity create(@Validated @RequestBody QuartzJob resources){
8282
@ApiOperation("修改定时任务")
8383
@PutMapping
8484
@PreAuthorize("@el.check('timing:edit')")
85-
public ResponseEntity update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){
85+
public ResponseEntity<Object> update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){
8686
quartzJobService.update(resources);
87-
return new ResponseEntity(HttpStatus.NO_CONTENT);
87+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
8888
}
8989

9090
@Log("更改定时任务状态")
9191
@ApiOperation("更改定时任务状态")
9292
@PutMapping(value = "/{id}")
9393
@PreAuthorize("@el.check('timing:edit')")
94-
public ResponseEntity updateIsPause(@PathVariable Long id){
94+
public ResponseEntity<Object> updateIsPause(@PathVariable Long id){
9595
quartzJobService.updateIsPause(quartzJobService.findById(id));
96-
return new ResponseEntity(HttpStatus.NO_CONTENT);
96+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
9797
}
9898

9999
@Log("执行定时任务")
100100
@ApiOperation("执行定时任务")
101101
@PutMapping(value = "/exec/{id}")
102102
@PreAuthorize("@el.check('timing:edit')")
103-
public ResponseEntity execution(@PathVariable Long id){
103+
public ResponseEntity<Object> execution(@PathVariable Long id){
104104
quartzJobService.execution(quartzJobService.findById(id));
105-
return new ResponseEntity(HttpStatus.NO_CONTENT);
105+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
106106
}
107107

108108
@Log("删除定时任务")
109109
@ApiOperation("删除定时任务")
110110
@DeleteMapping(value = "/{id}")
111111
@PreAuthorize("@el.check('timing:del')")
112-
public ResponseEntity delete(@PathVariable Long id){
112+
public ResponseEntity<Object> delete(@PathVariable Long id){
113113
quartzJobService.delete(quartzJobService.findById(id));
114-
return new ResponseEntity(HttpStatus.OK);
114+
return new ResponseEntity<>(HttpStatus.OK);
115115
}
116116
}

eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public AuthController(SecurityProperties properties, RedisUtils redisUtils, User
7070
@ApiOperation("登录授权")
7171
@AnonymousAccess
7272
@PostMapping(value = "/login")
73-
public ResponseEntity login(@Validated @RequestBody AuthUser authUser, HttpServletRequest request){
73+
public ResponseEntity<Object> login(@Validated @RequestBody AuthUser authUser, HttpServletRequest request){
7474
// 密码解密
7575
RSA rsa = new RSA(privateKey, null);
7676
String password = new String(rsa.decrypt(authUser.getPassword(), KeyType.PrivateKey));
@@ -108,15 +108,15 @@ public ResponseEntity login(@Validated @RequestBody AuthUser authUser, HttpServl
108108

109109
@ApiOperation("获取用户信息")
110110
@GetMapping(value = "/info")
111-
public ResponseEntity getUserInfo(){
111+
public ResponseEntity<Object> getUserInfo(){
112112
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(SecurityUtils.getUsername());
113113
return ResponseEntity.ok(jwtUser);
114114
}
115115

116116
@AnonymousAccess
117117
@ApiOperation("获取验证码")
118118
@GetMapping(value = "/code")
119-
public ResponseEntity getCode(){
119+
public ResponseEntity<Object> getCode(){
120120
// 算术类型 https://gitee.com/whvse/EasyCaptcha
121121
ArithmeticCaptcha captcha = new ArithmeticCaptcha(111, 36);
122122
// 几位数运算,默认是两位
@@ -137,8 +137,8 @@ public ResponseEntity getCode(){
137137
@ApiOperation("退出登录")
138138
@AnonymousAccess
139139
@DeleteMapping(value = "/logout")
140-
public ResponseEntity logout(HttpServletRequest request){
140+
public ResponseEntity<Object> logout(HttpServletRequest request){
141141
onlineUserService.logout(tokenProvider.getToken(request));
142-
return new ResponseEntity(HttpStatus.OK);
142+
return new ResponseEntity<>(HttpStatus.OK);
143143
}
144144
}

0 commit comments

Comments
 (0)