| | |
| | | /** |
| | | * 插入文件 |
| | | */ |
| | | 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); |
| | | loadData(list); |
| | | copyFiles(list); |
| | | |
| | | return insertMetas(list); |
| | | publishFiles(list); |
| | | insertMetas(list); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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); |
| | |
| | | */ |
| | | 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++) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 插入元数据 |
| | | * 发布文件 |
| | | */ |
| | | 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 ? "成功" : "失败"); |
| | | } |
| | | } |
| | | |
| | | /** |