修复框架tableInfo不失效问题,修改数据平台对象保存空字符串异常问题

This commit is contained in:
lhc
2021-03-19 10:41:32 +08:00
parent b9ccc48445
commit f792d8feeb
10 changed files with 71 additions and 20 deletions

View File

@@ -53,6 +53,13 @@ public class ObjectUtil {
String fieldName = field.getName();
if (field.getAnnotation(Id.class) != null) {
dataMap = dataMap.toBuilder().pkName(StringUtils.toUnderScoreUpperCase(fieldName)).build();
try {
if (!org.springframework.util.StringUtils.isEmpty(field.get(obj))) {
dataMap.setPkValue(field.get(obj));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
try {
if (!fieldName.equals(SERIAL_VERSION_UID)) {
@@ -87,6 +94,13 @@ public class ObjectUtil {
String fieldName = field.getName();
if (field.getAnnotation(Id.class) != null) {
dataMap = dataMap.pkName(StringUtils.toUnderScoreUpperCase(fieldName));
try {
if (!org.springframework.util.StringUtils.isEmpty(field.get(obj))) {
dataMap.pkValue(field.get(obj));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
try {
if (!fieldName.equals(SERIAL_VERSION_UID)) {

View File

@@ -109,7 +109,7 @@ public class TableCache implements CacheService {
@Override
public boolean delete(String typeName) {
return false;
return baseCache.delete(CacheType.tableCache.toString(), typeName);
}
@Override

View File

@@ -1,9 +1,7 @@
package com.hcframe.base.module.data.module;
import com.alibaba.druid.pool.DruidDataSource;
import com.hcframe.base.common.WebPageInfo;
import com.hcframe.base.common.utils.MyPageHelper;
import com.hcframe.base.common.utils.SpringContextUtil;
import com.hcframe.base.common.utils.StringUtils;
import com.hcframe.base.module.data.dao.TableMapper;
import com.hcframe.base.module.data.exception.BaseMapperException;
@@ -626,7 +624,11 @@ public class BaseMapperImpl implements BaseMapper {
DataMap<Object> dataMap = DataMap.builder().tableName(tableName).pkName(pkName).fields(pkName).build();
Condition condition = Condition.creatCriteria(dataMap).build();
Map<String, Object> map = selectOneByCondition(condition);
tableMapper.createSequence(tableName, map.get(pkName));
if (map == null) {
tableMapper.createSequence(tableName, 1);
} else {
tableMapper.createSequence(tableName, map.get(pkName));
}
id = tableMapper.getSequence(tableName);
}
return Long.parseLong(id.toString())+1L;

View File

@@ -47,7 +47,7 @@ public class WebCondition {
public static Condition.ConditionBuilder setSign(WebCondition webCondition,Condition.ConditionBuilder builder) {
switch (webCondition.getSign()) {
case QueryConstants.LIKE:{
return builder.like(webCondition.key, webCondition.value);
return builder.like(webCondition.key, "%"+webCondition.value+"%");
}
case QueryConstants.EQUAL:{
return builder.equal(webCondition.key,webCondition.value);

View File

@@ -15,6 +15,6 @@ import java.util.List;
*/
public interface OsSysFieldDao extends Mapper<OsSysField> {
List<Integer> getTableId(@Param("ids") String ids);
List<String> getTableAlise(@Param("ids") String ids);
}

View File

@@ -77,8 +77,6 @@ public class TableConfigServiceImpl implements TableConfigService {
if (list != null && list.size() > 0) {
return ResultVO.getFailed("表别名重复,请修改后提交!");
}
// DataMap<OsSysTable> dataMap = DataMap.<OsSysTable>builder().obj(osSysTable).build();
// baseMapper.save(dataMap);
baseMapper.save(osSysTable);
tableCache.save(CacheType.tableCache, osSysTable.getTableAlias(), osSysTable, OsSysTable.class);
return ResultVO.getSuccess(osSysTable);
@@ -92,6 +90,9 @@ public class TableConfigServiceImpl implements TableConfigService {
Example queryExample = new Example(OsSysTable.class);
queryExample.createCriteria().andIn("tableId", Arrays.asList(idArr));
List<OsSysTable> osSysTables = osSysTableMapper.selectByExample(queryExample);
for (OsSysTable osSysTable : osSysTables) {
tableCache.delete(osSysTable.getTableAlias());
}
Example fieldExample = new Example(OsSysField.class);
fieldExample.createCriteria().andIn("tableId", Arrays.asList(idArr));
List<OsSysField> osSysFields = osSysFieldDao.selectByExample(fieldExample);
@@ -112,6 +113,7 @@ public class TableConfigServiceImpl implements TableConfigService {
@Override
@Transactional(rollbackFor = Exception.class)
public ResultVO updateTable(OsSysTable osSysTable) {
tableCache.delete(osSysTable.getTableAlias());
List<OsSysTable> osSysTables = osSysTableMapper.select(OsSysTable.builder().tableAlias(osSysTable.getTableAlias()).build());
if (osSysTables.size() > 1) {
return ResultVO.getFailed("表别名设置重复");
@@ -157,6 +159,7 @@ public class TableConfigServiceImpl implements TableConfigService {
DataMap<OsSysField> dataMap = DataMap.<OsSysField>builder().obj(osSysField).build();
baseMapper.save(dataMap);
OsSysTable osSysTable = osSysTableMapper.selectOne(OsSysTable.builder().tableId(osSysField.getTableId()).build());
tableCache.delete(osSysTable.getTableAlias());
return ResultVO.getSuccess();
}
@@ -166,6 +169,7 @@ public class TableConfigServiceImpl implements TableConfigService {
int i = osSysFieldDao.updateByPrimaryKeySelective(osSysField);
SqlException.operation(i, "修改字段信息失败");
OsSysTable osSysTable = osSysTableMapper.selectOne(OsSysTable.builder().tableId(osSysField.getTableId()).build());
tableCache.delete(osSysTable.getTableAlias());
return ResultVO.getSuccess();
}
@@ -177,7 +181,10 @@ public class TableConfigServiceImpl implements TableConfigService {
fieldExample.createCriteria().andIn("fieldId", Arrays.asList(idArr));
Example selectExample = new Example(OsSysField.class);
selectExample.createCriteria().andIn("fieldId", Arrays.asList(idArr));
List<Integer> list = osSysFieldDao.getTableId(ids);
List<String> list = osSysFieldDao.getTableAlise(ids);
for (String tableAlise : list) {
tableCache.delete(tableAlise);
}
int i = osSysFieldDao.deleteByExample(fieldExample);
SqlException.operation(i, "删除字段信息失败");
i = osSysSelectDao.deleteByExample(selectExample);
@@ -195,6 +202,10 @@ public class TableConfigServiceImpl implements TableConfigService {
public ResultVO saveSelectInfo(OsSysSelect osSysSelect) {
DataMap<OsSysSelect> dataMap = DataMap.<OsSysSelect>builder().obj(osSysSelect).build();
baseMapper.save(dataMap);
List<String> list = osSysFieldDao.getTableAlise(osSysSelect.getFieldId().toString());
for (String tableAlise : list) {
tableCache.delete(tableAlise);
}
return ResultVO.getSuccess();
}
@@ -202,6 +213,10 @@ public class TableConfigServiceImpl implements TableConfigService {
public ResultVO updateSelectInfo(OsSysSelect osSysSelect) {
int i = osSysSelectDao.updateByPrimaryKeySelective(osSysSelect);
if (i > 0) {
List<String> list = osSysFieldDao.getTableAlise(osSysSelect.getFieldId().toString());
for (String tableAlise : list) {
tableCache.delete(tableAlise);
}
return ResultVO.getSuccess();
} else {
return ResultVO.getFailed("更新下拉选项失败");
@@ -212,8 +227,19 @@ public class TableConfigServiceImpl implements TableConfigService {
public ResultVO deleteSelectInfo(String ids) {
Example example = new Example(OsSysSelect.class);
example.createCriteria().andIn("selectId", Arrays.asList(ids.split(",")));
List<OsSysSelect> selects = osSysSelectDao.selectByExample(example);
int i = osSysSelectDao.deleteByExample(example);
if (i > 0) {
StringBuilder stringBuilder = new StringBuilder();
for (OsSysSelect osSysSelect : selects) {
stringBuilder.append(osSysSelect.getFieldId()).append(",");
}
if (selects.size() > 0) {
List<String> list = osSysFieldDao.getTableAlise(stringBuilder.substring(0,stringBuilder.length()));
for (String tableAlise : list) {
tableCache.delete(tableAlise);
}
}
return ResultVO.getSuccess();
} else {
return ResultVO.getFailed("删除下拉选项失败");

View File

@@ -19,9 +19,13 @@
<result column="IS_SEARCH" jdbcType="VARCHAR" property="isSearch" />
<collection property="selectList" resultMap="com.hcframe.base.module.tableconfig.dao.OsSysSelectDao.OsSysSelectMap"/>
</resultMap>
<select id="getTableId" resultType="java.lang.Integer">
SELECT DISTINCT TABLE_ID
FROM OS_SYS_FIELD
WHERE FIELD_ID IN (${ids});
<select id="getTableAlise" resultType="java.lang.String">
SELECT DISTINCT
TABLE_ALIAS
FROM
OS_SYS_TABLE
LEFT JOIN OS_SYS_FIELD ON OS_SYS_TABLE.TABLE_ID = OS_SYS_FIELD.TABLE_ID
WHERE
FIELD_ID IN (${ids})
</select>
</mapper>

View File

@@ -1,6 +1,5 @@
package com.hcframe.config;
import net.unicon.cas.client.configuration.EnableCasClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -19,7 +18,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableCaching
@EnableDiscoveryClient
@EnableFeignClients
@EnableCasClient
//@EnableCasClient
@ComponentScan(basePackages = {"com.hcframe.**"})
public class ConfigApplication {
public static void main(String[] args) {

View File

@@ -143,13 +143,15 @@
<!--当前环境-->
<profile.name>dev</profile.name>
<!--Nacos配置中心地址-->
<config.server-addr>192.168.100.98:8848</config.server-addr>
<config.server-addr>taixingyiji.synology.me:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID不能使用名称,默认为空-->
<config.namespace>2e9f0148-751e-4da2-83ec-cb00ffe0d83a</config.namespace>
<config.namespace>686efed2-0f46-4f3f-9a67-10e858ee1d44</config.namespace>
<!--Nacos配置分组名称-->
<config.group>DEFAULT_GROUP</config.group>
<config.username>dev</config.username>
<config.password>123456</config.password>
<!-- Nacos服务发现地址-->
<discovery.server-addr>192.168.100.98:8848</discovery.server-addr>
<discovery.server-addr>taixingyiji.synology.me:8848</discovery.server-addr>
<!-- redis 配置-->
<redis.database>0</redis.database>
<redis.host>192.168.4.119</redis.host>
@@ -157,10 +159,10 @@
<redis.password/>
<!-- cas配置 -->
<cas.client-context-path>/user/cas/valid</cas.client-context-path>
<cas.cas-service-url>http://192.168.100.98:8080</cas.cas-service-url>
<cas.cas-service-url>http://taixingyiji.synology.me:8081</cas.cas-service-url>
<cas.cas-context-path>/cas</cas.cas-context-path>
<cas.white-url>^.*(/logout?)$</cas.white-url>
<cas.service-url>http://192.168.1.130:8084</cas.service-url>
<cas.service-url>http://localhost:8084</cas.service-url>
<cas.cookie-holder-pattern>com.hcframe.gateway.config.MyDataStorage</cas.cookie-holder-pattern>
<cas.login-url>/login</cas.login-url>
<cas.logout-url>/logout</cas.logout-url>
@@ -176,6 +178,8 @@
<config.namespace>2e9f0148-751e-4da2-83ec-cb00ffe0d83a</config.namespace>
<!--Nacos配置分组名称-->
<config.group>DEFAULT_GROUP</config.group>
<config.username>dev</config.username>
<config.password>123456</config.password>
<!-- Nacos服务发现地址-->
<discovery.server-addr>192.168.100.98:8848</discovery.server-addr>
<!-- redis 配置-->
@@ -205,6 +209,8 @@
<config.namespace></config.namespace>
<!--Nacos配置分组名称-->
<config.group>DEFAULT_GROUP</config.group>
<config.username>dev</config.username>
<config.password>123456</config.password>
<!--Nacos服务发现地址-->
<discovery.server-addr>127.0.0.1:8848</discovery.server-addr>
<redis.database>0</redis.database>