From 1b3785aaf7457b4411a3073bf85eb0a4c9f1e680 Mon Sep 17 00:00:00 2001 From: PeterAlbus Date: Fri, 21 Jan 2022 12:18:15 +0800 Subject: [PATCH] basic codes --- .gitignore | 35 ++++ README.md | 4 + pom.xml | 107 +++++++++++ .../com/peteralbus/EarthquickApplication.java | 26 +++ .../com/peteralbus/config/SwaggerConfig.java | 48 +++++ .../controller/EarthquakeInfoController.java | 168 ++++++++++++++++++ .../com/peteralbus/entity/EarthquakeInfo.java | 121 +++++++++++++ .../com/peteralbus/entity/IntensityLine.java | 39 ++++ .../mapper/EarthquakeInfoMapper.java | 26 +++ .../mapper/IntensityLineMapper.java | 15 ++ .../service/EarthquakeInfoService.java | 39 ++++ .../service/IntensityLineService.java | 20 +++ .../impl/EarthquakeInfoServiceImpl.java | 91 ++++++++++ .../impl/IntensityLineServiceImpl.java | 40 +++++ .../com/peteralbus/task/ScheduleTask.java | 86 +++++++++ .../com/peteralbus/util/EstimateUtil.java | 49 +++++ src/main/resources/application.yml.example | 26 +++ .../resources/mapper/EarthquakeInfoMapper.xml | 33 ++++ .../EarthquickApplicationTests.java | 25 +++ 19 files changed, 998 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/peteralbus/EarthquickApplication.java create mode 100644 src/main/java/com/peteralbus/config/SwaggerConfig.java create mode 100644 src/main/java/com/peteralbus/controller/EarthquakeInfoController.java create mode 100644 src/main/java/com/peteralbus/entity/EarthquakeInfo.java create mode 100644 src/main/java/com/peteralbus/entity/IntensityLine.java create mode 100644 src/main/java/com/peteralbus/mapper/EarthquakeInfoMapper.java create mode 100644 src/main/java/com/peteralbus/mapper/IntensityLineMapper.java create mode 100644 src/main/java/com/peteralbus/service/EarthquakeInfoService.java create mode 100644 src/main/java/com/peteralbus/service/IntensityLineService.java create mode 100644 src/main/java/com/peteralbus/service/impl/EarthquakeInfoServiceImpl.java create mode 100644 src/main/java/com/peteralbus/service/impl/IntensityLineServiceImpl.java create mode 100644 src/main/java/com/peteralbus/task/ScheduleTask.java create mode 100644 src/main/java/com/peteralbus/util/EstimateUtil.java create mode 100644 src/main/resources/application.yml.example create mode 100644 src/main/resources/mapper/EarthquakeInfoMapper.xml create mode 100644 src/test/java/com/peteralbus/EarthquickApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e97857 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index 37cfba9..fd4fdf7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # earthquick_springboot back end of project earthquick + +使用流程: +将application.yml.example修改为application.yml +其中的数据库信息改成自己的 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e33d4d2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,107 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.6.2 + + + com.peteralbus + earthquick + 0.0.1-SNAPSHOT + earthquick + earthquick + + 1.8 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-jdbc + + + com.baomidou + mybatis-plus-boot-starter + 3.5.0 + + + mysql + mysql-connector-java + runtime + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + com.alibaba + fastjson + 1.2.79 + + + + com.fasterxml.jackson.core + jackson-databind + 2.13.1 + + + joda-time + joda-time + 2.10.13 + + + + io.springfox + springfox-swagger2 + 3.0.0 + + + io.springfox + springfox-swagger-ui + 3.0.0 + + + + com.github.xiaoymin + swagger-bootstrap-ui + 1.9.6 + + + + org.jsoup + jsoup + 1.14.3 + + + + org.projectlombok + lombok + 1.18.22 + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/main/java/com/peteralbus/EarthquickApplication.java b/src/main/java/com/peteralbus/EarthquickApplication.java new file mode 100644 index 0000000..38a33e0 --- /dev/null +++ b/src/main/java/com/peteralbus/EarthquickApplication.java @@ -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); + } + +} diff --git a/src/main/java/com/peteralbus/config/SwaggerConfig.java b/src/main/java/com/peteralbus/config/SwaggerConfig.java new file mode 100644 index 0000000..a339d32 --- /dev/null +++ b/src/main/java/com/peteralbus/config/SwaggerConfig.java @@ -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(); + } + +} diff --git a/src/main/java/com/peteralbus/controller/EarthquakeInfoController.java b/src/main/java/com/peteralbus/controller/EarthquakeInfoController.java new file mode 100644 index 0000000..98d7ae4 --- /dev/null +++ b/src/main/java/com/peteralbus/controller/EarthquakeInfoController.java @@ -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 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 mapParameter = new HashMap(); + 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 mapParameter = new HashMap(); + 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 mapParameter = new HashMap(); + 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()0) + { + return "success"; + } + else + { + return "fail"; + } + } +} diff --git a/src/main/java/com/peteralbus/entity/EarthquakeInfo.java b/src/main/java/com/peteralbus/entity/EarthquakeInfo.java new file mode 100644 index 0000000..49eedf8 --- /dev/null +++ b/src/main/java/com/peteralbus/entity/EarthquakeInfo.java @@ -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 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); + } +} diff --git a/src/main/java/com/peteralbus/entity/IntensityLine.java b/src/main/java/com/peteralbus/entity/IntensityLine.java new file mode 100644 index 0000000..79f80e3 --- /dev/null +++ b/src/main/java/com/peteralbus/entity/IntensityLine.java @@ -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; + } +} diff --git a/src/main/java/com/peteralbus/mapper/EarthquakeInfoMapper.java b/src/main/java/com/peteralbus/mapper/EarthquakeInfoMapper.java new file mode 100644 index 0000000..383a43e --- /dev/null +++ b/src/main/java/com/peteralbus/mapper/EarthquakeInfoMapper.java @@ -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 +{ + /** + * Query info with line list. + * + * @param parameter the parameter which can contain earthquakeId,startIndex,pageSize + * @return the list + */ + List queryInfoWithLine(Map parameter); +} diff --git a/src/main/java/com/peteralbus/mapper/IntensityLineMapper.java b/src/main/java/com/peteralbus/mapper/IntensityLineMapper.java new file mode 100644 index 0000000..597fdab --- /dev/null +++ b/src/main/java/com/peteralbus/mapper/IntensityLineMapper.java @@ -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 +{ +} diff --git a/src/main/java/com/peteralbus/service/EarthquakeInfoService.java b/src/main/java/com/peteralbus/service/EarthquakeInfoService.java new file mode 100644 index 0000000..a11a0b8 --- /dev/null +++ b/src/main/java/com/peteralbus/service/EarthquakeInfoService.java @@ -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 queryInfoWithLine(Map 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); +} diff --git a/src/main/java/com/peteralbus/service/IntensityLineService.java b/src/main/java/com/peteralbus/service/IntensityLineService.java new file mode 100644 index 0000000..a74eb03 --- /dev/null +++ b/src/main/java/com/peteralbus/service/IntensityLineService.java @@ -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 getMultiLineStringWktToJson(String wkt); +} diff --git a/src/main/java/com/peteralbus/service/impl/EarthquakeInfoServiceImpl.java b/src/main/java/com/peteralbus/service/impl/EarthquakeInfoServiceImpl.java new file mode 100644 index 0000000..afbbb06 --- /dev/null +++ b/src/main/java/com/peteralbus/service/impl/EarthquakeInfoServiceImpl.java @@ -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 queryInfoWithLine(Map 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 intensityLineQueryWrapper = new QueryWrapper<>(); + intensityLineQueryWrapper.eq("earthquake_id", earthquakeInfo.getEarthquakeId()); + result = intensityLineMapper.delete(intensityLineQueryWrapper); + if (result > 0) + { + result = earthquakeInfoMapper.deleteById(earthquakeInfo); + } + return result; + } +} diff --git a/src/main/java/com/peteralbus/service/impl/IntensityLineServiceImpl.java b/src/main/java/com/peteralbus/service/impl/IntensityLineServiceImpl.java new file mode 100644 index 0000000..b0ccd3c --- /dev/null +++ b/src/main/java/com/peteralbus/service/impl/IntensityLineServiceImpl.java @@ -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 getMultiLineStringWktToJson(String wkt) + { + String toTailWkt = wkt.substring(0, wkt.length() - 1); + String[] strHead = toTailWkt.split("\\(", 2); + String[] strList = strHead[1].split("\\),\\("); + List list = new ArrayList(); + 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; + } +} diff --git a/src/main/java/com/peteralbus/task/ScheduleTask.java b/src/main/java/com/peteralbus/task/ScheduleTask.java new file mode 100644 index 0000000..7c28a55 --- /dev/null +++ b/src/main/java/com/peteralbus/task/ScheduleTask.java @@ -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()4.0) + { + earthquakeInfoService.insertEarthquakeInfo(earthquakeInfo); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/peteralbus/util/EstimateUtil.java b/src/main/java/com/peteralbus/util/EstimateUtil.java new file mode 100644 index 0000000..c27f029 --- /dev/null +++ b/src/main/java/com/peteralbus/util/EstimateUtil.java @@ -0,0 +1,49 @@ +package com.peteralbus.util; + +import org.springframework.stereotype.Component; + +/** + * The type Estimate util. + * @author PeterAlbus + */ +@Component +public class EstimateUtil +{ + /** + * death predict int. + * + * @param population the population + * @param magnitude the magnitude + * @return the double + */ + public double deathPredict(int population,double magnitude,double intensity) + { + double deathPredict = 0; + /*M为震级 I为震中强度*/ + double mCoefficient = Math.abs((magnitude-4.17)/0.35*intensity-0.97); + /*population 为人口密度*/ + double denCoefficient = 0.05*Math.log(population)+0.74; + /*白天为1,夜晚为0.75*/ + double timeCoefficient = 0.75; + /*西部强度修正系数 0.3661*/ + double strengthCoefficient = 0.4853; + double bdr = 0.5; + deathPredict = 0.461*mCoefficient*denCoefficient*timeCoefficient*strengthCoefficient*Math.exp(12.285*bdr); + return deathPredict; +// double deathPredict = 0; +// deathPredict = 9.6*Math.pow(10,-11)*(0.00564*population+0.1634)*Math.exp(4.19*magnitude); +// return (int)deathPredict; + } + + /** + * economy lose predict double. + * + * @param highIntensity the high intensity + * @return the double + */ + public double economyPredict(double highIntensity) + { + return Math.pow(10,0.84444*highIntensity-1.831)/10000; + } + +} diff --git a/src/main/resources/application.yml.example b/src/main/resources/application.yml.example new file mode 100644 index 0000000..4355fcd --- /dev/null +++ b/src/main/resources/application.yml.example @@ -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 diff --git a/src/main/resources/mapper/EarthquakeInfoMapper.xml b/src/main/resources/mapper/EarthquakeInfoMapper.xml new file mode 100644 index 0000000..9dcc848 --- /dev/null +++ b/src/main/resources/mapper/EarthquakeInfoMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/com/peteralbus/EarthquickApplicationTests.java b/src/test/java/com/peteralbus/EarthquickApplicationTests.java new file mode 100644 index 0000000..3a855fb --- /dev/null +++ b/src/test/java/com/peteralbus/EarthquickApplicationTests.java @@ -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() + { + } + +}