Merge remote-tracking branch 'origin/mdc' into mdc

This commit is contained in:
nieziyan 2024-02-19 18:58:20 +08:00
commit c0b3709d99
13 changed files with 323 additions and 88 deletions

View File

@ -69,7 +69,7 @@ public class UndealHandleManager{
//ftp解析失败文件存储路径
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
final String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath();
List<File> spectrumFiles = FileOperation.getFiles(rootPath+ filePath,taskProperties.getUndealDirReceiveNum());
List<File> spectrumFiles = FileOperation.getFiles(rootPath+ filePath);
if(!CollectionUtils.isEmpty(spectrumFiles)){
CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size());
for(File spectrumFile : spectrumFiles){

View File

@ -69,6 +69,50 @@ public class FileOperation {
return sortList.stream().limit(num).collect(Collectors.toList());
}
/**
* 获取指定路径下指定数量的文件
* @param path
* @return
* @throws FileNotFoundException
*/
public static List<File> getFiles(String path) throws FileNotFoundException {
File file = new File(path);
if (!file.exists()){
throw new FileNotFoundException(path+" directory does not exist");
}
if (!file.isDirectory()){
throw new FileNotFoundException(path+" file is not a directory");
}
if(FileUtil.isDirEmpty(file)){
return Collections.emptyList();
}
if(CollectionUtils.isEmpty(dataTypeMap)){
final DataType[] dataTypes = DataType.values();
for (DataType dataType : dataTypes){
dataTypeMap.put(dataType.getSuffix(),"default");
}
}
File[] spectrumFiles = file.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
final String suffix = file.getName().substring(file.getName().lastIndexOf(StringConstant.DOT));
if (dataTypeMap.containsKey(suffix)){
return true;
}
return false;
}
});
List<File> sortList = new ArrayList<>();
for (File spectrumFile : spectrumFiles){
if(spectrumFile.getName().contains(BlockConstant.sampleFlag)){
sortList.add(spectrumFile);
}else {
sortList.add(0,spectrumFile);
}
}
return sortList.stream().collect(Collectors.toList());
}
/**
* 保存或追加写入文件
* @param filePath

View File

@ -118,6 +118,10 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
} else if (StringUtils.isNotBlank(sourceData.acquisition_start_time) && StringUtils.isNotBlank(sourceData.acquisition_start_date)) {
DateUtils.parseDate(sourceData.acquisition_start_date + StringPool.SPACE + sourceData.acquisition_start_time);
}
if (!Double.isFinite(sourceData.acquisition_live_time) || !Double.isFinite(sourceData.acquisition_real_time)) {
throw new RuntimeException();
}
} catch (Exception e) {
//将文件移动到错误文件目录
super.isDateFormatErr = true;

View File

@ -306,8 +306,22 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
log.error("An error occurred during the process of processing the failed parsing file. The file is: {}, and the reason is: {}",this.spectrumFile.getAbsolutePath(),e.getMessage());
ex.printStackTrace();
}
}else if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource) && (e instanceof FileRepeatException)){
} else if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource) && (e instanceof FileRepeatException)){
this.spectrumFile.delete();
} else if (SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)) {
try {
if (isDateFormatErr) {
//修改能谱文件名称
this.updateErrorSpectrumFileName();
//解析失败会把文件移动到errorfile目录
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
final String errorFilePath = spectrumServiceQuotes.getSpectrumPathProperties().getErrorFilePath();
final String finalPath = rootPath+errorFilePath;
FileOperation.moveFile(spectrumFile,finalPath,true);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}

View File

@ -60,8 +60,8 @@ public class StationOperationController {
@GetMapping("getDataReceivingStatus")
@ApiOperation(value = "查询台站监测数据信息", notes = "查询台站监测数据信息")
public Result getDataReceivingStatus(String userId, String oneStationId){
return stationOperationService.getDataReceivingStatus(userId, oneStationId);
public Result getDataReceivingStatus(String userId, Double cacheTime, String oneStationId){
return stationOperationService.getDataReceivingStatus(userId, cacheTime, oneStationId);
}

View File

@ -38,6 +38,12 @@ public class SysUserFocusStationController {
return sysUserFocusStationService.deleteById(stationId);
}
@DeleteMapping("deleteUserCache")
@ApiOperation(value = "删除用户的临时缓存", notes = "删除用户的临时缓存")
public Result deleteUserCache(String userId) {
return sysUserFocusStationService.deleteUserCache(userId);
}
@GetMapping("findUserFocusByUserId")
@ApiOperation(value = "根据用户id查询用户的缓存配置信息及关注台站信息", notes = "根据用户id查询用户的缓存配置信息及关注台站信息")
public Result findUserFocusByUserId(String userId){

View File

@ -39,4 +39,10 @@ public class SysUserFocusStationStation extends SysUserFocusStation {
@TableField(exist = false)
private String stationCode;
/**
* 是否是排班任务台站
*/
@TableField(exist = false)
private boolean isScheduling;
}

View File

@ -0,0 +1,12 @@
package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.base.entity.postgre.SysTaskStation;
import java.util.List;
public interface SysTaskStationMapper extends BaseMapper<SysTaskStation> {
List<String> findTaskStation(String userId, String nowDate);
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.SysTaskStationMapper">
<select id="findTaskStation" resultType="java.lang.String">
SELECT
station_id
from
sys_task_station
where
task_id =
(SELECT
id
FROM
sys_task
where
user_id = #{userId}
and scheduling_date = to_date(#{nowDate}, 'YYYY-MM-DD')
)
</select>
</mapper>

View File

@ -49,7 +49,7 @@ public interface IStationOperationService extends IService<StationOperation> {
* @param oneStationId
* @return
*/
Result getDataReceivingStatus(String userId, String oneStationId);
Result getDataReceivingStatus(String userId, Double cacheTime, String oneStationId);
/**
* 获取台站数据的提供率及有效率

View File

@ -27,6 +27,13 @@ public interface ISysUserFocusStationService extends IService<SysUserFocusStatio
*/
Result deleteById(String stationId);
/**
* 删除用户的临时缓存记录
* @param userId
* @return
*/
Result deleteUserCache(String userId);
/**
* 根据用户id查询对应的缓存配置信息
* @param userId

View File

@ -48,11 +48,14 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
@Autowired
private RedisUtil redisUtil;
@Autowired
private ICacheTimeService cacheTimeService;
@Resource
private SysUserFocusStationMapper sysUserFocusStationMapper;
@Resource
private StationReceivingConfigMapper stationReceivingConfigMapper;
private SysTaskStationMapper taskStationMapper;
@Autowired
private StationTypeUtil stationTypeUtil;
@ -387,13 +390,18 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
}
@Override
public Result getDataReceivingStatus(String userId, String oneStationId) {
public Result getDataReceivingStatus(String userId, Double cacheTime, String oneStationId) {
Result result = new Result();
Map<String, StationData> stationDataMap = (Map<String, StationData>) redisUtil.get("stationDataMap");
LambdaQueryWrapper<StationReceivingConfigStation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StationReceivingConfig::getUserId, userId);
StationReceivingConfigStation configStation = stationReceivingConfigMapper.selectOne(queryWrapper);
Double cacheTime = configStation.getCacheTime();
//调用接口获取数据库中对应缓存配置信息默认值
if (Objects.isNull(cacheTime) || cacheTime <= 0) {
List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
for (int i=0; i< cacheList.size(); i++){
if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ){
cacheTime = Double.valueOf(cacheList.get(i).get(CacheName.cacheTime));
}
}
}
//获取当前日期时间 作为结束查询时间
LocalDateTime endDate = LocalDateTime.now();
//根据缓存日期 得到开始查询时间
@ -416,38 +424,54 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
for (Map<String, DetectorData> detectorDataMap:detectorValue) {
for (String key :detectorDataMap.keySet()) {
DetectorData detectorData = detectorDataMap.get(key);
List<DataInfoVo> dataList = detectorData.getDataList();
//通过流过滤出数据的开始时间戳在用户统计的开始时间戳之后的数据
detectorData.getDataList().stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList());
dataList = dataList.stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList());
detectorData.setDataList(dataList);
}
}
}
stationDataList.add(stationData);
}
stationDataList.add(stationData);
} else {
List<String> stationIds = new LinkedList<>();
//根据用户id查询出当前用户关注的台站信息
LambdaQueryWrapper<SysUserFocusStationStation> userFocusStationQueryWrapper = new LambdaQueryWrapper<>();
userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
List<SysUserFocusStationStation> userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper);
List<String> stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList());
for (String stationId:stationIds) {
StationData stationData = stationDataMap.get(stationId);
if (Objects.nonNull(stationData)) {
//读取探测器的数据集合
Map<String, List<Map<String, DetectorData>>> detectors = stationData.getDetectors();
//遍历探测器的集合
for (Map.Entry<String, List<Map<String, DetectorData>>> detector:detectors.entrySet()) {
//获取探测器对应的数组
List<Map<String, DetectorData>> detectorValue = detector.getValue();
//遍历探测器数组
for (Map<String, DetectorData> detectorDataMap:detectorValue) {
for (String key :detectorDataMap.keySet()) {
DetectorData detectorData = detectorDataMap.get(key);
//通过流过滤出数据的开始时间戳在用户统计的开始时间戳之后的数据
detectorData.getDataList().stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(userFocusStations)) {
List<String> focusStationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList());
stationIds.addAll(focusStationIds);
}
String nowDate = DateUtils.now();
List<String> taskStationIds = taskStationMapper.findTaskStation(userId, nowDate);
if (CollectionUtils.isNotEmpty(taskStationIds)) {
stationIds.addAll(taskStationIds);
}
stationIds = stationIds.stream().distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(stationIds)) {
for (String stationId:stationIds) {
StationData stationData = stationDataMap.get(stationId);
if (Objects.nonNull(stationData)) {
//读取探测器的数据集合
Map<String, List<Map<String, DetectorData>>> detectors = stationData.getDetectors();
//遍历探测器的集合
for (Map.Entry<String, List<Map<String, DetectorData>>> detector:detectors.entrySet()) {
//获取探测器对应的数组
List<Map<String, DetectorData>> detectorValue = detector.getValue();
//遍历探测器数组
for (Map<String, DetectorData> detectorDataMap:detectorValue) {
for (String key :detectorDataMap.keySet()) {
DetectorData detectorData = detectorDataMap.get(key);
List<DataInfoVo> dataList = detectorData.getDataList();
//通过流过滤出数据的开始时间戳在用户统计的开始时间戳之后的数据
dataList = dataList.stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList());
detectorData.setDataList(dataList);
}
}
}
stationDataList.add(stationData);
}
stationDataList.add(stationData);
}
}
}

View File

@ -8,7 +8,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.CacheName;
import org.jeecg.common.StationTypeUtil;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.config.mqtoken.UserTokenContext;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.base.entity.configuration.GardsStations;
@ -18,9 +20,11 @@ import org.jeecg.modules.entity.StationReceivingConfigStation;
import org.jeecg.modules.entity.SysUserFocusStationStation;
import org.jeecg.modules.entity.data.UserFocusStation;
import org.jeecg.modules.mapper.StationReceivingConfigMapper;
import org.jeecg.modules.mapper.SysTaskStationMapper;
import org.jeecg.modules.mapper.SysUserFocusStationMapper;
import org.jeecg.modules.service.ICacheTimeService;
import org.jeecg.modules.service.ISysUserFocusStationService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -30,6 +34,8 @@ import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import static org.jeecg.common.util.TokenUtils.getTempToken;
@Service("sysUserFocusStationService")
public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStationMapper, SysUserFocusStationStation> implements ISysUserFocusStationService {
@ -38,7 +44,7 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
@Autowired
private ICacheTimeService cacheTimeService;
@Autowired
private StationReceivingConfigMapper stationReceivingConfigMapper;
private SysTaskStationMapper taskStationMapper;
@Autowired
private StationTypeUtil stationTypeUtil;
@ -50,29 +56,9 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
String username = JwtUtil.getUserNameByToken(request);
//根据用户名称查询对应的用户信息
SysUser sysUser = cacheTimeService.findUserByName(username);
//查询全部台站信息
HashMap<String, Object> stationInfoMap = (HashMap<String, Object>) redisUtil.get("stationInfoMap");
LambdaQueryWrapper<SysUserFocusStationStation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserFocusStationStation::getUserId, sysUser.getId());
List<SysUserFocusStationStation> sysUserFocusStations = this.baseMapper.selectList(queryWrapper);
if (CollectionUtils.isNotEmpty(sysUserFocusStations)){
sysUserFocusStations.stream().forEach(item->{
if (CollectionUtils.isNotEmpty(stationInfoMap)){
if (Objects.nonNull(stationInfoMap.get(item.getStationId()))){
GardsStations stations = (GardsStations) stationInfoMap.get(item.getStationId());
String stationType = stationTypeUtil.getStationType(stations.getStationId());
item.setStationType(stationType);
item.setStationCode(stations.getStationCode());
item.setLon(stations.getLon());
item.setLat(stations.getLat());
item.setStatus(stations.getStatus());
item.setAltitude(Objects.isNull(stations.getElevation())?"--":stations.getElevation()+"m");
}
}
});
return sysUserFocusStations;
}
return Collections.emptyList();
//调用公用方法查询关注台站信息
List<SysUserFocusStationStation> resultList = findUserFocusStations(sysUser.getId());
return resultList;
}
@Override
@ -91,28 +77,22 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
}
//判断传递参数信息是否为空
if (Objects.nonNull(userFocusStation)){
//通过用户id判断是否存在用户的缓存配置信息
LambdaQueryWrapper<StationReceivingConfigStation> receivingConfigQueryWrapper = new LambdaQueryWrapper<>();
receivingConfigQueryWrapper.eq(StationReceivingConfigStation::getUserId, sysUser.getId());
StationReceivingConfigStation receivingConfig = stationReceivingConfigMapper.selectOne(receivingConfigQueryWrapper);
//如果没有对应的用户缓存信息 则进行新增
if (Objects.isNull(receivingConfig)){
receivingConfig = new StationReceivingConfigStation();
Long id = IdWorker.getId();
receivingConfig.setId(id.toString());
receivingConfig.setUserId(sysUser.getId());
receivingConfig.setCacheTime(userFocusStation.getCacheTime());
receivingConfig.setScaleInterval(userFocusStation.getScaleInterval());
receivingConfig.setTimelineLength(userFocusStation.getTimelineLength());
receivingConfig.setUpdateIntervalTime(userFocusStation.getUpdateIntervalTime());
stationReceivingConfigMapper.insert(receivingConfig);
}else {
receivingConfig.setCacheTime(userFocusStation.getCacheTime());
receivingConfig.setScaleInterval(userFocusStation.getScaleInterval());
receivingConfig.setTimelineLength(userFocusStation.getTimelineLength());
receivingConfig.setUpdateIntervalTime(userFocusStation.getUpdateIntervalTime());
stationReceivingConfigMapper.updateById(receivingConfig);
//判断是否包含最大缓存时间
if (redisUtil.hasKey("maxCacheTime")) {
//最大的缓存时间
String maxCacheTime = (String) redisUtil.get("maxCacheTime");
//用户临时记录的缓存时间
Double cacheTime = userFocusStation.getCacheTime();
//如果用户临时记录的缓存时间大于最大缓存时间
if (cacheTime > Double.valueOf(maxCacheTime)) {
redisUtil.set("maxCacheTime", String.valueOf(cacheTime));
}
}
//记录当前用户的临时数据
redisUtil.set("cacheTime:"+sysUser.getId(), userFocusStation.getCacheTime());
redisUtil.set("scaleInterval:"+sysUser.getId(), userFocusStation.getScaleInterval());
redisUtil.set("timelineLength:"+sysUser.getId(), userFocusStation.getTimelineLength());
redisUtil.set("updateIntervalTime:"+sysUser.getId(), userFocusStation.getUpdateIntervalTime());
}
if (CollectionUtils.isNotEmpty(userFocusStation.getStationIds())){
//根据用户id查询出对应的用户关注台站信息 删除用户的所有关注台站信息并重新保存
@ -135,9 +115,12 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
if (focusStationStationList.size()>0) {
this.saveBatch(focusStationStationList);
}
} else {
//根据用户id查询出对应的用户关注台站信息 删除用户的所有关注台站信息并重新保存
LambdaQueryWrapper<SysUserFocusStationStation> userFocusStationQueryWrapper = new LambdaQueryWrapper<>();
userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, sysUser.getId());
this.baseMapper.delete(userFocusStationQueryWrapper);
}
//重新保存后重新缓存
cacheStationReceivingConfig();
result.success("Save successfully");
return result;
}
@ -164,16 +147,28 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
return result;
}
@Override
public Result deleteUserCache(String userId) {
redisUtil.del("cacheTime:"+userId, "scaleInterval:"+userId, "timelineLength:"+userId, "updateIntervalTime:"+userId);
return Result.ok();
}
@Override
public Result findUserFocusByUserId(String userId) {
Result result = new Result();
//根据用户id查询存储的缓存配置信息
LambdaQueryWrapper<StationReceivingConfigStation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StationReceivingConfigStation::getUserId, userId);
StationReceivingConfigStation receivingConfig = stationReceivingConfigMapper.selectOne(queryWrapper);
//如果用户对应的缓存配置信息为空时查询字典表中的默认值
if (Objects.isNull(receivingConfig)){
receivingConfig = new StationReceivingConfigStation();
StationReceivingConfigStation receivingConfig = new StationReceivingConfigStation();
//判断用户是否有缓存数据记录
if (redisUtil.hasKey("cacheTime:"+userId)) {
String cacheTime = String.valueOf(redisUtil.get("cacheTime:"+userId));
receivingConfig.setCacheTime(Double.valueOf(cacheTime));
String scaleInterval = String.valueOf(redisUtil.get("scaleInterval:"+userId));
receivingConfig.setScaleInterval(Double.valueOf(scaleInterval));
String timelineLength = String.valueOf(redisUtil.get("timelineLength:"+userId));
receivingConfig.setTimelineLength(Double.valueOf(timelineLength));
String updateIntervalTime = String.valueOf(redisUtil.get("updateIntervalTime:"+userId));
receivingConfig.setUpdateIntervalTime(Double.valueOf(updateIntervalTime));
} else {
//调用接口获取数据库中对应缓存配置信息默认值
List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
for (int i=0; i< cacheList.size(); i++){
@ -196,10 +191,10 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
LambdaQueryWrapper<SysUserFocusStationStation> focusStationQueryWrapper = new LambdaQueryWrapper<>();
focusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
List<SysUserFocusStationStation> sysUserFocusStations = this.baseMapper.selectList(focusStationQueryWrapper);
if (Objects.nonNull(sysUserFocusStations)){
if (CollectionUtils.isNotEmpty(sysUserFocusStations)){
receivingConfig.setSysUserFocusStations(sysUserFocusStations);
} else {
receivingConfig.setSysUserFocusStations(new ArrayList<>());
receivingConfig.setSysUserFocusStations(Collections.emptyList());
}
result.setSuccess(true);
result.setResult(receivingConfig);
@ -208,9 +203,110 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
@Override
public void cacheStationReceivingConfig() {
//查询用户名以及用户名关联的缓存设置
String maxCacheTime = stationReceivingConfigMapper.findMaxCacheTime();
redisUtil.set("maxCacheTime", maxCacheTime);
String maxCacheTime = "30";
redisUtil.del("cacheTime", "scaleInterval", "timelineLength", "updateIntervalTime");
UserTokenContext.setToken(getTempToken());
//调用接口获取数据库中对应缓存配置信息默认值
List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
for (int i=0; i< cacheList.size(); i++){
if ( StringUtils.isNotBlank(cacheList.get(i).get(CacheName.cacheTime)) ){
maxCacheTime = cacheList.get(i).get(CacheName.cacheTime);
}
}
if (StringUtils.isNotBlank(maxCacheTime)) {
redisUtil.set("maxCacheTime", maxCacheTime);
}
UserTokenContext.remove();
}
private List<SysUserFocusStationStation> findUserFocusStations(String userId) {
List<SysUserFocusStationStation> resultList = new LinkedList<>();
//查询全部台站信息
HashMap<String, Object> stationInfoMap = (HashMap<String, Object>) redisUtil.get("stationInfoMap");
//根据用户id查询关注台站信息
LambdaQueryWrapper<SysUserFocusStationStation> focusStationQueryWrapper = new LambdaQueryWrapper<>();
focusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
List<SysUserFocusStationStation> sysUserFocusStations = this.baseMapper.selectList(focusStationQueryWrapper);
//根据用户id查询排班任务的台站信息
//查询用户的排班任务
String nowDate = DateUtils.now();
List<String> taskStation = taskStationMapper.findTaskStation(userId, nowDate);
//判断用户是否有关注台站列表
if (CollectionUtils.isNotEmpty(sysUserFocusStations)){
//遍历关注台站列表
for (SysUserFocusStationStation item:sysUserFocusStations) {
//判断台站map是否为空
if (CollectionUtils.isNotEmpty(stationInfoMap)){
//判断台站map是否包含当前台站id
if (Objects.nonNull(stationInfoMap.get(item.getStationId()))){
//获取台站信息
GardsStations stations = (GardsStations) stationInfoMap.get(item.getStationId());
//获取台站类型
String stationType = stationTypeUtil.getStationType(stations.getStationId());
item.setStationType(stationType);
item.setStationCode(stations.getStationCode());
item.setLon(stations.getLon());
item.setLat(stations.getLat());
item.setStatus(stations.getStatus());
item.setAltitude(Objects.isNull(stations.getElevation())?"--":stations.getElevation()+"m");
item.setScheduling(false);
resultList.add(item);
}
}
}
}
if (CollectionUtils.isNotEmpty(taskStation)) {
//遍历排班任务id
for (String stationId:taskStation) {
//台站map不为空
if (CollectionUtils.isNotEmpty(stationInfoMap)){
if (Objects.nonNull(stationInfoMap.get(stationId))){
SysUserFocusStationStation item = new SysUserFocusStationStation();
//获取台站信息
GardsStations stations = (GardsStations) stationInfoMap.get(stationId);
//获取台站类型
String stationType = stationTypeUtil.getStationType(stations.getStationId());
//将台站信息复制给关注台站实体类
BeanUtils.copyProperties(stations, item);
item.setStationId(stationId);
item.setUserId(userId);
item.setStationType(stationType);
item.setStationCode(stations.getStationCode());
item.setLon(stations.getLon());
item.setLat(stations.getLat());
item.setStatus(stations.getStatus());
item.setAltitude(Objects.isNull(stations.getElevation())?"--":stations.getElevation()+"m");
item.setScheduling(true);
resultList.add(item);
}
}
}
}
List<Integer> removeIndex = new LinkedList<>();
for (int i=0; i<resultList.size(); i++) {
SysUserFocusStationStation nowStation = resultList.get(i);
for (int j=i+1; j<resultList.size(); j++) {
SysUserFocusStationStation compareStation = resultList.get(j);
//如果当前台站与对比台站的台站编码一致
if (nowStation.getStationCode().equals(compareStation.getStationCode())) {
//如果当前台站不是排班任务的台站 对比的台站是排班任务台站 将当前台站的下标记录用于移除处理
if (!nowStation.isScheduling() && compareStation.isScheduling()) {
removeIndex.add(i);
} else {//否则移除对比台站 将对比台站下标记录用于移除处理
removeIndex.add(j);
}
}
}
}
if (CollectionUtils.isNotEmpty(removeIndex)) {
for (int index:removeIndex) {
resultList.remove(index);
}
}
if (CollectionUtils.isNotEmpty(resultList)) {
resultList = resultList.stream().distinct().sorted(Comparator.comparing(SysUserFocusStationStation::getStationCode)).collect(Collectors.toList());
}
return resultList;
}
}