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 lombok.RequiredArgsConstructor; 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; @PostConstruct public void calc() { ArrayList imageResourceSecurities = new ArrayList<>(); List 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 detail = imageResourceSecurityDetailMapper.getList(); // 每个部门循环一次 list.forEach(checkIndexVideo -> { ImageResourceSecurity imageResourceSecurity = new ImageResourceSecurity(); imageResourceSecurity.setDeptId(checkIndexVideo.getDeptId()); // 直接取指标 imageResourceSecurity.setPlatformOnline(checkIndexVideo.getPlatformOnline()); imageResourceSecurity.setPropertyAccuracy(checkIndexVideo.getMonitorQualification()); // 获取当前部门的detail进行计算 List detailList = detail.stream().filter(imageResourceSecurityDetail -> Objects.equals(imageResourceSecurityDetail.getDeptId(), checkIndexVideo.getDeptId())).toList(); // 循环detail计算 detailList.forEach(imageResourceSecurityDetail -> { int score = 100; score -= imageResourceSecurityDetail.getAlarmCategory().getScore(); imageResourceSecurity.setWeakPassword(BigDecimal.valueOf(score)); }); // TODO 差一个 imageResourceSecurities.add(imageResourceSecurity); }); imageResourceSecurityService.saveBatch(imageResourceSecurities); } }