|
@@ -10,6 +10,7 @@ import com.gis.common.base.entity.dto.PageDto;
|
|
|
import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
import com.gis.common.constant.ErrorEnum;
|
|
|
import com.gis.common.util.BaseUtil;
|
|
|
+import com.gis.common.util.RedisUtil;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.db.entity.dto.FieldDto;
|
|
|
import com.gis.db.entity.dto.FieldPageDto;
|
|
@@ -20,15 +21,16 @@ import com.gis.db.entity.po.TableEntity;
|
|
|
import com.gis.db.entity.vo.FieldVo;
|
|
|
import com.gis.db.mapper.DdlMapper;
|
|
|
import com.gis.db.mapper.FieldMapper;
|
|
|
-import com.gis.db.service.DdlService;
|
|
|
import com.gis.db.service.FieldService;
|
|
|
import com.gis.db.service.TableService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* Created by owen on 2022/3/10 0010 17:29
|
|
@@ -37,8 +39,7 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> implements FieldService {
|
|
|
|
|
|
- @Autowired
|
|
|
- DdlService ddlService;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
TableService tableService;
|
|
@@ -46,6 +47,17 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
@Autowired
|
|
|
DdlMapper ddlMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ static final String TABLE_KEY = "table:";
|
|
|
+
|
|
|
+ static final String FIELD_TABLE_KEY = "fieldTable:";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Result addField(List<FieldDto> param) {
|
|
|
|
|
@@ -70,7 +82,11 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
this.saveBatch(list);
|
|
|
|
|
|
// 添加字段到表
|
|
|
- ddlService.addField(list, tableEntity.getName());
|
|
|
+ tableService.addField(list, tableEntity.getName());
|
|
|
+
|
|
|
+ // 删除缓存
|
|
|
+ String fieldTableKey = FIELD_TABLE_KEY+tableId;
|
|
|
+ redisUtil.delete(fieldTableKey);
|
|
|
|
|
|
|
|
|
return Result.success();
|
|
@@ -112,11 +128,15 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
// todo 校验appId
|
|
|
|
|
|
// 删除表字段
|
|
|
-
|
|
|
List<Integer> ids = param.getIds();
|
|
|
List<String> fieldNames = getFieldName(ids);
|
|
|
|
|
|
- String tableName = getTableNameByFieldId(ids.get(0));
|
|
|
+// String tableName = getTableNameByFieldId(ids.get(0));
|
|
|
+
|
|
|
+ TableEntity tableEntity = tableService.getTableByFieldId(ids.get(0));
|
|
|
+ BaseRuntimeException.isNull(tableEntity, null, "该表不存在");
|
|
|
+ String tableName = tableEntity.getName();
|
|
|
+ Long tableId = tableEntity.getId();
|
|
|
|
|
|
for (String name : fieldNames) {
|
|
|
// 检查字段是否存在
|
|
@@ -132,6 +152,10 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
this.removeByIds(ids);
|
|
|
|
|
|
|
|
|
+ // 删除缓存
|
|
|
+ String fieldTableKey = FIELD_TABLE_KEY+tableId;
|
|
|
+ redisUtil.delete(fieldTableKey);
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -139,6 +163,8 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
return getBaseMapper().getTableNameByFieldId(id);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Result getList(FieldPageDto param) {
|
|
|
BaseUtil.startPage(param);
|
|
@@ -198,6 +224,12 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result upload(MultipartFile file, String tableName) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private List<String> getFieldName(List<Integer> ids){
|
|
|
List<FieldEntity> entityList = this.listByIds(ids);
|
|
|
List<String> filedNames = new ArrayList<>();
|
|
@@ -222,17 +254,25 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
return count != 0;
|
|
|
}
|
|
|
|
|
|
- private List<FieldEntity> findByTableId(Long tableId){
|
|
|
+ private List<FieldEntity> cacheByTableId(Long tableId){
|
|
|
+ String tableKey = FIELD_TABLE_KEY + tableId;
|
|
|
+ if (redisUtil.hasKey(tableKey)){
|
|
|
+ return redisUtil.getCacheObject(tableKey);
|
|
|
+ }
|
|
|
+
|
|
|
LambdaQueryWrapper<FieldEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(FieldEntity::getTableId, tableId);
|
|
|
List<FieldEntity> list = this.list(wrapper);
|
|
|
BaseRuntimeException.isEmpty(list, ErrorEnum.FAILURE_SYS_2011);
|
|
|
+
|
|
|
+ redisUtil.setCacheObject(tableKey, list, 5, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
// 获取字段名称
|
|
|
private List<String> getFileNames(Long tableId){
|
|
|
- List<FieldEntity> list = findByTableId(tableId);
|
|
|
+ List<FieldEntity> list = cacheByTableId(tableId);
|
|
|
ArrayList<String> fileNames = new ArrayList<>();
|
|
|
for (FieldEntity entity : list) {
|
|
|
fileNames.add(entity.getName());
|
|
@@ -244,10 +284,26 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
return fileNames;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取搜索字段
|
|
|
+ * @param tableId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getSearchField(Long tableId){
|
|
|
+ List<FieldEntity> list = cacheByTableId(tableId);
|
|
|
+ ArrayList<String> fileNames = new ArrayList<>();
|
|
|
+ for (FieldEntity entity : list) {
|
|
|
+ if (entity.getIsQuery() == 1){
|
|
|
+ fileNames.add(entity.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileNames;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
private Map getMapByTableId(Long tableId){
|
|
|
- List<FieldEntity> list = findByTableId(tableId);
|
|
|
+ List<FieldEntity> list = cacheByTableId(tableId);
|
|
|
|
|
|
Map filedMap = new HashMap();
|
|
|
FieldVo vo ;
|
|
@@ -269,7 +325,7 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
}
|
|
|
|
|
|
private List<Object> gertFieldListByTableId(Long tableId){
|
|
|
- List<FieldEntity> list = findByTableId(tableId);
|
|
|
+ List<FieldEntity> list = cacheByTableId(tableId);
|
|
|
|
|
|
List<Object> fields = new ArrayList<>();
|
|
|
FieldVo vo ;
|
|
@@ -292,7 +348,11 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
IPage<Map> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
TableEntity tableEntity = tableService.getById(tableId);
|
|
|
BaseRuntimeException.isNull(tableEntity, ErrorEnum.FAILURE_CODE_3001);
|
|
|
- IPage<Map> resPage = getBaseMapper().page(tableEntity.getName(), getFileNames(tableId), page);
|
|
|
+
|
|
|
+ List<String> searchField = getSearchField(tableId);
|
|
|
+ List<String> fileNames = getFileNames(tableId);
|
|
|
+// IPage<Map> resPage = getBaseMapper().page(tableEntity.getName(), fileNames, searchField, param.getSearchKey(), page);
|
|
|
+ IPage<Map> resPage = getBaseMapper().page(tableEntity.getName(), searchField, param.getSearchKey(), page);
|
|
|
|
|
|
Map resultMap = new HashMap();
|
|
|
resultMap.put("fieldNames", gertFieldListByTableId(tableId));
|