| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入KML文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "list", value = "元数据文件集合", dataType = "MetaFileEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/insertKml") |
| | | public ResponseMsg<Object> insertKml(@RequestBody List<MetaFileEntity> list, HttpServletRequest req){ |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (null == ue) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | if (null == list || list.isEmpty()) { |
| | | return fail("元数据文件集合为空", null); |
| | | } |
| | | |
| | | uploadService.insertKml(ue, list); |
| | | |
| | | return success("成功", list); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "删除元数据") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", allowMultiple = true, example = "1") |
| | |
| | | |
| | | public final static String MDB = ".mdb"; |
| | | |
| | | public final static String KML = ".kml"; |
| | | |
| | | public final static String SHP = ".shp"; |
| | | |
| | | public final static String NGDB = "gdb"; |
| | |
| | | /** |
| | | * 所有文件扩展名 |
| | | */ |
| | | public final static List<String> ALL_EXTENSION = new ArrayList<>(Arrays.asList(".txt", ".xml", ".pdf", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx", ".shp", ".gdb", ".mdb", ".dwg", ".las", ".laz", ".cpt", ".mpt", ".ei.mpt", ".fly", ".efb", ".g3d", ".fbx", ".obj", ".3dm", ".3dml", ".osgb", ".rvt", ".ifc", ".jpg", ".jp2", ".png", ".img", ".tif", ".tiff", ".dem", ".bmp", ".gif", ".rmvb", ".rm", ".mp3", ".mp4", ".avi", ".wma", ".wmv", ".7z", ".rar", ".zip", ".lz")); |
| | | public final static List<String> ALL_EXTENSION = new ArrayList<>(Arrays.asList(".txt", ".xml", ".pdf", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx", ".shp", ".gdb", ".mdb", ".dwg", ".las", ".laz", ".cpt", ".mpt", ".ei.mpt", ".fly", ".efb", ".g3d", ".fbx", ".obj", ".3dm", ".3dml", ".osgb", ".rvt", ".ifc", ".jpg", ".jp2", ".png", ".img", ".tif", ".tiff", ".dem", ".bmp", ".gif", ".rmvb", ".rm", ".mp3", ".mp4", ".avi", ".wma", ".wmv", ".7z", ".rar", ".zip", ".lz", ".kml")); |
| | | |
| | | /** |
| | | * 插入排除字段 |
| | |
| | | |
| | | private String xlsPath; |
| | | |
| | | private String medium; |
| | | |
| | | public String getEventid() { |
| | | return eventid; |
| | | } |
| | |
| | | public void setXlsPath(String xlsPath) { |
| | | this.xlsPath = xlsPath; |
| | | } |
| | | |
| | | public String getMedium() { |
| | | return medium; |
| | | } |
| | | |
| | | public void setMedium(String medium) { |
| | | this.medium = medium; |
| | | } |
| | | } |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.lang.reflect.Field; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.sql.Timestamp; |
| | | import java.util.ArrayList; |
| | | import java.util.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()); |
| | | } |
| | |
| | | |
| | | return meta; |
| | | } |
| | | |
| | | /** |
| | | * 插入KML文件 |
| | | */ |
| | | public void insertKml(UserEntity ue, List<MetaFileEntity> list) { |
| | | checkMetaFiles(ue, list); |
| | | loadKml(list); |
| | | copyFiles(list); |
| | | insertMetas(list); |
| | | } |
| | | |
| | | /** |
| | | * 加载Kml |
| | | */ |
| | | private void loadKml(List<MetaFileEntity> list) { |
| | | for (MetaFileEntity mf : list) { |
| | | if (null != mf.getMsg() || StringHelper.isEmpty(mf.getEntity()) || !StaticData.KML.equals(mf.getExtName())) { |
| | | continue; |
| | | } |
| | | |
| | | String geom = readKml(mf.getPath()); |
| | | if (StringHelper.isEmpty(geom)) { |
| | | continue; |
| | | } |
| | | |
| | | loadKmlData(mf, geom); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取KML |
| | | */ |
| | | private String readKml(String path) { |
| | | try { |
| | | List<String> list = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8); |
| | | for (String str : list) { |
| | | if (!str.contains("<coordinates>")) { |
| | | continue; |
| | | } |
| | | |
| | | return getWktFromCoordinates(str); |
| | | } |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取KWT |
| | | */ |
| | | private String getWktFromCoordinates(String coords) { |
| | | String[] strs = coords.replace("<coordinates>", "").replace("</coordinates>", "").split(" "); |
| | | if (strs.length == 0) { |
| | | return null; |
| | | } |
| | | |
| | | // MULTILINESTRING((108.99843373100003 34.736292580000054,108.99818970700005 34.73764945000005,108.99831780400007 34.738880547000065,108.99812184300004 34.739564029000064)) |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("MULTILINESTRING(("); |
| | | for (String str : strs) { |
| | | if (StringHelper.isEmpty(str)) { |
| | | continue; |
| | | } |
| | | |
| | | String[] vals = str.split(StaticData.COMMA); |
| | | sb.append(vals[0]).append(" ").append(vals[1]).append(StaticData.COMMA); |
| | | } |
| | | sb.deleteCharAt(sb.length() - 1); |
| | | sb.append("))"); |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 加载Kml数据 |
| | | */ |
| | | private void loadKmlData(MetaFileEntity mf, String geom) { |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity()); |
| | | if (null == basicMapper) { |
| | | return; |
| | | } |
| | | |
| | | String tabName = BaseQueryService.getTabName(basicMapper); |
| | | String className = ClassHelper.getClassName(basicMapper); |
| | | Class clazz = ClassHelper.getEntityClass(className); |
| | | if (null == clazz || null == tabName) { |
| | | return; |
| | | } |
| | | |
| | | String name = FileHelper.getFileName(mf.getPath()); |
| | | List<?> list = createKmlEntity(clazz, geom, name); |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | | mf.setRecords(list.size()); |
| | | setCreateInfo(list, mf); |
| | | |
| | | int rows = batchInserts(basicMapper, list); |
| | | if (rows > 0) { |
| | | mf.setEntity(mf.getTab()); |
| | | mf.setTab(tabName); |
| | | mf.setRows(rows); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建KML实体类 |
| | | */ |
| | | private <T> List<T> createKmlEntity(Class clazz, String geom, String name) { |
| | | try { |
| | | T t = (T) clazz.newInstance(); |
| | | |
| | | Field gField = clazz.getSuperclass().getDeclaredField("geom"); |
| | | gField.setAccessible(true); |
| | | gField.set(t, geom); |
| | | |
| | | Field pField = clazz.getSuperclass().getDeclaredField("pipename"); |
| | | pField.setAccessible(true); |
| | | pField.set(t, name); |
| | | |
| | | List<T> list = new ArrayList<>(); |
| | | list.add(t); |
| | | |
| | | return list; |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | } |