feat: add highgo support

This commit is contained in:
2025-03-28 18:34:20 +08:00
parent 30aaef565c
commit 583b5864d5
6 changed files with 93 additions and 42 deletions

View File

@@ -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>

View File

@@ -58,6 +58,9 @@ public class BaseMapperImpl implements BaseMapper {
if (dataType.contains("sqlite")) {
datasourceConfig.setCommonType(DataUnit.SQLITE);
}
if(dataType.contains("highgo")) {
datasourceConfig.setCommonType(DataUnit.HANGO);
}
}
JudgesNull(dataMap.getData(), "data can not be null!");
JudgesNull(dataMap.getTableName(), "tableName can not be null!");
@@ -65,7 +68,7 @@ public class BaseMapperImpl implements BaseMapper {
dataMap.setPkName("ID");
}
int i;
if (DataUnit.ORACLE.equals(datasourceConfig.getCommonType()) || DataUnit.DAMENG.equals(datasourceConfig.getCommonType())) {
if (DataUnit.ORACLE.equals(datasourceConfig.getCommonType()) || DataUnit.DAMENG.equals(datasourceConfig.getCommonType()) || DataUnit.HANGO.equals(datasourceConfig.getCommonType())) {
if (org.springframework.util.StringUtils.isEmpty(dataMap.get(dataMap.getPkName()))) {
Object id = getSequence(dataMap.getTableName(), dataMap.getPkName());
dataMap.toBuilder().add(dataMap.getPkName(), id);
@@ -82,10 +85,14 @@ public class BaseMapperImpl implements BaseMapper {
return i;
}
private String formatTable(String tableName) {
return "`"+tableName+"`";
}
@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!");
tableName = formatTable(tableName);
String key;
DatasourceConfig datasourceConfig = new DatasourceConfig();
try {
@@ -132,6 +139,7 @@ public class BaseMapperImpl implements BaseMapper {
private int updateByWhere(Condition condition, String tableName, Map<String, Object> data) {
Map<String, Object> params = condition.getParamMap();
tableName = formatTable(tableName);
params.put("tableName", tableName);
params.put("info", data);
params.put("sql", condition.getSql());
@@ -244,6 +252,7 @@ public class BaseMapperImpl implements BaseMapper {
private int deleteByWhere(Condition condition, String tableName) {
Map<String, Object> params = condition.getParamMap();
tableName = formatTable(tableName);
params.put("tableName", tableName);
params.put("sql", condition.getSql());
return sqlSessionTemplate.delete(TABLE_MAPPER_PACKAGE + "deleteByWhere", params);
@@ -330,6 +339,7 @@ public class BaseMapperImpl implements BaseMapper {
@Override
public List<Map<String, Object>> selectAll(String tableName) {
JudgesNull(tableName, "tableName can not be null!");
tableName = formatTable(tableName);
return tableMapper.useSql(SelectCondition.builder().tableName(tableName).build().getSql());
}
@@ -734,7 +744,7 @@ public class BaseMapperImpl implements BaseMapper {
String key = entry.getKey();
Object value = entry.getValue();
if (!key.equals(pkName) && value != null && !(value instanceof String && ((String) value).isEmpty())) {
sql.append(key).append(" = #{item").append(index).append("_").append(key).append("}, ");
sql.append("`").append(key).append("`").append(" = #{item").append(index).append("_").append(key).append("}, ");
paramMap.put("item" + index + "_" + key, value);
hasSetClause = true;
}
@@ -746,7 +756,7 @@ public class BaseMapperImpl implements BaseMapper {
// 如果没有要更新的字段,跳过这条记录
continue;
}
sql.append(" WHERE ").append(pkName).append(" = #{item").append(index).append("_").append(pkName).append("};");
sql.append(" WHERE ").append("`").append(pkName).append("`").append(" = #{item").append(index).append("_").append(pkName).append("};");
paramMap.put("item" + index + "_" + pkName, item.get(pkName));
index++;
}
@@ -769,7 +779,7 @@ public class BaseMapperImpl implements BaseMapper {
try {
id = tableMapper.getSequence(tableName);
} catch (Exception e) {
MyPageHelper.start(WebPageInfo.builder().pageNum(1).pageSize(1).order(WebPageInfo.DESC).sortField(pkName).build());
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();
Map<String, Object> map = selectOneByCondition(condition);

View File

@@ -273,7 +273,7 @@ public class Condition implements Serializable {
value = value.toString().replaceAll("\"", "");
}
String sqlKey = "item_" + IdUtil.fastUUID();
this.conditionSql += " " + key + EQUAL + "#{" + sqlKey + "}";
this.conditionSql += " `" + key +"` "+ EQUAL + "#{" + sqlKey + "}";
this.paramMap.put(sqlKey, value);
return this;
}
@@ -290,7 +290,7 @@ public class Condition implements Serializable {
public ConditionBuilder like(String key, Object value) {
sqlCheckLike(value);
this.conditionSql += " " + key + " " + LIKE + " '" + value + "'";
this.conditionSql += " `" + key +"` "+ " " + LIKE + " '" + value + "'";
return this;
}
@@ -318,7 +318,7 @@ public class Condition implements Serializable {
i++;
}
inStr.append(R_CURVES);
this.conditionSql += " " + key + " " + IN + " " + inStr.toString();
this.conditionSql += " `" + key +"` "+ " " + IN + " " + inStr.toString();
return this;
}
@@ -337,7 +337,7 @@ public class Condition implements Serializable {
String sqlKey2 = "item_" + IdUtil.fastUUID();
this.paramMap.put(sqlKey, start);
this.paramMap.put(sqlKey2, end);
this.conditionSql += " " + key + " " + BETWEEN + " #{" + sqlKey + "} " + AND + " #{" + sqlKey2 + "} ";
this.conditionSql += " `" + key +"` "+ " " + BETWEEN + " #{" + sqlKey + "} " + AND + " #{" + sqlKey2 + "} ";
return this;
}
@@ -354,7 +354,7 @@ public class Condition implements Serializable {
public ConditionBuilder lt(String key, Object value) {
String sqlKey = "item_" + IdUtil.fastUUID();
this.paramMap.put(sqlKey, value);
this.conditionSql += " " + key + " " + LT + " #{" + sqlKey + "} ";
this.conditionSql += " `" + key +"` "+ " " + LT + " #{" + sqlKey + "} ";
return this;
}
@@ -376,7 +376,7 @@ public class Condition implements Serializable {
public ConditionBuilder notEqual(String key, Object value) {
String sqlKey = "item_" + IdUtil.fastUUID();
this.paramMap.put(sqlKey, value);
this.conditionSql += " " + key + " " + NOT_EQUAL + " #{" + sqlKey + "} ";
this.conditionSql += " `" + key +"` "+ " " + NOT_EQUAL + " #{" + sqlKey + "} ";
return this;
}
@@ -393,7 +393,7 @@ public class Condition implements Serializable {
public ConditionBuilder gt(String key, Object value) {
String sqlKey = "item_" + IdUtil.fastUUID();
this.paramMap.put(sqlKey, value);
this.conditionSql += " " + key + " " + GT + " #{" + sqlKey + "} ";
this.conditionSql += " `" + key +"` "+ " " + GT + " #{" + sqlKey + "} ";
return this;
}
@@ -410,7 +410,7 @@ public class Condition implements Serializable {
public ConditionBuilder lte(String key, Object value) {
String sqlKey = "item_" + IdUtil.fastUUID();
this.paramMap.put(sqlKey, value);
this.conditionSql += " " + key + " " + LTE + " #{" + value.toString() + "} ";
this.conditionSql += " `" + key +"` "+ " " + LTE + " #{" + value.toString() + "} ";
return this;
}
@@ -427,7 +427,7 @@ public class Condition implements Serializable {
public ConditionBuilder gte(String key, Object value) {
String sqlKey = "item_" + IdUtil.fastUUID();
this.paramMap.put(sqlKey, value);
this.conditionSql += " " + key + " " + GTE + " #{" + value.toString() + "} ";
this.conditionSql += " `" + key +"` "+ " " + GTE + " #{" + value.toString() + "} ";
return this;
}

View File

@@ -113,7 +113,7 @@ public class SelectCondition implements Serializable {
}
public SelectBuilder tableName(String tableName) {
this.tableName = tableName;
this.tableName = "`"+tableName+"`";
return this;
}

View File

@@ -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 = "******";

View File

@@ -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().equal("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((String) map.get("USER_ID"));
osToken.setExpireTime((Date) map.get("EXPIRE_TIME"));
osToken.setUpdateTime((Date) map.get("UPDATE_TIME"));
return osToken;
}
@Override