New file |
| | |
| | | package com.ycl.task; |
| | | |
| | | 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 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; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/8/26 下午 4:43 |
| | | */ |
| | | @Component("ImageResourceSecurityTask") |
| | | @RequiredArgsConstructor |
| | | public class ImageResourceSecurityTask { |
| | | |
| | | private final IImageResourceSecurityService imageResourceSecurityService; |
| | | private final CheckIndexVideoMapper checkIndexVideoMapper; |
| | | private final ImageResourceSecurityDetailMapper imageResourceSecurityDetailMapper; |
| | | |
| | | /** |
| | | * 每天晚上1点执行 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ?") |
| | | public void calc() { |
| | | ArrayList<ImageResourceSecurity> imageResourceSecurities = new ArrayList<>(); |
| | | List<CheckIndexVideo> list = checkIndexVideoMapper.selectAndDeptName(); |
| | | List<ImageResourceSecurityDetail> detail = imageResourceSecurityDetailMapper.getList(); |
| | | |
| | | // 每个部门循环一次计算数据 |
| | | for (CheckIndexVideo checkIndexVideo : list) { |
| | | ImageResourceSecurity imageResourceSecurity = new ImageResourceSecurity(); |
| | | imageResourceSecurity.setDeptId(checkIndexVideo.getDeptId()); |
| | | // 直接取指标 |
| | | imageResourceSecurity.setPlatformOnline(checkIndexVideo.getPlatformOnline()); |
| | | 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计算 |
| | | for (ImageResourceSecurityDetail imageResourceSecurityDetail : detailList) { |
| | | // 扣除分数 |
| | | score -= imageResourceSecurityDetail.getAlarmCategory().getScore(); |
| | | imageResourceSecurity.setWeakPassword(BigDecimal.valueOf(score)); |
| | | // 统计数量 |
| | | 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); |
| | | |
| | | } |
| | | |
| | | } |