| | |
| | | /** |
| | | * 插入文件 |
| | | */ |
| | | public List<MetaEntity> insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { |
| | | public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { |
| | | checkMetaFiles(ue, list); |
| | | excelLoader(list, req); |
| | | |
| | | return dataLoader(list); |
| | | loadData(list); |
| | | copyFiles(list); |
| | | publishFiles(list); |
| | | insertMetas(list); |
| | | } |
| | | |
| | | /** |
| | |
| | | mf.setCreateTime(createTime); |
| | | mf.setDepid(ue.getDepid()); |
| | | mf.setPath(tempPath + File.separator + mf.getPath()); |
| | | mf.setMsg(null); |
| | | |
| | | File f = new File(mf.getPath()); |
| | | if (!f.exists()) { |
| | |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | if (null != old) { |
| | | mf.setMsg("文件已入库"); |
| | | mf.setMsg("已入库"); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) { |
| | | xlsList.add(mf); |
| | | } |
| | |
| | | /** |
| | | * 加载数据 |
| | | */ |
| | | private List<MetaEntity> dataLoader(List<MetaFileEntity> list) { |
| | | loadData(list); |
| | | copyFiles(list); |
| | | |
| | | return insertMetas(list); |
| | | } |
| | | |
| | | /** |
| | | * 加载数据 |
| | | */ |
| | | private void loadData(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (StringHelper.isEmpty(mf.getEntity())) { |
| | | if (null != mf.getMsg() || StringHelper.isEmpty(mf.getEntity())) { |
| | | continue; |
| | | } |
| | | if (StaticData.SHP.equals(mf.getExtName()) || StaticData.GDB.equals(mf.getExtName())) { |
| | |
| | | return; |
| | | } |
| | | |
| | | File file = new File(mf.getPath()); |
| | | if (!file.exists()) { |
| | | mf.setMsg("文件丢失"); |
| | | return; |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName); |
| | | if (old != null) { |
| | | mf.setMsg("文件已入库"); |
| | | if (null != old) { |
| | | mf.setMsg("已入库"); |
| | | return; |
| | | } |
| | | |
| | |
| | | private void copyFiles(List<MetaFileEntity> list) { |
| | | List<String> gdbList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | switch (mf.getExtName()) { |
| | | case StaticData.MPT: |
| | | copyMultiFile(mf, StaticData.MPT_EXT); |
| | |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | if (null != old) { |
| | | mf.setPath(old.getPath()); |
| | | mf.setTab(old.getTab()); |
| | | mf.setEntity(old.getLayer()); |
| | | mf.setRows(old.getRows()); |
| | | mf.setMsg("已入库"); |
| | | file.delete(); |
| | | return 0; |
| | | } |
| | |
| | | */ |
| | | private void copyMultiFile(MetaFileEntity mf, List<String> extList) { |
| | | String path = mf.getPath(); |
| | | |
| | | int status = copySingleFile(mf); |
| | | if (status < 1) { |
| | | for (int i = 0, c = extList.size(); i < c; i++) { |
| | |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | if (null != old) { |
| | | mf.setPath(old.getPath()); |
| | | mf.setMsg("已入库"); |
| | | FileHelper.deleteFiles(file); |
| | | return; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 插入元数据 |
| | | * 发布文件 |
| | | */ |
| | | private List<MetaEntity> insertMetas(List<MetaFileEntity> list) { |
| | | List<MetaEntity> metas = new ArrayList<>(); |
| | | private void publishFiles(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (StringHelper.isEmpty(mf.getMsg())) { |
| | | metas.add(createMeta(mf)); |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | switch (mf.getExtName()) { |
| | | case StaticData.MPT: |
| | | linkFiles(mf, StaticData.MPT_EXT, pathHelper.getConfig().getPublishMptPath()); |
| | | break; |
| | | case StaticData.D3DML: |
| | | linkFiles(mf, null, pathHelper.getConfig().getPublish3dmlPath()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | if (metas.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 链接文件 |
| | | */ |
| | | private void linkFiles(MetaFileEntity mf, List<String> exts, String publishPath) { |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | String source = uploadPath + File.separator + mf.getPath(); |
| | | String target = publishPath + File.separator + mf.getName(); |
| | | |
| | | File sourceFile = new File(source); |
| | | if (!sourceFile.exists() || sourceFile.isDirectory()) { |
| | | return; |
| | | } |
| | | |
| | | int rows = metaService.inserts(metas); |
| | | createFileLink(source, target); |
| | | if (null == exts) { |
| | | return; |
| | | } |
| | | |
| | | return rows > 0 ? metas : null; |
| | | for (String ext : exts) { |
| | | File f=new File(source.replace(mf.getExtName(), ext)); |
| | | if (f.exists()&&!f.isDirectory()) { |
| | | createFileLink(source.replace(mf.getExtName(), ext), target.replace(mf.getExtName(), ext)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建文件链接 |
| | | */ |
| | | private void createFileLink(String source, String target) { |
| | | String cmd = String.format("cmd /c mklink \"%s\" \"%s\"", target, source); |
| | | WebHelper.exec(cmd); |
| | | } |
| | | |
| | | /** |
| | | * 插入元数据 |
| | | */ |
| | | private void insertMetas(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | MetaEntity me = createMeta(mf); |
| | | metaService.insert(me); |
| | | |
| | | mf.setMsg(me.getId() > 0 ? "成功" : "失败"); |
| | | } |
| | | } |
| | | |
| | | /** |