| | |
| | | package com.se.simu.controller; |
| | | |
| | | import com.se.simu.domain.Layer; |
| | | import com.se.simu.helper.WebHelper; |
| | | import com.se.simu.service.WaterService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | |
| | | /** |
| | | * 内涝控制器 |
| | |
| | | return; |
| | | } |
| | | |
| | | Layer layer = waterService.getLayer(serviceName); |
| | | byte[] bytes = waterService.getLayerJson(serviceName); |
| | | |
| | | WebHelper.writeJson2Page(res, HttpStatus.OK, layer); |
| | | WebHelper.writeBytes(bytes, res); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); |
| | |
| | | } |
| | | |
| | | String file = waterService.getTerraMap(serviceName, width, height); |
| | | writeFile(file, res); |
| | | |
| | | WebHelper.writePng(file, res); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); |
| | |
| | | return; |
| | | } |
| | | |
| | | String file = waterService.getWaterMap(serviceName, width, height); |
| | | writeFile(file, res); |
| | | String file = waterService.getWaterMap(serviceName, width, height, timestamp); |
| | | |
| | | WebHelper.writePng(file, res); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); |
| | |
| | | } |
| | | |
| | | String file = waterService.getFlowMap(serviceName, width, height, timestamp); |
| | | writeFile(file, res); |
| | | |
| | | WebHelper.writePng(file, res); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); |
| | |
| | | if (null == timestamp || timestamp < Y2000) { |
| | | return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "时间不能为空且大于2000年"); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 写文件 |
| | | */ |
| | | private boolean writeFile(String path, HttpServletResponse res) throws Exception { |
| | | if (WebHelper.isEmpty(path)) { |
| | | return WebHelper.writeJson2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, "生成PNG失败"); |
| | | } |
| | | File file = new File(path); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | return WebHelper.writeJson2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, "PNG文件找不到"); |
| | | } |
| | | |
| | | WebHelper.download(path, file.getName(), res); |
| | | |
| | | return true; |
| | | } |