优化双火点渠道入库逻辑
This commit is contained in:
parent
8b69e5a874
commit
ff294b8213
@ -3,6 +3,7 @@ package com.xkrs.straw.helper;
|
|||||||
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
||||||
import com.xkrs.straw.service.impl.DispatchFirePointServiceImpl;
|
import com.xkrs.straw.service.impl.DispatchFirePointServiceImpl;
|
||||||
import com.xkrs.utils.GaoDeApiUtil;
|
import com.xkrs.utils.GaoDeApiUtil;
|
||||||
|
import org.apache.hc.core5.util.TextUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -92,10 +93,12 @@ public class GeoCodeHelper {
|
|||||||
log.info("-------逆地理编码校验失败:接收到的countyName=" + receivedCountyName + ",计算得到的countyName=" + calCountyName);
|
log.info("-------逆地理编码校验失败:接收到的countyName=" + receivedCountyName + ",计算得到的countyName=" + calCountyName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!TextUtils.isEmpty(receivedTownCode)) {
|
||||||
if (!calTownCode.equals(receivedTownCode)) {
|
if (!calTownCode.equals(receivedTownCode)) {
|
||||||
log.info("-------逆地理编码校验失败:接收到的townCode=" + receivedTownCode + ",计算得到的townCode=" + calTownCode);
|
log.info("-------逆地理编码校验失败:接收到的townCode=" + receivedTownCode + ",计算得到的townCode=" + calTownCode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.xkrs.straw.service.impl;
|
package com.xkrs.straw.service.impl;
|
||||||
|
|
||||||
|
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||||
import com.xkrs.straw.dao.FirePointChannelConfigDao;
|
import com.xkrs.straw.dao.FirePointChannelConfigDao;
|
||||||
import com.xkrs.straw.dao.FirePointOrdinaryDao;
|
import com.xkrs.straw.dao.FirePointOrdinaryDao;
|
||||||
import com.xkrs.straw.dao.FirePointPreciseDao;
|
import com.xkrs.straw.dao.FirePointPreciseDao;
|
||||||
@ -13,21 +14,31 @@ import com.xkrs.straw.utils.DispatchFirePointUtils;
|
|||||||
import com.xkrs.utils.DateTimeUtils;
|
import com.xkrs.utils.DateTimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
||||||
|
|
||||||
public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class);
|
public static Logger log = LoggerFactory.getLogger(DispatchFirePointServiceImpl.class);
|
||||||
|
|
||||||
|
private final Locale locale = LocaleContextHolder.getLocale();
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FirePointChannelConfigDao channelConfigDao;
|
private FirePointChannelConfigDao channelConfigDao;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FirePointOrdinaryDao firePointOrdinaryDao;
|
private FirePointOrdinaryDao firePointOrdinaryDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
private FirePointPreciseDao firePointPreciseDao;
|
private FirePointPreciseDao firePointPreciseDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -115,7 +126,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
firePointPreciseDao.save(firePointPreciseEntity);
|
firePointPreciseDao.save(firePointPreciseEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -160,7 +171,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
firePointPreciseDao.save(firePointPreciseEntity);
|
firePointPreciseDao.save(firePointPreciseEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功", locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindFirePointAddress(FirePointPreciseEntity firePointPreciseEntity) {
|
private void bindFirePointAddress(FirePointPreciseEntity firePointPreciseEntity) {
|
||||||
@ -176,6 +187,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
firePointPreciseEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
|
firePointPreciseEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
|
||||||
firePointPreciseEntity.setRemark("");
|
firePointPreciseEntity.setRemark("");
|
||||||
} else {
|
} else {
|
||||||
|
firePointPreciseEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
|
||||||
String remark = "接收到的countyCode=" + countyCode + ",计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + ",计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + ",计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "。";
|
String remark = "接收到的countyCode=" + countyCode + ",计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + ",计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + ",计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "。";
|
||||||
firePointPreciseEntity.setRemark(remark);
|
firePointPreciseEntity.setRemark(remark);
|
||||||
}
|
}
|
||||||
@ -194,6 +206,7 @@ public class DispatchFirePointServiceImpl implements DispatchFirePointService {
|
|||||||
firePointOrdinaryEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
|
firePointOrdinaryEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
|
||||||
firePointOrdinaryEntity.setRemark("");
|
firePointOrdinaryEntity.setRemark("");
|
||||||
} else {
|
} else {
|
||||||
|
firePointOrdinaryEntity.setFirePointAddress(geoCodeHelper.getCalFirePointAddress());
|
||||||
String remark = "接收到的countyCode=" + countyCode + ",计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + ",计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + ",计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "。";
|
String remark = "接收到的countyCode=" + countyCode + ",计算得到的countyCode=" + geoCodeHelper.getCalCountyCode() + "。接收到的countyName=" + countyName + ",计算得到的countyName=" + geoCodeHelper.getCalCountyName() + "。接收到的townCode=" + townCode + ",计算得到的townCode=" + geoCodeHelper.getCalTownCode() + "。";
|
||||||
firePointOrdinaryEntity.setRemark(remark);
|
firePointOrdinaryEntity.setRemark(remark);
|
||||||
}
|
}
|
||||||
|
@ -38,47 +38,47 @@ public class DispatchFirePointUtils {
|
|||||||
//预处理开始时间
|
//预处理开始时间
|
||||||
String startTime = channelConfig.getStartTime();//获取精准火点渠道的开始时间
|
String startTime = channelConfig.getStartTime();//获取精准火点渠道的开始时间
|
||||||
boolean needCheckStartTime = !TextUtils.isEmpty(startTime);
|
boolean needCheckStartTime = !TextUtils.isEmpty(startTime);
|
||||||
LocalDateTime thisYearStartTime = null;
|
LocalDateTime sameYearStartTime = null;//计算得出精准渠道和传入火点同年的开始时间
|
||||||
if (needCheckStartTime) {
|
if (needCheckStartTime) {
|
||||||
thisYearStartTime = obtainLocalDateTimeThisYear(startTime);
|
sameYearStartTime = obtainLocalDateTimeSameYear(satelliteLocalDateTime.getYear(), startTime);
|
||||||
needCheckStartTime = thisYearStartTime != null;
|
needCheckStartTime = sameYearStartTime != null;
|
||||||
}
|
}
|
||||||
//预处理结束时间
|
//预处理结束时间
|
||||||
String endTime = channelConfig.getEndTime();//获取精准火点渠道的结束时间
|
String endTime = channelConfig.getEndTime();//获取精准火点渠道的结束时间
|
||||||
boolean needCheckEndTime = !TextUtils.isEmpty(endTime);
|
boolean needCheckEndTime = !TextUtils.isEmpty(endTime);
|
||||||
LocalDateTime thisYearEndTime = null;
|
LocalDateTime sameYearEndTime = null;//计算得出精准渠道和传入火点同年的结束时间
|
||||||
if (needCheckEndTime) {
|
if (needCheckEndTime) {
|
||||||
thisYearEndTime = obtainLocalDateTimeThisYear(endTime);
|
sameYearEndTime = obtainLocalDateTimeSameYear(satelliteLocalDateTime.getYear(), endTime);
|
||||||
needCheckEndTime = thisYearEndTime != null;
|
needCheckEndTime = sameYearEndTime != null;
|
||||||
}
|
}
|
||||||
//排列组合4种情况
|
//排列组合4种情况
|
||||||
if (needCheckStartTime) {
|
if (needCheckStartTime) {
|
||||||
if (needCheckEndTime) {
|
if (needCheckEndTime) {
|
||||||
//开始时间、结束时间都需要比较
|
//开始时间、结束时间都需要比较
|
||||||
if (satelliteLocalDateTime.isBefore(thisYearStartTime) || thisYearEndTime.isBefore(satelliteLocalDateTime)) {
|
if (sameYearStartTime.isBefore(satelliteLocalDateTime) && sameYearEndTime.isAfter(satelliteLocalDateTime)) {
|
||||||
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
|
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
|
||||||
String time1 = DateTimeUtils.localDateTimeToString(thisYearStartTime);
|
String time1 = DateTimeUtils.localDateTimeToString(sameYearStartTime);
|
||||||
String time2 = DateTimeUtils.localDateTimeToString(thisYearEndTime);
|
String time2 = DateTimeUtils.localDateTimeToString(sameYearEndTime);
|
||||||
log.info("开始时间、结束时间都需要比较,比较结果:不属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1 + ",结束时间=" + time2);
|
log.info("开始时间、结束时间都需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1 + ",结束时间=" + time2);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//开始时间需要比较,结束时间不需要比较
|
//开始时间需要比较,结束时间不需要比较
|
||||||
if (satelliteLocalDateTime.isBefore(thisYearStartTime)) {
|
if (sameYearStartTime.isBefore(satelliteLocalDateTime)) {
|
||||||
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
|
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
|
||||||
String time1 = DateTimeUtils.localDateTimeToString(thisYearStartTime);
|
String time1 = DateTimeUtils.localDateTimeToString(sameYearStartTime);
|
||||||
log.info("开始时间需要比较,结束时间不需要比较,比较结果:不属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1);
|
log.info("开始时间需要比较,结束时间不需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",开始时间=" + time1);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (needCheckEndTime) {
|
if (needCheckEndTime) {
|
||||||
//开始时间不需要比较,结束时间需要比较
|
//开始时间不需要比较,结束时间需要比较
|
||||||
if (thisYearEndTime.isBefore(satelliteLocalDateTime)) {
|
if (sameYearEndTime.isAfter(satelliteLocalDateTime)) {
|
||||||
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
|
String time0 = DateTimeUtils.localDateTimeToString(satelliteLocalDateTime);
|
||||||
String time2 = DateTimeUtils.localDateTimeToString(thisYearEndTime);
|
String time2 = DateTimeUtils.localDateTimeToString(sameYearEndTime);
|
||||||
log.info("开始时间不需要比较,结束时间需要比较,比较结果:不属于精准时间范围内,详情:火点时间=" + time0 + ",结束时间=" + time2);
|
log.info("开始时间不需要比较,结束时间需要比较,比较结果:属于精准时间范围内,详情:火点时间=" + time0 + ",结束时间=" + time2);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//开始时间、结束时间都不需要比较
|
//开始时间、结束时间都不需要比较
|
||||||
@ -89,17 +89,17 @@ public class DispatchFirePointUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//没有因为遇到不符合条件的情况提前退出,就认为在精准渠道配置的时间范围之内
|
//没有因为遇到符合条件的情况提前退出,就认为不属于精准渠道配置的时间范围之内
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param formattedTime 2022-01-01 00:00:00
|
* @param formattedTime 2022-01-01 00:00:00
|
||||||
*/
|
*/
|
||||||
private static LocalDateTime obtainLocalDateTimeThisYear(String formattedTime) {
|
private static LocalDateTime obtainLocalDateTimeSameYear(int targetYear, String formattedTime) {
|
||||||
try {
|
try {
|
||||||
LocalDateTime localDateTime = LocalDateTime.parse(formattedTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
|
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);
|
return localDateTime.plusYears(dYear);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user