| | |
| | | package com.ycl.task; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.platform.base.CheckIndex; |
| | | import com.ycl.platform.domain.entity.CheckIndexVideo; |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurity; |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurityDetail; |
| | | import com.ycl.platform.mapper.CheckIndexVideoMapper; |
| | | import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper; |
| | | import com.ycl.platform.service.IImageResourceSecurityService; |
| | | import jakarta.annotation.PostConstruct; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.DictUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | private final CheckIndexVideoMapper checkIndexVideoMapper; |
| | | private final ImageResourceSecurityDetailMapper imageResourceSecurityDetailMapper; |
| | | |
| | | @PostConstruct |
| | | /** |
| | | * 每天晚上1点执行 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ?") |
| | | public void calc() { |
| | | ArrayList<ImageResourceSecurity> imageResourceSecurities = new ArrayList<>(); |
| | | List<CheckIndexVideo> list = new LambdaQueryChainWrapper<>(checkIndexVideoMapper) |
| | | .select(CheckIndexVideo::getPlatformOnline, CheckIndexVideo::getMonitorQualification, CheckIndexVideo::getDeptId) |
| | | // .eq(CheckIndex::getCreateTime, LocalDate.now().minusDays(1)) |
| | | .orderByDesc(CheckIndex::getCreateTime) |
| | | .last("limit 7") |
| | | .list(); |
| | | List<CheckIndexVideo> list = checkIndexVideoMapper.selectAndDeptName(); |
| | | List<ImageResourceSecurityDetail> detail = imageResourceSecurityDetailMapper.getList(); |
| | | |
| | | // 每个部门循环一次 |
| | | list.forEach(checkIndexVideo -> { |
| | | // 每个部门循环一次计算数据 |
| | | for (CheckIndexVideo checkIndexVideo : list) { |
| | | ImageResourceSecurity imageResourceSecurity = new ImageResourceSecurity(); |
| | | imageResourceSecurity.setDeptId(checkIndexVideo.getDeptId()); |
| | | // 直接取指标 |
| | |
| | | imageResourceSecurity.setPropertyAccuracy(checkIndexVideo.getMonitorQualification()); |
| | | // 获取当前部门的detail进行计算 |
| | | List<ImageResourceSecurityDetail> detailList = detail.stream().filter(imageResourceSecurityDetail -> Objects.equals(imageResourceSecurityDetail.getDeptId(), checkIndexVideo.getDeptId())).toList(); |
| | | int score = 100; |
| | | int count = 0; |
| | | // 循环detail计算 |
| | | detailList.forEach(imageResourceSecurityDetail -> { |
| | | int score = 100; |
| | | for (ImageResourceSecurityDetail imageResourceSecurityDetail : detailList) { |
| | | // 扣除分数 |
| | | score -= imageResourceSecurityDetail.getAlarmCategory().getScore(); |
| | | imageResourceSecurity.setWeakPassword(BigDecimal.valueOf(score)); |
| | | }); |
| | | // TODO 差一个 |
| | | // 统计数量 |
| | | if (Integer.parseInt(imageResourceSecurityDetail.getAlarmLevel().getValue()) > 1) { |
| | | count++; |
| | | } |
| | | } |
| | | // 获取字典值-总数 |
| | | int onlineAssetsTotal = Integer.parseInt(DictUtils.getDictValue("online_assets_total", checkIndexVideo.getDeptName())); |
| | | imageResourceSecurity.setRiskProperty(BigDecimal.valueOf(count / onlineAssetsTotal)); |
| | | imageResourceSecurity.setCreateTime(DateUtils.getNowDate()); |
| | | imageResourceSecurities.add(imageResourceSecurity); |
| | | }); |
| | | } |
| | | imageResourceSecurityService.saveBatch(imageResourceSecurities); |
| | | |
| | | } |