| | |
| | | File f = new File(mf.getPath()); |
| | | if (!f.exists()) { |
| | | mf.setMsg("文件丢失"); |
| | | mf.setRows(-1); |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | if (null != old) { |
| | | mf.setMsg("文件已入库"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Excel入库 |
| | | */ |
| | | private String excelLoader(List<MetaFileEntity> list, HttpServletRequest req) { |
| | | List<MetaFileEntity> xlsList = getExcelFiles(list); |
| | | if (xlsList.isEmpty()) { |
| | | return ""; |
| | | } |
| | | |
| | | String guid = null; |
| | | try { |
| | | MetaFileEntity meta = getExcelMeta(xlsList); |
| | | guid = fmeService.excelLoader(meta, req); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return guid; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel元数据文件 |
| | | */ |
| | | private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) { |
| | | List<MetaFileEntity> xlsList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) { |
| | | xlsList.add(mf); |
| | | } |
| | | } |
| | | |
| | | return xlsList; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel的元数据 |
| | | */ |
| | | private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) { |
| | | List<String> pathList = new ArrayList<>(); |
| | | List<String> dirList = new ArrayList<>(); |
| | | List<String> pidList = new ArrayList<>(); |
| | | |
| | | String xlsBasePath = getXlsPath(xlsList.get(0).getPath()); |
| | | for (int i = 0, c = xlsList.size(); i < c; i++) { |
| | | MetaFileEntity mf = xlsList.get(i); |
| | | |
| | | String path = copyXlsFile(xlsBasePath, i, mf); |
| | | if (null != path) { |
| | | pathList.add(path); |
| | | dirList.add(mf.getDirid() + ""); |
| | | pidList.add(mf.getEventid()); |
| | | } |
| | | } |
| | | |
| | | MetaFileEntity meta = new MetaFileEntity(); |
| | | meta.setPath(StringHelper.join(pathList, ",")); |
| | | meta.setEpsgCode(xlsList.get(0).getEpsgCode()); |
| | | meta.setName(StringHelper.join(dirList, ";")); |
| | | meta.setDepid(xlsList.get(0).getDepid()); |
| | | meta.setVerid(xlsList.get(0).getVerid()); |
| | | meta.setCreateUser(xlsList.get(0).getCreateUser()); |
| | | meta.setEventid(StringHelper.join(pidList, ";")); |
| | | |
| | | return meta; |
| | | } |
| | | |
| | | /** |
| | | * 获取Xls目录 |
| | | */ |
| | | private String getXlsPath(String filePath) { |
| | | String tempPath = pathHelper.getConfig().getTempPath() + File.separator; |
| | | String subPath = filePath.substring(tempPath.length()); |
| | | subPath = tempPath + subPath.substring(0, subPath.indexOf(File.separator)).replace("_zip", "") + "_xls"; |
| | | |
| | | File f = new File(subPath); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | | f.mkdirs(); |
| | | } |
| | | |
| | | return subPath; |
| | | } |
| | | |
| | | /** |
| | | * 复制Xls文件 |
| | | */ |
| | | private String copyXlsFile(String xlsBasePath, int i, MetaFileEntity mf) { |
| | | try { |
| | | String xlsPath = xlsBasePath + File.separator + i; |
| | | |
| | | File file = new File(xlsPath); |
| | | if (!file.exists() || !file.isDirectory()) { |
| | | file.mkdirs(); |
| | | } |
| | | file = new File(mf.getPath()); |
| | | |
| | | File newFile = new File(xlsPath + File.separator + FileHelper.getFileName(file.getPath())); |
| | | FileUtils.copyFile(file, newFile); |
| | | |
| | | return newFile.getPath(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName); |
| | | if (old != null) { |
| | | mf.setEntity(old.getLayer()); |
| | | mf.setTab(old.getTab()); |
| | | mf.setRows(old.getRows()); |
| | | mf.setMsg("文件已入库"); |
| | | return; |
| | | } |
| | | |
| | |
| | | me.setCreateTime(mf.getCreateTime()); |
| | | |
| | | return me; |
| | | } |
| | | |
| | | /** |
| | | * Excel入库 |
| | | */ |
| | | private String excelLoader(List<MetaFileEntity> list, HttpServletRequest req) { |
| | | List<MetaFileEntity> xlsList = getExcelFiles(list); |
| | | if (xlsList.isEmpty()) { |
| | | return ""; |
| | | } |
| | | |
| | | String guid = null; |
| | | try { |
| | | MetaFileEntity meta = getExcelMeta(xlsList); |
| | | guid = fmeService.excelLoader(meta, req); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return guid; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel元数据文件 |
| | | */ |
| | | private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) { |
| | | List<MetaFileEntity> xlsList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | | boolean isXls = StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName()); |
| | | if (mf.getRows() > -1 && isXls) { |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | if (null == old) { |
| | | xlsList.add(mf); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return xlsList; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel的元数据 |
| | | */ |
| | | private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) { |
| | | List<String> pathList = new ArrayList<>(); |
| | | List<String> dirList = new ArrayList<>(); |
| | | List<String> pidList = new ArrayList<>(); |
| | | |
| | | String xlsBasePath = getXlsPath(xlsList.get(0).getPath()); |
| | | for (int i = 0, c = xlsList.size(); i < c; i++) { |
| | | MetaFileEntity mf = xlsList.get(i); |
| | | |
| | | String path = copyXlsFile(xlsBasePath, i, mf); |
| | | if (null != path) { |
| | | pathList.add(path); |
| | | dirList.add(mf.getDirid() + ""); |
| | | pidList.add(mf.getEventid()); |
| | | } |
| | | } |
| | | |
| | | MetaFileEntity meta = new MetaFileEntity(); |
| | | meta.setPath(StringHelper.join(pathList, ",")); |
| | | meta.setEpsgCode(xlsList.get(0).getEpsgCode()); |
| | | meta.setName(StringHelper.join(dirList, ";")); |
| | | meta.setDepid(xlsList.get(0).getDepid()); |
| | | meta.setVerid(xlsList.get(0).getVerid()); |
| | | meta.setCreateUser(xlsList.get(0).getCreateUser()); |
| | | meta.setEventid(StringHelper.join(pidList, ";")); |
| | | |
| | | return meta; |
| | | } |
| | | |
| | | /** |
| | | * 获取Xls目录 |
| | | */ |
| | | private String getXlsPath(String filePath) { |
| | | String tempPath = pathHelper.getConfig().getTempPath() + File.separator; |
| | | String subPath = filePath.substring(tempPath.length()); |
| | | subPath = tempPath + subPath.substring(0, subPath.indexOf(File.separator)).replace("_zip", "") + "_xls"; |
| | | |
| | | File f = new File(subPath); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | | f.mkdirs(); |
| | | } |
| | | |
| | | return subPath; |
| | | } |
| | | |
| | | /** |
| | | * 复制Xls文件 |
| | | */ |
| | | private String copyXlsFile(String xlsBasePath, int i, MetaFileEntity mf) { |
| | | try { |
| | | String xlsPath = xlsBasePath + File.separator + i; |
| | | |
| | | File file = new File(xlsPath); |
| | | if (!file.exists() || !file.isDirectory()) { |
| | | file.mkdirs(); |
| | | } |
| | | file = new File(mf.getPath()); |
| | | |
| | | File newFile = new File(xlsPath + File.separator + FileHelper.getFileName(file.getPath())); |
| | | FileUtils.copyFile(file, newFile); |
| | | |
| | | return newFile.getPath(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | } |