| | |
| | | @Service |
| | | public class BaseUploadService { |
| | | @Autowired |
| | | private DirService dirService; |
| | | protected DirService dirService; |
| | | |
| | | @Autowired |
| | | private PathHelper pathHelper; |
| | | protected PathHelper pathHelper; |
| | | |
| | | public final Log log = LogFactory.getLog(getClass()); |
| | | |
| | |
| | | List<DirEntity> dirs = dirService.selectDirRecursive(dir.getName()); |
| | | for (MetaFileEntity meta : metas) { |
| | | meta.setEventid(StringHelper.getGuid()); |
| | | meta.setDirid(dir.getId()); |
| | | meta.setDepid(ue.getDepid()); |
| | | meta.setDircode(dir.getCode()); |
| | | meta.setDepcode(ue.getDepcode()); |
| | | meta.setVerid(ver.getId()); |
| | | meta.setCreateUser(ue.getId()); |
| | | meta.setEpsgCode(epsgCode); |
| | |
| | | |
| | | list.add(meta); |
| | | } |
| | | setMetaType(list); |
| | | |
| | | return list; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | List<File> files = new ArrayList<>(); |
| | | getFilesByPath(files, subPath); |
| | | |
| | | return getMapperFiles(files, dir, dirs, meta, tempPath.length() + 1); |
| | | } |
| | | |
| | | /** |
| | | * 根据路径获取文件 |
| | | */ |
| | | private void getFilesByPath(List<File> list, String path) { |
| | | File file = new File(path); |
| | | if (!file.isDirectory()) { |
| | | String extName = FileHelper.getExtension(file); |
| | | if (StaticData.ALL_EXTENSION.contains(extName)) { |
| | | list.add(file); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (isGdbFile(file)) { |
| | | list.add(file); |
| | | return; |
| | | } |
| | | |
| | | File[] files = file.listFiles(); |
| | | if (null == files) { |
| | | return; |
| | | } |
| | | for (File f : files) { |
| | | if (f.isDirectory()) { |
| | | getFilesByPath(list, f.getPath()); |
| | | } else { |
| | | String extName = FileHelper.getExtension(f); |
| | | if (StaticData.ALL_EXTENSION.contains(extName)) { |
| | | list.add(f); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取映射文件 |
| | | */ |
| | | private List<MetaFileEntity> getMapperFiles(File[] files, DirEntity dir, List<DirEntity> dirs, MetaFileEntity meta, int start) { |
| | | private List<MetaFileEntity> getMapperFiles(List<File> files, DirEntity dir, List<DirEntity> dirs, MetaFileEntity meta, int start) { |
| | | List<MetaFileEntity> list = new ArrayList<>(); |
| | | for (File f : files) { |
| | | boolean isGdb = isGdbFile(f); |
| | |
| | | |
| | | String fileName = FileHelper.getFileName(f.getPath()); |
| | | String extName = FileHelper.getExtension(fileName); |
| | | if (!StaticData.ALL_EXTENSION.contains(extName)) { |
| | | if (!StaticData.ALL_EXTENSION.contains(extName) || fileName.startsWith("~")) { |
| | | continue; |
| | | } |
| | | |
| | | int dirid = getDirByPath(f.getPath(), dir, dirs); |
| | | String dircode = getDirByPath(f.getPath(), fileName, dir, dirs); |
| | | boolean isShp = StaticData.SHP.equals(extName); |
| | | if (isGdb) { |
| | | List<MetaFileEntity> rs = getGdbMappers(f, meta, dirid, start); |
| | | List<MetaFileEntity> rs = getGdbMappers(f, meta, dircode, start); |
| | | if (null != rs && rs.size() > 0) { |
| | | list.addAll(rs); |
| | | } |
| | |
| | | } |
| | | |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setDirid(dirid); |
| | | mf.setDircode(dircode); |
| | | mf.setEventid(StringHelper.getGuid()); |
| | | mf.setName(fileName); |
| | | mf.setExtName(extName); |
| | |
| | | |
| | | if (isShp) { |
| | | List<String> shpFiles = getShpFiles(f.getPath()); |
| | | mf.setTab(fileName); |
| | | mf.setTab(fileName.replace(StaticData.SHP, "")); |
| | | mf.setSizes(getFilesSize(shpFiles)); |
| | | mf.setGuid(getFilesMd5(shpFiles)); |
| | | } else { |
| | |
| | | */ |
| | | private MetaFileEntity createMetaFileEntity(MetaFileEntity meta) { |
| | | MetaFileEntity mf = new MetaFileEntity(); |
| | | mf.setDirid(meta.getDirid()); |
| | | mf.setDepid(meta.getDepid()); |
| | | mf.setDircode(meta.getDircode()); |
| | | mf.setDepcode(meta.getDepcode()); |
| | | mf.setVerid(meta.getVerid()); |
| | | mf.setCreateUser(meta.getCreateUser()); |
| | | mf.setEpsgCode(meta.getEpsgCode()); |
| | |
| | | /** |
| | | * 根据文件路径获取目录ID |
| | | */ |
| | | private int getDirByPath(String filePath, DirEntity dir, List<DirEntity> dirs) { |
| | | private String getDirByPath(String filePath,String fileName, DirEntity dir, List<DirEntity> dirs) { |
| | | if (0 != dir.getPid() || null == dirs || dirs.isEmpty()) { |
| | | return dir.getId(); |
| | | return dir.getCode(); |
| | | } |
| | | if ("/".equals(File.separator)) { |
| | | if (StaticData.SLASH.equals(File.separator)) { |
| | | filePath = filePath.replace("/", "\\"); |
| | | } |
| | | |
| | | for (DirEntity entity : dirs) { |
| | | if (filePath.contains(entity.getFullName())) { |
| | | return entity.getId(); |
| | | if (filePath.contains(entity.getFullName() + "\\" + fileName)) { |
| | | return entity.getCode(); |
| | | } |
| | | } |
| | | |
| | | return dir.getId(); |
| | | return dir.getCode(); |
| | | } |
| | | |
| | | /** |
| | | * 获取SHP文件集合 |
| | | */ |
| | | private List<String> getShpFiles(String shpPath) { |
| | | private List<String> getShpFiles(String shpPath) { |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(shpPath); |
| | | |
| | | for (int i = 1, c = StaticData.SHP_EXTENSION.size(); i < c; i++) { |
| | | String path = shpPath.replace(".shp", StaticData.SHP_EXTENSION.get(i)); |
| | | for (int i = 0, c = StaticData.SHP_EXT.size(); i < c; i++) { |
| | | String path = shpPath.replace(".shp", StaticData.SHP_EXT.get(i)); |
| | | |
| | | File f = new File(path); |
| | | if (f.exists() && !f.isDirectory()) { |
| | |
| | | /** |
| | | * 获取GDB文件映射 |
| | | */ |
| | | private List<MetaFileEntity> getGdbMappers(File f, MetaFileEntity meta, int dirid, int start) { |
| | | private List<MetaFileEntity> getGdbMappers(File f, MetaFileEntity meta, String dircode, int start) { |
| | | List<String> tabs = GdbHelper.getTabNames(f.getPath()); |
| | | if (null == tabs || tabs.size() == 0) { |
| | | return null; |
| | |
| | | List<MetaFileEntity> list = new ArrayList<>(); |
| | | for (String tab : tabs) { |
| | | MetaFileEntity mf = createMetaFileEntity(meta); |
| | | mf.setDirid(dirid); |
| | | mf.setDircode(dircode); |
| | | mf.setEventid(StringHelper.getGuid()); |
| | | mf.setName(fileName); |
| | | mf.setExtName(extName); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置元数据文件的类型 |
| | | */ |
| | | private void setMetaType(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getExtName()) { |
| | | mf.setType(mf.getExtName().replace(".", "")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理目录 |
| | | */ |
| | | public void copePath(List<MetaFileEntity> list) { |
| | | String basePath = pathHelper.getConfig().getTempPath() + File.separator; |
| | | for (MetaFileEntity mf : list) { |
| | | mf.setPath(mf.getPath().replace(basePath, "")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取参数 * |
| | | * Enumeration<String> headers = req.getHeaderNames(); |
| | | * Enumeration<String> attributes = req.getAttributeNames(); |