feat: 增加缓存运维每天设备上图情况

dev
huangfeng 11 months ago
parent d6ded607de
commit 533814fd1a

@ -0,0 +1,19 @@
package com.shxy.xymanager_framework.timeTask;
import com.shxy.xymanager_service.service.NewCacheService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class ClearCacheTask {
@Resource
NewCacheService newCacheService;
@Scheduled(cron = "0 0 3 * * ?")
private void clear() {
newCacheService.clearOneDayStat();
}
}

@ -1,13 +1,17 @@
package com.shxy.xymanager_service.impl;
import com.github.pagehelper.PageHelper;
import com.shxy.xymanager_common.bean.PermissionDetail;
import com.shxy.xymanager_common.entity.*;
import com.shxy.xymanager_common.model.StatTerm;
import com.shxy.xymanager_dao.dao.*;
import com.shxy.xymanager_service.service.NewCacheService;
import com.shxy.xymanager_service.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.HashMap;
@ -28,6 +32,8 @@ public class NewCacheServiceImpl implements NewCacheService {
TowerDao towerDao;
@Resource
TerminalsDao terminalsDao;
@Resource
MntnRawReportsMapper rawReportsMapper;
@Override
@ -217,4 +223,35 @@ public class NewCacheServiceImpl implements NewCacheService {
Terminals terminal = terminalsDao.selectByPrimaryKey(termId);
return terminal;
}
@Override
@Cacheable(value = "cacheStatTerm", key = "#termId + #start")
public StatTerm getOneDayStat(Integer termId, Long start) {
StatTerm stat = null;
Long end = start + 60 * 60 * 24;
MntnRawReportsExample example = new MntnRawReportsExample();
MntnRawReportsExample.Criteria criteria = example.createCriteria();
criteria.andTermIdEqualTo(termId);
criteria.andCreateTimeGreaterThanOrEqualTo(start);
criteria.andCreateTimeLessThan(end);
example.setOrderByClause("create_time desc");
PageHelper.startPage(1, 1);
List<MntnRawReports> reportsList = rawReportsMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(reportsList)) {
MntnRawReports reports = reportsList.get(0);
reports.makeRawReport();
stat = new StatTerm();
stat.setTermId(termId);
stat.setUploads(reports.getReportMap().get("uploads"));
}
return stat;
}
@Override
@CacheEvict(cacheNames = {"cacheStatTerm"}, allEntries = true)
public void clearOneDayStat() {
}
}

@ -300,17 +300,22 @@ public class TerminalExtServiceImpl implements TerminalExtService {
return stat;
}
private void statOneDay(StatDay item, List<View_Dy_Line_Tower_Terminals> list) {
private void statOneDay(StatDay item, List<View_Dy_Line_Tower_Terminals> list) throws Exception {
long today = DateUtil.getTodayZero().getTime() / 1000;
for (View_Dy_Line_Tower_Terminals term : list) {
long start = item.getDay().getTime() / 1000;
Date end = DateUtil.addDay(item.getDay(), 1);
long max = end.getTime() / 1000;
Long start = item.getDay().getTime() / 1000;
if (start < today) {
StatTerm statTerm = newCacheService.getOneDayStat(term.getId(), start);
if (statTerm != null) {
item.getTermList().add(statTerm);
}
} else {
Long end = start + 60 * 60 * 24;
MntnRawReportsExample example = new MntnRawReportsExample();
MntnRawReportsExample.Criteria criteria = example.createCriteria();
criteria.andTermIdEqualTo(term.getId());
criteria.andCreateTimeGreaterThanOrEqualTo(start);
criteria.andCreateTimeLessThan(max);
criteria.andCreateTimeLessThan(end);
example.setOrderByClause("create_time desc");
PageHelper.startPage(1, 1);
List<MntnRawReports> reportsList = rawReportsMapper.selectByExample(example);
@ -325,4 +330,5 @@ public class TerminalExtServiceImpl implements TerminalExtService {
}
}
}
}
}

@ -6,6 +6,7 @@ import com.shxy.xymanager_common.entity.DyLevel;
import com.shxy.xymanager_common.entity.Lines;
import com.shxy.xymanager_common.entity.Terminals;
import com.shxy.xymanager_common.entity.Towers;
import com.shxy.xymanager_common.model.StatTerm;
import java.util.List;
@ -22,4 +23,8 @@ public interface NewCacheService {
Towers getTower(Integer towerId);
Terminals getTerminal(Integer termId);
StatTerm getOneDayStat(Integer termId, Long start);
void clearOneDayStat();
}

Loading…
Cancel
Save