台站运行管理模块新增加删除用户临时缓存数据接口
台站运行管理模块保存用户关注台站及缓存数据接口修改,缓存时间等数据内容改为临时缓存不再存库 台站运行管理模块查询台站监测数据弹窗增加字段传递缓存时间 台站运行管理模块关注台站实现类新增方法查询用户关注台站及用户排班任务台站信息并去重过滤 台站运行管理模块查询关注台站接口,增加标识区分台站是否是排班任务台站 自动处理程序undeal处理文件数量限制取消,查询undeal所有文件并进行及时处理 自动处理程序查询指定路径文件方法增加去掉数量限制参数
This commit is contained in:
parent
fe755c83ee
commit
1a12d82ba6
|
@ -69,7 +69,7 @@ public class UndealHandleManager{
|
||||||
//ftp解析失败文件存储路径
|
//ftp解析失败文件存储路径
|
||||||
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
|
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
|
||||||
final String filePath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath();
|
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)){
|
if(!CollectionUtils.isEmpty(spectrumFiles)){
|
||||||
CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size());
|
CountDownLatch taskLatch = new CountDownLatch(spectrumFiles.size());
|
||||||
for(File spectrumFile : spectrumFiles){
|
for(File spectrumFile : spectrumFiles){
|
||||||
|
|
|
@ -69,6 +69,50 @@ public class FileOperation {
|
||||||
return sortList.stream().limit(num).collect(Collectors.toList());
|
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
|
* @param filePath
|
||||||
|
|
|
@ -60,8 +60,8 @@ public class StationOperationController {
|
||||||
|
|
||||||
@GetMapping("getDataReceivingStatus")
|
@GetMapping("getDataReceivingStatus")
|
||||||
@ApiOperation(value = "查询台站监测数据信息", notes = "查询台站监测数据信息")
|
@ApiOperation(value = "查询台站监测数据信息", notes = "查询台站监测数据信息")
|
||||||
public Result getDataReceivingStatus(String userId, String oneStationId){
|
public Result getDataReceivingStatus(String userId, Double cacheTime, String oneStationId){
|
||||||
return stationOperationService.getDataReceivingStatus(userId, oneStationId);
|
return stationOperationService.getDataReceivingStatus(userId, cacheTime, oneStationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,12 @@ public class SysUserFocusStationController {
|
||||||
return sysUserFocusStationService.deleteById(stationId);
|
return sysUserFocusStationService.deleteById(stationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("deleteUserCache")
|
||||||
|
@ApiOperation(value = "删除用户的临时缓存", notes = "删除用户的临时缓存")
|
||||||
|
public Result deleteUserCache(String userId) {
|
||||||
|
return sysUserFocusStationService.deleteUserCache(userId);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("findUserFocusByUserId")
|
@GetMapping("findUserFocusByUserId")
|
||||||
@ApiOperation(value = "根据用户id查询用户的缓存配置信息及关注台站信息", notes = "根据用户id查询用户的缓存配置信息及关注台站信息")
|
@ApiOperation(value = "根据用户id查询用户的缓存配置信息及关注台站信息", notes = "根据用户id查询用户的缓存配置信息及关注台站信息")
|
||||||
public Result findUserFocusByUserId(String userId){
|
public Result findUserFocusByUserId(String userId){
|
||||||
|
|
|
@ -39,4 +39,10 @@ public class SysUserFocusStationStation extends SysUserFocusStation {
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String stationCode;
|
private String stationCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是排班任务台站
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private boolean isScheduling;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -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>
|
|
@ -49,7 +49,7 @@ public interface IStationOperationService extends IService<StationOperation> {
|
||||||
* @param oneStationId
|
* @param oneStationId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Result getDataReceivingStatus(String userId, String oneStationId);
|
Result getDataReceivingStatus(String userId, Double cacheTime, String oneStationId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取台站数据的提供率及有效率
|
* 获取台站数据的提供率及有效率
|
||||||
|
|
|
@ -27,6 +27,13 @@ public interface ISysUserFocusStationService extends IService<SysUserFocusStatio
|
||||||
*/
|
*/
|
||||||
Result deleteById(String stationId);
|
Result deleteById(String stationId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户的临时缓存记录
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Result deleteUserCache(String userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户id查询对应的缓存配置信息
|
* 根据用户id查询对应的缓存配置信息
|
||||||
* @param userId
|
* @param userId
|
||||||
|
|
|
@ -48,11 +48,14 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ICacheTimeService cacheTimeService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SysUserFocusStationMapper sysUserFocusStationMapper;
|
private SysUserFocusStationMapper sysUserFocusStationMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private StationReceivingConfigMapper stationReceivingConfigMapper;
|
private SysTaskStationMapper taskStationMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StationTypeUtil stationTypeUtil;
|
private StationTypeUtil stationTypeUtil;
|
||||||
|
@ -387,13 +390,18 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result getDataReceivingStatus(String userId, String oneStationId) {
|
public Result getDataReceivingStatus(String userId, Double cacheTime, String oneStationId) {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
Map<String, StationData> stationDataMap = (Map<String, StationData>) redisUtil.get("stationDataMap");
|
Map<String, StationData> stationDataMap = (Map<String, StationData>) redisUtil.get("stationDataMap");
|
||||||
LambdaQueryWrapper<StationReceivingConfigStation> queryWrapper = new LambdaQueryWrapper<>();
|
//调用接口获取数据库中对应缓存配置信息默认值
|
||||||
queryWrapper.eq(StationReceivingConfig::getUserId, userId);
|
if (Objects.isNull(cacheTime) || cacheTime <= 0) {
|
||||||
StationReceivingConfigStation configStation = stationReceivingConfigMapper.selectOne(queryWrapper);
|
List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
|
||||||
Double cacheTime = configStation.getCacheTime();
|
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();
|
LocalDateTime endDate = LocalDateTime.now();
|
||||||
//根据缓存日期 得到开始查询时间
|
//根据缓存日期 得到开始查询时间
|
||||||
|
@ -421,33 +429,45 @@ public class StationOperationServiceImpl extends ServiceImpl<StationOperationMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stationDataList.add(stationData);
|
||||||
}
|
}
|
||||||
stationDataList.add(stationData);
|
|
||||||
} else {
|
} else {
|
||||||
|
List<String> stationIds = new LinkedList<>();
|
||||||
//根据用户id查询出当前用户关注的台站信息
|
//根据用户id查询出当前用户关注的台站信息
|
||||||
LambdaQueryWrapper<SysUserFocusStationStation> userFocusStationQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysUserFocusStationStation> userFocusStationQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
|
userFocusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
|
||||||
List<SysUserFocusStationStation> userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper);
|
List<SysUserFocusStationStation> userFocusStations = sysUserFocusStationMapper.selectList(userFocusStationQueryWrapper);
|
||||||
List<String> stationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList());
|
if (CollectionUtils.isNotEmpty(userFocusStations)) {
|
||||||
for (String stationId:stationIds) {
|
List<String> focusStationIds = userFocusStations.stream().map(SysUserFocusStation::getStationId).collect(Collectors.toList());
|
||||||
StationData stationData = stationDataMap.get(stationId);
|
stationIds.addAll(focusStationIds);
|
||||||
if (Objects.nonNull(stationData)) {
|
}
|
||||||
//读取探测器的数据集合
|
String nowDate = DateUtils.now();
|
||||||
Map<String, List<Map<String, DetectorData>>> detectors = stationData.getDetectors();
|
List<String> taskStationIds = taskStationMapper.findTaskStation(userId, nowDate);
|
||||||
//遍历探测器的集合
|
if (CollectionUtils.isNotEmpty(taskStationIds)) {
|
||||||
for (Map.Entry<String, List<Map<String, DetectorData>>> detector:detectors.entrySet()) {
|
stationIds.addAll(taskStationIds);
|
||||||
//获取探测器对应的数组
|
}
|
||||||
List<Map<String, DetectorData>> detectorValue = detector.getValue();
|
stationIds = stationIds.stream().distinct().collect(Collectors.toList());
|
||||||
//遍历探测器数组
|
if (CollectionUtils.isNotEmpty(stationIds)) {
|
||||||
for (Map<String, DetectorData> detectorDataMap:detectorValue) {
|
for (String stationId:stationIds) {
|
||||||
for (String key :detectorDataMap.keySet()) {
|
StationData stationData = stationDataMap.get(stationId);
|
||||||
DetectorData detectorData = detectorDataMap.get(key);
|
if (Objects.nonNull(stationData)) {
|
||||||
//通过流过滤出数据的开始时间戳在用户统计的开始时间戳之后的数据
|
//读取探测器的数据集合
|
||||||
detectorData.getDataList().stream().filter(item -> item.getBeginTime() >= startMill).collect(Collectors.toList());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stationDataList.add(stationData);
|
||||||
}
|
}
|
||||||
stationDataList.add(stationData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.jeecg.common.CacheName;
|
import org.jeecg.common.CacheName;
|
||||||
import org.jeecg.common.StationTypeUtil;
|
import org.jeecg.common.StationTypeUtil;
|
||||||
import org.jeecg.common.api.vo.Result;
|
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.system.util.JwtUtil;
|
||||||
|
import org.jeecg.common.util.DateUtils;
|
||||||
import org.jeecg.common.util.RedisUtil;
|
import org.jeecg.common.util.RedisUtil;
|
||||||
import org.jeecg.common.util.SpringContextUtils;
|
import org.jeecg.common.util.SpringContextUtils;
|
||||||
import org.jeecg.modules.base.entity.configuration.GardsStations;
|
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.SysUserFocusStationStation;
|
||||||
import org.jeecg.modules.entity.data.UserFocusStation;
|
import org.jeecg.modules.entity.data.UserFocusStation;
|
||||||
import org.jeecg.modules.mapper.StationReceivingConfigMapper;
|
import org.jeecg.modules.mapper.StationReceivingConfigMapper;
|
||||||
|
import org.jeecg.modules.mapper.SysTaskStationMapper;
|
||||||
import org.jeecg.modules.mapper.SysUserFocusStationMapper;
|
import org.jeecg.modules.mapper.SysUserFocusStationMapper;
|
||||||
import org.jeecg.modules.service.ICacheTimeService;
|
import org.jeecg.modules.service.ICacheTimeService;
|
||||||
import org.jeecg.modules.service.ISysUserFocusStationService;
|
import org.jeecg.modules.service.ISysUserFocusStationService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -30,6 +34,8 @@ import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||||
|
|
||||||
@Service("sysUserFocusStationService")
|
@Service("sysUserFocusStationService")
|
||||||
public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStationMapper, SysUserFocusStationStation> implements ISysUserFocusStationService {
|
public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStationMapper, SysUserFocusStationStation> implements ISysUserFocusStationService {
|
||||||
|
|
||||||
|
@ -38,7 +44,7 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICacheTimeService cacheTimeService;
|
private ICacheTimeService cacheTimeService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private StationReceivingConfigMapper stationReceivingConfigMapper;
|
private SysTaskStationMapper taskStationMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private StationTypeUtil stationTypeUtil;
|
private StationTypeUtil stationTypeUtil;
|
||||||
|
|
||||||
|
@ -50,29 +56,9 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
String username = JwtUtil.getUserNameByToken(request);
|
String username = JwtUtil.getUserNameByToken(request);
|
||||||
//根据用户名称查询对应的用户信息
|
//根据用户名称查询对应的用户信息
|
||||||
SysUser sysUser = cacheTimeService.findUserByName(username);
|
SysUser sysUser = cacheTimeService.findUserByName(username);
|
||||||
//查询全部台站信息
|
//调用公用方法查询关注台站信息
|
||||||
HashMap<String, Object> stationInfoMap = (HashMap<String, Object>) redisUtil.get("stationInfoMap");
|
List<SysUserFocusStationStation> resultList = findUserFocusStations(sysUser.getId());
|
||||||
LambdaQueryWrapper<SysUserFocusStationStation> queryWrapper = new LambdaQueryWrapper<>();
|
return resultList;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,28 +77,22 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
}
|
}
|
||||||
//判断传递参数信息是否为空
|
//判断传递参数信息是否为空
|
||||||
if (Objects.nonNull(userFocusStation)){
|
if (Objects.nonNull(userFocusStation)){
|
||||||
//通过用户id判断是否存在用户的缓存配置信息
|
//判断是否包含最大缓存时间
|
||||||
LambdaQueryWrapper<StationReceivingConfigStation> receivingConfigQueryWrapper = new LambdaQueryWrapper<>();
|
if (redisUtil.hasKey("maxCacheTime")) {
|
||||||
receivingConfigQueryWrapper.eq(StationReceivingConfigStation::getUserId, sysUser.getId());
|
//最大的缓存时间
|
||||||
StationReceivingConfigStation receivingConfig = stationReceivingConfigMapper.selectOne(receivingConfigQueryWrapper);
|
String maxCacheTime = (String) redisUtil.get("maxCacheTime");
|
||||||
//如果没有对应的用户缓存信息 则进行新增
|
//用户临时记录的缓存时间
|
||||||
if (Objects.isNull(receivingConfig)){
|
Double cacheTime = userFocusStation.getCacheTime();
|
||||||
receivingConfig = new StationReceivingConfigStation();
|
//如果用户临时记录的缓存时间大于最大缓存时间
|
||||||
Long id = IdWorker.getId();
|
if (cacheTime > Double.valueOf(maxCacheTime)) {
|
||||||
receivingConfig.setId(id.toString());
|
redisUtil.set("maxCacheTime", String.valueOf(cacheTime));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
//记录当前用户的临时数据
|
||||||
|
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())){
|
if (CollectionUtils.isNotEmpty(userFocusStation.getStationIds())){
|
||||||
//根据用户id查询出对应的用户关注台站信息 删除用户的所有关注台站信息并重新保存
|
//根据用户id查询出对应的用户关注台站信息 删除用户的所有关注台站信息并重新保存
|
||||||
|
@ -135,9 +115,12 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
if (focusStationStationList.size()>0) {
|
if (focusStationStationList.size()>0) {
|
||||||
this.saveBatch(focusStationStationList);
|
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");
|
result.success("Save successfully");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -164,16 +147,28 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result deleteUserCache(String userId) {
|
||||||
|
redisUtil.del("cacheTime:"+userId, "scaleInterval:"+userId, "timelineLength:"+userId, "updateIntervalTime:"+userId);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result findUserFocusByUserId(String userId) {
|
public Result findUserFocusByUserId(String userId) {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
//根据用户id查询存储的缓存配置信息
|
|
||||||
LambdaQueryWrapper<StationReceivingConfigStation> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(StationReceivingConfigStation::getUserId, userId);
|
|
||||||
StationReceivingConfigStation receivingConfig = stationReceivingConfigMapper.selectOne(queryWrapper);
|
|
||||||
//如果用户对应的缓存配置信息为空时,查询字典表中的默认值
|
//如果用户对应的缓存配置信息为空时,查询字典表中的默认值
|
||||||
if (Objects.isNull(receivingConfig)){
|
StationReceivingConfigStation receivingConfig = new 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();
|
List<Map<String, String>> cacheList = cacheTimeService.findCacheTime();
|
||||||
for (int i=0; i< cacheList.size(); i++){
|
for (int i=0; i< cacheList.size(); i++){
|
||||||
|
@ -196,10 +191,10 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
LambdaQueryWrapper<SysUserFocusStationStation> focusStationQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysUserFocusStationStation> focusStationQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
focusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
|
focusStationQueryWrapper.eq(SysUserFocusStationStation::getUserId, userId);
|
||||||
List<SysUserFocusStationStation> sysUserFocusStations = this.baseMapper.selectList(focusStationQueryWrapper);
|
List<SysUserFocusStationStation> sysUserFocusStations = this.baseMapper.selectList(focusStationQueryWrapper);
|
||||||
if (Objects.nonNull(sysUserFocusStations)){
|
if (CollectionUtils.isNotEmpty(sysUserFocusStations)){
|
||||||
receivingConfig.setSysUserFocusStations(sysUserFocusStations);
|
receivingConfig.setSysUserFocusStations(sysUserFocusStations);
|
||||||
} else {
|
} else {
|
||||||
receivingConfig.setSysUserFocusStations(new ArrayList<>());
|
receivingConfig.setSysUserFocusStations(Collections.emptyList());
|
||||||
}
|
}
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
result.setResult(receivingConfig);
|
result.setResult(receivingConfig);
|
||||||
|
@ -208,9 +203,110 @@ public class SysUserFocusStationServiceImpl extends ServiceImpl<SysUserFocusStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cacheStationReceivingConfig() {
|
public void cacheStationReceivingConfig() {
|
||||||
//查询用户名以及用户名关联的缓存设置
|
String maxCacheTime = "30";
|
||||||
String maxCacheTime = stationReceivingConfigMapper.findMaxCacheTime();
|
redisUtil.del("cacheTime", "scaleInterval", "timelineLength", "updateIntervalTime");
|
||||||
redisUtil.set("maxCacheTime", maxCacheTime);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user