|
@@ -14,8 +14,10 @@ import com.gis.common.util.Result;
|
|
|
import com.gis.db.entity.dto.FieldDto;
|
|
|
import com.gis.db.entity.dto.FieldPageDto;
|
|
|
import com.gis.db.entity.dto.IdsDto;
|
|
|
+import com.gis.db.entity.dto.RecordDto;
|
|
|
import com.gis.db.entity.po.FieldEntity;
|
|
|
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;
|
|
@@ -150,6 +152,52 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
return Result.success(iPage);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加数据
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result insertRecord(RecordDto param) {
|
|
|
+
|
|
|
+ String tableName = tableService.getTableName(param.getTableId());
|
|
|
+
|
|
|
+ Map<String, Object> record = param.getRecord();
|
|
|
+ // 字段
|
|
|
+ List<String> fieldList = new ArrayList<>();
|
|
|
+ // 字段对应的值
|
|
|
+ List<Object> fieldData = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, Object> entry : record.entrySet()) {
|
|
|
+ fieldList.add(entry.getKey());
|
|
|
+ fieldData.add(entry.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ ddlMapper.insertRecord(tableName, fieldList, fieldData);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result delRecord(String tableId, String ids) {
|
|
|
+ String tableName = tableService.getTableName(tableId);
|
|
|
+ ddlMapper.delRecord(tableName, ids);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updateRecord(RecordDto param) {
|
|
|
+ String tableName = tableService.getTableName(param.getTableId());
|
|
|
+
|
|
|
+ String id = param.getId();
|
|
|
+ BaseRuntimeException.isBlank(id, null, "数据id不能为空");
|
|
|
+
|
|
|
+ // 字段对应的值
|
|
|
+ Map<String, Object> record = param.getRecord();
|
|
|
+
|
|
|
+ ddlMapper.updateRecord(tableName, id, record);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
private List<String> getFieldName(List<Integer> ids){
|
|
|
List<FieldEntity> entityList = this.listByIds(ids);
|
|
|
List<String> filedNames = new ArrayList<>();
|
|
@@ -198,23 +246,45 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
|
|
|
|
|
|
|
|
|
- private Map getResultByTableId(Long tableId){
|
|
|
+ private Map getMapByTableId(Long tableId){
|
|
|
List<FieldEntity> list = findByTableId(tableId);
|
|
|
|
|
|
Map filedMap = new HashMap();
|
|
|
+ FieldVo vo ;
|
|
|
for (FieldEntity entity : list) {
|
|
|
filedMap.put(entity.getName(), entity.getType());
|
|
|
+ vo = new FieldVo();
|
|
|
+ BeanUtils.copyProperties(entity, vo);
|
|
|
+ filedMap.put(entity.getName(), vo);
|
|
|
}
|
|
|
|
|
|
// 添加默认字段: 使用数据库下划线命名
|
|
|
- filedMap.put("id", "int");
|
|
|
- filedMap.put("create_time", "date");
|
|
|
- filedMap.put("update_time", "date");
|
|
|
- filedMap.put("creator_id", "int");
|
|
|
+ filedMap.put("id", new FieldVo("id", "int", "业务id", 8));
|
|
|
+ filedMap.put("create_time", new FieldVo("create_time", "date", "创建时间", 0));
|
|
|
+ filedMap.put("update_time", new FieldVo("update_time", "date", "修改时间", 0));
|
|
|
+ filedMap.put("creator_id", new FieldVo("creator_id", "int", "创建者id", 8));
|
|
|
+
|
|
|
|
|
|
return filedMap;
|
|
|
}
|
|
|
|
|
|
+ private List<Object> gertFieldListByTableId(Long tableId){
|
|
|
+ List<FieldEntity> list = findByTableId(tableId);
|
|
|
+
|
|
|
+ List<Object> fields = new ArrayList<>();
|
|
|
+ FieldVo vo ;
|
|
|
+ for (FieldEntity entity : list) {
|
|
|
+ vo = new FieldVo();
|
|
|
+ BeanUtils.copyProperties(entity, vo);
|
|
|
+ fields.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加默认字段: 使用数据库下划线命名
|
|
|
+ fields.add(new FieldVo("id", "int", "业务id", 8));
|
|
|
+ fields.add(new FieldVo("update_time", "date", "修改时间", 0));
|
|
|
+ return fields;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result getFieldData(Long tableId, PageDto param) {
|
|
@@ -225,7 +295,7 @@ public class FieldServiceImpl extends ServiceImpl<FieldMapper, FieldEntity> impl
|
|
|
IPage<Map> resPage = getBaseMapper().page(tableEntity.getName(), getFileNames(tableId), page);
|
|
|
|
|
|
Map resultMap = new HashMap();
|
|
|
- resultMap.put("fieldNames", getResultByTableId(tableId));
|
|
|
+ resultMap.put("fieldNames", gertFieldListByTableId(tableId));
|
|
|
resultMap.put("fieldData", resPage);
|
|
|
|
|
|
return Result.success(resultMap);
|