parent
9a4acbd1a4
commit
7d3ae901f1
@ -0,0 +1,107 @@
|
||||
package com.peteralbus.controller;
|
||||
|
||||
import com.peteralbus.entity.Estimate;
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
import com.peteralbus.service.EstimateService;
|
||||
import com.peteralbus.service.EarthquakeInfoService;
|
||||
import com.peteralbus.util.EstimateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@RequestMapping("/estimate")
|
||||
public class EstimateController {
|
||||
/**
|
||||
* The Estimate util.
|
||||
*/
|
||||
EstimateUtil estimateUtil;
|
||||
|
||||
EstimateService estimateService;
|
||||
/**
|
||||
* The Earthquake info service.
|
||||
*/
|
||||
EarthquakeInfoService earthquakeInfoService;
|
||||
|
||||
/**
|
||||
* Sets earthquake info service.
|
||||
*
|
||||
* @param earthquakeInfoService the earthquake info service
|
||||
*/
|
||||
@Autowired
|
||||
public void setEarthquakeInfoService(EarthquakeInfoService earthquakeInfoService)
|
||||
{
|
||||
this.earthquakeInfoService = earthquakeInfoService;
|
||||
}
|
||||
/**
|
||||
* Sets estimate util.
|
||||
*
|
||||
* @param estimateUtil the estimate util
|
||||
*/
|
||||
@Autowired
|
||||
public void setEstimateUtil(EstimateUtil estimateUtil)
|
||||
{
|
||||
this.estimateUtil = estimateUtil;
|
||||
}
|
||||
/**
|
||||
* Sets estimate service.
|
||||
*
|
||||
* @param estimateService
|
||||
*/
|
||||
@Autowired
|
||||
public void setAnalyzeService(EstimateService estimateService) {
|
||||
this.estimateService = estimateService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets estimate result.
|
||||
*
|
||||
* @param earthquakeId the earthquake info id
|
||||
* @return the estimate result
|
||||
*/
|
||||
@GetMapping("/getAnalyzeResult")
|
||||
public Estimate getPredictResult(long earthquakeId){
|
||||
System.out.println(earthquakeId);
|
||||
int count = estimateService.queryAnalyze(earthquakeId);
|
||||
Estimate estimate = new Estimate();
|
||||
if(count==0){
|
||||
Map<String, Object> mapParameter = new HashMap<String, Object>();
|
||||
mapParameter.put("earthquakeId",earthquakeId);
|
||||
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
|
||||
double magnitude = earthquakeInfo.getMagnitude(),
|
||||
highIntensity = earthquakeInfo.getHighIntensity(),
|
||||
longitude = earthquakeInfo.getLongitude(),
|
||||
latitude = earthquakeInfo.getLatitude(),
|
||||
longRadius = earthquakeInfo.getIntensityLineList().get(2).getLongRadius(),
|
||||
shortRadius = earthquakeInfo.getIntensityLineList().get(2).getShortRadius();
|
||||
System.out.println(longRadius);
|
||||
LocalDateTime earthquakeTime = earthquakeInfo.getEarthquakeTime();
|
||||
double radians = Math.toRadians(latitude);//将角度转换为弧度。
|
||||
double minLongitude = longitude-shortRadius/(111-Math.cos(radians)),
|
||||
maxLongitude = longitude+shortRadius/(111-Math.cos(radians)),
|
||||
minLatitude = latitude-longRadius/111,
|
||||
maxLatitude = latitude+longRadius/111;
|
||||
int population=(int)estimateService.getPopulation(minLongitude,maxLongitude,minLatitude,maxLatitude);
|
||||
estimate.setPredictDeath(estimateUtil.deathPredict(earthquakeInfo.getEarthquakeId(),population,magnitude,highIntensity,earthquakeTime,longitude,latitude));
|
||||
estimate.setPredictEconomy(estimateUtil.economyPredict(earthquakeInfo.getHighIntensity()));
|
||||
estimate.setEarthquakeId(earthquakeId);
|
||||
estimate.setPopulation(population);
|
||||
Date date = new Date();
|
||||
estimate.setGmt_time(date);
|
||||
estimateService.insertAnalyze(estimate);
|
||||
}
|
||||
else
|
||||
{
|
||||
estimate = estimateService.queryAnalyzeById(earthquakeId);
|
||||
}
|
||||
return estimate;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.peteralbus.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ToString
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Estimate {
|
||||
@TableId(type= IdType.ASSIGN_ID)
|
||||
private Long analyzeId;
|
||||
private Long earthquakeId;
|
||||
private Double predictDeath;
|
||||
private Double predictEconomy;
|
||||
private int population;
|
||||
private Date gmt_time;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.peteralbus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peteralbus.entity.Estimate;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface EstimateMapper extends BaseMapper<Estimate>
|
||||
{
|
||||
Double getPopulation(@Param("minLongitude") Double minLongitude, @Param("maxLongitude") Double maxLongitude, @Param("minLatitude") Double minLatitude, @Param("maxLatitude") Double maxLatitude);
|
||||
Estimate queryAnalyzeById(@Param("earthquakeId") long earthquakeId);
|
||||
int queryAnalyze(@Param("earthquakeId") long earthquakeId);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.peteralbus.service;
|
||||
|
||||
import com.peteralbus.entity.Estimate;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface EstimateService {
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param minLongitude the minimum Longitude
|
||||
* @param maxLongitude the maximum Longitude
|
||||
* @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);
|
||||
int insertAnalyze(Estimate estimate);
|
||||
Estimate queryAnalyzeById(long earthquakeId);
|
||||
int queryAnalyze(@Param("earthquakeId") long earthquakeId);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.peteralbus.service.impl;
|
||||
|
||||
import com.peteralbus.entity.Estimate;
|
||||
import com.peteralbus.mapper.EstimateMapper;
|
||||
import com.peteralbus.service.EstimateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EstimateServiceImpl implements EstimateService {
|
||||
|
||||
EstimateMapper estimateMapper;
|
||||
@Autowired
|
||||
public void setAnalyzeMapper(EstimateMapper estimateMapper){
|
||||
this.estimateMapper = estimateMapper;
|
||||
}
|
||||
@Override
|
||||
public double getPopulation(Double minLongitude, Double maxLongitude, Double minLatitude, Double maxLatitude) {
|
||||
return estimateMapper.getPopulation(minLongitude,maxLongitude,minLatitude,maxLatitude);
|
||||
}
|
||||
@Override
|
||||
public int insertAnalyze(Estimate analyze){
|
||||
int result = 0;
|
||||
result = estimateMapper.insert(analyze);
|
||||
if (result == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Estimate queryAnalyzeById(long earthquakeId) {
|
||||
return estimateMapper.queryAnalyzeById(earthquakeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryAnalyze(long earthquakeId) {
|
||||
return estimateMapper.queryAnalyze(earthquakeId);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?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.EstimateMapper">
|
||||
<resultMap id="EarthquakeInfoWithLines" type="EarthquakeInfo">
|
||||
<id property="earthquakeId" column="earthquake_id"/>
|
||||
<result property="earthquakeName" column="earthquake_name"/>
|
||||
<result property="magnitude" column="magnitude"/>
|
||||
<result property="highIntensity" column="high_intensity"/>
|
||||
<result property="longitude" column="longitude"/>
|
||||
<result property="latitude" column="latitude"/>
|
||||
<result property="depth" column="depth"/>
|
||||
<result property="earthquakeTime" column="earthquake_time"/>
|
||||
<collection property="intensityLineList" javaType="list" ofType="IntensityLine">
|
||||
<id property="lineId" column="line_id"/>
|
||||
<result property="longRadius" column="long_radius"/>
|
||||
<result property="shortRadius" column="short_radius"/>
|
||||
<result property="angle" column="angle"/>
|
||||
<result property="intensity" column="intensity"/>
|
||||
<result property="earthquakeId" column="earthquake_id"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getPopulation" resultType="double">
|
||||
select avg(z) from population
|
||||
where x>#{minLongitude} and x <#{maxLongitude} and y>#{minLatitude} and y < #{maxLatitude}
|
||||
</select>
|
||||
|
||||
<select id="queryAnalyzeById" resultType="Estimate">
|
||||
select predict_death,predict_economy,population
|
||||
from estimate
|
||||
where earthquake_id = #{earthquakeId}
|
||||
</select>
|
||||
|
||||
<select id="queryAnalyze" resultType="int">
|
||||
select count(*)
|
||||
from estimate
|
||||
where earthquake_id = #{earthquakeId}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue