Compare commits
19 Commits
base-1.2.3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 5714438fbf | |||
| e0c6c5afce | |||
| 6de131f358 | |||
| f6a51546ec | |||
| 66b58f624a | |||
| 27c48ca0dc | |||
| a9bdf4ce61 | |||
| 62ae719a72 | |||
| 0dec46a3c4 | |||
| 970459a733 | |||
| f4e6f492d7 | |||
| 5daf13eefe | |||
| 622e4cbbe5 | |||
| 51e53aeb0b | |||
| 58709fdc53 | |||
| 0e9da0de20 | |||
| 337cc6b8f2 | |||
| dd60a99f45 | |||
| 583b5864d5 |
224
EasyCodeConfig.json
Normal file
224
EasyCodeConfig.json
Normal file
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>hcframe-base</artifactId>
|
<artifactId>hcframe-base</artifactId>
|
||||||
<version>1.2.3-SNAPSHOT</version>
|
<version>1.2.4-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
@@ -48,6 +48,13 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.highgo/HgdbJdbc -->
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.highgo/HgdbJdbc -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.highgo</groupId>
|
||||||
|
<artifactId>HgdbJdbc</artifactId>
|
||||||
|
<version>6.2.3</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-api</artifactId>
|
<artifactId>log4j-api</artifactId>
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
package com.taixingyiji.base.common;
|
package com.taixingyiji.base.common;
|
||||||
|
|
||||||
|
import com.taixingyiji.base.module.cache.impl.DatasourceCache;
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
import org.apache.shiro.authz.AuthorizationException;
|
import org.apache.shiro.authz.AuthorizationException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* @description 异常信息拦截类,如果程序运行过程中抛出异常,会将异常拦截下来,并返回前端一个包含异常信息的Json数据
|
* @description 异常信息拦截类,如果程序运行过程中抛出异常,会将异常拦截下来,并返回前端一个包含异常信息的Json数据
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class ControllerExceptionHandler {
|
public class ControllerExceptionHandler {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(ControllerExceptionHandler.class);
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@@ -23,9 +30,13 @@ public class ControllerExceptionHandler {
|
|||||||
return ResultVO.getFailed("用户名或密码错误");
|
return ResultVO.getFailed("用户名或密码错误");
|
||||||
} else if (e instanceof RuntimeException) {
|
} else if (e instanceof RuntimeException) {
|
||||||
System.out.println("handleServiceException");
|
System.out.println("handleServiceException");
|
||||||
e.printStackTrace();
|
logger.error(e.getMessage(),e);
|
||||||
//封装错误信息
|
//封装错误信息
|
||||||
return ResultVO.getException(e);
|
return ResultVO.getException(e);
|
||||||
|
} else if(e instanceof MethodArgumentNotValidException){
|
||||||
|
String defaultMessage = Objects.requireNonNull(((MethodArgumentNotValidException) e).getBindingResult().getFieldError()).getDefaultMessage();
|
||||||
|
logger.error("请求参数验证异常:", e);
|
||||||
|
return ResultVO.getFailed(defaultMessage);
|
||||||
}else {
|
}else {
|
||||||
return ResultVO.getException(e);
|
return ResultVO.getException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class UserInfoUtil<T> {
|
|||||||
if (date.getTime() > expireData.getTime()) {
|
if (date.getTime() > expireData.getTime()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (T) shiroService.findByUserId(ftToken.getUserId());
|
return (T) shiroService.findByUserId(String.valueOf(ftToken.getUserId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public class QueryConstants {
|
|||||||
public static final int GT = 6;
|
public static final int GT = 6;
|
||||||
public static final int LTE = 7;
|
public static final int LTE = 7;
|
||||||
public static final int GTE = 8;
|
public static final int GTE = 8;
|
||||||
|
public static final int RIGHT_LIKE = 9;
|
||||||
|
public static final int LEFT_LIKE = 10;
|
||||||
|
|
||||||
public static final String QUERY = "query";
|
public static final String QUERY = "query";
|
||||||
public static final String JOIN = "join";
|
public static final String JOIN = "join";
|
||||||
|
|||||||
@@ -42,12 +42,17 @@ public interface TableMapper {
|
|||||||
List<Map<String, Object>> getListNoPage(@Param("typeName") String tableName, @Param("info") Map<String, Object> map);
|
List<Map<String, Object>> getListNoPage(@Param("typeName") String tableName, @Param("info") Map<String, Object> map);
|
||||||
|
|
||||||
Object getSequence(@Param("tableName") String tableName);
|
Object getSequence(@Param("tableName") String tableName);
|
||||||
|
Object getHighGoSequence(@Param("tableName") String tableName);
|
||||||
|
boolean judgeHighGoSequenceExist(@Param("tableName") String tableName);
|
||||||
|
int judgeDamengSequenceExist(@Param("tableName") String tableName,@Param("schema")String schema);
|
||||||
int createSequence(@Param("tableName") String tableName, @Param("lastId")Object lastId);
|
int createSequence(@Param("tableName") String tableName, @Param("lastId")Object lastId);
|
||||||
|
int createHighGoSequence(@Param("tableName") String tableName, @Param("lastId")Object lastId);
|
||||||
|
|
||||||
Long count(@Param("tableName")String tableName,@Param("sql")String sql);
|
Long count(@Param("tableName")String tableName,@Param("sql")String sql);
|
||||||
|
|
||||||
Long countBySql(@Param("sql") String sql);
|
Long countBySql(@Param("sql") String sql);
|
||||||
int insertBatch(@Param("list") List<Map<String, Object>> list, @Param("tableName") String tableName);
|
int insertBatch(@Param("list") List<Map<String, Object>> list, @Param("tableName") String tableName);
|
||||||
|
int insertBatchSeq(@Param("list") List<Map<String, Object>> list, @Param("tableName") String tableName,@Param("pkName")String pkName);
|
||||||
|
|
||||||
int updateBatchByPk(@Param("sql")String sql);
|
int updateBatchByPk(@Param("sql")String sql);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
|||||||
public interface BaseMapper {
|
public interface BaseMapper {
|
||||||
|
|
||||||
<E> int save(DataMap<E> dataMap);
|
<E> int save(DataMap<E> dataMap);
|
||||||
|
String getDataConfig();
|
||||||
int save(String tableName, String pkName, Map<String, Object> data);
|
int save(String tableName, String pkName, Map<String, Object> data);
|
||||||
|
|
||||||
<E> int save(E e);
|
<E> int save(E e);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.taixingyiji.base.module.data.module;
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.taixingyiji.base.common.ServiceException;
|
import com.taixingyiji.base.common.ServiceException;
|
||||||
import com.taixingyiji.base.common.WebPageInfo;
|
import com.taixingyiji.base.common.WebPageInfo;
|
||||||
@@ -17,10 +18,9 @@ import org.mybatis.spring.SqlSessionTemplate;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.sql.Connection;
|
||||||
import java.util.HashMap;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service("base")
|
@Service("base")
|
||||||
public class BaseMapperImpl implements BaseMapper {
|
public class BaseMapperImpl implements BaseMapper {
|
||||||
@@ -28,24 +28,48 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
public static final String BASE = "base";
|
public static final String BASE = "base";
|
||||||
public static final String TABLE_MAPPER_PACKAGE = "com.taixingyiji.base.module.data.dao.TableMapper.";
|
public static final String TABLE_MAPPER_PACKAGE = "com.taixingyiji.base.module.data.dao.TableMapper.";
|
||||||
final TableMapper tableMapper;
|
final TableMapper tableMapper;
|
||||||
|
final DruidDataSource druidDataSource;
|
||||||
|
|
||||||
@Value("${spring.datasource.druid.driver-class-name}")
|
@Value("${spring.datasource.druid.driver-class-name}")
|
||||||
public String dataType;
|
public String dataType;
|
||||||
final SqlSessionTemplate sqlSessionTemplate;
|
final SqlSessionTemplate sqlSessionTemplate;
|
||||||
|
|
||||||
public BaseMapperImpl(TableMapper tableMapper, SqlSessionTemplate sqlSessionTemplate) {
|
public BaseMapperImpl(TableMapper tableMapper, SqlSessionTemplate sqlSessionTemplate,
|
||||||
|
DruidDataSource druidDataSource) {
|
||||||
this.tableMapper = tableMapper;
|
this.tableMapper = tableMapper;
|
||||||
this.sqlSessionTemplate = sqlSessionTemplate;
|
this.sqlSessionTemplate = sqlSessionTemplate;
|
||||||
|
this.druidDataSource = druidDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> int save(DataMap<E> dataMap) {
|
public String getDataConfig() {
|
||||||
String key;
|
String key;
|
||||||
DatasourceConfig datasourceConfig = new DatasourceConfig();
|
DatasourceConfig datasourceConfig = new DatasourceConfig();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
key = DBContextHolder.getDataSource();
|
key = DBContextHolder.getDataSource();
|
||||||
datasourceConfig = DataSourceUtil.get(key);
|
datasourceConfig = DataSourceUtil.get(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
Connection connection = druidDataSource.getConnection();
|
||||||
|
String dbType = connection.getMetaData().getDatabaseProductName();
|
||||||
|
if (dbType.contains("Oracle")) {
|
||||||
|
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
||||||
|
}
|
||||||
|
if (dbType.contains("MySQL")) {
|
||||||
|
datasourceConfig.setCommonType(DataUnit.MYSQL);
|
||||||
|
}
|
||||||
|
if (dbType.contains("DM")) {
|
||||||
|
datasourceConfig.setCommonType(DataUnit.DAMENG);
|
||||||
|
}
|
||||||
|
if (dbType.contains("SQLite")) {
|
||||||
|
datasourceConfig.setCommonType(DataUnit.SQLITE);
|
||||||
|
}
|
||||||
|
if (dbType.contains("PostgreSQL")) {
|
||||||
|
datasourceConfig.setCommonType(DataUnit.HANGO);
|
||||||
|
}
|
||||||
|
connection.close();
|
||||||
|
} catch (Exception e1) {
|
||||||
if (dataType.contains("oracle")) {
|
if (dataType.contains("oracle")) {
|
||||||
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
||||||
}
|
}
|
||||||
@@ -58,14 +82,27 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
if (dataType.contains("sqlite")) {
|
if (dataType.contains("sqlite")) {
|
||||||
datasourceConfig.setCommonType(DataUnit.SQLITE);
|
datasourceConfig.setCommonType(DataUnit.SQLITE);
|
||||||
}
|
}
|
||||||
|
if (dataType.contains("highgo")) {
|
||||||
|
datasourceConfig.setCommonType(DataUnit.HANGO);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return datasourceConfig.getCommonType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> int save(DataMap<E> dataMap) {
|
||||||
|
String dataTypeConfig = getDataConfig();
|
||||||
JudgesNull(dataMap.getData(), "data can not be null!");
|
JudgesNull(dataMap.getData(), "data can not be null!");
|
||||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
|
if (DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||||
|
dataMap.getData().putAll(formatMap(dataMap.getData(),dataMap.getTableName()));
|
||||||
|
}
|
||||||
if (StringUtils.isEmpty(dataMap.getPkName())) {
|
if (StringUtils.isEmpty(dataMap.getPkName())) {
|
||||||
dataMap.setPkName("ID");
|
dataMap.setPkName("ID");
|
||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
if (DataUnit.ORACLE.equals(datasourceConfig.getCommonType()) || DataUnit.DAMENG.equals(datasourceConfig.getCommonType())) {
|
if (DataUnit.ORACLE.equals(dataTypeConfig) || DataUnit.DAMENG.equals(dataTypeConfig) || DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||||
if (org.springframework.util.StringUtils.isEmpty(dataMap.get(dataMap.getPkName()))) {
|
if (org.springframework.util.StringUtils.isEmpty(dataMap.get(dataMap.getPkName()))) {
|
||||||
Object id = getSequence(dataMap.getTableName(), dataMap.getPkName());
|
Object id = getSequence(dataMap.getTableName(), dataMap.getPkName());
|
||||||
dataMap.toBuilder().add(dataMap.getPkName(), id);
|
dataMap.toBuilder().add(dataMap.getPkName(), id);
|
||||||
@@ -82,34 +119,37 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> formatMap(Map<String, Object> data, String tableName) {
|
||||||
|
return getStringObjectMapForHighGo(tableName, data, getDataConfig());
|
||||||
|
// // 遍历 Map 并转换值
|
||||||
|
// for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||||
|
// Object value = entry.getValue();
|
||||||
|
// if (value instanceof String) {
|
||||||
|
// String strValue = (String) value;
|
||||||
|
// if (strValue.matches("-?\\d+")) { // 匹配整数
|
||||||
|
// data.put(entry.getKey(), Long.parseLong(strValue));
|
||||||
|
// } else if (strValue.matches("-?\\d*\\.\\d+")) { // 匹配浮点数
|
||||||
|
// data.put(entry.getKey(), (long) Double.parseDouble(strValue));
|
||||||
|
// }
|
||||||
|
// } else if (value instanceof Number) {
|
||||||
|
// data.put(entry.getKey(), ((Number) value).longValue());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int save(String tableName, String pkName, Map<String, Object> data) {
|
public int save(String tableName, String pkName, Map<String, Object> data) {
|
||||||
JudgesNull(tableName, "data can not be null!");
|
JudgesNull(tableName, "data can not be null!");
|
||||||
JudgesNull(data, "tableName can not be null!");
|
JudgesNull(data, "tableName can not be null!");
|
||||||
String key;
|
String dataTypeConfig = getDataConfig();
|
||||||
DatasourceConfig datasourceConfig = new DatasourceConfig();
|
if (DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||||
try {
|
data.putAll(formatMap(data, tableName));
|
||||||
key = DBContextHolder.getDataSource();
|
|
||||||
datasourceConfig = DataSourceUtil.get(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (dataType.contains("oracle")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
|
||||||
}
|
|
||||||
if (dataType.contains("mysql")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.MYSQL);
|
|
||||||
}
|
|
||||||
if (dataType.contains("DmDriver")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.DAMENG);
|
|
||||||
}
|
|
||||||
if (dataType.contains("sqlite")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.SQLITE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(pkName)) {
|
if (StringUtils.isEmpty(pkName)) {
|
||||||
pkName = "ID";
|
pkName = "ID";
|
||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
if (datasourceConfig.getCommonType().equals(DataUnit.ORACLE) || datasourceConfig.getCommonType().equals(DataUnit.DAMENG)) {
|
if (DataUnit.ORACLE.equals(dataTypeConfig) || DataUnit.DAMENG.equals(dataTypeConfig) || DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||||
if (org.springframework.util.StringUtils.isEmpty(data.get(pkName))) {
|
if (org.springframework.util.StringUtils.isEmpty(data.get(pkName))) {
|
||||||
data.put(pkName, getSequence(tableName, pkName));
|
data.put(pkName, getSequence(tableName, pkName));
|
||||||
}
|
}
|
||||||
@@ -133,12 +173,26 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
private int updateByWhere(Condition condition, String tableName, Map<String, Object> data) {
|
private int updateByWhere(Condition condition, String tableName, Map<String, Object> data) {
|
||||||
Map<String, Object> params = condition.getParamMap();
|
Map<String, Object> params = condition.getParamMap();
|
||||||
params.put("tableName", tableName);
|
params.put("tableName", tableName);
|
||||||
|
String dataTypeConfig = getDataConfig();
|
||||||
|
data.putAll(formatMap(data,tableName));
|
||||||
params.put("info", data);
|
params.put("info", data);
|
||||||
params.put("sql", condition.getSql());
|
params.put("sql", condition.getSql());
|
||||||
int i = sqlSessionTemplate.update(TABLE_MAPPER_PACKAGE + "updateByWhere", params);
|
int i = sqlSessionTemplate.update(TABLE_MAPPER_PACKAGE + "updateByWhere", params);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> getStringObjectMapForHighGo(String tableName, Map<String, Object> data, String dataTypeConfig) {
|
||||||
|
if (DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||||
|
// 获取数据库字段类型
|
||||||
|
Map<String, String> columnTypes = TableMetadataCache.getColumnTypesFromCache(tableName.toLowerCase());
|
||||||
|
if(columnTypes!=null){
|
||||||
|
// 自动转换数据类型
|
||||||
|
data = DataTypeConverter.convertDataTypes(data, columnTypes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> int updateByPk(DataMap<E> dataMap) {
|
public <E> int updateByPk(DataMap<E> dataMap) {
|
||||||
JudgesNull(dataMap.getData(), "data can not be null!");
|
JudgesNull(dataMap.getData(), "data can not be null!");
|
||||||
@@ -333,14 +387,16 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
return tableMapper.useSql(SelectCondition.builder().tableName(tableName).build().getSql());
|
return tableMapper.useSql(SelectCondition.builder().tableName(tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Map<String, Object>> selectList(Condition condition) {
|
private List<Map<String, Object>> selectList(Condition condition, String tableName) {
|
||||||
Map<String, Object> params = condition.getParamMap();
|
Map<String, Object> params = condition.getParamMap();
|
||||||
|
String dataTypeConfig = getDataConfig();
|
||||||
params.put("sql", condition.getSql());
|
params.put("sql", condition.getSql());
|
||||||
return sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params);
|
return sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> selectOne(Condition condition) {
|
private Map<String, Object> selectOne(Condition condition, String tableName) {
|
||||||
Map<String, Object> params = condition.getParamMap();
|
Map<String, Object> params = condition.getParamMap();
|
||||||
|
String dataTypeConfig = getDataConfig();
|
||||||
params.put("sql", condition.getSql());
|
params.put("sql", condition.getSql());
|
||||||
return sqlSessionTemplate.selectOne(TABLE_MAPPER_PACKAGE + "userSqlByOne", params);
|
return sqlSessionTemplate.selectOne(TABLE_MAPPER_PACKAGE + "userSqlByOne", params);
|
||||||
}
|
}
|
||||||
@@ -349,14 +405,14 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
public <E> List<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
public <E> List<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
||||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
Condition condition = equal(dataMap, map);
|
Condition condition = equal(dataMap, map);
|
||||||
return selectList(condition);
|
return selectList(condition, dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> selectByEqual(String tableName, Map<String, Object> map) {
|
public List<Map<String, Object>> selectByEqual(String tableName, Map<String, Object> map) {
|
||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
Condition condition = equal(DataMap.builder().tableName(tableName).build(), map);
|
Condition condition = equal(DataMap.builder().tableName(tableName).build(), map);
|
||||||
return selectList(condition);
|
return selectList(condition, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -378,10 +434,10 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
Condition condition = equal(dataMap, map);
|
Condition condition = equal(dataMap, map);
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(condition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(condition, dataMap.getTableName()));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition, dataMap.getTableName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -389,17 +445,17 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
Condition condition = equal(DataMap.builder().tableName(tableName).build(), map);
|
Condition condition = equal(DataMap.builder().tableName(tableName).build(), map);
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(condition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(condition, tableName));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition, tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> Map<String, Object> selectOneByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
public <E> Map<String, Object> selectOneByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
||||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
Condition condition = equal(dataMap, map);
|
Condition condition = equal(dataMap, map);
|
||||||
return selectOne(condition);
|
return selectOne(condition, dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -409,7 +465,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
JudgesNull(dataMap.getPkValue(), "pkValue can not be null!");
|
JudgesNull(dataMap.getPkValue(), "pkValue can not be null!");
|
||||||
Condition condition = Condition.creatCriteria(dataMap).build();
|
Condition condition = Condition.creatCriteria(dataMap).build();
|
||||||
condition = condition.toCreatCriteria().andEqual(dataMap.getPkName(), dataMap.getPkValue()).build();
|
condition = condition.toCreatCriteria().andEqual(dataMap.getPkName(), dataMap.getPkValue()).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition, dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -419,7 +475,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
JudgesNull(pkValue, "pkValue can not be null!");
|
JudgesNull(pkValue, "pkValue can not be null!");
|
||||||
Condition condition = Condition.creatCriteria(DataMap.builder().sysOsTable(osSysTable).pkValue(pkValue).build()).build();
|
Condition condition = Condition.creatCriteria(DataMap.builder().sysOsTable(osSysTable).pkValue(pkValue).build()).build();
|
||||||
condition = condition.toCreatCriteria().andEqual(osSysTable.getTablePk(), pkValue).build();
|
condition = condition.toCreatCriteria().andEqual(osSysTable.getTablePk(), pkValue).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition, osSysTable.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -429,26 +485,27 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
JudgesNull(pkValue, "pkValue can not be null!");
|
JudgesNull(pkValue, "pkValue can not be null!");
|
||||||
Condition condition = Condition.creatCriteria(DataMap.builder().tableName(tableName).pkName(pkName).pkValue(pkValue).build()).build();
|
Condition condition = Condition.creatCriteria(DataMap.builder().tableName(tableName).pkName(pkName).pkValue(pkValue).build()).build();
|
||||||
condition = condition.toCreatCriteria().andEqual(pkName, pkValue).build();
|
condition = condition.toCreatCriteria().andEqual(pkName, pkValue).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> selectByCondition(Condition condition) {
|
public List<Map<String, Object>> selectByCondition(Condition condition) {
|
||||||
return selectList(condition);
|
JudgesNull(condition.getSelectCondition(), "tableName can not be null!");
|
||||||
|
return selectList(condition,condition.getSelectCondition().getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> List<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition) {
|
public <E> List<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition) {
|
||||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
condition = condition.toCreatCriteria(dataMap).build();
|
condition = condition.toCreatCriteria(dataMap).build();
|
||||||
return selectList(condition);
|
return selectList(condition,dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> selectByCondition(String tableName, Condition condition) {
|
public List<Map<String, Object>> selectByCondition(String tableName, Condition condition) {
|
||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
||||||
return selectList(condition);
|
return selectList(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -457,7 +514,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
condition = condition
|
condition = condition
|
||||||
.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build())
|
.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build())
|
||||||
.build();
|
.build();
|
||||||
return selectList(condition);
|
return selectList(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -466,16 +523,16 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
condition = condition
|
condition = condition
|
||||||
.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build())
|
.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build())
|
||||||
.build();
|
.build();
|
||||||
return selectList(condition);
|
return selectList(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<Map<String, Object>> selectByCondition(Condition condition, WebPageInfo webPageInfo) {
|
public PageInfo<Map<String, Object>> selectByCondition(Condition condition, WebPageInfo webPageInfo) {
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(condition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(condition,condition.getSelectCondition().getTableName()));
|
||||||
}
|
}
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition,condition.getSelectCondition().getTableName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -484,10 +541,10 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
condition = condition.toCreatCriteria(dataMap).build();
|
condition = condition.toCreatCriteria(dataMap).build();
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
Condition finalCondition = condition;
|
Condition finalCondition = condition;
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,dataMap.getTableName()));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition,dataMap.getTableName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -496,10 +553,10 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
Condition finalCondition = condition;
|
Condition finalCondition = condition;
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,tableName));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition,tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -508,10 +565,10 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build()).build();
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
Condition finalCondition = condition;
|
Condition finalCondition = condition;
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,tableName));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition,tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -520,43 +577,43 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build()).build();
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
Condition finalCondition = condition;
|
Condition finalCondition = condition;
|
||||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,tableName));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(selectList(condition));
|
return new PageInfo<>(selectList(condition,tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> Map<String, Object> selectOneByCondition(DataMap<E> dataMap, Condition condition) {
|
public <E> Map<String, Object> selectOneByCondition(DataMap<E> dataMap, Condition condition) {
|
||||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
condition = condition.toCreatCriteria(dataMap).build();
|
condition = condition.toCreatCriteria(dataMap).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition,dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> selectOneByCondition(String tableName, Condition condition) {
|
public Map<String, Object> selectOneByCondition(String tableName, Condition condition) {
|
||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> selectOneByCondition(String tableName, List<String> fieldList, Condition condition) {
|
public Map<String, Object> selectOneByCondition(String tableName, List<String> fieldList, Condition condition) {
|
||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build()).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> selectOneByCondition(String tableName, String fieldList, Condition condition) {
|
public Map<String, Object> selectOneByCondition(String tableName, String fieldList, Condition condition) {
|
||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build()).build();
|
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build()).build();
|
||||||
return selectOne(condition);
|
return selectOne(condition,tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> selectOneByCondition(Condition condition) {
|
public Map<String, Object> selectOneByCondition(Condition condition) {
|
||||||
return selectOne(condition);
|
return selectOne(condition,condition.getSelectCondition().getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -565,18 +622,17 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
SelectCondition selectJoinBuilder = SelectCondition
|
SelectCondition selectJoinBuilder = SelectCondition
|
||||||
.joinBuilder(tableName)
|
.joinBuilder(tableName)
|
||||||
.join(joinCondition).build();
|
.join(joinCondition).build();
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> selectJoinByCondition(String tableName, List<JoinCondition> joinCondition, Condition condition) {
|
public List<Map<String, Object>> selectJoinByCondition(String tableName, List<JoinCondition> joinCondition, Condition condition) {
|
||||||
JudgesNull(tableName, "tableName can not be null!");
|
JudgesNull(tableName, "tableName can not be null!");
|
||||||
SelectCondition selectJoinBuilder = SelectCondition
|
SelectCondition selectJoinBuilder = SelectCondition
|
||||||
.joinBuilder(tableName)
|
.joinBuilder(tableName)
|
||||||
.join(joinCondition).build();
|
.join(joinCondition).build();
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -585,7 +641,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
SelectCondition selectJoinBuilder = SelectCondition
|
SelectCondition selectJoinBuilder = SelectCondition
|
||||||
.joinBuilder(tableName)
|
.joinBuilder(tableName)
|
||||||
.leftJoin(joinCondition).build();
|
.leftJoin(joinCondition).build();
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -594,7 +650,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
SelectCondition selectJoinBuilder = SelectCondition
|
SelectCondition selectJoinBuilder = SelectCondition
|
||||||
.joinBuilder(tableName)
|
.joinBuilder(tableName)
|
||||||
.leftJoin(joinCondition).build();
|
.leftJoin(joinCondition).build();
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -603,7 +659,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
SelectCondition selectJoinBuilder = SelectCondition
|
SelectCondition selectJoinBuilder = SelectCondition
|
||||||
.joinBuilder(tableName)
|
.joinBuilder(tableName)
|
||||||
.rightJoin(joinCondition).build();
|
.rightJoin(joinCondition).build();
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -612,12 +668,12 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
SelectCondition selectJoinBuilder = SelectCondition
|
SelectCondition selectJoinBuilder = SelectCondition
|
||||||
.joinBuilder(tableName)
|
.joinBuilder(tableName)
|
||||||
.rightJoin(joinCondition).build();
|
.rightJoin(joinCondition).build();
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> selectionByCondition(SelectCondition selectCondition, Condition condition) {
|
public List<Map<String, Object>> selectionByCondition(SelectCondition selectCondition, Condition condition) {
|
||||||
return tableMapper.useSql(condition.toCreatCriteria(selectCondition).build().getSql());
|
return tableMapper.useSql(condition.toCreatCriteria(selectCondition,selectCondition.getTableName()).build().getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -640,11 +696,14 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
return sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params);
|
return sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<Map<String, Object>> selectSqlByPage(String sql, Map<String, Object> params, WebPageInfo webPageInfo) {
|
public PageInfo<Map<String, Object>> selectSqlByPage(String sql, Map<String, Object> params, WebPageInfo webPageInfo) {
|
||||||
|
String dataTypeConfig = getDataConfig();
|
||||||
params.put("sql", sql);
|
params.put("sql", sql);
|
||||||
if (webPageInfo.isEnableCache()) {
|
if (webPageInfo.isEnableCache()) {
|
||||||
return MyPageHelper.start(webPageInfo,sql,() -> sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params));
|
Map<String, Object> finalParams = params;
|
||||||
|
return MyPageHelper.start(webPageInfo, sql, () -> sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", finalParams));
|
||||||
}
|
}
|
||||||
MyPageHelper.start(webPageInfo);
|
MyPageHelper.start(webPageInfo);
|
||||||
return new PageInfo<>(sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params));
|
return new PageInfo<>(sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params));
|
||||||
@@ -666,7 +725,7 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
String sql = condition.getSql();
|
String sql = condition.getSql();
|
||||||
sql = "SELECT count(0) as COUNT FROM " + tableName + " " + sql;
|
sql = "SELECT count(0) as COUNT FROM " + tableName + " " + sql;
|
||||||
condition.setSql(sql);
|
condition.setSql(sql);
|
||||||
Map<String,Object> map = selectOne(condition);
|
Map<String, Object> map = selectOne(condition, tableName);
|
||||||
return Long.parseLong(String.valueOf(map.get("COUNT")));
|
return Long.parseLong(String.valueOf(map.get("COUNT")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,36 +742,41 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
throw new ServiceException("list can not empty");
|
throw new ServiceException("list can not empty");
|
||||||
}
|
}
|
||||||
// JudgesNull(data, "tableName can not be null!");
|
// JudgesNull(data, "tableName can not be null!");
|
||||||
String key;
|
String dataTypeConfig = getDataConfig();
|
||||||
DatasourceConfig datasourceConfig = new DatasourceConfig();
|
|
||||||
try {
|
|
||||||
key = DBContextHolder.getDataSource();
|
|
||||||
datasourceConfig = DataSourceUtil.get(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (dataType.contains("oracle")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
|
||||||
}
|
|
||||||
if (dataType.contains("mysql")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.MYSQL);
|
|
||||||
}
|
|
||||||
if (dataType.contains("DmDriver")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.DAMENG);
|
|
||||||
}
|
|
||||||
if (dataType.contains("sqlite")) {
|
|
||||||
datasourceConfig.setCommonType(DataUnit.SQLITE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isEmpty(pkName)) {
|
if (StringUtils.isEmpty(pkName)) {
|
||||||
pkName = "ID";
|
pkName = "ID";
|
||||||
}
|
}
|
||||||
|
int i;
|
||||||
if (datasourceConfig.getCommonType().equals(DataUnit.ORACLE) || datasourceConfig.getCommonType().equals(DataUnit.DAMENG)) {
|
if (dataTypeConfig.equals(DataUnit.ORACLE)) {
|
||||||
for (Map<String, Object> map : list) {
|
for (Map<String, Object> map : list) {
|
||||||
Object id = getSequence(tableName, pkName);
|
Object id = getSequence(tableName, pkName);
|
||||||
map.put(pkName, id);
|
map.put(pkName, id);
|
||||||
}
|
}
|
||||||
|
i = tableMapper.insertBatch(list, tableName);
|
||||||
|
}else if(dataTypeConfig.equals(DataUnit.DAMENG)){
|
||||||
|
getSequence(tableName, pkName);
|
||||||
|
List<Map<String,Object>> tempList = new ArrayList<>();
|
||||||
|
for (Map<String, Object> map : list) {
|
||||||
|
map = formatMap(map,tableName);
|
||||||
|
map.put(pkName, tableName + "_SEQ.nextval");
|
||||||
|
tempList.add(map);
|
||||||
|
}
|
||||||
|
list = tempList;
|
||||||
|
i = tableMapper.insertBatchSeq(list, tableName, pkName);
|
||||||
|
} else if (dataTypeConfig.equals(DataUnit.HANGO)) {
|
||||||
|
getSequence(tableName, pkName);
|
||||||
|
List<Map<String,Object>> tempList = new ArrayList<>();
|
||||||
|
for (Map<String, Object> map : list) {
|
||||||
|
map = formatMap(map,tableName);
|
||||||
|
map.put(pkName, "nextval('" + tableName.toLowerCase() + "_seq')");
|
||||||
|
tempList.add(map);
|
||||||
|
}
|
||||||
|
list = tempList;
|
||||||
|
i = tableMapper.insertBatchSeq(list, tableName, pkName);
|
||||||
|
} else {
|
||||||
|
i = tableMapper.insertBatch(list, tableName);
|
||||||
|
|
||||||
}
|
}
|
||||||
int i = tableMapper.insertBatch(list, tableName);
|
|
||||||
SqlException.base(i, "保存失败");
|
SqlException.base(i, "保存失败");
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -765,14 +829,29 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object getSequence(String tableName, String pkName) {
|
public Object getSequence(String tableName, String pkName) {
|
||||||
|
String dataTypeConfig = getDataConfig();
|
||||||
Object id;
|
Object id;
|
||||||
|
if (DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||||
|
if (!tableMapper.judgeHighGoSequenceExist(tableName.toLowerCase())) {
|
||||||
|
Map<String, Object> map = selectRecentData(tableName, pkName);
|
||||||
|
if (map == null) {
|
||||||
|
tableMapper.createHighGoSequence(tableName.toLowerCase(), 1);
|
||||||
|
} else {
|
||||||
|
tableMapper.createHighGoSequence(tableName.toLowerCase(), map.get(pkName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id = tableMapper.getHighGoSequence(tableName.toLowerCase());
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
|
String url = druidDataSource.getUrl();
|
||||||
|
String schema = getSchemaFromJdbcUrl(url);
|
||||||
|
if (tableMapper.judgeDamengSequenceExist(tableName, schema) > 0) {
|
||||||
id = tableMapper.getSequence(tableName);
|
id = tableMapper.getSequence(tableName);
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("序列不存在");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MyPageHelper.start(WebPageInfo.builder().pageNum(1).pageSize(1).order(WebPageInfo.DESC).sortField(pkName).build());
|
Map<String, Object> map = selectRecentData(tableName, pkName);
|
||||||
DataMap<Object> dataMap = DataMap.builder().tableName(tableName).pkName(pkName).fields(pkName).build();
|
|
||||||
Condition condition = Condition.creatCriteria(dataMap).build();
|
|
||||||
Map<String, Object> map = selectOneByCondition(condition);
|
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
tableMapper.createSequence(tableName, 1);
|
tableMapper.createSequence(tableName, 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -780,6 +859,34 @@ public class BaseMapperImpl implements BaseMapper {
|
|||||||
}
|
}
|
||||||
id = tableMapper.getSequence(tableName);
|
id = tableMapper.getSequence(tableName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Long.parseLong(id.toString()) + 1L;
|
return Long.parseLong(id.toString()) + 1L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> selectRecentData(String tableName, String pkName) {
|
||||||
|
MyPageHelper.noCount(WebPageInfo.builder().pageNum(1).pageSize(1).order(WebPageInfo.DESC).sortField(pkName).build());
|
||||||
|
DataMap<Object> dataMap = DataMap.builder().tableName(tableName).pkName(pkName).fields(pkName).build();
|
||||||
|
Condition condition = Condition.creatCriteria(dataMap).build();
|
||||||
|
return selectOneByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSchemaFromJdbcUrl(String url) {
|
||||||
|
if (url == null || !url.contains("?")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] parts = url.split("\\?");
|
||||||
|
if (parts.length < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] params = parts[1].split("&");
|
||||||
|
for (String param : params) {
|
||||||
|
if (param.toLowerCase().startsWith("schema=")) {
|
||||||
|
return param.substring("schema=".length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,22 +118,26 @@ public class Condition implements Serializable {
|
|||||||
return new ConditionBuilder();
|
return new ConditionBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConditionBuilder creatCriteria(SelectCondition selectCondition) {
|
public static ConditionBuilder creatCriteria(String tableName) {
|
||||||
return new ConditionBuilder(selectCondition,new HashMap<>());
|
return new ConditionBuilder(tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConditionBuilder creatCriteria(SelectCondition selectCondition, boolean flag) {
|
public static ConditionBuilder creatCriteria(SelectCondition selectCondition, String tableName) {
|
||||||
return new ConditionBuilder(selectCondition, flag);
|
return new ConditionBuilder(selectCondition, new HashMap<>(), tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConditionBuilder creatCriteria(SelectCondition selectCondition, boolean flag, String tableName) {
|
||||||
|
return new ConditionBuilder(selectCondition, flag, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConditionBuilder creatCriteria(DataMap dataMap) {
|
public static ConditionBuilder creatCriteria(DataMap dataMap) {
|
||||||
JudesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
return new ConditionBuilder(dataMap.getSelectCondition(),new HashMap<>());
|
return new ConditionBuilder(dataMap.getSelectCondition(), new HashMap<>(), dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConditionBuilder creatCriteria(DataMap dataMap, boolean flag) {
|
public static ConditionBuilder creatCriteria(DataMap dataMap, boolean flag) {
|
||||||
JudesNull(dataMap.getTableName(), "tableName can not be null!");
|
JudesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||||
return new ConditionBuilder(dataMap.getSelectCondition(), flag);
|
return new ConditionBuilder(dataMap.getSelectCondition(), flag, dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,12 +154,12 @@ public class Condition implements Serializable {
|
|||||||
return new ConditionBuilder(this.sql, this.paramMap);
|
return new ConditionBuilder(this.sql, this.paramMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionBuilder toCreatCriteria(SelectCondition selectCondition) {
|
public ConditionBuilder toCreatCriteria(SelectCondition selectCondition, String tableName) {
|
||||||
return new ConditionBuilder(selectCondition, this.sql,this.paramMap);
|
return new ConditionBuilder(selectCondition, this.sql, this.paramMap, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionBuilder toCreatCriteria(DataMap dataMap) {
|
public ConditionBuilder toCreatCriteria(DataMap dataMap) {
|
||||||
return new ConditionBuilder(dataMap.getSelectCondition(), this.sql,this.paramMap);
|
return new ConditionBuilder(dataMap.getSelectCondition(), this.sql, this.paramMap, dataMap.getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConditionBuilder {
|
public static class ConditionBuilder {
|
||||||
@@ -165,6 +169,7 @@ public class Condition implements Serializable {
|
|||||||
private String selecSql = "";
|
private String selecSql = "";
|
||||||
|
|
||||||
private String conditionSql = "";
|
private String conditionSql = "";
|
||||||
|
private String tableName = "";
|
||||||
|
|
||||||
private int lrn = 0;
|
private int lrn = 0;
|
||||||
|
|
||||||
@@ -195,23 +200,30 @@ public class Condition implements Serializable {
|
|||||||
public ConditionBuilder() {
|
public ConditionBuilder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConditionBuilder(String tableName) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
}
|
||||||
|
|
||||||
public ConditionBuilder(boolean flag) {
|
public ConditionBuilder(boolean flag) {
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionBuilder(SelectCondition selectCondition,Map<String,Object> paramMap) {
|
public ConditionBuilder(SelectCondition selectCondition, Map<String, Object> paramMap, String tableName) {
|
||||||
this.selectCondition = selectCondition;
|
this.selectCondition = selectCondition;
|
||||||
this.selecSql = selectCondition.getSql();
|
this.selecSql = selectCondition.getSql();
|
||||||
this.paramMap = paramMap;
|
this.paramMap = paramMap;
|
||||||
|
this.tableName = tableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionBuilder(SelectCondition selectCondition, boolean flag) {
|
public ConditionBuilder(SelectCondition selectCondition, boolean flag, String tableName) {
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
this.selectCondition = selectCondition;
|
this.selectCondition = selectCondition;
|
||||||
this.selecSql = selectCondition.getSql();
|
this.selecSql = selectCondition.getSql();
|
||||||
|
this.tableName = tableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionBuilder(SelectCondition selectCondition, String sql,Map<String,Object> paramMap) {
|
public ConditionBuilder(SelectCondition selectCondition, String sql, Map<String, Object> paramMap, String tableName) {
|
||||||
|
this.tableName = tableName;
|
||||||
spliteSql(sql);
|
spliteSql(sql);
|
||||||
this.selectCondition = selectCondition;
|
this.selectCondition = selectCondition;
|
||||||
this.selecSql = selectCondition.getSql();
|
this.selecSql = selectCondition.getSql();
|
||||||
@@ -240,6 +252,21 @@ public class Condition implements Serializable {
|
|||||||
this.selecSql = selectCondition.getSql();
|
this.selecSql = selectCondition.getSql();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object formatValue(String key, Object value) {
|
||||||
|
Map<String, String> columnTypes = TableMetadataCache.getColumnTypesFromCache(this.tableName.toLowerCase());
|
||||||
|
// 自动转换数据类型
|
||||||
|
if (value instanceof String && !org.springframework.util.StringUtils.isEmpty(this.tableName) && columnTypes != null) {
|
||||||
|
value = DataTypeConverter.convertDataTypes(key, (String) value, columnTypes);
|
||||||
|
// String str = (String)value;
|
||||||
|
// if (str.matches("-?\\d+")) { // 匹配整数
|
||||||
|
// return Long.parseLong(str);
|
||||||
|
// } else if (str.matches("-?\\d*\\.\\d+")) { // 匹配浮点数
|
||||||
|
// return Double.parseDouble(str);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public ConditionBuilder(String sql, Map<String, Object> paramMap) {
|
public ConditionBuilder(String sql, Map<String, Object> paramMap) {
|
||||||
this.sql = sql;
|
this.sql = sql;
|
||||||
this.paramMap = paramMap;
|
this.paramMap = paramMap;
|
||||||
@@ -274,7 +301,7 @@ public class Condition implements Serializable {
|
|||||||
}
|
}
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.conditionSql += " " + key + EQUAL + "#{" + sqlKey + "}";
|
this.conditionSql += " " + key + EQUAL + "#{" + sqlKey + "}";
|
||||||
this.paramMap.put(sqlKey, value);
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,9 +315,52 @@ public class Condition implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConditionBuilder leftLike(String key, Object value) {
|
||||||
|
if (value.toString().contains("\"")) {
|
||||||
|
value = value.toString().replaceAll("\"", "");
|
||||||
|
}
|
||||||
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
|
this.conditionSql += " " + key + " " + LIKE + " CONCAT('%',#{" + sqlKey + "})";
|
||||||
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionBuilder rightLike(String key, Object value) {
|
||||||
|
if (value.toString().contains("\"")) {
|
||||||
|
value = value.toString().replaceAll("\"", "");
|
||||||
|
}
|
||||||
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
|
this.conditionSql += " " + key + " " + LIKE + " CONCAT(#{" + sqlKey + "},'%')";
|
||||||
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public ConditionBuilder andLeftLike(String key, Object value) {
|
||||||
|
this.and().leftLike(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionBuilder andRightLike(String key, Object value) {
|
||||||
|
this.and().rightLike(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionBuilder orLeftLike(String key, Object value) {
|
||||||
|
this.or().leftLike(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionBuilder orRightLike(String key, Object value) {
|
||||||
|
this.or().rightLike(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ConditionBuilder like(String key, Object value) {
|
public ConditionBuilder like(String key, Object value) {
|
||||||
sqlCheckLike(value);
|
if (value.toString().contains("\"")) {
|
||||||
this.conditionSql += " " + key + " " + LIKE + " '" + value + "'";
|
value = value.toString().replaceAll("\"", "");
|
||||||
|
}
|
||||||
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
|
this.conditionSql += " " + key + " " + LIKE + " CONCAT('%',#{" + sqlKey + "},'%')";
|
||||||
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +380,7 @@ public class Condition implements Serializable {
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
for (Object object : value) {
|
for (Object object : value) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, object);
|
this.paramMap.put(sqlKey, formatValue(key, object));
|
||||||
inStr.append("#{").append(sqlKey).append("}");
|
inStr.append("#{").append(sqlKey).append("}");
|
||||||
if (i != value.size()) {
|
if (i != value.size()) {
|
||||||
inStr.append(",");
|
inStr.append(",");
|
||||||
@@ -335,8 +405,8 @@ public class Condition implements Serializable {
|
|||||||
public ConditionBuilder between(String key, Object start, Object end) {
|
public ConditionBuilder between(String key, Object start, Object end) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
String sqlKey2 = "item_" + IdUtil.fastUUID();
|
String sqlKey2 = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, start);
|
this.paramMap.put(sqlKey, formatValue(key, start));
|
||||||
this.paramMap.put(sqlKey2, end);
|
this.paramMap.put(sqlKey2, formatValue(key, end));
|
||||||
this.conditionSql += " " + key + " " + BETWEEN + " #{" + sqlKey + "} " + AND + " #{" + sqlKey2 + "} ";
|
this.conditionSql += " " + key + " " + BETWEEN + " #{" + sqlKey + "} " + AND + " #{" + sqlKey2 + "} ";
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -353,7 +423,7 @@ public class Condition implements Serializable {
|
|||||||
|
|
||||||
public ConditionBuilder lt(String key, Object value) {
|
public ConditionBuilder lt(String key, Object value) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, value);
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
this.conditionSql += " " + key + " " + LT + " #{" + sqlKey + "} ";
|
this.conditionSql += " " + key + " " + LT + " #{" + sqlKey + "} ";
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -375,7 +445,7 @@ public class Condition implements Serializable {
|
|||||||
|
|
||||||
public ConditionBuilder notEqual(String key, Object value) {
|
public ConditionBuilder notEqual(String key, Object value) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, value);
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
this.conditionSql += " " + key + " " + NOT_EQUAL + " #{" + sqlKey + "} ";
|
this.conditionSql += " " + key + " " + NOT_EQUAL + " #{" + sqlKey + "} ";
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -392,7 +462,7 @@ public class Condition implements Serializable {
|
|||||||
|
|
||||||
public ConditionBuilder gt(String key, Object value) {
|
public ConditionBuilder gt(String key, Object value) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, value);
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
this.conditionSql += " " + key + " " + GT + " #{" + sqlKey + "} ";
|
this.conditionSql += " " + key + " " + GT + " #{" + sqlKey + "} ";
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -409,7 +479,7 @@ public class Condition implements Serializable {
|
|||||||
|
|
||||||
public ConditionBuilder lte(String key, Object value) {
|
public ConditionBuilder lte(String key, Object value) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, value);
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
this.conditionSql += " " + key + " " + LTE + " #{" + value.toString() + "} ";
|
this.conditionSql += " " + key + " " + LTE + " #{" + value.toString() + "} ";
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -426,7 +496,7 @@ public class Condition implements Serializable {
|
|||||||
|
|
||||||
public ConditionBuilder gte(String key, Object value) {
|
public ConditionBuilder gte(String key, Object value) {
|
||||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||||
this.paramMap.put(sqlKey, value);
|
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||||
this.conditionSql += " " + key + " " + GTE + " #{" + value.toString() + "} ";
|
this.conditionSql += " " + key + " " + GTE + " #{" + value.toString() + "} ";
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lhc
|
||||||
|
* @version 1.0
|
||||||
|
* @className DataTypeConverter
|
||||||
|
* @date 2025年04月09日 15:17
|
||||||
|
* @description 描述
|
||||||
|
*/
|
||||||
|
public class DataTypeConverter {
|
||||||
|
// 缓存字段类型信息
|
||||||
|
// 自动转换数据类型
|
||||||
|
public static Map<String, Object> convertDataTypes(Map<String, Object> data, Map<String, String> columnTypes) {
|
||||||
|
Map<String, Object> convertedData = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||||
|
String column = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
String columnType = columnTypes.get(column.toLowerCase());
|
||||||
|
if (value instanceof String) {
|
||||||
|
if (columnType != null) {
|
||||||
|
switch (columnType) {
|
||||||
|
case "INTEGER":
|
||||||
|
case "INT":
|
||||||
|
case "integer":
|
||||||
|
case "int":
|
||||||
|
convertedData.put(column, Integer.parseInt(value.toString()));
|
||||||
|
break;
|
||||||
|
case "double":
|
||||||
|
case "DOUBLE":
|
||||||
|
convertedData.put(column, Double.parseDouble(value.toString()));
|
||||||
|
break;
|
||||||
|
case "float":
|
||||||
|
case "FLOAT":
|
||||||
|
convertedData.put(column, Float.parseFloat(value.toString()));
|
||||||
|
break;
|
||||||
|
case "bigint":
|
||||||
|
case "BIGINT":
|
||||||
|
convertedData.put(column, Long.parseLong(value.toString()));
|
||||||
|
break;
|
||||||
|
case "DATE":
|
||||||
|
case "DATETIME":
|
||||||
|
case "TIMESTAMP":
|
||||||
|
case "date":
|
||||||
|
case "datetime":
|
||||||
|
case "timestamp":
|
||||||
|
convertedData.put(column, DateUtil.parse(value.toString()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (columnType.contains("int") || columnType.contains("INT")) {
|
||||||
|
convertedData.put(column, Integer.parseInt(value.toString()));
|
||||||
|
} else if (columnType.contains("double") || columnType.contains("DOUBLE")) {
|
||||||
|
convertedData.put(column, Double.parseDouble(value.toString()));
|
||||||
|
} else if (columnType.contains("float") || columnType.contains("FLOAT")) {
|
||||||
|
convertedData.put(column, Float.parseFloat(value.toString()));
|
||||||
|
} else {
|
||||||
|
convertedData.put(column, value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
convertedData.put(column, value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
convertedData.put(column, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return convertedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object convertDataTypes(String column, String value, Map<String, String> columnTypes) {
|
||||||
|
Object result;
|
||||||
|
String columnType = columnTypes.get(column.toLowerCase());
|
||||||
|
if (columnType != null) {
|
||||||
|
switch (columnType) {
|
||||||
|
case "INTEGER":
|
||||||
|
case "INT":
|
||||||
|
case "integer":
|
||||||
|
case "int":
|
||||||
|
result = Integer.parseInt(value);
|
||||||
|
break;
|
||||||
|
case "bigint":
|
||||||
|
case "BIGINT":
|
||||||
|
result = Long.parseLong(value);
|
||||||
|
break;
|
||||||
|
case "DATE":
|
||||||
|
case "DATETIME":
|
||||||
|
case "TIMESTAMP":
|
||||||
|
case "date":
|
||||||
|
case "datetime":
|
||||||
|
case "timestamp":
|
||||||
|
result = DateUtil.parse(value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import tk.mybatis.mapper.autoconfigure.ConfigurationCustomizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @className MyBatisConfig
|
||||||
|
* @author lhc
|
||||||
|
* @date 2025年03月28日 19:43
|
||||||
|
* @description 描述
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MyBatisConfig {
|
||||||
|
@Value("${mybatis.enable-highgo}")
|
||||||
|
private boolean customObjectWrapperEnabled;
|
||||||
|
@Bean
|
||||||
|
public ConfigurationCustomizer configurationCustomizer() {
|
||||||
|
return configuration -> {
|
||||||
|
if (customObjectWrapperEnabled) {
|
||||||
|
configuration.setObjectWrapperFactory(new UpperCaseMapWrapperFactory());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,9 @@ public class SelectCondition implements Serializable {
|
|||||||
this.sql = sql;
|
this.sql = sql;
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
}
|
}
|
||||||
|
public String getTableName(){
|
||||||
|
return this.tableName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSql() {
|
public String getSql() {
|
||||||
return sql;
|
return sql;
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lhc
|
||||||
|
* @version 1.0
|
||||||
|
* @className TableMetadataCache
|
||||||
|
* @date 2025年04月09日 15:46
|
||||||
|
* @description 描述
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TableMetadataCache {
|
||||||
|
// 缓存所有表的字段类型信息
|
||||||
|
private static final ConcurrentHashMap<String, Map<String, String>> tableColumnTypesCache = new ConcurrentHashMap<>();
|
||||||
|
final DruidDataSource dataSource;
|
||||||
|
|
||||||
|
// 数据库连接池或者数据源
|
||||||
|
|
||||||
|
public TableMetadataCache(DruidDataSource druidDataSource) {
|
||||||
|
this.dataSource = druidDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 系统初始化时加载所有表的字段类型
|
||||||
|
@PostConstruct
|
||||||
|
public void initialize() {
|
||||||
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
DatabaseMetaData metaData = connection.getMetaData();
|
||||||
|
ResultSet tables = metaData.getTables(null, null, null, new String[]{"TABLE"});
|
||||||
|
|
||||||
|
while (tables.next()) {
|
||||||
|
String tableName = tables.getString("TABLE_NAME");
|
||||||
|
Map<String, String> columnTypes = getColumnTypes(connection, tableName);
|
||||||
|
tableColumnTypesCache.put(tableName, columnTypes);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取表的字段类型
|
||||||
|
private Map<String, String> getColumnTypes(Connection connection, String tableName) throws SQLException {
|
||||||
|
Map<String, String> columnTypes = new HashMap<>();
|
||||||
|
DatabaseMetaData metaData = connection.getMetaData();
|
||||||
|
ResultSet columns = metaData.getColumns(null, null, tableName, null);
|
||||||
|
|
||||||
|
while (columns.next()) {
|
||||||
|
String columnName = columns.getString("COLUMN_NAME");
|
||||||
|
String columnType = columns.getString("TYPE_NAME");
|
||||||
|
columnTypes.put(columnName, columnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return columnTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取缓存中的字段类型
|
||||||
|
public static Map<String, String> getColumnTypesFromCache(String tableName) {
|
||||||
|
return tableColumnTypesCache.get(tableName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
|
||||||
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
import org.apache.ibatis.reflection.wrapper.MapWrapper;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lhc
|
||||||
|
* @version 1.0
|
||||||
|
* @className UpperCaseMapWrapper
|
||||||
|
* @date 2025年03月28日 19:41
|
||||||
|
* @description 描述
|
||||||
|
*/
|
||||||
|
public class UpperCaseMapWrapper extends MapWrapper {
|
||||||
|
|
||||||
|
public UpperCaseMapWrapper(MetaObject metaObject, Map<String, Object> map) {
|
||||||
|
super(metaObject, map);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String findProperty(String name, boolean useCamelCaseMapping) {
|
||||||
|
return name==null?"":name.toUpperCase() ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
import org.apache.ibatis.reflection.wrapper.ObjectWrapper;
|
||||||
|
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lhc
|
||||||
|
* @version 1.0
|
||||||
|
* @className UpperCaseMapWrapperFactory
|
||||||
|
* @date 2025年03月28日 19:40
|
||||||
|
* @description 描述
|
||||||
|
*/
|
||||||
|
public class UpperCaseMapWrapperFactory implements ObjectWrapperFactory {
|
||||||
|
@Override
|
||||||
|
public boolean hasWrapperFor(Object object) {
|
||||||
|
return object instanceof Map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) {
|
||||||
|
return new UpperCaseMapWrapper(metaObject, (Map) object);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.taixingyiji.base.module.data.module;
|
package com.taixingyiji.base.module.data.module;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.taixingyiji.base.module.data.constants.QueryConstants;
|
import com.taixingyiji.base.module.data.constants.QueryConstants;
|
||||||
|
import com.taixingyiji.base.module.datasource.utils.DataUnit;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -44,10 +46,10 @@ public class WebCondition {
|
|||||||
return valueList;
|
return valueList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Condition.ConditionBuilder setSign(WebCondition webCondition,Condition.ConditionBuilder builder) {
|
public static Condition.ConditionBuilder setSign(WebCondition webCondition, Condition.ConditionBuilder builder, String dataType) {
|
||||||
switch (webCondition.getSign()) {
|
switch (webCondition.getSign()) {
|
||||||
case QueryConstants.LIKE: {
|
case QueryConstants.LIKE: {
|
||||||
return builder.like(webCondition.key, "%"+webCondition.value+"%");
|
return builder.like(webCondition.key, webCondition.value);
|
||||||
}
|
}
|
||||||
case QueryConstants.EQUAL: {
|
case QueryConstants.EQUAL: {
|
||||||
return builder.equal(webCondition.key, webCondition.value);
|
return builder.equal(webCondition.key, webCondition.value);
|
||||||
@@ -71,6 +73,12 @@ public class WebCondition {
|
|||||||
String[] strings = webCondition.value.toString().split(",");
|
String[] strings = webCondition.value.toString().split(",");
|
||||||
return builder.in(webCondition.key, Arrays.asList(strings));
|
return builder.in(webCondition.key, Arrays.asList(strings));
|
||||||
}
|
}
|
||||||
|
case QueryConstants.RIGHT_LIKE: {
|
||||||
|
return builder.rightLike(webCondition.key, webCondition.value);
|
||||||
|
}
|
||||||
|
case QueryConstants.LEFT_LIKE: {
|
||||||
|
return builder.leftLike(webCondition.key, webCondition.value);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected sign value: " + webCondition.getLogic());
|
throw new IllegalStateException("Unexpected sign value: " + webCondition.getLogic());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ public class TableServiceImpl implements TableService {
|
|||||||
selectJoinBuilder = selectJoinBuilder.join(joinCondition);
|
selectJoinBuilder = selectJoinBuilder.join(joinCondition);
|
||||||
}
|
}
|
||||||
SelectCondition selectCondition = selectJoinBuilder.build();
|
SelectCondition selectCondition = selectJoinBuilder.build();
|
||||||
Condition.ConditionBuilder builder = Condition.creatCriteria(selectCondition);
|
Condition.ConditionBuilder builder = Condition.creatCriteria(selectCondition,selectCondition.getTableName());
|
||||||
builder = getQueryBuilder(query, builder);
|
builder = getQueryBuilder(query, builder);
|
||||||
return baseMapper.selectByCondition(builder.build(), webPageInfo);
|
return baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||||
} else {
|
} else {
|
||||||
@@ -214,6 +214,7 @@ public class TableServiceImpl implements TableService {
|
|||||||
public ResultVO<Integer> logicDelete(OsSysTable tableName, String ids) {
|
public ResultVO<Integer> logicDelete(OsSysTable tableName, String ids) {
|
||||||
Map<String, Object> map = new HashMap<>(1);
|
Map<String, Object> map = new HashMap<>(1);
|
||||||
map.put(FieldConstants.DELETED.toString(), 0);
|
map.put(FieldConstants.DELETED.toString(), 0);
|
||||||
|
map.put(FieldConstants.UPDATE_TIME.toString(), new Date());
|
||||||
DataMap dataMap = DataMap.builder().sysOsTable(tableName).ids(ids).data(map).build();
|
DataMap dataMap = DataMap.builder().sysOsTable(tableName).ids(ids).data(map).build();
|
||||||
Condition condition = Condition.creatCriteria().andIn(dataMap.getPkName(), dataMap.getIdList()).build();
|
Condition condition = Condition.creatCriteria().andIn(dataMap.getPkName(), dataMap.getIdList()).build();
|
||||||
int i = baseMapper.updateByCondition(dataMap, condition);
|
int i = baseMapper.updateByCondition(dataMap, condition);
|
||||||
@@ -233,7 +234,7 @@ public class TableServiceImpl implements TableService {
|
|||||||
if (!StringUtils.isEmpty(webCondition.getCurves())) {
|
if (!StringUtils.isEmpty(webCondition.getCurves())) {
|
||||||
builder = WebCondition.setCurves(webCondition, builder);
|
builder = WebCondition.setCurves(webCondition, builder);
|
||||||
}
|
}
|
||||||
builder = WebCondition.setSign(webCondition, builder);
|
builder = WebCondition.setSign(webCondition, builder,baseMapper.getDataConfig());
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class DataSourceAop {
|
|||||||
@Before("log()")
|
@Before("log()")
|
||||||
public void doBefore(JoinPoint joinPoint) {
|
public void doBefore(JoinPoint joinPoint) {
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if (attributes != null) {
|
||||||
HttpServletRequest request = attributes.getRequest();
|
HttpServletRequest request = attributes.getRequest();
|
||||||
if (isMulti) {
|
if (isMulti) {
|
||||||
String key = request.getParameter("datasourceKey");
|
String key = request.getParameter("datasourceKey");
|
||||||
@@ -62,6 +63,7 @@ public class DataSourceAop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@After("log()")
|
@After("log()")
|
||||||
public void doAfter() {
|
public void doAfter() {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class DataUnit {
|
|||||||
public static final String MYSQL = "Mysql";
|
public static final String MYSQL = "Mysql";
|
||||||
public static final String ORACLE = "Oracle";
|
public static final String ORACLE = "Oracle";
|
||||||
public static final String DAMENG = "Dameng";
|
public static final String DAMENG = "Dameng";
|
||||||
|
public static final String HANGO= "HanGO";
|
||||||
public static final String MASTERBEAN = "masterDataSource";
|
public static final String MASTERBEAN = "masterDataSource";
|
||||||
public static final String DYNAMICBEAN = "dynamicDataSource";
|
public static final String DYNAMICBEAN = "dynamicDataSource";
|
||||||
public static final String PASSWORD = "******";
|
public static final String PASSWORD = "******";
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ public class RequestLogAspect {
|
|||||||
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
||||||
HttpServletRequest request = attributes.getRequest();
|
|
||||||
Object result = proceedingJoinPoint.proceed();
|
Object result = proceedingJoinPoint.proceed();
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if (attributes != null) {
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
if (frameConfig.getShowControllerLog()) {
|
if (frameConfig.getShowControllerLog()) {
|
||||||
RequestInfo requestInfo = new RequestInfo();
|
RequestInfo requestInfo = new RequestInfo();
|
||||||
requestInfo.setIp(request.getRemoteAddr());
|
requestInfo.setIp(request.getRemoteAddr());
|
||||||
@@ -61,12 +61,15 @@ public class RequestLogAspect {
|
|||||||
requestInfo.setTimeCost(System.currentTimeMillis() - start);
|
requestInfo.setTimeCost(System.currentTimeMillis() - start);
|
||||||
LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo));
|
LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterThrowing(pointcut = "requestServer()", throwing = "e")
|
@AfterThrowing(pointcut = "requestServer()", throwing = "e")
|
||||||
public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) {
|
public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) {
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if (attributes != null) {
|
||||||
HttpServletRequest request = attributes.getRequest();
|
HttpServletRequest request = attributes.getRequest();
|
||||||
RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
|
RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
|
||||||
requestErrorInfo.setIp(request.getRemoteAddr());
|
requestErrorInfo.setIp(request.getRemoteAddr());
|
||||||
@@ -78,6 +81,7 @@ public class RequestLogAspect {
|
|||||||
requestErrorInfo.setException(e);
|
requestErrorInfo.setException(e);
|
||||||
LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo));
|
LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取入参
|
* 获取入参
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class CustomRealm extends AuthorizingRealm {
|
|||||||
} else {
|
} else {
|
||||||
//1. 根据accessToken,查询用户信息
|
//1. 根据accessToken,查询用户信息
|
||||||
FtToken tokenEntity = shiroService.findByToken(accessToken);
|
FtToken tokenEntity = shiroService.findByToken(accessToken);
|
||||||
userId = tokenEntity.getUserId();
|
userId = String.valueOf(tokenEntity.getUserId());
|
||||||
//2. token失效
|
//2. token失效
|
||||||
if (tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()) {
|
if (tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()) {
|
||||||
throw new IncorrectCredentialsException("token失效,请重新登录");
|
throw new IncorrectCredentialsException("token失效,请重新登录");
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class FtToken implements Serializable {
|
|||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
private String userId;
|
private Integer userId;
|
||||||
|
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package com.taixingyiji.base.module.shiro.service;
|
|||||||
import com.taixingyiji.base.common.ResultVO;
|
import com.taixingyiji.base.common.ResultVO;
|
||||||
import com.taixingyiji.base.common.ServiceException;
|
import com.taixingyiji.base.common.ServiceException;
|
||||||
import com.taixingyiji.base.common.config.FrameConfig;
|
import com.taixingyiji.base.common.config.FrameConfig;
|
||||||
|
import com.taixingyiji.base.module.data.exception.SqlException;
|
||||||
|
import com.taixingyiji.base.module.data.module.BaseMapper;
|
||||||
|
import com.taixingyiji.base.module.data.module.Condition;
|
||||||
import com.taixingyiji.base.module.shiro.dao.FtTokenDao;
|
import com.taixingyiji.base.module.shiro.dao.FtTokenDao;
|
||||||
import com.taixingyiji.base.module.shiro.FtToken;
|
import com.taixingyiji.base.module.shiro.FtToken;
|
||||||
import com.taixingyiji.base.common.utils.TokenProccessor;
|
import com.taixingyiji.base.common.utils.TokenProccessor;
|
||||||
@@ -35,7 +38,8 @@ public class ShiroServiceImpl implements ShiroService {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
FtTokenDao tokenMapper;
|
FtTokenDao tokenMapper;
|
||||||
|
@Resource
|
||||||
|
BaseMapper baseMapper;
|
||||||
@Resource
|
@Resource
|
||||||
RedisUtil redisUtil;
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
@@ -52,6 +56,7 @@ public class ShiroServiceImpl implements ShiroService {
|
|||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
FtToken tokenEntity = new FtToken();
|
FtToken tokenEntity = new FtToken();
|
||||||
|
Map<String, Object> resultEntity = new HashMap<>();
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
// 是否使用redis存入token
|
// 是否使用redis存入token
|
||||||
if (isRedisLogin) {
|
if (isRedisLogin) {
|
||||||
@@ -72,25 +77,42 @@ public class ShiroServiceImpl implements ShiroService {
|
|||||||
throw new ServiceException("登陆失败");
|
throw new ServiceException("登陆失败");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tokenEntity.setUserId(userId);
|
// tokenEntity.setUserId(userId);
|
||||||
//判断是否生成过token
|
//判断是否生成过token
|
||||||
tokenEntity = tokenMapper.selectOne(tokenEntity);
|
Condition condition = Condition.creatCriteria().andEqual("USER_ID", userId).build();
|
||||||
if (tokenEntity == null) {
|
resultEntity = baseMapper.selectOneByCondition("FT_TOKEN", condition);
|
||||||
tokenEntity = new FtToken();
|
if (resultEntity == null || resultEntity.isEmpty()) {
|
||||||
tokenEntity.setTokenId(UUID.randomUUID().toString() + System.currentTimeMillis());
|
resultEntity = new HashMap<>();
|
||||||
tokenEntity.setUserId(userId);
|
resultEntity.put("TOKEN_ID", UUID.randomUUID().toString() + System.currentTimeMillis());
|
||||||
tokenEntity.setToken(token);
|
resultEntity.put("USER_ID", userId);
|
||||||
tokenEntity.setUpdateTime(now);
|
resultEntity.put("TOKEN", token);
|
||||||
tokenEntity.setExpireTime(expireTime);
|
resultEntity.put("UPDATE_TIME", now);
|
||||||
//保存token
|
resultEntity.put("EXPIRE_TIME", expireTime);
|
||||||
tokenMapper.insertSelective(tokenEntity);
|
baseMapper.save("FT_TOKEN", "TOKEN_ID", resultEntity);
|
||||||
} else {
|
} else {
|
||||||
tokenEntity.setToken(token);
|
resultEntity.put("TOKEN", token);
|
||||||
tokenEntity.setUpdateTime(now);
|
resultEntity.put("UPDATE_TIME", now);
|
||||||
tokenEntity.setExpireTime(expireTime);
|
resultEntity.put("EXPIRE_TIME", expireTime);
|
||||||
//更新token
|
int i = baseMapper.updateByPk("FT_TOKEN", "TOKEN_ID", resultEntity);
|
||||||
int i = tokenMapper.updateByPrimaryKey(tokenEntity);
|
SqlException.base(i, "登录失败");
|
||||||
}
|
}
|
||||||
|
// tokenEntity = tokenMapper.selectOne(tokenEntity);
|
||||||
|
// if (tokenEntity == null) {
|
||||||
|
// tokenEntity = new FtToken();
|
||||||
|
// tokenEntity.setTokenId(UUID.randomUUID().toString() + System.currentTimeMillis());
|
||||||
|
// tokenEntity.setUserId(userId);
|
||||||
|
// tokenEntity.setToken(token);
|
||||||
|
// tokenEntity.setUpdateTime(now);
|
||||||
|
// tokenEntity.setExpireTime(expireTime);
|
||||||
|
// //保存token
|
||||||
|
// tokenMapper.insertSelective(tokenEntity);
|
||||||
|
// } else {
|
||||||
|
// tokenEntity.setToken(token);
|
||||||
|
// tokenEntity.setUpdateTime(now);
|
||||||
|
// tokenEntity.setExpireTime(expireTime);
|
||||||
|
// //更新token
|
||||||
|
// int i = tokenMapper.updateByPrimaryKey(tokenEntity);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
//返回token给前端
|
//返回token给前端
|
||||||
result.put("token", token);
|
result.put("token", token);
|
||||||
@@ -113,11 +135,15 @@ public class ShiroServiceImpl implements ShiroService {
|
|||||||
//生成一个token
|
//生成一个token
|
||||||
String token = tokenProccessor.makeToken();
|
String token = tokenProccessor.makeToken();
|
||||||
//修改token
|
//修改token
|
||||||
FtToken tokenEntity = new FtToken();
|
// FtToken tokenEntity = new FtToken();
|
||||||
tokenEntity.setToken(token);
|
// tokenEntity.setToken(token);
|
||||||
Example example = new Example(FtToken.class);
|
// Example example = new Example(FtToken.class);
|
||||||
example.createCriteria().andEqualTo("token", accessToken);
|
// example.createCriteria().andEqualTo("token", accessToken);
|
||||||
int i = tokenMapper.updateByExampleSelective(tokenEntity, example);
|
// int i = tokenMapper.updateByExampleSelective(tokenEntity, example);
|
||||||
|
Map<String, Object> resultEntity = new HashMap<>();
|
||||||
|
resultEntity.put("TOKEN", token);
|
||||||
|
Condition condition = Condition.creatCriteria().andEqual("TOKEN", accessToken).build();
|
||||||
|
int i = baseMapper.updateByCondition("FT_TOKEN", resultEntity, condition);
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
return ResultVO.getSuccess();
|
return ResultVO.getSuccess();
|
||||||
} else {
|
} else {
|
||||||
@@ -129,8 +155,15 @@ public class ShiroServiceImpl implements ShiroService {
|
|||||||
@Override
|
@Override
|
||||||
public FtToken findByToken(String accessToken) {
|
public FtToken findByToken(String accessToken) {
|
||||||
FtToken osToken = new FtToken();
|
FtToken osToken = new FtToken();
|
||||||
osToken.setToken(accessToken);
|
// osToken.setToken(accessToken);
|
||||||
return tokenMapper.selectOne(osToken);
|
Condition condition = Condition.creatCriteria().andEqual("TOKEN", accessToken).build();
|
||||||
|
Map<String, Object> map = baseMapper.selectOneByCondition("FT_TOKEN", condition);
|
||||||
|
osToken.setToken((String) map.get("TOKEN"));
|
||||||
|
osToken.setTokenId((String) map.get("TOKEN_ID"));
|
||||||
|
osToken.setUserId((Integer) map.get("USER_ID"));
|
||||||
|
osToken.setExpireTime((Date) map.get("EXPIRE_TIME"));
|
||||||
|
osToken.setUpdateTime((Date) map.get("UPDATE_TIME"));
|
||||||
|
return osToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateInfo" parameterType="map" useGeneratedKeys="true" keyProperty="info.id" keyColumn="id">
|
<update id="updateInfo" parameterType="map">
|
||||||
update ${tableName}
|
update ${tableName}
|
||||||
<set>
|
<set>
|
||||||
<foreach collection="info" separator="," item="value" index="key">
|
<foreach collection="info" separator="," item="value" index="key">
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
</set>
|
</set>
|
||||||
where id = #{info.id}
|
where id = #{info.id}
|
||||||
</update>
|
</update>
|
||||||
<update id="updateInfoWithNull" parameterType="map" useGeneratedKeys="true" keyProperty="info.id" keyColumn="id">
|
<update id="updateInfoWithNull" parameterType="map" >
|
||||||
update ${tableName}
|
update ${tableName}
|
||||||
<set>
|
<set>
|
||||||
<foreach collection="info.keys" separator="," item="key" index="index">
|
<foreach collection="info.keys" separator="," item="key" index="index">
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
where id = #{info.id}
|
where id = #{info.id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateByWhere" parameterType="map" useGeneratedKeys="true" keyProperty="info.id">
|
<update id="updateByWhere" parameterType="map" >
|
||||||
update ${tableName}
|
update ${tableName}
|
||||||
<set>
|
<set>
|
||||||
<foreach collection="info" separator="," item="value" index="key">
|
<foreach collection="info" separator="," item="value" index="key">
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
${sql}
|
${sql}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateByWhereWithNull" parameterType="map" useGeneratedKeys="true" keyProperty="info.id" keyColumn="id">
|
<update id="updateByWhereWithNull" parameterType="map">
|
||||||
update ${tableName}
|
update ${tableName}
|
||||||
<set>
|
<set>
|
||||||
<foreach collection="info.keys" separator="," item="key" index="index">
|
<foreach collection="info.keys" separator="," item="key" index="index">
|
||||||
@@ -157,6 +157,9 @@
|
|||||||
select ${tableName}_seq.nextval
|
select ${tableName}_seq.nextval
|
||||||
from dual
|
from dual
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getHighGoSequence" resultType="java.lang.Object">
|
||||||
|
select nextval('${tableName}_seq')
|
||||||
|
</select>
|
||||||
<insert id="createSequence">
|
<insert id="createSequence">
|
||||||
CREATE
|
CREATE
|
||||||
SEQUENCE ${tableName}_seq
|
SEQUENCE ${tableName}_seq
|
||||||
@@ -167,6 +170,29 @@
|
|||||||
INCREMENT BY 1
|
INCREMENT BY 1
|
||||||
NOCACHE
|
NOCACHE
|
||||||
</insert>
|
</insert>
|
||||||
|
<insert id="createHighGoSequence">
|
||||||
|
CREATE SEQUENCE ${tableName}_seq
|
||||||
|
MINVALUE 1
|
||||||
|
NO MAXVALUE
|
||||||
|
START WITH ${lastId}
|
||||||
|
INCREMENT BY 1
|
||||||
|
CACHE 1;
|
||||||
|
</insert>
|
||||||
|
<select id="judgeHighGoSequenceExist" resultType="boolean">
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM pg_class
|
||||||
|
WHERE relkind = 'S'
|
||||||
|
AND relname = '${tableName}_seq'
|
||||||
|
AND pg_table_is_visible(oid)
|
||||||
|
);
|
||||||
|
</select>
|
||||||
|
<select id="judgeDamengSequenceExist" resultType="int">
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM all_sequences
|
||||||
|
WHERE sequence_owner = '${schema}'
|
||||||
|
AND sequence_name = '${tableName}_SEQ'
|
||||||
|
</select>
|
||||||
<select id="count" resultType="java.lang.Long">
|
<select id="count" resultType="java.lang.Long">
|
||||||
SELECT count(0) FROM ${tableName} ${sql}
|
SELECT count(0) FROM ${tableName} ${sql}
|
||||||
</select>
|
</select>
|
||||||
@@ -183,8 +209,31 @@
|
|||||||
VALUES
|
VALUES
|
||||||
<foreach collection="list" item="row" separator=",">
|
<foreach collection="list" item="row" separator=",">
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<foreach collection="row" item="value">
|
<foreach collection="row" item="value" separator=",">
|
||||||
#{value},
|
#{value}
|
||||||
|
</foreach>
|
||||||
|
</trim>
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<insert id="insertBatchSeq" parameterType="map">
|
||||||
|
INSERT INTO ${tableName}
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<foreach collection="list[0].keySet()" item="column" separator=",">
|
||||||
|
${column}
|
||||||
|
</foreach>
|
||||||
|
</trim>
|
||||||
|
VALUES
|
||||||
|
<foreach collection="list" item="row" separator=",">
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<foreach collection="row" item="value" index="key" separator=",">
|
||||||
|
<choose>
|
||||||
|
<when test="key == pkName">
|
||||||
|
${value}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
#{value}
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
</foreach>
|
</foreach>
|
||||||
</trim>
|
</trim>
|
||||||
</foreach>
|
</foreach>
|
||||||
|
|||||||
@@ -229,4 +229,26 @@
|
|||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
<distributionManagement>
|
||||||
|
<!-- <repository>-->
|
||||||
|
<!-- <id>releases</id>-->
|
||||||
|
<!-- <name>Releases</name>-->
|
||||||
|
<!-- <url>http://192.168.0.123:8081/repository/maven-releases/</url>-->
|
||||||
|
<!-- </repository>-->
|
||||||
|
<!-- <snapshotRepository>-->
|
||||||
|
<!-- <id>snapshots</id>-->
|
||||||
|
<!-- <name>Snapshot</name>-->
|
||||||
|
<!-- <url>http://192.168.0.123:8081/repository/maven-snapshots/</url>-->
|
||||||
|
<!-- </snapshotRepository>-->
|
||||||
|
<repository>
|
||||||
|
<id>releases-hc</id>
|
||||||
|
<name>Releases</name>
|
||||||
|
<url>https://qs.taixingyiji.com:8082/repository/maven-releases/</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>snapshots-hc</id>
|
||||||
|
<name>Snapshot</name>
|
||||||
|
<url>https://qs.taixingyiji.com:8082/repository/maven-snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Reference in New Issue
Block a user