|
@@ -1,6 +1,7 @@
|
|
|
package com.gis.db.service.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -12,6 +13,7 @@ import com.gis.common.constant.ErrorEnum;
|
|
|
import com.gis.common.util.BaseUtil;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.db.entity.dto.FieldDto;
|
|
|
+import com.gis.db.entity.dto.IdsDto;
|
|
|
import com.gis.db.entity.po.FieldEntity;
|
|
|
import com.gis.db.entity.po.TableEntity;
|
|
|
import com.gis.db.mapper.DdlMapper;
|
|
@@ -49,7 +51,12 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
Long tableId = null;
|
|
|
ArrayList<FieldEntity> list = new ArrayList<>();
|
|
|
for (FieldDto dto : param) {
|
|
|
- BaseRuntimeException.isHas(isExistByTableIdAndName(dto.getTableId(), dto.getName()), null, "字段重复添加");
|
|
|
+
|
|
|
+ // 驼峰转下划线
|
|
|
+ String underLineCase = StrUtil.toUnderlineCase(dto.getName());
|
|
|
+ dto.setName(underLineCase);
|
|
|
+
|
|
|
+ BaseRuntimeException.isTrue(isExistByTableIdAndName(dto.getTableId(), dto.getName()), null, "字段重复添加");
|
|
|
entity = new FieldEntity();
|
|
|
BeanUtils.copyProperties(dto, entity);
|
|
|
list.add(entity);
|
|
@@ -69,9 +76,7 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
|
|
|
@Override
|
|
|
public Result testSql() {
|
|
|
- //alter table ts_aa add age varchar(255);
|
|
|
String sql = "alter table ts_aa add age_1 varchar(255)";
|
|
|
-// ddlMapper.updateSql(sql);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -79,8 +84,6 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
public Result getFieldData(Long tableId, PageDto param) {
|
|
|
BaseUtil.startPage(param);
|
|
|
IPage<Map> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
-// List<String> strs = Arrays.asList("id", "age_2", "age_1");
|
|
|
-// String tableName = "ts_aa";
|
|
|
TableEntity tableEntity = tableService.getById(tableId);
|
|
|
BaseRuntimeException.isNull(tableEntity, ErrorEnum.FAILURE_CODE_3001);
|
|
|
IPage<Map> resPage = getBaseMapper().page(tableEntity.getName(), getFileNames(tableId), page);
|
|
@@ -117,10 +120,44 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * todo 需要校验appId
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result delField(IdsDto param) {
|
|
|
+
|
|
|
+
|
|
|
+ // todo 校验appId
|
|
|
+
|
|
|
+ // 删除表字段
|
|
|
+
|
|
|
+
|
|
|
+ List<String> fieldNames = getFieldName(param.getIds());
|
|
|
+
|
|
|
+ String tableName = "ts_cc";
|
|
|
+ ddlMapper.delFields(tableName, fieldNames);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getFieldName(List<Integer> ids){
|
|
|
+ List<FieldEntity> entityList = this.listByIds(ids);
|
|
|
+ List<String> filedNames = new ArrayList<>();
|
|
|
+ for (FieldEntity entity : entityList) {
|
|
|
+ filedNames.add(entity.getName());
|
|
|
+ }
|
|
|
+ return filedNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 判断该表是否已添加过字段
|
|
|
* @return
|
|
|
*/
|
|
|
private Boolean isExistByTableIdAndName(Long tableId, String filedName){
|
|
|
+
|
|
|
+ filedName = StrUtil.toUnderlineCase(filedName);
|
|
|
+
|
|
|
LambdaQueryWrapper<FieldEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(FieldEntity::getTableId, tableId);
|
|
|
wrapper.eq(FieldEntity::getName, filedName);
|