Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Dec 10, 2019
1 parent a9e12b5 commit 900ca22
Show file tree
Hide file tree
Showing 26 changed files with 156 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public GenConfigController(GenConfigService genConfigService) {

@ApiOperation("查询")
@GetMapping(value = "/{tableName}")
public ResponseEntity get(@PathVariable String tableName){
public ResponseEntity<Object> get(@PathVariable String tableName){
return new ResponseEntity<>(genConfigService.find(tableName), HttpStatus.OK);
}

@ApiOperation("修改")
@PutMapping
public ResponseEntity emailConfig(@Validated @RequestBody GenConfig genConfig){
public ResponseEntity<Object> emailConfig(@Validated @RequestBody GenConfig genConfig){
return new ResponseEntity<>(genConfigService.update(genConfig.getTableName(), genConfig),HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public GeneratorController(GeneratorService generatorService, GenConfigService g

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

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

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

@ApiOperation("保存字段数据")
@PutMapping
public ResponseEntity save(@RequestBody List<ColumnInfo> columnInfos){
public ResponseEntity<HttpStatus> save(@RequestBody List<ColumnInfo> columnInfos){
generatorService.save(columnInfos);
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation("生成代码")
@PostMapping(value = "/{tableName}/{type}")
public ResponseEntity generator(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){
public ResponseEntity<Object> generator(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){
if(!generatorEnabled && type == 0){
throw new BadRequestException("此环境不允许生成代码,请选择预览或者下载查看!");
}
Expand All @@ -84,6 +84,6 @@ public ResponseEntity generator(@PathVariable String tableName, @PathVariable In
break;
default: throw new BadRequestException("没有这个选项");
}
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public interface GeneratorService {
* @param columns 字段信息
* @return /
*/
ResponseEntity preview(GenConfig genConfig, List<ColumnInfo> columns);
ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns);

/**
* 打包下载
* @param genConfig 配置信息
* @param columns 字段信息
* @param request
* @param response
* @param request /
* @param response /
*/
void download(GenConfig genConfig, List<ColumnInfo> columns, HttpServletRequest request, HttpServletResponse response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification

/**
* 根据日志类型删除信息
* @param logType
* @param logType 日志类型
*/
@Query(nativeQuery = true,value = "delete from log where log_type = ?1")
@Modifying
@Transactional
void deleteByLogType(String logType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

Expand Down Expand Up @@ -50,14 +49,14 @@ public void errorDownload(HttpServletResponse response, LogQueryCriteria criteri
@GetMapping
@ApiOperation("日志查询")
@PreAuthorize("@el.check()")
public ResponseEntity getLogs(LogQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getLogs(LogQueryCriteria criteria, Pageable pageable){
criteria.setLogType("INFO");
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
}

@GetMapping(value = "/user")
@ApiOperation("用户日志查询")
public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getUserLogs(LogQueryCriteria criteria, Pageable pageable){
criteria.setLogType("INFO");
criteria.setBlurry(SecurityUtils.getUsername());
return new ResponseEntity<>(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
Expand All @@ -66,32 +65,32 @@ public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
@GetMapping(value = "/error")
@ApiOperation("错误日志查询")
@PreAuthorize("@el.check()")
public ResponseEntity getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
criteria.setLogType("ERROR");
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
}

@GetMapping(value = "/error/{id}")
@ApiOperation("日志异常详情查询")
@PreAuthorize("@el.check()")
public ResponseEntity getErrorLogs(@PathVariable Long id){
public ResponseEntity<Object> getErrorLogs(@PathVariable Long id){
return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
}
@DeleteMapping(value = "/del/error")
@Log("删除所有ERROR日志")
@ApiOperation("删除所有ERROR日志")
@PreAuthorize("@el.check()")
public ResponseEntity delAllByError(){
public ResponseEntity<Object> delAllByError(){
logService.delAllByError();
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}

@DeleteMapping(value = "/del/info")
@Log("删除所有INFO日志")
@ApiOperation("删除所有INFO日志")
@PreAuthorize("@el.check()")
public ResponseEntity delAllByInfo(){
public ResponseEntity<Object> delAllByInfo(){
logService.delAllByInfo();
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ private void sleep(int second) {
private void backupApp(ExecuteShellUtil executeShellUtil, String ip, String fileSavePath, String appName, String backupPath, Long id) {
String deployDate = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
StringBuilder sb = new StringBuilder();
if (!backupPath.endsWith(FILE_SEPARATOR)&&!backupPath.endsWith("\\")) {
String endsWith = "\\";
if (!backupPath.endsWith(FILE_SEPARATOR)&&!backupPath.endsWith(endsWith)) {
backupPath += FILE_SEPARATOR;
}
backupPath += appName + FILE_SEPARATOR + deployDate + "\n";
Expand Down Expand Up @@ -259,8 +260,7 @@ public String serverStatus(Deploy resources) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ public ServerController(ServerService serverService) {
@Log("查询服务监控")
@ApiOperation("查询服务监控")
@PreAuthorize("@el.check('server:list')")
public ResponseEntity getServers(ServerQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getServers(ServerQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(serverService.queryAll(criteria,pageable),HttpStatus.OK);
}

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

@PutMapping
@Log("修改服务监控")
@ApiOperation("修改服务监控")
@PreAuthorize("@el.check('server:edit')")
public ResponseEntity update(@Validated @RequestBody Server resources){
public ResponseEntity<Object> update(@Validated @RequestBody Server resources){
serverService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@DeleteMapping(value = "/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ public VisitsController(VisitsService visitsService) {

@PostMapping
@ApiOperation("创建访问记录")
public ResponseEntity create(){
public ResponseEntity<Object> create(){
visitsService.count(RequestHolder.getHttpServletRequest());
return new ResponseEntity(HttpStatus.CREATED);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping
@ApiOperation("查询")
public ResponseEntity get(){
public ResponseEntity<Object> get(){
return new ResponseEntity<>(visitsService.get(),HttpStatus.OK);
}

@GetMapping(value = "/chartData")
@ApiOperation("查询图表数据")
public ResponseEntity getChartData(){
public ResponseEntity<Object> getChartData(){
return new ResponseEntity<>(visitsService.getChartData(),HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public QuartzJobController(QuartzJobService quartzJobService) {
@ApiOperation("查询定时任务")
@GetMapping
@PreAuthorize("@el.check('timing:list')")
public ResponseEntity getJobs(JobQueryCriteria criteria, Pageable pageable){
public ResponseEntity<Object> getJobs(JobQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK);
}

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

@Log("新增定时任务")
@ApiOperation("新增定时任务")
@PostMapping
@PreAuthorize("@el.check('timing:add')")
public ResponseEntity create(@Validated @RequestBody QuartzJob resources){
public ResponseEntity<Object> create(@Validated @RequestBody QuartzJob resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
Expand All @@ -82,35 +82,35 @@ public ResponseEntity create(@Validated @RequestBody QuartzJob resources){
@ApiOperation("修改定时任务")
@PutMapping
@PreAuthorize("@el.check('timing:edit')")
public ResponseEntity update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){
public ResponseEntity<Object> update(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){
quartzJobService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

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

@Log("执行定时任务")
@ApiOperation("执行定时任务")
@PutMapping(value = "/exec/{id}")
@PreAuthorize("@el.check('timing:edit')")
public ResponseEntity execution(@PathVariable Long id){
public ResponseEntity<Object> execution(@PathVariable Long id){
quartzJobService.execution(quartzJobService.findById(id));
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Log("删除定时任务")
@ApiOperation("删除定时任务")
@DeleteMapping(value = "/{id}")
@PreAuthorize("@el.check('timing:del')")
public ResponseEntity delete(@PathVariable Long id){
public ResponseEntity<Object> delete(@PathVariable Long id){
quartzJobService.delete(quartzJobService.findById(id));
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public AuthController(SecurityProperties properties, RedisUtils redisUtils, User
@ApiOperation("登录授权")
@AnonymousAccess
@PostMapping(value = "/login")
public ResponseEntity login(@Validated @RequestBody AuthUser authUser, HttpServletRequest request){
public ResponseEntity<Object> login(@Validated @RequestBody AuthUser authUser, HttpServletRequest request){
// 密码解密
RSA rsa = new RSA(privateKey, null);
String password = new String(rsa.decrypt(authUser.getPassword(), KeyType.PrivateKey));
Expand Down Expand Up @@ -108,15 +108,15 @@ public ResponseEntity login(@Validated @RequestBody AuthUser authUser, HttpServl

@ApiOperation("获取用户信息")
@GetMapping(value = "/info")
public ResponseEntity getUserInfo(){
public ResponseEntity<Object> getUserInfo(){
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(SecurityUtils.getUsername());
return ResponseEntity.ok(jwtUser);
}

@AnonymousAccess
@ApiOperation("获取验证码")
@GetMapping(value = "/code")
public ResponseEntity getCode(){
public ResponseEntity<Object> getCode(){
// 算术类型 https://gitee.com/whvse/EasyCaptcha
ArithmeticCaptcha captcha = new ArithmeticCaptcha(111, 36);
// 几位数运算,默认是两位
Expand All @@ -137,8 +137,8 @@ public ResponseEntity getCode(){
@ApiOperation("退出登录")
@AnonymousAccess
@DeleteMapping(value = "/logout")
public ResponseEntity logout(HttpServletRequest request){
public ResponseEntity<Object> logout(HttpServletRequest request){
onlineUserService.logout(tokenProvider.getToken(request));
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public OnlineController(OnlineUserService onlineUserService) {
@ApiOperation("查询在线用户")
@GetMapping
@PreAuthorize("@el.check()")
public ResponseEntity getAll(String filter, Pageable pageable){
public ResponseEntity<Object> getAll(String filter, Pageable pageable){
return new ResponseEntity<>(onlineUserService.getAll(filter, pageable),HttpStatus.OK);
}

Expand All @@ -45,8 +45,8 @@ public void download(HttpServletResponse response, String filter) throws IOExcep
@ApiOperation("踢出用户")
@DeleteMapping(value = "/{key}")
@PreAuthorize("@el.check()")
public ResponseEntity delete(@PathVariable String key) throws Exception {
public ResponseEntity<Object> delete(@PathVariable String key) throws Exception {
onlineUserService.kickOut(key);
return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public OnlineUser getOne(String key) {

/**
* 检测用户是否在之前已经登录,已经登录踢下线
* @param userName
* @param userName 用户名
*/
public void checkLoginOnUser(String userName, String igoreToken){
List<OnlineUser> onlineUsers = getAll(userName);
Expand Down
Loading

0 comments on commit 900ca22

Please sign in to comment.