|
@@ -0,0 +1,505 @@
|
|
|
+package com.xxh.cloud.metadata.framework.modules.base.biz.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.xxh.cloud.framework.common.constant.DataSourceTypeEnum;
|
|
|
+import com.xxh.cloud.framework.common.constant.YN;
|
|
|
+import com.xxh.cloud.framework.common.exception.BusinessBaseErrorEnum;
|
|
|
+import com.xxh.cloud.framework.common.exception.BusinessException;
|
|
|
+import com.xxh.cloud.framework.common.mybatisplus.page.PageConverter;
|
|
|
+import com.xxh.cloud.framework.common.page.PageData;
|
|
|
+import com.xxh.cloud.framework.common.redis.RedisUtils;
|
|
|
+import com.xxh.cloud.framework.common.validator.ValidatorUtils;
|
|
|
+import com.xxh.cloud.log.bean.constant.ModuleTypeEnum;
|
|
|
+import com.xxh.cloud.log.bean.constant.ObjectTypeEnum;
|
|
|
+import com.xxh.cloud.log.bean.constant.OperationTypeEnum;
|
|
|
+import com.xxh.cloud.log.utils.OperationLogUtils;
|
|
|
+import com.xxh.cloud.metadata.client.api.MetadataClientService;
|
|
|
+import com.xxh.cloud.metadata.client.api.bean.bos.meta.MetadataBO;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.entity.dos.TableColumnInfo;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.entity.dos.TableInfo;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.entity.dto.*;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.service.TableColumnInfoService;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.service.TableInfoService;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.entity.vos.TableCategoryVO;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.entity.vos.TableInfoVO;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.helper.TableInfoHelper;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.base.biz.TableInfoBizService;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.cache.helper.MetaDataCacheKeysHelper;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.cache.service.TableCategoryCacheService;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.cache.service.TableInfoCacheService;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.tableData.bean.dto.EntityCreate2AlterByTableDTO;
|
|
|
+import com.xxh.cloud.metadata.framework.modules.tableData.biz.TableGenerateBizService;
|
|
|
+import com.xxh.cloud.user.client.api.AdminUserClientService;
|
|
|
+import com.xxh.cloud.user.client.api.bean.bos.AdminUserBO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class TableInfoBizServiceImpl implements TableInfoBizService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TableInfoService tableInfoService;
|
|
|
+ @Autowired
|
|
|
+ private TableColumnInfoService tableColumnInfoService;
|
|
|
+ @Autowired
|
|
|
+ private AdminUserClientService adminUserClientService;
|
|
|
+ @Autowired
|
|
|
+ private TableCategoryCacheService tableCategoryCacheService;
|
|
|
+ @Autowired
|
|
|
+ private MetadataClientService metadataClientService;
|
|
|
+ @Autowired
|
|
|
+ private TableGenerateBizService tableGenerateBizService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TableInfoCacheService tableInfoCacheService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageData<TableInfoVO> query(TableInfoQueryDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+
|
|
|
+ IPage<TableInfo> page = tableInfoService.page(new Page<>(params.getPage(), params.getRows()),
|
|
|
+ new QueryWrapper<TableInfo>()
|
|
|
+ .eq("rows_status", YN.YES.getCode())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getId()),"id",params.getId())
|
|
|
+ .in(CollUtil.isNotEmpty(params.getIds()),"id",params.getIds())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getCategoryId()),"category_id",params.getCategoryId())
|
|
|
+ .like(StrUtil.isNotEmpty(params.getName()),"name",params.getName())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getRelType()),"rel_type",params.getRelType())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getRelId()),"rel_id",params.getRelId())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getProjectCode()),"project_code",params.getProjectCode())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getStatus()),"status",params.getStatus())
|
|
|
+ );
|
|
|
+
|
|
|
+ if(page==null || CollUtil.isEmpty(page.getRecords())){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> tableIds=new HashSet<>();
|
|
|
+ Set<String> categoryIds=new HashSet<>();
|
|
|
+ Set<String> userIds=new HashSet<>();
|
|
|
+ page.getRecords().forEach(item->{
|
|
|
+ tableIds.add(item.getId());
|
|
|
+
|
|
|
+ if(StrUtil.isNotEmpty(item.getCategoryId())){
|
|
|
+ categoryIds.add(item.getCategoryId());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(item.getCreator())){
|
|
|
+ userIds.add(item.getCreator());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(item.getUpdater())){
|
|
|
+ userIds.add(item.getUpdater());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, AdminUserBO> userMap= adminUserClientService.getUserMapByIds(userIds);
|
|
|
+ Map<String, TableCategoryVO> categoryMap= tableCategoryCacheService.getMapByIds(categoryIds);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(params.isCols()){
|
|
|
+ List<TableColumnInfo> columnList= tableColumnInfoService.list(
|
|
|
+ new QueryWrapper<TableColumnInfo>()
|
|
|
+ .in("table_id",tableIds)
|
|
|
+ );
|
|
|
+ Set<String> metadataIds=new HashSet<>();
|
|
|
+ columnList.forEach(item->{
|
|
|
+ if(StrUtil.isNotEmpty(item.getMetadataId())){
|
|
|
+ metadataIds.add(item.getMetadataId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String, MetadataBO> metadataMap= metadataClientService.getMetadataMap(metadataIds);
|
|
|
+
|
|
|
+ PageData<TableInfoVO> data= new PageConverter<TableInfo, TableInfoVO>() {
|
|
|
+ @Override
|
|
|
+ public TableInfoVO converter(TableInfo entity) {
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity,userMap,categoryMap,columnList,metadataMap);
|
|
|
+ }
|
|
|
+ }.getPageData(page);
|
|
|
+ return data;
|
|
|
+
|
|
|
+ }else {
|
|
|
+
|
|
|
+ PageData<TableInfoVO> data= new PageConverter<TableInfo, TableInfoVO>() {
|
|
|
+ @Override
|
|
|
+ public TableInfoVO converter(TableInfo entity) {
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity,userMap,categoryMap);
|
|
|
+ }
|
|
|
+ }.getPageData(page);
|
|
|
+ return data;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TableInfoVO> list(TableInfoListDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ List<TableInfo> list= tableInfoService.list(
|
|
|
+ new QueryWrapper<TableInfo>()
|
|
|
+ .eq("rows_status",YN.YES.getCode())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getId()),"id",params.getId())
|
|
|
+ .in(CollUtil.isNotEmpty(params.getIds()),"id",params.getIds())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getCategoryId()),"category_id",params.getCategoryId())
|
|
|
+ .like(StrUtil.isNotEmpty(params.getName()),"name",params.getName())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getRelType()),"rel_type",params.getRelType())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getRelId()),"rel_id",params.getRelId())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getProjectCode()),"project_code",params.getProjectCode())
|
|
|
+ .eq(StrUtil.isNotEmpty(params.getStatus()),"status",params.getStatus())
|
|
|
+ );
|
|
|
+ if(CollUtil.isEmpty(list)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> tableIds=new HashSet<>();
|
|
|
+ Set<String> categoryIds=new HashSet<>();
|
|
|
+ Set<String> userIds=new HashSet<>();
|
|
|
+ list.forEach(item->{
|
|
|
+ tableIds.add(item.getId());
|
|
|
+
|
|
|
+ if(StrUtil.isNotEmpty(item.getCategoryId())){
|
|
|
+ categoryIds.add(item.getCategoryId());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(item.getCreator())){
|
|
|
+ userIds.add(item.getCreator());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(item.getUpdater())){
|
|
|
+ userIds.add(item.getUpdater());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, AdminUserBO> userMap= adminUserClientService.getUserMapByIds(userIds);
|
|
|
+ Map<String, TableCategoryVO> categoryMap= tableCategoryCacheService.getMapByIds(categoryIds);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<TableInfoVO> data=new ArrayList<>();
|
|
|
+
|
|
|
+ if(params.isCols()){
|
|
|
+ List<TableColumnInfo> columnList= tableColumnInfoService.list(
|
|
|
+ new QueryWrapper<TableColumnInfo>()
|
|
|
+ .in("table_id",tableIds)
|
|
|
+ );
|
|
|
+ Set<String> metadataIds=new HashSet<>();
|
|
|
+ columnList.forEach(item->{
|
|
|
+ if(StrUtil.isNotEmpty(item.getMetadataId())){
|
|
|
+ metadataIds.add(item.getMetadataId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<String, MetadataBO> metadataMap= metadataClientService.getMetadataMap(metadataIds);
|
|
|
+
|
|
|
+ list.forEach(item->{
|
|
|
+ data.add(TableInfoHelper.getTableInfoVO(item,userMap,categoryMap,columnList,metadataMap));
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ list.forEach(item->{
|
|
|
+ data.add(TableInfoHelper.getTableInfoVO(item,userMap,categoryMap));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private TableInfo getTableSaveEntity(TableInfoSaveDTO params){
|
|
|
+ TableInfo entity=new TableInfo();
|
|
|
+ entity.setId(TableInfoHelper.getTableConfigId());
|
|
|
+ entity.setProjectCode(params.getProjectCode());
|
|
|
+ entity.setCategoryId(params.getCategoryId());
|
|
|
+ entity.setName(params.getName());
|
|
|
+ entity.setAliasName(params.getAliasName());
|
|
|
+ entity.setRemark(params.getRemark());
|
|
|
+ entity.setRelType(params.getRelType());
|
|
|
+ entity.setRelId(params.getRelId());
|
|
|
+ entity.setOrders(params.getOrders());
|
|
|
+ entity.setStatus(YN.NO.getCode());
|
|
|
+ entity.setRowsStatus(YN.YES.getCode());
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ private TableColumnInfo getTableColumnSaveEntity(String tableId, TableColumnInfoOpDTO params){
|
|
|
+ TableColumnInfo entity=new TableColumnInfo();
|
|
|
+ entity.setId(TableInfoHelper.getTableColumnId());
|
|
|
+ entity.setTableId(tableId);
|
|
|
+ if(StrUtil.isNotEmpty(params.getCode())){
|
|
|
+ entity.setCode(params.getCode());
|
|
|
+ }else {
|
|
|
+ entity.setCode(StrUtil.format("F{}", IdUtil.getSnowflake(1,1).nextIdStr()));
|
|
|
+ }
|
|
|
+ entity.setName(params.getName());
|
|
|
+ entity.setType(params.getType());
|
|
|
+ entity.setGroupCode(params.getGroupCode());
|
|
|
+ entity.setGroupName(params.getGroupName());
|
|
|
+ entity.setMetadataId(params.getMetadataId());
|
|
|
+ entity.setRemark(params.getRemark());
|
|
|
+ entity.setOrders(params.getOrders());
|
|
|
+ if(MapUtil.isNotEmpty(params.getConfig())){
|
|
|
+ entity.setConfig(JSON.toJSONString(params.getConfig()));
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableInfoVO save(TableInfoSaveDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ TableInfo entity=this.getTableSaveEntity(params);
|
|
|
+ tableInfoService.save(entity);
|
|
|
+
|
|
|
+ Map<String, Object> logContent=new HashMap<>();
|
|
|
+ logContent.put("名称",entity.getName());
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Add, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),logContent);
|
|
|
+
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableInfoVO save2Column(TableInfoSave2ColDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ TableInfo entity=this.getTableSaveEntity(params);
|
|
|
+ tableInfoService.save(entity);
|
|
|
+
|
|
|
+ List<TableColumnInfo> list=new ArrayList<>();
|
|
|
+ if(CollUtil.isNotEmpty(params.getCols())){
|
|
|
+ params.getCols().forEach(item->{
|
|
|
+ list.add(this.getTableColumnSaveEntity(entity.getId(),item));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(list.size()>0){
|
|
|
+ tableColumnInfoService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> logContent=new HashMap<>();
|
|
|
+ logContent.put("名称",entity.getName());
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Add, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),logContent);
|
|
|
+
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableInfoVO update(TableInfoUpdateDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ TableInfo entity=tableInfoService.getById(params.getId());
|
|
|
+ if(entity==null || YN.NO.getCode().equals(entity.getRowsStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.DB_RECORD_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(YN.YES.getCode().equals(entity.getStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.Illegal_Operation_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> logContent=new HashMap<>();
|
|
|
+ logContent.put("原名称",entity.getName());
|
|
|
+
|
|
|
+ entity.setName(params.getName());
|
|
|
+ entity.setAliasName(params.getAliasName());
|
|
|
+ entity.setRemark(params.getRemark());
|
|
|
+ entity.setRelType(params.getRelType());
|
|
|
+ entity.setRelId(params.getRelId());
|
|
|
+ entity.setOrders(params.getOrders());
|
|
|
+ tableInfoService.updateById(entity);
|
|
|
+
|
|
|
+ tableInfoCacheService.removeById(entity.getId());
|
|
|
+
|
|
|
+ logContent.put("新名称",entity.getName());
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Edit, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),logContent);
|
|
|
+
|
|
|
+
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateStatus(TableInfoUpdateStatusDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ TableInfo entity=tableInfoService.getById(params.getId());
|
|
|
+ if(entity==null || YN.NO.getCode().equals(entity.getRowsStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.DB_RECORD_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ if(entity.getStatus().equals(params.getStatus())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> logContent=new HashMap<>();
|
|
|
+ logContent.put("名称",entity.getName());
|
|
|
+ logContent.put("原状态",entity.getStatus());
|
|
|
+
|
|
|
+ entity.setStatus(params.getStatus());
|
|
|
+ tableInfoService.updateById(entity);
|
|
|
+
|
|
|
+ tableInfoCacheService.removeById(entity.getId());
|
|
|
+
|
|
|
+ logContent.put("新状态",entity.getStatus());
|
|
|
+
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Edit, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),logContent);
|
|
|
+
|
|
|
+
|
|
|
+ if(YN.YES.getCode().equals(entity.getStatus())){
|
|
|
+ EntityCreate2AlterByTableDTO createTableParam=new EntityCreate2AlterByTableDTO(DataSourceTypeEnum.MySQL.getCode(),
|
|
|
+ "hh_biz_1",entity.getId(),entity.getName());
|
|
|
+ tableGenerateBizService.create2AlterEntityByTable(createTableParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableInfoVO update2Column(TableInfoUpdate2ColDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ TableInfo entity=tableInfoService.getById(params.getId());
|
|
|
+ if(entity==null || YN.NO.getCode().equals(entity.getRowsStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.DB_RECORD_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ if(YN.YES.getCode().equals(entity.getStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.Illegal_Operation_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> logContent=new HashMap<>();
|
|
|
+ logContent.put("原名称",entity.getName());
|
|
|
+
|
|
|
+ entity.setName(params.getName());
|
|
|
+ entity.setRemark(params.getRemark());
|
|
|
+ entity.setRelType(params.getRelType());
|
|
|
+ entity.setRelId(params.getRelId());
|
|
|
+ entity.setOrders(params.getOrders());
|
|
|
+ tableInfoService.updateById(entity);
|
|
|
+
|
|
|
+
|
|
|
+ List<TableColumnInfo> list=new ArrayList<>();
|
|
|
+ if(CollUtil.isNotEmpty(params.getCols())){
|
|
|
+ params.getCols().forEach(item->{
|
|
|
+ list.add(this.getTableColumnSaveEntity(entity.getId(),item));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(list.size()>0){
|
|
|
+ tableColumnInfoService.remove(
|
|
|
+ new QueryWrapper<TableColumnInfo>()
|
|
|
+ .eq("table_id",entity.getId())
|
|
|
+ );
|
|
|
+ tableColumnInfoService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ tableInfoCacheService.removeById(entity.getId());
|
|
|
+
|
|
|
+ logContent.put("新名称",entity.getName());
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Edit, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),logContent);
|
|
|
+
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableInfoVO save2updateColumnBatch(TableInfoUpdate2ColDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+ TableInfo entity=tableInfoService.getById(params.getId());
|
|
|
+ if(entity==null || YN.NO.getCode().equals(entity.getRowsStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.DB_RECORD_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ if(YN.YES.getCode().equals(entity.getStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.Illegal_Operation_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> logContent=new HashMap<>();
|
|
|
+ logContent.put("原名称",entity.getName());
|
|
|
+
|
|
|
+ List<TableColumnInfo> list=new ArrayList<>();
|
|
|
+ if(CollUtil.isNotEmpty(params.getCols())){
|
|
|
+ params.getCols().forEach(item->{
|
|
|
+ list.add(this.getTableColumnSaveEntity(entity.getId(),item));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(list.size()>0){
|
|
|
+ tableColumnInfoService.remove(
|
|
|
+ new QueryWrapper<TableColumnInfo>()
|
|
|
+ .eq("table_id",entity.getId())
|
|
|
+ );
|
|
|
+ tableColumnInfoService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ tableInfoCacheService.removeById(entity.getId());
|
|
|
+
|
|
|
+ logContent.put("新名称",entity.getName());
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Edit, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),logContent);
|
|
|
+
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableInfoVO infoById(String id) {
|
|
|
+ if(StrUtil.isEmpty(id)){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"ID不能为空");
|
|
|
+ }
|
|
|
+ TableInfo entity=tableInfoService.getById(id);
|
|
|
+ if(entity==null || YN.NO.getCode().equals(entity.getRowsStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.DB_RECORD_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ return this.info(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private TableInfoVO info(TableInfo entity){
|
|
|
+ List<TableColumnInfo> list= tableColumnInfoService.list(
|
|
|
+ new QueryWrapper<TableColumnInfo>()
|
|
|
+ .eq("table_id",entity.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ Set<String> categoryIds=new HashSet<>();
|
|
|
+ Set<String> userIds=new HashSet<>();
|
|
|
+ if(StrUtil.isNotEmpty(entity.getCategoryId())){
|
|
|
+ categoryIds.add(entity.getCategoryId());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(entity.getCreator())){
|
|
|
+ userIds.add(entity.getCreator());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(entity.getUpdater())){
|
|
|
+ userIds.add(entity.getUpdater());
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> metadataIds=new HashSet<>();
|
|
|
+ list.forEach(item->{
|
|
|
+ if(StrUtil.isNotEmpty(item.getMetadataId())){
|
|
|
+ metadataIds.add(item.getMetadataId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, AdminUserBO> userMap= adminUserClientService.getUserMapByIds(userIds);
|
|
|
+ Map<String, TableCategoryVO> categoryMap= tableCategoryCacheService.getMapByIds(categoryIds);
|
|
|
+ Map<String, MetadataBO> metadataMap= metadataClientService.getMetadataMap(metadataIds);
|
|
|
+
|
|
|
+ return TableInfoHelper.getTableInfoVO(entity,userMap,categoryMap,list,metadataMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delById(String id) {
|
|
|
+ if(StrUtil.isEmpty(id)){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.PARAMS_GET_ERROR,"ID不能为空");
|
|
|
+ }
|
|
|
+ TableInfo entity=tableInfoService.getById(id);
|
|
|
+ if(entity==null || YN.NO.getCode().equals(entity.getRowsStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.DB_RECORD_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(YN.YES.getCode().equals(entity.getStatus())){
|
|
|
+ throw new BusinessException(BusinessBaseErrorEnum.Illegal_Operation_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ entity.setRowsStatus(YN.NO.getCode());
|
|
|
+ tableInfoService.updateById(entity);
|
|
|
+
|
|
|
+ tableColumnInfoService.remove(
|
|
|
+ new QueryWrapper<TableColumnInfo>()
|
|
|
+ .eq("table_id",entity.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ tableInfoCacheService.removeById(entity.getId());
|
|
|
+
|
|
|
+ OperationLogUtils.addOpLogGen(OperationTypeEnum.OP_Del, ModuleTypeEnum.MT_Metadata, ObjectTypeEnum.OT_Table,entity.getId(),null);
|
|
|
+
|
|
|
+ }
|
|
|
+}
|