From 1b9c8347544ba168d5b8df9a31c3c35f7f78d2f2 Mon Sep 17 00:00:00 2001 From: lakefish <3488815871@qq.com> Date: Fri, 18 Feb 2022 10:32:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E7=89=A9=E8=B5=84?= =?UTF-8?q?=E5=88=86=E9=85=8D=E5=8A=9F=E8=83=BD=E3=80=90=E5=88=9D=E7=89=88?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FireCenterController.java | 142 ++++++++++++++++++ .../peteralbus/controller/MyComparator.java | 10 ++ .../com/peteralbus/entity/FireCenter.java | 24 +++ .../com/peteralbus/entity/FireWeight.java | 17 +++ .../peteralbus/mapper/FireCenterMapper.java | 9 ++ .../peteralbus/service/FireCenterService.java | 9 ++ .../service/impl/FireCenterServiceImpl.java | 25 +++ 7 files changed, 236 insertions(+) create mode 100644 src/main/java/com/peteralbus/controller/FireCenterController.java create mode 100644 src/main/java/com/peteralbus/controller/MyComparator.java create mode 100644 src/main/java/com/peteralbus/entity/FireCenter.java create mode 100644 src/main/java/com/peteralbus/entity/FireWeight.java create mode 100644 src/main/java/com/peteralbus/mapper/FireCenterMapper.java create mode 100644 src/main/java/com/peteralbus/service/FireCenterService.java create mode 100644 src/main/java/com/peteralbus/service/impl/FireCenterServiceImpl.java diff --git a/src/main/java/com/peteralbus/controller/FireCenterController.java b/src/main/java/com/peteralbus/controller/FireCenterController.java new file mode 100644 index 0000000..914b4d8 --- /dev/null +++ b/src/main/java/com/peteralbus/controller/FireCenterController.java @@ -0,0 +1,142 @@ +package com.peteralbus.controller; + +import com.peteralbus.entity.FireCenter; +import com.peteralbus.entity.FireWeight; +import com.peteralbus.service.FireCenterService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.*; + +@CrossOrigin +@RestController +public class FireCenterController { + @Autowired + FireCenterService fireCenterService; + @Autowired + EstimateController estimateController; + @RequestMapping("/getAllFireCenter") + public List getAllFireCenter(){ + return fireCenterService.getAllFireCenter(); + } + @RequestMapping("/getFireCenterResult") + public List getFireCenterIntensity(){ + List FireIntensity=new ArrayList<>(); + List fireCenters= fireCenterService.getAllFireCenter(); + for(FireCenter fireCenter:fireCenters){ + System.out.println(fireCenter.getFireId()); + FireIntensity.add(estimateController.getPointIntensity(16L, fireCenter.getFireLon(), fireCenter.getFireLat())); + } + return FireIntensity; + } + @RequestMapping("/getOneFireCenter") + public FireCenter getOneFireCenter(int id){ + return fireCenterService.getAllFireCenter().get(id); + } + @RequestMapping("/calculateWeight") + public List getFireCenterWeight(){ + double [][] arr=new double [10][988]; + List FireCenterIntensityArr=getFireCenterIntensity(); +// System.out.println(FireCenterIntensityArr); + int temp=0; + for(double f:FireCenterIntensityArr){ + arr[0][temp]=f;//属性1,对于资助点1、2、3的值,因为基本上属性是固定的,可能资助点的数量会增加,假定属性最大值为10个 + arr[1][temp]=101*f+100*Math.random(); + arr[2][temp]=Math.log(48.87775814060409*15.304510961044489)+100*Math.random(); + temp++; + } + System.out.println("temp的值为"+temp); +// arr[1]=new double[] {0.847,0.63,0.921}; +// arr[2]=new double[] {524,439,842}; + double [][]arrNew=new double[10][988]; + double [][]arrNew1=new double[10][988]; + double sumProvide=0; + double max; + double min; + int strictNum=arr[0].length;//代表有多少个救助点 + double k=1/(Math.log((double)strictNum)); + double[] e=new double[10];//第 j 项指标的熵值 ej + double[] g=new double[10];//差异性系数 gi越大指标越重要 + for(int j=0;j<3;j++) { + min=max=arr[j][0]; + sumProvide=0; + for(int i=0;imax) { + max=arr[j][i]; + } + } + for(int i=0;i arrayW1=new ArrayList<>(); + Map topTen=new LinkedHashMap(); + List resultFireWeightLists=new ArrayList<>(); + for(int i=0;i> entrys=new ArrayList<>(arrayStrict.entrySet()); + Collections.sort(entrys, new MyComparator()); + //输出排序后的键值对 + int count=0; + for(Map.Entry entry:entrys){ + System.out.println(entry.getKey()+","+entry.getValue()); + topTen.put(entry.getKey(),entry.getValue()); + FireCenter resultFireCenter=getOneFireCenter(entry.getKey()); + FireWeight fireWeight=new FireWeight(); + fireWeight.setFireId(resultFireCenter.getFireId()); + fireWeight.setFireLat(resultFireCenter.getFireLat()); + fireWeight.setFireLon(resultFireCenter.getFireLon()); + fireWeight.setFireName(resultFireCenter.getFireName()); + fireWeight.setFireAddress(resultFireCenter.getFireAddress()); + fireWeight.setFireCenterWeight(entry.getValue()); + resultFireWeightLists.add(fireWeight); + count++; + if(count==10){ + break; + } + } + +// return arrayW1; +// return topTen; + return resultFireWeightLists; + } +} diff --git a/src/main/java/com/peteralbus/controller/MyComparator.java b/src/main/java/com/peteralbus/controller/MyComparator.java new file mode 100644 index 0000000..130617e --- /dev/null +++ b/src/main/java/com/peteralbus/controller/MyComparator.java @@ -0,0 +1,10 @@ +package com.peteralbus.controller; + +import java.util.Comparator; +import java.util.Map; + +class MyComparator implements Comparator { +public int compare(Map.Entry o1, Map.Entry o2) { +return ((Double)o2.getValue()).compareTo((Double) o1.getValue()); +} +} \ No newline at end of file diff --git a/src/main/java/com/peteralbus/entity/FireCenter.java b/src/main/java/com/peteralbus/entity/FireCenter.java new file mode 100644 index 0000000..a50e508 --- /dev/null +++ b/src/main/java/com/peteralbus/entity/FireCenter.java @@ -0,0 +1,24 @@ +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; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("fire_center") +public class FireCenter { + @TableId(type= IdType.ASSIGN_ID) + private Integer fireId; + private Double fireLon; + private Double fireLat; + private String fireName; + private String fireAddress; + private String fireProvince; + private String fireCityName; + private String fireType; +} diff --git a/src/main/java/com/peteralbus/entity/FireWeight.java b/src/main/java/com/peteralbus/entity/FireWeight.java new file mode 100644 index 0000000..9cdd35e --- /dev/null +++ b/src/main/java/com/peteralbus/entity/FireWeight.java @@ -0,0 +1,17 @@ +package com.peteralbus.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class FireWeight { + private Integer fireId; + private Double fireLon; + private Double fireLat; + private String fireName; + private String fireAddress; + private Double fireCenterWeight; +} diff --git a/src/main/java/com/peteralbus/mapper/FireCenterMapper.java b/src/main/java/com/peteralbus/mapper/FireCenterMapper.java new file mode 100644 index 0000000..b61a4b3 --- /dev/null +++ b/src/main/java/com/peteralbus/mapper/FireCenterMapper.java @@ -0,0 +1,9 @@ +package com.peteralbus.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.peteralbus.entity.FireCenter; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface FireCenterMapper extends BaseMapper { +} diff --git a/src/main/java/com/peteralbus/service/FireCenterService.java b/src/main/java/com/peteralbus/service/FireCenterService.java new file mode 100644 index 0000000..0d42c55 --- /dev/null +++ b/src/main/java/com/peteralbus/service/FireCenterService.java @@ -0,0 +1,9 @@ +package com.peteralbus.service; + +import com.peteralbus.entity.FireCenter; + +import java.util.List; + +public interface FireCenterService { + ListgetAllFireCenter(); +} diff --git a/src/main/java/com/peteralbus/service/impl/FireCenterServiceImpl.java b/src/main/java/com/peteralbus/service/impl/FireCenterServiceImpl.java new file mode 100644 index 0000000..69a6f43 --- /dev/null +++ b/src/main/java/com/peteralbus/service/impl/FireCenterServiceImpl.java @@ -0,0 +1,25 @@ +package com.peteralbus.service.impl; + +import com.peteralbus.entity.FireCenter; +import com.peteralbus.mapper.FireCenterMapper; +import com.peteralbus.service.FireCenterService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class FireCenterServiceImpl implements FireCenterService { + + FireCenterMapper fireCenterMapper; + + @Autowired + public void setFireCenterMapper(FireCenterMapper fireCenterMapper) { + this.fireCenterMapper = fireCenterMapper; + } + + @Override + public List getAllFireCenter() { + return fireCenterMapper.selectList(null); + } +}