| | |
| | | package com.ycl.calculate; |
| | | |
| | | import com.fasterxml.jackson.databind.ser.Serializers; |
| | | import com.ycl.platform.domain.entity.CheckIndexVideo; |
| | | import com.ycl.platform.domain.result.BaseResult; |
| | | import com.ycl.platform.domain.result.UY.QueryVqdResult; |
| | | import com.ycl.platform.domain.result.UY.VideoOnlineResult; |
| | | 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 enumeration.general.AreaDeptEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | * 不区分区域 |
| | | */ |
| | | @Component |
| | | public class PlatformOnlineCalculation extends IndexCalculationServe implements CalculationStrategy<PlatformOnlineVO> { |
| | | @Slf4j |
| | | public class PlatformOnlineCalculation extends IndexCalculationUtils implements CalculationStrategy<PlatformOnlineVO> { |
| | | @Autowired |
| | | private SysDeptMapper deptMapper; |
| | | @Autowired |
| | |
| | | |
| | | @Override |
| | | public void calculate(List<PlatformOnlineVO> list) { |
| | | //list 对象是查询 t_platform_online 昨天时段的集合对象 |
| | | Map<String,Double> map = new HashMap<>(); |
| | | 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); |
| | | for (PlatformOnlineVO platformOnlineVO : list) { |
| | | String[] areas = platformOnlineVO.getArea().split(","); |
| | | for (String area : areas) { |
| | | Integer deptId = AreaDeptEnum.fromCode(area).getDeptId(); |
| | | //离线时长 |
| | | Integer time = platformOnlineVO.getTodayOutlineSed(); |
| | | //离线时长转换为分钟 |
| | | int num = (time / 60) / 30; |
| | | double score = Math.max(1 - num * 0.1, 0); |
| | | map.put(deptId+"",score); |
| | | map.put(ApiConstants.Province + deptId,score); |
| | | map.put(ApiConstants.Dept + deptId,score); |
| | | } |
| | | } |
| | | |
| | | //是否已经存在当日数据 |
| | | List<CheckIndexVideo> checkIndexVideos = videoMapper.selectToday(DateUtils.getDate()); |
| | | //所有区域部门 |
| | | List<Long> deptIds = deptMapper.selectByParentId(207L); |
| | | List<String> keys = new ArrayList<>(); |
| | | //准备区分省厅、区域的deptId list |
| | | for (Long deptId : deptIds) { |
| | | keys.add(deptId + ""); |
| | | keys.add(ApiConstants.Province + deptId); |
| | | } |
| | | |
| | | List<CheckIndexVideo> videos = new ArrayList<>(); |
| | | keys.forEach(key -> { |
| | | map.forEach((key,score) -> { |
| | | //如果不存在就新增如果存在则复用 |
| | | CheckIndexVideo checkIndex = getCheckIndex(key, checkIndexVideos, CheckIndexVideo.class); |
| | | if (checkIndex != null) { |
| | |
| | | videos.add(checkIndex); |
| | | } |
| | | }); |
| | | |
| | | checkIndexVideoService.saveOrUpdateBatch(videos); |
| | | }else { |
| | | log.info("数据为空"); |
| | | } |
| | | } |
| | | |
| | | } |