| | |
| | | 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.AttachEntity; |
| | | 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.show.DataLibService; |
| | | import com.lf.server.service.sys.MetaDownService; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.FileHeader; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 下载记录 |
| | |
| | | DownloadMapper downloadMapper; |
| | | |
| | | @Autowired |
| | | DataLibService dataLibService; |
| | | |
| | | @Autowired |
| | | MetaDownService metaDownService; |
| | | |
| | | private final static Log log = LogFactory.getLog(DownloadService.class); |
| | | |
| | | @Override |
| | | public Integer selectCount(String name) { |
| | | name = StringHelper.getLikeStr(name); |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return downloadMapper.selectCount(name); |
| | | } |
| | | |
| | | @Override |
| | | public List<DownloadEntity> selectByPage(String name, Integer limit, Integer offset) { |
| | | name = StringHelper.getLikeStr(name); |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return downloadMapper.selectByPage(name, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | | public Integer selectCountForUser(Integer createUser, Integer type, String name) { |
| | | name = StringHelper.getLikeStr(name); |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return downloadMapper.selectCountForUser(createUser, type, name); |
| | | } |
| | | |
| | | @Override |
| | | public List<DownloadEntity> selectByPageForUser(Integer createUser, Integer type, String name, Integer limit, Integer offset) { |
| | | name = StringHelper.getLikeStr(name); |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return downloadMapper.selectByPageForUser(createUser, type, name, limit, offset); |
| | | } |
| | |
| | | * @return 下载文件GUID |
| | | */ |
| | | public String zipFiles(UserEntity ue, List<MetaEntity> list, String pwd) throws Exception { |
| | | rmRepeatMetaFiles(list); |
| | | Map<String, List<String>> tabs = getTabs(list); |
| | | rmRepeatMetas(list); |
| | | |
| | | String downloadPath = pathHelper.getDownloadFullPath(); |
| | | String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip"; |
| | | String zipFile = downloadPath + File.separator + zipName; |
| | | Map<String, List<?>> dataMap = new HashMap<>(2); |
| | | Map<String, List<AttachEntity>> annexMap = new HashMap<>(2); |
| | | queryData(tabs, dataMap, annexMap); |
| | | |
| | | //String downloadPath = pathHelper.getDownloadFullPath(); |
| | | //String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip"; |
| | | //String zipFile = downloadPath + File.separator + zipName; |
| | | |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String tempPath = pathHelper.getTempPath(tempName); |
| | | String gdbPath = tempPath + File.separator + "tabs.gdb"; |
| | | |
| | | File gdbFile = new File(gdbPath); |
| | | if (gdbFile.exists() && gdbFile.isDirectory()) { |
| | | FileHelper.deleteDir(gdbPath); |
| | | } |
| | | if (dataMap.size() > 0) { |
| | | GdbHelper.createGdb(gdbPath, dataMap); |
| | | } |
| | | |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".gdb.zip"; |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); |
| | | ZipParameters params = Zip4jHelper.getZipParams(); |
| | | addMetaFiles(zip, params, list); |
| | | ZipParameters params = Zip4jHelper.getZipParams(true); |
| | | //addMetaFiles(zip, params, list); |
| | | zip.addFolder(new File(gdbPath), params); |
| | | dataLibService.addAnnex(zip, params, annexMap); |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); |
| | | DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd); |
| | | |
| | | int rows = downloadMapper.insert(de); |
| | | if (de.getId() > 0) { |
| | | insertMetaDown(ue, list, de); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取数据表 |
| | | */ |
| | | private Map<String, List<String>> getTabs(List<MetaEntity> list) { |
| | | Map<String, List<String>> tabs = new HashMap<>(2); |
| | | for (MetaEntity meta : list) { |
| | | if (StringHelper.isEmpty(meta.getTab()) || meta.getRows() == 0 || StringHelper.isEmpty(meta.getEventid())) { |
| | | continue; |
| | | } |
| | | |
| | | if (!tabs.containsKey(meta.getTab())) { |
| | | tabs.put(meta.getTab(), new ArrayList<>()); |
| | | } |
| | | |
| | | List<String> ids = tabs.get(meta.getTab()); |
| | | if (!ids.contains(meta.getEventid())) { |
| | | ids.add(meta.getEventid()); |
| | | } |
| | | } |
| | | |
| | | return tabs; |
| | | } |
| | | |
| | | /** |
| | | * 移除重复的元数据文件 |
| | | */ |
| | | private void rmRepeatMetaFiles(List<MetaEntity> list) { |
| | | private void rmRepeatMetas(List<MetaEntity> list) { |
| | | List<String> guidList = new ArrayList<>(); |
| | | |
| | | int i = 0; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询数据 |
| | | */ |
| | | private void queryData(Map<String, List<String>> tabs, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) { |
| | | // |
| | | } |
| | | |
| | | /** |
| | | * 添加元数据文件至Zip包 |
| | | */ |
| | | private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) { |