| | |
| | | package com.moon.server.service.data; |
| | | |
| | | import com.google.common.collect.Lists; |
| | | import com.moon.server.entity.all.BaseEntity; |
| | | import com.moon.server.entity.all.StaticData; |
| | | import com.moon.server.entity.data.*; |
| | | import com.moon.server.entity.sys.UserEntity; |
| | | import com.moon.server.helper.*; |
| | | import com.moon.server.mapper.all.BasicMapper; |
| | | import com.moon.server.mapper.data.UploadMapper; |
| | | import com.moon.server.service.all.BaseQueryService; |
| | | import com.moon.server.service.all.BaseUploadService; |
| | | import com.moon.server.service.sys.DepService; |
| | | import com.moon.server.entity.data.*; |
| | | import com.moon.server.helper.*; |
| | | import org.apache.commons.io.FileUtils; |
| | | 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; |
| | |
| | | @Autowired |
| | | DirService dirService; |
| | | |
| | | @Resource |
| | | ReadRasterService readRasterService; |
| | | |
| | | @Override |
| | | public List<CoordEntity> selectCoords(String zoning) { |
| | | return uploadMapper.selectCoords(zoning); |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | if (!f.exists()) { |
| | | mf.setMsg("文件丢失"); |
| | | } |
| | | if (f.exists() && StringHelper.isNull(mf.getGuid())) { |
| | | mf.setGuid(FileHelper.getFileMd5(f.getPath())); |
| | | } |
| | | |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), null); |
| | | if (null != old) { |
| | | mf.setMsg("已存在"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取栅格信息 |
| | | */ |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | List<?> list; |
| | | if (StaticData.SHP.equals(mf.getExtName())) { |
| | | list = ShpHelper.readData(clazz, mf.getPath()); |
| | | list = ShpHelper.readData(clazz, mf.getPath(), true); |
| | | } else { |
| | | list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab()); |
| | | list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab(), true); |
| | | } |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | | mf.setRecords(list.size()); |
| | | setCreateInfo(list, mf); |
| | | |
| | | int rows = basicMapper.insertBatch(list); |
| | | int rows = batchInserts(basicMapper, list); |
| | | if (rows > 0) { |
| | | mf.setEntity(mf.getTab()); |
| | | mf.setTab(tabName); |
| | | mf.setRows(rows); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量插入 |
| | | */ |
| | | private <T> int batchInserts(BasicMapper basicMapper, List<T> list) { |
| | | int rows = 0; |
| | | //int count = (int) Math.ceil(list.size() / StaticData.D100) |
| | | List<List<T>> subLists = Lists.partition(list, StaticData.I50); |
| | | for (List<T> sub : subLists) { |
| | | try { |
| | | rows += basicMapper.insertBatch(sub); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | } |
| | | } |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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); |
| | | break; |
| | |
| | | break; |
| | | case StaticData.SHP: |
| | | copyMultiFile(mf, StaticData.SHP_EXT); |
| | | break; |
| | | case StaticData.OSGB: |
| | | copyFolderFile(mf); |
| | | break; |
| | | case StaticData.GDB: |
| | | if (gdbList.contains(mf.getPath())) { |
| | |
| | | return; |
| | | } |
| | | |
| | | newFile.mkdirs(); |
| | | File[] files = file.listFiles(); |
| | | if (null == files || files.length == 0) { |
| | | return; |
| | | } |
| | | |
| | | for (File f : files) { |
| | | String subFile = targetPath + File.separator + FileHelper.getFileName(f.getPath()); |
| | | f.renameTo(new File(subFile)); |
| | | try { |
| | | // newFile.mkdirs() |
| | | FileUtils.moveDirectory(file, newFile); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | } |
| | | mf.setPath(subPath); |
| | | } |
| | |
| | | */ |
| | | private void insertMetas(List<MetaFileEntity> list) { |
| | | int metaId = insertParentMeta(list); |
| | | |
| | | List<String> guids = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg()) { |
| | | continue; |
| | | } |
| | | |
| | | MetaEntity me = createMeta(mf, metaId); |
| | | metaService.insert(me); |
| | | if (StaticData.NGDB.equals(me.getType())) { |
| | | if (guids.contains(me.getGuid())) { |
| | | me.setIsmeta((short) -1); |
| | | } else { |
| | | guids.add(me.getGuid()); |
| | | } |
| | | } |
| | | |
| | | mf.setMsg(me.getId() > 0 ? "成功" : "失败"); |
| | | metaService.insert(me); |
| | | String err = mf.getRows() < mf.getRecords() ? "(" + (mf.getRecords() - mf.getRows()) + " 条失败)" : ""; |
| | | mf.setMsg(me.getId() > 0 ? String.format("成功%s", err) : "失败"); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |