优化 更新订阅
This commit is contained in:
parent
070a2e8e22
commit
ea335163b6
@ -0,0 +1,34 @@
|
|||||||
|
package com.xkrs.straw.model.bean;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class LocalDateTimeRange {
|
||||||
|
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
public LocalDateTimeRange() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTimeRange(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(LocalDateTime startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(LocalDateTime endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,172 @@
|
|||||||
|
package com.xkrs.straw.utils;
|
||||||
|
|
||||||
|
import com.xkrs.straw.dao.FirePointChannelConfigDao;
|
||||||
|
import com.xkrs.straw.dao.SysUserDao;
|
||||||
|
import com.xkrs.straw.model.bean.DataWrapper4;
|
||||||
|
import com.xkrs.straw.model.bean.FirePointChannelConfigBean;
|
||||||
|
import com.xkrs.straw.model.bean.LocalDateTimeRange;
|
||||||
|
import com.xkrs.straw.model.entity.FirePointChannelConfigEntity;
|
||||||
|
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||||
|
import com.xkrs.utils.DateTimeUtils;
|
||||||
|
import com.xkrs.utils.FirePointCodeUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class FirePointSubscribeManager {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FirePointChannelConfigDao channelConfigDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysUserDao sysUserDao;
|
||||||
|
|
||||||
|
public void autoSync() {
|
||||||
|
List<String> subscribedCountyCodeList = obtainSubscribedCountyCodeList();
|
||||||
|
updateSubscribedCountyCodeList(subscribedCountyCodeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订阅的区划编码集合
|
||||||
|
*/
|
||||||
|
private List<String> obtainSubscribedCountyCodeList() {
|
||||||
|
//查询防火季时间范围配置
|
||||||
|
List<FirePointChannelConfigEntity> channelConfigEntityList = channelConfigDao.findAll();
|
||||||
|
//获取到防火季时间格式集合
|
||||||
|
List<LocalDateTimeRange> fireSeasonTimeRangeList = obtainFireSeasonTimeRangeList(channelConfigEntityList);
|
||||||
|
//判断当前是否处于防火季
|
||||||
|
boolean checkIfIn = checkIfIn(fireSeasonTimeRangeList, LocalDateTime.now());
|
||||||
|
//不在防火季就返回空订阅
|
||||||
|
if (!checkIfIn) {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
}
|
||||||
|
//在防火季,就获取全部系统用户
|
||||||
|
List<String> countyCodeList = obtainCountyCodeList(sysUserDao.findAll());
|
||||||
|
List<String> mergedCountyCodeList = mergeCountyCodeList(countyCodeList);
|
||||||
|
mergedCountyCodeList.sort(Comparator.naturalOrder());
|
||||||
|
return mergedCountyCodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSubscribedCountyCodeList(List<String> subscribedCountyCodeList) {
|
||||||
|
// String url = "http://118.24.27.47:10721/winxin_api/msg";
|
||||||
|
// Map<String, Object> map = new HashMap<>();
|
||||||
|
// map.put("wxid", wxid);
|
||||||
|
// map.put("text", text);
|
||||||
|
// map.put("type", type);
|
||||||
|
// sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取到防火季时间格式集合
|
||||||
|
*/
|
||||||
|
private List<LocalDateTimeRange> obtainFireSeasonTimeRangeList(List<FirePointChannelConfigEntity> channelConfigEntityList) {
|
||||||
|
List<LocalDateTimeRange> timeRangeList = new ArrayList<>();
|
||||||
|
for (FirePointChannelConfigEntity channelConfigEntity : channelConfigEntityList) {
|
||||||
|
String jsonContent = channelConfigEntity.getJsonContent();
|
||||||
|
FirePointChannelConfigBean firePointChannelConfigBean = JsonUtils.deserialize(jsonContent, FirePointChannelConfigBean.class);
|
||||||
|
if (FirePointChannelConfigBean.Precise.equals(firePointChannelConfigBean.getChannelName())) {
|
||||||
|
List<FirePointChannelConfigBean.ChannelConfig> channelConfigList = firePointChannelConfigBean.getConfigList();
|
||||||
|
for (FirePointChannelConfigBean.ChannelConfig channelConfig : channelConfigList) {
|
||||||
|
LocalDateTime startLocalDateTime = LocalDateTime.parse(channelConfig.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||||
|
startLocalDateTime.plusYears(LocalDateTime.now().getYear() - startLocalDateTime.getYear());
|
||||||
|
LocalDateTime endLocalDateTime = LocalDateTime.parse(channelConfig.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||||
|
endLocalDateTime.plusYears(LocalDateTime.now().getYear() - endLocalDateTime.getYear());
|
||||||
|
timeRangeList.add(new LocalDateTimeRange(startLocalDateTime, endLocalDateTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return timeRangeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfIn(List<LocalDateTimeRange> timeRangeList, LocalDateTime targetTime) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> obtainCountyCodeList(List<SysUserEntity> sysUserEntityList) {
|
||||||
|
List<String> countyCodeList = new ArrayList<>();
|
||||||
|
for (SysUserEntity sysUserEntity : sysUserEntityList) {
|
||||||
|
boolean inVipTimeRange = VipTimeRangeUtils.checkIfInVipTimeRange(sysUserEntity.getVipTimeRangeJson());
|
||||||
|
if (inVipTimeRange) {
|
||||||
|
countyCodeList.add(sysUserEntity.getCountyCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return countyCodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并区划编码
|
||||||
|
*/
|
||||||
|
private List<String> mergeCountyCodeList(List<String> countyCodeList) {
|
||||||
|
List<String> mergedCountyCodeList = new ArrayList<>();
|
||||||
|
for (String countyCode : countyCodeList) {
|
||||||
|
DataWrapper4<Boolean, Boolean, List<String>, String> checkMerged = checkMerged(mergedCountyCodeList, countyCode);
|
||||||
|
Boolean wasMerged = checkMerged.getData1();
|
||||||
|
Boolean needReplace = checkMerged.getData2();
|
||||||
|
List<String> oldValueList = checkMerged.getData3();
|
||||||
|
String newValue = checkMerged.getData4();
|
||||||
|
if (!wasMerged) {
|
||||||
|
if (needReplace) {
|
||||||
|
mergedCountyCodeList.removeAll(oldValueList);
|
||||||
|
}
|
||||||
|
mergedCountyCodeList.add(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mergedCountyCodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否被合并过了
|
||||||
|
* DataWrapper4<Boolean, Boolean, String, String>
|
||||||
|
* Boolean 是否被合并了
|
||||||
|
* Boolean 如果1==true则2失效,如果1==false则2表示这个未被合并的数据是否需要替换,如果2==true则将3替换成4,如果2==false则只添加4,忽略3
|
||||||
|
* String 如果1==false并且2==true(这个数据没有被合并,并且它需要替换添加),3是待替换的旧值
|
||||||
|
* String 如果1==false并且2==true(这个数据没有被合并,并且它需要替换添加),4是要替换成的新值;如果1==false并且2==false(这个数据没有被合并,并且它不需要替换添加),4是要添加的
|
||||||
|
*/
|
||||||
|
private DataWrapper4<Boolean, Boolean, List<String>, String> checkMerged(List<String> mergedCountyCodeList, String countyCode) {
|
||||||
|
for (String mergedCountyCode : mergedCountyCodeList) {
|
||||||
|
try {
|
||||||
|
String cutMergedCountyCode = FirePointCodeUtils.getFormatCutCode(mergedCountyCode);
|
||||||
|
String cutCountyCode = FirePointCodeUtils.getFormatCutCode(countyCode);
|
||||||
|
if (cutCountyCode.equals(cutMergedCountyCode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (cutCountyCode.startsWith(cutMergedCountyCode)) {
|
||||||
|
return new DataWrapper4<>(Boolean.TRUE, null, null, null);
|
||||||
|
}
|
||||||
|
if (cutMergedCountyCode.startsWith(cutCountyCode)) {
|
||||||
|
List<String> list = obtainRedundantMergedCountyCodeList(mergedCountyCodeList, cutCountyCode);
|
||||||
|
return new DataWrapper4<>(Boolean.FALSE, Boolean.TRUE, list, countyCode);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DataWrapper4<>(Boolean.FALSE, Boolean.FALSE, null, countyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在发现了一个新的、范围更大的区划时,获取这个区划下边已经包含的、冗余的、范围小一点的区划
|
||||||
|
*/
|
||||||
|
private List<String> obtainRedundantMergedCountyCodeList(List<String> mergedCountyCodeList, String cutCountyCode) {
|
||||||
|
List<String> redundantMergedCountyCodeList = new ArrayList<>();
|
||||||
|
for (String mergedCountyCode : mergedCountyCodeList) {
|
||||||
|
try {
|
||||||
|
String cutMergedCountyCode = FirePointCodeUtils.getFormatCutCode(mergedCountyCode);
|
||||||
|
if (cutMergedCountyCode.startsWith(cutCountyCode)) {
|
||||||
|
redundantMergedCountyCodeList.add(mergedCountyCode);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redundantMergedCountyCodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user