优化双火点渠道入库逻辑

This commit is contained in:
liuchengqian 2023-02-03 11:54:52 +08:00
parent 8b69e5a874
commit ff294b8213
3 changed files with 44 additions and 28 deletions

View File

@ -3,6 +3,7 @@ package com.xkrs.straw.helper;
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
import com.xkrs.straw.service.impl.DispatchFirePointServiceImpl;
import com.xkrs.utils.GaoDeApiUtil;
import org.apache.hc.core5.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -92,10 +93,12 @@ public class GeoCodeHelper {
log.info("-------逆地理编码校验失败接收到的countyName=" + receivedCountyName + "计算得到的countyName=" + calCountyName);
return false;
}
if (!TextUtils.isEmpty(receivedTownCode)) {
if (!calTownCode.equals(receivedTownCode)) {
log.info("-------逆地理编码校验失败接收到的townCode=" + receivedTownCode + "计算得到的townCode=" + calTownCode);
return false;
}
}
return true;
}
}

View File

@ -1,5 +1,6 @@
package com.xkrs.straw.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.straw.dao.FirePointChannelConfigDao;
import com.xkrs.straw.dao.FirePointOrdinaryDao;
import com.xkrs.straw.dao.FirePointPreciseDao;
@ -13,21 +14,31 @@ import com.xkrs.straw.utils.DispatchFirePointUtils;
import com.xkrs.utils.DateTimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class DispatchFirePointServiceImpl implements DispatchFirePointService {
public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class);
private final Locale locale = LocaleContextHolder.getLocale();
@Resource
private FirePointChannelConfigDao channelConfigDao;
@Resource
private FirePointOrdinaryDao firePointOrdinaryDao;
@Resource
private FirePointPreciseDao firePointPreciseDao;
@Override
@ -115,7 +126,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
firePointPreciseDao.save(firePointPreciseEntity);
}
return null;
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
}
@Override
@ -160,7 +171,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
firePointPreciseDao.save(firePointPreciseEntity);
}
return null;
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
}
private void bindFirePointAddress(FirePointPreciseEntity firePointPreciseEntity) {
@ -176,6 +187,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
firePointPreciseEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
firePointPreciseEntity.setRemark("");
} else {
firePointPreciseEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
String remark = "接收到的countyCode=" + countyCode + "计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + "计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + "计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "";
firePointPreciseEntity.setRemark(remark);
}
@ -194,6 +206,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
firePointOrdinaryEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
firePointOrdinaryEntity.setRemark("");
} else {
firePointOrdinaryEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
String remark = "接收到的countyCode=" + countyCode + "计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + "计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + "计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "";
firePointOrdinaryEntity.setRemark(remark);
}

View File

@ -38,47 +38,47 @@ public class DispatchFirePointUtils {
//预处理开始时间
String startTime = channelConfig.getStartTime();//获取精准火点渠道的开始时间
boolean needCheckStartTime = !TextUtils.isEmpty(startTime);
LocalDateTime thisYearStartTime = null;
LocalDateTime sameYearStartTime = null;//计算得出精准渠道和传入火点同年的开始时间
if (needCheckStartTime) {
thisYearStartTime = obtainLocalDateTimeThisYear(startTime);
needCheckStartTime = thisYearStartTime != null;
sameYearStartTime = obtainLocalDateTimeSameYear(satelliteLocalDateTime.getYear(), startTime);
needCheckStartTime = sameYearStartTime != null;
}
//预处理结束时间
String endTime = channelConfig.getEndTime();//获取精准火点渠道的结束时间
boolean needCheckEndTime = !TextUtils.isEmpty(endTime);
LocalDateTime thisYearEndTime = null;
LocalDateTime sameYearEndTime = null;//计算得出精准渠道和传入火点同年的结束时间
if (needCheckEndTime) {
thisYearEndTime = obtainLocalDateTimeThisYear(endTime);
needCheckEndTime = thisYearEndTime != null;
sameYearEndTime = obtainLocalDateTimeSameYear(satelliteLocalDateTime.getYear(), endTime);
needCheckEndTime = sameYearEndTime != null;
}
//排列组合4种情况
if (needCheckStartTime) {
if (needCheckEndTime) {
//开始时间结束时间都需要比较
if (satelliteLocalDateTime.isBefore(thisYearStartTime) || thisYearEndTime.isBefore(satelliteLocalDateTime)) {
if (sameYearStartTime.isBefore(satelliteLocalDateTime) && sameYearEndTime.isAfter(satelliteLocalDateTime)) {
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
String time1 = DateTimeUtils.localDateTimeToString(thisYearStartTime);
String time2 = DateTimeUtils.localDateTimeToString(thisYearEndTime);
log.info("开始时间、结束时间都需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1 + ",结束时间=" + time2);
return false;
String time1 = DateTimeUtils.localDateTimeToString(sameYearStartTime);
String time2 = DateTimeUtils.localDateTimeToString(sameYearEndTime);
log.info("开始时间、结束时间都需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1 + ",结束时间=" + time2);
return true;
}
} else {
//开始时间需要比较结束时间不需要比较
if (satelliteLocalDateTime.isBefore(thisYearStartTime)) {
if (sameYearStartTime.isBefore(satelliteLocalDateTime)) {
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
String time1 = DateTimeUtils.localDateTimeToString(thisYearStartTime);
log.info("开始时间需要比较,结束时间不需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1);
return false;
String time1 = DateTimeUtils.localDateTimeToString(sameYearStartTime);
log.info("开始时间需要比较,结束时间不需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1);
return true;
}
}
} else {
if (needCheckEndTime) {
//开始时间不需要比较结束时间需要比较
if (thisYearEndTime.isBefore(satelliteLocalDateTime)) {
if (sameYearEndTime.isAfter(satelliteLocalDateTime)) {
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
String time2 = DateTimeUtils.localDateTimeToString(thisYearEndTime);
log.info("开始时间不需要比较,结束时间需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",结束时间=" + time2);
return false;
String time2 = DateTimeUtils.localDateTimeToString(sameYearEndTime);
log.info("开始时间不需要比较,结束时间需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",结束时间=" + time2);
return true;
}
} else {
//开始时间结束时间都不需要比较
@ -89,17 +89,17 @@ public class DispatchFirePointUtils {
}
}
}
//没有因为遇到符合条件的情况提前退出就认为精准渠道配置的时间范围之内
return true;
//没有因为遇到符合条件的情况提前退出就认为不属于精准渠道配置的时间范围之内
return false;
}
/**
* @param formattedTime 2022-01-01 00:00:00
*/
private static LocalDateTime obtainLocalDateTimeThisYear(String formattedTime) {
private static LocalDateTime obtainLocalDateTimeSameYear(int targetYear, String formattedTime) {
try {
LocalDateTime localDateTime = LocalDateTime.parse(formattedTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
int dYear = LocalDateTime.now().getYear() - localDateTime.getYear();
int dYear = targetYear - localDateTime.getYear();
return localDateTime.plusYears(dYear);
} catch (Exception e) {
e.printStackTrace();