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>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hcframe-base</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<version>1.2.4-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@@ -48,6 +48,13 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</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>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
package com.taixingyiji.base.common;
|
||||
|
||||
import com.taixingyiji.base.module.cache.impl.DatasourceCache;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
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.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/***
|
||||
* @description 异常信息拦截类,如果程序运行过程中抛出异常,会将异常拦截下来,并返回前端一个包含异常信息的Json数据
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
public class ControllerExceptionHandler {
|
||||
private final static Logger logger = LoggerFactory.getLogger(ControllerExceptionHandler.class);
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
@@ -23,10 +30,14 @@ public class ControllerExceptionHandler {
|
||||
return ResultVO.getFailed("用户名或密码错误");
|
||||
} else if (e instanceof RuntimeException) {
|
||||
System.out.println("handleServiceException");
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(),e);
|
||||
//封装错误信息
|
||||
return ResultVO.getException(e);
|
||||
} else {
|
||||
} else if(e instanceof MethodArgumentNotValidException){
|
||||
String defaultMessage = Objects.requireNonNull(((MethodArgumentNotValidException) e).getBindingResult().getFieldError()).getDefaultMessage();
|
||||
logger.error("请求参数验证异常:", e);
|
||||
return ResultVO.getFailed(defaultMessage);
|
||||
}else {
|
||||
return ResultVO.getException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class UserInfoUtil<T> {
|
||||
if (date.getTime() > expireData.getTime()) {
|
||||
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 LTE = 7;
|
||||
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 JOIN = "join";
|
||||
|
||||
@@ -42,12 +42,17 @@ public interface TableMapper {
|
||||
List<Map<String, Object>> getListNoPage(@Param("typeName") String tableName, @Param("info") Map<String, Object> map);
|
||||
|
||||
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 createHighGoSequence(@Param("tableName") String tableName, @Param("lastId")Object lastId);
|
||||
|
||||
Long count(@Param("tableName")String tableName,@Param("sql")String sql);
|
||||
|
||||
Long countBySql(@Param("sql") String sql);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
||||
public interface BaseMapper {
|
||||
|
||||
<E> int save(DataMap<E> dataMap);
|
||||
|
||||
String getDataConfig();
|
||||
int save(String tableName, String pkName, Map<String, Object> data);
|
||||
|
||||
<E> int save(E e);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.taixingyiji.base.module.data.module;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.taixingyiji.base.common.ServiceException;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
@Service("base")
|
||||
public class BaseMapperImpl implements BaseMapper {
|
||||
@@ -28,24 +28,48 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
public static final String BASE = "base";
|
||||
public static final String TABLE_MAPPER_PACKAGE = "com.taixingyiji.base.module.data.dao.TableMapper.";
|
||||
final TableMapper tableMapper;
|
||||
final DruidDataSource druidDataSource;
|
||||
|
||||
@Value("${spring.datasource.druid.driver-class-name}")
|
||||
public String dataType;
|
||||
final SqlSessionTemplate sqlSessionTemplate;
|
||||
|
||||
public BaseMapperImpl(TableMapper tableMapper, SqlSessionTemplate sqlSessionTemplate) {
|
||||
public BaseMapperImpl(TableMapper tableMapper, SqlSessionTemplate sqlSessionTemplate,
|
||||
DruidDataSource druidDataSource) {
|
||||
this.tableMapper = tableMapper;
|
||||
this.sqlSessionTemplate = sqlSessionTemplate;
|
||||
this.druidDataSource = druidDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> int save(DataMap<E> dataMap) {
|
||||
public String getDataConfig() {
|
||||
String key;
|
||||
DatasourceConfig datasourceConfig = new DatasourceConfig();
|
||||
try {
|
||||
|
||||
key = DBContextHolder.getDataSource();
|
||||
datasourceConfig = DataSourceUtil.get(key);
|
||||
} 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")) {
|
||||
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
||||
}
|
||||
@@ -58,14 +82,27 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
if (dataType.contains("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.getTableName(), "tableName can not be null!");
|
||||
if (DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||
dataMap.getData().putAll(formatMap(dataMap.getData(),dataMap.getTableName()));
|
||||
}
|
||||
if (StringUtils.isEmpty(dataMap.getPkName())) {
|
||||
dataMap.setPkName("ID");
|
||||
}
|
||||
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()))) {
|
||||
Object id = getSequence(dataMap.getTableName(), dataMap.getPkName());
|
||||
dataMap.toBuilder().add(dataMap.getPkName(), id);
|
||||
@@ -82,34 +119,37 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
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
|
||||
public int save(String tableName, String pkName, Map<String, Object> data) {
|
||||
JudgesNull(tableName, "data can not be null!");
|
||||
JudgesNull(data, "tableName can not be null!");
|
||||
String key;
|
||||
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);
|
||||
}
|
||||
String dataTypeConfig = getDataConfig();
|
||||
if (DataUnit.HANGO.equals(dataTypeConfig)) {
|
||||
data.putAll(formatMap(data, tableName));
|
||||
}
|
||||
if (StringUtils.isEmpty(pkName)) {
|
||||
pkName = "ID";
|
||||
}
|
||||
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))) {
|
||||
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) {
|
||||
Map<String, Object> params = condition.getParamMap();
|
||||
params.put("tableName", tableName);
|
||||
String dataTypeConfig = getDataConfig();
|
||||
data.putAll(formatMap(data,tableName));
|
||||
params.put("info", data);
|
||||
params.put("sql", condition.getSql());
|
||||
int i = sqlSessionTemplate.update(TABLE_MAPPER_PACKAGE + "updateByWhere", params);
|
||||
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
|
||||
public <E> int updateByPk(DataMap<E> dataMap) {
|
||||
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());
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> selectList(Condition condition) {
|
||||
private List<Map<String, Object>> selectList(Condition condition, String tableName) {
|
||||
Map<String, Object> params = condition.getParamMap();
|
||||
String dataTypeConfig = getDataConfig();
|
||||
params.put("sql", condition.getSql());
|
||||
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();
|
||||
String dataTypeConfig = getDataConfig();
|
||||
params.put("sql", condition.getSql());
|
||||
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) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
Condition condition = equal(dataMap, map);
|
||||
return selectList(condition);
|
||||
return selectList(condition, dataMap.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectByEqual(String tableName, Map<String, Object> map) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
Condition condition = equal(DataMap.builder().tableName(tableName).build(), map);
|
||||
return selectList(condition);
|
||||
return selectList(condition, tableName);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,29 +433,29 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
public <E> PageInfo<Map<String, Object>> selectByEqual(DataMap<E> dataMap, Map<String, Object> map, WebPageInfo webPageInfo) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
Condition condition = equal(dataMap, map);
|
||||
if(webPageInfo.isEnableCache()){
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(condition));
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(condition, dataMap.getTableName()));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(selectList(condition));
|
||||
return new PageInfo<>(selectList(condition, dataMap.getTableName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByEqual(String tableName, Map<String, Object> map, WebPageInfo webPageInfo) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
Condition condition = equal(DataMap.builder().tableName(tableName).build(), map);
|
||||
if(webPageInfo.isEnableCache()){
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(condition));
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(condition, tableName));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(selectList(condition));
|
||||
return new PageInfo<>(selectList(condition, tableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> Map<String, Object> selectOneByEqual(DataMap<E> dataMap, Map<String, Object> map) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
Condition condition = equal(dataMap, map);
|
||||
return selectOne(condition);
|
||||
return selectOne(condition, dataMap.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -409,7 +465,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
JudgesNull(dataMap.getPkValue(), "pkValue can not be null!");
|
||||
Condition condition = Condition.creatCriteria(dataMap).build();
|
||||
condition = condition.toCreatCriteria().andEqual(dataMap.getPkName(), dataMap.getPkValue()).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition, dataMap.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -419,7 +475,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
JudgesNull(pkValue, "pkValue can not be null!");
|
||||
Condition condition = Condition.creatCriteria(DataMap.builder().sysOsTable(osSysTable).pkValue(pkValue).build()).build();
|
||||
condition = condition.toCreatCriteria().andEqual(osSysTable.getTablePk(), pkValue).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition, osSysTable.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,26 +485,27 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
JudgesNull(pkValue, "pkValue can not be null!");
|
||||
Condition condition = Condition.creatCriteria(DataMap.builder().tableName(tableName).pkName(pkName).pkValue(pkValue).build()).build();
|
||||
condition = condition.toCreatCriteria().andEqual(pkName, pkValue).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public <E> List<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(dataMap).build();
|
||||
return selectList(condition);
|
||||
return selectList(condition,dataMap.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectByCondition(String tableName, Condition condition) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
||||
return selectList(condition);
|
||||
return selectList(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -457,7 +514,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
condition = condition
|
||||
.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build())
|
||||
.build();
|
||||
return selectList(condition);
|
||||
return selectList(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -466,97 +523,97 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
condition = condition
|
||||
.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build())
|
||||
.build();
|
||||
return selectList(condition);
|
||||
return selectList(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByCondition(Condition condition, WebPageInfo webPageInfo) {
|
||||
MyPageHelper.start(webPageInfo);
|
||||
if(webPageInfo.isEnableCache()){
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(condition));
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
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
|
||||
public <E> PageInfo<Map<String, Object>> selectByCondition(DataMap<E> dataMap, Condition condition, WebPageInfo webPageInfo) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(dataMap).build();
|
||||
if(webPageInfo.isEnableCache()){
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
Condition finalCondition = condition;
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
||||
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,dataMap.getTableName()));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(selectList(condition));
|
||||
return new PageInfo<>(selectList(condition,dataMap.getTableName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByCondition(String tableName, Condition condition, WebPageInfo webPageInfo) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
||||
if(webPageInfo.isEnableCache()){
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
Condition finalCondition = condition;
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
||||
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,tableName));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(selectList(condition));
|
||||
return new PageInfo<>(selectList(condition,tableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByCondition(String tableName, List<String> fieldList, Condition condition, WebPageInfo webPageInfo) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build()).build();
|
||||
if(webPageInfo.isEnableCache()){
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
Condition finalCondition = condition;
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
||||
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,tableName));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(selectList(condition));
|
||||
return new PageInfo<>(selectList(condition,tableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectByCondition(String tableName, String fieldList, Condition condition, WebPageInfo webPageInfo) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build()).build();
|
||||
if(webPageInfo.isEnableCache()){
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
Condition finalCondition = condition;
|
||||
return MyPageHelper.start(webPageInfo,condition.getSql(),() -> selectList(finalCondition));
|
||||
return MyPageHelper.start(webPageInfo, condition.getSql(), () -> selectList(finalCondition,tableName));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(selectList(condition));
|
||||
return new PageInfo<>(selectList(condition,tableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> Map<String, Object> selectOneByCondition(DataMap<E> dataMap, Condition condition) {
|
||||
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(dataMap).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition,dataMap.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneByCondition(String tableName, Condition condition) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).build()).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneByCondition(String tableName, List<String> fieldList, Condition condition) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fieldList(fieldList).build()).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneByCondition(String tableName, String fieldList, Condition condition) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
condition = condition.toCreatCriteria(DataMap.builder().tableName(tableName).fields(fieldList).build()).build();
|
||||
return selectOne(condition);
|
||||
return selectOne(condition,tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneByCondition(Condition condition) {
|
||||
return selectOne(condition);
|
||||
return selectOne(condition,condition.getSelectCondition().getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -565,18 +622,17 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
SelectCondition selectJoinBuilder = SelectCondition
|
||||
.joinBuilder(tableName)
|
||||
.join(joinCondition).build();
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectJoinByCondition(String tableName, List<JoinCondition> joinCondition, Condition condition) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
SelectCondition selectJoinBuilder = SelectCondition
|
||||
.joinBuilder(tableName)
|
||||
.join(joinCondition).build();
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -585,7 +641,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
SelectCondition selectJoinBuilder = SelectCondition
|
||||
.joinBuilder(tableName)
|
||||
.leftJoin(joinCondition).build();
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -594,7 +650,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
SelectCondition selectJoinBuilder = SelectCondition
|
||||
.joinBuilder(tableName)
|
||||
.leftJoin(joinCondition).build();
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -603,7 +659,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
SelectCondition selectJoinBuilder = SelectCondition
|
||||
.joinBuilder(tableName)
|
||||
.rightJoin(joinCondition).build();
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -612,12 +668,12 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
SelectCondition selectJoinBuilder = SelectCondition
|
||||
.joinBuilder(tableName)
|
||||
.rightJoin(joinCondition).build();
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder).build().getSql());
|
||||
return tableMapper.useSql(condition.toCreatCriteria(selectJoinBuilder,tableName).build().getSql());
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
@@ -627,8 +683,8 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectSqlByPage(String sql, WebPageInfo webPageInfo) {
|
||||
if(webPageInfo.isEnableCache()){
|
||||
return MyPageHelper.start(webPageInfo,sql,() -> (tableMapper.useSql(sql)));
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
return MyPageHelper.start(webPageInfo, sql, () -> (tableMapper.useSql(sql)));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(tableMapper.useSql(sql));
|
||||
@@ -636,15 +692,18 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectSql(String sql, Map<String, Object> params) {
|
||||
params.put("sql",sql);
|
||||
params.put("sql", sql);
|
||||
return sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PageInfo<Map<String, Object>> selectSqlByPage(String sql, Map<String, Object> params, WebPageInfo webPageInfo) {
|
||||
params.put("sql",sql);
|
||||
if(webPageInfo.isEnableCache()){
|
||||
return MyPageHelper.start(webPageInfo,sql,() -> sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params));
|
||||
String dataTypeConfig = getDataConfig();
|
||||
params.put("sql", sql);
|
||||
if (webPageInfo.isEnableCache()) {
|
||||
Map<String, Object> finalParams = params;
|
||||
return MyPageHelper.start(webPageInfo, sql, () -> sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", finalParams));
|
||||
}
|
||||
MyPageHelper.start(webPageInfo);
|
||||
return new PageInfo<>(sqlSessionTemplate.selectList(TABLE_MAPPER_PACKAGE + "useSql", params));
|
||||
@@ -657,16 +716,16 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectOneSql(String sql, Map<String, Object> params) {
|
||||
params.put("sql",sql);
|
||||
params.put("sql", sql);
|
||||
return sqlSessionTemplate.selectOne(TABLE_MAPPER_PACKAGE + "userSqlByOne", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count(String tableName, Condition condition) {
|
||||
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);
|
||||
Map<String,Object> map = selectOne(condition);
|
||||
Map<String, Object> map = selectOne(condition, tableName);
|
||||
return Long.parseLong(String.valueOf(map.get("COUNT")));
|
||||
}
|
||||
|
||||
@@ -679,40 +738,45 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
public int saveBatch(String tableName, String pkName, List<Map<String, Object>> list) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
JudgesNull(pkName, "pkName can not be null!");
|
||||
if(list==null|| list.isEmpty()){
|
||||
if (list == null || list.isEmpty()) {
|
||||
throw new ServiceException("list can not empty");
|
||||
}
|
||||
// JudgesNull(data, "tableName can not be null!");
|
||||
String key;
|
||||
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);
|
||||
}
|
||||
}
|
||||
String dataTypeConfig = getDataConfig();
|
||||
if (StringUtils.isEmpty(pkName)) {
|
||||
pkName = "ID";
|
||||
}
|
||||
|
||||
if (datasourceConfig.getCommonType().equals(DataUnit.ORACLE) || datasourceConfig.getCommonType().equals(DataUnit.DAMENG)) {
|
||||
for(Map<String,Object> map:list){
|
||||
int i;
|
||||
if (dataTypeConfig.equals(DataUnit.ORACLE)) {
|
||||
for (Map<String, Object> map : list) {
|
||||
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, "保存失败");
|
||||
return i;
|
||||
}
|
||||
@@ -721,7 +785,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
public int updateBatchByPk(String tableName, String pkName, List<Map<String, Object>> list) {
|
||||
JudgesNull(tableName, "tableName can not be null!");
|
||||
JudgesNull(pkName, "pkName can not be null!");
|
||||
if(list==null|| list.isEmpty()){
|
||||
if (list == null || list.isEmpty()) {
|
||||
throw new ServiceException("list can not empty");
|
||||
}
|
||||
StringBuilder sql = new StringBuilder();
|
||||
@@ -755,7 +819,7 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
return 0;
|
||||
}
|
||||
paramMap.put("sql", sql.toString());
|
||||
return this.sqlSessionTemplate.update(TABLE_MAPPER_PACKAGE+"updateBatchByPk", paramMap);
|
||||
return this.sqlSessionTemplate.update(TABLE_MAPPER_PACKAGE + "updateBatchByPk", paramMap);
|
||||
}
|
||||
|
||||
public void JudgesNull(Object object, String str) {
|
||||
@@ -765,14 +829,29 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
|
||||
public Object getSequence(String tableName, String pkName) {
|
||||
String dataTypeConfig = getDataConfig();
|
||||
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 {
|
||||
String url = druidDataSource.getUrl();
|
||||
String schema = getSchemaFromJdbcUrl(url);
|
||||
if (tableMapper.judgeDamengSequenceExist(tableName, schema) > 0) {
|
||||
id = tableMapper.getSequence(tableName);
|
||||
} else {
|
||||
throw new ServiceException("序列不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MyPageHelper.start(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();
|
||||
Map<String, Object> map = selectOneByCondition(condition);
|
||||
Map<String, Object> map = selectRecentData(tableName, pkName);
|
||||
if (map == null) {
|
||||
tableMapper.createSequence(tableName, 1);
|
||||
} else {
|
||||
@@ -780,6 +859,34 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
}
|
||||
id = tableMapper.getSequence(tableName);
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
public static ConditionBuilder creatCriteria(SelectCondition selectCondition) {
|
||||
return new ConditionBuilder(selectCondition,new HashMap<>());
|
||||
public static ConditionBuilder creatCriteria(String tableName) {
|
||||
return new ConditionBuilder(tableName);
|
||||
}
|
||||
|
||||
public static ConditionBuilder creatCriteria(SelectCondition selectCondition, boolean flag) {
|
||||
return new ConditionBuilder(selectCondition, flag);
|
||||
public static ConditionBuilder creatCriteria(SelectCondition selectCondition, String tableName) {
|
||||
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) {
|
||||
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) {
|
||||
JudesNull(dataMap.getTableName(), "tableName can not be null!");
|
||||
return new ConditionBuilder(dataMap.getSelectCondition(), flag);
|
||||
return new ConditionBuilder(dataMap.getSelectCondition(), flag, dataMap.getTableName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,15 +151,15 @@ public class Condition implements Serializable {
|
||||
}
|
||||
|
||||
public ConditionBuilder toCreatCriteria() {
|
||||
return new ConditionBuilder(this.sql,this.paramMap);
|
||||
return new ConditionBuilder(this.sql, this.paramMap);
|
||||
}
|
||||
|
||||
public ConditionBuilder toCreatCriteria(SelectCondition selectCondition) {
|
||||
return new ConditionBuilder(selectCondition, this.sql,this.paramMap);
|
||||
public ConditionBuilder toCreatCriteria(SelectCondition selectCondition, String tableName) {
|
||||
return new ConditionBuilder(selectCondition, this.sql, this.paramMap, tableName);
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -165,6 +169,7 @@ public class Condition implements Serializable {
|
||||
private String selecSql = "";
|
||||
|
||||
private String conditionSql = "";
|
||||
private String tableName = "";
|
||||
|
||||
private int lrn = 0;
|
||||
|
||||
@@ -195,23 +200,30 @@ public class Condition implements Serializable {
|
||||
public ConditionBuilder() {
|
||||
}
|
||||
|
||||
public ConditionBuilder(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public ConditionBuilder(boolean 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.selecSql = selectCondition.getSql();
|
||||
this.paramMap = paramMap;
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public ConditionBuilder(SelectCondition selectCondition, boolean flag) {
|
||||
public ConditionBuilder(SelectCondition selectCondition, boolean flag, String tableName) {
|
||||
this.flag = flag;
|
||||
this.selectCondition = selectCondition;
|
||||
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);
|
||||
this.selectCondition = selectCondition;
|
||||
this.selecSql = selectCondition.getSql();
|
||||
@@ -240,7 +252,22 @@ public class Condition implements Serializable {
|
||||
this.selecSql = selectCondition.getSql();
|
||||
}
|
||||
|
||||
public ConditionBuilder(String sql,Map<String,Object> paramMap) {
|
||||
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) {
|
||||
this.sql = sql;
|
||||
this.paramMap = paramMap;
|
||||
spliteSql(sql);
|
||||
@@ -274,7 +301,7 @@ public class Condition implements Serializable {
|
||||
}
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.conditionSql += " " + key + EQUAL + "#{" + sqlKey + "}";
|
||||
this.paramMap.put(sqlKey, value);
|
||||
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -288,9 +315,52 @@ public class Condition implements Serializable {
|
||||
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) {
|
||||
sqlCheckLike(value);
|
||||
this.conditionSql += " " + key + " " + LIKE + " '" + 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;
|
||||
}
|
||||
|
||||
@@ -310,7 +380,7 @@ public class Condition implements Serializable {
|
||||
int i = 1;
|
||||
for (Object object : value) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, object);
|
||||
this.paramMap.put(sqlKey, formatValue(key, object));
|
||||
inStr.append("#{").append(sqlKey).append("}");
|
||||
if (i != value.size()) {
|
||||
inStr.append(",");
|
||||
@@ -335,8 +405,8 @@ public class Condition implements Serializable {
|
||||
public ConditionBuilder between(String key, Object start, Object end) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
String sqlKey2 = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, start);
|
||||
this.paramMap.put(sqlKey2, end);
|
||||
this.paramMap.put(sqlKey, formatValue(key, start));
|
||||
this.paramMap.put(sqlKey2, formatValue(key, end));
|
||||
this.conditionSql += " " + key + " " + BETWEEN + " #{" + sqlKey + "} " + AND + " #{" + sqlKey2 + "} ";
|
||||
return this;
|
||||
}
|
||||
@@ -353,7 +423,7 @@ public class Condition implements Serializable {
|
||||
|
||||
public ConditionBuilder lt(String key, Object value) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, value);
|
||||
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||
this.conditionSql += " " + key + " " + LT + " #{" + sqlKey + "} ";
|
||||
return this;
|
||||
}
|
||||
@@ -375,7 +445,7 @@ public class Condition implements Serializable {
|
||||
|
||||
public ConditionBuilder notEqual(String key, Object value) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, value);
|
||||
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||
this.conditionSql += " " + key + " " + NOT_EQUAL + " #{" + sqlKey + "} ";
|
||||
return this;
|
||||
}
|
||||
@@ -392,7 +462,7 @@ public class Condition implements Serializable {
|
||||
|
||||
public ConditionBuilder gt(String key, Object value) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, value);
|
||||
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||
this.conditionSql += " " + key + " " + GT + " #{" + sqlKey + "} ";
|
||||
return this;
|
||||
}
|
||||
@@ -409,7 +479,7 @@ public class Condition implements Serializable {
|
||||
|
||||
public ConditionBuilder lte(String key, Object value) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, value);
|
||||
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||
this.conditionSql += " " + key + " " + LTE + " #{" + value.toString() + "} ";
|
||||
return this;
|
||||
}
|
||||
@@ -426,7 +496,7 @@ public class Condition implements Serializable {
|
||||
|
||||
public ConditionBuilder gte(String key, Object value) {
|
||||
String sqlKey = "item_" + IdUtil.fastUUID();
|
||||
this.paramMap.put(sqlKey, value);
|
||||
this.paramMap.put(sqlKey, formatValue(key, value));
|
||||
this.conditionSql += " " + key + " " + GTE + " #{" + value.toString() + "} ";
|
||||
return this;
|
||||
}
|
||||
@@ -492,7 +562,7 @@ public class Condition implements Serializable {
|
||||
if (StringUtils.isEmpty(this.conditionSql)) {
|
||||
this.sql = this.selecSql;
|
||||
}
|
||||
return new Condition(this.sql, this.selectCondition,this.paramMap);
|
||||
return new Condition(this.sql, this.selectCondition, this.paramMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.tableName = tableName;
|
||||
}
|
||||
public String getTableName(){
|
||||
return this.tableName;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
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;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.taixingyiji.base.module.data.constants.QueryConstants;
|
||||
import com.taixingyiji.base.module.datasource.utils.DataUnit;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -44,44 +46,50 @@ public class WebCondition {
|
||||
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()) {
|
||||
case QueryConstants.LIKE:{
|
||||
return builder.like(webCondition.key, "%"+webCondition.value+"%");
|
||||
case QueryConstants.LIKE: {
|
||||
return builder.like(webCondition.key, webCondition.value);
|
||||
}
|
||||
case QueryConstants.EQUAL:{
|
||||
return builder.equal(webCondition.key,webCondition.value);
|
||||
case QueryConstants.EQUAL: {
|
||||
return builder.equal(webCondition.key, webCondition.value);
|
||||
}
|
||||
case QueryConstants.BETWEEN:{
|
||||
return builder.between(webCondition.key, webCondition.value,webCondition.sValue);
|
||||
case QueryConstants.BETWEEN: {
|
||||
return builder.between(webCondition.key, webCondition.value, webCondition.sValue);
|
||||
}
|
||||
case QueryConstants.GT:{
|
||||
case QueryConstants.GT: {
|
||||
return builder.gt(webCondition.key, webCondition.value);
|
||||
}
|
||||
case QueryConstants.GTE:{
|
||||
case QueryConstants.GTE: {
|
||||
return builder.gte(webCondition.key, webCondition.value);
|
||||
}
|
||||
case QueryConstants.LT:{
|
||||
case QueryConstants.LT: {
|
||||
return builder.lt(webCondition.key, webCondition.value);
|
||||
}
|
||||
case QueryConstants.LTE:{
|
||||
case QueryConstants.LTE: {
|
||||
return builder.lte(webCondition.key, webCondition.value);
|
||||
}
|
||||
case QueryConstants.IN:{
|
||||
case QueryConstants.IN: {
|
||||
String[] strings = webCondition.value.toString().split(",");
|
||||
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:
|
||||
throw new IllegalStateException("Unexpected sign value: " + webCondition.getLogic());
|
||||
}
|
||||
}
|
||||
|
||||
public static Condition.ConditionBuilder setLogic(WebCondition webCondition,Condition.ConditionBuilder builder) {
|
||||
public static Condition.ConditionBuilder setLogic(WebCondition webCondition, Condition.ConditionBuilder builder) {
|
||||
switch (webCondition.getLogic()) {
|
||||
case QueryConstants.AND:{
|
||||
case QueryConstants.AND: {
|
||||
return builder.and();
|
||||
}
|
||||
case QueryConstants.OR:{
|
||||
case QueryConstants.OR: {
|
||||
return builder.or();
|
||||
}
|
||||
default:
|
||||
@@ -89,12 +97,12 @@ public class WebCondition {
|
||||
}
|
||||
}
|
||||
|
||||
public static Condition.ConditionBuilder setCurves(WebCondition webCondition,Condition.ConditionBuilder builder) {
|
||||
public static Condition.ConditionBuilder setCurves(WebCondition webCondition, Condition.ConditionBuilder builder) {
|
||||
switch (webCondition.getCurves()) {
|
||||
case QueryConstants.L_CURVES:{
|
||||
case QueryConstants.L_CURVES: {
|
||||
return builder.leftCurves();
|
||||
}
|
||||
case QueryConstants.R_CURVES:{
|
||||
case QueryConstants.R_CURVES: {
|
||||
return builder.rightCurves();
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -202,7 +202,7 @@ public class TableServiceImpl implements TableService {
|
||||
selectJoinBuilder = selectJoinBuilder.join(joinCondition);
|
||||
}
|
||||
SelectCondition selectCondition = selectJoinBuilder.build();
|
||||
Condition.ConditionBuilder builder = Condition.creatCriteria(selectCondition);
|
||||
Condition.ConditionBuilder builder = Condition.creatCriteria(selectCondition,selectCondition.getTableName());
|
||||
builder = getQueryBuilder(query, builder);
|
||||
return baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||
} else {
|
||||
@@ -214,6 +214,7 @@ public class TableServiceImpl implements TableService {
|
||||
public ResultVO<Integer> logicDelete(OsSysTable tableName, String ids) {
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
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();
|
||||
Condition condition = Condition.creatCriteria().andIn(dataMap.getPkName(), dataMap.getIdList()).build();
|
||||
int i = baseMapper.updateByCondition(dataMap, condition);
|
||||
@@ -233,7 +234,7 @@ public class TableServiceImpl implements TableService {
|
||||
if (!StringUtils.isEmpty(webCondition.getCurves())) {
|
||||
builder = WebCondition.setCurves(webCondition, builder);
|
||||
}
|
||||
builder = WebCondition.setSign(webCondition, builder);
|
||||
builder = WebCondition.setSign(webCondition, builder,baseMapper.getDataConfig());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class DataSourceAop {
|
||||
@Before("log()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
if (isMulti) {
|
||||
String key = request.getParameter("datasourceKey");
|
||||
@@ -62,6 +63,7 @@ public class DataSourceAop {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@After("log()")
|
||||
public void doAfter() {
|
||||
|
||||
@@ -12,6 +12,7 @@ public class DataUnit {
|
||||
public static final String MYSQL = "Mysql";
|
||||
public static final String ORACLE = "Oracle";
|
||||
public static final String DAMENG = "Dameng";
|
||||
public static final String HANGO= "HanGO";
|
||||
public static final String MASTERBEAN = "masterDataSource";
|
||||
public static final String DYNAMICBEAN = "dynamicDataSource";
|
||||
public static final String PASSWORD = "******";
|
||||
|
||||
@@ -45,10 +45,10 @@ public class RequestLogAspect {
|
||||
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
Object result = proceedingJoinPoint.proceed();
|
||||
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
if (frameConfig.getShowControllerLog()) {
|
||||
RequestInfo requestInfo = new RequestInfo();
|
||||
requestInfo.setIp(request.getRemoteAddr());
|
||||
@@ -61,12 +61,15 @@ public class RequestLogAspect {
|
||||
requestInfo.setTimeCost(System.currentTimeMillis() - start);
|
||||
LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@AfterThrowing(pointcut = "requestServer()", throwing = "e")
|
||||
public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
|
||||
requestErrorInfo.setIp(request.getRemoteAddr());
|
||||
@@ -78,6 +81,7 @@ public class RequestLogAspect {
|
||||
requestErrorInfo.setException(e);
|
||||
LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取入参
|
||||
|
||||
@@ -80,7 +80,7 @@ public class CustomRealm extends AuthorizingRealm {
|
||||
} else {
|
||||
//1. 根据accessToken,查询用户信息
|
||||
FtToken tokenEntity = shiroService.findByToken(accessToken);
|
||||
userId = tokenEntity.getUserId();
|
||||
userId = String.valueOf(tokenEntity.getUserId());
|
||||
//2. token失效
|
||||
if (tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()) {
|
||||
throw new IncorrectCredentialsException("token失效,请重新登录");
|
||||
|
||||
@@ -29,7 +29,7 @@ public class FtToken implements Serializable {
|
||||
|
||||
private String token;
|
||||
|
||||
private String userId;
|
||||
private Integer userId;
|
||||
|
||||
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.ServiceException;
|
||||
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.FtToken;
|
||||
import com.taixingyiji.base.common.utils.TokenProccessor;
|
||||
@@ -35,7 +38,8 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
|
||||
@Resource
|
||||
FtTokenDao tokenMapper;
|
||||
|
||||
@Resource
|
||||
BaseMapper baseMapper;
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
|
||||
@@ -52,10 +56,11 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
FtToken tokenEntity = new FtToken();
|
||||
Map<String, Object> resultEntity = new HashMap<>();
|
||||
Date now = new Date();
|
||||
// 是否使用redis存入token
|
||||
if (isRedisLogin) {
|
||||
boolean flag = redisUtil.set("session:"+userId, token, EXPIRE / 1000);
|
||||
boolean flag = redisUtil.set("session:" + userId, token, EXPIRE / 1000);
|
||||
if (flag) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("userId", userId);
|
||||
@@ -72,25 +77,42 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
throw new ServiceException("登陆失败");
|
||||
}
|
||||
} else {
|
||||
tokenEntity.setUserId(userId);
|
||||
// tokenEntity.setUserId(userId);
|
||||
//判断是否生成过token
|
||||
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);
|
||||
Condition condition = Condition.creatCriteria().andEqual("USER_ID", userId).build();
|
||||
resultEntity = baseMapper.selectOneByCondition("FT_TOKEN", condition);
|
||||
if (resultEntity == null || resultEntity.isEmpty()) {
|
||||
resultEntity = new HashMap<>();
|
||||
resultEntity.put("TOKEN_ID", UUID.randomUUID().toString() + System.currentTimeMillis());
|
||||
resultEntity.put("USER_ID", userId);
|
||||
resultEntity.put("TOKEN", token);
|
||||
resultEntity.put("UPDATE_TIME", now);
|
||||
resultEntity.put("EXPIRE_TIME", expireTime);
|
||||
baseMapper.save("FT_TOKEN", "TOKEN_ID", resultEntity);
|
||||
} else {
|
||||
tokenEntity.setToken(token);
|
||||
tokenEntity.setUpdateTime(now);
|
||||
tokenEntity.setExpireTime(expireTime);
|
||||
//更新token
|
||||
int i = tokenMapper.updateByPrimaryKey(tokenEntity);
|
||||
resultEntity.put("TOKEN", token);
|
||||
resultEntity.put("UPDATE_TIME", now);
|
||||
resultEntity.put("EXPIRE_TIME", expireTime);
|
||||
int i = baseMapper.updateByPk("FT_TOKEN", "TOKEN_ID", resultEntity);
|
||||
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给前端
|
||||
result.put("token", token);
|
||||
@@ -104,8 +126,8 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
// Map<Object, Object> map = (Map<Object, Object>) redisUtil.get("tokenSession:"+accessToken);
|
||||
String userId = (String) redisUtil.hget("tokenSession:" + accessToken, "userId");
|
||||
// String userId = (String) map.get("userId");
|
||||
redisUtil.del("tokenSession:"+accessToken);
|
||||
redisUtil.del("session:"+userId);
|
||||
redisUtil.del("tokenSession:" + accessToken);
|
||||
redisUtil.del("session:" + userId);
|
||||
return ResultVO.getSuccess();
|
||||
} else {
|
||||
//生成一个token
|
||||
@@ -113,11 +135,15 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
//生成一个token
|
||||
String token = tokenProccessor.makeToken();
|
||||
//修改token
|
||||
FtToken tokenEntity = new FtToken();
|
||||
tokenEntity.setToken(token);
|
||||
Example example = new Example(FtToken.class);
|
||||
example.createCriteria().andEqualTo("token", accessToken);
|
||||
int i = tokenMapper.updateByExampleSelective(tokenEntity, example);
|
||||
// FtToken tokenEntity = new FtToken();
|
||||
// tokenEntity.setToken(token);
|
||||
// Example example = new Example(FtToken.class);
|
||||
// example.createCriteria().andEqualTo("token", accessToken);
|
||||
// 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) {
|
||||
return ResultVO.getSuccess();
|
||||
} else {
|
||||
@@ -129,8 +155,15 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
@Override
|
||||
public FtToken findByToken(String accessToken) {
|
||||
FtToken osToken = new FtToken();
|
||||
osToken.setToken(accessToken);
|
||||
return tokenMapper.selectOne(osToken);
|
||||
// osToken.setToken(accessToken);
|
||||
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
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateInfo" parameterType="map" useGeneratedKeys="true" keyProperty="info.id" keyColumn="id">
|
||||
<update id="updateInfo" parameterType="map">
|
||||
update ${tableName}
|
||||
<set>
|
||||
<foreach collection="info" separator="," item="value" index="key">
|
||||
@@ -96,7 +96,7 @@
|
||||
</set>
|
||||
where id = #{info.id}
|
||||
</update>
|
||||
<update id="updateInfoWithNull" parameterType="map" useGeneratedKeys="true" keyProperty="info.id" keyColumn="id">
|
||||
<update id="updateInfoWithNull" parameterType="map" >
|
||||
update ${tableName}
|
||||
<set>
|
||||
<foreach collection="info.keys" separator="," item="key" index="index">
|
||||
@@ -108,7 +108,7 @@
|
||||
where id = #{info.id}
|
||||
</update>
|
||||
|
||||
<update id="updateByWhere" parameterType="map" useGeneratedKeys="true" keyProperty="info.id">
|
||||
<update id="updateByWhere" parameterType="map" >
|
||||
update ${tableName}
|
||||
<set>
|
||||
<foreach collection="info" separator="," item="value" index="key">
|
||||
@@ -118,7 +118,7 @@
|
||||
${sql}
|
||||
</update>
|
||||
|
||||
<update id="updateByWhereWithNull" parameterType="map" useGeneratedKeys="true" keyProperty="info.id" keyColumn="id">
|
||||
<update id="updateByWhereWithNull" parameterType="map">
|
||||
update ${tableName}
|
||||
<set>
|
||||
<foreach collection="info.keys" separator="," item="key" index="index">
|
||||
@@ -157,6 +157,9 @@
|
||||
select ${tableName}_seq.nextval
|
||||
from dual
|
||||
</select>
|
||||
<select id="getHighGoSequence" resultType="java.lang.Object">
|
||||
select nextval('${tableName}_seq')
|
||||
</select>
|
||||
<insert id="createSequence">
|
||||
CREATE
|
||||
SEQUENCE ${tableName}_seq
|
||||
@@ -167,6 +170,29 @@
|
||||
INCREMENT BY 1
|
||||
NOCACHE
|
||||
</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 count(0) FROM ${tableName} ${sql}
|
||||
</select>
|
||||
@@ -183,8 +209,31 @@
|
||||
VALUES
|
||||
<foreach collection="list" item="row" separator=",">
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<foreach collection="row" item="value">
|
||||
#{value},
|
||||
<foreach collection="row" item="value" separator=",">
|
||||
#{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>
|
||||
</trim>
|
||||
</foreach>
|
||||
|
||||
@@ -229,4 +229,26 @@
|
||||
</properties>
|
||||
</profile>
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user