| | |
| | | import com.lf.server.mapper.data.UploadMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import com.lf.server.service.all.BaseUploadService; |
| | | import com.lf.server.service.sys.DepService; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | /** |
| | | * 数据上传服务类 |
| | | * |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | |
| | | |
| | | @Autowired |
| | | MetaService metaService; |
| | | |
| | | @Autowired |
| | | DepService depService; |
| | | |
| | | @Autowired |
| | | DirService dirService; |
| | | |
| | | @Override |
| | | public List<CoordEntity> selectCoords(String zoning) { |
| | |
| | | */ |
| | | public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { |
| | | checkMetaFiles(ue, list); |
| | | excelLoader(list, req); |
| | | List<MetaFileEntity> xlsList = getExcelFiles(list); |
| | | loadData(list); |
| | | copyFiles(list); |
| | | insertMetas(list); |
| | | if (xlsList.size() > 0) { |
| | | String guid = excelLoader(xlsList, req); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | for (MetaFileEntity mf : list) { |
| | | mf.setCreateUser(ue.getId()); |
| | | mf.setCreateTime(createTime); |
| | | mf.setDepid(ue.getDepid()); |
| | | mf.setDepcode(ue.getDepcode()); |
| | | mf.setPath(tempPath + File.separator + mf.getPath()); |
| | | mf.setMsg(null); |
| | | |
| | |
| | | mf.setMsg("文件丢失"); |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), null); |
| | | if (null != old) { |
| | | mf.setMsg("已入库"); |
| | | mf.setMsg("已存在"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Excel入库 |
| | | * 获取目录编码 |
| | | */ |
| | | private String excelLoader(List<MetaFileEntity> list, HttpServletRequest req) { |
| | | List<MetaFileEntity> xlsList = getExcelFiles(list); |
| | | if (xlsList.isEmpty()) { |
| | | return ""; |
| | | private String getDirCode(MetaFileEntity mf) { |
| | | if (StringHelper.isEmpty(mf.getDircode())) { |
| | | return null; |
| | | } |
| | | |
| | | String guid = null; |
| | | try { |
| | | MetaFileEntity meta = getExcelMeta(xlsList); |
| | | guid = fmeService.excelLoader(meta, req); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return guid; |
| | | return StringHelper.getRightLike(mf.getDircode().substring(0, 2)); |
| | | } |
| | | |
| | | /** |
| | |
| | | private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) { |
| | | List<MetaFileEntity> xlsList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) { |
| | | if (null == mf.getMsg() && isExcel(mf)) { |
| | | xlsList.add(mf); |
| | | } |
| | | } |
| | | if (xlsList.isEmpty()) { |
| | | return xlsList; |
| | | } |
| | | |
| | | String xlsBasePath = getXlsPath(xlsList.get(0).getPath()); |
| | | for (int i = 0, c = xlsList.size(); i < c; i++) { |
| | | MetaFileEntity mf = xlsList.get(i); |
| | | String xlsPath = copyXlsFile(xlsBasePath, i, mf); |
| | | mf.setXlsPath(xlsPath); |
| | | } |
| | | |
| | | return xlsList; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel的元数据 |
| | | * 是/否为Excel |
| | | */ |
| | | private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) { |
| | | List<String> pathList = new ArrayList<>(); |
| | | List<String> dirList = new ArrayList<>(); |
| | | List<String> pidList = new ArrayList<>(); |
| | | |
| | | 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(); |
| | | meta.setPath(StringHelper.join(pathList, ",")); |
| | | meta.setEpsgCode(xlsList.get(0).getEpsgCode()); |
| | | meta.setName(StringHelper.join(dirList, ";")); |
| | | meta.setDepid(xlsList.get(0).getDepid()); |
| | | meta.setVerid(xlsList.get(0).getVerid()); |
| | | meta.setCreateUser(xlsList.get(0).getCreateUser()); |
| | | meta.setEventid(StringHelper.join(pidList, ";")); |
| | | |
| | | return meta; |
| | | private boolean isExcel(MetaFileEntity mf) { |
| | | return StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName()); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 加载空间数据 |
| | | */ |
| | | private void loadSpatialData(MetaFileEntity mf) { |
| | | public void loadSpatialData(MetaFileEntity mf) { |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity()); |
| | | if (null == basicMapper) { |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName); |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), tabName); |
| | | if (null != old) { |
| | | mf.setMsg("已入库"); |
| | | mf.setMsg("已存在"); |
| | | return; |
| | | } |
| | | |
| | |
| | | BaseEntity be = (BaseEntity) t; |
| | | be.setEventid(StringHelper.getGuid()); |
| | | be.setParentid(mf.getEventid()); |
| | | be.setDirid(mf.getDirid()); |
| | | be.setDepid(mf.getDepid()); |
| | | be.setDirid(mf.getDircode()); |
| | | be.setDepid(mf.getDepcode()); |
| | | be.setVerid(mf.getVerid()); |
| | | be.setCreateuser(mf.getCreateUser()); |
| | | be.setCreatetime(mf.getCreateTime()); |
| | |
| | | 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); |
| | | break; |
| | | case StaticData.JPG: |
| | | copyMultiFile(mf, StaticData.JPG_EXT); |
| | | break; |
| | | case StaticData.IMG: |
| | | copyMultiFile(mf, StaticData.IMG_EXT); |
| | |
| | | return -1; |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null); |
| | | if (null != old) { |
| | | mf.setMsg("已入库"); |
| | | 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++) { |
| | |
| | | return; |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null); |
| | | if (null != old) { |
| | | mf.setMsg("已入库"); |
| | | mf.setMsg("已存在"); |
| | | FileHelper.deleteFiles(file); |
| | | return; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 创建文件链接 |
| | | */ |
| | | 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) { |
| | | int metaId = insertParentMeta(list); |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | MetaEntity me = createMeta(mf); |
| | | MetaEntity me = createMeta(mf, metaId); |
| | | metaService.insert(me); |
| | | |
| | | mf.setMsg(me.getId() > 0 ? "成功" : "失败"); |
| | |
| | | /** |
| | | * 创建元数据 |
| | | */ |
| | | private MetaEntity createMeta(MetaFileEntity mf) { |
| | | private MetaEntity createMeta(MetaFileEntity mf, int metaId) { |
| | | MetaEntity me = new MetaEntity(); |
| | | me.setMetaid(metaId); |
| | | me.setEventid(mf.getEventid()); |
| | | me.setDirid(mf.getDirid()); |
| | | me.setDepid(mf.getDepid()); |
| | | me.setDircode(mf.getDircode()); |
| | | me.setDepcode(mf.getDepcode()); |
| | | me.setVerid(mf.getVerid()); |
| | | me.setName(mf.getName()); |
| | | me.setType(mf.getType()); |
| | |
| | | |
| | | return me; |
| | | } |
| | | |
| | | /** |
| | | * 插入父元数据 |
| | | */ |
| | | private int insertParentMeta(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg() || !mf.getIsMeta()) { |
| | | continue; |
| | | } |
| | | |
| | | MetaEntity me = createMeta(mf, 0); |
| | | me.setIsmeta((short) 1); |
| | | metaService.insert(me); |
| | | mf.setMsg(me.getId() > 0 ? "成功" : "失败"); |
| | | |
| | | return me.getId(); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | /** |
| | | * Excel入库 |
| | | */ |
| | | private String excelLoader(List<MetaFileEntity> xlsList, HttpServletRequest req) { |
| | | try { |
| | | MetaFileEntity xlsMeta = getExcelMeta(xlsList); |
| | | if (null != xlsMeta) { |
| | | return fmeService.excelLoader(xlsMeta, req); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel的元数据 |
| | | */ |
| | | private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) { |
| | | if (null == xlsList || xlsList.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | List<String> pathList = new ArrayList<>(); |
| | | List<String> dirList = new ArrayList<>(); |
| | | List<String> pidList = new ArrayList<>(); |
| | | |
| | | for (int i = 0, c = xlsList.size(); i < c; i++) { |
| | | MetaFileEntity mf = xlsList.get(i); |
| | | if ("成功".equals(mf.getMsg()) && null != mf.getXlsPath()) { |
| | | pathList.add(mf.getXlsPath()); |
| | | dirList.add(mf.getDircode()); |
| | | pidList.add(mf.getEventid()); |
| | | } |
| | | } |
| | | |
| | | MetaFileEntity first = xlsList.get(0); |
| | | MetaFileEntity meta = new MetaFileEntity(); |
| | | meta.setPath(StringHelper.join(pathList, ",")); |
| | | meta.setEpsgCode(first.getEpsgCode()); |
| | | meta.setName(StringHelper.join(dirList, ";")); |
| | | meta.setDepcode(first.getDepcode()); |
| | | meta.setVerid(first.getVerid()); |
| | | meta.setCreateUser(first.getCreateUser()); |
| | | meta.setEventid(StringHelper.join(pidList, ";")); |
| | | |
| | | return meta; |
| | | } |
| | | } |