From 2b6951e3860fab987339e80126f6e05ccb779ec7 Mon Sep 17 00:00:00 2001 From: PeterAlbus Date: Sat, 5 Feb 2022 21:14:36 +0800 Subject: [PATCH] make code style better --- .gitignore | 2 +- .../controller/EstimateController.java | 23 ++++-- .../controller/HospitalController.java | 82 +++++++++++++++---- .../java/com/peteralbus/entity/Distance.java | 14 ++-- .../com/peteralbus/entity/EarthquakeInfo.java | 1 + .../java/com/peteralbus/entity/Estimate.java | 12 ++- .../java/com/peteralbus/entity/Hospital.java | 12 ++- .../com/peteralbus/entity/IntensityLine.java | 3 + .../com/peteralbus/mapper/HospitalMapper.java | 12 +-- .../peteralbus/service/EstimateService.java | 28 ++++++- .../peteralbus/service/HospitalService.java | 9 ++ .../service/impl/EstimateServiceImpl.java | 13 +++ .../service/impl/HospitalServiceImpl.java | 20 ++++- src/main/resources/mapper/EstimateMapper.xml | 2 +- src/main/resources/mapper/HospitalMapper.xml | 13 --- 15 files changed, 192 insertions(+), 54 deletions(-) delete mode 100644 src/main/resources/mapper/HospitalMapper.xml diff --git a/.gitignore b/.gitignore index a524c14..9e97857 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/main/java/com/peteralbus/controller/EstimateController.java b/src/main/java/com/peteralbus/controller/EstimateController.java index 6cd9d2c..7584416 100644 --- a/src/main/java/com/peteralbus/controller/EstimateController.java +++ b/src/main/java/com/peteralbus/controller/EstimateController.java @@ -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 mapParameter = new HashMap(); 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 { diff --git a/src/main/java/com/peteralbus/controller/HospitalController.java b/src/main/java/com/peteralbus/controller/HospitalController.java index dbf3e59..393c348 100644 --- a/src/main/java/com/peteralbus/controller/HospitalController.java +++ b/src/main/java/com/peteralbus/controller/HospitalController.java @@ -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 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 hospitals=hospitalService.findAllHospital(); - double minDistance=Double.MAX_VALUE; + Double minDistance=Double.MAX_VALUE; Distance distance=new Distance(); - for(int i=0;i findAllHospital(); - +public interface HospitalMapper extends BaseMapper +{ } diff --git a/src/main/java/com/peteralbus/service/EstimateService.java b/src/main/java/com/peteralbus/service/EstimateService.java index 730538e..9f0b8be 100644 --- a/src/main/java/com/peteralbus/service/EstimateService.java +++ b/src/main/java/com/peteralbus/service/EstimateService.java @@ -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); } diff --git a/src/main/java/com/peteralbus/service/HospitalService.java b/src/main/java/com/peteralbus/service/HospitalService.java index 23f6f42..6a63b62 100644 --- a/src/main/java/com/peteralbus/service/HospitalService.java +++ b/src/main/java/com/peteralbus/service/HospitalService.java @@ -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 findAllHospital(); } diff --git a/src/main/java/com/peteralbus/service/impl/EstimateServiceImpl.java b/src/main/java/com/peteralbus/service/impl/EstimateServiceImpl.java index 607deb4..2c89411 100644 --- a/src/main/java/com/peteralbus/service/impl/EstimateServiceImpl.java +++ b/src/main/java/com/peteralbus/service/impl/EstimateServiceImpl.java @@ -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; diff --git a/src/main/java/com/peteralbus/service/impl/HospitalServiceImpl.java b/src/main/java/com/peteralbus/service/impl/HospitalServiceImpl.java index eaab3f4..3b7227f 100644 --- a/src/main/java/com/peteralbus/service/impl/HospitalServiceImpl.java +++ b/src/main/java/com/peteralbus/service/impl/HospitalServiceImpl.java @@ -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 findAllHospital() { - return hospitalMapper.findAllHospital(); + return hospitalMapper.selectList(null); } } diff --git a/src/main/resources/mapper/EstimateMapper.xml b/src/main/resources/mapper/EstimateMapper.xml index 2975726..acd7110 100644 --- a/src/main/resources/mapper/EstimateMapper.xml +++ b/src/main/resources/mapper/EstimateMapper.xml @@ -26,7 +26,7 @@ diff --git a/src/main/resources/mapper/HospitalMapper.xml b/src/main/resources/mapper/HospitalMapper.xml deleted file mode 100644 index e6db5c1..0000000 --- a/src/main/resources/mapper/HospitalMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file