This commit is contained in:
hky 2023-10-12 14:58:04 +08:00
parent ff0e7ceac7
commit efb44660d2
7 changed files with 255 additions and 93 deletions

View File

@ -0,0 +1,38 @@
package org.jeecg.modules.project.baseAPI.service;
import java.io.IOException;
/**
* @Description: 通用API
* @Author: jeecg-boot
* @Date: 2023-09-20
* @Version: V1.0
*/
public interface IBizBaseAPIService {
/**
* 根据标点高度获取标点对应层级
* @param enginId
* @param height
*/
int getLayerByHeight(String enginId,Integer height) throws IOException;
/**
* 以北为0度获取目标方向可拿到方位角
* @param centerLon
* @param centerLat
* @param targetLon
* @param targetLat
*/
String calcAngle(Double centerLon, Double centerLat, Double targetLon, Double targetLat);
/**
* 获取两点之间的距离
* @param latx
* @param lonx
* @param laty
* @param lony
*/
double regDistance(double latx,double lonx,double laty,double lony);
}

View File

@ -0,0 +1,128 @@
package org.jeecg.modules.project.baseAPI.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.project.baseAPI.service.IBizBaseAPIService;
import org.jeecg.modules.project.baseConfig.bizEngineering.entity.BizEngineering;
import org.jeecg.modules.project.baseConfig.bizEngineering.service.IBizEngineeringService;
import org.jeecg.modules.project.calculateConfig.bizWrf.entity.BizWrf;
import org.jeecg.modules.project.calculateConfig.bizWrf.mapper.BizWrfMapper;
import org.jeecg.modules.util.NcUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ucar.nc2.NetcdfFile;
import ucar.nc2.dataset.NetcdfDataset;
import java.io.IOException;
import java.util.Date;
import static java.lang.Math.PI;
import static java.lang.Math.toRadians;
/**
* @Description: 通用API
* @Author: jeecg-boot
* @Date: 2023-09-20
* @Version: V1.0
*/
@Service
public class BizBaseAPIServiceImpl implements IBizBaseAPIService {
@Autowired
private BizWrfMapper bizWrfService;
@Autowired
private IBizEngineeringService bizEngineeringService;
@Value("${spring.baseHome}")
private String baseHome;
@Value("${spring.localFilePrefix}")
private String localFilePrefix;
@Override
public int getLayerByHeight(String enginId,Integer height) throws IOException {
BizEngineering engineering = bizEngineeringService.getById(enginId);
BizWrf bizWrf = bizWrfService.selectOne(new LambdaQueryWrapper<BizWrf>().eq(BizWrf::getEngineeringId, enginId));
String localFilePath = localFilePrefix + "/" + engineering.getCreateBy() + "/" + engineering.getEngineeringName() + "/";
DateTime startTime = DateUtil.parse(bizWrf.getStartTime(), "yyyy-MM-dd_hh:mm:ss");
String metcr03dName= "METCRO3D_d01_" + DateUtil.format(new Date(startTime.getTime()), "yyMMdd")+".nc";
NetcdfFile ncfile = NetcdfDataset.open(localFilePath + metcr03dName);
NcUtil.getNCByName(ncfile,"ZF",0);
return 0;
}
@Override
public String calcAngle(Double centerLon, Double centerLat, Double targetLon, Double targetLat) {
String direction = "";
//差值
double subLat = centerLon - targetLon;
double subLon = centerLat - targetLat;
double angle = 0;
if (subLat == 0) {
//纬度差值为0 表示两点在同一高度 此时点必然在x轴右侧 或者 x轴左侧
if (subLon > 0) {
//x轴右侧
angle = 90;
direction = "正东";
} else if (subLon < 0) {
//x轴左侧
angle = 270;
direction = "正西";
}
} else if (subLon == 0) {
//经度差值为0 说明点在y轴上方或者y轴下方
if (subLat > 0) {
//y轴上方
angle = 0;
direction = "正北";
} else if (subLat < 0) {
//y轴下方
angle = 180;
direction = "正南";
}
} else {
//根据tan的值求角度 subLon不能为0 纬度差值 除以 经度差值 = tan的值
double v = subLat / subLon;
angle = Math.atan(v) * 180 / PI;
//angle的值在-180到180之间
//判断数据在第几象限
//1正切小于0 在二四象限
if (angle < 0) {
if (subLon > 0) {
//此时的点在中心点的右下角
angle = Math.abs(angle)+ 90;
direction = "东南";
} else if (subLon < 0) {
//此时的点在中心点的左上角
angle = Math.abs(angle) + 270;
direction = "西北";
}
}
//2正切大于0 在一三象限
else if (angle > 0) {
if (subLon > 0) {
//此时的点在中心点的右上角 360-angle
angle = 90-angle;
direction = "东北";
} else if (subLat < 0) {
// 此时的点在中心点的左下角
angle += 180;
direction = "西南";
}
}
}
return direction;
}
@Override
public double regDistance(double latx, double lonx, double laty, double lony) {
return 111.71269150641055729984301412873 * 180 * Math.acos(
Math.cos(toRadians(latx)) * Math.cos(toRadians(laty)) *
Math.cos(toRadians(lonx) - toRadians(lony)) +
Math.sin(toRadians(latx)) * Math.sin(toRadians(laty))) / Math.PI;
}
}

View File

@ -0,0 +1,20 @@
package org.jeecg.modules.project.baseConfig.bizAim.VO;
import lombok.Data;
import org.jeecg.modules.project.baseConfig.bizAim.bizCityAim.entity.BizCityAim;
import org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.entity.BizFacilityAim;
import java.util.List;
@Data
public class FacilityAimVo {
//设施名称
List<String> facilityNames;
//城市信息
BizCityAim bizCityAim;
//目标方向
String direction;
//目标距离
double distance;
}

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
@ -69,4 +70,9 @@ public class BizCityAim implements Serializable {
@Excel(name = "备注", width = 15) @Excel(name = "备注", width = 15)
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
/**距离目标公里数*/
@TableField(exist = false)
private Double distance;
} }

View File

@ -1,20 +1,16 @@
package org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.controller; package org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.controller;
import java.util.Arrays; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.project.baseConfig.bizAim.VO.FacilityAimVo;
import org.jeecg.modules.project.baseConfig.bizAim.bizCityAim.entity.BizCityAim;
import org.jeecg.modules.project.baseConfig.bizAim.bizCityAim.service.IBizCityAimService;
import org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.entity.BizFacilityAim; import org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.entity.BizFacilityAim;
import org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.service.IBizFacilityAimService; import org.jeecg.modules.project.baseConfig.bizAim.bizFacilityAim.service.IBizFacilityAimService;
@ -23,18 +19,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.project.baseAPI.service.IBizBaseAPIService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.aspect.annotation.AutoLog;
@ -54,6 +43,12 @@ public class BizFacilityAimController extends JeecgController<BizFacilityAim, IB
@Autowired @Autowired
private IBizFacilityAimService bizFacilityAimService; private IBizFacilityAimService bizFacilityAimService;
@Autowired
private IBizCityAimService bizCityAimService;
@Autowired
private IBizBaseAPIService bizBaseAPIService;
/** /**
* 分页列表查询 * 分页列表查询
* *
@ -186,7 +181,58 @@ public class BizFacilityAimController extends JeecgController<BizFacilityAim, IB
return Result.OK(bizFacilityAims); return Result.OK(bizFacilityAims);
} }
/** /**
* 获取目标点附近信息
*
* @return
*/
//@AutoLog(value = "设施目标表-获取目标点附近信息")
@ApiOperation(value="设施目标表-获取目标点附近信息", notes="设施目标表-获取目标点附近信息")
@GetMapping(value = "/getAimNearbyInfo")
public Result<FacilityAimVo> getAimNearbyInfo(double lon, double lat) {
FacilityAimVo facilityAimVo = new FacilityAimVo();
List<String> facilityNames = new ArrayList<>();
//获取目标方圆五公里的设施名称
LambdaQueryWrapper<BizFacilityAim> lambdaFacility = new LambdaQueryWrapper();
lambdaFacility.between(BizFacilityAim::getFacilityLon,lon -0.1, lon + 0.1);
lambdaFacility.between(BizFacilityAim::getFacilityLat,lat -0.1, lat + 0.1);
List<BizFacilityAim> bizFacilityAims = bizFacilityAimService.list(lambdaFacility);
if(bizFacilityAims != null && !bizFacilityAims.isEmpty()) {
for (BizFacilityAim facilityAim : bizFacilityAims) {
double km = bizBaseAPIService.regDistance(lat, lon, facilityAim.getFacilityLat(), facilityAim.getFacilityLon());
if(km <= 5){
facilityNames.add(facilityAim.getFacilityName());
}
}
facilityAimVo.setFacilityNames(facilityNames);
}
//获取距离目标最近的城市信息
LambdaQueryWrapper<BizCityAim> lambdaCity = new LambdaQueryWrapper();
lambdaCity.between(BizCityAim::getCityLon,lon -0.1, lon + 0.1);
lambdaCity.between(BizCityAim::getCityLat,lat -0.1, lat + 0.1);
List<BizCityAim> bizCityAims = bizCityAimService.list(lambdaCity);
if(bizCityAims != null && !bizCityAims.isEmpty()) {
for (BizCityAim bizCityAim : bizCityAims) {
double km = bizBaseAPIService.regDistance(lat, lon, bizCityAim.getCityLat(), bizCityAim.getCityLon());
bizCityAim.setDistance(km);
}
List<BizCityAim> citysSorted = bizCityAims.stream().sorted(Comparator.comparing(BizCityAim::getDistance)).collect(Collectors.toList());
BizCityAim bizCityAim = citysSorted.get(0);
String direction = bizBaseAPIService.calcAngle(bizCityAim.getCityLon(), bizCityAim.getCityLat(), lon, lat);
facilityAimVo.setBizCityAim(bizCityAim);
facilityAimVo.setDirection(direction);
facilityAimVo.setDistance(bizCityAim.getDistance());
}
return Result.OK(facilityAimVo);
}
/**
* 导出excel * 导出excel
* *
* @param request * @param request

View File

@ -1,18 +0,0 @@
package org.jeecg.modules.project.calculateConfig.baseAPI.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.project.calculateConfig.bizConfigChemistry.entity.BizConfigChemistry;
import java.io.IOException;
/**
* @Description: 化爆配置表
* @Author: jeecg-boot
* @Date: 2023-09-20
* @Version: V1.0
*/
public interface IBizBaseAPIService {
int getLayerByHeight(String enginId,Integer height) throws IOException;
}

View File

@ -1,58 +0,0 @@
package org.jeecg.modules.project.calculateConfig.baseAPI.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.project.baseConfig.bizEngineering.entity.BizEngineering;
import org.jeecg.modules.project.baseConfig.bizEngineering.service.IBizEngineeringService;
import org.jeecg.modules.project.calculateConfig.baseAPI.service.IBizBaseAPIService;
import org.jeecg.modules.project.calculateConfig.bizConfigChemistry.entity.BizConfigChemistry;
import org.jeecg.modules.project.calculateConfig.bizConfigChemistry.mapper.BizConfigChemistryMapper;
import org.jeecg.modules.project.calculateConfig.bizWrf.entity.BizWrf;
import org.jeecg.modules.project.calculateConfig.bizWrf.mapper.BizWrfMapper;
import org.jeecg.modules.project.calculateConfig.bizWrf.service.IBizWrfService;
import org.jeecg.modules.util.NcUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ucar.nc2.NetcdfFile;
import ucar.nc2.dataset.NetcdfDataset;
import java.io.IOException;
import java.util.Date;
/**
* @Description: 化爆配置表
* @Author: jeecg-boot
* @Date: 2023-09-20
* @Version: V1.0
*/
@Service
public class BizBaseAPIServiceImpl implements IBizBaseAPIService {
@Autowired
private BizWrfMapper bizWrfService;
@Autowired
private IBizEngineeringService bizEngineeringService;
@Value("${spring.baseHome}")
private String baseHome;
@Value("${spring.localFilePrefix}")
private String localFilePrefix;
@Override
public int getLayerByHeight(String enginId,Integer height) throws IOException {
BizEngineering engineering = bizEngineeringService.getById(enginId);
BizWrf bizWrf = bizWrfService.selectOne(new LambdaQueryWrapper<BizWrf>().eq(BizWrf::getEngineeringId, enginId));
String localFilePath = localFilePrefix + "/" + engineering.getCreateBy() + "/" + engineering.getEngineeringName() + "/";
DateTime startTime = DateUtil.parse(bizWrf.getStartTime(), "yyyy-MM-dd_hh:mm:ss");
String metcr03dName= "METCRO3D_d01_" + DateUtil.format(new Date(startTime.getTime()), "yyMMdd")+".nc";
NetcdfFile ncfile = NetcdfDataset.open(localFilePath + metcr03dName);
NcUtil.getNCByName(ncfile,"ZF",0);
return 0;
}
}