| | |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.show.PipelineEntity; |
| | | import com.lf.server.entity.sys.MetaDownEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.data.DownloadMapper; |
| | | import com.lf.server.service.sys.MetaDownService; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.FileHeader; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | |
| | | |
| | | @Autowired |
| | | DownloadMapper downloadMapper; |
| | | |
| | | @Autowired |
| | | MetaDownService metaDownService; |
| | | |
| | | private final static Log log = LogFactory.getLog(DownloadService.class); |
| | | |
| | |
| | | addMetaFiles(zip, params, list); |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); |
| | | int rows = downloadMapper.insert(downloadEntity); |
| | | DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd); |
| | | |
| | | return rows > 0 ? downloadEntity.getGuid() : null; |
| | | int rows = downloadMapper.insert(de); |
| | | if (de.getId() > 0) { |
| | | insertMetaDown(ue, list, de); |
| | | } |
| | | |
| | | return rows > 0 ? de.getGuid() : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 添加目录文件 |
| | | */ |
| | | private void addFolderFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { |
| | | File file = new File(uploadPath + File.separator + mf.getPath()); |
| | | if (!file.exists() || !file.isDirectory()) { |
| | | return; |
| | | } |
| | | zip.addFolder(file, params); |
| | | |
| | | String fileName = FileHelper.getFileName(file.getPath()); |
| | | FileHeader header = zip.getFileHeader(fileName); |
| | | if (null != header) { |
| | | zip.renameFile(header, i + "_" + mf.getName()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | for (String ext : extList) { |
| | | File file = new File(uploadPath + File.separator + mf.getPath().replace("." + mf.getType(), ext)); |
| | | if (!file.exists() || !file.isDirectory()) { |
| | | if (!file.exists() || file.isDirectory()) { |
| | | continue; |
| | | } |
| | | zip.addFile(file, params); |
| | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception { |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { |
| | | DownloadEntity de = new DownloadEntity(); |
| | | de.setName(FileHelper.getFileName(file)); |
| | | // 1-Shp文件,2-专题图,3-元数据 |
| | | // 1-Shp文件,2-专题图,3-元数据,4-业务数据,5-管道分析,6-统计报告 |
| | | de.setType(3); |
| | | de.setSizes(FileHelper.sizeToMb(new File(file).length())); |
| | | de.setDepid(ue.getDepid()); |
| | |
| | | |
| | | return de; |
| | | } |
| | | |
| | | /** |
| | | * 插入元数据-下载表 |
| | | */ |
| | | private void insertMetaDown(UserEntity ue, List<MetaEntity> metas, DownloadEntity de) { |
| | | List<MetaDownEntity> list = new ArrayList<>(); |
| | | for (MetaEntity me : metas) { |
| | | MetaDownEntity md = new MetaDownEntity(); |
| | | md.setMetaid(me.getId()); |
| | | md.setDownid(de.getId()); |
| | | md.setCreateUser(ue.getId()); |
| | | |
| | | list.add(md); |
| | | } |
| | | |
| | | metaDownService.inserts(list); |
| | | } |
| | | } |