make code style better

main
PeterAlbus 3 years ago
parent 068af770ee
commit 2b6951e386

2
.gitignore vendored

@ -32,4 +32,4 @@ build/
### VS Code ###
.vscode/
/src/main/resources/5963105_www.peteralbus.com.pfx
/src/main/resources/application.yml.example
/src/main/resources/application.yml

@ -16,6 +16,10 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* The type Estimate controller.
* @author PeterAlbus
*/
@CrossOrigin
@RestController
@RequestMapping("/estimate")
@ -25,6 +29,9 @@ public class EstimateController {
*/
EstimateUtil estimateUtil;
/**
* The Estimate service.
*/
EstimateService estimateService;
/**
* The Earthquake info service.
@ -41,6 +48,7 @@ public class EstimateController {
{
this.earthquakeInfoService = earthquakeInfoService;
}
/**
* Sets estimate util.
*
@ -51,10 +59,11 @@ public class EstimateController {
{
this.estimateUtil = estimateUtil;
}
/**
* Sets estimate service.
*
* @param estimateService
* @param estimateService the service of estimate
*/
@Autowired
public void setAnalyzeService(EstimateService estimateService) {
@ -72,7 +81,8 @@ public class EstimateController {
System.out.println(earthquakeId);
int count = estimateService.queryAnalyze(earthquakeId);
Estimate estimate = new Estimate();
if(count==0){
if(count==0)
{
Map<String, Object> mapParameter = new HashMap<String, Object>();
mapParameter.put("earthquakeId",earthquakeId);
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
@ -84,7 +94,8 @@ public class EstimateController {
shortRadius = earthquakeInfo.getIntensityLineList().get(2).getShortRadius();
System.out.println(longRadius);
LocalDateTime earthquakeTime = earthquakeInfo.getEarthquakeTime();
double radians = Math.toRadians(latitude);//将角度转换为弧度。
//将角度转换为弧度。
double radians = Math.toRadians(latitude);
double minLongitude = longitude-shortRadius/(111-Math.cos(radians)),
maxLongitude = longitude+shortRadius/(111-Math.cos(radians)),
minLatitude = latitude-longRadius/111,
@ -94,9 +105,9 @@ public class EstimateController {
estimate.setPredictEconomy(estimateUtil.economyPredict(earthquakeInfo.getHighIntensity()));
estimate.setEarthquakeId(earthquakeId);
estimate.setPopulation(population);
Date date = new Date();
estimate.setGmt_time(date);
estimateService.insertAnalyze(estimate);
LocalDateTime date = LocalDateTime.now();
estimate.setGmtCreate(date);
int result=estimateService.insertAnalyze(estimate);
}
else
{

@ -10,28 +10,63 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* The type Hospital controller.
* @author PeterAlbus
*/
@CrossOrigin
@RestController
public class HospitalController {
@Autowired
/**
* The Hospital service.
*/
HospitalService hospitalService;
/**
* Sets hospital service.
*
* @param hospitalService the hospital service
*/
@Autowired
public void setHospitalService(HospitalService hospitalService)
{
this.hospitalService = hospitalService;
}
/**
* Find all hospital list.
*
* @return the list
*/
@RequestMapping("/findAllHospital")
public List<Hospital> findAllHospital(){
return hospitalService.findAllHospital();
}
/**
* Calculate distance distance.
*
* @param lng the lng
* @param lat the lat
* @return the distance
*/
@RequestMapping("/calculateDistance")
public Distance calculateDistance(double lng, double lat){//输入经纬度的值遍历所有Hosiptai的经纬度并比较其距离
// return getDistance(121.446014,31.215937,121.446028464238,31.2158502442799 );
public Distance calculateDistance(double lng, double lat)
{
//输入经纬度的值遍历所有Hospital的经纬度并比较其距离
//return getDistance(121.446014,31.215937,121.446028464238,31.2158502442799 );
System.out.print("进入函数calculate");
List<Hospital> hospitals=hospitalService.findAllHospital();
double minDistance=Double.MAX_VALUE;
Double minDistance=Double.MAX_VALUE;
Distance distance=new Distance();
for(int i=0;i<hospitals.size();i++){
Hospital hospital=hospitals.get(i);
double distanceTwoPlaces=getDistance(hospital.getLon(),hospital.getLat(),lng,lat);
for (Hospital hospital : hospitals)
{
Double distanceTwoPlaces = getDistance(hospital.getLon(), hospital.getLat(), lng, lat);
System.out.println(distanceTwoPlaces);
minDistance=Math.min(minDistance,distanceTwoPlaces);
if(minDistance==distanceTwoPlaces){
minDistance = Math.min(minDistance, distanceTwoPlaces);
if (minDistance.equals(distanceTwoPlaces))
{
distance.setDistance(minDistance);
distance.setEndLon(hospital.getLon());
distance.setEndLat(hospital.getLat());
@ -44,6 +79,16 @@ public class HospitalController {
return distance;
}
private static final double EARTH_RADIUS = 6378.137;
/**
* Gets distance.
*
* @param longitude1 the longitude 1
* @param latitude1 the latitude 1
* @param longitude2 the longitude 2
* @param latitude2 the latitude 2
* @return the distance
*/
public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
// 纬度
double lat1 = Math.toRadians(latitude1);
@ -56,16 +101,25 @@ public class HospitalController {
// 经度之差
double b = lng1 - lng2;
// 计算两点距离的公式
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
// 弧长乘地球半径, 返回单位: 千米
s = s * EARTH_RADIUS;
return s;
}
// Haversine公式的最终实现方式可以有多种比如借助转角度的函数atan2
public static double getDistance2(double longitude1, double latitude1,
double longitude2, double latitude2) {
/**
* Gets distance 2.
*
* @param longitude1 the longitude 1
* @param latitude1 the latitude 1
* @param longitude2 the longitude 2
* @param latitude2 the latitude 2
* @return the distance 2
*/
public static double getDistance2(double longitude1, double latitude1, double longitude2, double latitude2)
{
//Haversine公式的最终实现方式可以有多种比如借助转角度的函数atan2
double latDistance = Math.toRadians(longitude1 - longitude2);
double lngDistance = Math.toRadians(latitude1 - latitude2);

@ -4,15 +4,19 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* The type Distance.
* @author PeterAlbus
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Distance {
private double startLon;
private double startLat;
private double endLon;
private double endLat;
private double distance;
private Double startLon;
private Double startLat;
private Double endLon;
private Double endLat;
private Double distance;
private String endName;
private String endAddress;
}

@ -29,6 +29,7 @@ import java.util.List;
public class EarthquakeInfo implements Serializable
{
@TableId(type= IdType.ASSIGN_ID)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long earthquakeId;
private String earthquakeName;
private Double magnitude;

@ -3,11 +3,15 @@ package com.peteralbus.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.apache.tomcat.jni.Local;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import java.util.Date;
@ToString
@ -16,10 +20,14 @@ import java.util.Date;
@NoArgsConstructor
public class Estimate {
@TableId(type= IdType.ASSIGN_ID)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long analyzeId;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long earthquakeId;
private Double predictDeath;
private Double predictEconomy;
private int population;
private Date gmt_time;
private Integer population;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime gmtCreate;
}

@ -1,16 +1,22 @@
package com.peteralbus.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* The type Hospital.
* @author PeterAlbus
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("fire_center")
public class Hospital {
private int id;
private double lon;
private double lat;
private Integer id;
private Double lon;
private Double lat;
private String name;
private String address;
private String pname;

@ -2,6 +2,7 @@ package com.peteralbus.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -21,11 +22,13 @@ import java.io.Serializable;
public class IntensityLine implements Serializable
{
@TableId(type= IdType.ASSIGN_ID)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long lineId;
private Double longRadius;
private Double shortRadius;
private Double angle;
private Integer intensity;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long earthquakeId;
public IntensityLine(Double longRadius, Double shortRadius, Double angle, Integer intensity, Long earthquakeId)

@ -1,15 +1,17 @@
package com.peteralbus.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peteralbus.entity.Hospital;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
/**
* The interface Hospital mapper.
* @author PeterAlbus
*/
@Mapper
public interface HospitalMapper {
public List<Hospital> findAllHospital();
public interface HospitalMapper extends BaseMapper<Hospital>
{
}

@ -3,18 +3,42 @@ package com.peteralbus.service;
import com.peteralbus.entity.Estimate;
import org.apache.ibatis.annotations.Param;
/**
* The interface Estimate service.
*/
public interface EstimateService {
/**
* Get
*
* @param minLongitude the minimum Longitude
* @param maxLongitude the maximum Longitude
* @param minLatitude the minimum Latitude
* @param maxLatitude the maximum Latitude
* @param minLatitude the minimum Latitude
* @param maxLatitude the maximum Latitude
* @return the double
*/
double getPopulation(@Param("minLongitude") Double minLongitude, @Param("maxLongitude") Double maxLongitude, @Param("minLatitude") Double minLatitude, @Param("maxLatitude") Double maxLatitude);
/**
* Insert analyze int.
*
* @param estimate the estimate
* @return the int
*/
int insertAnalyze(Estimate estimate);
/**
* Query analyze by id estimate.
*
* @param earthquakeId the earthquake id
* @return the estimate
*/
Estimate queryAnalyzeById(long earthquakeId);
/**
* Query analyze int.
*
* @param earthquakeId the earthquake id
* @return the int
*/
int queryAnalyze(@Param("earthquakeId") long earthquakeId);
}

@ -4,6 +4,15 @@ import com.peteralbus.entity.Hospital;
import java.util.List;
/**
* The interface Hospital service.
* @author PeterAlbus
*/
public interface HospitalService {
/**
* Find all hospital list.
*
* @return the list
*/
public List<Hospital> findAllHospital();
}

@ -6,10 +6,23 @@ import com.peteralbus.service.EstimateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* The type Estimate service.
* @author PeterAlbus
*/
@Service
public class EstimateServiceImpl implements EstimateService {
/**
* The Estimate mapper.
*/
EstimateMapper estimateMapper;
/**
* Set analyze mapper.
*
* @param estimateMapper the estimate mapper
*/
@Autowired
public void setAnalyzeMapper(EstimateMapper estimateMapper){
this.estimateMapper = estimateMapper;

@ -8,12 +8,28 @@ import org.springframework.stereotype.Service;
import java.util.List;
/**
* The type Hospital service.
* @author PeterAlbus
*/
@Service
public class HospitalServiceImpl implements HospitalService {
@Autowired
private HospitalMapper hospitalMapper;
/**
* Sets hospital mapper.
*
* @param hospitalMapper the hospital mapper
*/
@Autowired
public void setHospitalMapper(HospitalMapper hospitalMapper)
{
this.hospitalMapper = hospitalMapper;
}
@Override
public List<Hospital> findAllHospital() {
return hospitalMapper.findAllHospital();
return hospitalMapper.selectList(null);
}
}

@ -26,7 +26,7 @@
</select>
<select id="queryAnalyzeById" resultType="Estimate">
select predict_death,predict_economy,population
select analyze_id, earthquake_id, predict_death, predict_economy, population, gmt_create
from estimate
where earthquake_id = #{earthquakeId}
</select>

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.peteralbus.mapper.HospitalMapper">
<select id="findAllHospital" resultType="com.peteralbus.entity.Hospital">
select * from hospital_center
</select>
</mapper>
Loading…
Cancel
Save