| | |
| | | import com.lf.server.mapper.data.UploadMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import com.lf.server.service.all.BaseUploadService; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | List<String> dirList = new ArrayList<>(); |
| | | List<String> pidList = new ArrayList<>(); |
| | | |
| | | for (MetaFileEntity mf : xlsList) { |
| | | pathList.add(mf.getPath()); |
| | | dirList.add(mf.getDirid() + ""); |
| | | pidList.add(mf.getEventid()); |
| | | 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(); |
| | |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | } |