diff --git a/common.sql b/common.sql
index 79f1e59..3745f7b 100644
--- a/common.sql
+++ b/common.sql
@@ -14,7 +14,7 @@ create table sys_config
type int default 1 null comment '配置类型',
config_desc varchar(256) null comment '描述'
)
- comment '系统配置(v3)' charset = utf8;
+ comment '系统配置(v3)' charset = utf8mb4;
create index sys_config__index_key
on sys_config (`key`);
@@ -40,7 +40,7 @@ create table sys_schedule
plat_exec_time datetime null comment '计划执行时间',
schedule_desc varchar(256) null comment '任务描述'
)
- comment '系统分布式任务(v3)';
+ comment '系统分布式任务(v3)' charset = utf8mb4;
create index index_status
on sys_schedule (status);
diff --git a/common/README.md b/common/README.md
index a76cec1..c52477b 100644
--- a/common/README.md
+++ b/common/README.md
@@ -8,7 +8,8 @@ keray:
global-switch: # 全局开启json解析
data: true # 接口qps配置
time: true # 接口时长统计
-
+ log:
+ all: true #api日志
```
## cache使用
diff --git a/common/src/main/java/com/keray/common/BEntity.java b/common/src/main/java/com/keray/common/BEntity.java
new file mode 100644
index 0000000..c4b58df
--- /dev/null
+++ b/common/src/main/java/com/keray/common/BEntity.java
@@ -0,0 +1,11 @@
+package com.keray.common;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+
+/**
+ * @author by keray
+ * date:2020/7/15 9:38 上午
+ */
+public class BEntity> extends Model implements IBEntity{
+
+}
diff --git a/common/src/main/java/com/keray/common/IBEntity.java b/common/src/main/java/com/keray/common/IBEntity.java
new file mode 100644
index 0000000..01c3390
--- /dev/null
+++ b/common/src/main/java/com/keray/common/IBEntity.java
@@ -0,0 +1,9 @@
+package com.keray.common;
+
+/**
+ * @author by keray
+ * date:2020/7/15 9:38 上午
+ */
+public interface IBEntity> {
+
+}
diff --git a/common/src/main/java/com/keray/common/IBMapper.java b/common/src/main/java/com/keray/common/IBMapper.java
new file mode 100644
index 0000000..590fad0
--- /dev/null
+++ b/common/src/main/java/com/keray/common/IBMapper.java
@@ -0,0 +1,117 @@
+package com.keray.common;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.TypeUtil;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.SqlSession;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * @author by keray
+ * date:2019/7/25 16:56
+ */
+public interface IBMapper> extends BaseMapper {
+
+ /**
+ * 根据 whereEntity 条件,更新记录
+ *
+ * @param entity 实体对象 (set 条件值,可以为 null)
+ * @param updateWrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
+ * @return
+ */
+ @Override
+ int update(@Param(Constants.ENTITY) B entity, @Param(Constants.WRAPPER) Wrapper updateWrapper);
+
+ /**
+ *
+ *
作者 keray
+ * 时间: 2019/10/24 17:43
+ * 查询sum
+ *
+ *
+ * @param wrapper
+ * @return {@link String}
+ * @throws
+ */
+ Double selectSum(@Param(Constants.WRAPPER) Wrapper wrapper);
+
+ /**
+ * 插入一条记录
+ *
+ * @param entity 实体对象
+ * @return
+ */
+ @Override
+ int insert(B entity);
+
+
+ /**
+ *
+ * 插入(批量)
+ *
+ *
+ * @param entityList 实体对象列表
+ * @param batchSize 插入批次数量
+ * @return boolean
+ */
+ @Transactional(rollbackFor = Exception.class)
+ default boolean insertBatch(List entityList, int batchSize) {
+ if (CollUtil.isEmpty(entityList)) {
+ throw new IllegalArgumentException("Error: entityList must not be empty");
+ }
+ try (SqlSession batchSqlSession = sqlSessionBatch()) {
+ int size = entityList.size();
+ String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE);
+ for (int i = 0; i < size; i++) {
+ batchSqlSession.insert(sqlStatement, entityList.get(i));
+ if (i >= 1 && i % batchSize == 0) {
+ batchSqlSession.flushStatements();
+ }
+ }
+ batchSqlSession.flushStatements();
+ } catch (Throwable e) {
+ throw new MybatisPlusException("Error: Cannot execute insertBatch Method. Cause", e);
+ }
+ return true;
+ }
+
+
+ default boolean exits(Wrapper wrapper) {
+ return selectCount(wrapper) > 0;
+ }
+ /**
+ *
+ * 批量操作 SqlSession
+ *
+ */
+ default SqlSession sqlSessionBatch() {
+ return SqlHelper.sqlSessionBatch(currentModelClass());
+ }
+ /**
+ * 获取SqlStatement
+ *
+ * @param sqlMethod 方法
+ * @return String
+ */
+ default String sqlStatement(SqlMethod sqlMethod) {
+ return SqlHelper.table(currentModelClass()).getSqlStatement(sqlMethod.getMethod());
+ }
+
+ /**
+ *
+ * 获取当前class
+ *
+ */
+ default Class currentModelClass() {
+ return (Class) TypeUtil.getTypeArgument(this.getClass().getInterfaces()[0].getGenericInterfaces()[0]);
+ }
+
+}
diff --git a/common/src/main/java/com/keray/common/IBSEntity.java b/common/src/main/java/com/keray/common/IBSEntity.java
new file mode 100644
index 0000000..0c0569e
--- /dev/null
+++ b/common/src/main/java/com/keray/common/IBSEntity.java
@@ -0,0 +1,13 @@
+package com.keray.common;
+
+import java.io.Serializable;
+
+/**
+ * @author by keray
+ * date:2020/7/15 9:39 上午
+ */
+public interface IBSEntity, ID extends Serializable> extends IBEntity {
+ ID getId();
+
+ void setId(ID id);
+}
diff --git a/common/src/main/java/com/keray/common/IBSMapper.java b/common/src/main/java/com/keray/common/IBSMapper.java
new file mode 100644
index 0000000..e59fcdc
--- /dev/null
+++ b/common/src/main/java/com/keray/common/IBSMapper.java
@@ -0,0 +1,65 @@
+package com.keray.common;
+
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.apache.ibatis.annotations.Param;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * @author by keray
+ * date:2020/7/15 9:39 上午
+ */
+public interface IBSMapper, ID extends Serializable> extends IBMapper {
+
+ /**
+ * 插入一条记录
+ *
+ * @param entity 实体对象
+ * @return
+ */
+ @Override
+ int insert(BS entity);
+
+ /**
+ * 根据 ID 修改
+ *
+ * @param entity 实体对象
+ * @return
+ */
+ @Override
+ int updateById(@Param(Constants.ENTITY) BS entity);
+
+
+ @Override
+ BS selectById(Serializable id);
+
+ default boolean contains(String id) {
+ return selectCount(Wrappers.query().eq("id", id)) == 1;
+ }
+
+ /**
+ * 删除(根据ID 批量删除)
+ *
+ * @param id 主键ID列表(不能为 null 以及 empty)
+ */
+ @Override
+ default int deleteById(Serializable id) {
+ return this.delete(Wrappers.update().eq("id", id));
+ }
+
+ /**
+ * 删除(根据ID 批量删除)
+ *
+ * @param idList 主键ID列表(不能为 null 以及 empty)
+ */
+ @Override
+ default int deleteBatchIds(@Param(Constants.COLLECTION) Collection extends Serializable> idList) {
+ return this.delete(Wrappers.update().in("id", idList));
+ }
+
+ default Boolean canDelete(@Param("ids") Collection extends Serializable> ids) {
+ return true;
+ }
+}
diff --git a/common/src/main/java/com/keray/common/SysThreadPool.java b/common/src/main/java/com/keray/common/SysThreadPool.java
index 2627b2c..bf09ad7 100644
--- a/common/src/main/java/com/keray/common/SysThreadPool.java
+++ b/common/src/main/java/com/keray/common/SysThreadPool.java
@@ -8,7 +8,7 @@
* date:2019/9/16 11:49
*/
public class SysThreadPool {
- private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(100, 1000, 10,
+ private static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(100, 1000, 10,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(10000000),
r -> {
Thread t = new Thread(r);
diff --git a/common/src/main/java/com/keray/common/config/ApiLogServletInvocableHandlerMethodHandler.java b/common/src/main/java/com/keray/common/config/ApiLogServletInvocableHandlerMethodHandler.java
new file mode 100644
index 0000000..f6342d3
--- /dev/null
+++ b/common/src/main/java/com/keray/common/config/ApiLogServletInvocableHandlerMethodHandler.java
@@ -0,0 +1,117 @@
+package com.keray.common.config;
+
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.keray.common.IBaseEntity;
+import com.keray.common.Result;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.MethodParameter;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.method.HandlerMethod;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.function.Consumer;
+
+/**
+ * @author by keray
+ * date:2020/6/3 10:08 上午
+ */
+@Slf4j
+@Configuration
+@ConfigurationProperties(prefix = "api.log")
+public class ApiLogServletInvocableHandlerMethodHandler implements ServletInvocableHandlerMethodHandler {
+
+ @Getter
+ @Setter
+ private Boolean all = false;
+
+ @Override
+ public Integer order() {
+ return 0;
+ }
+
+ @Override
+ public Object work(HandlerMethod handlerMethod, Object[] args, NativeWebRequest request, ServletInvocableHandlerMethodCallback callback) throws Exception {
+ long start = System.nanoTime();
+ for (Object o : args) {
+ if (o instanceof IBaseEntity) {
+ ((IBaseEntity) o).clearBaseField();
+ }
+ }
+ Consumer