From 475925322abe1a0e6bc85e84282c7aad026c1ee6 Mon Sep 17 00:00:00 2001
From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com>
Date: Mon, 2 Aug 2021 14:22:45 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=85=A8=E5=9B=BD?=
=?UTF-8?q?=E7=9C=81=E5=B8=82=E5=8C=BA=E7=BC=96=E7=A0=81=E5=92=8C=E5=90=8D?=
=?UTF-8?q?=E7=A7=B0=EF=BC=8C=20=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8A=A8?=
=?UTF-8?q?=E6=80=81=E5=A4=9A=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=E7=81=AB?=
=?UTF-8?q?=E7=82=B9=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86?=
=?UTF-8?q?=E4=BA=86=E8=B4=A6=E5=8F=B7=E5=88=86=E4=B8=BA=E7=9C=81=E5=B8=82?=
=?UTF-8?q?=E5=8C=BA=E4=B8=89=E4=B8=AA=E7=BA=A7=E5=88=AB=E8=B4=A6=E5=8F=B7?=
=?UTF-8?q?=E7=9A=84=E6=9F=A5=E8=AF=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 14 +++
.../xkrs/controller/FirePointController.java | 35 +++++-
src/main/java/com/xkrs/dao/CountyDao.java | 12 ++
.../com/xkrs/model/entity/CountyEntity.java | 104 ++++++++++++++++++
.../com/xkrs/service/FirePointService.java | 29 ++++-
.../service/impl/FirePointServiceImpl.java | 37 ++++++-
src/main/java/com/xkrs/utils/Query.java | 79 ++++++++++++-
src/main/resources/application.properties | 2 +-
8 files changed, 295 insertions(+), 17 deletions(-)
create mode 100644 src/main/java/com/xkrs/dao/CountyDao.java
create mode 100644 src/main/java/com/xkrs/model/entity/CountyEntity.java
diff --git a/pom.xml b/pom.xml
index b4cc137..f63154a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,8 @@
5.0.0
5.0.0
4.5.2
+ 5.0.0
+ 5.0.0
@@ -178,6 +180,18 @@
httpclient
${httpclient.version}
+
+
+ org.apache.poi
+ poi
+ ${poi.version}
+
+
+
+ org.apache.poi
+ poi-ooxml
+ ${poi-ooxml.version}
+
diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java
index c8d9d0d..126e654 100644
--- a/src/main/java/com/xkrs/controller/FirePointController.java
+++ b/src/main/java/com/xkrs/controller/FirePointController.java
@@ -4,11 +4,13 @@ import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tool.TokenUtil;
import com.xkrs.dao.FirePointDao;
import com.xkrs.dao.SysUserDao;
+import com.xkrs.model.entity.CountyEntity;
import com.xkrs.model.entity.FirePointEntity;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.qo.FirePointQo;
import com.xkrs.model.vo.AppTaskBodyVo;
import com.xkrs.service.FirePointService;
+import com.xkrs.utils.ExcelImportUtil;
import com.xkrs.websocket.service.WebSocketServer;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -20,6 +22,8 @@ import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@@ -38,6 +42,7 @@ public class FirePointController {
@Resource
private FirePointDao firePointDao;
+
/**
* 添加火点数据
* @param firePointQo
@@ -75,7 +80,7 @@ public class FirePointController {
}
/**
- * 查询今天的好点信息
+ * 查询今天的火点信息
* @param token
* @return
*/
@@ -112,11 +117,31 @@ public class FirePointController {
String startTime = (String) map.get("startTime");
// 结束时间
String endTime = (String) map.get("endTime");
- List firePointEntities = firePointService.selectFirePoint(cityCode, satelliteType, landType, startTime, endTime);
- if(firePointEntities == null || firePointEntities.size() == 0){
- return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有火点数据",locale);
+ // 验证token
+ String tokenUserName = TokenUtil.getTokenUserName(token);
+ SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
+ // 查询省
+ if(sysUserEntity.getCountyCode().substring(2).equals("0000")){
+ List firePointEntities = firePointService.selectFirePoint(sysUserEntity.getCountyCode(),cityCode, satelliteType, landType, startTime, endTime);
+ if(firePointEntities == null || firePointEntities.size() == 0){
+ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有火点数据",locale);
+ }
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale);
+ // 查询市
+ }else if(sysUserEntity.getCountyCode().substring(4).equals("00") && !sysUserEntity.getCountyCode().substring(2).equals("0000")){
+ List firePointEntities = firePointService.selectFirePointByCity(sysUserEntity.getCountyCode(), cityCode, satelliteType, landType, startTime, endTime);
+ if(firePointEntities == null || firePointEntities.size() == 0){
+ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有火点数据",locale);
+ }
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale);
+ // 查询县
+ }else {
+ List firePointEntities = firePointService.selectFirePointByCounty(cityCode, satelliteType, landType, startTime, endTime);
+ if(firePointEntities == null || firePointEntities.size() == 0){
+ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有火点数据",locale);
+ }
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale);
}
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale);
}
/**
diff --git a/src/main/java/com/xkrs/dao/CountyDao.java b/src/main/java/com/xkrs/dao/CountyDao.java
new file mode 100644
index 0000000..d131465
--- /dev/null
+++ b/src/main/java/com/xkrs/dao/CountyDao.java
@@ -0,0 +1,12 @@
+package com.xkrs.dao;
+
+import com.xkrs.model.entity.CountyEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author XinYi Song
+ */
+@Component
+public interface CountyDao extends JpaRepository {
+}
diff --git a/src/main/java/com/xkrs/model/entity/CountyEntity.java b/src/main/java/com/xkrs/model/entity/CountyEntity.java
new file mode 100644
index 0000000..7f83c3c
--- /dev/null
+++ b/src/main/java/com/xkrs/model/entity/CountyEntity.java
@@ -0,0 +1,104 @@
+package com.xkrs.model.entity;
+
+import javax.persistence.*;
+
+/**
+ * @author XinYi Song
+ */
+@Entity
+@Table(name = "county")
+public class CountyEntity {
+ /**
+ * 主键id
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "city_seq_gen")
+ @SequenceGenerator(name = "city_seq_gen", sequenceName = "city_id_seq",allocationSize = 1)
+ private Integer id;
+
+ /**
+ * 区县编码
+ */
+ @Column(length = 65, columnDefinition = "varchar(65)")
+ private String countyCode;
+
+ /**
+ * 区县名称
+ */
+ @Column(length = 65, columnDefinition = "varchar(65)")
+ private String countyName;
+
+ /**
+ * 城市编码
+ */
+ @Column(length = 65, columnDefinition = "varchar(65)")
+ private String cityCode;
+
+ /**
+ * 城市名称
+ */
+ @Column(length = 65, columnDefinition = "varchar(65)")
+ private String cityName;
+
+ public CountyEntity() {
+ }
+
+ public CountyEntity(Integer id, String countyCode, String countyName, String cityCode, String cityName) {
+ this.id = id;
+ this.countyCode = countyCode;
+ this.countyName = countyName;
+ this.cityCode = cityCode;
+ this.cityName = cityName;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getCountyCode() {
+ return countyCode;
+ }
+
+ public void setCountyCode(String countyCode) {
+ this.countyCode = countyCode;
+ }
+
+ public String getCountyName() {
+ return countyName;
+ }
+
+ public void setCountyName(String countyName) {
+ this.countyName = countyName;
+ }
+
+ public String getCityCode() {
+ return cityCode;
+ }
+
+ public void setCityCode(String cityCode) {
+ this.cityCode = cityCode;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ public void setCityName(String cityName) {
+ this.cityName = cityName;
+ }
+
+ @Override
+ public String toString() {
+ return "CountyEntity{" +
+ "id=" + id +
+ ", countyCode='" + countyCode + '\'' +
+ ", countyName='" + countyName + '\'' +
+ ", cityCode='" + cityCode + '\'' +
+ ", cityName='" + cityName + '\'' +
+ '}';
+ }
+}
diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java
index d3b8ebc..df00f78 100644
--- a/src/main/java/com/xkrs/service/FirePointService.java
+++ b/src/main/java/com/xkrs/service/FirePointService.java
@@ -30,7 +30,8 @@ public interface FirePointService {
List selectTodayFirePoint();
/**
- * 动态多条件查询火点信息
+ * 动态多条件查询火点信息(省)
+ * @param proCode
* @param cityCode
* @param satelliteType
* @param landType
@@ -38,7 +39,31 @@ public interface FirePointService {
* @param endTime
* @return
*/
- List selectFirePoint(String cityCode,String satelliteType,String landType,String startTime,String endTime);
+ List selectFirePoint(String proCode,String cityCode,String satelliteType,String landType,String startTime,String endTime);
+
+
+ /**
+ * 动态多条件查询火点信息(市)
+ * @param cityCodeOne 市编码
+ * @param cityCode 县编码
+ * @param satelliteType
+ * @param landType
+ * @param startTime
+ * @param endTime
+ * @return
+ */
+ List selectFirePointByCity(String cityCodeOne,String cityCode,String satelliteType,String landType,String startTime,String endTime);
+
+ /**
+ * 动态多条件查询火点信息(县)
+ * @param cityCode 县编码
+ * @param satelliteType
+ * @param landType
+ * @param startTime
+ * @param endTime
+ * @return
+ */
+ List selectFirePointByCounty(String cityCode,String satelliteType,String landType,String startTime,String endTime);
/**
* 根据火点编码修改火点的状态(预警)
diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java
index fd9303c..7c9d71a 100644
--- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java
+++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java
@@ -1,6 +1,5 @@
package com.xkrs.service.impl;
-import com.alibaba.fastjson.JSON;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tool.TokenUtil;
import com.xkrs.dao.*;
@@ -10,7 +9,6 @@ import com.xkrs.model.vo.AppPhotoVo;
import com.xkrs.model.vo.AppTaskBodyVo;
import com.xkrs.service.FirePointService;
import com.xkrs.utils.*;
-import com.xkrs.websocket.service.WebSocketServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanCopier;
@@ -118,7 +116,7 @@ public class FirePointServiceImpl implements FirePointService {
}
/**
- * 动态多条件查询火点信息
+ * 动态多条件查询火点信息(省)
* @param cityCode
* @param satelliteType
* @param landType
@@ -127,8 +125,37 @@ public class FirePointServiceImpl implements FirePointService {
* @return
*/
@Override
- public List selectFirePoint(String cityCode, String satelliteType, String landType, String startTime, String endTime) {
- return query.selectFirePoint(cityCode, satelliteType, landType, startTime, endTime);
+ public List selectFirePoint(String proCode,String cityCode, String satelliteType, String landType, String startTime, String endTime) {
+ return query.selectFirePointByPro(proCode,cityCode, satelliteType, landType, startTime, endTime);
+ }
+
+ /**
+ * 动态多条件查询火点信息(市)
+ * @param cityCodeOne 市编码
+ * @param cityCode 县编码
+ * @param satelliteType
+ * @param landType
+ * @param startTime
+ * @param endTime
+ * @return
+ */
+ @Override
+ public List selectFirePointByCity(String cityCodeOne, String cityCode, String satelliteType, String landType, String startTime, String endTime) {
+ return query.selectFirePointByCity(cityCodeOne,cityCode,satelliteType,landType,startTime,endTime);
+ }
+
+ /**
+ * 动态多条件查询火点信息(县)
+ * @param cityCode 县编码
+ * @param satelliteType
+ * @param landType
+ * @param startTime
+ * @param endTime
+ * @return
+ */
+ @Override
+ public List selectFirePointByCounty(String cityCode, String satelliteType, String landType, String startTime, String endTime) {
+ return query.selectFirePointByCounty(cityCode,satelliteType,landType,startTime,endTime);
}
/**
diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java
index dac4134..e858bfb 100644
--- a/src/main/java/com/xkrs/utils/Query.java
+++ b/src/main/java/com/xkrs/utils/Query.java
@@ -24,18 +24,89 @@ public class Query {
private FirePointDao firePointDao;
/**
- * 动态多条件查询项目信息
+ * 动态多条件查询项目信息(省)
* @param
* @return
*/
- public List selectFirePoint(String cityCode,String satelliteType,String landType,String startTime,String endTime) {
+ public List selectFirePointByPro(String proCode, String cityCode, String satelliteType, String landType, String startTime, String endTime) {
+ Specification specification = new Specification() {
+ @Override
+ public Predicate toPredicate(Root root, CriteriaQuery> criteriaQuery, CriteriaBuilder criteriaBuilder) {
+ List list = new ArrayList<>();
+ if(proCode != null && !"".equals(proCode)){
+ String substring = proCode.substring(0, 2);
+ list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "%" + substring + "%"));
+ }
+ if (cityCode != null && !"".equals(cityCode)) {
+ list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "%" + cityCode + "%"));
+ }
+ if (satelliteType != null && !"".equals(satelliteType)) {
+ list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
+ }
+ if (landType != null && !"".equals(landType)) {
+ list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
+ }
+ if(startTime != null && !"".equals(startTime)){
+ list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime));
+ }
+ if(endTime != null && !"".equals(endTime)){
+ list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime));
+ }
+ Predicate[] predicates = new Predicate[list.size()];
+ return criteriaBuilder.and(list.toArray(predicates));
+ }
+ };
+ return firePointDao.findAll(specification);
+ }
+
+ /**
+ * 动态多条件查询项目信息(市)
+ * @param
+ * @return
+ */
+ public List selectFirePointByCity(String cityCodeOne, String cityCode,String satelliteType,String landType,String startTime,String endTime) {
+ Specification specification = new Specification() {
+ @Override
+ public Predicate toPredicate(Root root, CriteriaQuery> criteriaQuery, CriteriaBuilder criteriaBuilder) {
+ List list = new ArrayList<>();
+ if(cityCodeOne != null && !"".equals(cityCodeOne)){
+ String substring = cityCodeOne.substring(0, 4);
+ list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "%" + substring + "%"));
+ }
+ if (cityCode != null && !"".equals(cityCode)) {
+ list.add(criteriaBuilder.equal(root.get("countyCode").as(String.class),cityCode));
+ }
+ if (satelliteType != null && !"".equals(satelliteType)) {
+ list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
+ }
+ if (landType != null && !"".equals(landType)) {
+ list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
+ }
+ if(startTime != null && !"".equals(startTime)){
+ list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime));
+ }
+ if(endTime != null && !"".equals(endTime)){
+ list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime));
+ }
+ Predicate[] predicates = new Predicate[list.size()];
+ return criteriaBuilder.and(list.toArray(predicates));
+ }
+ };
+ return firePointDao.findAll(specification);
+ }
+
+ /**
+ * 动态多条件查询项目信息(县)
+ * @param
+ * @return
+ */
+ public List selectFirePointByCounty(String cityCode,String satelliteType,String landType,String startTime,String endTime) {
Specification specification = new Specification() {
@Override
public Predicate toPredicate(Root root, CriteriaQuery> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List list = new ArrayList<>();
if (cityCode != null && !"".equals(cityCode)) {
- //String substring = cityCode.substring(0, 4);
- list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "%" + cityCode + "%"));
+ list.add(criteriaBuilder.equal(root.get("countyCode").as(String.class),cityCode));
}
if (satelliteType != null && !"".equals(satelliteType)) {
list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index f7f0d92..9f92cd9 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -24,7 +24,7 @@ spring.datasource.hikari.validation-timeout = 3000
## Spring Data JPA 配置
spring.jpa.database = POSTGRESQL
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
-spring.jpa.show-sql = false
+spring.jpa.show-sql = true
# 指定 ddl mode (none, validate, create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# 命名策略