From 2f869a7de985e75a54135147ef1ed624b7113abd Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 2 Mar 2023 17:28:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xkrs/service/FirePointService.java | 27 +++------- .../service/impl/FirePointServiceImpl.java | 51 ++++++++++++++----- .../straw/controller/FirePointController.java | 17 ++----- .../straw/utils/FirePointQueryManager.java | 42 +++++++++------ 4 files changed, 77 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index 0d8cc53..d3d527e 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -1,11 +1,9 @@ package com.xkrs.service; -import com.xkrs.model.entity.FirePointEntity; import com.xkrs.model.qo.FirePointQo; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.List; /** * @author XinYi Song @@ -20,14 +18,6 @@ public interface FirePointService { */ boolean insertFirePoint(FirePointQo firePointQo); - /** - * 查询今天的火点信息 - * - * @param - * @return - */ - List selectTodayFirePoint(String countyCode); - /** * download vip user's fire point * @@ -39,16 +29,13 @@ public interface FirePointService { String downloadFirePoint(HttpServletRequest request, HttpServletResponse response, String ids); /** - * 动态多条件查询火点列表 - * - * @param code 区划编码,可以是省市区县街道任意编码,如果传需要至少两位。不传代表查询全国火点 - * @param startTime 过滤火点开始卫星时间,不传代表不指定开始时间。后台会有限制。 - * @param endTime 过滤火点结束卫星时间,不传代表不指定结束时间。 - * @param satelliteType 过滤传感器类型,不传代表查询全部类型的传感器 - * @param landType 过滤地物类型,不传代表查询全部地物类型 - * @return 符合条件的火点列表 + * (Complete) */ - List queryFirePoint(String code, String startTime, String endTime, String satelliteType, String landType); - void queryFirePoint(String token,String code, String startTime, String endTime, String satelliteType, String landType); + String queryFirePoint(String token, String code, String startTime, String endTime, String satelliteType, String landType); + + /** + * 查询今天的火点信息 (Complete) + */ + String selectTodayFirePoint(String token, String countyCode); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index d2c15aa..3d03251 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -11,11 +11,13 @@ import com.xkrs.model.vo.GaoDeIgGeocodeVo; import com.xkrs.service.FirePointService; import com.xkrs.service.StreetService; import com.xkrs.straw.dao.SysUserDao; +import com.xkrs.straw.model.bean.FirePointQueryResultBean; import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.helper.PushHelper; import com.xkrs.straw.model.helper.SMSHelper; import com.xkrs.straw.utils.FirePointQueryManager; import com.xkrs.utils.*; +import org.apache.hc.core5.util.TextUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.CacheConfig; @@ -278,26 +280,44 @@ public class FirePointServiceImpl implements FirePointService { } /** - * 动态多条件查询火点列表 - * - * @param code 区划编码,可以是省市区县街道任意编码,如果传需要至少两位。不传代表查询全国火点 - * @param startTime 过滤火点开始卫星时间,不传代表不指定开始时间。后台会有限制。 - * @param endTime 过滤火点结束卫星时间,不传代表不指定结束时间。 - * @param satelliteType 过滤传感器类型,不传代表查询全部类型的传感器 - * @param landType 过滤地物类型,不传代表查询全部地物类型 - * @return 符合条件的火点列表 + * Complete */ @Override - public List queryFirePoint(String code, String startTime, String endTime, String satelliteType, String landType) { - return firePointQueryHelper.queryFirePoint(code, startTime, endTime, satelliteType, landType); + public String queryFirePoint(String token, String code, String startTime, String endTime, String satelliteType, String landType) { + //验证token + String userName = TokenUtil.obtainUserNameByToken(token); + if (TextUtils.isEmpty(userName)) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "账号不存在或错误", locale); + } + SysUserEntity sysUserEntity = sysUserDao.selectByUserName(userName); + if (sysUserEntity == null) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "账号不存在或错误", locale); + } + + FirePointQueryResultBean firePointQueryResult = firePointQueryManager.queryFirePointBelongToUser(sysUserEntity, code, startTime, endTime, satelliteType, landType); + if (firePointQueryResult.isSuccess()) { + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointQueryResult.getList(), locale); + } else { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, firePointQueryResult.getErrorMessage(), locale); + } } /** - * 查询今天的火点信息 + * Complete */ // @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null") @Override - public List selectTodayFirePoint(String countyCode) { + public String selectTodayFirePoint(String token, String countyCode) { + + //验证token + String userName = TokenUtil.obtainUserNameByToken(token); + if (TextUtils.isEmpty(userName)) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "账号不存在或错误", locale); + } + SysUserEntity sysUserEntity = sysUserDao.selectByUserName(userName); + if (sysUserEntity == null) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "账号不存在或错误", locale); + } LocalDateTime startTime1 = LocalDateTime.now(); LocalDateTime startTime2 = LocalDateTime.of(startTime1.getYear(), startTime1.getMonth(), startTime1.getDayOfMonth(), 0, 0, 0, 0); @@ -307,7 +327,12 @@ public class FirePointServiceImpl implements FirePointService { LocalDateTime endTime2 = LocalDateTime.of(endTime1.getYear(), endTime1.getMonth(), endTime1.getDayOfMonth(), 0, 0, 0, 0); String endTimeString = DateTimeUtils.localDateTimeToString(endTime2); - return firePointQueryHelper.queryFirePoint(countyCode, startTimeString, endTimeString, null, null); + FirePointQueryResultBean firePointQueryResult = firePointQueryManager.queryFirePointBelongToUser(sysUserEntity, countyCode, startTimeString, endTimeString, null, null); + if (firePointQueryResult.isSuccess()) { + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointQueryResult.getList(), locale); + } else { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, firePointQueryResult.getErrorMessage(), locale); + } } } diff --git a/src/main/java/com/xkrs/straw/controller/FirePointController.java b/src/main/java/com/xkrs/straw/controller/FirePointController.java index 8179678..2bf2f87 100644 --- a/src/main/java/com/xkrs/straw/controller/FirePointController.java +++ b/src/main/java/com/xkrs/straw/controller/FirePointController.java @@ -105,26 +105,19 @@ public class FirePointController { } /** - * 动态多条件查询火点列表 + * 动态多条件查询火点列表(Complete) */ @GetMapping("/queryFirePoint") - public String queryFirePoint(@RequestHeader(value = "Authorization") String token, - @RequestParam(value = "code", required = false) String code, - @RequestParam(value = "startTime", required = false) String startTime, - @RequestParam(value = "endTime", required = false) String endTime, - @RequestParam(value = "satelliteType", required = false) String satelliteType, - @RequestParam(value = "landType", required = false) String landType) { - List firePointList = firePointService.queryFirePoint(token, code, startTime, endTime, satelliteType, landType); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale); + public String queryFirePoint(@RequestHeader(value = "Authorization") String token, @RequestParam(value = "code", required = false) String code, @RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime, @RequestParam(value = "satelliteType", required = false) String satelliteType, @RequestParam(value = "landType", required = false) String landType) { + return firePointService.queryFirePoint(token, code, startTime, endTime, satelliteType, landType); } /** * 查询今天的火点信息 */ @GetMapping("/selectTodayFirePoint") - public String selectTodayFirePoint(@RequestParam("countyCode") String countyCode) { - List firePointList = firePointService.selectTodayFirePoint(countyCode); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, firePointList, locale); + public String selectTodayFirePoint(@RequestHeader(value = "Authorization") String token, @RequestParam("countyCode") String countyCode) { + return firePointService.selectTodayFirePoint(token, countyCode); } /** diff --git a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java index f3e6b04..f2ba742 100644 --- a/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java +++ b/src/main/java/com/xkrs/straw/utils/FirePointQueryManager.java @@ -37,28 +37,36 @@ public class FirePointQueryManager { @Resource private FirePointPreciseDao firePointPreciseDao; - public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String startTime, String endTime, String satelliteType, String landType) { + public FirePointQueryResultBean queryFirePointBelongToUser(SysUserEntity sysUserEntity, String userSubAreaCountyCode, String startTime, String endTime, String satelliteType, String landType) { String countyCode = sysUserEntity.getCountyCode(); String vipTimeRangeJson = sysUserEntity.getVipTimeRangeJson(); - return queryFirePointBelongToUser(countyCode, vipTimeRangeJson, startTime, endTime, satelliteType, landType); + return queryFirePointBelongToUser(countyCode, vipTimeRangeJson, userSubAreaCountyCode, startTime, endTime, satelliteType, landType); } - public FirePointQueryResultBean queryFirePointBelongToUser(String userCode, String vipTimeRangeJson, String startTime, String endTime, String satelliteType, String landType) { + public FirePointQueryResultBean queryFirePointBelongToUser(String userCode, String vipTimeRangeJson, String userSubAreaCountyCode, String startTime, String endTime, String satelliteType, String landType) { String mNoRedundantUserCode = null; final List mVipTimeRangeItemList = new ArrayList<>(); + String mUserSubAreaCutCountyCode = null; try { //如果用户注册的区划编码是空,就返回失败 if (TextUtils.isEmpty(userCode)) { return new FirePointQueryResultBean("User CountyCode Error 1, userCode = " + userCode); } //对用户区划编码进行格式化,获得没有冗余数据的区划编码 - String noRedundantUserCode = FirePointCodeUtils.getFormatCutCode(userCode); + mNoRedundantUserCode = FirePointCodeUtils.getFormatCutCode(userCode); //如果格式化后的用户区划编码是空,就返回失败 - if (TextUtils.isEmpty(noRedundantUserCode)) { - return new FirePointQueryResultBean("User CountyCode Error 2, userCode = " + userCode + ", noRedundantUserCode = " + noRedundantUserCode); + if (TextUtils.isEmpty(mNoRedundantUserCode)) { + return new FirePointQueryResultBean("User CountyCode Error 2, userCode = " + userCode + ", noRedundantUserCode = " + mNoRedundantUserCode); + } + if (!TextUtils.isEmpty(userSubAreaCountyCode)) { + mUserSubAreaCutCountyCode = FirePointCodeUtils.getFormatCutCode(userSubAreaCountyCode); + if (!TextUtils.isEmpty(mUserSubAreaCutCountyCode)) { + if (!mUserSubAreaCutCountyCode.startsWith(mNoRedundantUserCode)) { + return new FirePointQueryResultBean("User SubArea CountyCode 出现错误"); + } + } } - //如果用户的VIP时间范围数据是空,就返回失败 if (TextUtils.isEmpty(vipTimeRangeJson)) { return new FirePointQueryResultBean("User VipTimeRangeJson Error 1, vipTimeRangeJson = " + vipTimeRangeJson); @@ -105,7 +113,6 @@ public class FirePointQueryManager { } } } - mNoRedundantUserCode = noRedundantUserCode; mVipTimeRangeItemList.addAll(vipTimeRangeItemList); } catch (Exception e) { @@ -113,11 +120,10 @@ public class FirePointQueryManager { return new FirePointQueryResultBean(e.getMessage()); } - return queryFirePointBelongToUser(mNoRedundantUserCode, mVipTimeRangeItemList, startTime, endTime, satelliteType, landType); + return queryFirePointBelongToUser(mNoRedundantUserCode, mVipTimeRangeItemList, mUserSubAreaCutCountyCode, startTime, endTime, satelliteType, landType); } - public FirePointQueryResultBean queryFirePointBelongToUser(String noRedundantUserCode, List vipTimeRangeItemList, String startTime, String endTime, String satelliteType, String landType) { - + public FirePointQueryResultBean queryFirePointBelongToUser(String noRedundantUserCode, List vipTimeRangeItemList, String userSubAreaCutCountyCode, String startTime, String endTime, String satelliteType, String landType) { //如果格式化后的用户区划编码是空,就返回失败 if (TextUtils.isEmpty(noRedundantUserCode)) { return new FirePointQueryResultBean("User CountyCode Error 2, noRedundantUserCode = " + noRedundantUserCode); @@ -126,13 +132,19 @@ public class FirePointQueryManager { if (vipTimeRangeItemList == null || vipTimeRangeItemList.size() == 0) { return new FirePointQueryResultBean("User VipTimeRangeJson Error 2, 已保存的VIP时间范围出现错误"); } - - final String finalMNoRedundantUserCode = noRedundantUserCode; + if (!TextUtils.isEmpty(userSubAreaCutCountyCode)) { + if (!userSubAreaCutCountyCode.startsWith(noRedundantUserCode)) { + return new FirePointQueryResultBean("User SubArea CountyCode 出现错误"); + } + } //查询未审核的普通火点 Specification specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> { List predicateList = new ArrayList<>(); //添加区划编码的过滤 - predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), noRedundantUserCode + "%")); + if (!TextUtils.isEmpty(userSubAreaCutCountyCode)) { + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), userSubAreaCutCountyCode + "%")); + } //开始时间查询条件 if (!TextUtils.isEmpty(startTime)) { LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime); @@ -174,7 +186,7 @@ public class FirePointQueryManager { Specification specificationPrecise = (root, criteriaQuery, criteriaBuilder) -> { List predicateList = new ArrayList<>(); //添加区划编码的过滤 - predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), finalMNoRedundantUserCode + "%")); + predicateList.add(criteriaBuilder.like(root.get("townCode").as(String.class), noRedundantUserCode + "%")); //开始时间查询条件 if (!TextUtils.isEmpty(startTime)) { LocalDateTime startTime1 = DateTimeUtils.stringToLocalDateTime(startTime);