/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.floodinundation.service.impl; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springblade.modules.floodinundation.entity.floodinundation; import org.springblade.modules.floodinundation.mapper.FloodinundationMapper; import org.springblade.modules.floodinundation.service.IfloodinundationService; import org.springblade.modules.floodinundation.vo.FloodinundationVO; import org.springblade.modules.water.entity.water; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.InputStream; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 服务实现类 * * @author BladeX * @since 2020-02-27 */ @Service @DS("slaves") public class FloodinundationServiceImpl extends ServiceImpl implements IfloodinundationService { @Override public IPage selectfloodinundationPage(IPage page, FloodinundationVO floodinundationVO) { return baseMapper.selectfloodinundationPage(page, floodinundationVO); } @Override public void upLoadFile(MultipartFile file) { try{ InputStream in = file.getInputStream(); Workbook workbook = null; try{ workbook = new HSSFWorkbook(in); }catch(Exception e){ workbook = new XSSFWorkbook(in); } int numberOfSheets = workbook.getNumberOfSheets(); //第一个sheet for (int j=0;j selectNoticeList(String query) { return baseMapper.selectNoticeList(query); } @Override public List> selectC(int code, String times, String dateEnd) { return baseMapper.selectC(code, times, dateEnd); } @Override public List> selectCS(String times, String dateEnd) { return baseMapper.selectCS(times, dateEnd); } private String getCellValue(Cell cell){ String value =""; switch (cell.getCellType()){ case Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: value = String.valueOf(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_BLANK: value = ""; break; case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: value = String.valueOf(cell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: value = String.valueOf(cell.getCellFormula()); break; } return value; } private String getCellValue2(Cell cell){ String value =""; switch (cell.getCellType()){ case Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: NumberFormat nf = NumberFormat.getInstance(); value = nf.format(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_BLANK: value = ""; break; case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: value = String.valueOf(cell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: value = String.valueOf(cell.getCellFormula()); break; } return value; } @Override public Double selectSS(List waters, Double z, Double ds, Double bzgc) { /*//根据名称查询 List watersInfo = waterService.queryList(null, log);*/ //根据id查询 //List waters = waterService.queryList(pid, ""); int size = waters.size(); Double[] arr1 = new Double[size]; int length = arr1.length; int length1 = arr1.length - 1; //根据名称查询查出预警水面线值,通过实时水位值推算出最新水位差 Double water = bzgc; Double number = z;//实时水面线值 Double numbers = ds;//淹没区起点距 double vs = number - water; Double v = Double.parseDouble(String.format("%.2f", vs)); //定义一个返回的值 Double count = 0.0; Double water1; Double origin; Double sums; Double sum; //循环遍历水面线值,然后通过最新水位差进行更新 for (int i = 0; i < size; i++) { water1 = Double.parseDouble(waters.get(i).getWater()); origin = Double.parseDouble(waters.get(i).getOrigin()); //预警水面值+差值 sums = water1 + v; sum = Double.parseDouble(String.format("%.2f", sums)); waters.get(i).setWater(sum + ""); //把起点距存放到数组里 arr1[i] = origin; } //循环判断淹没区起点距位置 Double water0; Double water2; Double origin1; Double origin2; Double origins1; Double waters1; Double origins2; Double waters2; for (int j = 0; j < length; j++) { if (numbers <= arr1[j]) { water0 = Double.parseDouble(waters.get(j).getWater()); count = water0; break; } //判断是不是超过数组最大值 else if (numbers < arr1[length1]) { if (numbers > arr1[j+1] && numbers < arr1[j + 2]) { if(numbers==arr1[j+1]){ water2 = Double.parseDouble(waters.get(j + 1).getWater()); count = water2; break; } else if (numbers==arr1[j+2]){ water2 = Double.parseDouble(waters.get(j + 2).getWater()); count = water2; break; } else { //获取范围前的水面线值和起点距 origin1 = Double.parseDouble(waters.get(j + 1).getOrigin()); water1 = Double.parseDouble(waters.get(j + 1).getWater()); //获取范围后的水面线值和起点距 origin2 = Double.parseDouble(waters.get(j + 2).getOrigin()); water2 = Double.parseDouble(waters.get(j + 2).getWater()); count = algorithm(origin1, water1, origin2, water2, ds); break; } } /*//出现等于起点距的时候 else { Double water2 = Double.parseDouble(waters.get(j + 2).getWater()); count = water2; break; }*/ } //出现超过最大值的时候 else { origins1 = Double.parseDouble(waters.get(length1 - 1).getOrigin()); waters1 = Double.parseDouble(waters.get(length1 - 1).getWater()); //获取范围后的水面线值和起点距 origins2 = Double.parseDouble(waters.get(length1).getOrigin()); waters2 = Double.parseDouble(waters.get(length1).getWater()); count= algorithm(origins1, waters1, origins2, waters2, ds); break; } } return count; } /** * @param origin1 前一个起点距 * @param water1 前一个水面线 * @param origin2 后一个起点距 * @param water2 后一个水面线 * @param ds 淹没区起点距 * @return */ @Override public Double algorithm(Double origin1, Double water1, Double origin2, Double water2, Double ds) { //算X的值 double v = water2 - water1;//水面线差 double v1 = origin2 - origin1;//起点差 double count = 0.0; if (v < 0) { //如果水面线差是负数就先转正数 double abs = Math.abs(v); //去小数点2位数 Double parseDouble = Double.parseDouble(String.format("%.2f", abs)); //通过2点水面线和以及起点距,求出平均每米的差值 double v2 = parseDouble / v1; //把V2的值不以科学计数法输出,保留6位有效数字 Double s = Double.parseDouble(big2(v2)); //通过淹没区水面线起点距,算水面线值 double v3s = ds - origin1; Double v3 = Double.parseDouble(String.format("%.2f", v3s)); //通过起点距差*每米的差 double v4s = v3 * s; Double v4 = Double.parseDouble(String.format("%.2f", v4s)); //距离第一个起点距的水面线-计算出每米的差 count = water1 - v4; } else { //去小数点2位数 Double parseDouble = Double.parseDouble(String.format("%.2f", v)); //算2点水面线,起点距每米的差 double v2 = parseDouble / v1; //把V2的值不以科学计数法输出,保留6位有效数字 Double s = Double.parseDouble(big2(v2)); //通过淹没区水面线起点距,算水面线值 double v3s = ds - origin1; Double v3 = Double.parseDouble(String.format("%.2f", v3s)); //通过起点距差*每米的差 double v4s = v3 * s; Double v4 = Double.parseDouble(String.format("%.2f", v4s)); //距离第一个起点距的水面线-计算出每米的差 count = water1 + v4; } return count; } //把科学计数法转化成String private static String big2(double d) { BigDecimal d1 = new BigDecimal(Double.toString(d)); BigDecimal d2 = new BigDecimal(Integer.toString(1)); // 四舍五入,保留2位小数 return d1.divide(d2, 5, BigDecimal.ROUND_HALF_UP).toString(); } }