| | |
| | | try { |
| | | String temp = pathHelper.getConfig().getTempPath(); |
| | | String root = pathHelper.getUploadFullPath(); |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | |
| | | for (MetaFileEntity mf : list) { |
| | | // 移动文件 |
| | | File file = new File(temp + File.separator + mf.getPath()); |
| | | File newFile = new File(root + File.separator + mf.getGuid()); |
| | | |
| | | MetaFileEntity old = metaFileService.selectByGuid(mf.getGuid()); |
| | | String filePath = null; |
| | | if (null == old) { |
| | | filePath = newFile.getPath(); |
| | | file.renameTo(newFile); |
| | | } else { |
| | | filePath = old.getPath(); |
| | | file.delete(); |
| | | String filePath = getFilePath(temp, root, mf); |
| | | if (null == filePath) { |
| | | continue; |
| | | } |
| | | |
| | | // 元数据 |
| | | MetaEntity me = createMetaEntity(entity); |
| | | me.setName(mf.getName()); |
| | | me.setSizes(mf.getSizes()); |
| | | |
| | | MetaEntity me = createMetaEntity(entity, mf); |
| | | Integer rows = metaService.insert(me); |
| | | if (rows < 1) { |
| | | continue; |
| | | } |
| | | |
| | | // 元数据文件 |
| | | MetaFileEntity mef = createMetaFileEntity(mf, entity); |
| | | mef.setPath(FileHelper.getRelativePath(filePath)); |
| | | MetaFileEntity mfe = createMetaFileEntity(entity, mf, filePath); |
| | | rows = metaFileService.insert(mfe); |
| | | if (rows < 1) { |
| | | continue; |
| | | } |
| | | |
| | | rows = metaFileService.insert(mef); |
| | | rows = insertDb(mfe, uploadPath); |
| | | if (rows > 0) { |
| | | count++; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取文件路径 |
| | | */ |
| | | private String getFilePath(String temp, String root, MetaFileEntity mf) { |
| | | // 移动文件 |
| | | File file = new File(temp + File.separator + mf.getPath()); |
| | | File newFile = new File(root + File.separator + mf.getGuid()); |
| | | |
| | | // 文件类型 |
| | | String metaType = getType(mf.getName().toLowerCase()); |
| | | if (null == metaType) { |
| | | file.delete(); |
| | | return null; |
| | | } |
| | | |
| | | MetaFileEntity old = metaFileService.selectByGuid(mf.getGuid()); |
| | | |
| | | String filePath = null; |
| | | if (null == old) { |
| | | filePath = newFile.getPath(); |
| | | file.renameTo(newFile); |
| | | } else { |
| | | filePath = old.getPath(); |
| | | file.delete(); |
| | | } |
| | | |
| | | return filePath; |
| | | } |
| | | |
| | | /** |
| | | * 创建元数据实体 |
| | | */ |
| | | private MetaEntity createMetaEntity(MetaEntity entity) { |
| | | private MetaEntity createMetaEntity(MetaEntity entity, MetaFileEntity mf) { |
| | | MetaEntity me = new MetaEntity(); |
| | | me.setDepid(entity.getDepid()); |
| | | me.setDirid(entity.getDirid()); |
| | | me.setVerid(entity.getVerid()); |
| | | me.setType("file"); |
| | | me.setType(getType(entity.getName().toLowerCase())); |
| | | me.setGather(entity.getGather()); |
| | | me.setBatch(entity.getBatch()); |
| | | me.setDescr(entity.getDescr()); |
| | | me.setName(mf.getName()); |
| | | me.setSizes(mf.getSizes()); |
| | | me.setCreateTime(entity.getCreateTime()); |
| | | me.setCreateUser(entity.getCreateUser()); |
| | | |
| | |
| | | /** |
| | | * 创建元数据文件实体 |
| | | */ |
| | | private MetaFileEntity createMetaFileEntity(MetaFileEntity entity, MetaEntity metaEntity) { |
| | | private MetaFileEntity createMetaFileEntity(MetaEntity metaEntity, MetaFileEntity entity, String filePath) { |
| | | MetaFileEntity mfe = new MetaFileEntity(); |
| | | mfe.setName(entity.getName()); |
| | | mfe.setMetaid(metaEntity.getId()); |
| | | mfe.setGuid(entity.getGuid()); |
| | | mfe.setSizes(entity.getSizes()); |
| | | mfe.setPath(FileHelper.getRelativePath(filePath)); |
| | | mfe.setCreateUser(metaEntity.getCreateUser()); |
| | | mfe.setCreateTime(metaEntity.getCreateTime()); |
| | | |
| | | return mfe; |
| | | } |
| | | |
| | | /** |
| | | * 获取文件类型 |
| | | */ |
| | | private String getType(String name) { |
| | | if (name.contains(".xls")) { |
| | | return "xls"; |
| | | } |
| | | if (name.contains(".mdb")) { |
| | | return "mdb"; |
| | | } |
| | | if (name.contains(".shp")) { |
| | | return "shp"; |
| | | } |
| | | if (name.contains(".gdb")) { |
| | | return "gdb"; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 插入数据库 |
| | | */ |
| | | private Integer insertDb(MetaFileEntity mfe, String root) { |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | } |