| | |
| | | package com.se.simu.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.se.simu.domain.po.SimuPo; |
| | | import com.se.simu.domain.vo.*; |
| | | import com.se.simu.enums.RadioEnums; |
| | | import com.se.simu.enums.SemErrorEnums; |
| | | import com.se.simu.helper.StringHelper; |
| | | import com.se.simu.helper.WebHelper; |
| | | import com.se.simu.mapper.SimuMapper; |
| | | 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.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.sql.Timestamp; |
| | | 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 = "仿真管理") |
| | |
| | | |
| | | @Resource |
| | | PropertiesConfig config; |
| | | |
| | | @Resource |
| | | SimuMapper simuMapper; |
| | | |
| | | @Value("${simu-app.filePath}") |
| | | private String uploadedFolder; |
| | |
| | | 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); |
| | | SimuPo simu = saveSimu(vo); |
| | | //生成sem文件 |
| | | asyncCall(tableName, dtos, vo, token, simu); |
| | | |
| | | // 开始模拟计算 |
| | | boolean flag = simuFilesService.createByfiles(vo); |
| | | return success(flag, flag ? "成功" : "失败"); |
| | | //boolean flag = simuFilesService.createByfiles(vo, token); |
| | | return success(simu.getId() != null ? "成功" : "失败"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | public SimuPo saveSimu(CreateFilesSimuVo vo) { |
| | | Date now = new Date(); |
| | | String date = StringHelper.YMDHMS2_FORMAT.format(now); |
| | | if (StringHelper.isEmpty(vo.getName())) { |
| | | vo.setName(date); |
| | | } |
| | | DataPo data = BeanUtil.copyProperties(vo, DataPo.class); |
| | | data.setPath(date, date); |
| | | SimuPo simu = new SimuPo(vo.getNum(), vo.getPid(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak()); |
| | | simu.setServiceName(date); |
| | | simu.setCreateTime(new Timestamp(now.getTime())); |
| | | simu.setSemUrl(vo.getSemUrl()); |
| | | simu.setPointUrl(vo.getPointName()); |
| | | simu.setLinkUrl(vo.getLinkName()); |
| | | simu.setSemUrl(inPath + "\\" + vo.getSemUrl()); |
| | | int rows = simuMapper.insert(simu); |
| | | return simu; |
| | | } |
| | | |
| | | @ApiOperation(value = "获取点路径") |
| | |
| | | return success(null); |
| | | } |
| | | |
| | | public R<Boolean> createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo) throws Exception { |
| | | String name = vo.getSemUrl(); |
| | | vo.setSemUrl(inPath + "\\" + vo.getSemUrl()); |
| | | boolean ends = vo.getSemUrl().endsWith("\\"); |
| | | if (!ends) { |
| | | vo.setSemUrl(vo.getSemUrl() + "\\"); |
| | | } |
| | | File file = new File(vo.getSemUrl()); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | String token = EntityLibraryUtils.login(); |
| | | //降雨文件生成 |
| | | saveZarr(tableName, vo.getSemUrl()); |
| | | //管点生成 |
| | | pointTosem(dtos, token, vo.getSemUrl()); |
| | | //管线生成 |
| | | lineToSem(dtos, token, vo.getSemUrl()); |
| | | //范围生成 |
| | | gridToCityJson(dtos, vo.getSemUrl()); |
| | | //河流生成 |
| | | riverToSem(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); |
| | | private void asyncCall(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token, SimuPo simu) { |
| | | ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | createSem(tableName, dtos, vo, token, simu); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | public void createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token, SimuPo simu) throws Exception { |
| | | int code=1; |
| | | try { |
| | | vo.setSemUrl(inPath + "\\" + vo.getSemUrl()); |
| | | boolean ends = vo.getSemUrl().endsWith("\\"); |
| | | if (!ends) { |
| | | vo.setSemUrl(vo.getSemUrl() + "\\"); |
| | | } |
| | | File file = new File(vo.getSemUrl()); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | //初始化 |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //降雨文件生成 |
| | | saveZarr(tableName, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //管点生成 |
| | | pointTosem(dtos, token, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //管线生成 |
| | | lineToSem(dtos, token, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //范围生成 |
| | | gridToCityJson(dtos, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //河流生成 |
| | | riverToSem(vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //土地利用生成 |
| | | landuseToSem(vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //地形生成 |
| | | terrainToSem(dtos, vo.getSemUrl()); |
| | | update(simu, 10, null); |
| | | code+=1; |
| | | //9=调用求解/10=求解分析 |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | update(simu, -simu.getStatus(), SemErrorEnums.of(code)); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | private void update(SimuPo simu, int status, String rs) { |
| | | simu.setStatus(status); |
| | | if (null != rs) simu.setResult(rs); |
| | | simu.setUpdateTime(WebHelper.getCurrentTimestamp()); |
| | | |
| | | simuMapper.updateById(simu); |
| | | } |
| | | |
| | | public String assemble(String name, String layerid, String bbox, String token) throws Exception { |
| | | JSONObject jsonObject = EntityLibraryUtils.createAssemble(name, token); |