diff --git a/primihub-service/biz/src/main/java/com/primihub/biz/entity/data/base/ResourceFileData.java b/primihub-service/biz/src/main/java/com/primihub/biz/entity/data/base/ResourceFileData.java index b6db174c..de3fdf4a 100644 --- a/primihub-service/biz/src/main/java/com/primihub/biz/entity/data/base/ResourceFileData.java +++ b/primihub-service/biz/src/main/java/com/primihub/biz/entity/data/base/ResourceFileData.java @@ -33,10 +33,10 @@ public void setField(String field) { } } - public void addContentSzie(){ + public void addContentSize(){ fileContentSize++; } - public void addFileYRowSzie(){ + public void addFileYRowSize(){ resourceFileYRow++; } } diff --git a/primihub-service/biz/src/main/java/com/primihub/biz/service/data/DataResourceService.java b/primihub-service/biz/src/main/java/com/primihub/biz/service/data/DataResourceService.java index 79dee1ac..42441fb7 100644 --- a/primihub-service/biz/src/main/java/com/primihub/biz/service/data/DataResourceService.java +++ b/primihub-service/biz/src/main/java/com/primihub/biz/service/data/DataResourceService.java @@ -12,7 +12,6 @@ import com.primihub.biz.entity.base.*; import com.primihub.biz.entity.data.base.ResourceFileData; import com.primihub.biz.entity.data.dataenum.DataResourceAuthType; -import com.primihub.biz.entity.data.dataenum.ResourceStateEnum; import com.primihub.biz.entity.data.dataenum.SourceEnum; import com.primihub.biz.entity.data.dto.DataFusionCopyDto; import com.primihub.biz.entity.data.dto.ModelDerivationDto; @@ -83,28 +82,28 @@ public class DataResourceService { @Autowired private ApplicationContext applicationContext; - public BaseResultEntity getDataResourceList(DataResourceReq req, Long userId){ - Map paramMap = new HashMap<>(); - paramMap.put("userId",userId); - paramMap.put("offset",req.getOffset()); - paramMap.put("pageSize",req.getPageSize()); - paramMap.put("resourceId",req.getResourceId()); - paramMap.put("resourceAuthType",req.getResourceAuthType()); - paramMap.put("resourceSource",req.getResourceSource()); - paramMap.put("resourceName",req.getResourceName()); - paramMap.put("tag",req.getTag()); - paramMap.put("selectTag",req.getSelectTag()); - paramMap.put("userName",req.getUserName()); - paramMap.put("derivation",req.getDerivation()); - paramMap.put("fileContainsY",req.getFileContainsY()); + public BaseResultEntity getDataResourceList(DataResourceReq req, Long userId) { + Map paramMap = new HashMap<>(); + paramMap.put("userId", userId); + paramMap.put("offset", req.getOffset()); + paramMap.put("pageSize", req.getPageSize()); + paramMap.put("resourceId", req.getResourceId()); + paramMap.put("resourceAuthType", req.getResourceAuthType()); + paramMap.put("resourceSource", req.getResourceSource()); + paramMap.put("resourceName", req.getResourceName()); + paramMap.put("tag", req.getTag()); + paramMap.put("selectTag", req.getSelectTag()); + paramMap.put("userName", req.getUserName()); + paramMap.put("derivation", req.getDerivation()); + paramMap.put("fileContainsY", req.getFileContainsY()); List dataResources = dataResourceRepository.queryDataResource(paramMap); - if (dataResources.size()==0){ - return BaseResultEntity.success(new PageDataEntity(0,req.getPageSize(),req.getPageNo(),new ArrayList())); + if (dataResources.size() == 0) { + return BaseResultEntity.success(new PageDataEntity(0, req.getPageSize(), req.getPageNo(), new ArrayList())); } Integer count = dataResourceRepository.queryDataResourceCount(paramMap); List resourceIds = new ArrayList<>(); Set userIds = new HashSet<>(); - List voList = dataResources.stream().map(vo->{ + List voList = dataResources.stream().map(vo -> { resourceIds.add(vo.getResourceId()); userIds.add(vo.getUserId()); return DataResourceConvert.dataResourcePoConvertVo(vo); @@ -115,38 +114,38 @@ public BaseResultEntity getDataResourceList(DataResourceReq req, Long userId){ Map sysUserMap = sysUserService.getSysUserMap(userIds); for (DataResourceVo dataResourceVo : voList) { SysUser sysUser = sysUserMap.get(dataResourceVo.getUserId()); - dataResourceVo.setUserName(sysUser==null?"":sysUser.getUserName()); + dataResourceVo.setUserName(sysUser == null ? "" : sysUser.getUserName()); dataResourceVo.setTags(resourceTagMap.get(dataResourceVo.getResourceId())); dataResourceVo.setUrl(""); } - return BaseResultEntity.success(new PageDataEntity(count,req.getPageSize(),req.getPageNo(),voList)); + return BaseResultEntity.success(new PageDataEntity(count, req.getPageSize(), req.getPageNo(), voList)); } - public BaseResultEntity saveDataResource(DataResourceReq req,Long userId){ - Map map = new HashMap<>(); + public BaseResultEntity saveDataResource(DataResourceReq req, Long userId) { + Map map = new HashMap<>(); try { - DataResource dataResource = DataResourceConvert.dataResourceReqConvertPo(req,userId,null); + DataResource dataResource = DataResourceConvert.dataResourceReqConvertPo(req, userId, null); List fieldList = req.getFieldList(); BaseResultEntity handleDataResourceFileResult = null; DataSource dataSource = null; - if (req.getResourceSource() == 1){ + if (req.getResourceSource() == 1) { SysFile sysFile = sysFileSecondarydbRepository.selectSysFileByFileId(req.getFileId()); - if (sysFile==null){ - return BaseResultEntity.failure(BaseResultEnum.PARAM_INVALIDATION,"file"); + if (sysFile == null) { + return BaseResultEntity.failure(BaseResultEnum.PARAM_INVALIDATION, "file"); } - dataResource = DataResourceConvert.dataResourceReqConvertPo(req,userId,null,sysFile); + dataResource = DataResourceConvert.dataResourceReqConvertPo(req, userId, null, sysFile); handleDataResourceFileResult = handleDataResourceFile(dataResource, sysFile.getFileUrl()); - }else if (req.getResourceSource() == 2){ - dataSource = DataSourceConvert.DataSourceReqConvertPo(req.getDataSource()); - handleDataResourceFileResult = handleDataResourceSource(dataResource,fieldList,dataSource); + } else if (req.getResourceSource() == 2) { + dataSource = DataSourceConvert.DataSourceReqConvertPo(req.getDataSource()); + handleDataResourceFileResult = handleDataResourceSource(dataResource, fieldList, dataSource); dataResource.setUrl(dataSource.getDbUrl()); } - if (handleDataResourceFileResult.getCode()!=0) { + if (handleDataResourceFileResult.getCode() != 0) { return handleDataResourceFileResult; } SysLocalOrganInfo sysLocalOrganInfo = organConfiguration.getSysLocalOrganInfo(); - if (sysLocalOrganInfo!=null&&sysLocalOrganInfo.getOrganId()!=null&&!"".equals(sysLocalOrganInfo.getOrganId().trim())){ + if (sysLocalOrganInfo != null && sysLocalOrganInfo.getOrganId() != null && !"".equals(sysLocalOrganInfo.getOrganId().trim())) { dataResource.setResourceFusionId(organConfiguration.generateUniqueCode()); } List dataFileFieldList = new ArrayList<>(); @@ -154,10 +153,10 @@ public BaseResultEntity saveDataResource(DataResourceReq req,Long userId){ dataFileFieldList.add(DataResourceConvert.DataFileFieldReqConvertPo(field, 0L, dataResource.getResourceId())); } TaskParam taskParam = resourceSynGRPCDataSet(dataSource, dataResource, dataFileFieldList); - if (!taskParam.getSuccess()){ - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"无法将资源注册到数据集中:"+taskParam.getError()); + if (!taskParam.getSuccess()) { + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "无法将资源注册到数据集中:" + taskParam.getError()); } - if (dataSource!=null){ + if (dataSource != null) { dataResourcePrRepository.saveSource(dataSource); dataResource.setDbId(dataSource.getId()); } @@ -170,25 +169,25 @@ public BaseResultEntity saveDataResource(DataResourceReq req,Long userId){ for (String tagName : tags) { DataResourceTag dataResourceTag = new DataResourceTag(tagName); dataResourcePrRepository.saveResourceTag(dataResourceTag); - dataResourcePrRepository.saveResourceTagRelation(dataResourceTag.getTagId(),dataResource.getResourceId()); + dataResourcePrRepository.saveResourceTagRelation(dataResourceTag.getTagId(), dataResource.getResourceId()); } - if(req.getResourceAuthType().equals(DataResourceAuthType.ASSIGN.getAuthType())&&req.getFusionOrganList()!=null&&req.getFusionOrganList().size()!=0){ - List authList=new ArrayList<>(); - for(DataSourceOrganReq organ:req.getFusionOrganList()){ - DataResourceVisibilityAuth dataResourceVisibilityAuth=new DataResourceVisibilityAuth(dataResource.getResourceId(),organ.getOrganGlobalId(),organ.getOrganName()); + if (req.getResourceAuthType().equals(DataResourceAuthType.ASSIGN.getAuthType()) && req.getFusionOrganList() != null && req.getFusionOrganList().size() != 0) { + List authList = new ArrayList<>(); + for (DataSourceOrganReq organ : req.getFusionOrganList()) { + DataResourceVisibilityAuth dataResourceVisibilityAuth = new DataResourceVisibilityAuth(dataResource.getResourceId(), organ.getOrganGlobalId(), organ.getOrganName()); authList.add(dataResourceVisibilityAuth); } dataResourcePrRepository.saveVisibilityAuth(authList); } - fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(),findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); - singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(),dataResource))).build()); - map.put("resourceId",dataResource.getResourceId()); - map.put("resourceFusionId",dataResource.getResourceFusionId()); - map.put("resourceName",dataResource.getResourceName()); - map.put("resourceDesc",dataResource.getResourceDesc()); + fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(), findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); + singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(), dataResource))).build()); + map.put("resourceId", dataResource.getResourceId()); + map.put("resourceFusionId", dataResource.getResourceFusionId()); + map.put("resourceName", dataResource.getResourceName()); + map.put("resourceDesc", dataResource.getResourceDesc()); - }catch (Exception e){ - log.info("save DataResource Exception:{}",e.getMessage()); + } catch (Exception e) { + log.info("save DataResource Exception:{}", e.getMessage()); e.printStackTrace(); return BaseResultEntity.failure(BaseResultEnum.FAILURE); } @@ -198,51 +197,51 @@ public BaseResultEntity saveDataResource(DataResourceReq req,Long userId){ public BaseResultEntity editDataResource(DataResourceReq req, Long userId) { DataResource dataResource = dataResourceRepository.queryDataResourceById(req.getResourceId()); - if (dataResource==null){ - return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL,"找不到资源信息"); + if (dataResource == null) { + return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL, "找不到资源信息"); } - DataResourceConvert.editResourceReqConvertPo(req,dataResource); + DataResourceConvert.editResourceReqConvertPo(req, dataResource); try { dataResourcePrRepository.editResource(dataResource); - handleResourceTag(req.getTags(),dataResource.getResourceId()); - }catch (Exception e){ - log.info("edit DataResource Exception: {}",e.getMessage()); + handleResourceTag(req.getTags(), dataResource.getResourceId()); + } catch (Exception e) { + log.info("edit DataResource Exception: {}", e.getMessage()); } - if(req.getResourceAuthType()!=null){ + if (req.getResourceAuthType() != null) { dataResourcePrRepository.deleteVisibilityAuthByResourceId(req.getResourceId()); - if(req.getResourceAuthType().equals(DataResourceAuthType.ASSIGN.getAuthType())&&req.getFusionOrganList()!=null&&req.getFusionOrganList().size()!=0){ - List authList=new ArrayList<>(); - for(DataSourceOrganReq organ:req.getFusionOrganList()){ - DataResourceVisibilityAuth dataResourceVisibilityAuth=new DataResourceVisibilityAuth(dataResource.getResourceId(),organ.getOrganGlobalId(),organ.getOrganName()); + if (req.getResourceAuthType().equals(DataResourceAuthType.ASSIGN.getAuthType()) && req.getFusionOrganList() != null && req.getFusionOrganList().size() != 0) { + List authList = new ArrayList<>(); + for (DataSourceOrganReq organ : req.getFusionOrganList()) { + DataResourceVisibilityAuth dataResourceVisibilityAuth = new DataResourceVisibilityAuth(dataResource.getResourceId(), organ.getOrganGlobalId(), organ.getOrganName()); authList.add(dataResourceVisibilityAuth); } dataResourcePrRepository.saveVisibilityAuth(authList); } } DataSource dataSource = null; - if(dataResource.getDbId()!=null && dataResource.getDbId()!=0L){ + if (dataResource.getDbId() != null && dataResource.getDbId() != 0L) { Long dbId = dataResource.getDbId(); dataSource = dataResourceRepository.queryDataSourceById(dbId); - log.info("{}-{}",dbId,JSONObject.toJSONString(dataSource)); + log.info("{}-{}", dbId, JSONObject.toJSONString(dataSource)); } TaskParam taskParam = resourceSynGRPCDataSet(dataSource, dataResource, dataResourceRepository.queryDataFileFieldByFileId(dataResource.getResourceId())); - if (!taskParam.getSuccess()){ - return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL,"无法将资源注册到数据集中:"+taskParam.getError()); + if (!taskParam.getSuccess()) { + return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL, "无法将资源注册到数据集中:" + taskParam.getError()); } - fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(),findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); - singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(),dataResource))).build()); - Map map = new HashMap<>(); - map.put("resourceId",dataResource.getResourceId()); - map.put("resourceName",dataResource.getResourceName()); - map.put("resourceDesc",dataResource.getResourceDesc()); + fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(), findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); + singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(), dataResource))).build()); + Map map = new HashMap<>(); + map.put("resourceId", dataResource.getResourceId()); + map.put("resourceName", dataResource.getResourceName()); + map.put("resourceDesc", dataResource.getResourceDesc()); return BaseResultEntity.success(map); } public BaseResultEntity getDataResource(String resourceId) { DataResource dataResource = dataResourceRepository.queryDataResourceByResourceFusionId(resourceId); - if (dataResource == null){ + if (dataResource == null) { try { long l = Long.parseLong(resourceId); dataResource = dataResourceRepository.queryDataResourceById(Long.parseLong(resourceId)); @@ -257,106 +256,108 @@ public BaseResultEntity getDataResource(String resourceId) { List dataResourceTags = dataResourceRepository.queryTagsByResourceId(dataResource.getResourceId()); DataResourceVo dataResourceVo = DataResourceConvert.dataResourcePoConvertVo(dataResource); SysUser sysUser = sysUserService.getSysUserById(dataResourceVo.getUserId()); - dataResourceVo.setUserName(sysUser == null?"":sysUser.getUserName()); + dataResourceVo.setUserName(sysUser == null ? "" : sysUser.getUserName()); dataResourceVo.setTags(dataResourceTags.stream().map(DataResourceConvert::dataResourceTagPoConvertListVo).collect(Collectors.toList())); List dataFileFieldList = dataResourceRepository.queryDataFileFieldByFileId(dataResource.getResourceId()) .stream().map(DataResourceConvert::DataFileFieldPoConvertVo) .collect(Collectors.toList()); - Map map = new HashMap<>(); + Map map = new HashMap<>(); try { - if (dataResource.getResourceSource() == 2){ + if (dataResource.getResourceSource() == 2) { DataSource dataSource = dataResourceRepository.queryDataSourceById(dataResource.getDbId()); - log.info("{}-{}",dataResource.getDbId(),JSONObject.toJSONString(dataSource)); - if (dataSource!=null){ + log.info("{}-{}", dataResource.getDbId(), JSONObject.toJSONString(dataSource)); + if (dataSource != null) { BaseResultEntity baseResultEntity = dataSourceService.dataSourceTableDetails(dataSource); - if (baseResultEntity.getCode()==0){ - map.putAll((Map)baseResultEntity.getResult()); + if (baseResultEntity.getCode() == 0) { + map.putAll((Map) baseResultEntity.getResult()); } } - }else { + } else { List> csvData = FileUtil.getCsvData(dataResource.getUrl(), DataConstant.READ_DATA_ROW); - map.put("dataList",csvData); + map.put("dataList", csvData); } - }catch (Exception e){ - log.info("资源id:{}-文件读取失败:{}",dataResource.getResourceId(),e.getMessage()); - map.put("dataList",new ArrayList()); + } catch (Exception e) { + log.info("资源id:{}-文件读取失败:{}", dataResource.getResourceId(), e.getMessage()); + map.put("dataList", new ArrayList()); } - map.put("resource",dataResourceVo); + map.put("resource", dataResourceVo); DataResource finalDataResource = dataResource; - map.put("fusionOrganList",dataResourceRepository.findAuthOrganByResourceId(new ArrayList(){{add(finalDataResource.getResourceId());}})); - map.put("fieldList",dataFileFieldList); + map.put("fusionOrganList", dataResourceRepository.findAuthOrganByResourceId(new ArrayList() {{ + add(finalDataResource.getResourceId()); + }})); + map.put("fieldList", dataFileFieldList); return BaseResultEntity.success(map); } - public void handleResourceTag(List tags,Long resourceId){ - if (tags==null||tags.size()==0){ + public void handleResourceTag(List tags, Long resourceId) { + if (tags == null || tags.size() == 0) { return; } List tagIds = dataResourceRepository.queryResourceTagRelation(resourceId); - dataResourcePrRepository.deleteRelationResourceTag(tagIds,resourceId); + dataResourcePrRepository.deleteRelationResourceTag(tagIds, resourceId); dataResourcePrRepository.deleteResourceTag(tagIds); for (String tagName : tags) { DataResourceTag dataResourceTag = new DataResourceTag(tagName); dataResourcePrRepository.saveResourceTag(dataResourceTag); - dataResourcePrRepository.saveResourceTagRelation(dataResourceTag.getTagId(),resourceId); + dataResourcePrRepository.saveResourceTagRelation(dataResourceTag.getTagId(), resourceId); } } public BaseResultEntity deleteDataResource(Long resourceId) { DataResource dataResource = dataResourceRepository.queryDataResourceById(resourceId); if (dataResource == null) { - return BaseResultEntity.failure(BaseResultEnum.DATA_DEL_FAIL,"未查询到资源信息"); + return BaseResultEntity.failure(BaseResultEnum.DATA_DEL_FAIL, "未查询到资源信息"); } // Integer count = dataResourceRepository.queryResourceProjectRelationCount(dataResource.getResourceFusionId()); // if (count>0){ // return BaseResultEntity.failure(BaseResultEnum.DATA_DEL_FAIL,"该资源已关联项目"); // } - if (dataResource.getResourceSource().equals(1)){ + if (dataResource.getResourceSource().equals(1)) { SysFile sysFile = sysFileSecondarydbRepository.selectSysFileByFileId(dataResource.getFileId()); try { Files.delete(Paths.get(sysFile.getFileUrl())); - }catch (Exception e){ - log.info("filePaht:{} 删除失败:{}",sysFile.getFileUrl(),e.getMessage()); - return BaseResultEntity.failure(BaseResultEnum.DATA_DEL_FAIL,"文件删除失败:"+e.getMessage()); + } catch (Exception e) { + log.info("filePaht:{} 删除失败:{}", sysFile.getFileUrl(), e.getMessage()); + return BaseResultEntity.failure(BaseResultEnum.DATA_DEL_FAIL, "文件删除失败:" + e.getMessage()); } } dataResourcePrRepository.deleteResource(resourceId); dataResource.setIsDel(1); dataResource.setResourceState(1); - fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(),findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); - singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(),dataResource))).build()); + fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(), findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); + singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(), dataResource))).build()); return BaseResultEntity.success("删除资源成功"); } - public BaseResultEntity getDataResourceFieldPage(Long resourceId,PageReq req,Long userId) { - Map map = new HashMap<>(); - Map paramMap = new HashMap<>(); - paramMap.put("resourceId",resourceId); - paramMap.put("offset",req.getOffset()); - paramMap.put("pageSize",req.getPageSize()); - paramMap.put("isPage",1); + public BaseResultEntity getDataResourceFieldPage(Long resourceId, PageReq req, Long userId) { + Map map = new HashMap<>(); + Map paramMap = new HashMap<>(); + paramMap.put("resourceId", resourceId); + paramMap.put("offset", req.getOffset()); + paramMap.put("pageSize", req.getPageSize()); + paramMap.put("isPage", 1); List dataFileFieldList = dataResourceRepository.queryDataFileField(paramMap); - if (dataFileFieldList.size()==0){ - map.put("isUpdate",false); - map.put("pageData",new PageDataEntity(0,req.getPageSize(),req.getPageNo(),new ArrayList())); - }else { + if (dataFileFieldList.size() == 0) { + map.put("isUpdate", false); + map.put("pageData", new PageDataEntity(0, req.getPageSize(), req.getPageNo(), new ArrayList())); + } else { Integer count = dataResourceRepository.queryDataFileFieldCount(paramMap); boolean isUpdate = false; DataResource dataResource = dataResourceRepository.queryDataResourceById(resourceId); - if (dataResource!=null&&dataResource.getUserId().equals(userId)) { + if (dataResource != null && dataResource.getUserId().equals(userId)) { isUpdate = true; } - map.put("isUpdate",isUpdate); - map.put("pageData",new PageDataEntity(count,req.getPageSize(),req.getPageNo(),dataFileFieldList.stream().map(DataResourceConvert::DataFileFieldPoConvertVo).collect(Collectors.toList()))); + map.put("isUpdate", isUpdate); + map.put("pageData", new PageDataEntity(count, req.getPageSize(), req.getPageNo(), dataFileFieldList.stream().map(DataResourceConvert::DataFileFieldPoConvertVo).collect(Collectors.toList()))); } return BaseResultEntity.success(map); } public BaseResultEntity updateDataResourceField(DataResourceFieldReq req, FieldTypeEnum fieldTypeEnum) { if (StringUtils.isNotBlank(req.getFieldAs())) { - if (!req.getFieldAs().substring(0,1).matches(DataConstant.MATCHES)){ - return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL,"字段别名格式错误"); + if (!req.getFieldAs().substring(0, 1).matches(DataConstant.MATCHES)) { + return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL, "字段别名格式错误"); } } DataFileField dataFileField = DataResourceConvert.DataFileFieldReqConvertPo(req, fieldTypeEnum); @@ -364,13 +365,13 @@ public BaseResultEntity updateDataResourceField(DataResourceFieldReq req, FieldT return BaseResultEntity.success(); } - public BaseResultEntity resourceFilePreview(Long fileId,String resourceId) { - if(StringUtils.isNotBlank(resourceId)){ + public BaseResultEntity resourceFilePreview(Long fileId, String resourceId) { + if (StringUtils.isNotBlank(resourceId)) { DataResource dataResource = dataResourceRepository.queryDataResourceByResourceFusionId(resourceId); - if (dataResource==null) { + if (dataResource == null) { return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL); } - if (dataResource.getResourceSource() == 2){ + if (dataResource.getResourceSource() == 2) { DataSource dataSource = dataResourceRepository.queryDataSourceById(dataResource.getDbId()); return dataSourceService.dataSourceTableDetails(dataSource); @@ -379,7 +380,7 @@ public BaseResultEntity resourceFilePreview(Long fileId,String resourceId) { } SysFile sysFile = sysFileSecondarydbRepository.selectSysFileByFileId(fileId); - if (sysFile==null) { + if (sysFile == null) { return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL); } return getDataResourceCsvVo(sysFile); @@ -389,66 +390,66 @@ public BaseResultEntity getDataResourceCsvVo(SysFile sysFile) { DataResourceCsvVo csvVo = null; try { List fileContent = FileUtil.getFileContent(sysFile.getFileUrl(), 1); - if (fileContent==null||fileContent.size()==0) { + if (fileContent == null || fileContent.size() == 0) { return BaseResultEntity.failure(BaseResultEnum.DATA_RUN_FILE_CHECK_FAIL); } String headersStr = fileContent.get(0); if (StringUtils.isBlank(headersStr)) { return BaseResultEntity.failure(BaseResultEnum.DATA_RUN_FILE_CHECK_FAIL); } - csvVo = new DataResourceCsvVo(); + csvVo = new DataResourceCsvVo(); String[] headers = headersStr.split(","); if (headers[0].startsWith(DataConstant.UTF8_BOM)) { headers[0] = headers[0].substring(1); } - List> csvData = FileUtil.getCsvData(sysFile.getFileUrl(),DataConstant.READ_DATA_ROW); + List> csvData = FileUtil.getCsvData(sysFile.getFileUrl(), DataConstant.READ_DATA_ROW); csvVo.setDataList(csvData); List dataFileFieldList = batchInsertDataFileField(sysFile, headers, csvData.get(0)); csvVo.setFieldDataList(dataFileFieldList); csvVo.setFileId(sysFile.getFileId()); - }catch (Exception e){ - log.info("fileUrl:【{}】Exception Message : {}",sysFile.getFileUrl(),e); - return BaseResultEntity.failure(BaseResultEnum.DATA_RUN_FILE_CHECK_FAIL,"请检查文件编码格式"); + } catch (Exception e) { + log.info("fileUrl:【{}】Exception Message : {}", sysFile.getFileUrl(), e); + return BaseResultEntity.failure(BaseResultEnum.DATA_RUN_FILE_CHECK_FAIL, "请检查文件编码格式"); } return BaseResultEntity.success(csvVo); } - public List batchInsertDataFileField(SysFile sysFile,String[] headers,LinkedHashMap dataMap) { + public List batchInsertDataFileField(SysFile sysFile, String[] headers, LinkedHashMap dataMap) { List fileFieldList = new ArrayList<>(); int i = 1; for (String fieldName : headers) { if (StringUtils.isNotBlank(fieldName)) { FieldTypeEnum fieldType = getFieldType(dataMap.get(fieldName).toString()); if (fieldName.substring(0, 1).matches(DataConstant.MATCHES)) { - fileFieldList.add(new DataFileField(sysFile.getFileId(), fieldName,fieldType.getCode(), null)); + fileFieldList.add(new DataFileField(sysFile.getFileId(), fieldName, fieldType.getCode(), null)); } else { - fileFieldList.add(new DataFileField(sysFile.getFileId(), fieldName,fieldType.getCode(), DataConstant.FIELD_NAME_AS + i)); + fileFieldList.add(new DataFileField(sysFile.getFileId(), fieldName, fieldType.getCode(), DataConstant.FIELD_NAME_AS + i)); i++; } } else { - fileFieldList.add(new DataFileField(sysFile.getFileId(), fieldName,FieldTypeEnum.STRING.getCode(), DataConstant.FIELD_NAME_AS + i)); + fileFieldList.add(new DataFileField(sysFile.getFileId(), fieldName, FieldTypeEnum.STRING.getCode(), DataConstant.FIELD_NAME_AS + i)); i++; } } return fileFieldList; } - public List batchInsertDataDataSourceField(List headers,Map dataMap) { + public List batchInsertDataDataSourceField(List headers, Map dataMap) { List fileFieldList = new ArrayList<>(); int i = 1; Iterator iterator = headers.iterator(); - while (iterator.hasNext()){ + while (iterator.hasNext()) { String fieldName = iterator.next(); if (StringUtils.isNotBlank(fieldName)) { - FieldTypeEnum fieldType = dataMap.containsKey(fieldName)&&dataMap.get(fieldName)!=null?getFieldType(dataMap.get(fieldName).toString()):FieldTypeEnum.STRING; + FieldTypeEnum fieldType = dataMap.containsKey(fieldName) && dataMap.get(fieldName) != null ? getFieldType(dataMap.get(fieldName).toString()) : FieldTypeEnum.STRING; if (fieldName.substring(0, 1).matches(DataConstant.MATCHES)) { - fileFieldList.add(new DataFileField(null, fieldName,fieldType.getCode(), null)); + fileFieldList.add(new DataFileField(null, fieldName, fieldType.getCode(), null)); } else { - fileFieldList.add(new DataFileField(null, fieldName,fieldType.getCode(), DataConstant.FIELD_NAME_AS + i)); + fileFieldList.add(new DataFileField(null, fieldName, fieldType.getCode(), DataConstant.FIELD_NAME_AS + i)); i++; } } else { - fileFieldList.add(new DataFileField(null, fieldName,FieldTypeEnum.STRING.getCode(), DataConstant.FIELD_NAME_AS + i)); + fileFieldList.add(new DataFileField(null, fieldName, FieldTypeEnum.STRING.getCode(), DataConstant.FIELD_NAME_AS + i)); i++; } } @@ -456,7 +457,6 @@ public List batchInsertDataDataSourceField(List headers,M } - public FieldTypeEnum getFieldType(String fieldVal) { if (StringUtils.isBlank(fieldVal)) { return FieldTypeEnum.STRING; @@ -480,9 +480,9 @@ public BaseResultEntity getResourceTags() { return BaseResultEntity.success(dataResourceRepository.queryAllResourceTag()); } - public Object findFusionCopyResourceList(Long startOffset, Long endOffset){ + public Object findFusionCopyResourceList(Long startOffset, Long endOffset) { log.info("本方机构:{}, 查找fusionCopy的, startOffset :{}, endOffset:{}", organConfiguration.getSysLocalOrganName(), startOffset, endOffset); - List resourceList=dataResourceRepository.findCopyResourceList(startOffset,endOffset); + List resourceList = dataResourceRepository.findCopyResourceList(startOffset, endOffset); log.info("本地查找出的资源: {}", resourceList.size()); Set ids = resourceList.stream().map(DataResource::getResourceFusionId).collect(Collectors.toSet()); log.info("远程查找备份的资源ids: {}", ids); @@ -491,19 +491,19 @@ public Object findFusionCopyResourceList(Long startOffset, Long endOffset){ return result.getResult(); } - public List findCopyResourceList(Long startOffset, Long endOffset){ + public List findCopyResourceList(Long startOffset, Long endOffset) { String localOrganShortCode = organConfiguration.getLocalOrganShortCode(); - List resourceList=dataResourceRepository.findCopyResourceList(startOffset,endOffset); + List resourceList = dataResourceRepository.findCopyResourceList(startOffset, endOffset); if (resourceList.isEmpty()) { return new ArrayList<>(); } List resourceIds = resourceList.stream().map(DataResource::getResourceId).collect(Collectors.toList()); Map> resourceTagMap = dataResourceRepository.queryDataResourceListTags(resourceIds).stream().collect(Collectors.groupingBy(ResourceTagListVo::getResourceId)); - List filterIdList=resourceList.stream().filter(item->item.getResourceAuthType().equals(DataResourceAuthType.ASSIGN.getAuthType())).map(DataResource::getResourceId).collect(Collectors.toList()); - Map> resourceAuthMap=new HashMap<>(); - if(filterIdList!=null&&filterIdList.size()!=0) { - List authList=dataResourceRepository.findAuthOrganByResourceId(filterIdList); - resourceAuthMap=authList.stream().collect(Collectors.groupingBy(DataResourceVisibilityAuth::getResourceId)); + List filterIdList = resourceList.stream().filter(item -> item.getResourceAuthType().equals(DataResourceAuthType.ASSIGN.getAuthType())).map(DataResource::getResourceId).collect(Collectors.toList()); + Map> resourceAuthMap = new HashMap<>(); + if (filterIdList != null && filterIdList.size() != 0) { + List authList = dataResourceRepository.findAuthOrganByResourceId(filterIdList); + resourceAuthMap = authList.stream().collect(Collectors.groupingBy(DataResourceVisibilityAuth::getResourceId)); } List fileFieldList = dataResourceRepository.queryDataFileField(new HashMap() {{ put("resourceIds", resourceIds); @@ -515,24 +515,27 @@ public List findCopyResourceList(Long startOffset, Long endO for (DataResource dataResource : resourceList) { // if (dataResource.getResourceSource() == 3) // continue; - if (dataResource.getResourceFusionId()==null|| "".equals(dataResource.getResourceFusionId().trim())){ + if (dataResource.getResourceFusionId() == null || "".equals(dataResource.getResourceFusionId().trim())) { dataResource.setResourceFusionId(organConfiguration.generateUniqueCode()); dataResourcePrRepository.editResource(dataResource); - }else { + } else { String organShortCode = dataResource.getResourceFusionId().substring(0, 12); - if (!localOrganShortCode.equals(organShortCode)){ + if (!localOrganShortCode.equals(organShortCode)) { dataResource.setResourceFusionId(organConfiguration.generateUniqueCode()); dataResourcePrRepository.editResource(dataResource); } } List tags = Optional.ofNullable(resourceTagMap.get(dataResource.getResourceId())).map(list -> list.stream().map(ResourceTagListVo::getTagName).collect(Collectors.toList())).orElse(null); List authOrganList = Optional.ofNullable(resourceAuthMap.get(dataResource.getResourceId())).map(list -> list.stream().map(DataResourceVisibilityAuth::getOrganGlobalId).collect(Collectors.toList())).orElse(null); - copyVolist.add(DataResourceConvert.dataResourcePoConvertCopyVo(dataResource,organConfiguration.getSysLocalOrganId(),StringUtils.join(tags,","),authOrganList,fileFieldListMap.get(dataResource.getResourceId()),sysUserMap.get(dataResource.getUserId()))); + copyVolist.add(DataResourceConvert.dataResourcePoConvertCopyVo(dataResource, organConfiguration.getSysLocalOrganId(), StringUtils.join(tags, ","), authOrganList, fileFieldListMap.get(dataResource.getResourceId()), sysUserMap.get(dataResource.getUserId()))); } return copyVolist; } - public BaseResultEntity handleDataResourceFile(DataResource dataResource,String url) throws Exception { + /** + * 处理csv文件数据资源 + */ + public BaseResultEntity handleDataResourceFile(DataResource dataResource, String url) throws Exception { File file = new File(url); if (file.exists()) { ResourceFileData resourceFileData = getResourceFileData(url); @@ -544,21 +547,25 @@ public BaseResultEntity handleDataResourceFile(DataResource dataResource,String dataResource.setFileHandleField(""); dataResource.setFileColumns(0); } - if (resourceFileData.getResourceFileYRow()>0){ + if (resourceFileData.isFileContainsY() && resourceFileData.getResourceFileYRow() > 0) { dataResource.setFileContainsY(1); dataResource.setFileYRows(resourceFileData.getResourceFileYRow()); - BigDecimal yRowRatio = new BigDecimal(resourceFileData.getResourceFileYRow()).divide(new BigDecimal(dataResource.getFileRows()),6, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)); + BigDecimal yRowRatio = new BigDecimal(resourceFileData.getResourceFileYRow()).divide(new BigDecimal(dataResource.getFileRows()), 6, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)); dataResource.setFileYRatio(yRowRatio); + } else { + dataResource.setFileContainsY(0); + dataResource.setFileYRows(0); + dataResource.setFileYRatio(BigDecimal.ZERO); } try { String md5hash = FileUtil.md5HashCode(file); dataResource.setResourceHashCode(md5hash); - }catch (Exception e){ - log.info("resource_id:{} - url:{} - e:{}",dataResource.getResourceId(),url,e.getMessage()); - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"文件hash出错"); + } catch (Exception e) { + log.info("resource_id:{} - url:{} - e:{}", dataResource.getResourceId(), url, e.getMessage()); + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "文件hash出错"); } - }else { - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"无文件信息"); + } else { + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "无文件信息"); } return BaseResultEntity.success(); } @@ -569,29 +576,33 @@ public BaseResultEntity handleDataResourceSource(DataResource dataResource, List if (!baseResultEntity.getCode().equals(BaseResultEnum.SUCCESS.getReturnCode())) { return baseResultEntity; } - Map map = (Map) baseResultEntity.getResult(); + Map map = (Map) baseResultEntity.getResult(); Object total = map.get("total"); - if (total!=null){ + if (total != null) { dataResource.setFileRows(Integer.parseInt(total.toString())); dataResource.setFileHandleField(String.join(",", fieldNames)); dataResource.setFileColumns(fieldNames.size()); - }else { + } else { dataResource.setFileHandleField(""); dataResource.setFileColumns(0); } Object ytotal = map.get("ytotal"); - if (ytotal!=null){ + if (ytotal != null) { dataResource.setFileContainsY(1); dataResource.setFileYRows(Integer.parseInt(ytotal.toString())); - BigDecimal yRowRatio = new BigDecimal(dataResource.getFileYRows()).divide(new BigDecimal(dataResource.getFileRows()),6, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)); + BigDecimal yRowRatio = new BigDecimal(dataResource.getFileYRows()).divide(new BigDecimal(dataResource.getFileRows()), 6, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)); dataResource.setFileYRatio(yRowRatio); + } else { + dataResource.setFileContainsY(0); + dataResource.setFileYRows(0); + dataResource.setFileYRatio(BigDecimal.ZERO); } try { String md5hash = SignUtil.getMD5ValueLowerCaseByDefaultEncode(dataSource.getDbUrl()); dataResource.setResourceHashCode(md5hash); - }catch (Exception e){ - log.info("resource_id:{} - url:{} - e:{}",dataResource.getResourceId(),dataSource.getDbUrl(),e.getMessage()); - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"数据库url hash出错"); + } catch (Exception e) { + log.info("resource_id:{} - url:{} - e:{}", dataResource.getResourceId(), dataSource.getDbUrl(), e.getMessage()); + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "数据库url hash出错"); } return BaseResultEntity.success(); } @@ -599,47 +610,49 @@ public BaseResultEntity handleDataResourceSource(DataResource dataResource, List public ResourceFileData getResourceFileData(String filePath) throws Exception { ResourceFileData resourceFileData = new ResourceFileData(); File file = new File(filePath); - if (!file.exists()){ - log.info("{}-不存在",filePath); + if (!file.exists()) { + log.info("{}-不存在", filePath); return resourceFileData; } boolean header = true; int yIndex = 0; String charsetName = FileUtil.charset(file); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath),charsetName)); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), charsetName)); String str; - while((str = bufferedReader.readLine())!=null) { - if (header){ + while ((str = bufferedReader.readLine()) != null) { + if (header) { if (str.startsWith(DataConstant.UTF8_BOM)) { str = str.substring(1); } + // 这里处理Y值, Y值的字段名必须是小写的 `y` resourceFileData.setField(str); header = false; yIndex = resourceFileData.getYIndex(); continue; } - if (resourceFileData.isFileContainsY()){ - if (StringUtils.isNotBlank(str)){ + if (resourceFileData.isFileContainsY()) { + if (StringUtils.isNotBlank(str)) { String[] rowValSplit = str.split(","); - if (resourceFileData.getFieldSize() == rowValSplit.length){ - if (StringUtils.isNotBlank(rowValSplit[yIndex])&&!"0".equals(rowValSplit[yIndex])){ - resourceFileData.addFileYRowSzie(); + if (resourceFileData.getFieldSize() == rowValSplit.length) { + // 过滤出Y值是0的行 + if (StringUtils.isNotBlank(rowValSplit[yIndex]) && !"0".equals(rowValSplit[yIndex])) { + resourceFileData.addFileYRowSize(); } } } - }else { - resourceFileData.setFileContentSize( FileUtil.getFileLineNumber(filePath)-1); + } else { + resourceFileData.setFileContentSize(FileUtil.getFileLineNumber(filePath) - 1); break; } - resourceFileData.addContentSzie(); + resourceFileData.addContentSize(); } bufferedReader.close(); return resourceFileData; } - public Integer getResourceFileYRow(List fileContent){ - if (fileContent.size()<=0) { + public Integer getResourceFileYRow(List fileContent) { + if (fileContent.size() <= 0) { return -1; } String field = fileContent.get(0); @@ -648,17 +661,17 @@ public Integer getResourceFileYRow(List fileContent){ } List fieldList = Arrays.asList(field.toLowerCase().split(",")); int yIndex = fieldList.indexOf("y"); - if (yIndex<0) { + if (yIndex < 0) { return -1; } int yRow = 0; Integer fieldListSize = fieldList.size(); for (int i = 1; i < fileContent.size(); i++) { String rowVal = fileContent.get(i); - if (StringUtils.isNotBlank(rowVal)){ + if (StringUtils.isNotBlank(rowVal)) { String[] rowValSplit = rowVal.split(","); - if (fieldListSize == rowValSplit.length){ - if (StringUtils.isNotBlank(rowValSplit[yIndex])&&!"0".equals(rowValSplit[yIndex])){ + if (fieldListSize == rowValSplit.length) { + if (StringUtils.isNotBlank(rowValSplit[yIndex]) && !"0".equals(rowValSplit[yIndex])) { yRow++; } } @@ -667,28 +680,28 @@ public Integer getResourceFileYRow(List fileContent){ return yRow; } - public TaskParam resourceSynGRPCDataSet(DataSource dataSource,DataResource dataResource,List fieldList){ - if (dataResource.getResourceSource() !=2 ){ - return resourceSynGRPCDataSet(dataResource.getFileSuffix(),dataResource.getResourceFusionId(),dataResource.getUrl(),fieldList); + public TaskParam resourceSynGRPCDataSet(DataSource dataSource, DataResource dataResource, List fieldList) { + if (dataResource.getResourceSource() != 2) { + return resourceSynGRPCDataSet(dataResource.getFileSuffix(), dataResource.getResourceFusionId(), dataResource.getUrl(), fieldList); } - Map map = new HashMap<>(); - map.put("dbType",dataSource.getDbType()); - map.put("dbUrl",dataSource.getDbUrl()); + Map map = new HashMap<>(); + map.put("dbType", dataSource.getDbType()); + map.put("dbUrl", dataSource.getDbUrl()); map.put("tableName", dataSource.getDbTableName()); - map.put("dbDriver",dataSource.getDbDriver()); - if (SourceEnum.sqlite.getSourceType().equals(dataSource.getDbType())){ - map.put("db_path",dataSource.getDbUrl()); - }else { - map.put("username",dataSource.getDbUsername()); + map.put("dbDriver", dataSource.getDbDriver()); + if (SourceEnum.sqlite.getSourceType().equals(dataSource.getDbType())) { + map.put("db_path", dataSource.getDbUrl()); + } else { + map.put("username", dataSource.getDbUsername()); map.put("password", dataSource.getDbPassword()); map.put("dbName", dataSource.getDbName()); map.putAll(DataUtil.getJDBCData(dataSource.getDbUrl())); } - return resourceSynGRPCDataSet(SourceEnum.SOURCE_MAP.get(dataSource.getDbType()).getSourceName(),dataResource.getResourceFusionId(), JSONObject.toJSONString(map),fieldList); + return resourceSynGRPCDataSet(SourceEnum.SOURCE_MAP.get(dataSource.getDbType()).getSourceName(), dataResource.getResourceFusionId(), JSONObject.toJSONString(map), fieldList); } - public TaskParam resourceSynGRPCDataSet(String suffix, String id, String url, List fieldList){ - TaskParam taskParam=new TaskParam(); + public TaskParam resourceSynGRPCDataSet(String suffix, String id, String url, List fieldList) { + TaskParam taskParam = new TaskParam(); TaskDataSetParam param = new TaskDataSetParam(); param.setFieldTypes(new ArrayList<>()); param.setId(id); @@ -705,14 +718,14 @@ public TaskParam resourceSynGRPCDataSet(String suffix, String id, String url, Li public BaseResultEntity resourceStatusChange(Long resourceId, Integer resourceState) { DataResource dataResource = dataResourceRepository.queryDataResourceById(resourceId); - if (dataResource==null){ - return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL,"找不到资源信息"); + if (dataResource == null) { + return BaseResultEntity.failure(BaseResultEnum.DATA_EDIT_FAIL, "找不到资源信息"); } - if(!dataResource.getResourceState().equals(resourceState)){ + if (!dataResource.getResourceState().equals(resourceState)) { dataResource.setResourceState(resourceState); dataResourcePrRepository.editResource(dataResource); - fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(),findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); - singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(),dataResource))).build()); + fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(), findCopyResourceList(dataResource.getResourceId(), dataResource.getResourceId())); + singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(), dataResource))).build()); } return BaseResultEntity.success(); @@ -722,44 +735,44 @@ public BaseResultEntity displayDatabaseSourceType() { return BaseResultEntity.success(baseConfiguration.isDisplayDatabaseSourceType()); } - public BaseResultEntity saveDerivationResource(List derivationList,Long userId) { + public BaseResultEntity saveDerivationResource(List derivationList, Long userId) { try { Map> map = derivationList.stream().collect(Collectors.groupingBy(ModelDerivationDto::getOriginalResourceId)); Set resourceIds = map.keySet(); DataResource dataResource = null; for (String resourceId : resourceIds) { dataResource = dataResourceRepository.queryDataResourceByResourceFusionId(resourceId); - if (dataResource!=null) { + if (dataResource != null) { break; } } if (dataResource == null) { - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"衍生原始资源数据查询失败"); + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "衍生原始资源数据查询失败"); } BaseResultEntity result = otherBusinessesService.getResourceListById(new ArrayList<>(resourceIds)); - if (result.getCode()!=0) { - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"查询中心节点数据失败:"+result.getMsg()); + if (result.getCode() != 0) { + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "查询中心节点数据失败:" + result.getMsg()); } - List> fusionResourceMap = (List>)result.getResult(); + List> fusionResourceMap = (List>) result.getResult(); StringBuilder resourceNames = new StringBuilder(dataResource.getResourceName()); for (LinkedHashMap resourceMap : fusionResourceMap) { String resourceId = resourceMap.get("resourceId").toString(); - if (!dataResource.getResourceFusionId().equals(resourceId)){ + if (!dataResource.getResourceFusionId().equals(resourceId)) { resourceNames.append(resourceMap.get("resourceName").toString()); } } List modelDerivationDtos = map.get(dataResource.getResourceFusionId()); for (ModelDerivationDto modelDerivationDto : modelDerivationDtos) { String url = dataResource.getUrl(); - if (StringUtils.isNotBlank(modelDerivationDto.getPath())){ + if (StringUtils.isNotBlank(modelDerivationDto.getPath())) { url = modelDerivationDto.getPath(); - }else { + } else { if (url.contains(".csv")) { - url = url.replace(".csv","_"+modelDerivationDto.getType()+".csv"); + url = url.replace(".csv", "_" + modelDerivationDto.getType() + ".csv"); } - if (url.contains(".db")){ + if (url.contains(".db")) { String[] split = url.split("\\."); - url = url.replace("."+split[1],"_"+modelDerivationDto.getType()+".csv"); + url = url.replace("." + split[1], "_" + modelDerivationDto.getType() + ".csv"); } } log.info(url); @@ -779,9 +792,9 @@ public BaseResultEntity saveDerivationResource(List derivati derivationDataResource.setResourceName(resourceNames.toString() + modelDerivationDto.getDerivationType()); derivationDataResource.setResourceAuthType(2); derivationDataResource.setResourceSource(3); - if (userId==null || userId==0L){ + if (userId == null || userId == 0L) { derivationDataResource.setUserId(dataResource.getUserId()); - }else { + } else { derivationDataResource.setUserId(userId); } derivationDataResource.setOrganId(0L); @@ -808,34 +821,34 @@ public BaseResultEntity saveDerivationResource(List derivati dataResourcePrRepository.saveResourceFileFieldBatch(dataFileFields); DataResourceTag dataResourceTag = new DataResourceTag(modelDerivationDto.getDerivationType()); dataResourcePrRepository.saveResourceTag(dataResourceTag); - dataResourcePrRepository.saveResourceTagRelation(dataResourceTag.getTagId(),derivationDataResource.getResourceId()); - fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(),findCopyResourceList(derivationDataResource.getResourceId(), derivationDataResource.getResourceId())); + dataResourcePrRepository.saveResourceTagRelation(dataResourceTag.getTagId(), derivationDataResource.getResourceId()); + fusionResourceService.saveResource(organConfiguration.getSysLocalOrganId(), findCopyResourceList(derivationDataResource.getResourceId(), derivationDataResource.getResourceId())); // singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(),derivationDataResource))).build()); } return BaseResultEntity.success(modelDerivationDtos.stream().map(ModelDerivationDto::getNewResourceId).collect(Collectors.toList())); - }catch (Exception e){ - log.info("衍生数据异常:{}",e.getMessage()); - return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL,"衍生数据异常:"+e.getMessage()); + } catch (Exception e) { + log.info("衍生数据异常:{}", e.getMessage()); + return BaseResultEntity.failure(BaseResultEnum.DATA_SAVE_FAIL, "衍生数据异常:" + e.getMessage()); } } public BaseResultEntity getDerivationResourceList(DerivationResourceReq req) { List dataDerivationResourceVos = dataResourceRepository.queryDerivationResourceList(req); - if (dataDerivationResourceVos.size()==0){ - return BaseResultEntity.success(new PageDataEntity(0,req.getPageSize(),req.getPageNo(),new ArrayList())); + if (dataDerivationResourceVos.size() == 0) { + return BaseResultEntity.success(new PageDataEntity(0, req.getPageSize(), req.getPageNo(), new ArrayList())); } Set userIds = dataDerivationResourceVos.stream().map(DataDerivationResourceVo::getUserId).collect(Collectors.toSet()); Map sysUserMap = sysUserService.getSysUserMap(userIds); SysLocalOrganInfo sysLocalOrganInfo = organConfiguration.getSysLocalOrganInfo(); for (DataDerivationResourceVo dataDerivationResourceVo : dataDerivationResourceVos) { SysUser sysUser = sysUserMap.get(dataDerivationResourceVo.getUserId()); - dataDerivationResourceVo.setUserName(sysUser==null?"":sysUser.getUserName()); + dataDerivationResourceVo.setUserName(sysUser == null ? "" : sysUser.getUserName()); dataDerivationResourceVo.setOrganId(sysLocalOrganInfo.getOrganId()); dataDerivationResourceVo.setOrganName(sysLocalOrganInfo.getOrganName()); } Integer count = dataResourceRepository.queryDerivationResourceListCount(req); - return BaseResultEntity.success(new PageDataEntity(count,req.getPageSize(),req.getPageNo(),dataDerivationResourceVos)); + return BaseResultEntity.success(new PageDataEntity(count, req.getPageSize(), req.getPageNo(), dataDerivationResourceVos)); } public DataResource getDataResourceUrl(Long resourceId) { @@ -844,37 +857,37 @@ public DataResource getDataResourceUrl(Long resourceId) { public BaseResultEntity getDerivationResourceData(DerivationResourceReq req) { List dataDerivationResourceVos = dataResourceRepository.queryDerivationResourceList(req); - if (dataDerivationResourceVos.size()==0){ - return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL,"无数据信息"); + if (dataDerivationResourceVos.size() == 0) { + return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL, "无数据信息"); } DataDerivationResourceVo dataDerivationResourceVo = dataDerivationResourceVos.get(0); - DataDerivationResourceDataVo dataVo= DataResourceConvert.dataDerivationResourcePoConvertDataVo(dataDerivationResourceVo); + DataDerivationResourceDataVo dataVo = DataResourceConvert.dataDerivationResourcePoConvertDataVo(dataDerivationResourceVo); DataModelTask modelTask = dataModelRepository.queryModelTaskById(dataVo.getTaskId()); - if (modelTask==null) { + if (modelTask == null) { return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL); } - if (StringUtils.isBlank(modelTask.getComponentJson())){ + if (StringUtils.isBlank(modelTask.getComponentJson())) { return BaseResultEntity.success(); } - List dataComponents = JSONObject.parseArray(modelTask.getComponentJson(),DataComponent.class); - dataComponents = dataComponents.stream().filter(d->d.getComponentName().equals(dataVo.getTag())|| "dataSet".equals(d.getComponentCode())).collect(Collectors.toList()); + List dataComponents = JSONObject.parseArray(modelTask.getComponentJson(), DataComponent.class); + dataComponents = dataComponents.stream().filter(d -> d.getComponentName().equals(dataVo.getTag()) || "dataSet".equals(d.getComponentCode())).collect(Collectors.toList()); for (DataComponent dataComponent : dataComponents) { Map map = JSONArray.parseArray(dataComponent.getDataJson(), DataComponentValue.class).stream().collect(Collectors.toMap(DataComponentValue::getKey, DataComponentValue::getVal)); - if (dataComponent.getComponentName().equals(dataVo.getTag())){ + if (dataComponent.getComponentName().equals(dataVo.getTag())) { dataVo.setTotalTime(dataComponent.getEndTime() - dataComponent.getStartTime()); - if (map.containsKey("selectFeatures")){ + if (map.containsKey("selectFeatures")) { dataVo.setAlignFeature(map.get("selectFeatures")); - }else if (map.containsKey("MultipleSelected")){ + } else if (map.containsKey("MultipleSelected")) { dataVo.setAlignFeature(map.get("MultipleSelected")); } } - if ("dataSet".equals(dataComponent.getComponentCode())){ + if ("dataSet".equals(dataComponent.getComponentCode())) { log.info(dataComponent.getDataJson()); List modelProjectResourceVos = JSONArray.parseArray(map.get("selectData"), ModelProjectResourceVo.class); for (ModelProjectResourceVo modelProjectResourceVo : modelProjectResourceVos) { - if (modelProjectResourceVo.getParticipationIdentity() == 1){ + if (modelProjectResourceVo.getParticipationIdentity() == 1) { dataVo.setInitiateOrganResource(modelProjectResourceVo.getResourceId()); - }else if (modelProjectResourceVo.getParticipationIdentity() == 2){ + } else if (modelProjectResourceVo.getParticipationIdentity() == 2) { dataVo.setProviderOrganResource(modelProjectResourceVo.getResourceId()); } } @@ -882,7 +895,7 @@ public BaseResultEntity getDerivationResourceData(DerivationResourceReq req) { } SysUser sysUser = sysUserService.getSysUserById(dataVo.getUserId()); - if (sysUser!=null) { + if (sysUser != null) { dataVo.setUserName(sysUser.getUserName()); } return BaseResultEntity.success(dataVo); @@ -894,9 +907,9 @@ public BaseResultEntity saveFusionResource(DataFusionCopyDto dto) { List dataResourceCopyVos = JSONArray.parseArray(dto.getCopyPart(), DataResourceCopyVo.class); BaseResultEntity resultEntity = fusionResourceService.saveResource(dto.getOrganId(), dataResourceCopyVos); log.info(JSONObject.toJSONString(resultEntity)); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); - return BaseResultEntity.failure(BaseResultEnum.FAILURE,e.getMessage()); + return BaseResultEntity.failure(BaseResultEnum.FAILURE, e.getMessage()); } return BaseResultEntity.success(); } @@ -905,15 +918,16 @@ public BaseResultEntity noticeResource(String resourceId) { log.info(resourceId); DataResource dataResource = dataResourceRepository.queryDataResourceByResourceFusionId(resourceId); log.info(JSONObject.toJSONString(dataResource)); - if (dataResource==null){ - return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL,"找不到资源信息"); + if (dataResource == null) { + return BaseResultEntity.failure(BaseResultEnum.DATA_QUERY_NULL, "找不到资源信息"); } - singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(),dataResource))).build()); + singleTaskChannel.input().send(MessageBuilder.withPayload(JSON.toJSONString(new BaseFunctionHandleEntity(BaseFunctionHandleEnum.SINGLE_DATA_FUSION_RESOURCE_TASK.getHandleType(), dataResource))).build()); return BaseResultEntity.success(); } /** * 组装传输实体 + * * @param resourceId * @return */ @@ -926,7 +940,7 @@ public Map getDataResourceToTransfer(Long resourceId, Integer resourceState) { dataResource.setResourceState(resourceState); } List dataResourceTags = dataResourceRepository.queryTagsByResourceId(resourceId); - DataResourceVo dataResourceVo = DataResourceConvert.dataResourcePoConvertVo(dataResource, organConfiguration.getSysLocalOrganId() ,organConfiguration.getSysLocalOrganName()); + DataResourceVo dataResourceVo = DataResourceConvert.dataResourcePoConvertVo(dataResource, organConfiguration.getSysLocalOrganId(), organConfiguration.getSysLocalOrganName()); dataResourceVo.setTags(dataResourceTags.stream().map(DataResourceConvert::dataResourceTagPoConvertListVo).collect(Collectors.toList())); List dataFileFieldList = dataResourceRepository.queryDataFileFieldByFileId(dataResource.getResourceId()) .stream().map(DataResourceConvert::DataFileFieldPoConvertVo)