服务端rest接口调整,去掉无用的mapper.xml
This commit is contained in:
+1
-2
@@ -22,12 +22,11 @@
|
||||
package fun.asgc.neutrino.proxy.server.base.db;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
|
||||
import fun.asgc.neutrino.core.util.Assert;
|
||||
import fun.asgc.neutrino.core.util.CollectionUtil;
|
||||
import fun.asgc.neutrino.core.util.FileUtil;
|
||||
import fun.asgc.neutrino.core.util.StringUtil;
|
||||
import fun.asgc.neutrino.proxy.server.base.db.template.JdbcTemplate;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.config.DbConfig;
|
||||
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.rest.config;
|
||||
package fun.asgc.neutrino.proxy.server.base.db;
|
||||
|
||||
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
|
||||
import lombok.Data;
|
||||
+1
-2
@@ -5,8 +5,7 @@ import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
|
||||
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import fun.asgc.neutrino.proxy.server.base.db.template.JdbcTemplate;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.config.DbConfig;
|
||||
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
|
||||
import fun.asgc.neutrino.proxy.server.constant.DbTypeEnum;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
|
||||
+1
-1
@@ -28,11 +28,11 @@ import fun.asgc.neutrino.core.aop.Invocation;
|
||||
import fun.asgc.neutrino.core.aop.interceptor.Interceptor;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlParser;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.core.db.template.JdbcTemplate;
|
||||
import fun.asgc.neutrino.core.util.ArrayUtil;
|
||||
import fun.asgc.neutrino.core.util.Assert;
|
||||
import fun.asgc.neutrino.core.util.StringUtil;
|
||||
import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
import fun.asgc.neutrino.proxy.server.base.db.template.JdbcTemplate;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import fun.asgc.neutrino.core.db.dao.DBType;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 数据源持有者
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/28
|
||||
*/
|
||||
public class DataSourceHolder {
|
||||
/**
|
||||
* 数据源
|
||||
*/
|
||||
private DataSource dataSource;
|
||||
/**
|
||||
* 是否保持连接
|
||||
* 默认执行完SQL操作就归还连接
|
||||
* 在开启事务的情况下,事务操作完毕才能归还
|
||||
*/
|
||||
private ThreadLocal<Boolean> keepConnectionCache = new ThreadLocal<>();
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
private DBType dbType;
|
||||
|
||||
public DataSourceHolder(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public DataSourceHolder(DataSource dataSource, DBType dbType) {
|
||||
this.dataSource = dataSource;
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
return this.dataSource.getConnection();
|
||||
}
|
||||
|
||||
public void close(Connection conn) throws SQLException {
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void tryClose(Connection conn) throws SQLException {
|
||||
Boolean keepConnection = keepConnectionCache.get();
|
||||
if (null == keepConnection || !keepConnection) {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setKeepConnection(Boolean keepConnection) {
|
||||
this.keepConnectionCache.set(keepConnection);
|
||||
}
|
||||
|
||||
public DBType getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(DBType dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
}
|
||||
-281
@@ -1,281 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import fun.asgc.neutrino.core.cache.Cache;
|
||||
import fun.asgc.neutrino.core.cache.MemoryCache;
|
||||
import fun.asgc.neutrino.core.cache.MemoryCacheGroup;
|
||||
import fun.asgc.neutrino.core.db.annotation.Column;
|
||||
import fun.asgc.neutrino.core.db.annotation.NotColumn;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import fun.asgc.neutrino.core.util.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 数据库相关缓存
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public class DbCache {
|
||||
/**
|
||||
* 名称映射缓存组
|
||||
*/
|
||||
private static final MemoryCacheGroup<String, String> nameMappingCache = new MemoryCacheGroup<>();
|
||||
private static final String GROUP_COLUMN_NAME_TO = "GROUP_COLUMN_NAME_TO";
|
||||
private static final String GROUP_COLUMN_NAME_FROM = "GROUP_COLUMN_NAME_FROM";
|
||||
private static final String GROUP_TABLE_NAME_TO = "GROUP_TABLE_NAME_TO";
|
||||
private static final String GROUP_TABLE_NAME_FROM = "GROUP_TABLE_NAME_FROM";
|
||||
private static final Cache<Class<?>, Cache<Field, String>> fieldToColumnCache = new MemoryCache<>();
|
||||
private static final Object fieldToColumnCacheLock = new Object();
|
||||
private static final Cache<Class<?>,String> classTableNameCache = new MemoryCache<>();
|
||||
|
||||
/**
|
||||
* 转换为列名
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String toColumnName(String s) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !nameMappingCache.containsKey(GROUP_COLUMN_NAME_TO, s),
|
||||
GROUP_COLUMN_NAME_TO,
|
||||
() -> nameMappingCache.set(GROUP_COLUMN_NAME_TO, s, DefaultColumnNameConvert.getInstance().to(s)),
|
||||
() -> nameMappingCache.get(GROUP_COLUMN_NAME_TO, s)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字段名
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String fromColumnName(String s) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !nameMappingCache.containsKey(GROUP_COLUMN_NAME_FROM, s),
|
||||
GROUP_COLUMN_NAME_FROM,
|
||||
() -> nameMappingCache.set(GROUP_COLUMN_NAME_FROM, s, DefaultColumnNameConvert.getInstance().from(s)),
|
||||
() -> nameMappingCache.get(GROUP_COLUMN_NAME_FROM, s)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为表名
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String toTableName(String s) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !nameMappingCache.containsKey(GROUP_TABLE_NAME_TO, s),
|
||||
GROUP_TABLE_NAME_TO,
|
||||
() -> nameMappingCache.set(GROUP_TABLE_NAME_TO, s, DefaultTableNameConvert.getInstance().to(s)),
|
||||
() -> nameMappingCache.get(GROUP_TABLE_NAME_TO, s)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为表名
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static String toTableName(Class<?> clazz) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(() -> !classTableNameCache.containsKey(clazz),
|
||||
clazz,
|
||||
() -> {
|
||||
Table table = clazz.getAnnotation(Table.class);
|
||||
String tableName;
|
||||
if (null != table && StringUtil.notEmpty(table.value())) {
|
||||
tableName = table.value();
|
||||
} else {
|
||||
tableName = toTableName(TypeUtil.getSimpleName(clazz));
|
||||
}
|
||||
classTableNameCache.set(clazz, tableName);
|
||||
},
|
||||
() -> classTableNameCache.get(clazz)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为实体名
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String fromTableName(String s) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !nameMappingCache.containsKey(GROUP_TABLE_NAME_FROM, s),
|
||||
GROUP_TABLE_NAME_FROM,
|
||||
() -> nameMappingCache.set(GROUP_TABLE_NAME_FROM, s, DefaultTableNameConvert.getInstance().from(s)),
|
||||
() -> nameMappingCache.get(GROUP_TABLE_NAME_FROM, s)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类+列名获取字段
|
||||
* @param clazz
|
||||
* @param column
|
||||
* @return
|
||||
*/
|
||||
public static List<Field> getField(Class<?> clazz, String column) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !fieldToColumnCache.containsKey(clazz),
|
||||
fieldToColumnCacheLock,
|
||||
() -> initFieldCache(clazz),
|
||||
() -> {
|
||||
List<Field> list = Lists.newArrayList();
|
||||
Cache<Field, String> cache = fieldToColumnCache.get(clazz);
|
||||
if (null == cache || cache.isEmpty()) {
|
||||
return list;
|
||||
}
|
||||
for (Field field : cache.keySet()) {
|
||||
if (cache.get(field).equals(column)) {
|
||||
list.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类名获取列名列表
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static List<Field> getFieldList(Class<?> clazz) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !fieldToColumnCache.containsKey(clazz),
|
||||
fieldToColumnCacheLock,
|
||||
() -> initFieldCache(clazz),
|
||||
() -> {
|
||||
List<Field> list = Lists.newArrayList();
|
||||
Cache<Field, String> cache = fieldToColumnCache.get(clazz);
|
||||
if (null == cache || cache.isEmpty()) {
|
||||
return list;
|
||||
}
|
||||
list.addAll(cache.keySet());
|
||||
return list;
|
||||
}
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类获取字段缓存
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static Cache<Field, String> getFieldCache(Class<?> clazz) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !fieldToColumnCache.containsKey(clazz),
|
||||
clazz,
|
||||
() -> initFieldCache(clazz),
|
||||
() -> fieldToColumnCache.get(clazz)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getColumnNameByField(Field field) {
|
||||
try {
|
||||
return LockUtil.doubleCheckProcess(
|
||||
() -> !fieldToColumnCache.containsKey(field.getDeclaringClass()),
|
||||
fieldToColumnCacheLock,
|
||||
() -> initFieldCache(field.getDeclaringClass()),
|
||||
() -> {
|
||||
if (!fieldToColumnCache.containsKey(field.getDeclaringClass()) || !fieldToColumnCache.get(field.getDeclaringClass()).containsKey(field)) {
|
||||
return null;
|
||||
}
|
||||
return fieldToColumnCache.get(field.getDeclaringClass()).get(field);
|
||||
}
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化字段缓存
|
||||
* @param clazz
|
||||
*/
|
||||
private static void initFieldCache(Class<?> clazz) {
|
||||
Set<Field> fieldSet = ReflectUtil.getDeclaredFields(clazz);
|
||||
if (CollectionUtil.isEmpty(fieldSet)) {
|
||||
return;
|
||||
}
|
||||
Cache<Field, String> cache = new MemoryCache<>();
|
||||
fieldSet.forEach(field -> {
|
||||
if (field.isAnnotationPresent(NotColumn.class)) {
|
||||
return;
|
||||
}
|
||||
Column column = field.getAnnotation(Column.class);
|
||||
if (null != column && StringUtil.notEmpty(column.value())) {
|
||||
cache.set(field, column.value());
|
||||
} else {
|
||||
cache.set(field, toColumnName(field.getName()));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
fieldToColumnCache.set(clazz, cache);
|
||||
}
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import fun.asgc.neutrino.core.base.Convert;
|
||||
import fun.asgc.neutrino.core.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 默认的列名转换器转换器
|
||||
* 代码 -> DB
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public class DefaultColumnNameConvert implements Convert<String, String> {
|
||||
private static final DefaultColumnNameConvert instance = new DefaultColumnNameConvert();
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
private DefaultColumnNameConvert() {
|
||||
|
||||
}
|
||||
|
||||
public static DefaultColumnNameConvert getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String from(String target) {
|
||||
if (StringUtil.isEmpty(target)) {
|
||||
return "";
|
||||
}
|
||||
boolean flag = false;
|
||||
StringBuilder sb = new StringBuilder(target.length());
|
||||
for (char c : target.toCharArray()) {
|
||||
if (SEPARATOR == c) {
|
||||
flag = true;
|
||||
} else {
|
||||
if (flag) {
|
||||
sb.append(Character.toUpperCase(c));
|
||||
flag = false;
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String to(String source) {
|
||||
if (StringUtil.isEmpty(source)) {
|
||||
return "";
|
||||
}
|
||||
boolean flag = true;
|
||||
StringBuilder sb = new StringBuilder(source.length());
|
||||
for (char c : source.toCharArray()) {
|
||||
if (flag) {
|
||||
sb.append(Character.toLowerCase(c));
|
||||
flag = false;
|
||||
} else {
|
||||
if (Character.isUpperCase(c)) {
|
||||
sb.append(SEPARATOR);
|
||||
sb.append(Character.toLowerCase(c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import fun.asgc.neutrino.core.base.Convert;
|
||||
import fun.asgc.neutrino.core.util.StringUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public class DefaultTableNameConvert implements Convert<String, String> {
|
||||
private static final DefaultTableNameConvert instance = new DefaultTableNameConvert();
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
private DefaultTableNameConvert() {
|
||||
|
||||
}
|
||||
|
||||
public static DefaultTableNameConvert getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String from(String target) {
|
||||
if (StringUtil.isEmpty(target)) {
|
||||
return "";
|
||||
}
|
||||
boolean flag = true;
|
||||
StringBuilder sb = new StringBuilder(target.length());
|
||||
for (char c : target.toCharArray()) {
|
||||
if (SEPARATOR == c) {
|
||||
flag = true;
|
||||
} else {
|
||||
if (flag) {
|
||||
sb.append(Character.toUpperCase(c));
|
||||
flag = false;
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String to(String source) {
|
||||
if (StringUtil.isEmpty(source)) {
|
||||
return "";
|
||||
}
|
||||
boolean flag = true;
|
||||
StringBuilder sb = new StringBuilder(source.length());
|
||||
for (char c : source.toCharArray()) {
|
||||
if (flag) {
|
||||
sb.append(Character.toLowerCase(c));
|
||||
flag = false;
|
||||
} else {
|
||||
if (Character.isUpperCase(c)) {
|
||||
sb.append(SEPARATOR);
|
||||
sb.append(Character.toLowerCase(c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public interface JdbcCallback<T> {
|
||||
|
||||
/**
|
||||
* 执行
|
||||
* @return
|
||||
*/
|
||||
T execute() throws SQLException;
|
||||
|
||||
}
|
||||
-293
@@ -1,293 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.util.CollectionUtil;
|
||||
import fun.asgc.neutrino.core.util.ReflectUtil;
|
||||
import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public class JdbcOperations {
|
||||
private static final JdbcOperations instance = new JdbcOperations();
|
||||
|
||||
private static final Map<Class<?>, Field> generateIdFieldMap = new ConcurrentHashMap<>();
|
||||
|
||||
private JdbcOperations() {
|
||||
|
||||
}
|
||||
|
||||
public static JdbcOperations getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用执行方法
|
||||
* @param callback
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T> T execute(JdbcCallback<T> callback) throws SQLException {
|
||||
return callback.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行更新操作
|
||||
* @param conn
|
||||
* @param sql
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public int executeUpdate(final Connection conn , final String sql, final Object[] params) throws SQLException {
|
||||
return this.execute(new PreparedStatementJdbcCallback<Integer>(){
|
||||
@Override
|
||||
public Integer execute(PreparedStatement ps) throws SQLException {
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
@Override
|
||||
public Object[] getParams() {
|
||||
return params;
|
||||
}
|
||||
@Override
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
@Override
|
||||
public Connection getConnection(){
|
||||
return conn;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行更新操作
|
||||
* 临时兼容返设主键问题
|
||||
* @param conn
|
||||
* @param sql
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public int executeUpdateByModel(final Connection conn , final String sql, final Object model, final Object[] params) throws SQLException {
|
||||
return this.execute(new PreparedStatementJdbcCallback<Integer>(){
|
||||
@Override
|
||||
public Integer execute(PreparedStatement ps) throws SQLException {
|
||||
Integer res = ps.executeUpdate();
|
||||
if (null != model) {
|
||||
ResultSet resultSet = ps.getGeneratedKeys();
|
||||
if (resultSet.next()) {
|
||||
Field field = getGenerateIdField(model.getClass());
|
||||
if (null != field) {
|
||||
ReflectUtil.setFieldValue(field, model, resultSet.getInt(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@Override
|
||||
public Object[] getParams() {
|
||||
return params;
|
||||
}
|
||||
@Override
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
@Override
|
||||
public Connection getConnection(){
|
||||
return conn;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行单条查询操作
|
||||
* @param conn
|
||||
* @param clazz
|
||||
* @param sql
|
||||
* @param params
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T> T executeQuery(final Connection conn,final Class<T> clazz,final String sql,final Object[] params) throws SQLException {
|
||||
return this.execute(new PreparedStatementJdbcCallback<T>() {
|
||||
|
||||
@Override
|
||||
public T execute(PreparedStatement ps) {
|
||||
T obj = null;
|
||||
|
||||
try{
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
if(resultSet.next()){
|
||||
if(TypeUtil.isNormalBasicType(clazz)){
|
||||
Object value = resultSet.getObject(1);
|
||||
obj = TypeUtil.conversion(value, clazz);
|
||||
}else if(TypeUtil.isMap(clazz)){
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
obj = (T)map;
|
||||
|
||||
ResultSetMetaData rsmd = resultSet.getMetaData();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
for(int i = 1;i <= columnCount;i++){
|
||||
String name = rsmd.getColumnName(i);
|
||||
Object value = resultSet.getObject(i);
|
||||
map.put(DbCache.fromColumnName(name), value);
|
||||
}
|
||||
}else{
|
||||
obj = clazz.newInstance();
|
||||
ResultSetMetaData rsmd = resultSet.getMetaData();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
for(int i = 1;i <= columnCount;i++){
|
||||
String name = rsmd.getColumnName(i);
|
||||
Object value = resultSet.getObject(i);
|
||||
List<Field> fieldList = DbCache.getField(clazz, name);
|
||||
ReflectUtil.setFieldValue(fieldList, obj, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return conn;
|
||||
}
|
||||
@Override
|
||||
public Object[] getParams() {
|
||||
return params;
|
||||
}
|
||||
@Override
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行多条查询操作
|
||||
* @param conn
|
||||
* @param clazz
|
||||
* @param sql
|
||||
* @param params
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T> List<T> executeQueryForList(final Connection conn, final Class<T> clazz, final String sql, final Object[] params) throws SQLException {
|
||||
return this.execute(new PreparedStatementJdbcCallback<List<T>>() {
|
||||
@Override
|
||||
public List<T> execute(PreparedStatement ps) {
|
||||
List<T> res = new ArrayList<T>();
|
||||
try{
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
ResultSetMetaData rsmd = resultSet.getMetaData();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
|
||||
while(resultSet.next()){
|
||||
T obj = null;
|
||||
|
||||
if(TypeUtil.isNormalBasicType(clazz)){
|
||||
Object value = resultSet.getObject(1);
|
||||
obj = TypeUtil.conversion(value, clazz);
|
||||
}else if(TypeUtil.isMap(clazz)){
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
obj = (T)map;
|
||||
|
||||
for(int i = 1;i <= columnCount;i++){
|
||||
String name = rsmd.getColumnName(i);
|
||||
Object value = resultSet.getObject(i);
|
||||
map.put(DbCache.fromColumnName(name), value);
|
||||
}
|
||||
}else{
|
||||
obj = clazz.newInstance();
|
||||
|
||||
for(int i = 1;i <= columnCount;i++){
|
||||
String name = rsmd.getColumnName(i);
|
||||
Object value = resultSet.getObject(i);
|
||||
List<Field> fieldList = DbCache.getField(clazz, name);
|
||||
ReflectUtil.setFieldValue(fieldList, obj, value);
|
||||
}
|
||||
}
|
||||
|
||||
res.add(obj);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getParams() {
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSql() {
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自动生成ID字段
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
private static Field getGenerateIdField(Class<?> clazz) {
|
||||
if (null == clazz) {
|
||||
return null;
|
||||
}
|
||||
if (generateIdFieldMap.containsKey(clazz)) {
|
||||
return generateIdFieldMap.get(clazz);
|
||||
}
|
||||
Set<Field> fields = ReflectUtil.getDeclaredFields(clazz);
|
||||
if (CollectionUtil.isEmpty(fields)) {
|
||||
return null;
|
||||
}
|
||||
Field field = fields.stream().filter(f -> f.isAnnotationPresent(Id.class)).findFirst().orElse(null);
|
||||
if (null != field) {
|
||||
return field;
|
||||
}
|
||||
field = fields.stream().filter(f -> f.getName().equals("id")).findFirst().orElse(null);
|
||||
return field;
|
||||
}
|
||||
}
|
||||
-452
@@ -1,452 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public class JdbcTemplate {
|
||||
/**
|
||||
* 数据源持有者
|
||||
*/
|
||||
private DataSourceHolder dataSourceHolder;
|
||||
/**
|
||||
* jdbc操作
|
||||
*/
|
||||
private JdbcOperations jdbcOperations;
|
||||
|
||||
public JdbcTemplate(DataSource dataSource) {
|
||||
this(new DataSourceHolder(dataSource));
|
||||
}
|
||||
|
||||
public JdbcTemplate(DataSourceHolder dataSourceHolder) {
|
||||
this.dataSourceHolder = dataSourceHolder;
|
||||
this.jdbcOperations = JdbcOperations.getInstance();
|
||||
}
|
||||
|
||||
public int update(String sql, Object ...params) throws SQLException {
|
||||
int res = -1;
|
||||
Connection conn = null;
|
||||
|
||||
try {
|
||||
conn = dataSourceHolder.getConnection();
|
||||
res = jdbcOperations.executeUpdate(conn,sql, params);
|
||||
} finally {
|
||||
try {
|
||||
dataSourceHolder.tryClose(conn);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 临时用来兼容insert之后需要返设主键的问题
|
||||
* @param sql
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int updateByModel(String sql, Object model, Object ...params) throws SQLException {
|
||||
int res = -1;
|
||||
Connection conn = null;
|
||||
|
||||
try {
|
||||
conn = dataSourceHolder.getConnection();
|
||||
res = jdbcOperations.executeUpdateByModel(conn,sql, model, params);
|
||||
} finally {
|
||||
try {
|
||||
dataSourceHolder.tryClose(conn);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public int update(SqlAndParams sqlAndParams) throws SQLException {
|
||||
return update(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public int updateByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
return update(new SqlAndParams(sql, params));
|
||||
}
|
||||
|
||||
public int updateByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return updateByModel(sqlAndParams.getSql(), model, sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public <T> T query(Class<T> clazz, String sql, Object ...params) throws SQLException {
|
||||
T res = null;
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = dataSourceHolder.getConnection();
|
||||
res = jdbcOperations.executeQuery(conn, clazz,sql, params);
|
||||
} finally {
|
||||
try {
|
||||
dataSourceHolder.tryClose(conn);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public <T> T query(Class<T> clazz, SqlAndParams sqlAndParams) throws SQLException {
|
||||
return query(clazz, sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public <T> T queryByMap(Class<T> clazz, String sql, Map<String,Object> params) throws SQLException {
|
||||
return query(clazz, new SqlAndParams(sql, params));
|
||||
}
|
||||
|
||||
public <T> T queryByModel(Class<T> clazz, String sql, Object model) throws SQLException {
|
||||
return query(clazz, new SqlAndParams(sql, model));
|
||||
}
|
||||
|
||||
public byte queryForByteByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForByte(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public byte queryForByteByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForByte(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public byte queryForByte(String sql, Object ...params) throws SQLException {
|
||||
return query(byte.class, sql, params);
|
||||
}
|
||||
|
||||
public short queryForShortByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForShort(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public short queryForShortByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForShort(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public short queryForShort(String sql, Object ...params) throws SQLException {
|
||||
return query(short.class, sql, params);
|
||||
}
|
||||
|
||||
public int queryForIntByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForInt(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public int queryForIntByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForInt(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public int queryForInt(String sql, Object ...params) throws SQLException {
|
||||
return query(int.class, sql, params);
|
||||
}
|
||||
|
||||
public Long queryForLongByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForLong(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public Long queryForLongByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForLong(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public Long queryForLong(String sql,Object ...params) throws SQLException {
|
||||
return query(long.class, sql, params);
|
||||
}
|
||||
|
||||
public float queryForFloatByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForFloat(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public float queryForFloatByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForFloat(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public float queryForFloat(String sql,Object ...params) throws SQLException {
|
||||
return query(float.class, sql, params);
|
||||
}
|
||||
|
||||
public double queryForDoubleByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForDouble(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public double queryForDoubleByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForDouble(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public double queryForDouble(String sql, Object ...params) throws SQLException {
|
||||
return query(double.class, sql, params);
|
||||
}
|
||||
|
||||
public char queryForCharByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForChar(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public char queryForCharByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForChar(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public char queryForChar(String sql, Object ...params) throws SQLException {
|
||||
return query(char.class, sql, params);
|
||||
}
|
||||
|
||||
public boolean queryForBooleanByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForBoolean(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public boolean queryForBooleanByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForBoolean(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public boolean queryForBoolean(String sql, Object ...params) throws SQLException {
|
||||
return query(boolean.class, sql, params);
|
||||
}
|
||||
|
||||
public String queryForStringByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForString(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public String queryForStringByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForString(sql, sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public String queryForString(String sql, Object ...params) throws SQLException {
|
||||
return query(String.class, sql, params);
|
||||
}
|
||||
|
||||
public Map<String,Object> queryForMapByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForMap(sql, sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public Map<String,Object> queryForMapByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForMap(sql, sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public Map<String,Object> queryForMap(String sql, Object ...params) throws SQLException {
|
||||
return (Map<String,Object>)query(HashMap.class, sql, params);
|
||||
}
|
||||
|
||||
public <T> List<T> queryForList(Class<T> clazz, String sql, Object ...params) throws SQLException {
|
||||
List<T> res = null;
|
||||
Connection conn = null;
|
||||
|
||||
try {
|
||||
conn = dataSourceHolder.getConnection();
|
||||
res = jdbcOperations.executeQueryForList(conn, clazz, sql, params);
|
||||
} finally {
|
||||
try {
|
||||
dataSourceHolder.tryClose(conn);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public <T> List<T> queryForList(Class<T> clazz, SqlAndParams sqlAndParams) throws SQLException {
|
||||
return queryForList(clazz, sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public <T> List<T> queryForListByMap(Class<T> clazz, String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForList(clazz, sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public <T> List<T> queryForListByModel(Class<T> clazz, String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForList(clazz, sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Byte> queryForListByteByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListByte(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Byte> queryForListByteByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListByte(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Byte> queryForListByte(String sql,Object ...params) throws SQLException {
|
||||
return queryForList(byte.class, sql,params);
|
||||
}
|
||||
|
||||
public List<Short> queryForListShortByMap(String sql, Map<String, Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListShort(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Short> queryForListShortByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListShort(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Short> queryForListShort(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(short.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Integer> queryForListIntByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListInt(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Integer> queryForListIntByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListInt(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Integer> queryForListInt(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(int.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Long> queryForListLongByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListLong(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Long> queryForListLongByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListLong(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Long> queryForListLong(String sql,Object ...params) throws SQLException {
|
||||
return queryForList(long.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Float> queryForListFloatByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListFloat(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Float> queryForListFloatByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListFloat(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Float> queryForListFloat(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(float.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Double> queryForListDoubleByMap(String sql ,Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListDouble(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Double> queryForListDoubleByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListDouble(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Double> queryForListDouble(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(double.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Character> queryForListCharByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListChar(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Character> queryForListCharByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListChar(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Character> queryForListChar(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(char.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Boolean> queryForListBooleanByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListBoolean(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Boolean> queryForListBooleanByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListBoolean(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Boolean> queryForListBoolean(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(boolean.class, sql, params);
|
||||
}
|
||||
|
||||
public List<String> queryForListStringByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListString(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<String> queryForListStringByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListString(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<String> queryForListString(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(String.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Map> queryForListMap(String sql, Object ...params) throws SQLException {
|
||||
return queryForList(Map.class, sql, params);
|
||||
}
|
||||
|
||||
public List<Map> queryForListMapByMap(String sql, Map<String,Object> params) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, params);
|
||||
return queryForListMap(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
public List<Map> queryForListMapByModel(String sql, Object model) throws SQLException {
|
||||
SqlAndParams sqlAndParams = new SqlAndParams(sql, model);
|
||||
return queryForListMap(sqlAndParams.getSql(), sqlAndParams.getParamArray());
|
||||
}
|
||||
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* <p>
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
* <p>
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import fun.asgc.neutrino.core.util.ArrayUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class PreparedStatementJdbcCallback<T> implements JdbcCallback<T> {
|
||||
|
||||
@Override
|
||||
public T execute() throws SQLException {
|
||||
PreparedStatement pstm = null;
|
||||
Object[] params = this.getParams();
|
||||
Connection conn = getConnection();
|
||||
|
||||
T res = null;
|
||||
|
||||
log.debug("sql:" + this.getSql());
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (ArrayUtil.notEmpty(params)) {
|
||||
for (Object o : params) {
|
||||
sb.append(o).append(",");
|
||||
}
|
||||
|
||||
if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ',') {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
}
|
||||
log.debug("params:" + sb.toString());
|
||||
pstm = conn.prepareStatement(this.getSql(), Statement.RETURN_GENERATED_KEYS);
|
||||
if (ArrayUtil.notEmpty(params)) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
pstm.setObject(i + 1, params[i]);
|
||||
}
|
||||
}
|
||||
res = this.execute(pstm);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数
|
||||
* @return
|
||||
*/
|
||||
abstract Object[] getParams();
|
||||
|
||||
/**
|
||||
* 获取sql语句
|
||||
* @return
|
||||
*/
|
||||
abstract String getSql();
|
||||
|
||||
/**
|
||||
* 执行
|
||||
* @param ps
|
||||
* @return
|
||||
*/
|
||||
abstract T execute(PreparedStatement ps) throws SQLException;
|
||||
|
||||
/**
|
||||
* 获取数据库连接
|
||||
* @return
|
||||
*/
|
||||
abstract Connection getConnection();
|
||||
}
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.db.template;
|
||||
|
||||
import fun.asgc.neutrino.core.base.Orderly;
|
||||
import fun.asgc.neutrino.core.util.ReflectUtil;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* sql语句+sql参数的封装,用于支持以下3种用法
|
||||
* 1、jdbcTemplate.query(User.class,"select * from user where id = ?",1);
|
||||
* 2、dbcTemplate.query(User.class,"select * from user where id = :id", new HashMap<String,Object>(){
|
||||
* {
|
||||
* this.put("id","1");
|
||||
* }
|
||||
* });
|
||||
* 3、dbcTemplate.query(User.class,"select * from user where id = :id", new User().setId("1"));
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/27
|
||||
*/
|
||||
public class SqlAndParams {
|
||||
private String sql;
|
||||
private Object[] paramArray;
|
||||
private Map<String,Object> paramMap;
|
||||
private Object paramObject;
|
||||
|
||||
public SqlAndParams(String sql, Object[] paramArray) {
|
||||
this.sql = sql;
|
||||
this.paramArray = paramArray;
|
||||
}
|
||||
|
||||
public SqlAndParams(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public SqlAndParams(String sql,Map<String,Object> paramMap) {
|
||||
this.sql = sql;
|
||||
this.paramMap = paramMap;
|
||||
this.initParams();
|
||||
}
|
||||
|
||||
public SqlAndParams(String sql,Object paramObject) {
|
||||
this.sql = sql;
|
||||
this.paramObject = paramObject;
|
||||
|
||||
this.initParamMap();
|
||||
this.initParams();
|
||||
}
|
||||
|
||||
private void initParamMap(){
|
||||
if (null == paramObject) {
|
||||
return;
|
||||
}
|
||||
if (null == paramMap) {
|
||||
paramMap = new HashMap<>();
|
||||
}
|
||||
for(Field field : ReflectUtil.getDeclaredFields(paramObject.getClass())){
|
||||
paramMap.put(field.getName(), ReflectUtil.getFieldValue(field, paramObject));
|
||||
}
|
||||
}
|
||||
|
||||
private void initParams() {
|
||||
if (null == paramMap) {
|
||||
paramMap = new HashMap<>();
|
||||
}
|
||||
String originSql = sql;
|
||||
List<Orderly> orderlyList = new ArrayList<>();
|
||||
for(String key : paramMap.keySet()){
|
||||
int index = originSql.indexOf(":" + key);
|
||||
if(-1 != index){
|
||||
List<Orderly> currentList = new ArrayList<>();
|
||||
|
||||
// 解决数组、集合参数问题
|
||||
int count = 1;
|
||||
Object tmp = paramMap.get(key);
|
||||
if (null != tmp) {
|
||||
if (tmp.getClass().isArray()) {
|
||||
count = ((Object[])tmp).length;
|
||||
currentList.addAll(Stream.of((Object[])tmp).map(e -> new Orderly(e, index)).collect(Collectors.toList()));
|
||||
} else if (Collection.class.isAssignableFrom(tmp.getClass())) {
|
||||
count = ((Collection)tmp).size();
|
||||
Object[] arr = ((Collection)tmp).toArray();
|
||||
paramMap.put(key, arr);
|
||||
currentList.addAll((List)((Collection)tmp).stream().map(e -> new Orderly(e, index)).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
List<String> s = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
s.add("?");
|
||||
}
|
||||
sql = sql.replaceFirst(":" + key, s.stream().collect(Collectors.joining(",")));
|
||||
|
||||
if (currentList.isEmpty()) {
|
||||
currentList.add(new Orderly(paramMap.get(key), index));
|
||||
}
|
||||
|
||||
orderlyList.addAll(currentList);
|
||||
// orderlyList.add(new Orderly(paramMap.get(key), index));
|
||||
}
|
||||
}
|
||||
|
||||
this.paramArray = orderlyList.stream().sorted().map(Orderly::getData).collect(Collectors.toList()).toArray();
|
||||
}
|
||||
|
||||
public Object[] getParamArray(){
|
||||
return paramArray;
|
||||
}
|
||||
|
||||
public String getSql(){
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SqlAndParams{" +
|
||||
"sql='" + sql + '\'' +
|
||||
", paramArray=" + Arrays.toString(paramArray) +
|
||||
", paramMap=" + paramMap +
|
||||
", paramObject=" + paramObject +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+2
-7
@@ -19,9 +19,8 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.rest.config;
|
||||
package fun.asgc.neutrino.proxy.server.base.quartz;
|
||||
|
||||
import fun.asgc.neutrino.proxy.server.base.quartz.JobExecutor;
|
||||
import fun.asgc.neutrino.proxy.server.service.JobInfoService;
|
||||
import fun.asgc.neutrino.proxy.server.service.JobLogService;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
@@ -37,13 +36,9 @@ import org.noear.solon.core.event.EventBus;
|
||||
*/
|
||||
@Configuration
|
||||
public class JobConfig {
|
||||
@Inject
|
||||
private JobLogService jobLogService;
|
||||
@Inject
|
||||
private JobInfoService jobInfoService;
|
||||
|
||||
@Bean
|
||||
public JobExecutor jobExecutor() {
|
||||
public JobExecutor jobExecutor(@Inject JobLogService jobLogService, @Inject JobInfoService jobInfoService) {
|
||||
JobExecutor executor = new JobExecutor();
|
||||
executor.setJobSource(jobInfoService);
|
||||
executor.setJobCallback(jobLogService);
|
||||
+2
@@ -35,4 +35,6 @@ import java.lang.annotation.Target;
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface Authorization {
|
||||
boolean login() default true;
|
||||
|
||||
boolean onlyAdmin() default false;
|
||||
}
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.rest.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 暂不做复杂权限控制,仅用该注解标注,部分接口禁止游客身份调用
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/14
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface OnlyAdmin {
|
||||
|
||||
}
|
||||
+2
-3
@@ -2,7 +2,6 @@ package fun.asgc.neutrino.proxy.server.base.rest.interceptor;
|
||||
|
||||
import fun.asgc.neutrino.core.util.StringUtil;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.*;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
|
||||
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
@@ -35,7 +34,7 @@ public class BaseAuthInterceptor implements RouterInterceptor {
|
||||
|
||||
SystemContext systemContext = new SystemContext();
|
||||
SystemContextHolder.set(systemContext);
|
||||
systemContext.setIp(ctx.ip());
|
||||
systemContext.setIp(ctx.realIp());
|
||||
|
||||
Authorization authorization = targetMethod.getAnnotation(Authorization.class);
|
||||
if (null == authorization || authorization.login()) {
|
||||
@@ -50,7 +49,7 @@ public class BaseAuthInterceptor implements RouterInterceptor {
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(userDO.getEnable())) {
|
||||
throw ServiceException.create(ExceptionConstant.USER_DISABLE);
|
||||
}
|
||||
if (targetMethod.isAnnotationPresent(OnlyAdmin.class) && !userDO.getLoginName().equals("admin")) {
|
||||
if (null != authorization && authorization.onlyAdmin() && !userDO.getLoginName().equals("admin")) {
|
||||
throw ServiceException.create(ExceptionConstant.NO_PERMISSION_VISIT);
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -3,6 +3,7 @@ package fun.asgc.neutrino.proxy.server.base.rest.interceptor;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.ResponseBody;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.ServiceException;
|
||||
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.core.handle.Context;
|
||||
@@ -13,6 +14,7 @@ import org.noear.solon.core.handle.FilterChain;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/9
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class GlobalExceptionFilter implements Filter {
|
||||
|
||||
@@ -21,6 +23,7 @@ public class GlobalExceptionFilter implements Filter {
|
||||
try {
|
||||
chain.doFilter(ctx);
|
||||
} catch (Throwable e) {
|
||||
log.error("全局异常", e);
|
||||
if (e instanceof ServiceException) {
|
||||
ServiceException serviceException = (ServiceException)e;
|
||||
ctx.render(new ResponseBody<>()
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.controller;
|
||||
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestBody;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.Authorization;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LoginReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.LoginRes;
|
||||
@@ -50,7 +49,7 @@ public class IndexController {
|
||||
@Authorization(login = false)
|
||||
@Post
|
||||
@Mapping("/login")
|
||||
public LoginRes login(@RequestBody LoginReq req) {
|
||||
public LoginRes login(LoginReq req) {
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginName(), "loginName");
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword");
|
||||
|
||||
|
||||
+8
-9
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.controller;
|
||||
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestBody;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.Authorization;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoExecuteReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoUpdateEnableStatusReq;
|
||||
@@ -66,20 +65,20 @@ public class JobInfoController {
|
||||
return jobInfoService.findList();
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
public JobInfoUpdateEnableStatusRes updateEnableStatus(@RequestBody JobInfoUpdateEnableStatusReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public JobInfoUpdateEnableStatusRes updateEnableStatus(JobInfoUpdateEnableStatusReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
return jobInfoService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("execute")
|
||||
public JobInfoExecuteRes execute(@RequestBody JobInfoExecuteReq req) {
|
||||
@Mapping("/execute")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public JobInfoExecuteRes execute(JobInfoExecuteReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
@@ -87,8 +86,8 @@ public class JobInfoController {
|
||||
}
|
||||
|
||||
@Post
|
||||
@Mapping("update")
|
||||
public JobInfoUpdateRes update(@RequestBody JobInfoUpdateReq req) {
|
||||
@Mapping("/update")
|
||||
public JobInfoUpdateRes update(JobInfoUpdateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
|
||||
return jobInfoService.update(req);
|
||||
|
||||
+19
-19
@@ -23,11 +23,8 @@ package fun.asgc.neutrino.proxy.server.controller;
|
||||
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseCreateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateEnableStatusReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateReq;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.Authorization;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.*;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.service.LicenseService;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
@@ -59,9 +56,9 @@ public class LicenseController {
|
||||
return licenseService.list(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/create")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public LicenseCreateRes create(LicenseCreateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotEmpty(req.getName(), "name");
|
||||
@@ -70,9 +67,9 @@ public class LicenseController {
|
||||
return licenseService.create(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public LicenseUpdateRes update(LicenseUpdateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
@@ -83,15 +80,16 @@ public class LicenseController {
|
||||
|
||||
@Post
|
||||
@Mapping("/detail")
|
||||
public LicenseDetailRes detail(Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
public LicenseDetailRes detail(LicenseDetailReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
return licenseService.detail(id);
|
||||
return licenseService.detail(req.getId());
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(LicenseUpdateEnableStatusReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
@@ -100,22 +98,24 @@ public class LicenseController {
|
||||
return licenseService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/delete")
|
||||
public void delete(Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
@Authorization(onlyAdmin = true)
|
||||
public void delete(LicenseDeleteReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
licenseService.delete(id);
|
||||
licenseService.delete(req.getId());
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/reset")
|
||||
public void reset(Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
@Authorization(onlyAdmin = true)
|
||||
public void reset(LicenseResetReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
licenseService.reset(id);
|
||||
licenseService.reset(req.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-15
@@ -22,14 +22,9 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller;
|
||||
|
||||
import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestBody;
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestParam;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingCreateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingUpdateEnableStatusReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingUpdateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.*;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.service.PortMappingService;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
@@ -57,7 +52,7 @@ public class PortMappingController {
|
||||
|
||||
@Post
|
||||
@Mapping("/create")
|
||||
public PortMappingCreateRes create(@RequestBody PortMappingCreateReq req) {
|
||||
public PortMappingCreateRes create(PortMappingCreateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getLicenseId(), "licenseId");
|
||||
ParamCheckUtil.checkNotNull(req.getServerPort(), "serverPort");
|
||||
@@ -69,7 +64,7 @@ public class PortMappingController {
|
||||
|
||||
@Post
|
||||
@Mapping("/update")
|
||||
public PortMappingUpdateRes update(@RequestBody PortMappingUpdateReq req) {
|
||||
public PortMappingUpdateRes update(PortMappingUpdateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
|
||||
return portMappingService.update(req);
|
||||
@@ -77,15 +72,16 @@ public class PortMappingController {
|
||||
|
||||
@Get
|
||||
@Mapping("/detail")
|
||||
public PortMappingDetailRes detail(@RequestParam("id") Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
public PortMappingDetailRes detail(PortMappingDetailReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
return portMappingService.detail(id);
|
||||
return portMappingService.detail(req.getId());
|
||||
}
|
||||
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
public PortMappingUpdateEnableStatusRes updateEnableStatus(@RequestBody PortMappingUpdateEnableStatusReq req) {
|
||||
public PortMappingUpdateEnableStatusRes updateEnableStatus(PortMappingUpdateEnableStatusReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
@@ -95,9 +91,10 @@ public class PortMappingController {
|
||||
|
||||
@Post
|
||||
@Mapping("/delete")
|
||||
public void delete(@RequestParam("id") Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
public void delete(PortMappingDeleteReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
portMappingService.delete(id);
|
||||
portMappingService.delete(req.getId());
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -21,12 +21,11 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.controller;
|
||||
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestBody;
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestParam;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.Authorization;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolCreateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolDeleteReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolUpdateEnableStatusReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolCreateRes;
|
||||
@@ -63,20 +62,20 @@ public class PortPoolController {
|
||||
return portPoolService.list(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/create")
|
||||
public PortPoolCreateRes create(@RequestBody PortPoolCreateReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public PortPoolCreateRes create(PortPoolCreateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getPort(), "port");
|
||||
|
||||
return portPoolService.create(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
public PortPoolUpdateEnableStatusRes updateEnableStatus(@RequestBody PortPoolUpdateEnableStatusReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public PortPoolUpdateEnableStatusRes updateEnableStatus(PortPoolUpdateEnableStatusReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
@@ -84,12 +83,13 @@ public class PortPoolController {
|
||||
return portPoolService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/delete")
|
||||
public void delete(@RequestParam("id") Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
@Authorization(onlyAdmin = true)
|
||||
public void delete(PortPoolDeleteReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
portPoolService.delete(id);
|
||||
portPoolService.delete(req.getId());
|
||||
}
|
||||
}
|
||||
|
||||
+15
-16
@@ -21,12 +21,10 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.controller;
|
||||
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestBody;
|
||||
import fun.asgc.neutrino.core.web.annotation.RequestParam;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.Authorization;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
|
||||
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.*;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
@@ -73,10 +71,10 @@ public class UserController {
|
||||
return userService.info(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
public UserUpdateEnableStatusRes updateEnableStatus(@RequestBody UserUpdateEnableStatusReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public UserUpdateEnableStatusRes updateEnableStatus(UserUpdateEnableStatusReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
@@ -84,10 +82,10 @@ public class UserController {
|
||||
return userService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/create")
|
||||
public UserCreateRes create(@RequestBody UserCreateReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public UserCreateRes create(UserCreateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotEmpty(req.getName(), "name");
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginName(), "loginName");
|
||||
@@ -95,10 +93,10 @@ public class UserController {
|
||||
return userService.create(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update")
|
||||
public UserUpdateRes update(@RequestBody UserUpdateReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public UserUpdateRes update(UserUpdateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotEmpty(req.getName(), "name");
|
||||
@@ -107,10 +105,10 @@ public class UserController {
|
||||
return userService.update(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/update/password")
|
||||
public UserUpdatePasswordRes updatePassword(@RequestBody UserUpdatePasswordReq req) {
|
||||
@Authorization(onlyAdmin = true)
|
||||
public UserUpdatePasswordRes updatePassword(UserUpdatePasswordReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword");
|
||||
@@ -121,7 +119,7 @@ public class UserController {
|
||||
|
||||
@Post
|
||||
@Mapping("/current-user/update/password")
|
||||
public UserUpdatePasswordRes currentUserUpdatePassword(@RequestBody UserUpdatePasswordReq req) {
|
||||
public UserUpdatePasswordRes currentUserUpdatePassword(UserUpdatePasswordReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotEmpty(req.getOldLoginPassword(), "oldLoginPassword");
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword");
|
||||
@@ -135,12 +133,13 @@ public class UserController {
|
||||
return userService.updatePassword(req);
|
||||
}
|
||||
|
||||
@OnlyAdmin
|
||||
@Post
|
||||
@Mapping("/delete")
|
||||
public void delete(@RequestParam("id") Integer id) {
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
@Authorization(onlyAdmin = true)
|
||||
public void delete(UserDeleteReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
userService.delete(id);
|
||||
userService.delete(req.getId());
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* license删除请求
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/11
|
||||
*/
|
||||
@Data
|
||||
public class LicenseDeleteReq {
|
||||
private Integer id;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/11
|
||||
*/
|
||||
@Data
|
||||
public class LicenseDetailReq {
|
||||
private Integer id;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/11
|
||||
*/
|
||||
@Data
|
||||
public class LicenseResetReq {
|
||||
private Integer id;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/11
|
||||
*/
|
||||
@Data
|
||||
public class PortMappingDeleteReq {
|
||||
private Integer id;
|
||||
}
|
||||
+1
-1
@@ -30,5 +30,5 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class PortMappingDetailReq {
|
||||
|
||||
private Integer id;
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/11
|
||||
*/
|
||||
@Data
|
||||
public class PortPoolDeleteReq {
|
||||
private Integer id;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package fun.asgc.neutrino.proxy.server.controller.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/3/11
|
||||
*/
|
||||
@Data
|
||||
public class UserDeleteReq {
|
||||
private Integer id;
|
||||
}
|
||||
+8
-11
@@ -1,24 +1,21 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.ClientConnectRecordListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.ClientConnectRecordListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/11/23
|
||||
*/
|
||||
@Mapper
|
||||
public interface ClientConnectRecordMapper extends BaseMapper<ClientConnectRecordDO> {
|
||||
|
||||
void add(ClientConnectRecordDO clientConnectRecordDO);
|
||||
|
||||
@ResultType(ClientConnectRecordListRes.class)
|
||||
@Select("select * from client_connect_record order by id desc")
|
||||
void page(PageInfo pageInfo, ClientConnectRecordListReq req);
|
||||
default void clean(Date date) {
|
||||
this.delete(new LambdaQueryWrapper<ClientConnectRecordDO>()
|
||||
.lt(ClientConnectRecordDO::getCreateTime, date)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public interface DataCleanMapper {
|
||||
|
||||
@Delete("delete from `job_log` where create_time < ?")
|
||||
void cleanJobLog(Date date);
|
||||
|
||||
@Delete("delete from `user_login_record` where create_time < ?")
|
||||
void cleanUserLoginRecord(Date date);
|
||||
|
||||
@Delete("delete from `client_connect_record` where create_time < ?")
|
||||
void cleanClientConnectRecord(Date date);
|
||||
|
||||
@Delete("delete from `flow_report_minute` where create_time < ?")
|
||||
void cleanFlowMinuteReport(Date date);
|
||||
|
||||
@Delete("delete from `flow_report_hour` where create_time < ?")
|
||||
void cleanFlowHourReport(Date date);
|
||||
|
||||
@Delete("delete from `flow_report_day` where create_time < ?")
|
||||
void cleanFlowDayReport(Date date);
|
||||
|
||||
}
|
||||
+17
-15
@@ -21,12 +21,8 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportDayDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -35,16 +31,22 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface FlowReportDayMapper extends BaseMapper<FlowReportDayDO> {
|
||||
@Select("select * from flow_report_day where license_id = :licenseId and date_str = :dateStr")
|
||||
FlowReportDayDO findOne(@Param("licenseId") Integer licenseId, @Param("dateStr") String dateStr);
|
||||
default void clean(Date date) {
|
||||
this.delete(new LambdaQueryWrapper<FlowReportDayDO>()
|
||||
.lt(FlowReportDayDO::getCreateTime, date)
|
||||
);
|
||||
}
|
||||
|
||||
@Insert("insert into flow_report_day(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)")
|
||||
void add(FlowReportDayDO flowReportDayDO);
|
||||
default void deleteByDateStr(String dateStr) {
|
||||
this.delete(new LambdaQueryWrapper<FlowReportDayDO>()
|
||||
.eq(FlowReportDayDO::getDateStr, dateStr)
|
||||
);
|
||||
}
|
||||
|
||||
@Delete("delete from flow_report_day where date_str = :dateStr")
|
||||
void deleteByDateStr(@Param("dateStr") String dateStr);
|
||||
|
||||
@ResultType(FlowReportDayDO.class)
|
||||
@Select("select * from flow_report_day where date >= :startDate and date <= :endDate")
|
||||
List<FlowReportDayDO> findListByDateRange(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
|
||||
default List<FlowReportDayDO> findListByDateRange(Date startDate, Date endDate) {
|
||||
return this.selectList(new LambdaQueryWrapper<FlowReportDayDO>()
|
||||
.le(FlowReportDayDO::getDate, startDate)
|
||||
.gt(FlowReportDayDO::getDate, endDate)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-15
@@ -21,12 +21,8 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportHourDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -35,17 +31,23 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface FlowReportHourMapper extends BaseMapper<FlowReportHourDO> {
|
||||
@Select("select * from flow_report_hour where license_id = :licenseId and date_str = :dateStr")
|
||||
FlowReportHourDO findOne(@Param("licenseId") Integer licenseId, @Param("dateStr") String dateStr);
|
||||
default void clean(Date date) {
|
||||
this.delete(new LambdaQueryWrapper<FlowReportHourDO>()
|
||||
.lt(FlowReportHourDO::getCreateTime, date)
|
||||
);
|
||||
}
|
||||
|
||||
@Insert("insert into flow_report_hour(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)")
|
||||
void add(FlowReportHourDO flowReportHourDO);
|
||||
default void deleteByDateStr(String dateStr) {
|
||||
this.delete(new LambdaQueryWrapper<FlowReportHourDO>()
|
||||
.eq(FlowReportHourDO::getDateStr, dateStr)
|
||||
);
|
||||
}
|
||||
|
||||
@Delete("delete from flow_report_hour where date_str = :dateStr")
|
||||
void deleteByDateStr(@Param("dateStr") String dateStr);
|
||||
|
||||
@ResultType(FlowReportHourDO.class)
|
||||
@Select("select * from flow_report_hour where date >= :startDate and date <= :endDate")
|
||||
List<FlowReportHourDO> findListByDateRange(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
|
||||
default List<FlowReportHourDO> findListByDateRange(Date startDate, Date endDate) {
|
||||
return this.selectList(new LambdaQueryWrapper<FlowReportHourDO>()
|
||||
.ge(FlowReportHourDO::getDateStr, startDate)
|
||||
.le(FlowReportHourDO::getDateStr, endDate)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+18
-14
@@ -21,11 +21,8 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportMinuteDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -35,17 +32,24 @@ import java.util.Set;
|
||||
|
||||
@Mapper
|
||||
public interface FlowReportMinuteMapper extends BaseMapper<FlowReportMinuteDO> {
|
||||
@Select("select * from flow_report_minute where license_id = :licenseId and date = :date")
|
||||
FlowReportMinuteDO findOne(@Param("licenseId") Integer licenseId, @Param("date") String date);
|
||||
default void clean(Date date) {
|
||||
this.delete(new LambdaQueryWrapper<FlowReportMinuteDO>()
|
||||
.lt(FlowReportMinuteDO::getCreateTime, date)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(FlowReportMinuteDO.class)
|
||||
@Select("select * from flow_report_minute where license_id in (:licenseIds) and date = :date")
|
||||
List<FlowReportMinuteDO> findList(@Param("licenseIds") Set<Integer> licenseIds, @Param("date") String date);
|
||||
default List<FlowReportMinuteDO> findList(Set<Integer> licenseIds, String date) {
|
||||
return this.selectList(new LambdaQueryWrapper<FlowReportMinuteDO>()
|
||||
.in(FlowReportMinuteDO::getLicenseId, licenseIds)
|
||||
.eq(FlowReportMinuteDO::getDate, date)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(FlowReportMinuteDO.class)
|
||||
@Select("select * from flow_report_minute where date >= :startDate and date <= :endDate")
|
||||
List<FlowReportMinuteDO> findListByDateRange(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
|
||||
default List<FlowReportMinuteDO> findListByDateRange(Date startDate, Date endDate) {
|
||||
return this.selectList(new LambdaQueryWrapper<FlowReportMinuteDO>()
|
||||
.ge(FlowReportMinuteDO::getDate, startDate)
|
||||
.le(FlowReportMinuteDO::getDate, endDate)
|
||||
);
|
||||
}
|
||||
|
||||
@Insert("insert into flow_report_minute(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)")
|
||||
void add(FlowReportMinuteDO flowReportMinuteDO);
|
||||
}
|
||||
|
||||
+6
-11
@@ -21,22 +21,17 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportMonthDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FlowReportMonthMapper extends BaseMapper<FlowReportMonthDO> {
|
||||
@Select("select * from flow_report_month where license_id = :licenseId and date_str = :dateStr")
|
||||
FlowReportMonthDO findOne(@Param("licenseId") Integer licenseId, @Param("dateStr") String dateStr);
|
||||
|
||||
@Insert("insert into flow_report_month(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)")
|
||||
void add(FlowReportMonthDO flowReportMonthDO);
|
||||
|
||||
@Delete("delete from flow_report_month where date_str = :dateStr")
|
||||
void deleteByDateStr(@Param("dateStr") String dateStr);
|
||||
default void deleteByDateStr(String dateStr) {
|
||||
this.delete(new LambdaQueryWrapper<FlowReportMonthDO>()
|
||||
.eq(FlowReportMonthDO::getDateStr, dateStr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-20
@@ -21,14 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.annotation.Update;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.JobInfoListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.JobInfoListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.JobInfoDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -38,19 +33,19 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface JobInfoMapper extends BaseMapper<JobInfoDO> {
|
||||
|
||||
@ResultType(JobInfoListRes.class)
|
||||
@Select("select * from job_info")
|
||||
void page(PageInfo pageInfo, JobInfoListReq req);
|
||||
default JobInfoDO findById(Integer id) {
|
||||
return this.selectById(id);
|
||||
}
|
||||
|
||||
@Select("select * from job_info where id = ?")
|
||||
JobInfoDO findById(Integer id);
|
||||
default void updateEnableStatus(Integer id, Integer enable, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<JobInfoDO>()
|
||||
.eq(JobInfoDO::getId, id)
|
||||
.set(JobInfoDO::getEnable, enable)
|
||||
.set(JobInfoDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update `job_info` set enable = :enable,update_time = :updateTime where id = :id")
|
||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime") Date updateTime);
|
||||
|
||||
@ResultType(JobInfoDO.class)
|
||||
@Select("select * from job_info")
|
||||
List<JobInfoDO> findList();
|
||||
|
||||
void update(JobInfoDO jobInfoDO);
|
||||
default List<JobInfoDO> findList() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
}
|
||||
}
|
||||
|
||||
+8
-20
@@ -21,37 +21,25 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.JobLogListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.JobLogListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/9/5
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface JobLogMapper extends BaseMapper<JobLogDO> {
|
||||
|
||||
@Insert("insert into job_log(`job_id`,`handler`,`param`,`code`,`msg`,`alarm_status`,`create_time`) values(:jobId,:handler,:param,:code,:msg,:alarmStatus,:createTime)")
|
||||
void add(JobLogDO jobLog);
|
||||
|
||||
@ResultType(JobLogListRes.class)
|
||||
@Select("select * from job_log order by create_time desc")
|
||||
void page(PageInfo pageInfo, JobLogListReq req);
|
||||
|
||||
@ResultType(JobLogListRes.class)
|
||||
@Select("select * from job_log where job_id = :jobId order by create_time desc")
|
||||
void pageByJobId(PageInfo pageInfo, JobLogListReq req);
|
||||
default void clean(Date date) {
|
||||
this.delete(new LambdaQueryWrapper<JobLogDO>()
|
||||
.lt(JobLogDO::getCreateTime, date)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+46
-59
@@ -24,16 +24,6 @@ package fun.asgc.neutrino.proxy.server.dal;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.annotation.Update;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.LicenseListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -46,41 +36,28 @@ import java.util.Set;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/6
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface LicenseMapper extends BaseMapper<LicenseDO> {
|
||||
|
||||
/**
|
||||
* 查询license分页
|
||||
* @param pageInfo
|
||||
* @param req
|
||||
*/
|
||||
void page(PageInfo pageInfo, LicenseListReq req);
|
||||
default List<LicenseDO> listAll() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
}
|
||||
|
||||
@ResultType(LicenseListRes.class)
|
||||
@Select("select * from license where enable = 1")
|
||||
List<LicenseListRes> list();
|
||||
default List<LicenseDO> listByUserId(Integer userId) {
|
||||
return this.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getUserId, userId)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from license")
|
||||
List<LicenseDO> listAll();
|
||||
default void updateEnableStatus(Integer id, Integer enable, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getId, id)
|
||||
.set(LicenseDO::getEnable, enable)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where user_id = :userId")
|
||||
List<LicenseDO> listByUserId(@Param("userId") Integer userId);
|
||||
|
||||
/**
|
||||
* 新增license
|
||||
* @param license
|
||||
*/
|
||||
int add(LicenseDO license);
|
||||
|
||||
@Update("update `license` set enable = :enable, update_time = :updateTime where id = :id")
|
||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime") Date updateTime);
|
||||
|
||||
@Update("update `license` set is_online = :isOnline, update_time = :updateTime where id = :id")
|
||||
default void updateOnlineStatus(@Param("id") Integer id, @Param("isOnline") Integer isOnline, @Param("updateTime") Date updateTime) {
|
||||
default void updateOnlineStatus(Integer id, Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getId, id)
|
||||
.set(LicenseDO::getIsOnline, isOnline)
|
||||
@@ -88,32 +65,38 @@ public interface LicenseMapper extends BaseMapper<LicenseDO> {
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update `license` set is_online = :isOnline, update_time = :updateTime")
|
||||
void updateOnlineStatus(@Param("isOnline") Integer isOnline, @Param("updateTime") Date updateTime);
|
||||
default void updateOnlineStatus(Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.set(LicenseDO::getIsOnline, updateTime)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update `license` set `key` = :key,update_time = :updateTime where id = :id")
|
||||
void reset(@Param("id") Integer id, @Param("key") String key, @Param("updateTime") Date updateTime);
|
||||
default void reset(Integer id, String key, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getId, id)
|
||||
.set(LicenseDO::getKey, key)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Delete("delete from `license` where id = ?")
|
||||
void delete(Integer id);
|
||||
|
||||
@Select("select * from `license` where id = ?")
|
||||
default LicenseDO findById(Integer id) {
|
||||
return this.selectById(id);
|
||||
}
|
||||
|
||||
@Update("update `license` set name = :name, update_time = :updateTime where id = :id")
|
||||
void update(@Param("id") Integer id, @Param("name") String name, @Param("updateTime") Date updateTime);
|
||||
default void update(Integer id, String name, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getId, id)
|
||||
.set(LicenseDO::getName, name)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where id in (:ids)")
|
||||
default List<LicenseDO> findByIds(@Param("ids")Set<Integer> ids) {
|
||||
default List<LicenseDO> findByIds(Set<Integer> ids) {
|
||||
return selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where user_id = :userId and name =:name limit 0,1")
|
||||
default LicenseDO checkRepeat(@Param("userId") Integer userId, @Param("name") String name) {
|
||||
default LicenseDO checkRepeat(Integer userId, String name) {
|
||||
return this.selectOne(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getUserId, userId)
|
||||
.eq(LicenseDO::getName, name)
|
||||
@@ -121,11 +104,15 @@ public interface LicenseMapper extends BaseMapper<LicenseDO> {
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where user_id = :userId and name =:name and id not in (:excludeIds) limit 0,1")
|
||||
LicenseDO checkRepeat(@Param("userId") Integer userId, @Param("name") String name, @Param("excludeIds") Set<Integer> excludeIds);
|
||||
default LicenseDO checkRepeat(Integer userId, String name, Set<Integer> excludeIds) {
|
||||
return this.selectOne(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getUserId, userId)
|
||||
.eq(LicenseDO::getName, name)
|
||||
.notIn(LicenseDO::getId, excludeIds)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
@Select("select * from `license` where `key` = ?")
|
||||
default LicenseDO findByKey(String licenseKey) {
|
||||
return selectOne(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getKey, licenseKey)
|
||||
|
||||
+37
-45
@@ -24,17 +24,8 @@ package fun.asgc.neutrino.proxy.server.dal;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.annotation.Update;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.core.util.CollectionUtil;
|
||||
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortMappingListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -47,36 +38,29 @@ import java.util.Set;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/8
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface PortMappingMapper extends BaseMapper<PortMappingDO> {
|
||||
|
||||
@ResultType(PortMappingListRes.class)
|
||||
@Select("select * from port_mapping")
|
||||
void page(PageInfo pageInfo, PortMappingListReq req);
|
||||
default PortMappingDO findById(Integer id) {
|
||||
return this.selectById(id);
|
||||
}
|
||||
|
||||
void add(PortMappingDO portMappingDO);
|
||||
default void updateEnableStatus(Integer id, Integer enable, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getId, id)
|
||||
.set(PortMappingDO::getEnable, enable)
|
||||
.set(PortMappingDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
void update(PortMappingDO portMappingDO);
|
||||
default PortMappingDO findByPort(Integer port, Set<Integer> excludeIds) {
|
||||
return this.selectOne(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getServerPort, port)
|
||||
.notIn(!CollectionUtil.isEmpty(excludeIds), PortMappingDO::getId, excludeIds)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
@Select("select * from port_mapping where id = ?")
|
||||
PortMappingDO findById(Integer id);
|
||||
|
||||
@Update("update `port_mapping` set enable = :enable,update_time = :updateTime where id = :id")
|
||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime") Date updateTime);
|
||||
|
||||
@Delete("delete from `port_mapping` where id = ?")
|
||||
void delete(Integer id);
|
||||
|
||||
@Select("select * from port_mapping where server_port = ?")
|
||||
PortMappingDO findByPort(Integer port);
|
||||
|
||||
@Select("select * from port_mapping where server_port = :port and id not in (:excludeIds)")
|
||||
PortMappingDO findByPort(@Param("port") Integer port, @Param("excludeIds") Set<Integer> excludeIds);
|
||||
|
||||
@ResultType(PortMappingDO.class)
|
||||
@Select("select * from port_mapping where license_id = ? and enable = 1")
|
||||
default List<PortMappingDO> findEnableListByLicenseId(Integer licenseId) {
|
||||
return this.selectList(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
@@ -84,20 +68,19 @@ public interface PortMappingMapper extends BaseMapper<PortMappingDO> {
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(PortMappingDO.class)
|
||||
@Select("select * from port_mapping where server_port = :serverPort")
|
||||
List<PortMappingDO> findListByServerPort(@Param("serverPort") Integer serverPort);
|
||||
default List<PortMappingDO> findListByServerPort(Integer serverPort) {
|
||||
return this.selectList(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getServerPort, serverPort)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(PortMappingDO.class)
|
||||
@Select("select * from port_mapping where license_id = ?")
|
||||
default List<PortMappingDO> findListByLicenseId(Integer licenseId) {
|
||||
return this.selectList(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update `port_mapping` set is_online = :isOnline,update_time = :updateTime where license_id = :licenseId and server_port = :serverPort")
|
||||
default void updateOnlineStatus(@Param("licenseId") Integer licenseId, @Param("serverPort") Integer serverPort, @Param("isOnline") Integer isOnline, @Param("updateTime") Date updateTime) {
|
||||
default void updateOnlineStatus(Integer licenseId,Integer serverPort, Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
.eq(PortMappingDO::getServerPort, serverPort)
|
||||
@@ -106,9 +89,18 @@ public interface PortMappingMapper extends BaseMapper<PortMappingDO> {
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update `port_mapping` set is_online = :isOnline,update_time = :updateTime where license_id = :licenseId")
|
||||
void updateOnlineStatus(@Param("licenseId") Integer licenseId, @Param("isOnline") Integer isOnline, @Param("updateTime") Date updateTime);
|
||||
default void updateOnlineStatus(Integer licenseId, Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
.set(PortMappingDO::getIsOnline, isOnline)
|
||||
.set(PortMappingDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update `port_mapping` set is_online = :isOnline,update_time = :updateTime")
|
||||
void updateOnlineStatus(@Param("isOnline") Integer isOnline, @Param("updateTime") Date updateTime);
|
||||
default void updateOnlineStatus(Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<PortMappingDO>()
|
||||
.set(PortMappingDO::getIsOnline, isOnline)
|
||||
.set(PortMappingDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-30
@@ -22,54 +22,35 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.*;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/7
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface PortPoolMapper extends BaseMapper<PortPoolDO> {
|
||||
default void updateEnableStatus(Integer id, Integer enable, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<PortPoolDO>()
|
||||
.eq(PortPoolDO::getId, id)
|
||||
.set(PortPoolDO::getEnable, enable)
|
||||
.set(PortPoolDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(PortPoolListRes.class)
|
||||
@Select("select * from port_pool")
|
||||
void page(PageInfo<PortPoolListRes> pageInfo, PortPoolListReq req);
|
||||
|
||||
@ResultType(PortPoolListRes.class)
|
||||
@Select("select * from port_pool where enable = 1")
|
||||
List<PortPoolListRes> list();
|
||||
|
||||
@Insert("insert into port_pool(`port`,`enable`,`create_time`,`update_time`) values(:port,:enable,:createTime,:updateTime)")
|
||||
void add(PortPoolDO portPool);
|
||||
|
||||
@Update("update `port_pool` set enable = :enable, update_time = :updateTime where id = :id")
|
||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime") Date updateTime);
|
||||
|
||||
@Delete("delete from `port_pool` where id = ?")
|
||||
void delete(Integer id);
|
||||
|
||||
@Select("select * from port_pool where port = ? limit 0,1")
|
||||
default PortPoolDO findByPort(Integer port) {
|
||||
return this.selectOne(new LambdaQueryWrapper<PortPoolDO>()
|
||||
.eq(PortPoolDO::getPort, port)
|
||||
);
|
||||
}
|
||||
|
||||
@Select("select * from port_pool where id = ?")
|
||||
PortPoolDO findById(Integer id);
|
||||
default PortPoolDO findById(Integer id) {
|
||||
return this.selectById(id);
|
||||
}
|
||||
}
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/31
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
public interface UserConnectRecordMapper {
|
||||
|
||||
}
|
||||
+8
-21
@@ -21,36 +21,23 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.ResultType;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.UserLoginRecordListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.UserLoginRecordListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserLoginRecordDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/2
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface UserLoginRecordMapper extends BaseMapper<UserLoginRecordDO> {
|
||||
/**
|
||||
* 新增用户登录日志
|
||||
* @param userLoginRecord
|
||||
* @return
|
||||
*/
|
||||
@Insert("insert into `user_login_record`(`user_id`,`ip`,`token`,`type`,`create_time`) values(:userId,:ip,:token,:type,:createTime)")
|
||||
int add(UserLoginRecordDO userLoginRecord);
|
||||
|
||||
@ResultType(UserLoginRecordListRes.class)
|
||||
@Select("select * from user_login_record order by create_time desc")
|
||||
void page(PageInfo pageInfo, UserLoginRecordListReq req);
|
||||
default void clean(Date date) {
|
||||
this.delete(new LambdaQueryWrapper<UserLoginRecordDO>()
|
||||
.lt(UserLoginRecordDO::getCreateTime, date)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-32
@@ -22,14 +22,9 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.*;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.UserListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.UserListRes;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -42,8 +37,6 @@ import java.util.Set;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/1
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<UserDO> {
|
||||
|
||||
@@ -52,7 +45,6 @@ public interface UserMapper extends BaseMapper<UserDO> {
|
||||
* @param loginName
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from user where login_name = ?")
|
||||
default UserDO findByLoginName(String loginName) {
|
||||
return selectOne(new LambdaQueryWrapper<UserDO>()
|
||||
.eq(UserDO::getLoginName, loginName)
|
||||
@@ -65,36 +57,29 @@ public interface UserMapper extends BaseMapper<UserDO> {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from user where id = ?")
|
||||
default UserDO findById(Integer id) {
|
||||
return selectById(id);
|
||||
}
|
||||
|
||||
@ResultType(UserDO.class)
|
||||
@Select("select * from user where id in (:ids)")
|
||||
default List<UserDO> findByIds(@Param("ids") Set<Integer> ids) {
|
||||
default List<UserDO> findByIds(Set<Integer> ids) {
|
||||
return selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@ResultType(UserListRes.class)
|
||||
@Select("select * from user")
|
||||
void page(PageInfo pageInfo, UserListReq req);
|
||||
default void updateEnableStatus(Integer id, Integer enable, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<UserDO>()
|
||||
.eq(UserDO::getId, id)
|
||||
.set(UserDO::getEnable, enable)
|
||||
.set(UserDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@ResultType(UserListRes.class)
|
||||
@Select("select * from user where enable = 1")
|
||||
List<UserListRes> list();
|
||||
|
||||
@Update("update `user` set enable = :enable,update_time = :updateTime where id = :id")
|
||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable, @Param("updateTime")Date updateTime);
|
||||
|
||||
@Delete("delete from `user` where id = ?")
|
||||
void delete(Integer id);
|
||||
|
||||
@Update("update `user` set name = :name,login_name = :loginName,update_time = :updateTime where id = :id")
|
||||
void update(UserDO userDO);
|
||||
|
||||
@Update("update `user` set login_password = :loginPassword,update_time = :updateTime where id = :id")
|
||||
void updateLoginPassword(@Param("id") Integer id, @Param("loginPassword") String loginPassword, @Param("updateTime")Date updateTime);
|
||||
default void updateLoginPassword(Integer id, String loginPassword, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<UserDO>()
|
||||
.eq(UserDO::getId, id)
|
||||
.set(UserDO::getLoginPassword, loginPassword)
|
||||
.set(UserDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Insert("insert into user(`name`,`login_name`,`login_password`,`enable`,`create_time`,`update_time`) values(:name,:loginName,:loginPassword,:enable,:createTime,:updateTime)")
|
||||
void add(UserDO user);
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal;
|
||||
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.page.PageInfo;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/1/18
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface UserReportMapper {
|
||||
|
||||
void userFlowReportPage(PageInfo<UserFlowReportRes> pageInfo, @Param("todayBegin") Date todayBegin, @Param("todayEnd") Date todayEnd);
|
||||
|
||||
}
|
||||
+12
-23
@@ -24,11 +24,6 @@ package fun.asgc.neutrino.proxy.server.dal;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Update;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -39,18 +34,8 @@ import java.util.Date;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/1
|
||||
*/
|
||||
@Intercept(ignoreGlobal = true)
|
||||
@Component
|
||||
@Mapper
|
||||
public interface UserTokenMapper extends BaseMapper<UserTokenDO> {
|
||||
/**
|
||||
* 新增用户token
|
||||
* 支持注解 + xml配置2种方式
|
||||
* @param userToken
|
||||
* @return
|
||||
*/
|
||||
// @Insert("insert into `user_token`(`token`,`user_id`,`expiration_time`,`create_time`,`update_time`) values (:token,:userId,:expirationTime,:createTime,:updateTime)")
|
||||
int add(UserTokenDO userToken);
|
||||
|
||||
/**
|
||||
* 根据token查询单条记录
|
||||
@@ -59,7 +44,6 @@ public interface UserTokenMapper extends BaseMapper<UserTokenDO> {
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
// @Select("select * from user_token where token = ? and expiration_time > ?")
|
||||
default UserTokenDO findByAvailableToken(String token, Date date) {
|
||||
return selectOne(new LambdaQueryWrapper<UserTokenDO>()
|
||||
.eq(UserTokenDO::getToken, token)
|
||||
@@ -71,12 +55,14 @@ public interface UserTokenMapper extends BaseMapper<UserTokenDO> {
|
||||
* 根据token删除记录
|
||||
* @param token
|
||||
*/
|
||||
@Delete("delete from user_token where token = ?")
|
||||
void deleteByToken(String token);
|
||||
default void deleteByToken(String token) {
|
||||
this.delete(new LambdaQueryWrapper<UserTokenDO>()
|
||||
.eq(UserTokenDO::getToken, token)
|
||||
);
|
||||
}
|
||||
|
||||
@Update("update user_token set expiration_time = :expirationTime where token = :token")
|
||||
default void updateTokenExpirationTime(@Param("token") String token, @Param("expirationTime") Date expirationTime) {
|
||||
update(null, new LambdaUpdateWrapper<UserTokenDO>()
|
||||
default void updateTokenExpirationTime(String token, Date expirationTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<UserTokenDO>()
|
||||
.eq(UserTokenDO::getToken, token)
|
||||
.set(UserTokenDO::getExpirationTime, expirationTime)
|
||||
);
|
||||
@@ -86,6 +72,9 @@ public interface UserTokenMapper extends BaseMapper<UserTokenDO> {
|
||||
* 根据userId删除token
|
||||
* @param userId
|
||||
*/
|
||||
@Delete("delete from user_token where user_id = ?")
|
||||
void deleteByUserId(Integer userId);
|
||||
default void deleteByUserId(Integer userId) {
|
||||
this.delete(new LambdaQueryWrapper<UserTokenDO>()
|
||||
.eq(UserTokenDO::getUserId, userId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -1,9 +1,8 @@
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -17,11 +16,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("client_connect_record")
|
||||
@TableName("client_connect_record")
|
||||
public class ClientConnectRecordDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private String ip;
|
||||
private Integer licenseId;
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -38,11 +37,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("flow_report_day")
|
||||
@TableName("flow_report_day")
|
||||
public class FlowReportDayDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户ID
|
||||
|
||||
+4
-5
@@ -21,9 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -37,10 +37,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("flow_report_hour")
|
||||
@TableName("flow_report_hour")
|
||||
public class FlowReportHourDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户ID
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -38,11 +37,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("flow_report_minute")
|
||||
@TableName("flow_report_minute")
|
||||
public class FlowReportMinuteDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户ID
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -38,11 +37,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("flow_report_month")
|
||||
@TableName("flow_report_month")
|
||||
public class FlowReportMonthDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户ID
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -39,11 +38,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("job_info")
|
||||
@TableName("job_info")
|
||||
public class JobInfoDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private String cron;
|
||||
private String desc;
|
||||
|
||||
+2
-3
@@ -21,9 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -38,10 +38,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("job_log")
|
||||
@TableName("job_log")
|
||||
public class JobLogDO {
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Integer jobId;
|
||||
private String handler;
|
||||
|
||||
-4
@@ -24,8 +24,6 @@ package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
@@ -41,10 +39,8 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("license")
|
||||
@TableName("license")
|
||||
public class LicenseDO {
|
||||
@Id
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import fun.asgc.neutrino.proxy.server.constant.OnlineStatusEnum;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
@@ -40,11 +39,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("port_mapping")
|
||||
@TableName("port_mapping")
|
||||
public class PortMappingDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* licenseId
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -39,11 +38,9 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("port_pool")
|
||||
@TableName("port_pool")
|
||||
public class PortPoolDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 端口
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -37,11 +36,9 @@ import java.util.Date;
|
||||
*/
|
||||
@ToString
|
||||
@Data
|
||||
@Table("user")
|
||||
@TableName("user")
|
||||
public class UserDO {
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户名
|
||||
|
||||
+2
-5
@@ -12,10 +12,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -30,7 +29,6 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Table("user_login_record")
|
||||
@TableName("user_login_record")
|
||||
public class UserLoginRecordDO {
|
||||
/**
|
||||
@@ -42,8 +40,7 @@ public class UserLoginRecordDO {
|
||||
*/
|
||||
public static final Integer TYPE_LOGOUT = 2;
|
||||
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户ID
|
||||
|
||||
+2
-5
@@ -21,10 +21,9 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.dal.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.core.db.annotation.Table;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -39,12 +38,10 @@ import java.util.Date;
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@Table("user_token")
|
||||
@TableName("user_token")
|
||||
public class UserTokenDO {
|
||||
|
||||
@Id
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* token
|
||||
|
||||
+21
-11
@@ -22,16 +22,16 @@
|
||||
package fun.asgc.neutrino.proxy.server.job;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import fun.asgc.neutrino.core.annotation.Autowired;
|
||||
import fun.asgc.neutrino.core.util.DateUtil;
|
||||
import fun.asgc.neutrino.proxy.server.base.quartz.IJobHandler;
|
||||
import fun.asgc.neutrino.proxy.server.base.quartz.JobHandler;
|
||||
import fun.asgc.neutrino.proxy.server.dal.DataCleanMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.*;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
@@ -46,9 +46,6 @@ import java.util.Date;
|
||||
@Component
|
||||
@JobHandler(name = "DataCleanJob", cron = "0 0 1 * * ?")
|
||||
public class DataCleanJob implements IJobHandler {
|
||||
@Inject
|
||||
private DataCleanMapper dataCleanMapper;
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
/**
|
||||
* Job日志保存天数
|
||||
*/
|
||||
@@ -74,6 +71,19 @@ public class DataCleanJob implements IJobHandler {
|
||||
* 流量统计天报表记录保留天数
|
||||
*/
|
||||
private static final Integer FLOW_DAY_REPORT_KEEP_DAYS = 400;
|
||||
@Autowired
|
||||
private JobLogMapper jobLogMapper;
|
||||
@Autowired
|
||||
private UserLoginRecordMapper userLoginRecordMapper;
|
||||
@Autowired
|
||||
private ClientConnectRecordMapper clientConnectRecordMapper;
|
||||
@Autowired
|
||||
private FlowReportMinuteMapper flowReportMinuteMapper;
|
||||
@Autowired
|
||||
private FlowReportHourMapper flowReportHourMapper;
|
||||
@Autowired
|
||||
private FlowReportDayMapper flowReportDayMapper;
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public void execute(String s) throws Exception {
|
||||
@@ -82,37 +92,37 @@ public class DataCleanJob implements IJobHandler {
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getJobLogKeepDays());
|
||||
log.info("清理调度管理日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanJobLog(date);
|
||||
jobLogMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getUserLoginRecordKeepDays());
|
||||
log.info("清理用户登录日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanUserLoginRecord(date);
|
||||
userLoginRecordMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getClientConnectRecordKeepDays());
|
||||
log.info("清理客户端连接日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanClientConnectRecord(date);
|
||||
clientConnectRecordMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getFlowMinuteReportKeepDays());
|
||||
log.info("清理流通统计分钟报表日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanFlowMinuteReport(date);
|
||||
flowReportMinuteMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getFlowHourReportKeepDays());
|
||||
log.info("清理流通统计小时报表日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanFlowHourReport(date);
|
||||
flowReportHourMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getFlowDayReportKeepDays());
|
||||
log.info("清理流通统计日报表日志 date:{}", sdf.format(date));
|
||||
dataCleanMapper.cleanFlowDayReport(date);
|
||||
flowReportDayMapper.clean(date);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class FlowReportForDayJob implements IJobHandler {
|
||||
}
|
||||
|
||||
for (FlowReportDayDO item : map.values()) {
|
||||
flowReportDayMapper.add(item);
|
||||
flowReportDayMapper.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public class FlowReportForHourJob implements IJobHandler {
|
||||
}
|
||||
|
||||
for (FlowReportHourDO item : map.values()) {
|
||||
flowReportHourMapper.add(item);
|
||||
flowReportHourMapper.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ public class FlowReportForMinuteJob implements IJobHandler {
|
||||
flowReportMinuteDO.setDate(date);
|
||||
flowReportMinuteDO.setDateStr(dateStr);
|
||||
flowReportMinuteDO.setCreateTime(now);
|
||||
flowReportMinuteMapper.add(flowReportMinuteDO);
|
||||
flowReportMinuteMapper.insert(flowReportMinuteDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ public class FlowReportForMonthJob implements IJobHandler {
|
||||
}
|
||||
|
||||
for (FlowReportMonthDO item : map.values()) {
|
||||
flowReportMonthMapper.add(item);
|
||||
flowReportMonthMapper.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -39,6 +39,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -57,11 +58,11 @@ import java.util.stream.Collectors;
|
||||
public class ClientConnectRecordService {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private ClientConnectRecordMapper clientConnectRecordMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
|
||||
public void add(ClientConnectRecordDO clientConnectRecordDO) {
|
||||
|
||||
+3
-2
@@ -46,6 +46,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.JobInfoDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
@@ -63,7 +64,7 @@ import java.util.List;
|
||||
public class JobInfoService implements IJobSource {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private JobInfoMapper jobInfoMapper;
|
||||
|
||||
public PageInfo<JobInfoListRes> page(PageQuery pageQuery, JobInfoListReq req) {
|
||||
@@ -137,7 +138,7 @@ public class JobInfoService implements IJobSource {
|
||||
jobInfo.setParam(req.getParam());
|
||||
jobInfo.setUpdateTime(new Date());
|
||||
|
||||
jobInfoMapper.update( jobInfo);
|
||||
jobInfoMapper.updateById(jobInfo);
|
||||
return new JobInfoUpdateRes();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -35,6 +35,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.JobLogDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -51,7 +52,7 @@ import java.util.List;
|
||||
public class JobLogService implements IJobCallback {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private JobLogMapper jobLogMapper;
|
||||
|
||||
@Override
|
||||
@@ -66,7 +67,7 @@ public class JobLogService implements IJobCallback {
|
||||
msg = "执行异常:\r\n" + ExceptionUtils.getStackTrace(throwable);
|
||||
code = -1;
|
||||
}
|
||||
jobLogMapper.add(new JobLogDO()
|
||||
jobLogMapper.insert(new JobLogDO()
|
||||
.setJobId(Integer.valueOf(jobInfo.getId()))
|
||||
.setHandler(jobInfo.getName())
|
||||
.setParam(param)
|
||||
|
||||
+7
-3
@@ -44,6 +44,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.Lifecycle;
|
||||
@@ -61,9 +62,9 @@ import java.util.stream.Collectors;
|
||||
public class LicenseService implements Lifecycle {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
@@ -93,7 +94,10 @@ public class LicenseService implements Lifecycle {
|
||||
}
|
||||
|
||||
public List<LicenseListRes> list(LicenseListReq req) {
|
||||
List<LicenseListRes> licenseList = licenseMapper.list();
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getEnable, EnableStatusEnum.ENABLE.getStatus())
|
||||
);
|
||||
List<LicenseListRes> licenseList = mapperFactory.getMapperFacade().mapAsList(list, LicenseListRes.class);
|
||||
if (!CollectionUtil.isEmpty(licenseList)) {
|
||||
Set<Integer> userIds = licenseList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
|
||||
+9
-8
@@ -48,6 +48,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.Lifecycle;
|
||||
@@ -68,13 +69,13 @@ import java.util.stream.Collectors;
|
||||
public class PortMappingService implements Lifecycle {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private PortMappingMapper portMappingMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private PortPoolMapper portPoolMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
@@ -122,7 +123,7 @@ public class PortMappingService implements Lifecycle {
|
||||
}
|
||||
PortPoolDO portPoolDO = portPoolMapper.findByPort(req.getServerPort());
|
||||
ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
|
||||
ParamCheckUtil.checkExpression(null == portMappingMapper.findByPort(req.getServerPort()), ExceptionConstant.PORT_CANNOT_REPEAT_MAPPING, req.getServerPort());
|
||||
ParamCheckUtil.checkExpression(null == portMappingMapper.findByPort(req.getServerPort(), null), ExceptionConstant.PORT_CANNOT_REPEAT_MAPPING, req.getServerPort());
|
||||
|
||||
|
||||
Date now = new Date();
|
||||
@@ -135,7 +136,7 @@ public class PortMappingService implements Lifecycle {
|
||||
portMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
portMappingDO.setCreateTime(now);
|
||||
portMappingDO.setUpdateTime(now);
|
||||
portMappingMapper.add(portMappingDO);
|
||||
portMappingMapper.insert(portMappingDO);
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.addVisitorChannelByPortMapping(portMappingDO);
|
||||
return new PortMappingCreateRes();
|
||||
@@ -164,7 +165,7 @@ public class PortMappingService implements Lifecycle {
|
||||
portMappingDO.setClientPort(req.getClientPort());
|
||||
portMappingDO.setUpdateTime(new Date());
|
||||
portMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
portMappingMapper.update(portMappingDO);
|
||||
portMappingMapper.updateById(portMappingDO);
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByPortMapping(oldPortMappingDO, portMappingDO);
|
||||
return new PortMappingUpdateRes();
|
||||
@@ -232,7 +233,7 @@ public class PortMappingService implements Lifecycle {
|
||||
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
|
||||
}
|
||||
|
||||
portMappingMapper.delete(id);
|
||||
portMappingMapper.deleteById(id);
|
||||
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.removeVisitorChannelByPortMapping(portMappingDO);
|
||||
|
||||
+8
-4
@@ -38,6 +38,7 @@ import fun.asgc.neutrino.proxy.server.dal.PortPoolMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -53,7 +54,7 @@ import java.util.List;
|
||||
public class PortPoolService {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private PortPoolMapper portPoolMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
@@ -68,7 +69,10 @@ public class PortPoolService {
|
||||
}
|
||||
|
||||
public List<PortPoolListRes> list(PortPoolListReq req) {
|
||||
return portPoolMapper.list();
|
||||
List<PortPoolDO> list = portPoolMapper.selectList(new LambdaQueryWrapper<PortPoolDO>()
|
||||
.eq(PortPoolDO::getEnable, EnableStatusEnum.ENABLE.getStatus())
|
||||
);
|
||||
return mapperFactory.getMapperFacade().mapAsList(list, PortPoolListRes.class);
|
||||
}
|
||||
|
||||
public PortPoolCreateRes create(PortPoolCreateReq req) {
|
||||
@@ -77,7 +81,7 @@ public class PortPoolService {
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
portPoolMapper.add(new PortPoolDO()
|
||||
portPoolMapper.insert(new PortPoolDO()
|
||||
.setPort(req.getPort())
|
||||
.setEnable(EnableStatusEnum.ENABLE.getStatus())
|
||||
.setCreateTime(now)
|
||||
@@ -104,7 +108,7 @@ public class PortPoolService {
|
||||
PortPoolDO portPoolDO = portPoolMapper.findById(id);
|
||||
ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
|
||||
|
||||
portPoolMapper.delete(id);
|
||||
portPoolMapper.deleteById(id);
|
||||
|
||||
// 更新visitorChannel
|
||||
visitorChannelService.updateVisitorChannelByPortPool(portPoolDO.getPort(), EnableStatusEnum.DISABLE.getStatus());
|
||||
|
||||
+3
-3
@@ -26,8 +26,8 @@ import fun.asgc.neutrino.proxy.server.dal.LicenseMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.PortMappingMapper;
|
||||
import fun.asgc.neutrino.proxy.server.proxy.domain.CmdChannelAttachInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -39,9 +39,9 @@ import java.util.Date;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProxyMutualService {
|
||||
@Inject
|
||||
@Db
|
||||
private PortMappingMapper portMappingMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
|
||||
/**
|
||||
|
||||
-4
@@ -27,10 +27,8 @@ import fun.asgc.neutrino.proxy.server.controller.req.LicenseFlowReportReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.UserFlowReportReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.LicenseFlowReportRes;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.UserReportMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
@@ -39,8 +37,6 @@ import org.noear.solon.annotation.Inject;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ReportService {
|
||||
@Inject
|
||||
private UserReportMapper userReportMapper;
|
||||
|
||||
/**
|
||||
* 用户流量报表分页
|
||||
|
||||
+3
-2
@@ -35,6 +35,7 @@ import fun.asgc.neutrino.proxy.server.dal.UserMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserLoginRecordDO;
|
||||
import ma.glasnost.orika.MapperFactory;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -53,9 +54,9 @@ import java.util.stream.Collectors;
|
||||
public class UserLoginRecordService {
|
||||
@Inject
|
||||
private MapperFactory mapperFactory;
|
||||
@Inject
|
||||
@Db
|
||||
private UserLoginRecordMapper userLoginRecordMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
|
||||
public PageInfo<UserLoginRecordListRes> page(PageQuery pageQuery, UserLoginRecordListReq req) {
|
||||
|
||||
+11
-13
@@ -22,6 +22,7 @@
|
||||
package fun.asgc.neutrino.proxy.server.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import fun.asgc.neutrino.core.util.DateUtil;
|
||||
@@ -67,7 +68,7 @@ public class UserService {
|
||||
private UserTokenMapper userTokenMapper;
|
||||
@Db
|
||||
private UserLoginRecordMapper userLoginRecordMapper;
|
||||
@Db
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
|
||||
public LoginRes login(LoginReq req) {
|
||||
@@ -111,7 +112,7 @@ public class UserService {
|
||||
userTokenMapper.deleteByToken(SystemContextHolder.getToken());
|
||||
|
||||
// 新增用户登录日志
|
||||
userLoginRecordMapper.add(new UserLoginRecordDO()
|
||||
userLoginRecordMapper.insert(new UserLoginRecordDO()
|
||||
.setUserId(SystemContextHolder.getUser().getId())
|
||||
.setIp(SystemContextHolder.getIp())
|
||||
.setToken(SystemContextHolder.getToken())
|
||||
@@ -181,8 +182,6 @@ public class UserService {
|
||||
}
|
||||
|
||||
public UserCreateRes create(UserCreateReq req) {
|
||||
|
||||
|
||||
Date now = new Date();
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setName(req.getName());
|
||||
@@ -191,18 +190,17 @@ public class UserService {
|
||||
userDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
userDO.setCreateTime(now);
|
||||
userDO.setUpdateTime(now);
|
||||
userMapper.add(userDO);
|
||||
|
||||
userMapper.insert(userDO);
|
||||
return new UserCreateRes();
|
||||
}
|
||||
|
||||
public UserUpdateRes update(UserUpdateReq req) {
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setId(req.getId());
|
||||
userDO.setName(req.getName());
|
||||
userDO.setLoginName(req.getLoginName());
|
||||
userDO.setUpdateTime(new Date());
|
||||
userMapper.update(userDO);
|
||||
userMapper.update(null, new LambdaUpdateWrapper<UserDO>()
|
||||
.eq(UserDO::getId, req.getId())
|
||||
.set(UserDO::getName, req.getName())
|
||||
.set(UserDO::getLoginName, req.getLoginName())
|
||||
.set(UserDO::getUpdateTime, new Date())
|
||||
);
|
||||
return new UserUpdateRes();
|
||||
}
|
||||
|
||||
@@ -221,7 +219,7 @@ public class UserService {
|
||||
}
|
||||
|
||||
public void delete(Integer id) {
|
||||
userMapper.delete(id);
|
||||
userMapper.deleteById(id);
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByUserId(id, EnableStatusEnum.DISABLE.getStatus());
|
||||
}
|
||||
|
||||
+5
-4
@@ -46,6 +46,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -67,13 +68,13 @@ public class VisitorChannelService {
|
||||
private NioEventLoopGroup serverWorkerGroup;
|
||||
@Inject
|
||||
private ProxyMutualService proxyMutualService;
|
||||
@Inject
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private PortMappingMapper portMappingMapper;
|
||||
@Inject
|
||||
@Db
|
||||
private PortPoolMapper portPoolMapper;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.ClientConnectRecordMapper">
|
||||
|
||||
<update id="add">
|
||||
insert into client_connect_record(`ip`,`license_id`,`type`, `msg`, `code`, `err`, `create_time`)
|
||||
values(:ip,:licenseId,:type,:msg,:code,:err,:createTime)
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.JobInfoMapper">
|
||||
|
||||
<update id="update">
|
||||
update `job_info`
|
||||
set cron = :cron,desc = :desc,alarm_email=:alarmEmail,alarm_ding=:alarmDing,param=:param,update_time=:updateTime
|
||||
where id =:id
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.LicenseMapper">
|
||||
|
||||
<select id="pageInfo" resultType="fun.asgc.neutrino.proxy.server.controller.res.LicenseListRes">
|
||||
select * from `license`
|
||||
</select>
|
||||
|
||||
<insert id="add">
|
||||
insert into `license`(`name`,`key`,`user_id`,`is_online`,`enable`,`create_time`,`update_time`)
|
||||
values (:name, :key, :userId, :isOnline, :enable, :createTime, :updateTime)
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.PortMappingMapper">
|
||||
|
||||
<insert id="add">
|
||||
insert into `port_mapping`(`license_id`,`server_port`,`client_ip`,`client_port`,`is_online`,`enable`,`create_time`,`update_time`)
|
||||
values (:licenseId, :serverPort, :clientIp, :clientPort, :isOnline, :enable, :createTime, :updateTime)
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update `port_mapping`
|
||||
set license_id = :licenseId,server_port = :serverPort,client_ip=:clientIp,client_port=:clientPort,update_time=:updateTime
|
||||
where id =:id
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.UserReportMapper">
|
||||
|
||||
<select id="userFlowReportPage" resultType="fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes">
|
||||
SELECT
|
||||
u.id AS userId,
|
||||
u.NAME AS userName,
|
||||
IFNULL( SUM( frm.write_bytes ), 0 ) AS historyWriteBytes,
|
||||
IFNULL( SUM( frm.read_bytes ), 0 ) AS historyReadBytes
|
||||
FROM `user` u
|
||||
LEFT JOIN flow_report_month frm ON u.id = frm.user_id
|
||||
GROUP BY u.id
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.UserTokenMapper">
|
||||
|
||||
<insert id = "add">
|
||||
insert into `user_token`(`token`,`user_id`,`expiration_time`,`create_time`,`update_time`)
|
||||
values (:token, :userId, :expirationTime, :createTime, :updateTime)
|
||||
</insert>
|
||||
|
||||
<select id = "findByAvailableToken">
|
||||
select * from user_token where token = ? and expiration_time > ?
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,7 +0,0 @@
|
||||
<!--<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.ClientConnectRecordMapper">-->
|
||||
|
||||
<!-- <update id="add">-->
|
||||
<!-- insert into client_connect_record(`ip`,`license_id`,`type`, `msg`, `code`, `err`, `create_time`)-->
|
||||
<!-- values(:ip,:licenseId,:type,:msg,:code,:err,:createTime)-->
|
||||
<!-- </update>-->
|
||||
<!--</mapper>-->
|
||||
@@ -1,8 +0,0 @@
|
||||
<!--<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.JobInfoMapper">-->
|
||||
|
||||
<!-- <update id="update">-->
|
||||
<!-- update `job_info`-->
|
||||
<!-- set cron = :cron,desc = :desc,alarm_email=:alarmEmail,alarm_ding=:alarmDing,param=:param,update_time=:updateTime-->
|
||||
<!-- where id =:id-->
|
||||
<!-- </update>-->
|
||||
<!--</mapper>-->
|
||||
@@ -1,12 +0,0 @@
|
||||
<!--<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.LicenseMapper">-->
|
||||
|
||||
<!-- <select id="pageInfo" resultType="fun.asgc.neutrino.proxy.server.controller.res.LicenseListRes">-->
|
||||
<!-- select * from `license`-->
|
||||
<!-- </select>-->
|
||||
|
||||
<!-- <insert id="add">-->
|
||||
<!-- insert into `license`(`name`,`key`,`user_id`,`is_online`,`enable`,`create_time`,`update_time`)-->
|
||||
<!-- values (:name, :key, :userId, :isOnline, :enable, :createTime, :updateTime)-->
|
||||
<!-- </insert>-->
|
||||
|
||||
<!--</mapper>-->
|
||||
@@ -1,13 +0,0 @@
|
||||
<!--<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.PortMappingMapper">-->
|
||||
|
||||
<!-- <insert id="add">-->
|
||||
<!-- insert into `port_mapping`(`license_id`,`server_port`,`client_ip`,`client_port`,`is_online`,`enable`,`create_time`,`update_time`)-->
|
||||
<!-- values (:licenseId, :serverPort, :clientIp, :clientPort, :isOnline, :enable, :createTime, :updateTime)-->
|
||||
<!-- </insert>-->
|
||||
|
||||
<!-- <update id="update">-->
|
||||
<!-- update `port_mapping`-->
|
||||
<!-- set license_id = :licenseId,server_port = :serverPort,client_ip=:clientIp,client_port=:clientPort,update_time=:updateTime-->
|
||||
<!-- where id =:id-->
|
||||
<!-- </update>-->
|
||||
<!--</mapper>-->
|
||||
@@ -1,14 +0,0 @@
|
||||
<!--<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.UserReportMapper">-->
|
||||
|
||||
<!-- <select id="userFlowReportPage" resultType="fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes">-->
|
||||
<!-- SELECT-->
|
||||
<!-- u.id AS userId,-->
|
||||
<!-- u.NAME AS userName,-->
|
||||
<!-- IFNULL( SUM( frm.write_bytes ), 0 ) AS historyWriteBytes,-->
|
||||
<!-- IFNULL( SUM( frm.read_bytes ), 0 ) AS historyReadBytes-->
|
||||
<!-- FROM `user` u-->
|
||||
<!-- LEFT JOIN flow_report_month frm ON u.id = frm.user_id-->
|
||||
<!-- GROUP BY u.id-->
|
||||
<!-- </select>-->
|
||||
|
||||
<!--</mapper>-->
|
||||
@@ -1,12 +0,0 @@
|
||||
<!--<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.UserTokenMapper">-->
|
||||
|
||||
<!-- <insert id = "add">-->
|
||||
<!-- insert into `user_token`(`token`,`user_id`,`expiration_time`,`create_time`,`update_time`)-->
|
||||
<!-- values (:token, :userId, :expirationTime, :createTime, :updateTime)-->
|
||||
<!-- </insert>-->
|
||||
|
||||
<!-- <select id = "findByAvailableToken">-->
|
||||
<!-- select * from user_token where token = ? and expiration_time > ?-->
|
||||
<!-- </select>-->
|
||||
|
||||
<!--</mapper>-->
|
||||
Reference in New Issue
Block a user