| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.sql.Timestamp; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 数据上传服务类 |
| | | * |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class UploadService extends BaseUploadService implements UploadMapper { |
| | | @Autowired |
| | | UploadMapper uploadMapper; |
| | |
| | | |
| | | @Autowired |
| | | DirService dirService; |
| | | |
| | | @Resource |
| | | ReadRasterService readRasterService; |
| | | |
| | | @Override |
| | | public List<CoordEntity> selectCoords(String zoning) { |
| | |
| | | return uploadMapper.selectFmeLog(parentid); |
| | | } |
| | | |
| | | /** |
| | | * 插入文件 |
| | | */ |
| | | public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { |
| | | checkMetaFiles(ue, list); |
| | | List<MetaFileEntity> xlsList = getExcelFiles(list); |
| | | readRasterInfo(list); |
| | | loadData(list); |
| | | copyFiles(list); |
| | | insertMetas(list); |
| | | if (xlsList.size() > 0) { |
| | | String guid = excelLoader(xlsList, req); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查元数据文件 |
| | | */ |
| | | private void checkMetaFiles(UserEntity ue, List<MetaFileEntity> list) { |
| | | Timestamp createTime = WebHelper.getCurrentTimestamp(); |
| | | String tempPath = pathHelper.getConfig().getTempPath(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取目录编码 |
| | | */ |
| | | private void readRasterInfo(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | if (StaticData.RASTER_EXT.contains("." + mf.getType())) { |
| | | readRasterService.readRasterInfo(mf, mf.getPath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private String getDirCode(MetaFileEntity mf) { |
| | | if (StringHelper.isEmpty(mf.getDircode())) { |
| | | return null; |
| | |
| | | return StringHelper.getRightLike(mf.getDircode().substring(0, 2)); |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel元数据文件 |
| | | */ |
| | | private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) { |
| | | List<MetaFileEntity> xlsList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | |
| | | return xlsList; |
| | | } |
| | | |
| | | /** |
| | | * 是/否为Excel |
| | | */ |
| | | private boolean isExcel(MetaFileEntity mf) { |
| | | return StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName()); |
| | | } |
| | | |
| | | /** |
| | | * 获取Xls目录 |
| | | */ |
| | | private String getXlsPath(String filePath) { |
| | | String tempPath = pathHelper.getConfig().getTempPath() + File.separator; |
| | | String subPath = filePath.substring(tempPath.length()); |
| | |
| | | return subPath; |
| | | } |
| | | |
| | | /** |
| | | * 复制Xls文件 |
| | | */ |
| | | private String copyXlsFile(String xlsBasePath, int i, MetaFileEntity mf) { |
| | | try { |
| | | String xlsPath = xlsBasePath + File.separator + i; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载数据 |
| | | */ |
| | | private void loadData(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg() || StringHelper.isEmpty(mf.getEntity())) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载空间数据 |
| | | */ |
| | | public void loadSpatialData(MetaFileEntity mf) { |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity()); |
| | | if (null == basicMapper) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量插入 |
| | | */ |
| | | private <T> int batchInserts(BasicMapper basicMapper, List<T> list) { |
| | | int rows = 0; |
| | | //int count = (int) Math.ceil(list.size() / StaticData.D100) |
| | |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 设置创建信息 |
| | | */ |
| | | private <T> void setCreateInfo(List<T> list, MetaFileEntity mf) { |
| | | try { |
| | | if (!(list.get(0) instanceof BaseEntity)) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 复制文件 |
| | | */ |
| | | private void copyFiles(List<MetaFileEntity> list) { |
| | | List<String> gdbList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | |
| | | break; |
| | | case StaticData.JPG: |
| | | copyMultiFile(mf, StaticData.JPG_EXT); |
| | | break; |
| | | case StaticData.JP2: |
| | | copyMultiFile(mf, StaticData.JP2_EXT); |
| | | break; |
| | | case StaticData.IMG: |
| | | copyMultiFile(mf, StaticData.IMG_EXT); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 复制单个文件 |
| | | */ |
| | | private int copySingleFile(MetaFileEntity mf) { |
| | | File file = new File(mf.getPath()); |
| | | if (!file.exists()) { |
| | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 设置旧元数据信息 |
| | | */ |
| | | private void setOldMeta(MetaFileEntity mf, MetaEntity old) { |
| | | mf.setPath(old.getPath()); |
| | | mf.setTab(old.getTab()); |
| | |
| | | mf.setEntity(old.getEventid()); |
| | | } |
| | | |
| | | /** |
| | | * 复制多个文件 |
| | | */ |
| | | private void copyMultiFile(MetaFileEntity mf, List<String> extList) { |
| | | String path = mf.getPath(); |
| | | int status = copySingleFile(mf); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 复制文件夹文件 |
| | | */ |
| | | private void copyFolderFile(MetaFileEntity mf) { |
| | | File file = new File(mf.getPath()); |
| | | if (!file.exists()) { |
| | |
| | | mf.setPath(subPath); |
| | | } |
| | | |
| | | /** |
| | | * 根据GUID查找路径 |
| | | */ |
| | | private String findPathByGuid(List<MetaFileEntity> list, MetaFileEntity mf) { |
| | | for (MetaFileEntity meta : list) { |
| | | if (meta.getGuid().equals(mf.getGuid()) && !meta.getPath().equals(mf.getPath())) { |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 创建文件链接 |
| | | */ |
| | | 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); |
| | | |
| | |
| | | MetaEntity me = createMeta(mf, metaId); |
| | | if (StaticData.NGDB.equals(me.getType())) { |
| | | if (guids.contains(me.getGuid())) { |
| | | me.setIsmeta((short)-1); |
| | | me.setIsmeta((short) -1); |
| | | } else { |
| | | guids.add(me.getGuid()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建元数据 |
| | | */ |
| | | private MetaEntity createMeta(MetaFileEntity mf, int metaId) { |
| | | MetaEntity me = new MetaEntity(); |
| | | me.setMetaid(metaId); |
| | |
| | | me.setRows(mf.getRows()); |
| | | me.setCreateUser(mf.getCreateUser()); |
| | | me.setCreateTime(mf.getCreateTime()); |
| | | // 栅格信息 |
| | | me.setGeom(StringHelper.isEmpty(mf.getGeom()) ? "null" : mf.getGeom()); |
| | | me.setSensortype(mf.getSensortype()); |
| | | me.setAcqTime(mf.getAcqTime()); |
| | | me.setResolution(mf.getResolution()); |
| | | me.setGridsize(mf.getGridsize()); |
| | | me.setCoorSys(mf.getCoorSys()); |
| | | me.setEpsg(mf.getEpsg()); |
| | | me.sethDatum(mf.gethDatum()); |
| | | me.setMataType(mf.getMataType()); |
| | | me.setBands(mf.getBands()); |
| | | me.setBandType(mf.getBandType()); |
| | | me.setCt(mf.getCt()); |
| | | |
| | | return me; |
| | | } |
| | | |
| | | /** |
| | | * 插入父元数据 |
| | | */ |
| | | private int insertParentMeta(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg() || !mf.getIsMeta()) { |
| | |
| | | return 0; |
| | | } |
| | | |
| | | /** |
| | | * Excel入库 |
| | | */ |
| | | private String excelLoader(List<MetaFileEntity> xlsList, HttpServletRequest req) { |
| | | try { |
| | | MetaFileEntity xlsMeta = getExcelMeta(xlsList); |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel的元数据 |
| | | */ |
| | | private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) { |
| | | if (null == xlsList || xlsList.isEmpty()) { |
| | | return null; |