New file |
| | |
| | | package enumeration.converter; |
| | | |
| | | import com.alibaba.excel.converters.Converter; |
| | | import com.alibaba.excel.enums.CellDataTypeEnum; |
| | | import com.alibaba.excel.metadata.GlobalConfiguration; |
| | | import com.alibaba.excel.metadata.data.ReadCellData; |
| | | import com.alibaba.excel.metadata.data.WriteCellData; |
| | | import com.alibaba.excel.metadata.property.ExcelContentProperty; |
| | | import enumeration.general.AlarmCategoryEnum; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/8/26 下午 4:00 |
| | | */ |
| | | public class AlarmCategoryConverter implements Converter<AlarmCategoryEnum> { |
| | | |
| | | @Override |
| | | public Class<?> supportJavaTypeKey() { |
| | | return Converter.super.supportJavaTypeKey(); |
| | | } |
| | | |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return Converter.super.supportExcelTypeKey(); |
| | | } |
| | | |
| | | @Override |
| | | public AlarmCategoryEnum convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | String value = cellData.getStringValue(); |
| | | if (AlarmCategoryEnum.SSH.getDesc().equals(value)) { |
| | | return AlarmCategoryEnum.SSH; |
| | | } |
| | | if (AlarmCategoryEnum.TELNET.getDesc().equals(value)) { |
| | | return AlarmCategoryEnum.TELNET; |
| | | } |
| | | if (AlarmCategoryEnum.RDP.getDesc().equals(value)) { |
| | | return AlarmCategoryEnum.RDP; |
| | | } |
| | | if (AlarmCategoryEnum.FTP.getDesc().equals(value)) { |
| | | return AlarmCategoryEnum.FTP; |
| | | } |
| | | if (AlarmCategoryEnum.DATABASE.getDesc().equals(value)) { |
| | | return AlarmCategoryEnum.DATABASE; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public WriteCellData<AlarmCategoryEnum> convertToExcelData(AlarmCategoryEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | return new WriteCellData<>(value.getDesc()); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package enumeration.converter; |
| | | |
| | | import com.alibaba.excel.converters.Converter; |
| | | import com.alibaba.excel.enums.CellDataTypeEnum; |
| | | import com.alibaba.excel.metadata.GlobalConfiguration; |
| | | import com.alibaba.excel.metadata.data.ReadCellData; |
| | | import com.alibaba.excel.metadata.data.WriteCellData; |
| | | import com.alibaba.excel.metadata.property.ExcelContentProperty; |
| | | import enumeration.general.AlarmLevelEnum; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/8/26 下午 4:00 |
| | | */ |
| | | public class AlarmLevelConverter implements Converter<AlarmLevelEnum> { |
| | | |
| | | @Override |
| | | public Class<?> supportJavaTypeKey() { |
| | | return Converter.super.supportJavaTypeKey(); |
| | | } |
| | | |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return Converter.super.supportExcelTypeKey(); |
| | | } |
| | | |
| | | @Override |
| | | public AlarmLevelEnum convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | String value = cellData.getStringValue(); |
| | | if (AlarmLevelEnum.LOW.getDesc().equals(value)) { |
| | | return AlarmLevelEnum.LOW; |
| | | } |
| | | if (AlarmLevelEnum.MIDDLE.getDesc().equals(value)) { |
| | | return AlarmLevelEnum.MIDDLE; |
| | | } |
| | | if (AlarmLevelEnum.HIGH.getDesc().equals(value)) { |
| | | return AlarmLevelEnum.HIGH; |
| | | } |
| | | if (AlarmLevelEnum.VERY_HIGH.getDesc().equals(value)) { |
| | | return AlarmLevelEnum.VERY_HIGH; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public WriteCellData<AlarmLevelEnum> convertToExcelData(AlarmLevelEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | return new WriteCellData<>(value.getDesc()); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.alibaba.excel.metadata.data.WriteCellData; |
| | | import com.alibaba.excel.metadata.property.ExcelContentProperty; |
| | | import enumeration.general.RuleDeductCategoryEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * 扣分类型枚举装换器 |
| | | * |
| | | * @author gonghl |
| | | */ |
| | | @Slf4j |
| | | public class RuleDeductCategoryConverter implements Converter<RuleDeductCategoryEnum> { |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public RuleDeductCategoryEnum convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | public RuleDeductCategoryEnum convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | if (cellData.getStringValue().equals(RuleDeductCategoryEnum.DEDUCT_POINTS.getDesc())) { |
| | | return RuleDeductCategoryEnum.DEDUCT_POINTS; |
| | | } else if (cellData.getStringValue().equals(RuleDeductCategoryEnum.MULTIPLY_POINTS_BY_QUANTITY.getDesc())) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public WriteCellData convertToExcelData(RuleDeductCategoryEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | return new WriteCellData(value.getDesc()); |
| | | public WriteCellData<RuleDeductCategoryEnum> convertToExcelData(RuleDeductCategoryEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
| | | return new WriteCellData<>(value.getDesc()); |
| | | } |
| | | } |
New file |
| | |
| | | package enumeration.general; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | import com.fasterxml.jackson.annotation.JsonValue; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/8/26 下午 3:47 |
| | | */ |
| | | @Getter |
| | | public enum AlarmCategoryEnum { |
| | | |
| | | SSH("1", "SSH弱口令", 2), |
| | | TELNET("2", "Telnet弱口令", 2), |
| | | RDP("3", "RDP弱口令", 2), |
| | | FTP("4", "FTP弱口令", 6), |
| | | DATABASE("5", "数据库弱口令", 6); |
| | | |
| | | @EnumValue |
| | | private final String value; |
| | | @JsonValue |
| | | private final String desc; |
| | | private final Integer score; |
| | | |
| | | AlarmCategoryEnum(String value, String desc, Integer score) { |
| | | this.value = value; |
| | | this.desc = desc; |
| | | this.score = score; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package enumeration.general; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | import com.fasterxml.jackson.annotation.JsonValue; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/8/26 下午 3:47 |
| | | */ |
| | | @Getter |
| | | public enum AlarmLevelEnum { |
| | | |
| | | LOW("1", "低危"), |
| | | MIDDLE("2", "中危"), |
| | | HIGH("3", "高危"), |
| | | VERY_HIGH("4", "超危"); |
| | | |
| | | @EnumValue |
| | | private final String value; |
| | | @JsonValue |
| | | private final String desc; |
| | | |
| | | AlarmLevelEnum(String value, String desc) { |
| | | this.value = value; |
| | | this.desc = desc; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | @Excel(name = "部门id") |
| | | private Long deptId; |
| | | |
| | | private String deptName; |
| | | |
| | | /** 平台运行率 */ |
| | | @Excel(name = "平台运行率") |
| | | private BigDecimal platformOnline; |
| | |
| | | package com.ycl.platform.domain.entity; |
| | | |
| | | import annotation.Excel; |
| | | import com.alibaba.excel.annotation.ExcelIgnore; |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.alibaba.excel.annotation.write.style.ColumnWidth; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ycl.system.entity.BaseEntity; |
| | | import enumeration.converter.AlarmCategoryConverter; |
| | | import enumeration.converter.AlarmLevelConverter; |
| | | import enumeration.general.AlarmCategoryEnum; |
| | | import enumeration.general.AlarmLevelEnum; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | |
| | | * @date 2024-08-24 |
| | | */ |
| | | @Data |
| | | public class ImageResourceSecurityDetail extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | @ColumnWidth(20) |
| | | public class ImageResourceSecurityDetail { |
| | | |
| | | /** $column.columnComment */ |
| | | @ExcelIgnore |
| | | private Long id; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") |
| | | @ExcelProperty("IP地址") |
| | | private String ip; |
| | | |
| | | /** 部门id */ |
| | | @Excel(name = "部门id") |
| | | /** |
| | | * 部门id |
| | | */ |
| | | @ExcelIgnore |
| | | private Long deptId; |
| | | |
| | | /** 报警类型 */ |
| | | @Excel(name = "报警类型") |
| | | private String alarmCategory; |
| | | @ExcelProperty("部门名称") |
| | | @TableField(exist = false) |
| | | private String deptName; |
| | | |
| | | /** 报警级别 */ |
| | | @Excel(name = "报警级别") |
| | | private Long alarmLevel; |
| | | /** |
| | | * 报警类型 |
| | | */ |
| | | @ExcelProperty(value = "报警类型", converter = AlarmCategoryConverter.class) |
| | | private AlarmCategoryEnum alarmCategory; |
| | | |
| | | /** 报警次数 */ |
| | | @Excel(name = "报警次数") |
| | | /** |
| | | * 报警级别 |
| | | */ |
| | | @ExcelProperty(value = "报警级别", converter = AlarmLevelConverter.class) |
| | | private AlarmLevelEnum alarmLevel; |
| | | |
| | | /** |
| | | * 报警次数 |
| | | */ |
| | | @ExcelProperty("报警次数") |
| | | private Long num; |
| | | |
| | | /** 报警时间 */ |
| | | /** |
| | | * 报警时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd") |
| | | @Excel(name = "报警时间", width = 30, dateFormat = "yyyy-MM-dd") |
| | | @ExcelProperty("报警时间") |
| | | private Date alarmTime; |
| | | |
| | | @ExcelIgnore |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
New file |
| | |
| | | package com.ycl.handler; |
| | | |
| | | import com.alibaba.excel.write.handler.SheetWriteHandler; |
| | | import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext; |
| | | import org.apache.poi.ss.usermodel.DataValidation; |
| | | import org.apache.poi.ss.usermodel.DataValidationConstraint; |
| | | import org.apache.poi.ss.usermodel.DataValidationHelper; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/8/26 下午 1:38 |
| | | */ |
| | | public class ImageResourceHandler implements SheetWriteHandler { |
| | | |
| | | @Override |
| | | public void afterSheetCreate(SheetWriteHandlerContext context) { |
| | | Sheet sheet = context.getWriteSheetHolder().getSheet(); |
| | | // 区域/单位名称 |
| | | CellRangeAddressList cellRangeAddressList3 = new CellRangeAddressList(1, 9999, 1, 1); |
| | | DataValidationHelper helper3 = context.getWriteSheetHolder().getSheet().getDataValidationHelper(); |
| | | DataValidationConstraint constraint3 = helper3.createExplicitListConstraint(new String[]{"富顺县公安局", "大安区公安局", "自流井区公安局", "贡井区公安局", "荣县公安局", "自贡市公安局", "高新区公安局", "沿滩区公安局"}); |
| | | DataValidation dataValidation3 = helper3.createValidation(constraint3, cellRangeAddressList3); |
| | | // 报警类型 |
| | | CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(1, 9999, 2, 2); |
| | | DataValidationHelper helper = context.getWriteSheetHolder().getSheet().getDataValidationHelper(); |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(new String[]{"SSH弱口令", "Telnet弱口令", "RDP弱口令", "FTP弱口令", "数据库弱口令"}); |
| | | DataValidation dataValidation = helper.createValidation(constraint, cellRangeAddressList); |
| | | // 报警级别 |
| | | CellRangeAddressList cellRangeAddressList2 = new CellRangeAddressList(1, 9999, 3, 3); |
| | | DataValidationHelper helper2 = context.getWriteSheetHolder().getSheet().getDataValidationHelper(); |
| | | DataValidationConstraint constraint2 = helper2.createExplicitListConstraint(new String[]{"低危", "中危", "高危", "超危"}); |
| | | DataValidation dataValidation2 = helper2.createValidation(constraint2, cellRangeAddressList2); |
| | | sheet.addValidationData(dataValidation); |
| | | sheet.addValidationData(dataValidation2); |
| | | sheet.addValidationData(dataValidation3); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.ycl.system.AjaxResult; |
| | | import com.ycl.system.controller.BaseController; |
| | | import com.ycl.system.page.TableDataInfo; |
| | | import com.ycl.utils.poi.ExcelUtil; |
| | | import enumeration.BusinessType; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | { |
| | | return toAjax(imageResourceSecurityService.updateImageResourceSecurity(imageResourceSecurity)); |
| | | } |
| | | |
| | | /** |
| | | * 导入模板 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('platform:security:list')") |
| | | @Log(title = "导入模板", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) { |
| | | imageResourceSecurityService.importTemplate(response); |
| | | } |
| | | |
| | | /** |
| | | * 导入数据 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('platform:security:list')") |
| | | @Log(title = "导入", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importData") |
| | | public AjaxResult importData(MultipartFile file) { |
| | | return toAjax(imageResourceSecurityService.importData(file)); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ycl.platform.mapper; |
| | | |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurityDetail; |
| | | import org.apache.ibatis.annotations.Select; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | public int deleteImageResourceSecurityDetailByIds(Long[] ids); |
| | | |
| | | /** |
| | | * 批量插入 |
| | | * @param list 数据 |
| | | */ |
| | | void saveBatch(ArrayList<ImageResourceSecurityDetail> list); |
| | | |
| | | /** |
| | | * 定时任务获取详情计算 |
| | | * @return 数据 |
| | | */ |
| | | @Select("select dept_id, alarm_category, alarm_level, num from t_image_resource_security_detail") |
| | | List<ImageResourceSecurityDetail> getList(); |
| | | } |
| | |
| | | |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurity; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | public int deleteImageResourceSecurityByIds(Long[] ids); |
| | | |
| | | /** |
| | | * 批量保存 |
| | | * @param imageResourceSecurities 数据集合 |
| | | */ |
| | | void saveBatch(ArrayList<ImageResourceSecurity> imageResourceSecurities); |
| | | } |
| | |
| | | package com.ycl.platform.service; |
| | | |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurity; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | public int deleteImageResourceSecurityById(Long id); |
| | | |
| | | /** |
| | | * 导入模板 |
| | | * @param response 文件 |
| | | */ |
| | | void importTemplate(HttpServletResponse response); |
| | | |
| | | /** |
| | | * 导入数据 |
| | | * @param file 数据 |
| | | * @return 结果 |
| | | */ |
| | | Boolean importData(MultipartFile file); |
| | | |
| | | /** |
| | | * 批量保存 |
| | | * @param imageResourceSecurities 数据集合 |
| | | */ |
| | | void saveBatch(ArrayList<ImageResourceSecurity> imageResourceSecurities); |
| | | } |
| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.read.listener.PageReadListener; |
| | | import com.ycl.handler.ImageResourceHandler; |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurity; |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurityDetail; |
| | | import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper; |
| | | import com.ycl.platform.mapper.ImageResourceSecurityMapper; |
| | | import com.ycl.platform.service.IImageResourceSecurityService; |
| | | import com.ycl.system.entity.SysDept; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import com.ycl.utils.DateUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * @date 2024-08-24 |
| | | */ |
| | | @Service |
| | | public class ImageResourceSecurityServiceImpl implements IImageResourceSecurityService |
| | | { |
| | | @Autowired |
| | | private ImageResourceSecurityMapper imageResourceSecurityMapper; |
| | | @RequiredArgsConstructor |
| | | public class ImageResourceSecurityServiceImpl implements IImageResourceSecurityService { |
| | | |
| | | /** |
| | | * 查询platform |
| | | * |
| | | * @param id platform主键 |
| | | * @return platform |
| | | */ |
| | | private final ImageResourceSecurityMapper imageResourceSecurityMapper; |
| | | private final ImageResourceSecurityDetailMapper imageResourceSecurityDetailMapper; |
| | | private final ISysDeptService deptService; |
| | | |
| | | @Override |
| | | public ImageResourceSecurity selectImageResourceSecurityById(Long id) |
| | | { |
| | | public ImageResourceSecurity selectImageResourceSecurityById(Long id) { |
| | | return imageResourceSecurityMapper.selectImageResourceSecurityById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询platform列表 |
| | | * |
| | | * @param imageResourceSecurity platform |
| | | * @return platform |
| | | */ |
| | | @Override |
| | | public List<ImageResourceSecurity> selectImageResourceSecurityList(ImageResourceSecurity imageResourceSecurity) |
| | | { |
| | | public List<ImageResourceSecurity> selectImageResourceSecurityList(ImageResourceSecurity imageResourceSecurity) { |
| | | return imageResourceSecurityMapper.selectImageResourceSecurityList(imageResourceSecurity); |
| | | } |
| | | |
| | | /** |
| | | * 新增platform |
| | | * |
| | | * @param imageResourceSecurity platform |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) |
| | | { |
| | | public int insertImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) { |
| | | imageResourceSecurity.setCreateTime(DateUtils.getNowDate()); |
| | | return imageResourceSecurityMapper.insertImageResourceSecurity(imageResourceSecurity); |
| | | } |
| | | |
| | | /** |
| | | * 修改platform |
| | | * |
| | | * @param imageResourceSecurity platform |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) |
| | | { |
| | | public int updateImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) { |
| | | return imageResourceSecurityMapper.updateImageResourceSecurity(imageResourceSecurity); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除platform |
| | | * |
| | | * @param ids 需要删除的platform主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteImageResourceSecurityByIds(Long[] ids) |
| | | { |
| | | public int deleteImageResourceSecurityByIds(Long[] ids) { |
| | | return imageResourceSecurityMapper.deleteImageResourceSecurityByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 删除platform信息 |
| | | * |
| | | * @param id platform主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteImageResourceSecurityById(Long id) |
| | | { |
| | | public int deleteImageResourceSecurityById(Long id) { |
| | | return imageResourceSecurityMapper.deleteImageResourceSecurityById(id); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void importTemplate(HttpServletResponse response) { |
| | | EasyExcel.write(response.getOutputStream(), ImageResourceSecurityDetail.class).sheet("模板").registerWriteHandler(new ImageResourceHandler()).doWrite(Collections.emptyList()); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public Boolean importData(MultipartFile file) { |
| | | ArrayList<ImageResourceSecurityDetail> list = new ArrayList<>(); |
| | | List<SysDept> sysDept = deptService.selectDeptList(new SysDept()); |
| | | EasyExcel.read(file.getInputStream(), ImageResourceSecurityDetail.class, new PageReadListener<ImageResourceSecurityDetail>(dataList -> { |
| | | for (ImageResourceSecurityDetail detail : dataList) { |
| | | SysDept sysDept1 = sysDept.stream().filter(dept -> dept.getDeptName().equals(detail.getDeptName())).findFirst().orElseThrow(() -> new RuntimeException(detail.getDeptName() + "不存在")); |
| | | detail.setDeptId(sysDept1.getDeptId()); |
| | | list.add(detail); |
| | | } |
| | | })).sheet().doRead(); |
| | | imageResourceSecurityDetailMapper.saveBatch(list); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void saveBatch(ArrayList<ImageResourceSecurity> imageResourceSecurities) { |
| | | imageResourceSecurityMapper.saveBatch(imageResourceSecurities); |
| | | } |
| | | } |
New file |
| | |
| | | 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<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<ImageResourceSecurityDetail> detail = imageResourceSecurityDetailMapper.getList(); |
| | | |
| | | // 每个部门循环一次 |
| | | list.forEach(checkIndexVideo -> { |
| | | 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(); |
| | | // 循环detail计算 |
| | | detailList.forEach(imageResourceSecurityDetail -> { |
| | | int score = 100; |
| | | score -= imageResourceSecurityDetail.getAlarmCategory().getScore(); |
| | | imageResourceSecurity.setWeakPassword(BigDecimal.valueOf(score)); |
| | | }); |
| | | // TODO 差一个 |
| | | imageResourceSecurities.add(imageResourceSecurity); |
| | | }); |
| | | imageResourceSecurityService.saveBatch(imageResourceSecurities); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | </resultMap> |
| | | |
| | | <sql id="selectImageResourceSecurityDetailVo"> |
| | | select id, |
| | | SELECT id, |
| | | ip, |
| | | dept_id, |
| | | alarm_category, |
| | |
| | | num, |
| | | alarm_time, |
| | | create_time |
| | | from t_image_resource_security_detail |
| | | FROM t_image_resource_security_detail |
| | | </sql> |
| | | |
| | | <select id="selectImageResourceSecurityDetailList" resultMap="ImageResourceSecurityDetailResult"> |
| | | <include refid="selectImageResourceSecurityDetailVo"/> |
| | | <select id="selectImageResourceSecurityDetailList" resultType="com.ycl.platform.domain.entity.ImageResourceSecurityDetail"> |
| | | select id, |
| | | ip, |
| | | a.dept_id, |
| | | dept_name, |
| | | alarm_category, |
| | | alarm_level, |
| | | num, |
| | | alarm_time, |
| | | a.create_time |
| | | from t_image_resource_security_detail a |
| | | LEFT JOIN sys_dept b ON a.dept_id = b.dept_id AND b.del_flag = 0 |
| | | <where> |
| | | <if test="ip != null and ip != ''">and ip = #{ip}</if> |
| | | <if test="deptId != null ">and dept_id = #{deptId}</if> |
| | | <if test="deptId != null ">and a.dept_id = #{deptId}</if> |
| | | <if test="alarmCategory != null and alarmCategory != ''">and alarm_category = #{alarmCategory}</if> |
| | | <if test="alarmLevel != null ">and alarm_level = #{alarmLevel}</if> |
| | | <if test="num != null ">and num = #{num}</if> |
| | |
| | | </select> |
| | | |
| | | <select id="selectImageResourceSecurityDetailById"> |
| | | resultMap="ImageResourceSecurityDetailResult"> |
| | | resultMap="ImageResourceSecurityDetailResult"> |
| | | <include refid="selectImageResourceSecurityDetailVo"/> |
| | | where id = #{id} |
| | | </select> |
| | |
| | | </trim> |
| | | </insert> |
| | | |
| | | <insert id="saveBatch"> |
| | | INSERT INTO t_image_resource_security_detail (ip, dept_id, alarm_category, alarm_level, num, alarm_time, create_time) VALUES |
| | | <foreach collection="list" item="item" index="index" separator=","> |
| | | (#{item.ip}, #{item.deptId}, #{item.alarmCategory}, #{item.alarmLevel}, #{item.num}, #{item.alarmTime}, NOW()) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | <update id="updateImageResourceSecurityDetail"> |
| | | update t_image_resource_security_detail |
| | | <trim prefix="SET" suffixOverrides=","> |
| | |
| | | </update> |
| | | |
| | | <delete id="deleteImageResourceSecurityDetailById"> |
| | | delete |
| | | from t_image_resource_security_detail |
| | | where id = #{id} |
| | | DELETE |
| | | FROM t_image_resource_security_detail |
| | | WHERE id = #{id} |
| | | </delete> |
| | | |
| | | <delete id="deleteImageResourceSecurityDetailByIds"> |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ycl.platform.mapper.ImageResourceSecurityMapper"> |
| | | |
| | | <resultMap type="com.ycl.platform.domain.entity.ImageResourceSecurity" id="ImageResourceSecurityResult"> |
| | | <result property="id" column="id" /> |
| | | <result property="deptId" column="dept_id" /> |
| | | <result property="platformOnline" column="platform_online" /> |
| | | <result property="propertyAccuracy" column="property_accuracy" /> |
| | | <result property="weakPassword" column="weak_password" /> |
| | | <result property="riskProperty" column="risk_property" /> |
| | | <result property="boundaryIntegrity" column="boundary_integrity" /> |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="id" column="id"/> |
| | | <result property="deptId" column="dept_id"/> |
| | | <result property="platformOnline" column="platform_online"/> |
| | | <result property="propertyAccuracy" column="property_accuracy"/> |
| | | <result property="weakPassword" column="weak_password"/> |
| | | <result property="riskProperty" column="risk_property"/> |
| | | <result property="boundaryIntegrity" column="boundary_integrity"/> |
| | | <result property="createTime" column="create_time"/> |
| | | </resultMap> |
| | | |
| | | <sql id="selectImageResourceSecurityVo"> |
| | | select id, dept_id, platform_online, property_accuracy, weak_password, risk_property, boundary_integrity, create_time from t_image_resource_security |
| | | SELECT id, |
| | | dept_id, |
| | | platform_online, |
| | | property_accuracy, |
| | | weak_password, |
| | | risk_property, |
| | | boundary_integrity, |
| | | create_time |
| | | FROM t_image_resource_security |
| | | </sql> |
| | | |
| | | <select id="selectImageResourceSecurityList" resultMap="ImageResourceSecurityResult"> |
| | | <include refid="selectImageResourceSecurityVo"/> |
| | | <select id="selectImageResourceSecurityList" resultType="com.ycl.platform.domain.entity.ImageResourceSecurity"> |
| | | select id, a.dept_id, dept_name, platform_online, property_accuracy, weak_password, risk_property, boundary_integrity from t_image_resource_security a |
| | | LEFT JOIN sys_dept b ON a.dept_id = b.dept_id AND b.del_flag = 0 |
| | | <where> |
| | | <if test="deptId != null "> and dept_id = #{deptId}</if> |
| | | <if test="platformOnline != null "> and platform_online = #{platformOnline}</if> |
| | | <if test="propertyAccuracy != null "> and property_accuracy = #{propertyAccuracy}</if> |
| | | <if test="weakPassword != null "> and weak_password = #{weakPassword}</if> |
| | | <if test="riskProperty != null "> and risk_property = #{riskProperty}</if> |
| | | <if test="boundaryIntegrity != null "> and boundary_integrity = #{boundaryIntegrity}</if> |
| | | <if test="platformOnline != null ">and platform_online = #{platformOnline}</if> |
| | | <if test="propertyAccuracy != null ">and property_accuracy = #{propertyAccuracy}</if> |
| | | <if test="weakPassword != null ">and weak_password = #{weakPassword}</if> |
| | | <if test="riskProperty != null ">and risk_property = #{riskProperty}</if> |
| | | <if test="boundaryIntegrity != null ">and boundary_integrity = #{boundaryIntegrity}</if> |
| | | </where> |
| | | ORDER BY a.create_time DESC |
| | | limit 7 |
| | | </select> |
| | | |
| | | <select id="selectImageResourceSecurityById" resultMap="ImageResourceSecurityResult"> |
| | |
| | | <if test="riskProperty != null">risk_property,</if> |
| | | <if test="boundaryIntegrity != null">boundary_integrity,</if> |
| | | <if test="createTime != null">create_time,</if> |
| | | </trim> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="deptId != null">#{deptId},</if> |
| | | <if test="platformOnline != null">#{platformOnline},</if> |
| | |
| | | <if test="riskProperty != null">#{riskProperty},</if> |
| | | <if test="boundaryIntegrity != null">#{boundaryIntegrity},</if> |
| | | <if test="createTime != null">#{createTime},</if> |
| | | </trim> |
| | | </trim> |
| | | </insert> |
| | | |
| | | <insert id="saveBatch"> |
| | | insert into t_image_resource_security (dept_id, platform_online, property_accuracy, weak_password, risk_property, boundary_integrity, create_time) VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.deptId}, #{item.platformOnline}, #{item.propertyAccuracy}, #{item.weakPassword}, #{item.riskProperty}, #{item.boundaryIntegrity}, NOW()) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | <update id="updateImageResourceSecurity"> |
| | |
| | | </update> |
| | | |
| | | <delete id="deleteImageResourceSecurityById"> |
| | | delete from t_image_resource_security where id = #{id} |
| | | DELETE |
| | | FROM t_image_resource_security |
| | | WHERE id = #{id} |
| | | </delete> |
| | | |
| | | <delete id="deleteImageResourceSecurityByIds"> |