Skip to content

Commit

Permalink
[refactor] delete unuse code and deprecate code (#2183)
Browse files Browse the repository at this point in the history
* delete unuse code and deprecate code

* Spotless Apply

* modify some code

---------

Co-authored-by: zhu-mingye <[email protected]>
  • Loading branch information
Zzm0809 and zhu-mingye authored Aug 9, 2023
1 parent 65ea93a commit 74d746f
Show file tree
Hide file tree
Showing 91 changed files with 536 additions and 1,876 deletions.
4 changes: 2 additions & 2 deletions dinky-admin/src/main/java/org/dinky/aop/LogAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.dinky.aop;

import org.dinky.annotation.Log;
import org.dinky.context.UserInfoContextHolder;
import org.dinky.data.annotation.Log;
import org.dinky.data.enums.BusinessStatus;
import org.dinky.data.model.OperateLog;
import org.dinky.data.model.User;
Expand Down Expand Up @@ -60,7 +60,7 @@
@Component
public class LogAspect {

@Pointcut("@annotation(org.dinky.annotation.Log)")
@Pointcut("@annotation(org.dinky.data.annotation.Log)")
public void logPointCut() {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.dinky.controller;

import org.dinky.annotation.Log;
import org.dinky.data.annotation.Log;
import org.dinky.data.dto.APICancelDTO;
import org.dinky.data.dto.APIExecuteJarDTO;
import org.dinky.data.dto.APIExecuteSqlDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.dinky.controller;

import org.dinky.annotation.Log;
import org.dinky.data.annotation.Log;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertGroup;
Expand All @@ -29,7 +29,6 @@
import org.dinky.service.AlertGroupService;
import org.dinky.service.AlertHistoryService;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -65,9 +64,10 @@ public class AlertGroupController {
* @throws Exception {@link Exception}
*/
@PutMapping
@Log(title = "INSERT OR UPDATE AlertGroup ", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("INSERT OR UPDATE AlertGroup")
public Result<Void> saveOrUpdate(@RequestBody AlertGroup alertGroup) throws Exception {
@Log(title = "Insert OR Update AlertGroup ", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("Insert OR Update AlertGroup")
public Result<Void> saveOrUpdateAlertGroup(@RequestBody AlertGroup alertGroup)
throws Exception {
if (alertGroupService.saveOrUpdate(alertGroup)) {
return Result.succeed(Status.SAVE_SUCCESS);
} else {
Expand All @@ -87,42 +87,15 @@ public ProTableResult<AlertGroup> listAlertGroups(@RequestBody JsonNode para) {
return alertGroupService.selectForProTable(para);
}

/**
* batch Delete alert group , this method is {@link Deprecated} in the future , please use
* {@link #deleteGroupById(Integer)} instead
*
* @param para {@link JsonNode}
* @return {@link Result} with {@link Void}
*/
@DeleteMapping
public Result<Void> deleteMul(@RequestBody JsonNode para) {
if (para.size() > 0) {
List<Integer> error = new ArrayList<>();
for (final JsonNode item : para) {
Integer id = item.asInt();
if (!alertGroupService.removeById(id)) {
error.add(id);
}
}
if (error.size() == 0) {
return Result.succeed("删除成功");
} else {
return Result.succeed("删除部分成功,但" + error + "删除失败,共" + error.size() + "次失败。");
}
} else {
return Result.failed("请选择要删除的记录");
}
}

/**
* get all enabled alert group
*
* @return {@link Result} with {@link List} of {@link AlertGroup}
*/
@GetMapping("/listEnabledAll")
@ApiOperation("Query AlertGroup List Of Enable")
public Result<List<AlertGroup>> listEnabledAll() {
return Result.succeed(alertGroupService.listEnabledAll());
public Result<List<AlertGroup>> listEnabledAllAlertGroups() {
return Result.succeed(alertGroupService.listEnabledAllAlertGroups());
}

/**
Expand All @@ -133,8 +106,8 @@ public Result<List<AlertGroup>> listEnabledAll() {
@PutMapping("/enable")
@ApiOperation("Update AlertGroup Status")
@Log(title = "Update AlertGroup Status", businessType = BusinessType.UPDATE)
public Result<List<AlertGroup>> enable(@RequestParam("id") Integer id) {
if (alertGroupService.enable(id)) {
public Result<List<AlertGroup>> modifyAlertGroupStatus(@RequestParam("id") Integer id) {
if (alertGroupService.modifyAlertGroupStatus(id)) {
return Result.succeed(Status.MODIFY_SUCCESS);
} else {
return Result.failed(Status.MODIFY_FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.dinky.controller;

import org.dinky.annotation.Log;
import org.dinky.data.annotation.Log;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.model.AlertHistory;
import org.dinky.data.result.ProTableResult;
Expand Down Expand Up @@ -53,7 +53,7 @@ public class AlertHistoryController {
@PostMapping
@ApiOperation("Query Alert History")
@Log(title = "Query Alert History", businessType = BusinessType.QUERY)
public ProTableResult<AlertHistory> listAlertHistory(@RequestBody JsonNode para) {
public ProTableResult<AlertHistory> listAlertHistoryRecord(@RequestBody JsonNode para) {
return alertHistoryService.selectForProTable(para);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.dinky.alert.AlertPool;
import org.dinky.alert.AlertResult;
import org.dinky.annotation.Log;
import org.dinky.data.annotation.Log;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertInstance;
Expand Down Expand Up @@ -63,8 +63,8 @@ public class AlertInstanceController {
* @throws Exception {@link Exception}
*/
@PutMapping
@Log(title = "INSERT OR UPDATE AlertInstance", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("INSERT OR UPDATE AlertInstance")
@Log(title = "Insert OR Update AlertInstance", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("Insert OR Update AlertInstance")
public Result<Void> saveOrUpdate(@RequestBody AlertInstance alertInstance) throws Exception {
if (alertInstanceService.saveOrUpdate(alertInstance)) {
AlertPool.remove(alertInstance.getName());
Expand All @@ -81,25 +81,11 @@ public Result<Void> saveOrUpdate(@RequestBody AlertInstance alertInstance) throw
* @return {@link ProTableResult} of {@link AlertInstance}
*/
@PostMapping
@Log(title = "Query AlertInstance List", businessType = BusinessType.QUERY)
@ApiOperation("Query AlertInstance List")
public ProTableResult<AlertInstance> listAlertInstances(@RequestBody JsonNode para) {
return alertInstanceService.selectForProTable(para);
}

/**
* batch Delete AlertInstance, this method is {@link Deprecated} and will be removed in the
* future, please use {@link #deleteInstanceById(Integer)} instead.
*
* @param para
* @return
*/
@DeleteMapping
@Deprecated
public Result<Void> deleteMul(@RequestBody JsonNode para) {
return alertInstanceService.deleteAlertInstance(para);
}

/**
* delete AlertInstance by id
*
Expand All @@ -109,7 +95,7 @@ public Result<Void> deleteMul(@RequestBody JsonNode para) {
@DeleteMapping("/delete")
@Log(title = "Delete AlertInstance By Id", businessType = BusinessType.DELETE)
@ApiOperation("Delete AlertInstance By Id")
public Result<AlertInstance> deleteInstanceById(@RequestParam("id") Integer id) {
public Result<AlertInstance> deleteAlertInstanceById(@RequestParam("id") Integer id) {
if (alertInstanceService.deleteAlertInstance(id)) {
return Result.succeed(Status.DELETE_SUCCESS);
} else {
Expand All @@ -126,8 +112,8 @@ public Result<AlertInstance> deleteInstanceById(@RequestParam("id") Integer id)
@PutMapping("/enable")
@Log(title = "Update AlertInstance Status", businessType = BusinessType.UPDATE)
@ApiOperation("Update AlertInstance Status")
public Result<AlertInstance> enable(@RequestParam("id") Integer id) {
if (alertInstanceService.enable(id)) {
public Result<AlertInstance> modifyAlertInstanceStatus(@RequestParam("id") Integer id) {
if (alertInstanceService.modifyAlertInstanceStatus(id)) {
return Result.succeed(Status.MODIFY_SUCCESS);
} else {
return Result.failed(Status.MODIFY_FAILED);
Expand All @@ -140,7 +126,6 @@ public Result<AlertInstance> enable(@RequestParam("id") Integer id) {
* @return {@link Result} of {@link AlertInstance}
*/
@GetMapping("/listEnabledAll")
@Log(title = "Query AlertInstance List Of Enable", businessType = BusinessType.QUERY)
@ApiOperation("Query AlertInstance List Of Enable")
public Result<List<AlertInstance>> listEnabledAll() {
return Result.succeed(alertInstanceService.listEnabledAll());
Expand All @@ -155,7 +140,7 @@ public Result<List<AlertInstance>> listEnabledAll() {
@PostMapping("/sendTest")
@Log(title = "Test Send To AlertInstance", businessType = BusinessType.TEST)
@ApiOperation("Test Send To AlertInstance")
public Result<Void> sendTest(@RequestBody AlertInstance alertInstance) {
public Result<Void> sendAlertMsgTest(@RequestBody AlertInstance alertInstance) {
AlertResult alertResult = alertInstanceService.testAlert(alertInstance);
if (alertResult.getSuccess()) {
return Result.succeed(Status.SEND_TEST_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.dinky.controller;

import org.dinky.annotation.Log;
import org.dinky.data.annotation.Log;
import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
Expand All @@ -28,12 +28,8 @@
import org.dinky.function.constant.PathConstant;
import org.dinky.service.CatalogueService;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.List;
import java.util.UUID;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -85,8 +81,8 @@ public Result<String> upload(MultipartFile file, @PathVariable Integer id) {
Thread.sleep(1L);
if (!unzipFile.exists()) {
ZipUtil.unzip(zipPath, filePath);
Catalogue cata = getCatalogue(id, unzipFileName);
traverseFile(unzipPath, cata);
Catalogue cata = catalogueService.getCatalogue(id, unzipFileName);
catalogueService.traverseFile(unzipPath, cata);
}
} catch (Exception e) {
return Result.failed(e.getMessage());
Expand All @@ -96,98 +92,25 @@ public Result<String> upload(MultipartFile file, @PathVariable Integer id) {
return Result.succeed("上传zip包并创建工程成功");
}

private void traverseFile(String sourcePath, Catalogue catalog) {
File file = new File(sourcePath);
File[] fs = file.listFiles();
if (fs == null) {
throw new RuntimeException("目录层级有误");
}
for (File fl : fs) {
if (fl.isFile()) {
CatalogueTaskDTO dto =
getCatalogueTaskDTO(
fl.getName(),
catalogueService
.findByParentIdAndName(
catalog.getParentId(), catalog.getName())
.getId());
String fileText = getFileText(fl);
catalogueService.createCatalogAndFileTask(dto, fileText);
} else {
Catalogue newCata =
getCatalogue(
catalogueService
.findByParentIdAndName(
catalog.getParentId(), catalog.getName())
.getId(),
fl.getName());
traverseFile(fl.getPath(), newCata);
}
}
}

private String getFileText(File sourceFile) {
StringBuilder sb = new StringBuilder();
try (InputStreamReader isr =
new InputStreamReader(Files.newInputStream(sourceFile.toPath()));
BufferedReader br = new BufferedReader(isr)) {
if (sourceFile.isFile() && sourceFile.exists()) {

String lineText;
while ((lineText = br.readLine()) != null) {
sb.append(lineText).append("\n");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}

private Catalogue getCatalogue(Integer parentId, String name) {
Catalogue subcata = new Catalogue();
subcata.setTaskId(null);
subcata.setName(name);
subcata.setType("null");
subcata.setParentId(parentId);
subcata.setIsLeaf(false);
catalogueService.saveOrUpdate(subcata);
return subcata;
}

private CatalogueTaskDTO getCatalogueTaskDTO(String name, Integer parentId) {
CatalogueTaskDTO catalogueTaskDTO = new CatalogueTaskDTO();
catalogueTaskDTO.setName(UUID.randomUUID().toString().substring(0, 6) + name);
catalogueTaskDTO.setId(null);
catalogueTaskDTO.setParentId(parentId);
catalogueTaskDTO.setLeaf(true);
return catalogueTaskDTO;
}

/** 新增或者更新 */
/**
* insert or update catalogue
*
* @param catalogue
* @return Result<Void>
*/
@PutMapping
@Log(title = "Insert Or Update Catalogue", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("Insert Or Update Catalogue")
public Result<Void> saveOrUpdate(@RequestBody Catalogue catalogue) throws Exception {
public Result<Void> saveOrUpdateCatalogue(@RequestBody Catalogue catalogue) {
if (catalogueService.saveOrUpdate(catalogue)) {
return Result.succeed(Status.SAVE_SUCCESS);
} else {
return Result.failed(Status.SAVE_FAILED);
}
}

/** 获取指定ID的信息 */
@PostMapping("/getOneById")
@Log(title = "Get Catalogue Info By Id", businessType = BusinessType.QUERY)
@ApiOperation("Get Catalogue Info By Id")
public Result<Catalogue> getOneById(@RequestBody Catalogue catalogue) throws Exception {
catalogue = catalogueService.getById(catalogue.getId());
return Result.succeed(catalogue);
}

/** 获取所有目录 */
@PostMapping("/getCatalogueTreeData")
@Log(title = "Get Catalogue Tree Data", businessType = BusinessType.QUERY)
@ApiOperation("Get Catalogue Tree Data")
public Result<List<Catalogue>> getCatalogueTreeData() {
List<Catalogue> catalogues = catalogueService.getAllData();
Expand Down
Loading

0 comments on commit 74d746f

Please sign in to comment.