二次版本提交
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.njcn.gather.event.devcie.job;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.gather.event.devcie.mapper.PqLineMapper;
|
||||
import com.njcn.gather.event.devcie.pojo.po.PqLine;
|
||||
import com.njcn.gather.event.devcie.pojo.po.PqsDeptsline;
|
||||
import com.njcn.gather.event.devcie.service.PqsDeptslineService;
|
||||
import com.njcn.gather.event.transientes.pojo.po.PqsDepts;
|
||||
import com.njcn.gather.event.transientes.service.PqsDeptsService;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2025/08/05 上午 10:17【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class LineCacheJob {
|
||||
@Autowired
|
||||
private PqLineMapper pqLineMapper;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private PqsDeptslineService pqsDeptslineService;
|
||||
@Autowired
|
||||
|
||||
private PqsDeptsService pqsDeptsService;
|
||||
private final static String NAME_KEY = "LineCache:";
|
||||
@Value("${SYS_TYPE_ZT}")
|
||||
private String sysTypeZt;
|
||||
@Scheduled(cron="0 0 1 * * ?" ) // 每3钟执行一次
|
||||
public void lineCache(){
|
||||
redisUtil.deleteKeysByString(NAME_KEY);
|
||||
|
||||
List<PqLine> pqLines = pqLineMapper.selectList(null);
|
||||
redisUtil.saveByKey(NAME_KEY + StrUtil.DASHED+"pqLineList",pqLines);
|
||||
List<PqsDepts> list = pqsDeptsService.lambdaQuery().eq(PqsDepts::getState, 1).list();
|
||||
for (PqsDepts pqsDepts : list) {
|
||||
List<String> deptAndChildren = pqsDeptsService.findDeptAndChildren(pqsDepts.getDeptsIndex());
|
||||
List<PqsDeptsline> deptslines = pqsDeptslineService.lambdaQuery().in(PqsDeptsline::getDeptsIndex, deptAndChildren).eq(PqsDeptsline::getSystype, sysTypeZt).list();
|
||||
List<Integer> deptslineIds = deptslines.stream().map(PqsDeptsline::getLineIndex).collect(Collectors.toList());
|
||||
redisUtil.saveByKey(NAME_KEY + StrUtil.DASHED+pqsDepts.getDeptsIndex(),deptslineIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,14 @@ package com.njcn.gather.event.transientes.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.gather.event.devcie.mapper.PqDeviceMapper;
|
||||
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
||||
import com.njcn.gather.event.devcie.pojo.dto.LedgerBaseInfoDTO;
|
||||
import com.njcn.gather.event.devcie.pojo.po.PqDevice;
|
||||
import com.njcn.gather.event.devcie.pojo.po.PqLine;
|
||||
import com.njcn.gather.event.devcie.service.PqLineService;
|
||||
import com.njcn.gather.event.transientes.mapper.PqUserLedgerMapper;
|
||||
@@ -16,10 +18,7 @@ import com.njcn.gather.event.transientes.mapper.PqUserLineAssMapper;
|
||||
import com.njcn.gather.event.transientes.mapper.PqsDicTreeMapper;
|
||||
import com.njcn.gather.event.transientes.pojo.DicTreeEnum;
|
||||
import com.njcn.gather.event.transientes.pojo.param.LargeScreenCountParam;
|
||||
import com.njcn.gather.event.transientes.pojo.po.PqUserLedgerPO;
|
||||
import com.njcn.gather.event.transientes.pojo.po.PqUserLineAssPO;
|
||||
import com.njcn.gather.event.transientes.pojo.po.PqsDicTreePO;
|
||||
import com.njcn.gather.event.transientes.pojo.po.PqsEventdetail;
|
||||
import com.njcn.gather.event.transientes.pojo.po.*;
|
||||
import com.njcn.gather.event.transientes.pojo.vo.EventDetailVO;
|
||||
import com.njcn.gather.event.transientes.pojo.vo.LedgerCountVO;
|
||||
import com.njcn.gather.event.transientes.pojo.vo.UserLedgerStatisticVO;
|
||||
@@ -29,7 +28,11 @@ import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -59,6 +62,8 @@ public class EventRightServiceImpl implements EventRightService {
|
||||
private final CommGeneralService commGeneralService;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
private final PqsOnlinerateService pqsOnlinerateService;
|
||||
|
||||
|
||||
private final static String NAME_KEY = "LineCache:";
|
||||
private final PqDeviceMapper pqDeviceMapper;
|
||||
@@ -256,6 +261,8 @@ public class EventRightServiceImpl implements EventRightService {
|
||||
|
||||
@Override
|
||||
public Page<DeviceDTO> rightEventDevOpen(LargeScreenCountParam param) {
|
||||
LocalDateTime startTime = param.getStartTime().atStartOfDay();
|
||||
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(param.getEndTime().atStartOfDay());
|
||||
Page<DeviceDTO> result = new Page<>(PageFactory.getPageNum(param),PageFactory.getPageSize(param));
|
||||
List<Integer> lineIds = commGeneralService.getLineIdsByRedis(param.getDeptId());
|
||||
|
||||
@@ -293,6 +300,22 @@ public class EventRightServiceImpl implements EventRightService {
|
||||
result = pqDeviceMapper.queryListByLineIds(new Page<DeviceDTO>(PageFactory.getPageNum(param),PageFactory.getPageSize(param)),param.getSearchValue(),lineAssIds);
|
||||
|
||||
}
|
||||
List<Integer> devList = result.getRecords().stream().map(DeviceDTO::getDevId).collect(Collectors.toList());
|
||||
|
||||
List<PqsOnlinerate> list = pqsOnlinerateService.lambdaQuery().in(PqsOnlinerate::getDevIndex,devList).between(PqsOnlinerate::getTimeid, startTime, endTime).list();
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
for (DeviceDTO record : result.getRecords()) {
|
||||
List<PqsOnlinerate> tempList = list.stream().filter(temp -> Objects.equals(temp.getDevIndex(), record.getDevId())).collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(tempList)){
|
||||
double asDouble = tempList.stream().mapToDouble(temp -> {
|
||||
return Double.valueOf(temp.getOnlinemin()*100) / (temp.getOfflinemin() + temp.getOnlinemin());
|
||||
}).average().getAsDouble();
|
||||
record.setOnLineRate(new BigDecimal(asDouble).setScale(2, RoundingMode.UP).doubleValue());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user