From e258f92e27f3089d91e0d0f100b9fca4f3c0a0cb Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Tue, 21 Jun 2022 16:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E5=8F=AA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=B1=B1=E4=B8=9C=E7=9C=81=E5=86=85=E7=9A=84?= =?UTF-8?q?=E7=81=AB=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xkrs/dao/GlobalSettingDao.java | 11 ++++ .../model/entity/GlobalSettingEntity.java | 57 +++++++++++++++++++ .../xkrs/service/GlobalSettingService.java | 7 +++ .../impl/GlobalSettingServiceImpl.java | 32 +++++++++++ .../com/xkrs/utils/FirePointQueryHelper.java | 8 +++ 5 files changed, 115 insertions(+) create mode 100644 src/main/java/com/xkrs/dao/GlobalSettingDao.java create mode 100644 src/main/java/com/xkrs/model/entity/GlobalSettingEntity.java create mode 100644 src/main/java/com/xkrs/service/GlobalSettingService.java create mode 100644 src/main/java/com/xkrs/service/impl/GlobalSettingServiceImpl.java diff --git a/src/main/java/com/xkrs/dao/GlobalSettingDao.java b/src/main/java/com/xkrs/dao/GlobalSettingDao.java new file mode 100644 index 0000000..5a71162 --- /dev/null +++ b/src/main/java/com/xkrs/dao/GlobalSettingDao.java @@ -0,0 +1,11 @@ +package com.xkrs.dao; + +import com.xkrs.model.entity.GlobalSettingEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Component; + +@Component +public interface GlobalSettingDao extends JpaRepository, JpaSpecificationExecutor { + +} diff --git a/src/main/java/com/xkrs/model/entity/GlobalSettingEntity.java b/src/main/java/com/xkrs/model/entity/GlobalSettingEntity.java new file mode 100644 index 0000000..2e25f27 --- /dev/null +++ b/src/main/java/com/xkrs/model/entity/GlobalSettingEntity.java @@ -0,0 +1,57 @@ +package com.xkrs.model.entity; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * 全局配置表 + */ +@Entity +@Table(name = "global_setting") +public class GlobalSettingEntity implements Serializable { + + /** + * 主键id + */ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_setting_seq_gen") + @SequenceGenerator(name = "global_setting_seq_gen", sequenceName = "global_setting_id_seq", allocationSize = 1) + private Long id; + + /** + * 全局配置项的键 + */ + private String key; + + /** + * 全局配置项的值 + */ + private Long value; + + public GlobalSettingEntity() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Long getValue() { + return value; + } + + public void setValue(Long value) { + this.value = value; + } +} diff --git a/src/main/java/com/xkrs/service/GlobalSettingService.java b/src/main/java/com/xkrs/service/GlobalSettingService.java new file mode 100644 index 0000000..4a5bf72 --- /dev/null +++ b/src/main/java/com/xkrs/service/GlobalSettingService.java @@ -0,0 +1,7 @@ +package com.xkrs.service; + +public interface GlobalSettingService { + + boolean onlyShanDong(); + +} diff --git a/src/main/java/com/xkrs/service/impl/GlobalSettingServiceImpl.java b/src/main/java/com/xkrs/service/impl/GlobalSettingServiceImpl.java new file mode 100644 index 0000000..1d909d2 --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/GlobalSettingServiceImpl.java @@ -0,0 +1,32 @@ +package com.xkrs.service.impl; + +import com.xkrs.dao.GlobalSettingDao; +import com.xkrs.model.entity.GlobalSettingEntity; +import com.xkrs.service.GlobalSettingService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class GlobalSettingServiceImpl implements GlobalSettingService { + + @Resource + private GlobalSettingDao globalSettingDao; + + @Override + public boolean onlyShanDong() { + try { + List globalSettingList = globalSettingDao.findAll(); + for (GlobalSettingEntity globalSetting : globalSettingList) { + if (globalSetting.getKey().equalsIgnoreCase("OnlyShanDong")) { + return globalSetting.getValue() == 1L; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + +} diff --git a/src/main/java/com/xkrs/utils/FirePointQueryHelper.java b/src/main/java/com/xkrs/utils/FirePointQueryHelper.java index d016690..908ab56 100644 --- a/src/main/java/com/xkrs/utils/FirePointQueryHelper.java +++ b/src/main/java/com/xkrs/utils/FirePointQueryHelper.java @@ -2,6 +2,7 @@ package com.xkrs.utils; import com.xkrs.dao.FirePointDao; import com.xkrs.model.entity.FirePointEntity; +import com.xkrs.service.GlobalSettingService; import org.apache.hc.core5.util.TextUtils; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; @@ -22,10 +23,17 @@ public class FirePointQueryHelper { @Resource private FirePointDao firePointDao; + @Resource + private GlobalSettingService globalSettingService; + public List queryFirePoint(String code, String startTime, String endTime, String satelliteType, String landType) { Specification specification = (root, criteriaQuery, criteriaBuilder) -> { //查询条件集合 List predicateList = new ArrayList<>(); + if (globalSettingService.onlyShanDong()) { + predicateList.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "37%")); + predicateList.add(criteriaBuilder.like(root.get("streetCode").as(String.class), "37%")); + } //添加区划编码查询条件 if (!TextUtils.isEmpty(code)) { try {