fuliqi
2024-09-24 8f83a63bc5f046e34a1a06bcf6f1a8241c7277ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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;
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 IndexCalculationUtils implements CalculationStrategy<PlatformOnlineVO> {
    @Autowired
    private SysDeptMapper deptMapper;
    @Autowired
    private CheckIndexVideoMapper videoMapper;
    @Autowired
    private ICheckIndexVideoService checkIndexVideoService;
 
    @Override
    public void calculate(List<PlatformOnlineVO> list) {
        Map<String,Double> map = new HashMap<>();
        if (!CollectionUtils.isEmpty(list)) {
            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<CheckIndexVideo> videos = new ArrayList<>();
            map.forEach((key,score) -> {
                //如果不存在就新增如果存在则复用
                CheckIndexVideo checkIndex = getCheckIndex(key, checkIndexVideos, CheckIndexVideo.class);
                if (checkIndex != null) {
                    checkIndex.setPlatformOnline(new BigDecimal(score));
                    videos.add(checkIndex);
                }
            });
            checkIndexVideoService.saveOrUpdateBatch(videos);
        }else {
            log.info("数据为空");
        }
    }
 
}