basic codes
parent
96577fd4ce
commit
1b3785aaf7
@ -0,0 +1,35 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
/src/main/resources/5963105_www.peteralbus.com.pfx
|
||||
/src/main/resources/application.yml
|
@ -1,2 +1,6 @@
|
||||
# earthquick_springboot
|
||||
back end of project earthquick
|
||||
|
||||
使用流程:
|
||||
将application.yml.example修改为application.yml
|
||||
其中的数据库信息改成自己的
|
||||
|
@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.peteralbus</groupId>
|
||||
<artifactId>earthquick</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>earthquick</name>
|
||||
<description>earthquick</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
<!-- 引入json处理包 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.79</version>
|
||||
</dependency>
|
||||
<!--使用日期格式注解需要的两个包-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.10.13</version>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<!-- swagger-bootstrap-ui增强ui -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
<!--jsoup-->
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.14.3</version>
|
||||
</dependency>
|
||||
<!--lombok-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--test-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,26 @@
|
||||
package com.peteralbus;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* The type Earthquick application.
|
||||
* @author PeterAlbus
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class EarthquickApplication
|
||||
{
|
||||
|
||||
/**
|
||||
* The entry point of application.
|
||||
*
|
||||
* @param args the input arguments
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(EarthquickApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.peteralbus.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
|
||||
/**
|
||||
* The type Swagger config.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig
|
||||
{
|
||||
/**
|
||||
* Create rest api docket.
|
||||
*
|
||||
* @return the docket
|
||||
*/
|
||||
@Bean
|
||||
public Docket createRestApi()
|
||||
{
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
.paths(PathSelectors.any()).build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo()
|
||||
{
|
||||
return new ApiInfoBuilder()
|
||||
.title("EarthQuick API Doc")
|
||||
.description("This is a restful api document of EarthQuick.")
|
||||
.contact(new Contact("PeterAlbus", "https://www.peteralbus.com/", "wuhongdb@163.com"))
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package com.peteralbus.controller;
|
||||
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
import com.peteralbus.service.EarthquakeInfoService;
|
||||
import com.peteralbus.util.EstimateUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Earthquake info controller.
|
||||
*
|
||||
* @author PeterAlbus
|
||||
*/
|
||||
@Api(value = "api of earthquake info")
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@RequestMapping("/earthquakeInfo")
|
||||
public class EarthquakeInfoController
|
||||
{
|
||||
/**
|
||||
* The Estimate util.
|
||||
*/
|
||||
EstimateUtil estimateUtil;
|
||||
/**
|
||||
* The Earthquake info service.
|
||||
*/
|
||||
EarthquakeInfoService earthquakeInfoService;
|
||||
|
||||
/**
|
||||
* Sets estimate util.
|
||||
*
|
||||
* @param estimateUtil the estimate util
|
||||
*/
|
||||
@Autowired
|
||||
public void setEstimateUtil(EstimateUtil estimateUtil)
|
||||
{
|
||||
this.estimateUtil = estimateUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets earthquake info service.
|
||||
*
|
||||
* @param earthquakeInfoService the earthquake info service
|
||||
*/
|
||||
@Autowired
|
||||
public void setEarthquakeInfoService(EarthquakeInfoService earthquakeInfoService)
|
||||
{
|
||||
this.earthquakeInfoService = earthquakeInfoService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all earthquake.
|
||||
*
|
||||
* @return the all earthquake
|
||||
*/
|
||||
@ApiOperation(value = "get all earthquake")
|
||||
@GetMapping("/getAllEarthquake")
|
||||
List<EarthquakeInfo> getAllEarthquake()
|
||||
{
|
||||
return earthquakeInfoService.queryInfoWithLine(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets earthquake by id.
|
||||
*
|
||||
* @param earthquakeId the earthquake info id
|
||||
* @return the earthquake by id
|
||||
*/
|
||||
@GetMapping("/getEarthquakeById")
|
||||
EarthquakeInfo getEarthquakeById(int earthquakeId)
|
||||
{
|
||||
Map<String, Object> mapParameter = new HashMap<String, Object>();
|
||||
mapParameter.put("earthquakeId",earthquakeId);
|
||||
return earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets death predict.
|
||||
*
|
||||
* @param earthquakeId the earthquake info id
|
||||
* @return the death predict
|
||||
*/
|
||||
@GetMapping("/getDeathPredict")
|
||||
public double getDeathPredict(int earthquakeId)
|
||||
{
|
||||
Map<String, Object> mapParameter = new HashMap<String, Object>();
|
||||
mapParameter.put("earthquakeId",earthquakeId);
|
||||
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
|
||||
int population=3133;
|
||||
return estimateUtil.deathPredict(population,earthquakeInfo.getMagnitude(),earthquakeInfo.getHighIntensity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets economy predict.
|
||||
*
|
||||
* @param earthquakeId the earthquake info id
|
||||
* @return the economy predict
|
||||
*/
|
||||
@GetMapping("/getEconomyPredict")
|
||||
public double getEconomyPredict(int earthquakeId)
|
||||
{
|
||||
Map<String, Object> mapParameter = new HashMap<String, Object>();
|
||||
mapParameter.put("earthquakeId",earthquakeId);
|
||||
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
|
||||
return estimateUtil.economyPredict(earthquakeInfo.getHighIntensity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add earthquake string.
|
||||
*
|
||||
* @param earthquakeInfo the earthquake info
|
||||
* @return the string
|
||||
*/
|
||||
@RequestMapping("/addEarthquake")
|
||||
public String addEarthquake(EarthquakeInfo earthquakeInfo)
|
||||
{
|
||||
Double dividingLine=105.0;
|
||||
if(earthquakeInfo.getLongitude()<dividingLine)
|
||||
{
|
||||
/*西部地区*/
|
||||
earthquakeInfo.getIntensity(5.253,1.398,4.164,26,0,2.019,1.398,2.943,8,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*东部地区*/
|
||||
earthquakeInfo.getIntensity(5.019,1.446,4.136,24,0,2.240,1.446,3.070,9,0);
|
||||
}
|
||||
int result=earthquakeInfoService.insertEarthquakeInfo(earthquakeInfo);
|
||||
if(result==0)
|
||||
{
|
||||
return "fail";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete earthquake string.
|
||||
*
|
||||
* @param earthquakeId the earthquake id
|
||||
* @return the string
|
||||
*/
|
||||
@RequestMapping("/deleteById")
|
||||
public String deleteEarthquake(int earthquakeId)
|
||||
{
|
||||
EarthquakeInfo earthquakeInfo=this.getEarthquakeById(earthquakeId);
|
||||
int result=earthquakeInfoService.deleteEarthquakeInfo(earthquakeInfo);
|
||||
if(result>0)
|
||||
{
|
||||
return "success";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.peteralbus.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Earthquake info.
|
||||
*
|
||||
* @author PeterAlbus
|
||||
*/
|
||||
@ToString
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EarthquakeInfo implements Serializable
|
||||
{
|
||||
@TableId(type= IdType.ASSIGN_ID)
|
||||
private Long earthquakeId;
|
||||
private String earthquakeName;
|
||||
private Double magnitude;
|
||||
private Double highIntensity;
|
||||
private Double longitude;
|
||||
private Double latitude;
|
||||
private Double depth;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime earthquakeTime;
|
||||
@TableField(exist = false)
|
||||
private List<IntensityLine> intensityLineList=new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Gets intensity.
|
||||
*
|
||||
* @param x1 The first regression constant of the regression equation(for long radius)
|
||||
* @param y1 the second regression constant of the regression equation(for long radius)
|
||||
* @param z1 the third regression constant of the regression equation(for long radius)
|
||||
* @param b1 the fourth regression constant of the regression equation(for long radius)
|
||||
* @param e1 the fifth regression constant of the regression equation(for long radius)
|
||||
* @param x2 The first regression constant of the regression equation(for short radius)
|
||||
* @param y2 the second regression constant of the regression equation(for short radius)
|
||||
* @param z2 the third regression constant of the regression equation(for short radius)
|
||||
* @param b2 the fourth regression constant of the regression equation(for short radius)
|
||||
* @param e2 the fifth regression constant of the regression equation(for short radius)
|
||||
*/
|
||||
public void getIntensity(double x1,double y1,double z1,double b1,double e1,double x2,double y2,double z2,double b2,double e2)
|
||||
{
|
||||
double longRadius =0,shortRadius = 0;
|
||||
double ia=x1+y1*magnitude-z1*Math.log10(longRadius+b1)+e1;
|
||||
double ib=x2+y2*magnitude-z2*Math.log10(shortRadius+b2)+e2;
|
||||
System.out.println("震中烈度:"+ia+"/"+ib);
|
||||
setHighIntensity(ia);
|
||||
int intensity=(int)ia;
|
||||
intensityLineList.clear();
|
||||
int count=0;
|
||||
while (intensity>3)
|
||||
{
|
||||
longRadius=Math.pow(10,-(intensity-x1-e1-y1*magnitude)/z1)-b1;
|
||||
shortRadius=Math.pow(10,-(intensity-x2-e2-y2*magnitude)/z2)-b2;
|
||||
IntensityLine intensityLine=new IntensityLine(longRadius,shortRadius,-20.0,intensity,earthquakeId);
|
||||
intensityLineList.add(intensityLine);
|
||||
intensity--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets intensity , use ln.
|
||||
*
|
||||
* @param x1 The first regression constant of the regression equation(for long radius)
|
||||
* @param y1 the second regression constant of the regression equation(for long radius)
|
||||
* @param z1 the third regression constant of the regression equation(for long radius)
|
||||
* @param b1 the fourth regression constant of the regression equation(for long radius)
|
||||
* @param x2 The first regression constant of the regression equation(for short radius)
|
||||
* @param y2 the second regression constant of the regression equation(for short radius)
|
||||
* @param z2 the third regression constant of the regression equation(for short radius)
|
||||
* @param b2 the fourth regression constant of the regression equation(for short radius)
|
||||
*/
|
||||
public void getIntensityLn(double x1,double y1,double z1,double b1,double x2,double y2,double z2,double b2)
|
||||
{
|
||||
double longRadius =0,shortRadius = 0;
|
||||
double ia=x1+y1*magnitude-z1*Math.log10(longRadius+b1);
|
||||
double ib=x2+y2*magnitude-z2*Math.log10(shortRadius+b2);
|
||||
System.out.println("震中烈度:"+ia+"/"+ib);
|
||||
setHighIntensity(ia);
|
||||
int intensity=(int)ia;
|
||||
intensityLineList.clear();
|
||||
while (intensity>1)
|
||||
{
|
||||
longRadius=Math.exp(-(intensity-x1-y1*magnitude)/z1)-b1;
|
||||
shortRadius=Math.exp(-(intensity-x2-y2*magnitude)/z2)-b2;
|
||||
IntensityLine intensityLine=new IntensityLine(longRadius,shortRadius,-20.0,intensity,earthquakeId);
|
||||
intensityLineList.add(intensityLine);
|
||||
intensity--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets formatted time.
|
||||
*
|
||||
* @return the formatted time
|
||||
*/
|
||||
public String getFormattedTime()
|
||||
{
|
||||
DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
return dateTimeFormatter.format(earthquakeTime);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.peteralbus.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Intensity line.
|
||||
*
|
||||
* @author PeterAlbus
|
||||
*/
|
||||
@ToString
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IntensityLine implements Serializable
|
||||
{
|
||||
@TableId(type= IdType.ASSIGN_ID)
|
||||
private Long lineId;
|
||||
private Double longRadius;
|
||||
private Double shortRadius;
|
||||
private Double angle;
|
||||
private Integer intensity;
|
||||
private Long earthquakeId;
|
||||
|
||||
public IntensityLine(Double longRadius, Double shortRadius, Double angle, Integer intensity, Long earthquakeId)
|
||||
{
|
||||
this.longRadius = longRadius;
|
||||
this.shortRadius = shortRadius;
|
||||
this.angle = angle;
|
||||
this.intensity = intensity;
|
||||
this.earthquakeId = earthquakeId;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.peteralbus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The interface Earthquake info mapper.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
@Mapper
|
||||
public interface EarthquakeInfoMapper extends BaseMapper<EarthquakeInfo>
|
||||
{
|
||||
/**
|
||||
* Query info with line list.
|
||||
*
|
||||
* @param parameter the parameter which can contain earthquakeId,startIndex,pageSize
|
||||
* @return the list
|
||||
*/
|
||||
List<EarthquakeInfo> queryInfoWithLine(Map<String, Object> parameter);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.peteralbus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peteralbus.entity.IntensityLine;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* The interface Intensity line mapper.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
@Mapper
|
||||
public interface IntensityLineMapper extends BaseMapper<IntensityLine>
|
||||
{
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.peteralbus.service;
|
||||
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The interface Earthquake info service.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
public interface EarthquakeInfoService
|
||||
{
|
||||
/**
|
||||
* Query info with line list.
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @return the list
|
||||
*/
|
||||
List<EarthquakeInfo> queryInfoWithLine(Map<String, Object> parameter);
|
||||
|
||||
/**
|
||||
* Insert earthquake info int.
|
||||
*
|
||||
* @param earthquakeInfo the earthquake info
|
||||
* @return the int
|
||||
*/
|
||||
int insertEarthquakeInfo(EarthquakeInfo earthquakeInfo);
|
||||
|
||||
/**
|
||||
* Delete earthquake info int.
|
||||
*
|
||||
* @param earthquakeInfo the earthquake info
|
||||
* @return the int
|
||||
*/
|
||||
int deleteEarthquakeInfo(EarthquakeInfo earthquakeInfo);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.peteralbus.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* The interface Intensity line service.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
public interface IntensityLineService
|
||||
{
|
||||
/**
|
||||
* Gets multi line string wkt to json.
|
||||
*
|
||||
* @param wkt the wkt
|
||||
* @return the multi line string wkt to json
|
||||
*/
|
||||
List<Double[]> getMultiLineStringWktToJson(String wkt);
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.peteralbus.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
import com.peteralbus.entity.IntensityLine;
|
||||
import com.peteralbus.mapper.EarthquakeInfoMapper;
|
||||
import com.peteralbus.mapper.IntensityLineMapper;
|
||||
import com.peteralbus.service.EarthquakeInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The type Earthquake info service.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
@Service
|
||||
public class EarthquakeInfoServiceImpl implements EarthquakeInfoService
|
||||
{
|
||||
/**
|
||||
* The Earthquake info mapper.
|
||||
*/
|
||||
EarthquakeInfoMapper earthquakeInfoMapper;
|
||||
/**
|
||||
* The Intensity line mapper.
|
||||
*/
|
||||
IntensityLineMapper intensityLineMapper;
|
||||
|
||||
/**
|
||||
* Sets earthquake info mapper.
|
||||
*
|
||||
* @param earthquakeInfoMapper the earthquake info mapper
|
||||
*/
|
||||
@Autowired
|
||||
public void setEarthquakeInfoMapper(EarthquakeInfoMapper earthquakeInfoMapper)
|
||||
{
|
||||
this.earthquakeInfoMapper = earthquakeInfoMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets intensity line mapper.
|
||||
*
|
||||
* @param intensityLineMapper the intensity line mapper
|
||||
*/
|
||||
@Autowired
|
||||
public void setIntensityLineMapper(IntensityLineMapper intensityLineMapper)
|
||||
{
|
||||
this.intensityLineMapper = intensityLineMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EarthquakeInfo> queryInfoWithLine(Map<String, Object> parameter)
|
||||
{
|
||||
return earthquakeInfoMapper.queryInfoWithLine(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertEarthquakeInfo(EarthquakeInfo earthquakeInfo)
|
||||
{
|
||||
int result = 0;
|
||||
result = earthquakeInfoMapper.insert(earthquakeInfo);
|
||||
if (result == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
for (IntensityLine inensityLine : earthquakeInfo.getIntensityLineList())
|
||||
{
|
||||
inensityLine.setEarthquakeId(earthquakeInfo.getEarthquakeId());
|
||||
result = intensityLineMapper.insert(inensityLine);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteEarthquakeInfo(EarthquakeInfo earthquakeInfo)
|
||||
{
|
||||
int result = 0;
|
||||
QueryWrapper<IntensityLine> intensityLineQueryWrapper = new QueryWrapper<>();
|
||||
intensityLineQueryWrapper.eq("earthquake_id", earthquakeInfo.getEarthquakeId());
|
||||
result = intensityLineMapper.delete(intensityLineQueryWrapper);
|
||||
if (result > 0)
|
||||
{
|
||||
result = earthquakeInfoMapper.deleteById(earthquakeInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.peteralbus.service.impl;
|
||||
|
||||
|
||||
import com.peteralbus.service.IntensityLineService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Intensity line service.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
public class IntensityLineServiceImpl implements IntensityLineService
|
||||
{
|
||||
@Override
|
||||
public List<Double[]> getMultiLineStringWktToJson(String wkt)
|
||||
{
|
||||
String toTailWkt = wkt.substring(0, wkt.length() - 1);
|
||||
String[] strHead = toTailWkt.split("\\(", 2);
|
||||
String[] strList = strHead[1].split("\\),\\(");
|
||||
List<Double[]> list = new ArrayList<Double[]>();
|
||||
for (String value : strList)
|
||||
{
|
||||
String item = value.trim();
|
||||
item = item.substring(1, item.length() - 1);
|
||||
String[] items = item.split(",");
|
||||
for (String s : items)
|
||||
{
|
||||
String jItem = s.trim();
|
||||
String[] jItems = jItem.split(" ");
|
||||
Double[] listResult = new Double[]{
|
||||
Double.parseDouble(jItems[0]),
|
||||
Double.parseDouble(jItems[1])};
|
||||
list.add(listResult);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.peteralbus.task;
|
||||
|
||||
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
import com.peteralbus.service.EarthquakeInfoService;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* The type Schedule Task.
|
||||
* @author PeterAlbus
|
||||
* Created on 2022/1/20.
|
||||
*/
|
||||
@Component
|
||||
public class ScheduleTask
|
||||
{
|
||||
EarthquakeInfoService earthquakeInfoService;
|
||||
|
||||
@Autowired
|
||||
public void setEarthquakeInfoService(EarthquakeInfoService earthquakeInfoService)
|
||||
{
|
||||
this.earthquakeInfoService = earthquakeInfoService;
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 55 23 * * ?")
|
||||
public void getNewEarthquake()
|
||||
{
|
||||
String url = "http://www.ceic.ac.cn/speedsearch";
|
||||
try
|
||||
{
|
||||
Document doc = Jsoup.connect(url).get();
|
||||
Element element = doc.select("table").first();
|
||||
Elements els = element.select("tr");
|
||||
int skip=1;
|
||||
for (Element el : els)
|
||||
{
|
||||
if(skip==1)
|
||||
{
|
||||
skip=0;
|
||||
continue;
|
||||
}
|
||||
Elements ele = el.select("td");
|
||||
Double magnitude=Double.parseDouble(ele.get(0).text());
|
||||
Double longitude=Double.parseDouble(ele.get(3).text());
|
||||
Double latitude=Double.parseDouble(ele.get(2).text());
|
||||
Double depth=Double.parseDouble(ele.get(4).text());
|
||||
String earthquakeName=ele.get(5).text();
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime time=LocalDateTime.parse(ele.get(1).text(),dtf);
|
||||
EarthquakeInfo earthquakeInfo=new EarthquakeInfo();
|
||||
earthquakeInfo.setEarthquakeName(earthquakeName);
|
||||
earthquakeInfo.setLatitude(latitude);
|
||||
earthquakeInfo.setLongitude(longitude);
|
||||
earthquakeInfo.setLatitude(latitude);
|
||||
earthquakeInfo.setMagnitude(magnitude);
|
||||
earthquakeInfo.setEarthquakeTime(time);
|
||||
earthquakeInfo.setDepth(depth);
|
||||
Double dividingLine=105.1;
|
||||
if(earthquakeInfo.getLongitude()<dividingLine)
|
||||
{
|
||||
earthquakeInfo.getIntensity(5.253,1.398,4.164,26,0,2.019,1.398,2.943,8,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
earthquakeInfo.getIntensity(5.019,1.446,4.136,24,0,2.240,1.446,3.070,9,0);
|
||||
}
|
||||
if(earthquakeInfo.getMagnitude()>4.0)
|
||||
{
|
||||
earthquakeInfoService.insertEarthquakeInfo(earthquakeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
server:
|
||||
port: 8087
|
||||
|
||||
spring:
|
||||
servlet:
|
||||
multipart:
|
||||
enabled: true
|
||||
max-file-size: 100MB
|
||||
max-request-size: 1000MB
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
datasource:
|
||||
username: username
|
||||
password: password
|
||||
url: jdbc:mysql://47.117.160.245:3306/earthquake?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*Mapper.xml
|
||||
type-aliases-package: com.peteralbus.entity
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
@ -0,0 +1,33 @@
|
||||
<?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.EarthquakeInfoMapper">
|
||||
<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="queryInfoWithLine" resultMap="EarthquakeInfoWithLines">
|
||||
select earthquake_info.earthquake_id,earthquake_name,magnitude,high_intensity,longitude, latitude, depth ,earthquake_time, line_id, long_radius, angle, intensity, short_radius
|
||||
from earthquake.earthquake_info,earthquake.intensity_line
|
||||
WHERE intensity_line.earthquake_id=earthquake_info.earthquake_id
|
||||
<if test="earthquakeId !=null">
|
||||
and intensity_line.earthquake_id=#{earthquakeId}
|
||||
</if>
|
||||
<if test="startIndex != null and pageSize != NULL">
|
||||
limit #{startIndex},#{pageSize}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,25 @@
|
||||
package com.peteralbus;
|
||||
|
||||
import com.peteralbus.entity.EarthquakeInfo;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
@SpringBootTest
|
||||
class EarthquickApplicationTests
|
||||
{
|
||||
|
||||
@Test
|
||||
void contextLoads()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue