| | |
| | | */ |
| | | @Service |
| | | public class BaseUploadService { |
| | | private final static String XLS = ".xls"; |
| | | |
| | | private final static String MDB = ".mdb"; |
| | | |
| | | private final static String GDB = ".gdb"; |
| | | |
| | | private final static String SHP_ZIP = ".shp.zip"; |
| | | |
| | | private final static String GDB_ZIP = ".gdb.zip"; |
| | | |
| | | private final static String ZIP = ".zip"; |
| | | |
| | | @Autowired |
| | | public PathHelper pathHelper; |
| | | |
| | |
| | | mf.setExtName(extName); |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setPath(subPath + File.separator + fileName); |
| | | // mf.setGuid(FileHelper.getFileMd5(f.getPath())) |
| | | if (!StaticData.ZIP.equals(extName)) { |
| | | mf.setGuid(FileHelper.getFileMd5(f.getPath())); |
| | | } |
| | | |
| | | list.add(mf); |
| | | } |
| | |
| | | meta.setEpsgCode(epsgCode); |
| | | |
| | | if (StaticData.ZIP.equals(meta.getExtName())) { |
| | | List<MetaFileEntity> subs = getMappers(path, meta.getPath(), meta); |
| | | List<MetaFileEntity> subs = getMapperFiles(path, meta); |
| | | if (null != subs && subs.size() > 0) { |
| | | list.addAll(subs); |
| | | continue; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取映射 |
| | | * 获取映射文件 |
| | | */ |
| | | private List<MetaFileEntity> getMappers(String path, String zipPath, MetaFileEntity meta) { |
| | | File file = new File(pathHelper.getConfig().getTempPath() + File.separator + zipPath); |
| | | private List<MetaFileEntity> getMapperFiles(String path, MetaFileEntity meta) { |
| | | String zipFile = pathHelper.getConfig().getTempPath() + File.separator + meta.getPath(); |
| | | File file = new File(zipFile); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | return null; |
| | | } |
| | |
| | | zipFolder.mkdirs(); |
| | | } |
| | | |
| | | List<MetaFileEntity> list = new ArrayList<>(); |
| | | String subPath = zipFolder + File.separator + meta.getName().toLowerCase().replace(".zip", ""); |
| | | ZipHelper.unzip(zipFile, subPath); |
| | | |
| | | File subFile = new File(subPath); |
| | | File[] files = subFile.listFiles(); |
| | | if (null == files || files.length == 0) { |
| | | return null; |
| | | } |
| | | |
| | | return getMapperFiles(files, meta, subPath); |
| | | } |
| | | |
| | | /** |
| | | * 获取映射文件 |
| | | */ |
| | | private List<MetaFileEntity> getMapperFiles(File[] files, MetaFileEntity meta,String subPath) { |
| | | List<MetaFileEntity> list = new ArrayList<>(); |
| | | for (File f : files) { |
| | | boolean isGdb = isGdbFile(f); |
| | | if (!isGdb && f.isDirectory()) { |
| | | continue; |
| | | } |
| | | |
| | | String fileName = FileHelper.getFileName(f.getPath()); |
| | | String extName = FileHelper.getExtension(fileName); |
| | | if (!StaticData.ALL_EXTENSION.contains(extName)) { |
| | | continue; |
| | | } |
| | | |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setName(fileName); |
| | | mf.setExtName(extName); |
| | | mf.setSizes(FileHelper.sizeToMb(f.length())); |
| | | mf.setPath(f.getPath().substring(subPath.length())); |
| | | mf.setGuid(FileHelper.getFileMd5(f.getPath())); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 创建元数据文件实体类 |
| | | */ |
| | | private MetaFileEntity createMetaFileEntity(MetaFileEntity meta) { |
| | | MetaFileEntity mf = new MetaFileEntity(); |
| | | mf.setDirid(meta.getDirid()); |
| | | mf.setDepid(meta.getDepid()); |
| | | mf.setVerid(meta.getVerid()); |
| | | mf.setCreateUser(meta.getCreateUser()); |
| | | mf.setEpsgCode(meta.getEpsgCode()); |
| | | |
| | | return mf; |
| | | } |
| | | |
| | | /*private List<TabMapperEntity> getMappers(String zipPath, File[] files) { |
| | |
| | | }*/ |
| | | |
| | | private boolean isGdbFile(File f) { |
| | | if (f.getName().toLowerCase().endsWith(GDB)) { |
| | | if (f.isDirectory() && f.getName().toLowerCase().endsWith(StaticData.GDB)) { |
| | | File[] files = f.listFiles(); |
| | | if (null == files || files.length == 0) { |
| | | return false; |