kongx初始化
36
.gitignore
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
catalina.base_IS_UNDEFINED/
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
*.db
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
logs
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### maven ###
|
||||
.mvn
|
||||
mvnw
|
42
README.md
@ -1,37 +1,9 @@
|
||||
# kongx
|
||||
初始化
|
||||
|
||||
#### 介绍
|
||||
kong网关的可视化管理界面,更人性、更方便管理微服务的网关管理。
|
||||
##设置版本号
|
||||
mvn versions:set -DnewVersion=1.0.1
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 码云特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
|
||||
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
##设置错误回滚
|
||||
mvn versions:revert
|
||||
##提交
|
||||
mvn versions:commit
|
BIN
docs/dashboard.png
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
docs/plugin_add.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
docs/route_add.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
docs/route_plugin.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/service_list.png
Normal file
After Width: | Height: | Size: 87 KiB |
BIN
docs/service_route.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
docs/service_view.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/shell.png
Normal file
After Width: | Height: | Size: 102 KiB |
BIN
docs/upsream_targets.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
docs/upstream_healthcheck.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
docs/upstream_list.png
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
docs/upstream_view.png
Normal file
After Width: | Height: | Size: 19 KiB |
0
healthcheck.html
Normal file
46
kongx-common/pom.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>kongx</artifactId>
|
||||
<groupId>com.kongx</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>kongx-common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.2.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
50
kongx-common/src/main/java/com/kongx/common/KongxBanner.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.kongx.common;
|
||||
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.SpringBootVersion;
|
||||
import org.springframework.boot.ansi.AnsiColor;
|
||||
import org.springframework.boot.ansi.AnsiOutput;
|
||||
import org.springframework.boot.ansi.AnsiStyle;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class KongxBanner implements Banner {
|
||||
private static final String BANNER = " \\ \n" +
|
||||
" | , __. , __ ___. _ .-\n" +
|
||||
" | / .' \\ |' `. .' ` \\,' \n" +
|
||||
" |-< | | | | | | /\\ \n" +
|
||||
" / \\_ `._.' / | `---| / \\ \n" +
|
||||
" \\___/ \n";
|
||||
|
||||
private static final String SPRING_BOOT = " :: Spring Boot :: ";
|
||||
|
||||
private static final int STRAP_LINE_SIZE = 42;
|
||||
|
||||
@Override
|
||||
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream printStream) {
|
||||
this.print(" :: Support kong :: ", "(v1.2.1)", printStream);
|
||||
printStream.println(BANNER);
|
||||
String copyright = " :: Copyright@2020 :: ";
|
||||
String version = SpringBootVersion.getVersion();
|
||||
version = (version != null) ? " (v" + version + ")" : "";
|
||||
this.print(copyright, "raoxiaoyan", printStream);
|
||||
this.print(SPRING_BOOT, version, printStream);
|
||||
|
||||
printStream.println();
|
||||
}
|
||||
|
||||
private void print(String title, String msg, PrintStream printStream) {
|
||||
StringBuilder padding = new StringBuilder();
|
||||
while (padding.length() < STRAP_LINE_SIZE - (msg.length() + title.length())) {
|
||||
padding.append(" ");
|
||||
}
|
||||
|
||||
printStream.println(
|
||||
AnsiOutput.toString(
|
||||
AnsiColor.GREEN, title, AnsiColor.DEFAULT,
|
||||
padding.toString(), AnsiStyle.FAINT, msg
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.kongx.common.aop;
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.common.utils.JWTTokenUtils;
|
||||
import com.kongx.common.utils.Jackson2Helper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class LoginValidateInterceptor implements HandlerInterceptor {
|
||||
static Logger log = LoggerFactory.getLogger(LoginValidateInterceptor.class);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
log.info("LoginValidateInterceptor preHandle " + request.getRequestURL());
|
||||
log.debug("start try fetch user info...");
|
||||
Object dLoginUser = request.getSession().getAttribute("USER_INFO");
|
||||
String token = request.getHeader("Authorization");
|
||||
if (token == null || dLoginUser == null || !JWTTokenUtils.verify(token.replaceAll("Bearer ", ""))) {
|
||||
// 未登录,转向登录页面!
|
||||
JsonHeaderWrapper baseDTO = new JsonHeaderWrapper<>();
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
baseDTO.setErrmsg("Token已失效或用户未登录!");
|
||||
PrintWriter writer = response.getWriter();
|
||||
Map<String, Object> data = new HashMap<>(2);
|
||||
baseDTO.setData(data);
|
||||
baseDTO.setStatus(401);
|
||||
writer.print(Jackson2Helper.toJsonString(baseDTO));
|
||||
return false;
|
||||
}
|
||||
HandlerMethod method = (HandlerMethod) handler;
|
||||
Method method1 = method.getMethod();
|
||||
Class[] classes = method1.getParameterTypes();
|
||||
for (Class aClass : classes) {
|
||||
aClass.getAnnotation(PreAuthorize.class);
|
||||
}
|
||||
PreAuthorize preAuthorize = method.getMethodAnnotation(PreAuthorize.class);
|
||||
if (Optional.ofNullable(preAuthorize).isPresent()) {
|
||||
String value = preAuthorize.value();
|
||||
if ("".equals(value)) {
|
||||
return true;
|
||||
}
|
||||
Object list = request.getSession().getAttribute("PERMISSIONS");
|
||||
if (list != null) {
|
||||
Set<String> strings = (Set<String>) list;
|
||||
boolean authorize = strings.stream().filter((s) -> value.equalsIgnoreCase(s)).count() > 0;
|
||||
if (!authorize) {
|
||||
JsonHeaderWrapper baseDTO = new JsonHeaderWrapper<>();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/html; charset=utf-8");
|
||||
PrintWriter writer = response.getWriter();
|
||||
baseDTO.setErrmsg("拒绝访问");
|
||||
baseDTO.setStatus(403);
|
||||
writer.print(Jackson2Helper.toJsonString(baseDTO));
|
||||
}
|
||||
return authorize;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.kongx.common.aop;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface PreAuthorize {
|
||||
String value();
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.kongx.common.aop;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.web.bind.support.WebArgumentResolver;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class UserArgumentResolver implements WebArgumentResolver {
|
||||
static Logger log = LoggerFactory.getLogger(UserArgumentResolver.class);
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
|
||||
if (methodParameter.getParameterType().equals(UserInfo.class)) {
|
||||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
|
||||
UserInfo dLoginUser = (UserInfo) request.getSession().getAttribute("USER_INFO");
|
||||
if (dLoginUser == null) {
|
||||
dLoginUser = new UserInfo();
|
||||
}
|
||||
log.debug("LoginUser={}", dLoginUser);
|
||||
return dLoginUser;
|
||||
}
|
||||
return UNRESOLVED;
|
||||
}
|
||||
}
|
17
kongx-common/src/main/java/com/kongx/common/cache/CacheResults.java
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
package com.kongx.common.cache;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CacheResults<T> {
|
||||
private String type;
|
||||
private T data;
|
||||
|
||||
public CacheResults() {
|
||||
}
|
||||
|
||||
public CacheResults(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.kongx.common.config;
|
||||
|
||||
import com.kongx.common.aop.LoginValidateInterceptor;
|
||||
import com.kongx.common.aop.UserArgumentResolver;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Configurable
|
||||
public class KongxConfig implements WebMvcConfigurer {
|
||||
@Value("${portal.exclude.paths:/index,/authorize/login.do,/inner/monitor/ping,/health/check,/authorize/getUserInfo.do,/authorize/logout.do," +
|
||||
"/authorize/errorTimes.do,/index.html,/cdn/**,/css/**,/img/**,/js/**,/svg/**,/util/**,/favicon.ico}")
|
||||
private String excludePaths;
|
||||
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
argumentResolvers.add(new ServletWebArgumentResolverAdapter(new UserArgumentResolver()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new LoginValidateInterceptor()).excludePathPatterns(excludePaths.split(","));
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.kongx.common.core.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class BaseEntity extends PaginationQC {
|
||||
private int id;//主键
|
||||
private Date create_at = new Date(); //创建时间
|
||||
private String creator;//创建人
|
||||
private Date modify_at = new Date();//修改时间
|
||||
private String modifier;//修改人
|
||||
protected String remark;
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.kongx.common.core.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PaginationQC implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PaginationQC [page=" + page + ", start=" + start + ", limit=" + limit + "]";
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Integer getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Integer start) {
|
||||
if (start <= 0) {
|
||||
start = 0;
|
||||
}
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public Integer getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(Integer limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(String sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
|
||||
private Integer page = 0;
|
||||
private Integer start = 0;
|
||||
private Integer limit = 10;
|
||||
private String sort;
|
||||
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
package com.kongx.common.core.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用于HTML 与 Action的参数传递,Action与BO的传递
|
||||
* 1. HTML指定: 显示的页号(startIndex)、每页的记录数(pageSize)
|
||||
* 2. BO 指定 总记录数(totalCount)
|
||||
* 重新计算:currPageNo 从1开始
|
||||
* 填写一页的业务数据列表 List<E> items
|
||||
*
|
||||
* @param <E>
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PaginationSupport<E> implements java.io.Serializable {
|
||||
|
||||
|
||||
public final static int PAGESIZE = 25;
|
||||
|
||||
private int pageSize = PAGESIZE;
|
||||
|
||||
private List<E> items;
|
||||
|
||||
private int totalCount;
|
||||
|
||||
/**
|
||||
* 重0开始,代表记录序号
|
||||
*/
|
||||
private int startIndex = 0;
|
||||
|
||||
|
||||
/**
|
||||
* buli
|
||||
* 总页数 , 每次计算
|
||||
*/
|
||||
public PaginationSupport() {
|
||||
}
|
||||
|
||||
public PaginationSupport(List<E> items, int totalCount) {
|
||||
setPageSize(PAGESIZE);
|
||||
setTotalCount(totalCount);
|
||||
setItems(items);
|
||||
setStartIndex(0);
|
||||
}
|
||||
|
||||
public PaginationSupport(List<E> items, int totalCount, int startIndex) {
|
||||
setPageSize(PAGESIZE);
|
||||
setTotalCount(totalCount);
|
||||
setItems(items);
|
||||
setStartIndex(startIndex);
|
||||
}
|
||||
|
||||
public PaginationSupport(List<E> items, int totalCount, int pageSize, int startIndex) {
|
||||
setPageSize(pageSize);
|
||||
setTotalCount(totalCount);
|
||||
setItems(items);
|
||||
setStartIndex(startIndex);
|
||||
}
|
||||
|
||||
public List<E> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<E> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
computeStartIndex();
|
||||
}
|
||||
|
||||
public int getStartIndex() {
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTML提交,不能马上计算, 又了真正的 totalCount后,才能计算computeStartIndex()
|
||||
*
|
||||
* @param startIndex
|
||||
*/
|
||||
public void setStartIndex(int startIndex) {
|
||||
this.startIndex = startIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BO放入 totalCount后,要重新计算 当前页号
|
||||
* startIndex是从0开始的
|
||||
*/
|
||||
public int computeStartIndex() {
|
||||
if (totalCount <= 0) {
|
||||
this.startIndex = 0;
|
||||
}else if (startIndex >= totalCount) {
|
||||
this.startIndex = (getTotalPages() - 1) * pageSize;
|
||||
}else if (startIndex < 0) {
|
||||
this.startIndex = 0;
|
||||
}else {
|
||||
|
||||
}
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取出当前页号,从1开始
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getCurrPageNo() {
|
||||
return getStartIndex() / pageSize + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出总页数,从1开始
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTotalPages() {
|
||||
int totalPages = getTotalCount() / pageSize;
|
||||
if (getTotalCount() % pageSize > 0) {
|
||||
totalPages++;
|
||||
}
|
||||
if (totalPages <= 0) {
|
||||
totalPages = 1;
|
||||
}
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public int getNextIndex() {
|
||||
int nextIndex = getStartIndex() + pageSize;
|
||||
if (nextIndex >= totalCount) {
|
||||
return getStartIndex();
|
||||
} else {
|
||||
return nextIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public int getPreviousIndex() {
|
||||
int previousIndex = getStartIndex() - pageSize;
|
||||
if (previousIndex < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return previousIndex;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.kongx.common.core.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class UserInfo extends BaseEntity {
|
||||
|
||||
public static final String SUPER_ADMIN = "super_admin";
|
||||
|
||||
public static final String DOMESTIC_CONSUMER = "domestic_consumer";
|
||||
|
||||
public static final String MENUS = "menus";
|
||||
|
||||
public static final String PERMISSIONS = "permission";
|
||||
|
||||
private String userId;//用户Id
|
||||
|
||||
private String name;//用户名
|
||||
|
||||
private String email;//邮箱
|
||||
|
||||
private String password;//密码
|
||||
|
||||
private String mobile;//手机号
|
||||
|
||||
private String roleName = DOMESTIC_CONSUMER;//角色
|
||||
|
||||
private String status = "activate";
|
||||
|
||||
private String creator;
|
||||
|
||||
private Date create_at = new Date();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.kongx.common.exception;
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import feign.FeignException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@ControllerAdvice(basePackages = "com.kongx.kong")
|
||||
@Slf4j
|
||||
public class ExceptionGlobalHandler {
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = FeignException.class)
|
||||
public <T> JsonHeaderWrapper<T> errorHandler(FeignException ex) {
|
||||
FeignException exception = (FeignException) ex.getCause();
|
||||
JsonHeaderWrapper<T> jsonWrapper = new JsonHeaderWrapper<>();
|
||||
jsonWrapper.setStatus(ex.status());
|
||||
jsonWrapper.setErrmsg(ex.getMessage());
|
||||
log.info("Error msg{}", ex.getMessage());
|
||||
return jsonWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.kongx.common.handler;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JSONHandler<T extends Object> extends BaseTypeHandler<T> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JSONHandler.class);
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private Class<T> clazz;
|
||||
|
||||
static {
|
||||
mapper.configure(JsonParser.Feature.ALLOW_MISSING_VALUES, false);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
public JSONHandler(Class<T> clazz) {
|
||||
if (clazz == null) {
|
||||
throw new NullPointerException("Type argument cannot be null");
|
||||
}
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* object转json string
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
private String toJSON(T object) {
|
||||
try {
|
||||
String string = mapper.writeValueAsString(object);
|
||||
LOGGER.info(">>>> json execute string:{} <<<<", string);
|
||||
return string;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(">>>> covert object to json string failed, error message: <<<<", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* json转object
|
||||
*
|
||||
* @param json
|
||||
* @param clazz
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private T toObject(String json, Class<T> clazz) throws IOException {
|
||||
if (json != null && json != "") {
|
||||
return mapper.readValue(json, clazz);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement preparedStatement, int i, T t, JdbcType jdbcType) throws SQLException {
|
||||
try {
|
||||
preparedStatement.setString(i, toJSON(t));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(">>>> preparedStatement set string failed, error message:{} <<<<", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getNullableResult(ResultSet resultSet, String s) throws SQLException {
|
||||
try {
|
||||
return toObject(resultSet.getString(s), clazz);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(">>>> convert json string to object failed, error message:{} <<<<", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getNullableResult(ResultSet resultSet, int i) throws SQLException {
|
||||
try {
|
||||
return toObject(resultSet.getString(i), clazz);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(">>>> convert json string to object failed, error message:{} <<<<", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
|
||||
try {
|
||||
return toObject(callableStatement.getString(i), clazz);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(">>>> convert json string to object failed, error message:{} <<<<", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
package com.kongx.common.jsonwrapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 所有数据传输对象的父类 Created by liuyang on 2015/3/10.
|
||||
*/
|
||||
public class JsonHeaderWrapper<T extends Object> {
|
||||
|
||||
|
||||
/**
|
||||
* 当前数据结构的版本号, 版本升级意味着json数据结构变化
|
||||
*/
|
||||
private String version = "1.0";
|
||||
/**
|
||||
* 客户标识. 要求接口传入, 原值返回
|
||||
*/
|
||||
private String clientFrom;
|
||||
|
||||
/**
|
||||
* 服务器返回json时的时间戳
|
||||
*/
|
||||
private String timestamp;
|
||||
/**
|
||||
* 可选, http get请求的原始URL, post请求可不填写, 用于跟踪调试
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 0:全部成功, 202:部分成功, 405:接口超时返回,406客户流量超量, 500:全部失败, 505:传入参数错误(如:不存在的参数名称)
|
||||
*/
|
||||
private int status;
|
||||
/**
|
||||
* 可选, 错误信息, 当status不为0的时候必填
|
||||
*/
|
||||
private String errmsg;
|
||||
/**
|
||||
* 可选, 接口接到请求到返回数据花销的毫秒数, 建议填写
|
||||
*/
|
||||
private long elapsed;
|
||||
|
||||
/**
|
||||
* 必填, 用于表示本次会话的唯一ID
|
||||
*/
|
||||
private String trackId;
|
||||
/**
|
||||
* 可选, 安全限制 [内网(1),内网认证(2),公网(3),公网认证(4),IP限制(5)], 建议填写, 该值可能会在反向代理等节点做安全处理
|
||||
*/
|
||||
@JsonIgnore
|
||||
private int securType;
|
||||
/**
|
||||
* 业务数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/*
|
||||
*/
|
||||
public JsonHeaderWrapper() {
|
||||
clientFrom = "";
|
||||
url = "";
|
||||
status = StatusEnum.Success.getCode();
|
||||
errmsg = "";
|
||||
elapsed = 0;
|
||||
trackId = UUID.randomUUID().toString();
|
||||
securType = SecurTypeEnum.UnknownOther.getCode();
|
||||
data = null;
|
||||
}
|
||||
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getClientFrom() {
|
||||
return clientFrom;
|
||||
}
|
||||
|
||||
public void setClientFrom(String clientFrom) {
|
||||
this.clientFrom = clientFrom;
|
||||
}
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getErrmsg() {
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
public void setErrmsg(String errmsg) {
|
||||
this.errmsg = errmsg;
|
||||
}
|
||||
|
||||
public long getElapsed() {
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* public void setAcc_point(String acc_point) { this.acc_point = acc_point;
|
||||
* }
|
||||
*/
|
||||
public String getTrackId() {
|
||||
return trackId;
|
||||
}
|
||||
|
||||
public void setTrackId(String trackId) {
|
||||
this.trackId = trackId;
|
||||
}
|
||||
|
||||
public int getSecurType() {
|
||||
return securType;
|
||||
}
|
||||
|
||||
public void setSecurType(int securType) {
|
||||
this.securType = securType;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public enum SecurTypeEnum {
|
||||
/**
|
||||
* 安全限制 [内网(1),内网认证(2),公网(3),公网认证(4),IP限制(5)], 建议填写, 该值可能会在反向代理等节点做安全处理
|
||||
*/
|
||||
|
||||
InnerAcc(1, "内网"), InnerAuthAcc(2, "内网认证"), PublicAcc(3, "公网"), PublicAuthAcc(4, "公网认证"), IPAuthAcc(5, "IP限制"), UnknownOther(599, "未知类型");
|
||||
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCodee(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
SecurTypeEnum(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态枚举类
|
||||
*/
|
||||
public enum StatusEnum {
|
||||
|
||||
Success(0, "全部成功"), //
|
||||
Success4M(200, "全部成功"),
|
||||
//无线端统一使用200作为成功代码返回
|
||||
PartialSuccess(202, "库存数不足"), //
|
||||
Timeout(405, "接口超时返回"), //
|
||||
OverFlowCtrl(406, "客户流量超量"), //
|
||||
Failed(500, "全部失败"), //
|
||||
ParamError(505, "传入参数错误"), //
|
||||
UnknownOther(599, "未知错误,系统错误");
|
||||
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int value) {
|
||||
this.code = value;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
StatusEnum(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.kongx.common.utils;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class BaseUtils {
|
||||
private static String base64hash = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
public static String atob(String inStr) {
|
||||
if (inStr == null) return null;
|
||||
inStr = inStr.replaceAll("\\s|=", "");
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int cur;
|
||||
int prev = -1;
|
||||
int mod;
|
||||
int i = 0;
|
||||
while (i < inStr.length()) {
|
||||
cur = base64hash.indexOf(inStr.charAt(i));
|
||||
mod = i % 4;
|
||||
switch (mod) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
result.append(String.valueOf((char) (prev << 2 | cur >> 4)));
|
||||
break;
|
||||
case 2:
|
||||
result.append(String.valueOf((char) ((prev & 0x0f) << 4 | cur >> 2)));
|
||||
break;
|
||||
case 3:
|
||||
result.append(String.valueOf((char) ((prev & 3) << 6 | cur)));
|
||||
break;
|
||||
}
|
||||
prev = cur;
|
||||
i++;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String sha1(String psw) {
|
||||
if (StringUtils.isEmpty(psw)) {
|
||||
return null;
|
||||
} else {
|
||||
return DigestUtils.sha1Hex(psw);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(sha1("UmFveHkyMDE4"));
|
||||
}
|
||||
}
|
106
kongx-common/src/main/java/com/kongx/common/utils/DateUtils.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.kongx.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 描述:公共日期工具类
|
||||
*/
|
||||
public class DateUtils {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DateUtils.class);
|
||||
|
||||
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
|
||||
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static final String DATE_FORMAT_CHINESE = "yyyy年M月d日";
|
||||
|
||||
public static final String FORMAT_HH_MM = "HH:mm";
|
||||
|
||||
|
||||
public static long dateDiffMinute(Date start, Date end) {
|
||||
long diff = end.getTime() - start.getTime();
|
||||
return diff / 60 / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串日期转换为日期格式 自定義格式
|
||||
*
|
||||
* @param datestr
|
||||
* @return
|
||||
*/
|
||||
public static Date stringToDate(String datestr, String dateformat) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat df = new SimpleDateFormat(dateformat);
|
||||
try {
|
||||
date = df.parse(datestr);
|
||||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将日期格式日期转换为字符串格式 自定義格式
|
||||
*
|
||||
* @param date
|
||||
* @param dateformat
|
||||
* @return
|
||||
*/
|
||||
public static String dateToString(Date date, String dateformat) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
String datestr = null;
|
||||
SimpleDateFormat df = new SimpleDateFormat(dateformat);
|
||||
datestr = df.format(date);
|
||||
return datestr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期转换
|
||||
*
|
||||
* @param effectDateStr
|
||||
* @param pattern
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static Date parseDate(String effectDateStr, String pattern) throws ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
|
||||
Date effectDate = simpleDateFormat.parse(effectDateStr);
|
||||
return effectDate;
|
||||
}
|
||||
|
||||
|
||||
public static String getDateDiff(Date endDate, Date nowDate) {
|
||||
long nd = 1000 * 24 * 60 * 60;
|
||||
long nh = 1000 * 60 * 60;
|
||||
long nm = 1000 * 60;
|
||||
// 获得两个时间的毫秒时间差异
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
// 计算差多少天
|
||||
long day = diff / nd;
|
||||
// 计算差多少小时
|
||||
long hour = diff % nd / nh;
|
||||
// 计算差多少分钟
|
||||
long min = diff % nd % nh / nm;
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (day > 0) {
|
||||
result.append(day + "天");
|
||||
}
|
||||
if (hour > 0) {
|
||||
result.append(hour + "小时");
|
||||
}
|
||||
if (min > 0) {
|
||||
result.append(min + "分钟");
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.kongx.common.utils;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.JWTVerificationException;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
|
||||
public abstract class JWTTokenUtils {
|
||||
private final static String SECRET = "kongx";
|
||||
|
||||
public static String getToken(UserInfo user) {
|
||||
String token = "";
|
||||
token = JWT.create().withAudience(Jackson2Helper.toJsonString(user))
|
||||
.sign(Algorithm.HMAC256(SECRET));
|
||||
return token;
|
||||
}
|
||||
|
||||
public static UserInfo decode(String token) {
|
||||
String user = JWT.decode(token).getAudience().get(0);
|
||||
return Jackson2Helper.parsonObject(user, new TypeReference<UserInfo>() {
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean verify(String token) {
|
||||
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(SECRET)).build();
|
||||
try {
|
||||
DecodedJWT decodedJWT = jwtVerifier.verify(token);
|
||||
} catch (JWTVerificationException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.kongx.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Jackson2Helper {
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static Logger log = LoggerFactory.getLogger(Jackson2Helper.class);
|
||||
|
||||
public static final String toJsonString(Object obj) {
|
||||
if (null == obj) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Writer strWriter = new StringWriter();
|
||||
// mapper.writeValue(strWriter, obj);
|
||||
// return strWriter.toString();
|
||||
return MAPPER.writeValueAsString(obj);
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支持泛型
|
||||
*
|
||||
* @param jsonString
|
||||
* @param valueTypeRef
|
||||
* @return T
|
||||
* @Author 杨健/YangJian
|
||||
* @Date 2015年3月30日 下午12:35:45
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
public static final <T> T parsonObject(String jsonString, TypeReference<T> valueTypeRef) {
|
||||
try {
|
||||
|
||||
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
|
||||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return MAPPER.readValue(jsonString, valueTypeRef);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("parsonObject error ", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JsonNode readJson(String json) {
|
||||
try {
|
||||
return MAPPER.readTree(json);
|
||||
} catch (Exception e) {
|
||||
log.error("readJson error ", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T extends Object> List<T> jsonToList(String json, Class<T> bean) {
|
||||
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, bean);
|
||||
try {
|
||||
return MAPPER.readValue(json, javaType);
|
||||
} catch (IOException e) {
|
||||
log.error("jsonToList error ", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String vlaues = "[\"betadeva\",\"betadevb\",\"betaa\",\"betab\",\"betac\",\"betad\",\"betae\",\"betad\",\"betap\",\"betai\",\"betat\",\"prod\"]";
|
||||
List<String> values = Jackson2Helper.parsonObject(vlaues, new TypeReference<List<String>>() {
|
||||
});
|
||||
System.out.println(Jackson2Helper.toJsonString(values));
|
||||
}
|
||||
}
|
208
kongx-common/src/main/java/com/kongx/common/utils/WebUtil.java
Normal file
@ -0,0 +1,208 @@
|
||||
package com.kongx.common.utils;
|
||||
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* WebUtil 负责Cookie/Session等的管理。通常,所有对Cookie/Session的操作都通过此类来完成。 <br>
|
||||
*
|
||||
* @author shubing.wang
|
||||
* @date 2014-01-07
|
||||
* @version 1.0
|
||||
*/
|
||||
public class WebUtil {
|
||||
/**
|
||||
* 根据名字从Session中获取一个对象
|
||||
*
|
||||
* @param request
|
||||
* HttpServletRequest对象
|
||||
* @param name
|
||||
* Session中对象的名字
|
||||
* @return Object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getObject(HttpServletRequest request, String name) {
|
||||
return (T) request.getSession().getAttribute(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的name将一个对象保存到Session中
|
||||
*
|
||||
* @param request
|
||||
* HttpServletRequest对象
|
||||
* @param name
|
||||
* Session中对象的名字
|
||||
* @param object
|
||||
* 需要保存到Session的对象
|
||||
*/
|
||||
public static <T> void putObject(HttpServletRequest request, String name, T object) {
|
||||
request.getSession().setAttribute(name, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Session置为无效状态,通常在注销时调用
|
||||
*
|
||||
* @param request
|
||||
* HttpServletRequest
|
||||
*/
|
||||
public static void invalidateSession(HttpServletRequest request) {
|
||||
request.getSession().invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取URI的路径,如路径为http://www.example.com/example/user.do?method=add, 得到的值为"/example/user.do"
|
||||
*
|
||||
* @param request
|
||||
* @return String
|
||||
*/
|
||||
public static String getRequestURI(HttpServletRequest request) {
|
||||
return request.getRequestURI();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不包含应用名字的URI的路径, 并去掉最前面的"/", <br>
|
||||
* 如路径为http://r.daling.com:8080/appName/user/list.do, 得到的值为"user/list.do",其中appNames为应用的名字
|
||||
*
|
||||
* @param request
|
||||
* @return String
|
||||
*/
|
||||
public static String getNoAppNamedRequestURI(HttpServletRequest request) {
|
||||
String contextPath = request.getContextPath();
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.indexOf(contextPath) >= 0) {
|
||||
uri = uri.substring(contextPath.length());
|
||||
}
|
||||
while (uri.startsWith("/")) {
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
uri = uri.replaceAll("/+", "/");
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static String getHttpHeaderInfo(HttpServletRequest request) {
|
||||
Enumeration<String> names = request.getHeaderNames();
|
||||
StringBuilder buf =new StringBuilder(0);
|
||||
|
||||
|
||||
while (names.hasMoreElements()) {
|
||||
String name = (String)names.nextElement();
|
||||
buf.append(name+": "+request.getHeader(name)+" \n");
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取应用的根目录
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getContextPath(HttpServletRequest request) {
|
||||
String contextPath = request.getContextPath();
|
||||
if ("/".equals(contextPath)) {
|
||||
return "";
|
||||
}
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整请求路径(含内容路径及请求参数)
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getRequestURIWithParam(HttpServletRequest request) {
|
||||
return getRequestURI(request) + (request.getQueryString() == null ? "" : "?" + request.getQueryString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加cookie
|
||||
*
|
||||
* @param response
|
||||
* @param name
|
||||
* cookie的名称
|
||||
* @param value
|
||||
* cookie的值
|
||||
* @param maxAge
|
||||
* cookie存放的时间(以秒为单位,假如存放三天,即3*24*60*60; 如果值为0,cookie将随浏览器关闭而清除)
|
||||
*/
|
||||
public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {
|
||||
Cookie cookie = new Cookie(name, value);
|
||||
cookie.setPath("/");
|
||||
if (maxAge > 0) {
|
||||
cookie.setMaxAge(maxAge);
|
||||
}
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
public static void addCookie(HttpServletResponse response, String name, String value, int maxAge, String domain) {
|
||||
Cookie cookie = new Cookie(name, value);
|
||||
cookie.setPath("/");
|
||||
if (maxAge > 0) {
|
||||
cookie.setMaxAge(maxAge);
|
||||
}
|
||||
cookie.setDomain(domain);
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取cookie的值
|
||||
*
|
||||
* @param request
|
||||
* @param name
|
||||
* cookie的名称
|
||||
* @return
|
||||
*/
|
||||
public static String getCookieByName(HttpServletRequest request, String name) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (null != cookies) {
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
if (cookies[i].getName().equals(name)) {
|
||||
return cookies[i].getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getOSName(){
|
||||
String os ="Windows";
|
||||
if (System.getProperty("os.name").indexOf("Linux")!=-1 ) {
|
||||
os = "Linux";
|
||||
} else if (System.getProperty("os.name").indexOf("Windows")!=-1 ) {
|
||||
os ="Windows";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
public static void main(String[] s){
|
||||
String os = WebUtil.getOSName();
|
||||
System.out.println(os);
|
||||
}
|
||||
|
||||
private static String[] getVisitorIp(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return new String[]{"127.0.0.1"};
|
||||
}
|
||||
String ip = request.getHeader("X-Real-IP");
|
||||
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("X-Forwarded-For");
|
||||
}
|
||||
if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip.split("\\s,\\s");
|
||||
}
|
||||
|
||||
public static String getClientIp(HttpServletRequest request) {
|
||||
String[] ips = getVisitorIp(request);
|
||||
return (ips == null || ips.length == 0) ? "127.0.0.1" : ips[0];
|
||||
}
|
||||
}
|
127
kongx-serve/pom.xml
Normal file
@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>kongx</artifactId>
|
||||
<groupId>com.kongx</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>kongx-serve</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.kongx</groupId>
|
||||
<artifactId>kongx-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>1.8</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>5.0.11.RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.70</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<executable>true</executable>
|
||||
<mainClass>com.kongx.serve.Application</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>0.4.13</version>
|
||||
<configuration>
|
||||
<imageName>${project.artifactId}</imageName>
|
||||
<dockerDirectory>src/main/docker</dockerDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>*.zip</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/assembly-descriptor.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
46
kongx-serve/src/assembly/assembly-descriptor.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
|
||||
<id>kongx-assembly</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<!--scripts -->
|
||||
<fileSet>
|
||||
<directory>src/main/scripts</directory>
|
||||
<outputDirectory>scripts</outputDirectory>
|
||||
<includes>
|
||||
<include>*.sh</include>
|
||||
</includes>
|
||||
<fileMode>0755</fileMode>
|
||||
<lineEnding>unix</lineEnding>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>src/main/config</directory>
|
||||
<outputDirectory>./</outputDirectory>
|
||||
<includes>
|
||||
<include>kongx-serve.conf</include>
|
||||
</includes>
|
||||
<lineEnding>unix</lineEnding>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>./config</outputDirectory>
|
||||
<includes>
|
||||
<include>application.properties</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<!--artifact -->
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>./</outputDirectory>
|
||||
<includes>
|
||||
<include>${project.artifactId}-*.jar</include>
|
||||
</includes>
|
||||
<fileMode>0755</fileMode>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
3
kongx-serve/src/main/config/application.properties
Normal file
@ -0,0 +1,3 @@
|
||||
spring.datasource.url= @spring_datasource_url@
|
||||
spring.datasource.username= @spring_datasource_username@
|
||||
spring.datasource.password= @spring_datasource_password@
|
3
kongx-serve/src/main/config/kongx-serve.conf
Normal file
@ -0,0 +1,3 @@
|
||||
MODE=service
|
||||
PID_FOLDER=.
|
||||
LOG_FOLDER=/var/log/kongx/
|
24
kongx-serve/src/main/java/com/kongx/serve/Application.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.kongx.serve;
|
||||
|
||||
import com.kongx.common.KongxBanner;
|
||||
import com.kongx.common.config.KongxConfig;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@SpringBootApplication()
|
||||
@EnableFeignClients(basePackages = "com.kongx")
|
||||
@Configurable
|
||||
@Import(KongxConfig.class)
|
||||
@MapperScan("com.kongx.serve.mapper")
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(Application.class);
|
||||
application.setBanner(new KongxBanner());
|
||||
application.run(args);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.kongx.serve.config;
|
||||
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class FastJsonConfiguration {
|
||||
@Bean
|
||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||
FastJsonHttpMessageConverter fasHttpMessageConverter = new FastJsonHttpMessageConverter();
|
||||
HttpMessageConverter<?> converter = fasHttpMessageConverter;
|
||||
|
||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
List<MediaType> fastMediaTypes = new ArrayList<>();
|
||||
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
fastMediaTypes.add(MediaType.TEXT_HTML);
|
||||
fastMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
fasHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
|
||||
fasHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
|
||||
|
||||
return new HttpMessageConverters(converter);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.kongx.serve.config;
|
||||
|
||||
import feign.Logger;
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.cloud.openfeign.support.SpringEncoder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FormSupportConfig {
|
||||
@Autowired
|
||||
private ObjectFactory<HttpMessageConverters> messageConverters;
|
||||
|
||||
/**
|
||||
* new一个form编码器,实现支持form表单提交
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
public Encoder feignFormEncoder() {
|
||||
return new SpringFormEncoder(new SpringEncoder(messageConverters));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启Feign的日志
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Logger.Level logger() {
|
||||
return Logger.Level.FULL;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.kongx.serve.config;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class KongRequestInterceptor implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate template) {
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.kongx.serve.config;
|
||||
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class MyBatisConfiguration {
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory( DataSource dataSource) throws Exception {
|
||||
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
factoryBean.setVfs(SpringBootVFS.class);
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
package com.kongx.serve.controller;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.common.utils.JWTTokenUtils;
|
||||
import com.kongx.serve.entity.system.Menu;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.ServerConfig;
|
||||
import com.kongx.serve.service.system.ServerConfigService;
|
||||
import com.kongx.serve.service.system.UserInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
|
||||
import static com.kongx.common.core.entity.UserInfo.SUPER_ADMIN;
|
||||
|
||||
/**
|
||||
* @ClassName AuthorizeEndpoint
|
||||
* @Description TODO
|
||||
* @Author raoxiaoyan
|
||||
* @Date 2019/3/20 15:06
|
||||
* @Version 1.0
|
||||
**/
|
||||
@RequestMapping
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class AuthorizeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ServerConfigService serverConfigService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@RequestMapping(value = "/authorize/login.do", method = RequestMethod.POST)
|
||||
public ResponseEntity<JsonHeaderWrapper<String>> authorize(HttpServletRequest request, HttpServletResponse response) {
|
||||
JsonHeaderWrapper<String> jsonHeaderWrapper = init();
|
||||
try {
|
||||
UserInfo userInfo = userInfoService.login(request.getParameter("username"), request.getParameter("password"));
|
||||
jsonHeaderWrapper.setData(JWTTokenUtils.getToken(userInfo));
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_LOGIN, OperationLog.OperationTarget.SYSTEM, userInfo);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(500);
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return new ResponseEntity<>(jsonHeaderWrapper, HttpStatus.OK);
|
||||
}
|
||||
|
||||
public final static String COOKIE_ACCESS_TOKEN = "E_ACCESS_TOKEN";
|
||||
|
||||
public static String getAccessToken(HttpServletRequest request) {
|
||||
String accessToken = getCookieByName(request, COOKIE_ACCESS_TOKEN);
|
||||
if (StringUtils.isEmpty(accessToken)) {
|
||||
accessToken = request.getHeader(COOKIE_ACCESS_TOKEN);
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public static String getCookieByName(HttpServletRequest request, String name) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (null != cookies) {
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
if (cookies[i].getName().equals(name)) {
|
||||
return cookies[i].getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/authorize/getUserInfo.do", method = RequestMethod.GET)
|
||||
public ResponseEntity<JsonHeaderWrapper> getUserInfo(HttpServletRequest request) {
|
||||
Map<String, Object> results = new HashMap<>(3);
|
||||
String token = getAccessToken(request);
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
UserInfo userInfo = JWTTokenUtils.decode(token);
|
||||
UserInfo entityUserInfo = this.userInfoService.findById(userInfo.getUserId());
|
||||
List list = new ArrayList<>();
|
||||
list.add("");
|
||||
results.put("roles", list);
|
||||
ServerConfig superServerConfig = this.serverConfigService.findByKey(SUPER_ADMIN);
|
||||
String[] nameList = superServerConfig.getConfigValue().split(",");
|
||||
long cnt = Arrays.stream(nameList).filter((name) -> userInfo.getUserId().equals(name)).count();
|
||||
//为超级管理员
|
||||
if (cnt > 0) {
|
||||
entityUserInfo.setRoleName(SUPER_ADMIN);
|
||||
}
|
||||
results.put("userInfo", entityUserInfo);
|
||||
Set<String> pointCodes = new HashSet<>();
|
||||
Optional<List<Menu>> optional = this.userInfoService.findAllMenu(entityUserInfo, null, "point", this.systemProfile(userInfo));
|
||||
optional.get().stream().forEach((menu -> pointCodes.add(menu.getCode())));
|
||||
results.put("permission", pointCodes);
|
||||
request.getSession().setAttribute("USER_INFO", entityUserInfo);
|
||||
request.getSession().setAttribute("PERMISSIONS", pointCodes);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(500);
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return new ResponseEntity<>(jsonHeaderWrapper, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/authorize/getMenu.do", method = RequestMethod.GET)
|
||||
public ResponseEntity<JsonHeaderWrapper> getMenu(UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.userInfoService.findAllMenu(userInfo, -1, "menu", this.systemProfile(userInfo)));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(500);
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return new ResponseEntity<>(jsonHeaderWrapper, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/authorize/logout.do", method = RequestMethod.GET)
|
||||
public ResponseEntity<JsonHeaderWrapper> logout(HttpServletRequest request, HttpServletResponse response) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
|
||||
return new ResponseEntity<>(jsonHeaderWrapper, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.kongx.serve.controller;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import com.kongx.serve.service.system.LogService;
|
||||
import com.kongx.serve.service.system.SystemProfileService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public abstract class BaseController<T> {
|
||||
|
||||
@Autowired
|
||||
private SystemProfileService systemProfileService;
|
||||
|
||||
@Autowired
|
||||
protected LogService logService;
|
||||
|
||||
public Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public JsonHeaderWrapper init() {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = new JsonHeaderWrapper();
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
protected SystemProfile systemProfile(UserInfo userInfo) {
|
||||
return this.systemProfileService.getClientByName(userInfo.getUserId());
|
||||
}
|
||||
|
||||
protected void log(UserInfo userInfo, OperationLog.OperationType operationType, OperationLog.OperationTarget operationTarget, Object content) {
|
||||
OperationLog operationLog = to(userInfo, operationType, operationTarget, content);
|
||||
this.logService.log(systemProfile(userInfo), operationLog);
|
||||
}
|
||||
|
||||
private OperationLog to(UserInfo userInfo, OperationLog.OperationType operationType, OperationLog.OperationTarget operationTarget, Object content) {
|
||||
OperationLog operationLog = new OperationLog();
|
||||
SystemProfile systemProfile = this.systemProfile(userInfo);
|
||||
operationLog.setUserId(userInfo.getUserId());
|
||||
operationLog.setCreator(userInfo.getName());
|
||||
operationLog.setTarget(operationTarget.getType());
|
||||
operationLog.setOperation(operationType.getType());
|
||||
operationLog.setProfile(systemProfile.getProfile());
|
||||
operationLog.setContent(content);
|
||||
operationLog.setRemark(String.format("%s %s %s", operationLog.getCreator(), operationType.getRemark(), operationTarget.getTarget()));
|
||||
return operationLog;
|
||||
}
|
||||
|
||||
protected void log(UserInfo userInfo, OperationLog.OperationType operationType, OperationLog.OperationTarget operationTarget, Object content, String remark) {
|
||||
OperationLog operationLog = to(userInfo, operationType, operationTarget, content);
|
||||
operationLog.setRemark(String.format("%s %s %s %s", operationLog.getCreator(), operationType.getRemark(), operationTarget.getTarget(), remark));
|
||||
this.logService.log(systemProfile(userInfo), operationLog);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.kongx.serve.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class HealthCheckController {
|
||||
|
||||
@RequestMapping(value = "/inner/monitor/ping")
|
||||
public void ping(HttpServletResponse response) {
|
||||
int status = 200;
|
||||
File file = new File("./healthcheck.html");
|
||||
if (!file.exists()) {
|
||||
status = 404;
|
||||
}
|
||||
response.setStatus(status);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/health/check")
|
||||
public void check(HttpServletResponse response) {
|
||||
response.setStatus(200);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.kongx.serve.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author raoxiaoyan
|
||||
*/
|
||||
@Controller
|
||||
public class SignInController {
|
||||
|
||||
@GetMapping("/index")
|
||||
public String login(@RequestParam(value = "error", required = false) String error,
|
||||
@RequestParam(value = "logout", required = false) String logout) {
|
||||
return "index.html";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.gateway.Consumer;
|
||||
import com.kongx.serve.entity.gateway.KongEntity;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.service.gateway.ConsumerService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@RestController("consumerController")
|
||||
@RequestMapping("/kong/api/")
|
||||
@Slf4j
|
||||
public class ConsumerController extends BaseController {
|
||||
private static final String CONSUMER_URI = "/consumers";
|
||||
private static final String CONSUMER_URI_ID = "/consumers/{id}";
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
/**
|
||||
* 查询所有upstream
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = CONSUMER_URI, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<Consumer> upstreamKongEntity = consumerService.findAll(systemProfile(userInfo));
|
||||
jsonHeaderWrapper.setData(upstreamKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增upstream
|
||||
*
|
||||
* @param consumer
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = CONSUMER_URI, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper addUpstream(UserInfo userInfo, @RequestBody Consumer consumer) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Consumer results = this.consumerService.add(systemProfile(userInfo), consumer.trim());
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.UPSTREAM, consumer.getUsername());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新consumer
|
||||
*
|
||||
* @param id
|
||||
* @param consumer
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = CONSUMER_URI_ID, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(UserInfo userInfo, @PathVariable String id, @RequestBody Consumer consumer) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Consumer results = this.consumerService.update(systemProfile(userInfo), id, consumer.trim());
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.UPSTREAM, consumer, consumer.getUsername());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除consumer
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = CONSUMER_URI_ID, method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(UserInfo userInfo, @PathVariable String id) throws Exception {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Consumer consumer = this.consumerService.findConsumer(systemProfile(userInfo), id);
|
||||
KongEntity<Consumer> upstreamKongEntity = this.consumerService.remove(systemProfile(userInfo), id);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_DELETE, OperationLog.OperationTarget.UPSTREAM, consumer);
|
||||
jsonHeaderWrapper.setData(upstreamKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个consumer的信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = CONSUMER_URI_ID, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findUpstream(UserInfo userInfo, @PathVariable String id) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Consumer results = this.consumerService.findConsumer(systemProfile(userInfo), id);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.service.gateway.KongInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController("/KongInfoController")
|
||||
@RequestMapping("/kong/api/")
|
||||
public class KongInfoController extends BaseController {
|
||||
private static final String INFO_URI = "/info";
|
||||
private static final String STATUS_URI = "/status";
|
||||
@Autowired
|
||||
private KongInfoService kongInfoService;
|
||||
|
||||
@RequestMapping(value = INFO_URI, method = RequestMethod.GET)
|
||||
public Map info(UserInfo userInfo) throws URISyntaxException {
|
||||
return kongInfoService.info(systemProfile(userInfo));
|
||||
}
|
||||
|
||||
@RequestMapping(value = STATUS_URI, method = RequestMethod.GET)
|
||||
public Map status(UserInfo userInfo) throws URISyntaxException {
|
||||
return kongInfoService.status(systemProfile(userInfo));
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.gateway.*;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.service.gateway.PluginService;
|
||||
import com.kongx.serve.service.gateway.RouteService;
|
||||
import com.kongx.serve.service.gateway.ServiceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController("/PluginController")
|
||||
@RequestMapping("/kong/api/")
|
||||
@Import(FeignClientsConfiguration.class)
|
||||
public class PluginController extends BaseController {
|
||||
private static final String PLUGIN_URI = "/plugins";
|
||||
private static final String PLUGIN_ROUTE_URI_PATH = "/routes/{routeId}/plugins";
|
||||
private static final String PLUGIN_SERVICE_URI_PATH = "/services/{serviceId}/plugins";
|
||||
private static final String PLUGIN_URI_ID_PATH = "/plugins/{id}";
|
||||
private static final String PLUGIN_URI_SCHEMA_PATH = "/plugins/schema/{name}";
|
||||
@Autowired
|
||||
private PluginService kongFeignService;
|
||||
|
||||
@Autowired
|
||||
private RouteService routeService;
|
||||
|
||||
@Autowired
|
||||
private ServiceService serviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有plugin
|
||||
*
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = PLUGIN_URI, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<PluginVO> pluginVOKongEntity = this.kongFeignService.findAll(systemProfile(userInfo));
|
||||
jsonHeaderWrapper.setData(pluginVOKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = PLUGIN_ROUTE_URI_PATH, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAllByRoute(UserInfo userInfo, @PathVariable String routeId) throws URISyntaxException {
|
||||
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<PluginVO> pluginVOKongEntity = this.kongFeignService.findAllByRoute(systemProfile(userInfo), routeId);
|
||||
jsonHeaderWrapper.setData(pluginVOKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = PLUGIN_SERVICE_URI_PATH, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAllByService(UserInfo userInfo, @PathVariable String serviceId) throws URISyntaxException {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<PluginVO> pluginVOKongEntity = this.kongFeignService.findAllByService(systemProfile(userInfo), serviceId);
|
||||
jsonHeaderWrapper.setData(pluginVOKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = PLUGIN_URI_SCHEMA_PATH, method = RequestMethod.GET)
|
||||
public Map findPluginSchema(UserInfo userInfo, @PathVariable String name) throws URISyntaxException {
|
||||
return this.kongFeignService.findPluginSchema(systemProfile(userInfo), name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增全局的plugin
|
||||
*
|
||||
* @param plugin
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = PLUGIN_URI, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper<Plugin> add(UserInfo userInfo, @RequestBody Plugin plugin) {
|
||||
JsonHeaderWrapper<Plugin> jsonHeaderWrapper = init();
|
||||
try {
|
||||
Plugin result = this.kongFeignService.add(systemProfile(userInfo), plugin);
|
||||
jsonHeaderWrapper.setData(result);
|
||||
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.GLOBAL_PLUGIN, plugin, remark(userInfo, plugin));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
private String remark(UserInfo userInfo, Plugin plugin) {
|
||||
String remark = String.format(" '%s' 从属于全局", plugin.getName());
|
||||
try {
|
||||
if (plugin.getRoute() != null) {
|
||||
Route route = routeService.find(systemProfile(userInfo), plugin.getRoute().getId());
|
||||
remark = String.format("'%s' 从属于路由 '%s'", plugin.getName(), route.getName());
|
||||
}
|
||||
if (plugin.getService() != null) {
|
||||
Service service = this.serviceService.find(systemProfile(userInfo), plugin.getService().getId());
|
||||
remark = String.format("'%s' 从属于服务 '%s'", plugin.getName(), service.getName());
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
return "";
|
||||
}
|
||||
return remark;
|
||||
}
|
||||
|
||||
@RequestMapping(value = PLUGIN_ROUTE_URI_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper addByRoute(UserInfo userInfo, @PathVariable String routeId, @RequestBody Plugin plugin) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
this.kongFeignService.addByRoute(systemProfile(userInfo), routeId, plugin);
|
||||
KongEntity<PluginVO> pluginVOKongEntity = this.kongFeignService.findAllByRoute(systemProfile(userInfo), routeId);
|
||||
jsonHeaderWrapper.setData(pluginVOKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = PLUGIN_SERVICE_URI_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper addByService(UserInfo userInfo, @PathVariable String routeId, @RequestBody Plugin plugin) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
this.kongFeignService.addByService(systemProfile(userInfo), routeId, plugin);
|
||||
KongEntity<PluginVO> pluginVOKongEntity = this.kongFeignService.findAllByService(systemProfile(userInfo), routeId);
|
||||
jsonHeaderWrapper.setData(pluginVOKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Plugin
|
||||
*
|
||||
* @param id
|
||||
* @param plugin
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = PLUGIN_URI_ID_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper<Plugin> update(UserInfo userInfo, @PathVariable String id, @RequestBody Plugin plugin) {
|
||||
JsonHeaderWrapper<Plugin> jsonHeaderWrapper = init();
|
||||
try {
|
||||
Plugin result = this.kongFeignService.update(systemProfile(userInfo), id, plugin);
|
||||
jsonHeaderWrapper.setData(result);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.GLOBAL_PLUGIN, plugin, remark(userInfo, plugin));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Plugin
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = PLUGIN_URI_ID_PATH, method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(UserInfo userInfo, @PathVariable String id) throws URISyntaxException {
|
||||
Plugin plugin = this.find(userInfo, id);
|
||||
this.kongFeignService.remove(systemProfile(userInfo), id);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_DELETE, OperationLog.OperationTarget.GLOBAL_PLUGIN, plugin, remark(userInfo, plugin));
|
||||
return findAll(userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个Plugin的信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = PLUGIN_URI_ID_PATH, method = RequestMethod.GET)
|
||||
public Plugin find(UserInfo userInfo, @PathVariable String id) throws URISyntaxException {
|
||||
return this.kongFeignService.find(systemProfile(userInfo), id);
|
||||
}
|
||||
}
|
@ -0,0 +1,225 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.common.utils.Jackson2Helper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.gateway.KongEntity;
|
||||
import com.kongx.serve.entity.gateway.Route;
|
||||
import com.kongx.serve.entity.gateway.RouteParams;
|
||||
import com.kongx.serve.entity.gateway.Service;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import com.kongx.serve.service.gateway.RouteService;
|
||||
import com.kongx.serve.service.gateway.ServiceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@RestController("/RouteController")
|
||||
@RequestMapping("/kong/api/")
|
||||
public class RouteController extends BaseController {
|
||||
private static final String ROUTE_URI = "/routes";
|
||||
private static final String ROUTE_URI_ID_PATH = "/routes/{id}";
|
||||
private static final String ROUTE_PLUGIN_URI_ID_PATH = "/plugins/{pluginId}/route";
|
||||
private static final String ROUTE_SERVICE_URI_PATH = "/services/{serviceId}/routes";
|
||||
private static final String ROUTE_HOSTS_URI_PATH = "/routes/hosts";
|
||||
private static final String ROUTE_SERVICE_LIST_URI_PATH = "/services/{serviceId}/routes/list";
|
||||
|
||||
@Autowired
|
||||
private RouteService kongFeignService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有route
|
||||
*
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_URI, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<Route> routeKongEntity = kongFeignService.findAll(systemProfile(userInfo));
|
||||
jsonHeaderWrapper.setData(routeKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有route
|
||||
*
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_SERVICE_LIST_URI_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper findAllRoutesByService(UserInfo userInfo, @PathVariable String serviceId, @RequestBody SystemProfile systemProfile) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
SystemProfile activeClient = this.systemProfile(userInfo);
|
||||
KongEntity<Route> routeKongEntity = this.kongFeignService.findAllByService(systemProfile.IS_NULL() ? activeClient : systemProfile, serviceId);
|
||||
jsonHeaderWrapper.setData(routeKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新路由Hosts
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = {ROUTE_HOSTS_URI_PATH}, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper batchUpdateRouteDomain(UserInfo userInfo, @RequestBody RouteParams routeParams) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
SystemProfile systemProfile = this.systemProfile(userInfo);
|
||||
KongEntity<Route> routeKongEntity = this.kongFeignService.findAll(systemProfile);
|
||||
if (routeParams.getService() != null) {
|
||||
Service service = this.serviceService.find(systemProfile, routeParams.getService().getId());
|
||||
routeKongEntity = this.kongFeignService.findAllByService(systemProfile, service.getName());
|
||||
}
|
||||
StringBuilder routeNames = new StringBuilder();
|
||||
for (Route datum : routeKongEntity.getData()) {
|
||||
datum.setHosts(routeParams.getHosts());
|
||||
this.kongFeignService.update(systemProfile, datum.getId(), datum);
|
||||
}
|
||||
if (!routeKongEntity.getData().isEmpty()) {
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.ROUTE, routeParams,
|
||||
routeKongEntity.getData().get(0).getName() + " ...等路由的主机名为:" + Jackson2Helper.toJsonString(routeParams.getHosts()));
|
||||
}
|
||||
jsonHeaderWrapper.setErrmsg(routeNames.toString());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增Route
|
||||
*
|
||||
* @param route
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_SERVICE_URI_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(UserInfo userInfo, @PathVariable String serviceId, @RequestBody Route route) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<Route> routeKongEntity = this.kongFeignService.add(systemProfile(userInfo), serviceId, route.clear());
|
||||
jsonHeaderWrapper.setData(routeKongEntity.getData());
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.ROUTE, route, remark(userInfo, route));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ServiceService serviceService;
|
||||
|
||||
private String remark(UserInfo userInfo, Route route) {
|
||||
String remark = "";
|
||||
try {
|
||||
if (route.getService() != null) {
|
||||
Service service = this.serviceService.find(systemProfile(userInfo), route.getService().getId());
|
||||
remark = String.format("'%s' 从属于服务 '%s'", route.getName(), service.getName());
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
return "";
|
||||
}
|
||||
return remark;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Route
|
||||
*
|
||||
* @param id
|
||||
* @param route
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_URI_ID_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(UserInfo userInfo, @PathVariable String id, @RequestBody Route route) throws URISyntaxException {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Route results = this.kongFeignService.update(systemProfile(userInfo), id, route.clear());
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.ROUTE, route, remark(userInfo, route));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Route
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_URI_ID_PATH, method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(UserInfo userInfo, @PathVariable String id) throws URISyntaxException {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Route route = this.kongFeignService.find(systemProfile(userInfo), id);
|
||||
KongEntity<Route> routeKongEntity = this.kongFeignService.remove(systemProfile(userInfo), id);
|
||||
jsonHeaderWrapper.setData(routeKongEntity.getData());
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_DELETE, OperationLog.OperationTarget.ROUTE, route, remark(userInfo, route));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个route的信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_URI_ID_PATH, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper find(UserInfo userInfo, @PathVariable String id) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Route results = this.kongFeignService.find(systemProfile(userInfo), id);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过插件查询单个route的信息
|
||||
*
|
||||
* @param pluginId
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = ROUTE_PLUGIN_URI_ID_PATH, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findByPlugin(UserInfo userInfo, @PathVariable String pluginId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Route results = this.kongFeignService.findByPlugin(systemProfile(userInfo), pluginId);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.gateway.KongEntity;
|
||||
import com.kongx.serve.entity.gateway.PluginVO;
|
||||
import com.kongx.serve.entity.gateway.Service;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import com.kongx.serve.service.gateway.PluginService;
|
||||
import com.kongx.serve.service.gateway.ServiceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@RestController("/ServiceController")
|
||||
@RequestMapping("/kong/api/")
|
||||
public class ServiceController extends BaseController {
|
||||
private static final String SERVICE_URI = "/services";
|
||||
private static final String SERVICE_URI_ID_PATH = "/services/{id}";
|
||||
private static final String SERVICE_URI_ID_PLUGIN_PATH = "/services/{serviceId}/list/plugins";
|
||||
private static final String SERVICE_ROUTE_URI_ID_PATH = "/routes/{routeId}/service";
|
||||
private static final String SERVICE_PLUGIN_URI_ID_PATH = "/plugins/{pluginId}/service";
|
||||
|
||||
@Autowired
|
||||
private ServiceService kongFeignService;
|
||||
|
||||
@Autowired
|
||||
private PluginService pluginService;
|
||||
|
||||
/**
|
||||
* 查询所有SERVICE
|
||||
*
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = SERVICE_URI, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<Service> upstreamKongEntity = kongFeignService.findAll(systemProfile(userInfo));
|
||||
jsonHeaderWrapper.setData(upstreamKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = SERVICE_URI_ID_PLUGIN_PATH, method = {RequestMethod.POST})
|
||||
public JsonHeaderWrapper findAllPlugin(UserInfo userInfo, @PathVariable String serviceId, @RequestBody SystemProfile systemProfile) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
SystemProfile activeClient = this.systemProfile(userInfo);
|
||||
Service service = this.kongFeignService.find(this.systemProfile(userInfo), serviceId);
|
||||
KongEntity<PluginVO> pluginVOKongEntity = pluginService.findAllPluginByService(systemProfile.IS_NULL() ? activeClient : systemProfile, serviceId);
|
||||
jsonHeaderWrapper.setData(pluginVOKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增service
|
||||
*
|
||||
* @param service
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = SERVICE_URI, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(UserInfo userInfo, @RequestBody Service service) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Service results = this.kongFeignService.add(systemProfile(userInfo), service);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.SERVICE, results, results.getName());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新service
|
||||
*
|
||||
* @param id
|
||||
* @param service
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = SERVICE_URI_ID_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(UserInfo userInfo, @PathVariable String id, @RequestBody Service service) throws URISyntaxException {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Service results = this.kongFeignService.update(systemProfile(userInfo), id, service);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.SERVICE, results, results.getName());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除upstream
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = SERVICE_URI_ID_PATH, method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(UserInfo userInfo, @PathVariable String id) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Service service = this.kongFeignService.find(systemProfile(userInfo), id);
|
||||
KongEntity<Service> upstreamKongEntity = this.kongFeignService.remove(systemProfile(userInfo), id);
|
||||
jsonHeaderWrapper.setData(upstreamKongEntity.getData());
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_DELETE, OperationLog.OperationTarget.SERVICE, service, service.getName());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个upstream的信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = SERVICE_URI_ID_PATH, method = RequestMethod.GET)
|
||||
public Service find(UserInfo userInfo, @PathVariable String id) throws URISyntaxException {
|
||||
return this.kongFeignService.find(systemProfile(userInfo), id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = SERVICE_ROUTE_URI_ID_PATH, method = RequestMethod.GET)
|
||||
public Service findByRoute(UserInfo userInfo, @PathVariable String routeId) throws URISyntaxException {
|
||||
return this.kongFeignService.findByRoute(systemProfile(userInfo), routeId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = SERVICE_PLUGIN_URI_ID_PATH, method = RequestMethod.GET)
|
||||
public Service findByPlugin(UserInfo userInfo, @PathVariable String pluginId) throws URISyntaxException {
|
||||
return this.kongFeignService.findByPlugin(systemProfile(userInfo), pluginId);
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.PaginationSupport;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.serve.entity.gateway.Service;
|
||||
import com.kongx.serve.entity.gateway.SyncConfig;
|
||||
import com.kongx.serve.entity.gateway.SyncEntity;
|
||||
import com.kongx.serve.entity.gateway.SyncLog;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import com.kongx.serve.service.SyncLogService;
|
||||
import com.kongx.serve.service.system.SyncConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController("/SyncConfigController")
|
||||
@RequestMapping("/kong/sync/")
|
||||
public class SyncConfigController extends BaseController {
|
||||
@Autowired
|
||||
private SyncConfigService syncConfigService;
|
||||
|
||||
@Autowired
|
||||
private SyncLogService syncLogService;
|
||||
|
||||
@RequestMapping(value = "/configs", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(UserInfo userInfo, @RequestBody SyncConfig syncConfig) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
syncConfig.setCreator(userInfo.getName());
|
||||
jsonHeaderWrapper.setData(this.syncConfigService.addSyncConfig(userInfo, syncConfig));
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_SYNC, OperationLog.OperationTarget.SYNC_SERVICE, syncConfig, remark(userInfo, syncConfig));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
private String remark(UserInfo userInfo, SyncConfig syncConfig) {
|
||||
String remark = String.format(",源环境为:%s", this.systemProfile(userInfo).getProfile());
|
||||
StringBuilder names = new StringBuilder();
|
||||
for (Service service : syncConfig.getServices()) {
|
||||
names.append(service.getName()).append(",");
|
||||
}
|
||||
StringBuilder profiles = new StringBuilder();
|
||||
for (SystemProfile client : syncConfig.getClients()) {
|
||||
profiles.append(client.getProfile()).append(",");
|
||||
}
|
||||
return String.format(remark + ",目标环境列表为:%s服务列表为:%s", profiles, names);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(SyncConfig syncConfig) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
PaginationSupport paginationSupport = this.syncConfigService.findAll(syncConfig);
|
||||
jsonHeaderWrapper.setData(paginationSupport);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs/{syncNo}/logs", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(@PathVariable String syncNo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
List<SyncLog> syncLogList = this.syncLogService.findAllBySyncNo(syncNo);
|
||||
jsonHeaderWrapper.setData(syncLogList);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs/logs", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAll(SyncLog syncLog) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
List<SyncLog> syncLogList = this.syncLogService.findBySyncNoAndService(syncLog.getSyncNo(), syncLog.getService(), syncLog.getDest_client());
|
||||
jsonHeaderWrapper.setData(syncLogList);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs/{syncNo}/config", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findBySyncNo(@PathVariable String syncNo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
SyncEntity syncConfig = this.syncConfigService.findBySyncConfig(syncNo);
|
||||
jsonHeaderWrapper.setData(syncConfig);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.gateway.KongEntity;
|
||||
import com.kongx.serve.entity.gateway.Target;
|
||||
import com.kongx.serve.entity.gateway.TargetHealth;
|
||||
import com.kongx.serve.entity.gateway.Upstream;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import com.kongx.serve.service.gateway.TargetService;
|
||||
import com.kongx.serve.service.gateway.UpstreamService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@RestController("/targetController")
|
||||
@RequestMapping("/kong/api/")
|
||||
@Import(FeignClientsConfiguration.class)
|
||||
public class TargetController extends BaseController {
|
||||
private static final String TARGET_URI_PATH = "/upstreams/{id}/targets";
|
||||
private static final String TARGET_URI_HEALTH_PATH = "/upstreams/{id}/targets/health";
|
||||
private static final String TARGET_URI_ID_PATH = "/upstreams/{upstreamId}/targets/{id}";
|
||||
|
||||
@Autowired
|
||||
private TargetService targetFeignService;
|
||||
|
||||
/**
|
||||
* 查询upstream下的所有target
|
||||
*
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = TARGET_URI_HEALTH_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper findAll(UserInfo userInfo, @PathVariable String id, @RequestBody SystemProfile systemProfile) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
SystemProfile activeClient = this.systemProfile(userInfo);
|
||||
KongEntity<TargetHealth> results = this.targetFeignService.findAllHealth(systemProfile.IS_NULL() ? activeClient : systemProfile, id);
|
||||
jsonHeaderWrapper.setData(results.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增upstream
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = TARGET_URI_PATH, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(UserInfo userInfo, @PathVariable String id, @RequestBody Target target) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
this.targetFeignService.add(systemProfile(userInfo), id, target);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.TARGETS, target,
|
||||
remark(userInfo, target, target.getUpstream().getId()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除target
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = TARGET_URI_ID_PATH, method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(UserInfo userInfo, @PathVariable String upstreamId, @PathVariable String id) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
Target target = this.targetFeignService.findById(systemProfile(userInfo), upstreamId, id);
|
||||
this.targetFeignService.remove(systemProfile(userInfo), upstreamId, id);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_DELETE, OperationLog.OperationTarget.TARGETS, target,
|
||||
remark(userInfo, target, upstreamId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private UpstreamService upstreamService;
|
||||
|
||||
private String remark(UserInfo userInfo, Target target, String upstreamId) {
|
||||
Upstream upstream = null;
|
||||
String remark = "";
|
||||
try {
|
||||
upstream = this.upstreamService.findUpstream(systemProfile(userInfo), upstreamId);
|
||||
remark = String.format("'%s' 从属于上游服务 '%s'", target.getTarget(), upstream.getName());
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return remark;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
package com.kongx.serve.controller.gateway;
|
||||
|
||||
import com.kongx.common.aop.PreAuthorize;
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.gateway.KongEntity;
|
||||
import com.kongx.serve.entity.gateway.Upstream;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.service.gateway.UpstreamService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@RestController("/upstreamController")
|
||||
@RequestMapping("/kong/api/")
|
||||
@Import(FeignClientsConfiguration.class)
|
||||
@Slf4j
|
||||
public class UpstreamController extends BaseController {
|
||||
private static final String UPSTREAM_URI = "/upstreams";
|
||||
private static final String UPSTREAM_URI_ID = "/upstreams/{id}";
|
||||
|
||||
@Autowired
|
||||
private UpstreamService upstreamService;
|
||||
|
||||
/**
|
||||
* 查询所有upstream
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = UPSTREAM_URI, method = RequestMethod.GET)
|
||||
@PreAuthorize("upstream_view")
|
||||
public JsonHeaderWrapper findAll(UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
KongEntity<Upstream> upstreamKongEntity = upstreamService.findAll(systemProfile(userInfo));
|
||||
jsonHeaderWrapper.setData(upstreamKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增upstream
|
||||
*
|
||||
* @param upstream
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = UPSTREAM_URI, method = RequestMethod.POST)
|
||||
@PreAuthorize("upstream_add")
|
||||
public JsonHeaderWrapper addUpstream(UserInfo userInfo, @RequestBody Upstream upstream) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Upstream results = this.upstreamService.add(systemProfile(userInfo), upstream.clear());
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.UPSTREAM, upstream, upstream.getName());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新upstream
|
||||
*
|
||||
* @param id
|
||||
* @param upstream
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = UPSTREAM_URI_ID, method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(UserInfo userInfo, @PathVariable String id, @RequestBody Upstream upstream) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Upstream results = this.upstreamService.update(systemProfile(userInfo), id, upstream.clear());
|
||||
jsonHeaderWrapper.setData(results);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.UPSTREAM, upstream, upstream.getName());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除upstream
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = UPSTREAM_URI_ID, method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(UserInfo userInfo, @PathVariable String id) throws Exception {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Upstream upstream = this.upstreamService.findUpstream(systemProfile(userInfo), id);
|
||||
KongEntity<Upstream> upstreamKongEntity = this.upstreamService.remove(systemProfile(userInfo), id);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_DELETE, OperationLog.OperationTarget.UPSTREAM, upstream, upstream.getName());
|
||||
jsonHeaderWrapper.setData(upstreamKongEntity.getData());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个upstream的信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@RequestMapping(value = UPSTREAM_URI_ID, method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findUpstream(UserInfo userInfo, @PathVariable String id) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
Upstream results = this.upstreamService.findUpstream(systemProfile(userInfo), id);
|
||||
jsonHeaderWrapper.setData(results);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.common.core.entity.PaginationSupport;
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.service.IBaseService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class DefaultController<T, PK> extends BaseController {
|
||||
protected IBaseService baseService;
|
||||
|
||||
@RequestMapping(value = "/page", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findByPage(T project) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
PaginationSupport paginationSupport = baseService.findByPage(project);
|
||||
jsonHeaderWrapper.setData(paginationSupport);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public List<T> findAll(T project) {
|
||||
return baseService.findAll(project);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(@RequestBody T project, UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
this.baseService.add(project, userInfo);
|
||||
jsonHeaderWrapper.setData(project);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, operationTarget(), project);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/{id}", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(@RequestBody T project, UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
this.baseService.update(project, userInfo);
|
||||
jsonHeaderWrapper.setData(project);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, operationTarget(), project);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
protected abstract void setBaseService(IBaseService<T, PK> iBaseService);
|
||||
|
||||
protected abstract OperationLog.OperationTarget operationTarget();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.service.system.EnvService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController("/EnvController")
|
||||
@RequestMapping("/system/envs/")
|
||||
public class EnvController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private EnvService envService;
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public List<Map> findAllEnvs() {
|
||||
return this.envService.findAllEnvs();
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/configTypes", method = RequestMethod.GET)
|
||||
public List<Map> findAllConfigType() {
|
||||
return this.envService.findAllConfigTypes();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemFunction;
|
||||
import com.kongx.serve.service.IBaseService;
|
||||
import com.kongx.serve.service.system.FunctionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("system/function")
|
||||
@Slf4j
|
||||
public class FunctionController extends DefaultController<SystemFunction, Integer> {
|
||||
@Autowired
|
||||
private FunctionService functionService;
|
||||
|
||||
/**
|
||||
* 左侧菜单树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/tree")
|
||||
public JsonHeaderWrapper menuTree() {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.functionService.findFunctionByTree());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping("/menu/role")
|
||||
public JsonHeaderWrapper menuTreeToRole() {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.functionService.findFunctionByRole());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Resource(name = "systemFunctionService")
|
||||
protected void setBaseService(IBaseService iBaseService) {
|
||||
this.baseService = iBaseService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OperationLog.OperationTarget operationTarget() {
|
||||
return OperationLog.OperationTarget.SYSTEM_FUNCTION;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,157 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.system.LogParams;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController("/OperationLogController")
|
||||
@RequestMapping("/operating/logs/")
|
||||
public class LogController extends BaseController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAllLogsByDay(LogParams logParams) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
|
||||
jsonHeaderWrapper.setData(query(logParams));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
private Map query(LogParams logParams) {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
QueryType queryType = QueryType.to(logParams.getLabel());
|
||||
int days = logParams.getValue();
|
||||
String fmt = "day";
|
||||
switch (queryType) {
|
||||
case ALL:
|
||||
break;
|
||||
case RECENT7:
|
||||
logParams.setBegin(0);
|
||||
logParams.setEnd(7);
|
||||
break;
|
||||
case PRE_WEEK:
|
||||
if (logParams.getValue() == 0) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int _days = cal.get(Calendar.DAY_OF_WEEK);
|
||||
logParams.setValue(_days);
|
||||
logParams.setBegin(_days);
|
||||
logParams.setEnd(_days + 6);
|
||||
}
|
||||
days = logParams.getValue();
|
||||
break;
|
||||
case THIS_WEEK:
|
||||
fmt = "day";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int _days = cal.get(Calendar.DAY_OF_WEEK);
|
||||
logParams.setEnd(7 - _days);
|
||||
break;
|
||||
case PRE_MONTH:
|
||||
if (logParams.getValue() == 0) {
|
||||
_days = this.getCurrentDays();
|
||||
logParams.setValue(_days);
|
||||
int preMonthDays = this.getMonthDays(-1);
|
||||
logParams.setBegin(_days);
|
||||
logParams.setEnd(_days + preMonthDays);
|
||||
}
|
||||
days = logParams.getValue();
|
||||
break;
|
||||
case THIS_MONTH:
|
||||
logParams.setEnd(this.getCurrentDays());
|
||||
fmt = "month";
|
||||
break;
|
||||
}
|
||||
values.put("logTags", wrap(logParams));
|
||||
values.putAll(this.logService.getDateStr(days, fmt));
|
||||
values.put("logParams", logParams);
|
||||
values.put("logs", logService.findAllByDays(logParams.getValue(), logParams.getKeyword()));
|
||||
return values;
|
||||
}
|
||||
|
||||
private Map wrap(LogParams logParams) {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
LogParams pre = this.nextOrPre(logParams, true);
|
||||
LogParams next = this.nextOrPre(logParams, false);
|
||||
if (pre != null) values.put("pre", pre);
|
||||
if (next != null) values.put("next", next);
|
||||
return values;
|
||||
}
|
||||
|
||||
private LogParams nextOrPre(final LogParams logParams, boolean isPre) {
|
||||
|
||||
if (logParams.getValue() == logParams.getBegin() && !isPre) return null;
|
||||
if (logParams.getValue() == logParams.getEnd() && isPre) return null;
|
||||
if (logParams.getBegin() == logParams.getEnd()) return null;
|
||||
|
||||
if (isPre && logParams.getValue() + 1 == logParams.getEnd()) {
|
||||
return null;
|
||||
}
|
||||
LogParams results = logParams.clone();
|
||||
|
||||
if (isPre) results.setValue(logParams.getValue() + 1);
|
||||
if (!isPre) results.setValue(logParams.getValue() - 1);
|
||||
return results;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{days}/before", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findAllLogsByBefore(@PathVariable("days") int days) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
values.putAll(this.logService.getDateStr(days, "day"));
|
||||
values.put("logs", logService.findAllByBeforeDays(days));
|
||||
jsonHeaderWrapper.setData(values);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
|
||||
enum QueryType {
|
||||
ALL("all"), TODAY("today"), YESTERDAY("yesterday"),
|
||||
RECENT7("recent7"),
|
||||
PRE_WEEK("preweek"),
|
||||
THIS_WEEK("thisweek"),
|
||||
PRE_MONTH("premonth"),
|
||||
THIS_MONTH("thismonth");
|
||||
private String type;
|
||||
|
||||
QueryType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static QueryType to(String type) {
|
||||
for (QueryType value : QueryType.values()) {
|
||||
if (value.type.equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return TODAY;
|
||||
}
|
||||
}// 获得本周一0点时间
|
||||
|
||||
public int getMonthDays(int month) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.MONDAY, month);
|
||||
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
public int getCurrentDays() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
return cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.RoleMenuParas;
|
||||
import com.kongx.serve.entity.system.SystemRole;
|
||||
import com.kongx.serve.service.IBaseService;
|
||||
import com.kongx.serve.service.system.RoleService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController("SystemRoleController")
|
||||
@RequestMapping("system/role")
|
||||
public class RoleController extends DefaultController<SystemRole, Integer> {
|
||||
|
||||
@Resource(name = "roleService")
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
@Resource(name = "roleService")
|
||||
protected void setBaseService(IBaseService iBaseService) {
|
||||
this.baseService = iBaseService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OperationLog.OperationTarget operationTarget() {
|
||||
return OperationLog.OperationTarget.SYSTEM_ROLE;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/updateRoleMenu", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper updateRoleMenu(@RequestBody RoleMenuParas paras) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.roleService.updateRoleMenu(paras));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{roleId}/menu", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper findMenusByRoleId(@PathVariable int roleId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.roleService.findMenuByRoleId(roleId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.common.utils.Jackson2Helper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.ServerConfig;
|
||||
import com.kongx.serve.service.system.ServerConfigService;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController("/ServerConfigController")
|
||||
@RequestMapping("/system/server/")
|
||||
public class ServerConfigController extends BaseController {
|
||||
@Autowired
|
||||
private ServerConfigService serverConfigService;
|
||||
|
||||
@RequestMapping(value = "/configs", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper list() {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
List<ServerConfig> serverConfigs = this.serverConfigService.findAll();
|
||||
jsonHeaderWrapper.setData(serverConfigs);
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(@RequestBody ServerConfig serverConfig, UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
this.serverConfigService.addServerConfig(serverConfig);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_ADD, OperationLog.OperationTarget.SERVER_CONFIG, serverConfig, serverConfig.getConfigKey());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs/{id}", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(@PathVariable int id, @RequestBody ServerConfig serverConfig, UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
this.serverConfigService.updateServerConfig(serverConfig);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.SERVER_CONFIG, serverConfig, serverConfig.getConfigKey());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs/{key}", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findByKey(@PathVariable String key) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.serverConfigService.findByKey(key));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configs/{key}/json", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findJsonByKey(@PathVariable String key) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
ServerConfig serverConfig = this.serverConfigService.findByKey(key);
|
||||
jsonHeaderWrapper.setData(Jackson2Helper.parsonObject(serverConfig.getConfigValue(), new TypeReference<Object>() {
|
||||
}));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.controller.BaseController;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import com.kongx.serve.service.system.SystemProfileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController("/SystemProfileController")
|
||||
@RequestMapping("/system/profile/")
|
||||
public class SystemProfileController extends BaseController {
|
||||
@Autowired
|
||||
private SystemProfileService systemProfileService;
|
||||
|
||||
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public List<SystemProfile> findAll() {
|
||||
return systemProfileService.findAll();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/active", method = RequestMethod.GET)
|
||||
public SystemProfile findActiveKongClient(UserInfo userInfo) {
|
||||
return this.systemProfileService.getClientByName(userInfo.getUserId());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/active", method = RequestMethod.POST)
|
||||
public SystemProfile setActiveKongClient(UserInfo userInfo, @RequestBody SystemProfile systemProfile) {
|
||||
this.systemProfileService.setActiveClient(userInfo.getUserId(), systemProfile);
|
||||
return systemProfile;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/profiles", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper list() {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
List<SystemProfile> systemProfiles = this.systemProfileService.findAll();
|
||||
jsonHeaderWrapper.setData(systemProfiles);
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/profiles/group", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper profilesGroup() {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
List<Map<String, Object>> systemProfiles = this.systemProfileService.findAllByGroup();
|
||||
jsonHeaderWrapper.setData(systemProfiles);
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/profiles", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper add(@RequestBody SystemProfile systemProfile) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
this.systemProfileService.addClient(systemProfile);
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/profiles/{clientId}", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper update(@PathVariable int clientId, @RequestBody SystemProfile systemProfile, UserInfo userInfo) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
this.systemProfileService.updateClient(systemProfile);
|
||||
this.log(userInfo, OperationLog.OperationType.OPERATION_UPDATE, OperationLog.OperationTarget.SYSTEM_PROFILE, systemProfile, systemProfile.getProfile());
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/profiles/{clientId}", method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper remove(@PathVariable int clientId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.systemProfileService.removeClient(clientId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/profiles/{profile}", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findByProfile(@PathVariable String profile) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = this.init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.systemProfileService.findByProfile(profile));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.UserGroup;
|
||||
import com.kongx.serve.service.IBaseService;
|
||||
import com.kongx.serve.service.system.GroupRoleService;
|
||||
import com.kongx.serve.service.system.UserGroupService;
|
||||
import com.kongx.serve.service.system.GroupUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController("UserGroupController")
|
||||
@RequestMapping("system/user/group")
|
||||
public class UserGroupController extends DefaultController<UserGroup, Integer> {
|
||||
|
||||
@Resource(name = "userGroupService")
|
||||
private UserGroupService userGroupService;
|
||||
|
||||
@Autowired
|
||||
private GroupUserService groupUserService;
|
||||
|
||||
@Autowired
|
||||
private GroupRoleService groupRoleService;
|
||||
|
||||
@Override
|
||||
@Resource(name = "userGroupService")
|
||||
protected void setBaseService(IBaseService iBaseService) {
|
||||
this.baseService = iBaseService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OperationLog.OperationTarget operationTarget() {
|
||||
return OperationLog.OperationTarget.USER_GROUP;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{groupId}/user/{userId}", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper setGroupUser(@PathVariable int groupId, @PathVariable String userId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(groupUserService.add(groupId, userId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{groupId}/user", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper setBatchGroupUser(@PathVariable int groupId, @RequestBody List<String> userId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
if (userId.isEmpty()) {
|
||||
jsonHeaderWrapper.setStatus(500);
|
||||
jsonHeaderWrapper.setErrmsg("请选择用户列表!");
|
||||
} else {
|
||||
jsonHeaderWrapper.setData(groupUserService.batchInsert(groupId, userId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{groupId}/user", method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper deleteBatchGroupUser(@PathVariable int groupId, @RequestBody List<String> userId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(groupUserService.batchDelete(groupId, userId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{groupId}/user/{userId}", method = RequestMethod.DELETE)
|
||||
public JsonHeaderWrapper removeGroupUser(@PathVariable int groupId, @PathVariable String userId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(groupUserService.delete(groupId, userId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{groupId}/role/{roleId}", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper setGroupRole(@PathVariable int groupId, @PathVariable int roleId,
|
||||
@RequestBody List<Map> systemProfileList) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(groupRoleService.add(groupId, roleId, systemProfileList));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{groupId}/drole/{roleId}", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper removeGroupRole(@PathVariable int groupId, @PathVariable int roleId,
|
||||
@RequestBody List<Map> systemProfileList) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(groupRoleService.delete(groupId, roleId, systemProfileList));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.kongx.serve.controller.system;
|
||||
|
||||
import com.kongx.common.core.entity.PaginationSupport;
|
||||
import com.kongx.common.jsonwrapper.JsonHeaderWrapper;
|
||||
import com.kongx.serve.entity.system.OperationLog;
|
||||
import com.kongx.serve.entity.system.UserInfoVO;
|
||||
import com.kongx.serve.entity.system.UserPwd;
|
||||
import com.kongx.serve.entity.system.UserRoleParas;
|
||||
import com.kongx.serve.service.IBaseService;
|
||||
import com.kongx.serve.service.system.UserInfoService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.kongx.serve.entity.system.OperationLog.OperationTarget.USER_INFO;
|
||||
|
||||
@RestController("UserInfoController")
|
||||
@RequestMapping("/system/user")
|
||||
public class UserInfoController extends DefaultController<UserInfoVO, Integer> {
|
||||
@Resource(name = "userInfoService")
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@RequestMapping(value = "/page", method = RequestMethod.GET)
|
||||
public JsonHeaderWrapper findByPage(UserInfoVO project) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
PaginationSupport paginationSupport = userInfoService.findByPage(project);
|
||||
jsonHeaderWrapper.setData(paginationSupport);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Resource(name = "userInfoService")
|
||||
protected void setBaseService(IBaseService<UserInfoVO, Integer> iBaseService) {
|
||||
this.baseService = iBaseService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OperationLog.OperationTarget operationTarget() {
|
||||
return USER_INFO;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/updateUserRole", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper updateUserRole(@RequestBody UserRoleParas paras) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.userInfoService.updateUserRole(paras));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/reset/{userId}/", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper resetpwd(@PathVariable String userId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.userInfoService.resetpwd(userId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/status/{status}/{userId}/", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper status(@PathVariable String status, @PathVariable String userId) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.userInfoService.status(status, userId));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/modifypwd/", method = RequestMethod.POST)
|
||||
public JsonHeaderWrapper modifypwd(@RequestBody UserPwd userPwd) {
|
||||
JsonHeaderWrapper jsonHeaderWrapper = init();
|
||||
try {
|
||||
jsonHeaderWrapper.setData(this.userInfoService.modifyPwd(userPwd));
|
||||
} catch (Exception e) {
|
||||
jsonHeaderWrapper.setErrmsg(e.getMessage());
|
||||
jsonHeaderWrapper.setStatus(JsonHeaderWrapper.StatusEnum.Failed.getCode());
|
||||
}
|
||||
return jsonHeaderWrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Consumer implements Comparable {
|
||||
private Timestamp created_at;
|
||||
private String username;
|
||||
private String custom_id;
|
||||
private String id;
|
||||
private List<String> tags = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Consumer consumer = null;
|
||||
if (o instanceof Consumer) {
|
||||
consumer = (Consumer) o;
|
||||
}
|
||||
return consumer.created_at.compareTo(this.created_at);
|
||||
}
|
||||
|
||||
public Consumer trim() {
|
||||
this.username = StringUtils.isEmpty(this.username) ? null : this.username;
|
||||
this.custom_id = StringUtils.isEmpty(this.custom_id) ? null : this.custom_id;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 18:37:41
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public class EntityId {
|
||||
|
||||
private String id;
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class KongEntity<T> {
|
||||
|
||||
private String next;
|
||||
private List<T> data = new ArrayList<>();
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 18:41:14
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Plugin implements Comparable {
|
||||
|
||||
public static final String AUTH_SERVER_CODE = "auth_server_code";
|
||||
|
||||
private Timestamp created_at;
|
||||
private Map config;
|
||||
private String id;
|
||||
private EntityId service;
|
||||
private String name;
|
||||
private List<String> protocols;
|
||||
private boolean enabled;
|
||||
private String run_on;
|
||||
private String consumer;
|
||||
private EntityId route;
|
||||
private String tags;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Plugin upstream = null;
|
||||
if (o instanceof Plugin) {
|
||||
upstream = (Plugin) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 18:41:14
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class PluginVO extends Plugin {
|
||||
|
||||
private Timestamp created_at;
|
||||
private Map config;
|
||||
private String id;
|
||||
private EntityId service;
|
||||
private String name;
|
||||
private List<String> protocols;
|
||||
private boolean enabled;
|
||||
private String run_on;
|
||||
private String consumer;
|
||||
private EntityId route;
|
||||
private String tags;
|
||||
private String scope = "global";
|
||||
private Map applyObject;
|
||||
|
||||
public Plugin to() {
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setCreated_at(created_at);
|
||||
plugin.setConfig(config);
|
||||
plugin.setId(id);
|
||||
plugin.setService(service);
|
||||
plugin.setRoute(route);
|
||||
plugin.setConsumer(consumer);
|
||||
plugin.setEnabled(enabled);
|
||||
plugin.setName(name);
|
||||
plugin.setProtocols(protocols);
|
||||
plugin.setTags(tags);
|
||||
plugin.setRun_on(run_on);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setApplyTo(List<Route> routes, List<Service> services) {
|
||||
Map map = new HashMap();
|
||||
if (route != null) {
|
||||
routes.stream().filter(route1 -> route.getId().equals(route1.getId())).forEach(route1 -> {
|
||||
map.put("name", route1.getName());
|
||||
});
|
||||
this.applyObject = map;
|
||||
this.scope = "routes";
|
||||
return;
|
||||
}
|
||||
if (service != null) {
|
||||
services.stream().filter(route1 -> service.getId().equals(route1.getId())).forEach(route1 -> {
|
||||
map.put("name", route1.getName());
|
||||
});
|
||||
this.applyObject = map;
|
||||
this.scope = "services";
|
||||
return;
|
||||
}
|
||||
|
||||
map.put("name", "All Entrypoints");
|
||||
this.applyObject = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
PluginVO upstream = null;
|
||||
if (o instanceof PluginVO) {
|
||||
upstream = (PluginVO) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 18:37:41
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Route implements Comparable {
|
||||
|
||||
private String id;
|
||||
private String tags;
|
||||
private List<String> paths = new ArrayList<>();
|
||||
private String destinations;
|
||||
private List<String> protocols;
|
||||
private Timestamp created_at;
|
||||
private String snis;
|
||||
private List<String> hosts = new ArrayList<>();
|
||||
private String name;
|
||||
private boolean preserve_host;
|
||||
private int regex_priority;
|
||||
private boolean strip_path;
|
||||
private String sources;
|
||||
private Timestamp updated_at;
|
||||
private int https_redirect_status_code = 426;
|
||||
private EntityId service;
|
||||
private List<String> methods = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Route upstream = null;
|
||||
if (o instanceof Route) {
|
||||
upstream = (Route) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
|
||||
public Route clear() {
|
||||
this.snis = set(this.snis);
|
||||
this.protocols = set(this.protocols);
|
||||
this.paths = set(this.paths);
|
||||
this.hosts = set(this.hosts);
|
||||
this.methods = set(this.methods);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String set(String value) {
|
||||
if ("".equals(value)) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private List<String> set(List<String> value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class RouteParams implements Serializable {
|
||||
private EntityId service;
|
||||
|
||||
private String policy;//更新策略(只更新当前环境,同步更新到其它环境 )
|
||||
|
||||
private List<String> hosts;
|
||||
|
||||
private List<SystemProfile> profiles;//更新到其它环境中
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 18:35:55
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Service implements Comparable {
|
||||
|
||||
private String host;
|
||||
private Timestamp created_at;
|
||||
private int connect_timeout;
|
||||
private String id;
|
||||
private String protocol;
|
||||
private String name;
|
||||
private int read_timeout;
|
||||
private int port;
|
||||
private String path;
|
||||
private long updated_at;
|
||||
private int retries;
|
||||
private int write_timeout;
|
||||
private List<String> tags;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Service upstream = null;
|
||||
if (o instanceof Service) {
|
||||
upstream = (Service) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
|
||||
|
||||
public Service clear() {
|
||||
this.protocol = set(this.protocol);
|
||||
return this;
|
||||
}
|
||||
|
||||
private String set(String value) {
|
||||
if ("".equals(value)) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SyncConfig extends SyncEntity<Service> {
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import com.kongx.common.core.entity.PaginationQC;
|
||||
import com.kongx.serve.entity.system.SystemProfile;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
public class SyncEntity<T> extends PaginationQC {
|
||||
public static final String LOG_STATUS_FAILURE = "failure";
|
||||
public static final String LOG_STATUS_RUNNING = "running";
|
||||
public static final String LOG_STATUS_SUCCESS = "success";
|
||||
|
||||
public static final int LOG_TYPE_KONG_SERVICES = 0;
|
||||
public static final int LOG_TYPE_HOT_CONFIG_PARAMS = 1;
|
||||
|
||||
private int id;
|
||||
|
||||
private SystemProfile src_client;
|
||||
private List<SystemProfile> clients;
|
||||
private String syncNo = UUID.randomUUID().toString();//同步编号
|
||||
|
||||
private List<T> services;
|
||||
|
||||
private Date create_at = new Date();
|
||||
|
||||
private int logType = LOG_TYPE_KONG_SERVICES;
|
||||
|
||||
private String dataType;
|
||||
|
||||
private String policy;
|
||||
|
||||
private String creator;
|
||||
|
||||
private String comment;
|
||||
|
||||
private String status = LOG_STATUS_RUNNING;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class SyncLog {
|
||||
|
||||
public static final String LOG_STATUS_FAILURE = "failure";
|
||||
public static final String LOG_STATUS_SUCCESS = "success";
|
||||
|
||||
private int id;
|
||||
|
||||
private String service;
|
||||
|
||||
private String syncNo;//同步编号
|
||||
|
||||
private String src_client;
|
||||
|
||||
private String dest_client;
|
||||
|
||||
private String creator;
|
||||
|
||||
private Date create_at = new Date();
|
||||
|
||||
private String status = LOG_STATUS_SUCCESS;
|
||||
|
||||
private Object content;
|
||||
|
||||
private String comment;
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-21 9:44:22
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Target implements Comparable {
|
||||
|
||||
private Timestamp created_at;
|
||||
private EntityId upstream;
|
||||
private String id;
|
||||
private String target;
|
||||
private int weight;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Target upstream = null;
|
||||
if (o instanceof Target) {
|
||||
upstream = (Target) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-21 9:44:22
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class TargetHealth implements Comparable {
|
||||
|
||||
private Timestamp created_at;
|
||||
private EntityId upstream;
|
||||
private String id;
|
||||
private String health;
|
||||
private String target;
|
||||
private int weight;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
TargetHealth upstream = null;
|
||||
if (o instanceof TargetHealth) {
|
||||
upstream = (TargetHealth) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway;
|
||||
|
||||
import com.kongx.serve.entity.gateway.upstream.Healthchecks;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Data
|
||||
public class Upstream implements Comparable {
|
||||
|
||||
private Timestamp created_at;
|
||||
private String id;
|
||||
private String tags;
|
||||
private String hash_on;
|
||||
private String hash_fallback_header;
|
||||
private String hash_on_header;
|
||||
private String hash_on_cookie;
|
||||
private Healthchecks healthchecks;
|
||||
private String hash_on_cookie_path;
|
||||
private String name;
|
||||
private String hash_fallback;
|
||||
private int slots;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Upstream upstream = null;
|
||||
if (o instanceof Upstream) {
|
||||
upstream = (Upstream) o;
|
||||
}
|
||||
return upstream.created_at.compareTo(this.created_at);
|
||||
}
|
||||
|
||||
public Upstream clear() {
|
||||
this.hash_fallback = set(this.hash_fallback);
|
||||
this.hash_on = set(this.hash_on);
|
||||
this.hash_fallback_header = set(this.hash_fallback_header);
|
||||
this.hash_on_header = set(this.hash_on_header);
|
||||
this.hash_on_cookie = set(this.hash_on_cookie);
|
||||
this.hash_on_cookie_path = set(this.hash_on_cookie_path);
|
||||
this.hash_fallback = set(this.hash_fallback);
|
||||
if (this.healthchecks != null)
|
||||
this.healthchecks.getActive().setHttps_sni(set(this.healthchecks.getActive().getHttps_sni()));
|
||||
return this;
|
||||
}
|
||||
|
||||
private String set(String value) {
|
||||
if ("".equals(value)) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Active {
|
||||
|
||||
private ActiveUnhealthy unhealthy;
|
||||
private String type;
|
||||
private String http_path;
|
||||
private int timeout;
|
||||
private ActiveHealthy healthy;
|
||||
private String https_sni;
|
||||
private boolean https_verify_certificate;
|
||||
private int concurrency;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class ActiveHealthy extends Healthy{
|
||||
private int interval;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class ActiveUnhealthy extends Unhealthy{
|
||||
private int interval;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Healthchecks {
|
||||
|
||||
private Active active;
|
||||
private Passive passive;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Healthy {
|
||||
|
||||
private List<Integer> http_statuses;
|
||||
private int successes;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Passive {
|
||||
|
||||
private Unhealthy unhealthy;
|
||||
private Healthy healthy;
|
||||
private String type;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2019 bejson.com
|
||||
*/
|
||||
package com.kongx.serve.entity.gateway.upstream;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2019-11-20 17:10:47
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class Unhealthy {
|
||||
private int http_failures;
|
||||
private List<Integer> http_statuses;
|
||||
private int tcp_failures;
|
||||
private int timeouts;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LogParams {
|
||||
private String name;
|
||||
private String type;
|
||||
private int value;
|
||||
private int begin;
|
||||
private int end;
|
||||
private String label;
|
||||
private String keyword;
|
||||
|
||||
public LogParams clone() {
|
||||
LogParams logParams = new LogParams();
|
||||
logParams.setBegin(begin);
|
||||
logParams.setEnd(end);
|
||||
logParams.setKeyword(keyword);
|
||||
logParams.setLabel(label);
|
||||
logParams.setValue(value);
|
||||
logParams.setName(name);
|
||||
logParams.setType(type);
|
||||
return logParams;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Menu {
|
||||
private String label;
|
||||
private Integer id;
|
||||
private Integer parentId;
|
||||
private String code;
|
||||
private String path;
|
||||
private String icon;
|
||||
private String component;
|
||||
private List<Menu> children = new ArrayList<>();
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
public enum MenuTypeEnum {
|
||||
APPLICATION("application", "系统", "A"),
|
||||
FUNCTION("function", "菜单", "F"),
|
||||
POINT("point", "按钮", "P");
|
||||
private String code;
|
||||
private String name;
|
||||
|
||||
private String ab;
|
||||
|
||||
MenuTypeEnum(String code, String name, String ab) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.ab = ab;
|
||||
|
||||
}
|
||||
|
||||
public static MenuTypeEnum codeOf(String code) {
|
||||
for (MenuTypeEnum menuTypeEnum : MenuTypeEnum.values()) {
|
||||
if (menuTypeEnum.code.equals(code)) {
|
||||
return menuTypeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAb() {
|
||||
return ab;
|
||||
}
|
||||
|
||||
public void setAb(String ab) {
|
||||
this.ab = ab;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class OperationLog {
|
||||
private int id;
|
||||
|
||||
private String userId;
|
||||
|
||||
private String profile;
|
||||
|
||||
private String creator;
|
||||
|
||||
private String operation;
|
||||
|
||||
private String target;
|
||||
|
||||
private Date create_at = new Date();
|
||||
|
||||
private Object content;
|
||||
|
||||
private String remark;
|
||||
|
||||
|
||||
public static enum OperationType {
|
||||
OPERATION_LOGIN("login", "登录"),
|
||||
OPERATION_LOGOUT("logout", "登出"),
|
||||
OPERATION_SYNC("sync", "同步"),
|
||||
OPERATION_ADD("add", "新增"),
|
||||
OPERATION_UPDATE("update", "修改"),
|
||||
OPERATION_DELETE("delete", "删除"),
|
||||
OPERATION_SUBSCRIBE("subscribe", "订阅"),
|
||||
JOB_STARTUP("job_startup", "启动"),
|
||||
JOB_PAUSE("job_pause", "暂停"),
|
||||
JOB_DELETE("job_delete", "删除"),
|
||||
DEMOTE_CONFIG("demote_config", "执行降级"),
|
||||
ROLLBACK_CONFIG("rollback_config", "降级回滚"),
|
||||
ARTHAS_ATTACH("arthas_attach", "Arthas调试"),
|
||||
OPERATION_DEFAULT("none", "");
|
||||
private String type;
|
||||
private String remark;
|
||||
|
||||
private OperationType(String type, String remark) {
|
||||
this.type = type;
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public static OperationType to(String type) {
|
||||
for (OperationType value : OperationType.values()) {
|
||||
if (value.type.equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return OPERATION_DEFAULT;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum OperationTarget {
|
||||
GLOBAL_PLUGIN("global_plugin", "插件"),
|
||||
ROUTE_PLUGIN("route_plugin", "路由插件"),
|
||||
SERVICE_PLUGIN("service_plugin", "服务插件"),
|
||||
ROUTE("route", "路由"),
|
||||
SERVICE("service", "服务"),
|
||||
UPSTREAM("upstream", "上游服务"),
|
||||
TARGETS("targets", "上游代理"),
|
||||
SYSTEM("system", "系统"),
|
||||
SYSTEM_ROLE("system_role", "系统角色"),
|
||||
USER_GROUP("user_group", "用户组"),
|
||||
SYSTEM_FUNCTION("system_function", "系统功能菜单"),
|
||||
SYNC_SERVICE("sync_service", "网关服务"),
|
||||
USER_INFO("user_info", "用户信息"),
|
||||
TEMPLATE_TYPE("template_type", "模板类型"),
|
||||
SERVER_CONFIG("server_config", "系统参数"),
|
||||
SYSTEM_PROFILE("system_profile", "系统环境"),
|
||||
DEMOTE_APP_PARAMS("demote_app_params", "降级参数"),
|
||||
SERVICE_PROGRESS("service_progress", "服务进程"),
|
||||
MONITOR_JOB("monitor_job", "作业"),
|
||||
MONITOR_JOB_TASK("monitor_job_task", "作业任务"),
|
||||
DING_TALK_ROBOT("ding_talk_robot", "钉钉机器人"),
|
||||
ALERT_RULE("alert_rule", "告警规则"),
|
||||
ALERT_RECORD("alert_record", "告警记录"),
|
||||
ALERT_TEMPLATE("alert_template", "告警模板"),
|
||||
PROJECT("project", "项目管理"),
|
||||
SYNC_APP_PARAMS("sync_app_params", "热配参数"),
|
||||
LOGGER_LEVEL("logger_level", "日志级别");
|
||||
private String type;
|
||||
private String target;
|
||||
|
||||
private OperationTarget(String type, String target) {
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Permission {
|
||||
private String name;
|
||||
private String code;
|
||||
private String url;
|
||||
private String menu;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ProfileRole {
|
||||
private String profile;
|
||||
private List<SystemRole> roleList;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class RoleMenuParas {
|
||||
private SystemRole systemRole;
|
||||
|
||||
private List<Long> ids = new ArrayList<>();
|
||||
|
||||
private List<SystemFunction> items = new ArrayList<>();
|
||||
private List<SystemFunction> halfItems = new ArrayList<>();//半选中的菜单
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ServerConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private String configKey;
|
||||
|
||||
private String configValue;
|
||||
|
||||
private String comment;
|
||||
|
||||
private String configType;
|
||||
|
||||
private Date create_at = new Date();
|
||||
|
||||
private String creator;
|
||||
|
||||
private String modifier;
|
||||
|
||||
private Date modify_at = new Date();
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SystemFunction {
|
||||
private int id;
|
||||
/**
|
||||
* 父级菜单id
|
||||
*/
|
||||
private Integer parentId;
|
||||
/**
|
||||
* 菜单编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 菜单icon
|
||||
*/
|
||||
private String menuIcon = "";
|
||||
/**
|
||||
* 是否可用 n-不可用,y-可用
|
||||
*/
|
||||
private String useYn = "y";
|
||||
|
||||
/**
|
||||
* 所属系统编码
|
||||
*/
|
||||
private String applicationCode;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
/**
|
||||
* 菜单视图
|
||||
*/
|
||||
private String visitView = "";
|
||||
|
||||
private String menuType = "menu";//菜单类型
|
||||
/**
|
||||
* 菜单的访问地址
|
||||
*/
|
||||
private String visitPath = "";
|
||||
|
||||
private List<SystemFunction> children = new ArrayList<>();
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import com.kongx.common.utils.Jackson2Helper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class SystemProfile {
|
||||
|
||||
private int id;
|
||||
|
||||
private String profileCode;
|
||||
|
||||
private String name;
|
||||
|
||||
private String profile;
|
||||
|
||||
private String env;
|
||||
|
||||
private String deployType;
|
||||
|
||||
private String ab;//环境缩写
|
||||
|
||||
private String url;
|
||||
|
||||
private String consul_url;
|
||||
|
||||
private String config_url;
|
||||
|
||||
private String extensions = "[]";//扩展配置
|
||||
|
||||
private String creator;
|
||||
|
||||
private Date create_at = new Date();
|
||||
|
||||
private String remark;
|
||||
|
||||
public boolean IS_NULL() {
|
||||
return id == 0 || url == null;
|
||||
}
|
||||
|
||||
public System to(String code) {
|
||||
List<System> systems = Jackson2Helper.parsonObject(extensions, new TypeReference<List<System>>() {
|
||||
});
|
||||
for (System system : systems) {
|
||||
if (system.code.equals(code)) {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class System {
|
||||
private String name;
|
||||
private String code;
|
||||
private String url;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import com.kongx.common.core.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SystemRole extends BaseEntity {
|
||||
/**
|
||||
* 角色编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 角色类型
|
||||
*/
|
||||
private String roleType;
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Long sortOrder;
|
||||
/**
|
||||
* 是否可用 n-不可用,y-可用
|
||||
*/
|
||||
private String useYn;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SystemRoleFunction {
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private int roleId;
|
||||
/**
|
||||
* 菜单id
|
||||
*/
|
||||
private int functionId;
|
||||
|
||||
private String halfChecked = "n";
|
||||
|
||||
public SystemRoleFunction(int roleId, int functionId, String halfChecked) {
|
||||
this.roleId = roleId;
|
||||
this.functionId = functionId;
|
||||
this.halfChecked = halfChecked;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SystemUserRole {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private String userId;
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private int roleId;
|
||||
|
||||
public SystemUserRole(String userId, int roleId) {
|
||||
this.userId = userId;
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import com.kongx.common.core.entity.BaseEntity;
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UserGroup extends BaseEntity {
|
||||
private String name;
|
||||
private String useYn = "y";
|
||||
private List<UserInfo> userList = new ArrayList<>();
|
||||
private List<ProfileRole> profileRoles = new ArrayList<>();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.kongx.serve.entity.system;
|
||||
|
||||
import com.kongx.common.core.entity.UserInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class UserInfoVO extends UserInfo {
|
||||
private List<UserGroup> userGroupList = new ArrayList<>();
|
||||
}
|