Skip to content

Commit

Permalink
refactor some list search (#2516)
Browse files Browse the repository at this point in the history
* refactor-some-list-search

* Spotless Apply

* format code

---------

Co-authored-by: zhu-mingye <[email protected]>
  • Loading branch information
Zzm0809 and zhu-mingye authored Nov 11, 2023
1 parent 1c816ce commit 2a36f3b
Show file tree
Hide file tree
Showing 24 changed files with 303 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertGroup;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.service.AlertGroupService;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -65,7 +61,7 @@ public class AlertGroupController {
* @param alertGroup {@link AlertGroup}
* @return {@link Result} with {@link Void}
*/
@PutMapping
@PutMapping("/addOrUpdate")
@SaCheckPermission(
value = {PermissionConstants.REGISTRATION_ALERT_GROUP_ADD, PermissionConstants.REGISTRATION_ALERT_GROUP_EDIT
},
Expand All @@ -89,19 +85,13 @@ public Result<Void> saveOrUpdateAlertGroup(@RequestBody AlertGroup alertGroup) {
/**
* list alert groups
*
* @param para {@link JsonNode}
* @return {@link ProTableResult} with {@link AlertGroup}
* @param keyword {@link String}
* @return {@link Result} with {@link AlertGroup}
*/
@PostMapping
@ApiImplicitParam(
name = "para",
value = "JsonNode",
required = true,
dataType = "JsonNode",
dataTypeClass = JsonNode.class)
@GetMapping("/list")
@ApiOperation("Query AlertGroup List")
public ProTableResult<AlertGroup> listAlertGroups(@RequestBody JsonNode para) {
return alertGroupService.selectForProTable(para);
public Result<List<AlertGroup>> listAlertGroups(@RequestParam String keyword) {
return Result.succeed(alertGroupService.selectListByKeyWord(keyword));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertInstance;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.service.AlertInstanceService;

Expand All @@ -42,7 +41,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;

Expand All @@ -54,7 +52,9 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/** AlertInstanceController */
/**
* AlertInstanceController
*/
@Slf4j
@RestController
@Api(tags = "Alert Instance Controller")
Expand All @@ -71,7 +71,7 @@ public class AlertInstanceController {
* @return {@link Result} of {@link Void}
* @throws Exception {@link Exception}
*/
@PutMapping
@PutMapping("/saveOrUpdate")
@Log(title = "Insert OR Update AlertInstance", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("Insert OR Update AlertInstance")
@ApiImplicitParam(
Expand All @@ -98,21 +98,12 @@ public Result<Void> saveOrUpdate(@RequestBody AlertInstance alertInstance) throw

/**
* listAlertInstances
*
* @param para {@link JsonNode}
* @return {@link ProTableResult} of {@link AlertInstance}
* @return {@link Result} of {@link AlertInstance}
*/
@PostMapping
@GetMapping("/list")
@ApiOperation("Query AlertInstance List")
@ApiImplicitParam(
name = "para",
value = "Query Condition",
dataType = "JsonNode",
paramType = "body",
required = true,
dataTypeClass = JsonNode.class)
public ProTableResult<AlertInstance> listAlertInstances(@RequestBody JsonNode para) {
return alertInstanceService.selectForProTable(para);
public Result<List<AlertInstance>> listAlertInstances(@RequestParam(value = "keyword") String keyword) {
return Result.succeed(alertInstanceService.selectListByKeyWord(keyword));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.ClusterConfiguration;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.gateway.result.TestResult;
import org.dinky.service.ClusterConfigurationService;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -42,8 +40,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -70,7 +66,7 @@ public class ClusterConfigurationController {
* @param clusterConfiguration
* @return
*/
@PutMapping
@PutMapping("/saveOrUpdate")
@Log(title = "Insert Or Update Cluster Config", businessType = BusinessType.INSERT_OR_UPDATE)
@ApiOperation("Insert Or Update Cluster Config")
@ApiImplicitParam(
Expand Down Expand Up @@ -98,29 +94,13 @@ public Result<Void> saveOrUpdateClusterConfig(@RequestBody ClusterConfigurationD

/**
* query cluster config list
*
* @param para
* @param keyword
* @return
*/
@PostMapping
@GetMapping("/list")
@ApiOperation("Cluster Config List")
@ApiImplicitParam(
name = "para",
value = "Cluster Configuration",
dataType = "JsonNode",
paramType = "body",
required = true)
public ProTableResult<ClusterConfigurationDTO> listClusterConfigList(@RequestBody JsonNode para) {
ProTableResult<ClusterConfiguration> result = clusterConfigurationService.selectForProTable(para);
List<ClusterConfigurationDTO> dtoList =
result.getData().stream().map(ClusterConfigurationDTO::fromBean).collect(Collectors.toList());
return ProTableResult.<ClusterConfigurationDTO>builder()
.success(true)
.data(dtoList)
.total(result.getTotal())
.current(result.getCurrent())
.pageSize(result.getPageSize())
.build();
public Result<List<ClusterConfigurationDTO>> listClusterConfigList(@RequestParam String keyword) {
return Result.succeed(clusterConfigurationService.selectListByKeyWord(keyword));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckPermission;
Expand Down Expand Up @@ -156,12 +155,7 @@ public Result<Void> deleteClusterInstanceById(@RequestParam Integer id) {
required = true,
dataTypeClass = JsonNode.class)
public Result<List<ClusterInstance>> listClusterInstance(@RequestParam("keyword") String searchKeyWord) {
return Result.succeed(clusterInstanceService.list(new LambdaQueryWrapper<ClusterInstance>()
.like(ClusterInstance::getName, searchKeyWord)
.or()
.like(ClusterInstance::getAlias, searchKeyWord)
.or()
.like(ClusterInstance::getNote, searchKeyWord)));
return Result.succeed(clusterInstanceService.selectListByKeyWord(searchKeyWord));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.dinky.data.model.QueryData;
import org.dinky.data.model.Schema;
import org.dinky.data.model.SqlGeneration;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.metadata.driver.DriverPool;
import org.dinky.metadata.result.JdbcSelectResult;
Expand All @@ -50,8 +49,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand Down Expand Up @@ -107,27 +104,13 @@ public Result<Void> saveOrUpdateDataBase(@RequestBody DataBaseDTO dataBaseDTO) {
/**
* get all database
*
* @param para {@link JsonNode}
* @return {@link ProTableResult}< {@link DataBase}>
* @param keyword {@link String}
* @return {@link Result}< {@link DataBase}>
*/
@PostMapping
@GetMapping("/list")
@ApiOperation("DataBase Get All")
@ApiImplicitParam(
name = "para",
value = "JsonNode",
required = true,
dataType = "JsonNode",
paramType = "body",
dataTypeClass = JsonNode.class)
public ProTableResult<DataBase> listDataBases(@RequestBody JsonNode para) {
final ProTableResult<DataBase> result = databaseService.selectForProTable(para);
// 密码不返回
if (result != null && result.getData() != null) {
for (DataBase data : result.getData()) {
data.setPassword(null);
}
}
return result;
public Result<List<DataBase>> listDataBases(@RequestParam(value = "keyword") String keyword) {
return Result.succeed(databaseService.selectListByKeyWord(keyword));
}

/**
Expand Down Expand Up @@ -295,9 +278,9 @@ public Result<String> unCacheSchemasAndTables(@RequestParam Integer id) {
/**
* get columns of table
*
* @param id {@link Integer}
* @param id {@link Integer}
* @param schemaName {@link String}
* @param tableName {@link String}
* @param tableName {@link String}
* @return {@link Result}< {@link List}< {@link Column}>>
*/
@GetMapping("/listColumns")
Expand Down Expand Up @@ -387,9 +370,9 @@ public Result<JdbcSelectResult> execSql(@RequestBody QueryData queryData) {
/**
* get sql generation
*
* @param id {@link Integer}
* @param id {@link Integer}
* @param schemaName {@link String}
* @param tableName {@link String}
* @param tableName {@link String}
* @return {@link Result}< {@link SqlGeneration}>
*/
@GetMapping("/getSqlGeneration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public interface AlertGroupService extends ISuperService<AlertGroup> {
* @return {@link Boolean}
*/
Boolean deleteGroupById(Integer id);

List<AlertGroup> selectListByKeyWord(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ public interface AlertInstanceService extends ISuperService<AlertInstance> {
* @return {@link Boolean}
*/
Boolean modifyAlertInstanceStatus(Integer id);

List<AlertInstance> selectListByKeyWord(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ public interface ClusterConfigurationService extends ISuperService<ClusterConfig
* @return A boolean value indicating whether the modification was successful.
*/
Boolean modifyClusterConfigStatus(Integer id);

List<ClusterConfigurationDTO> selectListByKeyWord(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,6 @@ public interface ClusterInstanceService extends ISuperService<ClusterInstance> {
* @return {@link ClusterInstance}
*/
ClusterInstance deploySessionCluster(Integer id);

List<ClusterInstance> selectListByKeyWord(String searchKeyWord);
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,6 @@ public interface DataBaseService extends ISuperService<DataBase> {
* @return A {@link JobResult} object representing the execution result of the SQL statement.
*/
JobResult executeCommonSql(SqlDTO sqlDTO);

List<DataBase> selectListByKeyWord(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;

/** AlertGroupServiceImpl */
/**
* AlertGroupServiceImpl
*/
@Service
@RequiredArgsConstructor
public class AlertGroupServiceImpl extends SuperServiceImpl<AlertGroupMapper, AlertGroup> implements AlertGroupService {
Expand Down Expand Up @@ -100,4 +102,17 @@ public Boolean deleteGroupById(Integer id) {
.forEach(alertHistory -> alertHistoryService.removeById(alertHistory.getId()));
return removeById(id);
}

/**
* @param keyword
* @return
*/
@Override
public List<AlertGroup> selectListByKeyWord(String keyword) {
return getBaseMapper()
.selectList(new LambdaQueryWrapper<>(AlertGroup.class)
.like(AlertGroup::getName, keyword)
.or()
.like(AlertGroup::getNote, keyword));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ public Boolean modifyAlertInstanceStatus(Integer id) {
return updateById(alertInstance);
}

/**
* @param keyword
* @return
*/
@Override
public List<AlertInstance> selectListByKeyWord(String keyword) {
return getBaseMapper()
.selectList(new LambdaQueryWrapper<AlertInstance>()
.like(AlertInstance::getName, keyword)
.or()
.like(AlertInstance::getType, keyword));
}

private void writeBackGroupInformation(Map<Integer, Set<Integer>> alertGroupInformation) {
if (MapUtils.isEmpty(alertGroupInformation)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import org.dinky.service.ClusterConfigurationService;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.hutool.core.lang.Assert;
Expand Down Expand Up @@ -87,4 +89,17 @@ public Boolean modifyClusterConfigStatus(Integer id) {
}
return false;
}

/**
* @param keyword
* @return
*/
@Override
public List<ClusterConfigurationDTO> selectListByKeyWord(String keyword) {
return getBaseMapper()
.selectList(new LambdaQueryWrapper<ClusterConfiguration>().like(ClusterConfiguration::getName, keyword))
.stream()
.map(ClusterConfigurationDTO::fromBean)
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 2a36f3b

Please sign in to comment.