| | |
| | | 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 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 = "仿真管理") |
| | |
| | | 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(); |
| | | 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(); |
| | | 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()); |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | |
| | | |