package com.ycl.calculate; import com.ycl.platform.domain.entity.CheckIndexVideo; import com.ycl.platform.domain.result.UY.QueryVqdResult; import com.ycl.platform.domain.vo.PlatformOnlineVO; import com.ycl.platform.mapper.CheckIndexVideoMapper; import com.ycl.platform.service.ICheckIndexVideoService; import com.ycl.system.mapper.SysDeptMapper; import constant.ApiConstants; import constant.CheckConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import utils.DateUtils; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 平台在线率计算 * 离线时长每超过30分钟扣百分之十 * 不区分区域 */ @Component @Slf4j public class PlatformOnlineCalculation extends IndexCalculationServe implements CalculationStrategy { @Autowired private SysDeptMapper deptMapper; @Autowired private CheckIndexVideoMapper videoMapper; @Autowired private ICheckIndexVideoService checkIndexVideoService; @Override public void calculate(List list) { if (!CollectionUtils.isEmpty(list)) { //总离线时长 int time = list.stream().map(PlatformOnlineVO::getTodayOutlineSed).reduce(0, Integer::sum); //离线时长转换位分钟然后取模 int num = (time / 60) % 30; double score = Math.max(1 - num * 0.1, 0); //是否已经存在当日数据 List checkIndexVideos = videoMapper.selectToday(DateUtils.getDate()); //所有区域部门 List deptIds = deptMapper.selectByParentId(207L); List keys = new ArrayList<>(); //准备区分省厅、区域的deptId list for (Long deptId : deptIds) { keys.add(deptId + ""); keys.add(ApiConstants.Province + deptId); } List videos = new ArrayList<>(); keys.forEach(key -> { //如果不存在就新增如果存在则复用 CheckIndexVideo checkIndex = getCheckIndex(key, checkIndexVideos, CheckIndexVideo.class); if (checkIndex != null) { checkIndex.setPlatformOnline(new BigDecimal(score)); videos.add(checkIndex); } }); checkIndexVideoService.saveOrUpdateBatch(videos); }else { log.info("数据为空"); } } }