Feature: 开发对接前端控制台接口.

pull/10/head
chen.ma 3 years ago
parent ca42e2b522
commit 6549da27b8

@ -0,0 +1,22 @@
package com.github.dynamic.threadpool.console.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Web config.
*
* @author chen.ma
* @date 2021/11/9 22:56
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/index.html").addResourceLocations("classpath:/static/index.html");
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/static/");
}
}

@ -0,0 +1,31 @@
package com.github.dynamic.threadpool.console.controller;
import com.github.dynamic.threadpool.common.constant.Constants;
import com.github.dynamic.threadpool.common.web.base.Result;
import com.github.dynamic.threadpool.common.web.base.Results;
import com.github.dynamic.threadpool.console.model.ChartInfo;
import com.github.dynamic.threadpool.console.service.DashboardService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Dash board controller.
*
* @author chen.ma
* @date 2021/11/10 21:03
*/
@RestController
@AllArgsConstructor
@RequestMapping(Constants.BASE_PATH + "/dashboard")
public class DashboardController {
private final DashboardService dashboardService;
@GetMapping
public Result<ChartInfo> dashboard() {
return Results.success(dashboardService.getChartInfo());
}
}

@ -27,7 +27,8 @@ public class TenantController {
@PostMapping("/query/page") @PostMapping("/query/page")
public Result<IPage<TenantRespDTO>> queryNameSpacePage(@RequestBody TenantQueryReqDTO reqDTO) { public Result<IPage<TenantRespDTO>> queryNameSpacePage(@RequestBody TenantQueryReqDTO reqDTO) {
return Results.success(tenantService.queryTenantPage(reqDTO)); IPage<TenantRespDTO> resultPage = tenantService.queryTenantPage(reqDTO);
return Results.success(resultPage);
} }
@GetMapping("/query/{tenantId}") @GetMapping("/query/{tenantId}")
@ -36,21 +37,21 @@ public class TenantController {
} }
@PostMapping("/save") @PostMapping("/save")
public Result saveNameSpace(@RequestBody TenantSaveReqDTO reqDTO) { public Result<Boolean> saveNameSpace(@RequestBody TenantSaveReqDTO reqDTO) {
tenantService.saveTenant(reqDTO); tenantService.saveTenant(reqDTO);
return Results.success(); return Results.success(Boolean.TRUE);
} }
@PostMapping("/update") @PostMapping("/update")
public Result updateNameSpace(@RequestBody TenantUpdateReqDTO reqDTO) { public Result<Boolean> updateNameSpace(@RequestBody TenantUpdateReqDTO reqDTO) {
tenantService.updateTenant(reqDTO); tenantService.updateTenant(reqDTO);
return Results.success(); return Results.success(Boolean.TRUE);
} }
@DeleteMapping("/delete/{tenantId}") @DeleteMapping("/delete/{tenantId}")
public Result deleteNameSpace(@PathVariable("tenantId") String tenantId) { public Result<Boolean> deleteNameSpace(@PathVariable("tenantId") String tenantId) {
tenantService.deleteTenantById(tenantId); tenantService.deleteTenantById(tenantId);
return Results.success(); return Results.success(Boolean.TRUE);
} }
} }

@ -1,20 +1,30 @@
package com.github.dynamic.threadpool.console.controller; package com.github.dynamic.threadpool.console.controller;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.dynamic.threadpool.common.constant.Constants; import com.github.dynamic.threadpool.common.constant.Constants;
import com.github.dynamic.threadpool.common.model.InstanceInfo; import com.github.dynamic.threadpool.common.model.InstanceInfo;
import com.github.dynamic.threadpool.common.web.base.Result; import com.github.dynamic.threadpool.common.web.base.Result;
import com.github.dynamic.threadpool.common.web.base.Results; import com.github.dynamic.threadpool.common.web.base.Results;
import com.github.dynamic.threadpool.config.model.CacheItem;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolDelReqDTO;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolQueryReqDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolQueryReqDTO;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolRespDTO;
import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO; import com.github.dynamic.threadpool.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO;
import com.github.dynamic.threadpool.config.service.ConfigCacheService;
import com.github.dynamic.threadpool.config.service.biz.ThreadPoolService; import com.github.dynamic.threadpool.config.service.biz.ThreadPoolService;
import com.github.dynamic.threadpool.config.toolkit.BeanUtil;
import com.github.dynamic.threadpool.console.model.ThreadPoolInstanceInfo;
import com.github.dynamic.threadpool.discovery.core.BaseInstanceRegistry; import com.github.dynamic.threadpool.discovery.core.BaseInstanceRegistry;
import com.github.dynamic.threadpool.discovery.core.Lease; import com.github.dynamic.threadpool.discovery.core.Lease;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Map;
import static com.github.dynamic.threadpool.common.toolkit.ContentUtil.getGroupKey;
/** /**
* Thread pool controller. * Thread pool controller.
@ -24,34 +34,58 @@ import java.util.List;
*/ */
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
@RequestMapping(Constants.BASE_PATH + "/thread") @RequestMapping(Constants.BASE_PATH + "/thread/pool")
public class ThreadPoolController { public class ThreadPoolController {
private final ThreadPoolService threadPoolService; private final ThreadPoolService threadPoolService;
private final BaseInstanceRegistry baseInstanceRegistry; private final BaseInstanceRegistry baseInstanceRegistry;
@PostMapping("/pool/query/page") @PostMapping("/query/page")
public Result<IPage<ThreadPoolRespDTO>> queryNameSpacePage(@RequestBody ThreadPoolQueryReqDTO reqDTO) { public Result<IPage<ThreadPoolRespDTO>> queryNameSpacePage(@RequestBody ThreadPoolQueryReqDTO reqDTO) {
return Results.success(threadPoolService.queryThreadPoolPage(reqDTO)); return Results.success(threadPoolService.queryThreadPoolPage(reqDTO));
} }
@PostMapping("/pool/query") @PostMapping("/query")
public Result<ThreadPoolRespDTO> queryNameSpace(@RequestBody ThreadPoolQueryReqDTO reqDTO) { public Result<ThreadPoolRespDTO> queryNameSpace(@RequestBody ThreadPoolQueryReqDTO reqDTO) {
return Results.success(threadPoolService.getThreadPool(reqDTO)); return Results.success(threadPoolService.getThreadPool(reqDTO));
} }
@PostMapping("/pool/save_or_update}") @PostMapping("/save_or_update")
public Result saveOrUpdateThreadPoolConfig(@RequestParam(value = "identify", required = false) String identify, public Result saveOrUpdateThreadPoolConfig(@RequestParam(value = "identify", required = false) String identify,
@RequestBody ThreadPoolSaveOrUpdateReqDTO reqDTO) { @RequestBody ThreadPoolSaveOrUpdateReqDTO reqDTO) {
threadPoolService.saveOrUpdateThreadPoolConfig(identify, reqDTO); threadPoolService.saveOrUpdateThreadPoolConfig(identify, reqDTO);
return Results.success(); return Results.success();
} }
@GetMapping("/pool/list/instance/{itemId}") @GetMapping("/list/instance/{itemId}/{tpId}")
public Result<List<Lease<InstanceInfo>>> listInstance(@PathVariable("itemId") String itemId) { public Result<List<ThreadPoolInstanceInfo>> listInstance(@PathVariable("itemId") String itemId, @PathVariable("tpId") String tpId) {
List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId); List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId);
return Results.success(leases); Lease<InstanceInfo> first = CollUtil.getFirst(leases);
if (first == null) {
return Results.success(Lists.newArrayList());
}
InstanceInfo holder = first.getHolder();
String itemTenantKey = holder.getGroupKey();
String groupKey = getGroupKey(tpId, itemTenantKey);
Map<String, CacheItem> content = ConfigCacheService.getContent(groupKey);
List<ThreadPoolInstanceInfo> returnThreadPool = Lists.newArrayList();
content.forEach((key, val) -> {
ThreadPoolInstanceInfo threadPoolInstanceInfo = BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);
threadPoolInstanceInfo.setIdentify(key);
threadPoolInstanceInfo.setClientBasePath(holder.getClientBasePath());
returnThreadPool.add(threadPoolInstanceInfo);
});
return Results.success(returnThreadPool);
}
@DeleteMapping("/delete")
public Result deletePool(@RequestBody ThreadPoolDelReqDTO reqDTO) {
threadPoolService.deletePool(reqDTO);
return Results.success();
} }
} }

@ -1,8 +1,11 @@
package com.github.dynamic.threadpool.console.controller; package com.github.dynamic.threadpool.console.controller;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.dynamic.threadpool.auth.model.biz.user.UserQueryPageReqDTO;
import com.github.dynamic.threadpool.auth.model.biz.user.UserReqDTO;
import com.github.dynamic.threadpool.auth.model.biz.user.UserRespDTO; import com.github.dynamic.threadpool.auth.model.biz.user.UserRespDTO;
import com.github.dynamic.threadpool.auth.service.UserService; import com.github.dynamic.threadpool.auth.service.UserService;
import com.github.dynamic.threadpool.common.constant.Constants;
import com.github.dynamic.threadpool.common.web.base.Result; import com.github.dynamic.threadpool.common.web.base.Result;
import com.github.dynamic.threadpool.common.web.base.Results; import com.github.dynamic.threadpool.common.web.base.Results;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -18,30 +21,30 @@ import java.util.List;
*/ */
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
@RequestMapping({"/v1/auth", "/v1/auth/users"}) @RequestMapping(Constants.BASE_PATH + "/auth/users")
public class UserController { public class UserController {
private final UserService userService; private final UserService userService;
@GetMapping("/{pageNo}/{pageSize}") @PostMapping("/page")
public Result<IPage<UserRespDTO>> listUser(@PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) { public Result<IPage<UserRespDTO>> listUser(@RequestBody UserQueryPageReqDTO reqDTO) {
IPage<UserRespDTO> resultUserPage = userService.listUser(pageNo, pageSize); IPage<UserRespDTO> resultUserPage = userService.listUser(reqDTO);
return Results.success(resultUserPage); return Results.success(resultUserPage);
} }
@PostMapping("/{userName}/{password}") @PostMapping("/add")
public Result<Void> addUser(@PathVariable("userName") String userName, @PathVariable("password") String password) { public Result<Void> addUser(@RequestBody UserReqDTO reqDTO) {
userService.addUser(userName, password); userService.addUser(reqDTO);
return Results.success(); return Results.success();
} }
@PutMapping("/{userName}/{password}") @PutMapping("/update")
public Result<Void> updateUser(@PathVariable("userName") String userName, @PathVariable("password") String password) { public Result<Void> updateUser(@RequestBody UserReqDTO reqDTO) {
userService.updateUser(userName, password); userService.updateUser(reqDTO);
return Results.success(); return Results.success();
} }
@DeleteMapping("/{userName}") @DeleteMapping("/remove/{userName}")
public Result<Void> deleteUser(@PathVariable("userName") String userName) { public Result<Void> deleteUser(@PathVariable("userName") String userName) {
userService.deleteUser(userName); userService.deleteUser(userName);
return Results.success(); return Results.success();

@ -0,0 +1,31 @@
package com.github.dynamic.threadpool.console.model;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Char info.
*
* @author chen.ma
* @date 2021/11/10 21:06
*/
@Data
@Accessors(chain = true)
public class ChartInfo {
/**
*
*/
private Integer tenantCount;
/**
*
*/
private Integer itemCount;
/**
* 线
*/
private Integer threadPoolCount;
}

@ -0,0 +1,25 @@
package com.github.dynamic.threadpool.console.model;
import com.github.dynamic.threadpool.config.model.ConfigAllInfo;
import lombok.Data;
/**
* ThreadPool instance info.
*
* @author chen.ma
* @date 2021/11/11 23:39
*/
@Data
public class ThreadPoolInstanceInfo extends ConfigAllInfo {
/**
* identify
*/
private String identify;
/**
* clientBasePath
*/
private String clientBasePath;
}

@ -0,0 +1,20 @@
package com.github.dynamic.threadpool.console.service;
import com.github.dynamic.threadpool.console.model.ChartInfo;
/**
* Dashboard service.
*
* @author chen.ma
* @date 2021/11/1 21:06
*/
public interface DashboardService {
/**
* Get chart info.
*
* @return
*/
ChartInfo getChartInfo();
}

@ -0,0 +1,45 @@
package com.github.dynamic.threadpool.console.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.dynamic.threadpool.config.enums.DelEnum;
import com.github.dynamic.threadpool.config.mapper.ConfigInfoMapper;
import com.github.dynamic.threadpool.config.mapper.ItemInfoMapper;
import com.github.dynamic.threadpool.config.mapper.TenantInfoMapper;
import com.github.dynamic.threadpool.config.model.ConfigAllInfo;
import com.github.dynamic.threadpool.config.model.ItemInfo;
import com.github.dynamic.threadpool.config.model.TenantInfo;
import com.github.dynamic.threadpool.console.model.ChartInfo;
import com.github.dynamic.threadpool.console.service.DashboardService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* Dashboard service impl.
*
* @author chen.ma
* @date 2021/11/10 21:08
*/
@Service
@AllArgsConstructor
public class DashboardServiceImpl implements DashboardService {
private final TenantInfoMapper tenantInfoMapper;
private final ItemInfoMapper itemInfoMapper;
private final ConfigInfoMapper configInfoMapper;
@Override
public ChartInfo getChartInfo() {
Integer tenantCount = tenantInfoMapper.selectCount(Wrappers.lambdaQuery(TenantInfo.class).eq(TenantInfo::getDelFlag, DelEnum.NORMAL));
Integer itemCount = itemInfoMapper.selectCount(Wrappers.lambdaQuery(ItemInfo.class).eq(ItemInfo::getDelFlag, DelEnum.NORMAL));
Integer threadPoolCount = configInfoMapper.selectCount(Wrappers.lambdaQuery(ConfigAllInfo.class).eq(ConfigAllInfo::getDelFlag, DelEnum.NORMAL));
ChartInfo chartInfo = new ChartInfo();
chartInfo.setTenantCount(tenantCount)
.setItemCount(itemCount)
.setThreadPoolCount(threadPoolCount);
return chartInfo;
}
}
Loading…
Cancel
Save