feat: aos-web 完善
This commit is contained in:
@@ -32,6 +32,21 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.aos.common.copy;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -84,4 +85,26 @@ public class AosBeanUtils extends BeanUtils {
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页对象拷贝
|
||||
*
|
||||
* @param sources
|
||||
* @param target
|
||||
* @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<T>
|
||||
* @Date 2022/11/12
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static <S, T> Page<T> copyPageProperties(Page<S> sources, Supplier<T> target, BiConsumer<S, T> callBack) {
|
||||
Page<T> resultPage = new Page();
|
||||
copyProperties(sources, resultPage);
|
||||
List<S> records = sources.getRecords();
|
||||
List<T> targets = copyListProperties(records, target, callBack);
|
||||
resultPage.setRecords(targets);
|
||||
return resultPage;
|
||||
}
|
||||
|
||||
public static <S, T> Page<T> copyPageProperties(Page<S> sources, Supplier<T> target) {
|
||||
return copyPageProperties(sources, target, null);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ package com.aos.common.model;
|
||||
*/
|
||||
public interface ResultCodeInterface {
|
||||
/**
|
||||
* @return java.lang.Integer
|
||||
* @return java.lang.String
|
||||
* @Description 获取错误码
|
||||
* @Date 2020/11/8 15:37
|
||||
* @Author wangyl
|
||||
|
||||
@@ -16,9 +16,9 @@ public class SecurityUserInfo {
|
||||
*/
|
||||
private String username = "未知";
|
||||
/**
|
||||
* 登录id
|
||||
* 用户自增id
|
||||
*/
|
||||
private Long loginId = -1L;
|
||||
private Long id = -1L;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@@ -27,4 +27,6 @@ public class SecurityUserInfo {
|
||||
* 手机号
|
||||
*/
|
||||
private String phone = "";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,54 +14,39 @@ import lombok.Data;
|
||||
@Data
|
||||
public class AosBaseBizException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
protected String errorCode;
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
protected String errorMsg;
|
||||
|
||||
public AosBaseBizException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AosBaseBizException(ResultCodeInterface resultCode) {
|
||||
super(resultCode.getCode());
|
||||
super(resultCode.getMsg());
|
||||
this.errorCode = resultCode.getCode();
|
||||
this.errorMsg = resultCode.getMsg();
|
||||
}
|
||||
|
||||
public AosBaseBizException(ResultCodeInterface resultCode, Throwable cause) {
|
||||
super(resultCode.getCode(), cause);
|
||||
super(resultCode.getMsg(), cause);
|
||||
this.errorCode = resultCode.getCode();
|
||||
this.errorMsg = resultCode.getMsg();
|
||||
}
|
||||
|
||||
public AosBaseBizException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public AosBaseBizException(String errorCode, String errorMsg) {
|
||||
super(errorCode.toString());
|
||||
super(errorMsg);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public AosBaseBizException(String errorCode, String errorMsg, Throwable cause) {
|
||||
super(errorCode.toString(), cause);
|
||||
super(errorMsg, cause);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,12 +2,17 @@ package com.aos.common.model.result;
|
||||
|
||||
import com.aos.common.model.ResultCodeInterface;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/13
|
||||
* @description: 基础返回结果
|
||||
*/
|
||||
public enum ResultCode implements ResultCodeInterface {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
SUCCEED("200", "成功"),
|
||||
FAILED("-1", "系统异常");
|
||||
SUCCEED("000000", "成功"),
|
||||
FAILED("000001", "系统异常");
|
||||
private String code;
|
||||
private String msg;
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.aos.common.model.result;
|
||||
|
||||
import com.aos.common.model.ResultCodeInterface;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum WebResponse {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
WebResponse;
|
||||
|
||||
public <T> WebResult ok() {
|
||||
return new WebResult(ResultCode.SUCCEED);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(ResultCodeInterface resultCode, T data) {
|
||||
return new WebResult(resultCode, data);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(T data) {
|
||||
return new WebResult(ResultCode.SUCCEED, data);
|
||||
}
|
||||
|
||||
public <T> WebResult error() {
|
||||
return new WebResult(ResultCode.FAILED);
|
||||
}
|
||||
|
||||
public <T> WebResult error(T data) {
|
||||
return new WebResult(ResultCode.FAILED, data);
|
||||
}
|
||||
|
||||
public <T> WebResult error(ResultCodeInterface resultCode, T data) {
|
||||
return new WebResult(resultCode, data);
|
||||
}
|
||||
|
||||
public <T> WebResult error(ResultCodeInterface resultCode) {
|
||||
return new WebResult(resultCode);
|
||||
}
|
||||
|
||||
public <T> WebResult error(String code, String msg) {
|
||||
return new WebResult(code, msg);
|
||||
}
|
||||
|
||||
private <T> WebResult WebResponse(String code, String msg, T data) {
|
||||
return new WebResult(code, msg, data);
|
||||
}
|
||||
|
||||
private <T> WebResult WebResponse(String code, String msg) {
|
||||
return new WebResult(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.aos.common.request;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.ServletRequestBindingException;
|
||||
import org.springframework.web.bind.ServletRequestUtils;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/12
|
||||
* @description: 请求工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class RequestUtils {
|
||||
public static HttpServletRequest getRequest() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
|
||||
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static HttpServletResponse getResponse() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
|
||||
HttpServletResponse response = ((ServletRequestAttributes) requestAttributes).getResponse();
|
||||
return response;
|
||||
}
|
||||
|
||||
public static String getValueFromRequest(String key) {
|
||||
HttpServletRequest request = getRequest();
|
||||
String value = getValue(request, key);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Cookie getCookie(String key) {
|
||||
return getCookie(getRequest(), key);
|
||||
}
|
||||
|
||||
public static void cleanCookie(String key) {
|
||||
HttpServletResponse response = getResponse();
|
||||
HttpServletRequest request = getRequest();
|
||||
Cookie cookie = getCookie(request, key);
|
||||
if (!Objects.isNull(cookie)) {
|
||||
cookie.setValue(null);
|
||||
cookie.setMaxAge(0);
|
||||
cookie.setPath("/");
|
||||
cookie.setDomain(request.getServerName());
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String getValue(HttpServletRequest request, String key) {
|
||||
String value = null;
|
||||
try {
|
||||
value = ServletRequestUtils.getStringParameter(request, key);
|
||||
} catch (ServletRequestBindingException var4) {
|
||||
log.error("获取请求参数异常:", var4);
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = request.getHeader(key);
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
Cookie cookie = getCookie(request, key);
|
||||
value = Objects.isNull(cookie) ? null : cookie.getValue();
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Cookie getCookie(HttpServletRequest request, String key) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (!Objects.isNull(cookies)) {
|
||||
Cookie[] var3 = cookies;
|
||||
int var4 = cookies.length;
|
||||
|
||||
for (int var5 = 0; var5 < var4; ++var5) {
|
||||
Cookie cookie = var3[var5];
|
||||
if (cookie.getName().equals(key)) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,133 @@
|
||||
package com.aos.common.thread;
|
||||
|
||||
import com.alibaba.ttl.TtlRunnable;
|
||||
import lombok.Builder;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/4
|
||||
* @description: ttl的线程池
|
||||
*/
|
||||
@Builder
|
||||
public class TtlThreadPool extends ThreadPoolExecutor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code ThreadPoolExecutor} with the given initial
|
||||
* parameters and default thread factory and rejected execution handler.
|
||||
* It may be more convenient to use one of the {@link Executors} factory
|
||||
* methods instead of this general purpose constructor.
|
||||
*
|
||||
* @param corePoolSize the number of threads to keep in the pool, even
|
||||
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
|
||||
* @param maximumPoolSize the maximum number of threads to allow in the
|
||||
* pool
|
||||
* @param keepAliveTime when the number of threads is greater than
|
||||
* the core, this is the maximum time that excess idle threads
|
||||
* will wait for new tasks before terminating.
|
||||
* @param unit the time unit for the {@code keepAliveTime} argument
|
||||
* @param workQueue the queue to use for holding tasks before they are
|
||||
* executed. This queue will hold only the {@code Runnable}
|
||||
* tasks submitted by the {@code execute} method.
|
||||
* @throws IllegalArgumentException if one of the following holds:<br>
|
||||
* {@code corePoolSize < 0}<br>
|
||||
* {@code keepAliveTime < 0}<br>
|
||||
* {@code maximumPoolSize <= 0}<br>
|
||||
* {@code maximumPoolSize < corePoolSize}
|
||||
* @throws NullPointerException if {@code workQueue} is null
|
||||
*/
|
||||
public TtlThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code ThreadPoolExecutor} with the given initial
|
||||
* parameters and default rejected execution handler.
|
||||
*
|
||||
* @param corePoolSize the number of threads to keep in the pool, even
|
||||
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
|
||||
* @param maximumPoolSize the maximum number of threads to allow in the
|
||||
* pool
|
||||
* @param keepAliveTime when the number of threads is greater than
|
||||
* the core, this is the maximum time that excess idle threads
|
||||
* will wait for new tasks before terminating.
|
||||
* @param unit the time unit for the {@code keepAliveTime} argument
|
||||
* @param workQueue the queue to use for holding tasks before they are
|
||||
* executed. This queue will hold only the {@code Runnable}
|
||||
* tasks submitted by the {@code execute} method.
|
||||
* @param threadFactory the factory to use when the executor
|
||||
* creates a new thread
|
||||
* @throws IllegalArgumentException if one of the following holds:<br>
|
||||
* {@code corePoolSize < 0}<br>
|
||||
* {@code keepAliveTime < 0}<br>
|
||||
* {@code maximumPoolSize <= 0}<br>
|
||||
* {@code maximumPoolSize < corePoolSize}
|
||||
* @throws NullPointerException if {@code workQueue}
|
||||
* or {@code threadFactory} is null
|
||||
*/
|
||||
public TtlThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code ThreadPoolExecutor} with the given initial
|
||||
* parameters and default thread factory.
|
||||
*
|
||||
* @param corePoolSize the number of threads to keep in the pool, even
|
||||
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
|
||||
* @param maximumPoolSize the maximum number of threads to allow in the
|
||||
* pool
|
||||
* @param keepAliveTime when the number of threads is greater than
|
||||
* the core, this is the maximum time that excess idle threads
|
||||
* will wait for new tasks before terminating.
|
||||
* @param unit the time unit for the {@code keepAliveTime} argument
|
||||
* @param workQueue the queue to use for holding tasks before they are
|
||||
* executed. This queue will hold only the {@code Runnable}
|
||||
* tasks submitted by the {@code execute} method.
|
||||
* @param handler the handler to use when execution is blocked
|
||||
* because the thread bounds and queue capacities are reached
|
||||
* @throws IllegalArgumentException if one of the following holds:<br>
|
||||
* {@code corePoolSize < 0}<br>
|
||||
* {@code keepAliveTime < 0}<br>
|
||||
* {@code maximumPoolSize <= 0}<br>
|
||||
* {@code maximumPoolSize < corePoolSize}
|
||||
* @throws NullPointerException if {@code workQueue}
|
||||
* or {@code handler} is null
|
||||
*/
|
||||
public TtlThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code ThreadPoolExecutor} with the given initial
|
||||
* parameters.
|
||||
*
|
||||
* @param corePoolSize the number of threads to keep in the pool, even
|
||||
* if they are idle, unless {@code allowCoreThreadTimeOut} is set
|
||||
* @param maximumPoolSize the maximum number of threads to allow in the
|
||||
* pool
|
||||
* @param keepAliveTime when the number of threads is greater than
|
||||
* the core, this is the maximum time that excess idle threads
|
||||
* will wait for new tasks before terminating.
|
||||
* @param unit the time unit for the {@code keepAliveTime} argument
|
||||
* @param workQueue the queue to use for holding tasks before they are
|
||||
* executed. This queue will hold only the {@code Runnable}
|
||||
* tasks submitted by the {@code execute} method.
|
||||
* @param threadFactory the factory to use when the executor
|
||||
* creates a new thread
|
||||
* @param handler the handler to use when execution is blocked
|
||||
* because the thread bounds and queue capacities are reached
|
||||
* @throws IllegalArgumentException if one of the following holds:<br>
|
||||
* {@code corePoolSize < 0}<br>
|
||||
* {@code keepAliveTime < 0}<br>
|
||||
* {@code maximumPoolSize <= 0}<br>
|
||||
* {@code maximumPoolSize < corePoolSize}
|
||||
* @throws NullPointerException if {@code workQueue}
|
||||
* or {@code threadFactory} or {@code handler} is null
|
||||
*/
|
||||
public TtlThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
TtlRunnable.get(command);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.aos.common.tree;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wangyl
|
||||
* @version V1.0
|
||||
* @ClassName: TreeNode
|
||||
* @Function: 树节点
|
||||
* @Date: 2019/9/24 14:29
|
||||
*/
|
||||
@Data
|
||||
public class TreeNode<T> {
|
||||
protected Object id;
|
||||
protected String name;
|
||||
protected Object parentId;
|
||||
protected Integer childrenCount = 0;
|
||||
|
||||
public TreeNode(Object id, Object parentId) {
|
||||
this.id = id;
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
List<T> children = new ArrayList<T>();
|
||||
|
||||
public void add(T node) {
|
||||
children.add(node);
|
||||
this.childrenCount = this.childrenCount + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.aos.common.tree;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author wangyl
|
||||
* @version V1.0
|
||||
* @ClassName: TreeUtil
|
||||
* @Function: 建立树型结构
|
||||
* @Date: 2019/9/24 14:28
|
||||
*/
|
||||
public class TreeUtil<T extends TreeNode> {
|
||||
/**
|
||||
* @Description 建立树
|
||||
* @Date 2019/9/24 14:33
|
||||
* @Param
|
||||
* @return
|
||||
* @Author wangyl
|
||||
* @Version V1.0
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> bulid(List<T> treeNodes, Object root) {
|
||||
List<T> trees = new ArrayList<T>();
|
||||
for (T treeNode : treeNodes){
|
||||
if (root.equals(treeNode.getParentId())) {
|
||||
trees.add(treeNode);
|
||||
}
|
||||
for (T it : treeNodes){
|
||||
if (it.getParentId()
|
||||
.equals(treeNode.getId())) {
|
||||
if (treeNode.getChildren() == null) {
|
||||
treeNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
treeNode.add(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 递归建树
|
||||
* @Date 2019/9/24 14:34
|
||||
* @Param
|
||||
* @return
|
||||
* @Author wangyl
|
||||
* @Version V1.0
|
||||
*/
|
||||
public static <T extends TreeNode> List<T> buildByRecursive(List<T> treeNodes, Object root) {
|
||||
List<T> trees = new ArrayList<T>();
|
||||
for (T treeNode : treeNodes) {
|
||||
if (root.equals(treeNode.getParentId())) {
|
||||
trees.add(findChildren(treeNode, treeNodes));
|
||||
}
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 递归查找子节点
|
||||
* @Date 2019/9/24 14:34
|
||||
* @Param
|
||||
* @return
|
||||
* @Author wangyl
|
||||
* @Version V1.0
|
||||
*/
|
||||
public static <T extends TreeNode> T findChildren(T treeNode, List<T> treeNodes) {
|
||||
for (T it : treeNodes) {
|
||||
if (treeNode.getId().equals(it.getParentId())) {
|
||||
if (treeNode.getChildren() == null) {
|
||||
treeNode.setChildren(new ArrayList<TreeNode>());
|
||||
}
|
||||
treeNode.add(findChildren(it, treeNodes));
|
||||
}
|
||||
}
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 获取树的所有节点的值
|
||||
* @param treeNodes 树
|
||||
* @param resultIdList 返回所有节点的id列表
|
||||
* @return void
|
||||
* @Date 2020/3/30 16:23
|
||||
* @Author wangyl
|
||||
* @Version V1.0
|
||||
*/
|
||||
public static <T extends TreeNode> void getTreeChildrenIds(List<T> treeNodes, List<Object> resultIdList) {
|
||||
for (T it : treeNodes){
|
||||
resultIdList.add(it.getId());
|
||||
if (it.getChildrenCount() != 0) {
|
||||
getTreeChildrenIds(it.getChildren(), resultIdList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,27 @@
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>${ttl.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--aos-->
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-web</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-mybatis-plus</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-swagger</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
+17
-4
@@ -27,13 +27,21 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-swagger</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-swagger</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
@@ -45,6 +53,11 @@
|
||||
<artifactId>aos-robot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-mybatis-plus</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.aos.test.web;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -19,10 +16,10 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Api(value = "ActivityDemandController", tags = "需求计划入口")
|
||||
public class ActivityDemandController {
|
||||
|
||||
@PostMapping("/getListPage")
|
||||
@PostMapping("/保存")
|
||||
@ApiOperation(value = "分页查询活动需求")
|
||||
public String getListPage() {
|
||||
return "1";
|
||||
public void save() {
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/getListPage1")
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.aos.test.web2;
|
||||
|
||||
import com.aos.common.model.result.WebResponse;
|
||||
import com.aos.common.model.result.WebResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: zouyang
|
||||
* @date: 2022/6/1
|
||||
@@ -18,14 +23,14 @@ public class ActivityDemandController2 {
|
||||
|
||||
@PostMapping("/getListPage2")
|
||||
@ApiOperation(value = "分页查询活动需求2")
|
||||
public String getListPage() {
|
||||
return "1";
|
||||
public WebResult<String> getListPage() {
|
||||
return WebResponse.WebResponse.ok(1);
|
||||
}
|
||||
|
||||
@PostMapping("/getListPage12")
|
||||
@ApiOperation(value = "分页查询活动需求12")
|
||||
public String getListPage1() {
|
||||
return "2";
|
||||
public List<Long> getListPage1() {
|
||||
return Arrays.asList(1L, 2L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
aos.robots.wx.id=dc62c56e-c194-4a22-87ff-d9d0e30f56b4
|
||||
spring.profiles.active=dev
|
||||
spring.datasource.url=jdbc:mysql://wylgyx.top:6003/aos-core?useUnicode=true&serverTimezone=UTC&characterEncoding=utf8&useSSL=false&autoReconnect=true&failOverReadOnly=false&rewriteBatchedStatements=true
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=Wyl.0629
|
||||
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
spring.profiles.active=dev
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.aos.test;
|
||||
|
||||
import com.aos.robot.WXAlarm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@Slf4j
|
||||
public class ApplicationTest {
|
||||
|
||||
@Autowired
|
||||
WXAlarm wxAlarm;
|
||||
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
wxAlarm.alarm("wx", "qwe");
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,13 @@
|
||||
package com.aos.test;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.aos.robot.WXAlarm;
|
||||
import lombok.Data;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(args = "--eureka.client.register-with-eureka=false", webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseTest.Application.class)
|
||||
public class BaseTest {
|
||||
@@ -22,28 +16,29 @@ public class BaseTest {
|
||||
WXAlarm wxAlarm;
|
||||
|
||||
@ComponentScan(basePackages = {"com.aos.test"})
|
||||
@MapperScan(basePackages = {"com.aos.test.mybatis.mapper"})
|
||||
public static class Application {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotTest() {
|
||||
tmp tmp = new tmp();
|
||||
tmp.setAge(1);
|
||||
tmp.setName("wyl");
|
||||
String test = JSONUtil.toJsonStr(tmp);
|
||||
String format = MessageFormat.format("测试 {0},{1}", test, test);
|
||||
System.out.println(format);
|
||||
// wxAlarm.alarm("test", "123");
|
||||
}
|
||||
|
||||
@Data
|
||||
public class tmp {
|
||||
String name;
|
||||
Integer age;
|
||||
LocalDate date = LocalDate.now();
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
}
|
||||
// @Test
|
||||
// public void robotTest() {
|
||||
// tmp tmp = new tmp();
|
||||
// tmp.setAge(1);
|
||||
// tmp.setName("wyl");
|
||||
// String test = JSONUtil.toJsonStr(tmp);
|
||||
// String format = MessageFormat.format("测试 {0},{1}", test, test);
|
||||
// System.out.println(format);
|
||||
//// wxAlarm.alarm("test", "123");
|
||||
// }
|
||||
//
|
||||
// @Data
|
||||
// public class tmp {
|
||||
// String name;
|
||||
// Integer age;
|
||||
// LocalDate date = LocalDate.now();
|
||||
// LocalDateTime dateTime = LocalDateTime.now();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.aos.test.mybatis;
|
||||
|
||||
import com.aos.test.BaseTest;
|
||||
import com.aos.test.mybatis.domain.TestTable;
|
||||
import com.aos.test.mybatis.service.TestService;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MybatisPlusTest extends BaseTest {
|
||||
@Autowired
|
||||
TestService testService;
|
||||
|
||||
@Test
|
||||
public void add() {
|
||||
TestTable test = new TestTable();
|
||||
test.setText("123");
|
||||
testService.save(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() {
|
||||
testService.removeById(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void get() {
|
||||
List<TestTable> list = testService.list();
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@
|
||||
|
||||
<artifactId>aos-mybatis-plus</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
@@ -19,17 +23,18 @@
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.aos.mybatis.plus.conf;
|
||||
|
||||
import com.aos.mybatis.plus.handle.AosMetaObjectHandler;
|
||||
import com.aos.mybatis.plus.interceptor.MybatisSqlCompletePrintInterceptor;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@@ -27,7 +30,6 @@ public class MybatisPlusConf {
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnClass(org.apache.ibatis.plugin.Interceptor.class)
|
||||
MybatisSqlCompletePrintInterceptor mybatisSqlCompletePrintInterceptor() {
|
||||
return new MybatisSqlCompletePrintInterceptor();
|
||||
}
|
||||
@@ -44,7 +46,18 @@ public class MybatisPlusConf {
|
||||
@ConditionalOnMissingBean(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.class)
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
/**
|
||||
* 分页 size -1 为全部
|
||||
*/
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
/**
|
||||
* 全表更新
|
||||
*/
|
||||
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@@ -62,8 +75,28 @@ public class MybatisPlusConf {
|
||||
public MybatisPlusPropertiesCustomizer plusPropertiesCustomizer() {
|
||||
return plusProperties -> plusProperties.getGlobalConfig()
|
||||
.getDbConfig()
|
||||
.setLogicDeleteField("deleted")
|
||||
.setLogicDeleteValue("1")
|
||||
.setLogicNotDeleteValue("0");
|
||||
.setLogicDeleteField(MybatisPlusConstant.DELETE)
|
||||
.setLogicDeleteValue(MybatisPlusConstant.TRUE)
|
||||
.setLogicNotDeleteValue(MybatisPlusConstant.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* aos默认字段填充
|
||||
*
|
||||
* @param
|
||||
* @return com.aos.mybatis.plus.handle.AosMetaObjectHandler
|
||||
* @Date 2022/11/12
|
||||
* @Author wangyl
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({AosMetaObjectHandler.class})
|
||||
public AosMetaObjectHandler aosMetaObjectHandler() {
|
||||
return new AosMetaObjectHandler();
|
||||
}
|
||||
|
||||
public class MybatisPlusConstant {
|
||||
final static String DELETE = "delete_time";
|
||||
final static String FALSE = "null";
|
||||
final static String TRUE = "now()";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.aos.mybatis.plus.handle;
|
||||
|
||||
import com.aos.common.model.context.CurrentUserContextHolder;
|
||||
import com.aos.common.model.context.SecurityUserInfo;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Component
|
||||
public class AosMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
/**
|
||||
* 有值也覆盖
|
||||
*
|
||||
* @param metaObject
|
||||
* @param fieldName
|
||||
* @param fieldVal
|
||||
* @return com.baomidou.mybatisplus.core.handlers.MetaObjectHandler
|
||||
* @Date 2022/11/12
|
||||
* @Author wangyl
|
||||
*/
|
||||
@Override
|
||||
public MetaObjectHandler strictFillStrategy(MetaObject metaObject, String fieldName, Supplier<?> fieldVal) {
|
||||
Object obj = fieldVal.get();
|
||||
if (Objects.nonNull(obj)) {
|
||||
metaObject.setValue(fieldName, obj);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
SecurityUserInfo securityUserInfo = CurrentUserContextHolder.getContext();
|
||||
Long userId = securityUserInfo.getId();
|
||||
String userName = securityUserInfo.getUsername();
|
||||
this.strictInsertFill(metaObject, MybatisPlusConstant.CREATE_USER_BY, Long.class, userId);
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.CREATE_USER_NAME)) {
|
||||
this.strictInsertFill(metaObject, MybatisPlusConstant.CREATE_USER_NAME, String.class, userName);
|
||||
}
|
||||
|
||||
this.strictInsertFill(metaObject, MybatisPlusConstant.CREATE_AT, LocalDateTime.class, LocalDateTime.now());
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.UPDATE_USER_BY)) {
|
||||
this.strictInsertFill(metaObject, MybatisPlusConstant.UPDATE_USER_BY, Long.class, userId);
|
||||
}
|
||||
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.UPDATE_USER_NAME)) {
|
||||
this.strictInsertFill(metaObject, MybatisPlusConstant.UPDATE_USER_NAME, String.class, userName);
|
||||
}
|
||||
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.UPDATE_AT)) {
|
||||
this.strictInsertFill(metaObject, MybatisPlusConstant.UPDATE_AT, LocalDateTime.class, LocalDateTime.now());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
SecurityUserInfo securityUserInfo = CurrentUserContextHolder.getContext();
|
||||
Long userId = securityUserInfo.getId();
|
||||
String userName = securityUserInfo.getUsername();
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.UPDATE_USER_BY)) {
|
||||
this.strictUpdateFill(metaObject, MybatisPlusConstant.UPDATE_USER_BY, Long.class, userId);
|
||||
}
|
||||
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.UPDATE_USER_NAME)) {
|
||||
this.strictUpdateFill(metaObject, MybatisPlusConstant.UPDATE_USER_NAME, String.class, userName);
|
||||
}
|
||||
|
||||
if (metaObject.hasSetter(MybatisPlusConstant.UPDATE_AT)) {
|
||||
this.strictUpdateFill(metaObject, MybatisPlusConstant.UPDATE_AT, LocalDateTime.class, LocalDateTime.now());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MybatisPlusConstant {
|
||||
public static final String CREATE_USER_BY = "createdBy";
|
||||
public static final String CREATE_USER_NAME = "createdName";
|
||||
public static final String CREATE_AT = "createdAt";
|
||||
public static final String UPDATE_USER_BY = "updatedBy";
|
||||
public static final String UPDATE_USER_NAME = "updatedName";
|
||||
public static final String UPDATE_AT = "updatedAt";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.aos.mybatis.plus.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/10/31
|
||||
* @description: 数据表基础类
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseEntity {
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@ApiModelProperty(value = "创建人ID")
|
||||
private Long createdBy;
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@ApiModelProperty(value = "创建人姓名")
|
||||
private String createdName;
|
||||
/**
|
||||
* 创建时间,默认为当前时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
/**
|
||||
* 更新人id
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@ApiModelProperty(value = "更新人id")
|
||||
private Long updatedBy;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private String updatedName;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
/**
|
||||
* 逻辑删除
|
||||
* null 未删除
|
||||
* 其他值为删除时间
|
||||
*/
|
||||
@TableField(value = "delete_time")
|
||||
@TableLogic
|
||||
@ApiModelProperty(value = "删除时间")
|
||||
private LocalDateTime deleteTime;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.aos.robot;
|
||||
|
||||
import com.aos.robot.model.MegTypeEnum;
|
||||
import com.aos.robot.model.WxRobotParam;
|
||||
import com.aos.robot.model.wx.WxRobotParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
package com.aos.robot;
|
||||
|
||||
import com.aos.robot.model.RobotConfig;
|
||||
import com.aos.robot.model.RobotInfo;
|
||||
import com.aos.robot.model.RobotPatam;
|
||||
import com.aos.robot.model.WxRobotRes;
|
||||
import com.aos.robot.service.Robot;
|
||||
import com.aos.robot.conf.RobotInfo;
|
||||
import com.aos.robot.model.MegTypeEnum;
|
||||
import com.aos.robot.model.base.RobotPatam;
|
||||
import com.aos.robot.model.wx.WxRobotRes;
|
||||
import com.aos.robot.service.AbstractRobot;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WxRobot implements Robot {
|
||||
public class WxRobot extends AbstractRobot {
|
||||
|
||||
@Resource(name = "robotRestTemplate")
|
||||
RestTemplate restTemplate;
|
||||
@Autowired
|
||||
RobotConfig robotConfig;
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
@@ -34,12 +30,9 @@ public class WxRobot implements Robot {
|
||||
* @Author wangyl
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String robotName, RobotPatam robotParam) {
|
||||
RobotInfo robotInfo = robotConfig.getRobots().get(robotName);
|
||||
if (StringUtils.isEmpty(robotInfo)) {
|
||||
throw new RuntimeException("获取机器人名称:" + robotName + "对应的id失败,请检查配置asura.robot.wx.ids." + robotName + "是否存在");
|
||||
}
|
||||
String url = robotInfo.getUrl() + robotInfo.getId();
|
||||
protected void sendMessage(String robotName, RobotPatam robotParam) {
|
||||
RobotInfo robotInfo = getRobotInfo(robotName);
|
||||
String url = robotInfo.getUrl() + robotInfo.getToken();
|
||||
ResponseEntity<WxRobotRes> stringResponseEntity = restTemplate.postForEntity(url, robotParam, WxRobotRes.class);
|
||||
if (stringResponseEntity.getStatusCode() != HttpStatus.OK) {
|
||||
throw new RuntimeException("消息发送异常,网络代码【" + stringResponseEntity.getStatusCodeValue() + "】");
|
||||
@@ -51,4 +44,52 @@ public class WxRobot implements Robot {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通信息
|
||||
*
|
||||
* @param robotName
|
||||
* @param messageTypeEnum
|
||||
* @param message
|
||||
* @param value
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
@Override
|
||||
public void info(String robotName, MegTypeEnum messageTypeEnum, String message, Object... value) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警信息
|
||||
*
|
||||
* @param robotName
|
||||
* @param messageTypeEnum
|
||||
* @param message
|
||||
* @param value
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
@Override
|
||||
public void warning(String robotName, MegTypeEnum messageTypeEnum, String message, Object... value) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*
|
||||
* @param robotName
|
||||
* @param messageTypeEnum
|
||||
* @param message
|
||||
* @param error
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
@Override
|
||||
public void error(String robotName, MegTypeEnum messageTypeEnum, String message, Throwable error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.aos.robot.conf;
|
||||
|
||||
import com.aos.robot.model.RobotConfig;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.aos.robot.model;
|
||||
package com.aos.robot.conf;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.aos.robot.conf;
|
||||
|
||||
import com.aos.robot.model.RobotTypeEnum;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/11
|
||||
* @description: 机器人基础配置
|
||||
*/
|
||||
@Data
|
||||
public class RobotInfo {
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
private String token;
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 机器人类型
|
||||
*/
|
||||
private RobotTypeEnum robotTypeEnum;
|
||||
|
||||
public String getUrl() {
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
return robotTypeEnum.getDefaultUrl();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.aos.robot.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class RobotInfo {
|
||||
private String id;
|
||||
private String url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.aos.robot.model;
|
||||
|
||||
public interface RobotPatam {
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.aos.robot.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: zouyang
|
||||
* @date: 2022/6/1
|
||||
* @description: 活动需求状态
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum RobotTypeEnum {
|
||||
/**
|
||||
* 企业微信机器人
|
||||
*/
|
||||
WX(0, "WX", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key="),
|
||||
/**
|
||||
* 钉钉机器人
|
||||
*/
|
||||
DingDing(1, "DingDing", ""),
|
||||
;
|
||||
private static final Map<Integer, RobotTypeEnum> RobotTypeMAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (RobotTypeEnum type : RobotTypeEnum.values()) {
|
||||
RobotTypeMAP.put(type.getValue(), type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实际值
|
||||
*/
|
||||
private final Integer value;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String desc;
|
||||
/**
|
||||
* 默认url
|
||||
*/
|
||||
private final String defaultUrl;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.aos.robot.model.base;
|
||||
|
||||
public interface RobotPatam {
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.aos.robot.model;
|
||||
package com.aos.robot.model.base;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package com.aos.robot.model;
|
||||
package com.aos.robot.model.wx;
|
||||
|
||||
import com.aos.robot.model.MegTypeEnum;
|
||||
import com.aos.robot.model.base.RobotPatam;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.aos.robot.model;
|
||||
package com.aos.robot.model.wx;
|
||||
|
||||
import com.aos.robot.model.base.RobotRes;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.aos.robot.service;
|
||||
|
||||
import com.aos.robot.conf.RobotConfig;
|
||||
import com.aos.robot.conf.RobotInfo;
|
||||
import com.aos.robot.model.base.RobotPatam;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public abstract class AbstractRobot implements Robot {
|
||||
|
||||
@Autowired
|
||||
protected RobotConfig robotConfig;
|
||||
|
||||
/**
|
||||
* 通过机器人名字 获取机器人配置
|
||||
*
|
||||
* @param robotName
|
||||
* @return com.aos.robot.conf.RobotInfo
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
protected RobotInfo getRobotInfo(String robotName) {
|
||||
RobotInfo robotInfo = robotConfig.getRobots().get(robotName);
|
||||
if (StringUtils.isEmpty(robotInfo)) {
|
||||
throw new RuntimeException("获取机器人名称:" + robotName + "对应的id失败,请检查配置asura.robot.wx.ids." + robotName + "是否存在");
|
||||
}
|
||||
return robotInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装错误堆栈信息
|
||||
*
|
||||
* @param error
|
||||
* @return java.lang.String
|
||||
* @Date 2022/11/11
|
||||
* @Author wangyl
|
||||
*/
|
||||
protected String getStackTrace(Throwable error) {
|
||||
String stackTrace = ExceptionUtils.getStackTrace(error);
|
||||
String message = "\n" + "错误信息:" + error.getMessage();
|
||||
message = message + "\n" + stackTrace;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param robotName
|
||||
* @param robotParam
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
abstract protected void sendMessage(String robotName, RobotPatam robotParam);
|
||||
|
||||
}
|
||||
@@ -1,16 +1,46 @@
|
||||
package com.aos.robot.service;
|
||||
|
||||
import com.aos.robot.model.RobotPatam;
|
||||
import com.aos.robot.model.MegTypeEnum;
|
||||
import com.aos.robot.model.base.RobotPatam;
|
||||
|
||||
public interface Robot {
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* 普通信息
|
||||
*
|
||||
* @param robotName
|
||||
* @param robotParam
|
||||
* @param messageTypeEnum
|
||||
* @param message
|
||||
* @param value
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
void sendMessage(String robotName, RobotPatam robotParam);
|
||||
void info(String robotName, MegTypeEnum messageTypeEnum, String message, Object... value);
|
||||
|
||||
/**
|
||||
* 告警信息
|
||||
*
|
||||
* @param robotName
|
||||
* @param messageTypeEnum
|
||||
* @param message
|
||||
* @param value
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
void warning(String robotName, MegTypeEnum messageTypeEnum, String message, Object... value);
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*
|
||||
* @param robotName
|
||||
* @param messageTypeEnum
|
||||
* @param message
|
||||
* @param error
|
||||
* @return void
|
||||
* @Date 2022/11/10
|
||||
* @Author wangyl
|
||||
*/
|
||||
void error(String robotName, MegTypeEnum messageTypeEnum, String message, Throwable error);
|
||||
}
|
||||
|
||||
+8
-18
@@ -17,24 +17,6 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger-bootstrap-ui-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
@@ -52,5 +34,13 @@
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.aos.web.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/13
|
||||
* @description: 标记不需要包装返回结果的方法
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NotControllerResponseAdvice {
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.aos.web.conf;
|
||||
import com.aos.web.filter.BodyRepeatReaderHttpServletFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
@@ -11,6 +12,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @description: mybatis-plus配置
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan()
|
||||
public class AosWebConf {
|
||||
|
||||
@Bean
|
||||
@@ -24,8 +26,7 @@ public class AosWebConf {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BodyRepeatReaderHttpServletFilter bodyRepeatReaderHttpServletFilter()
|
||||
{
|
||||
public BodyRepeatReaderHttpServletFilter bodyRepeatReaderHttpServletFilter() {
|
||||
return new BodyRepeatReaderHttpServletFilter();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.aos.web.conf;
|
||||
|
||||
import com.aos.common.model.result.WebResponse;
|
||||
import com.aos.common.model.result.WebResult;
|
||||
import com.aos.web.annotations.NotControllerResponseAdvice;
|
||||
import com.aos.web.exception.AosWebBizException;
|
||||
import com.aos.web.exception.WebResultCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/14
|
||||
* @description: 统一返回处理器
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
|
||||
@Autowired
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
/**
|
||||
*response是ResultVo类型,或者注释了NotControllerResponseAdvice都不进行包装
|
||||
*/
|
||||
return (!methodParameter.getParameterType().isAssignableFrom(WebResult.class)
|
||||
|| methodParameter.hasMethodAnnotation(NotControllerResponseAdvice.class));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object data, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
||||
if (returnType.getGenericParameterType().equals(String.class)) {
|
||||
try {
|
||||
/**
|
||||
* 如果返回值是String 需要手动转换为json
|
||||
*/
|
||||
return objectMapper.writeValueAsString(WebResponse.WebResponse.ok(data));
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("", e);
|
||||
throw new AosWebBizException(WebResultCode.WEB_CONVERSION_ERROR, e);
|
||||
}
|
||||
}
|
||||
return WebResponse.WebResponse.ok(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.aos.web.exception;
|
||||
|
||||
import com.aos.common.model.ResultCodeInterface;
|
||||
import com.aos.common.model.exception.AosBaseBizException;
|
||||
|
||||
public class AosWebBizException extends AosBaseBizException {
|
||||
public AosWebBizException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AosWebBizException(ResultCodeInterface resultCode) {
|
||||
super(resultCode);
|
||||
}
|
||||
|
||||
public AosWebBizException(ResultCodeInterface resultCode, Throwable cause) {
|
||||
super(resultCode, cause);
|
||||
}
|
||||
|
||||
public AosWebBizException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
}
|
||||
|
||||
public AosWebBizException(String errorCode, String errorMsg) {
|
||||
super(errorCode, errorMsg);
|
||||
}
|
||||
|
||||
public AosWebBizException(String errorCode, String errorMsg, Throwable cause) {
|
||||
super(errorCode, errorMsg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.aos.web.exception;
|
||||
|
||||
import com.aos.common.model.ResultCodeInterface;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author: wangyl
|
||||
* @date: 2022/11/13
|
||||
* @description: 基础返回结果
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum WebResultCode implements ResultCodeInterface {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
WEB_CONVERSION_ERROR("010000", "String类型参数转化失败"),
|
||||
;
|
||||
private String code;
|
||||
private String msg;
|
||||
}
|
||||
Reference in New Issue
Block a user