| | |
| | | import com.se.simu.domain.po.DataPo; |
| | | import com.se.simu.domain.po.SimuPo; |
| | | import com.se.simu.domain.vo.*; |
| | | import com.se.simu.enums.RadioEnums; |
| | | import com.se.simu.service.*; |
| | | import com.se.simu.utils.*; |
| | | import io.swagger.annotations.*; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api(tags = "仿真管理") |
| | |
| | | if (StringUtils.isEmpty(floodFile)) { |
| | | return fail("范围文件地址不能为空", false); |
| | | } else { |
| | | // todo: 解析范围文件 根据不同的的格式文件进行不同的解析,获取需要计算的范围值 |
| | | // 上传格式:.shp/.tiff/.img/.geojson |
| | | // 重新给vo赋值 |
| | | // 获取文件的后缀名 |
| | | String fileName = floodFile.substring(floodFile.lastIndexOf(".")); |
| | | // 判断后缀名是否为.shp |
| | |
| | | rangeVerify(minX, maxX, minY, maxY); |
| | | } |
| | | } |
| | | // todo: 解析范围文件 根据不同的的格式文件进行不同的解析,获取需要计算的范围值 |
| | | // 上传格式:.shp/.tiff/.img/.geojson |
| | | // 重新给vo赋值 |
| | | } catch (Exception e) { |
| | | log.error("解析范围文件失败"); |
| | | if (null == vo.getMinx() || null == vo.getMiny() || null == vo.getMaxx() || null == vo.getMaxy()) { |
| | | return fail("解析范围文件失败!选择范围不能为空,请重新选择文件!", false); |
| | | } |
| | | } |
| | | JSONArray jsonArray = new JSONArray(); |
| | | String stationFile = vo.getStationFile(); |
| | | log.info("站点文件shp地址:{}", stationFile); |
| | | try { |
| | | // 判断地址不为空 |
| | | if (StringUtils.isEmpty(stationFile)) { |
| | | return fail("站点文件shp地址不能为空", false); |
| | | if (RadioEnums.ACCESS.getCode().equals(vo.getRadio()) && StringUtils.isNotEmpty(stationFile)) { |
| | | // 1 读取shp文件,获取站点坐标值 |
| | | ShpToolUtils.readShpGetLocal(stationFile); |
| | | } |
| | | // 1 读取shp文件,获取站点坐标值 |
| | | jsonArray = ShpToolUtils.readShpGetLocal(stationFile); |
| | | System.out.println("jsonArray = " + jsonArray); |
| | | } catch (Exception e) { |
| | | log.error("解析站点文件shp失败"); |
| | | } |
| | | |
| | | String stationRainFile = vo.getStationRainFile(); |
| | | log.info("站点雨量CSV文件地址:{}", floodFile); |
| | | JSONArray array = new JSONArray(); |
| | | // 创建表名 时间戳 |
| | | String tableName = "station_rain_" + System.currentTimeMillis(); |
| | | try { |
| | | // 判断地址不为空 |
| | | if (StringUtils.isEmpty(stationRainFile)) { |
| | | return fail("站点雨量CSV文件地址不能为空", false); |
| | | //接入处理 |
| | | if (RadioEnums.ACCESS.getCode().equals(vo.getRadio())) { |
| | | String stationRainFile = vo.getStationRainFile(); |
| | | log.info("站点雨量CSV文件地址:{}", floodFile); |
| | | // 判断地址不为空 |
| | | if (StringUtils.isEmpty(stationRainFile)) { |
| | | return fail("站点雨量CSV文件地址不能为空", false); |
| | | } |
| | | // 1 读取CSV 文件 |
| | | CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName); |
| | | // 获取仿真时间 duration |
| | | Integer duration = CsvToSQLiteUtils.getDuration(tableName); |
| | | log.info("仿真时间 duration = {}", duration); |
| | | vo.setDuration(duration); |
| | | // 获取降雨总量 total |
| | | Double total = CsvToSQLiteUtils.getTotal(tableName); |
| | | log.info("降雨总量 total = {}", total); |
| | | vo.setTotal(total); |
| | | } else if (RadioEnums.SIMULATE.getCode().equals(vo.getRadio())) { |
| | | if (StringUtils.isEmpty(vo.getStation())) { |
| | | return fail("模拟计算站点不能为空!", false); |
| | | } |
| | | if (vo.getTotal() == null) { |
| | | return fail("模拟计算降雨量不能为空!", false); |
| | | } |
| | | if (vo.getDuration() == null || vo.getDuration() <= 0) { |
| | | return fail("模拟计算计算时长不能为空!", false); |
| | | } |
| | | if (vo.getStationLatitude() == null) { |
| | | return fail("模拟计算计算坐标!", false); |
| | | } |
| | | if (vo.getStationLongitude() == null) { |
| | | return fail("模拟计算计算坐标!", false); |
| | | } |
| | | double aveTotal = BigDecimal.valueOf(vo.getTotal()).divide(BigDecimal.valueOf(vo.getDuration()), 2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | DateTimeFormatter customFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); |
| | | for (int i = 0; i < vo.getDuration(); i++) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("stationName", vo.getStation()); |
| | | jsonObject.put("rainfall", aveTotal); |
| | | jsonObject.put("longitude", vo.getStationLongitude()); |
| | | jsonObject.put("latitude", vo.getStationLatitude()); |
| | | LocalDateTime plusMinutes = now.plusMinutes(i); |
| | | jsonObject.put("datetime", customFormatter.format(plusMinutes)); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | CsvToSQLiteUtils.readCsvSaveLocal(jsonArray, tableName); |
| | | } else { |
| | | return fail("无效的模型计算方式", false); |
| | | } |
| | | // 1 读取CSV 文件 |
| | | array = CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName); |
| | | // 获取仿真时间 duration |
| | | Integer duration = CsvToSQLiteUtils.getDuration(tableName); |
| | | log.info("仿真时间 duration = {}", duration); |
| | | vo.setDuration(duration); |
| | | |
| | | // 获取降雨总量 total |
| | | Double total = CsvToSQLiteUtils.getTotal(tableName); |
| | | log.info("降雨总量 total = {}", total); |
| | | vo.setTotal(total); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("解析站点雨量CSV文件失败"); |
| | | return fail("雨量处理失败!", false); |
| | | } |
| | | // TODO: 2024/12/24 根据这些文件的地址,获取文件内容,创建仿真视图 |
| | | try { |
| | |
| | | dtos.add(new GridDto(vo.getMaxy(), vo.getMinx())); |
| | | dtos.add(new GridDto(vo.getMaxy(), vo.getMaxx())); |
| | | dtos.add(new GridDto(vo.getMiny(), vo.getMaxx())); |
| | | createSem(tableName, dtos, vo); |
| | | String bbox = ""; |
| | | //生成点和线的实体库模型并保存路径 |
| | | String name = vo.getSemUrl(); |
| | | String token = EntityLibraryUtils.login(); |
| | | vo.setPointName(name + "-point"); |
| | | vo.setLinkName(name + "-line"); |
| | | JSONArray min = ProjectionToGeographicUtil.get4548Point(dtos.get(0).getLon(), dtos.get(0).getLat()); |
| | | JSONArray max = ProjectionToGeographicUtil.get4548Point(dtos.get(2).getLon(), dtos.get(2).getLat()); |
| | | bbox = bbox + min.getDouble(0) + "," + min.getDouble(1) + "," + max.getDouble(0) + "," + max.getDouble(1); |
| | | JSONObject point = getModule("layerQueryPointParams.json"); |
| | | String pointUrl = assemble(vo.getPointName(), point.getString("layerid"), bbox, token); |
| | | vo.setPointName(pointUrl); |
| | | JSONObject link = getModule("layerQueryParams.json"); |
| | | String linkUrl = assemble(vo.getLinkName(), link.getString("layerid"), bbox, token); |
| | | vo.setLinkName(linkUrl); |
| | | asyncCall(tableName, dtos, vo, token); |
| | | // 开始模拟计算 |
| | | boolean flag = simuFilesService.createByfiles(vo); |
| | | boolean flag = simuFilesService.createByfiles(vo,token); |
| | | return success(flag, flag ? "成功" : "失败"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | |
| | | |
| | | @ApiOperation(value = "获取点路径") |
| | | @GetMapping("/getPointUrl") |
| | | public R<String> getPointUrl(@RequestParam("id") Integer id) throws Exception{ |
| | | public R<String> getPointUrl(@RequestParam("id") Integer id) throws Exception { |
| | | SimuPo po = simuService.getSimuById(id); |
| | | String token = EntityLibraryUtils.login(); |
| | | if (po != null) { |
| | | return success(po.getPointUrl().replace("{token}",token)); |
| | | return success(po.getPointUrl().replace("{token}", token)); |
| | | } |
| | | return success(null); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取线路径") |
| | | @GetMapping("/getLineUrl") |
| | | public R<String> getLineUrl(@RequestParam("id") Integer id) throws Exception{ |
| | | public R<String> getLineUrl(@RequestParam("id") Integer id) throws Exception { |
| | | SimuPo po = simuService.getSimuById(id); |
| | | String token = EntityLibraryUtils.login(); |
| | | if (po != null) { |
| | | return success(po.getLinkUrl().replace("{token}",token)); |
| | | return success(po.getLinkUrl().replace("{token}", token)); |
| | | } |
| | | return success(null); |
| | | } |
| | | |
| | | public R<Boolean> createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo) throws Exception { |
| | | String name = vo.getSemUrl(); |
| | | private void asyncCall(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token) { |
| | | ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | createSem(tableName, dtos, vo, token); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | public void createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token) throws Exception { |
| | | vo.setSemUrl(inPath + "\\" + vo.getSemUrl()); |
| | | boolean ends = vo.getSemUrl().endsWith("\\"); |
| | | if (!ends) { |
| | |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | String token = EntityLibraryUtils.login(); |
| | | //降雨文件生成 |
| | | saveZarr(tableName, vo.getSemUrl()); |
| | | //管点生成 |
| | |
| | | landuseToSem(vo.getSemUrl()); |
| | | //地形生成 |
| | | terrainToSem(dtos, vo.getSemUrl()); |
| | | String bbox = ""; |
| | | //生成点和线的实体库模型并保存路径 |
| | | vo.setPointName(name + "-point"); |
| | | vo.setLinkName(name + "-line"); |
| | | JSONArray min = ProjectionToGeographicUtil.get4548Point(dtos.get(0).getLon(), dtos.get(0).getLat()); |
| | | JSONArray max = ProjectionToGeographicUtil.get4548Point(dtos.get(2).getLon(), dtos.get(2).getLat()); |
| | | bbox = bbox + min.getDouble(0) + "," + min.getDouble(1) + "," + max.getDouble(0) + "," + max.getDouble(1); |
| | | JSONObject point = getModule("layerQueryPointParams.json"); |
| | | String pointUrl = assemble(vo.getPointName(), point.getString("layerid"), bbox, token); |
| | | vo.setPointName(pointUrl); |
| | | JSONObject link = getModule("layerQueryParams.json"); |
| | | String linkUrl = assemble(vo.getLinkName(), link.getString("layerid"), bbox, token); |
| | | vo.setLinkName(linkUrl); |
| | | return success(true); |
| | | } |
| | | |
| | | |