From 4e5c8f0726c8cf986a352f42408e4b5bee8ba851 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 24 Oct 2024 16:10:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/aop/SystemEventAspect.java | 19 +++++++++++-------- .../controller/AlertRecordController.java | 6 +++--- .../dto/alertTip/AlertTipQueryDTO.java | 3 +++ .../dto/record/AlertRecordQueryDTO.java | 3 +++ .../xiannccda/mapper/AlertTipMapper.java | 3 ++- .../repository/IAlertTipRepository.java | 3 ++- .../impl/AlertRecordRepository.java | 3 ++- .../repository/impl/AlertTipRepository.java | 5 +++-- .../repository/impl/EventLogRepository.java | 2 +- .../xiannccda/service/AlertTipService.java | 13 ++++++++++++- .../mybatis/mapper/AlertTipMapper.xml | 17 ++--------------- 11 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java b/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java index d58603c..909e01d 100644 --- a/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java +++ b/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java @@ -81,6 +81,8 @@ public class SystemEventAspect { if (Objects.nonNull(commonLogAnno)) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); String uri = request.getRequestURI(); + String method = request.getMethod(); + Long userId = this.userId(commonLogAnno.subLogType()); GetMapping getMapping = ms.getMethod().getDeclaredAnnotation(GetMapping.class); PostMapping postMapping = ms.getMethod().getDeclaredAnnotation(PostMapping.class); DeleteMapping deleteMapping = ms.getMethod().getDeclaredAnnotation(DeleteMapping.class); @@ -95,20 +97,21 @@ public class SystemEventAspect { } else if (Objects.nonNull(deleteMapping)) { String requestURI = this.getUri(deleteMapping.value(), uri); params = getRequestParam(requestURI, joinPoint.getArgs()); - - } - - String method = request.getMethod(); - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - Long userId = null; - if (commonLogAnno.logType() != CommonLogTypeEnum.LOGIN) { - userId = Long.valueOf(authentication.getName()); } return new OperateEvent(commonLogAnno.name(), commonLogAnno.logType(), commonLogAnno.subLogType(), uri, method, params, userId); } return null; } + private Long userId(SubEventType subEventType) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + Long userId = null; + if (subEventType != SubEventType.LOGIN) { + userId = Long.valueOf(authentication.getName()); + } + return userId; + } + private Map getRequestParam(String uriMap, Object[] args) { Map params = new HashMap<>(); int argsIndex = 0; diff --git a/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java b/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java index 725c1d9..431936f 100644 --- a/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java +++ b/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java @@ -74,7 +74,7 @@ public class AlertRecordController { this.alertRecordService.failAlarm(List.of(recordId), AlertStatus.FAIL_DO); } - @PostMapping("/page") + /* @PostMapping("/page") @SecurityRequirement(name = "jwt") @Operation(summary = "分页查询报警记录") @ApiResponse(description = "报警记录") @@ -82,14 +82,14 @@ public class AlertRecordController { public Page pageQuery(@RequestBody AlertRecordQueryDTO queryDTO) { return alertRecordRepository.newPage(CommonPageRequest.defaultPage(), queryDTO); - } + }*/ @GetMapping("/page/detail") @SecurityRequirement(name = "jwt") @Operation(summary = "分页查询报警记录详情") @ApiResponse(description = "报警记录详情") - @CommonLogAnno(name = "报警信息-列表数据2", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) + @CommonLogAnno(name = "报警信息-列表数据", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) public Page pageQueryAlertDetail(AlertRecordQueryDTO queryDTO) { return alertRecordService.pageQueryAlertDetail(queryDTO); } diff --git a/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipQueryDTO.java b/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipQueryDTO.java index c89e72a..81fe6a2 100644 --- a/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipQueryDTO.java +++ b/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipQueryDTO.java @@ -1,6 +1,7 @@ package club.joylink.xiannccda.dto.alertTip; import club.joylink.xiannccda.alert.AlertTipTimeType; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.dto.CommonPage; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertLocation; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; @@ -16,6 +17,8 @@ import lombok.Setter; @NoArgsConstructor public class AlertTipQueryDTO extends CommonPage { + private Integer lineId; + private LineTypeEnum lineType; @Schema(description = "告警类型") private String alertType; @Schema(description = "时间类型") diff --git a/src/main/java/club/joylink/xiannccda/dto/record/AlertRecordQueryDTO.java b/src/main/java/club/joylink/xiannccda/dto/record/AlertRecordQueryDTO.java index 1c2f986..dcb18bf 100644 --- a/src/main/java/club/joylink/xiannccda/dto/record/AlertRecordQueryDTO.java +++ b/src/main/java/club/joylink/xiannccda/dto/record/AlertRecordQueryDTO.java @@ -1,5 +1,6 @@ package club.joylink.xiannccda.dto.record; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.dto.CommonPage; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.entity.AlertRecord; @@ -13,6 +14,8 @@ public class AlertRecordQueryDTO extends CommonPage { private AlertType alertType; private Integer lineId; + + private LineTypeEnum lineType; private LocalDateTime beginDateTime; private LocalDateTime endDateTime; diff --git a/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java b/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java index ecda0b6..d455996 100644 --- a/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java +++ b/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java @@ -3,6 +3,7 @@ package club.joylink.xiannccda.mapper; import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto; import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO; import club.joylink.xiannccda.entity.AlertTip; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -20,5 +21,5 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface AlertTipMapper extends BaseMapper { - IPage selectForPage(IPage page, @Param("tipQuery") AlertTipQueryDTO dto); + IPage selectForPage(IPage page, @Param("ew") QueryWrapper qw); } diff --git a/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java index 900d0b0..8973ee6 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java @@ -3,6 +3,7 @@ package club.joylink.xiannccda.repository; import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto; import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO; import club.joylink.xiannccda.entity.AlertTip; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; @@ -22,5 +23,5 @@ public interface IAlertTipRepository extends IService { Map findBindAreaConfigId(List areaConfigList); - IPage leftAreaPage(IPage page, AlertTipQueryDTO queryDTO); + IPage leftAreaPage(IPage page, QueryWrapper qw); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AlertRecordRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AlertRecordRepository.java index dcb5922..5b7a8b4 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/AlertRecordRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AlertRecordRepository.java @@ -32,8 +32,9 @@ public class AlertRecordRepository extends ServiceImpl queryWrapper = Wrappers.lambdaQuery(AlertRecord.class); - queryWrapper.eq(Objects.nonNull(queryDTO.getAlertType()), AlertRecord::getAlertType, queryDTO.getAlertType()); queryWrapper.eq(Objects.nonNull(queryDTO.getLineId()), AlertRecord::getLineId, queryDTO.getLineId()); + queryWrapper.eq(Objects.nonNull(queryDTO.getLineType()), AlertRecord::getLineType, queryDTO.getLineType()); + queryWrapper.eq(Objects.nonNull(queryDTO.getAlertType()), AlertRecord::getAlertType, queryDTO.getAlertType()); queryWrapper.ge(Objects.nonNull(queryDTO.getBeginDateTime()), AlertRecord::getAlertTime, queryDTO.getBeginDateTime()); queryWrapper.le(Objects.nonNull(queryDTO.getEndDateTime()), AlertRecord::getAlertTime, queryDTO.getEndDateTime()); queryWrapper.eq(Objects.nonNull(queryDTO.getAlertStatus()), AlertRecord::getAlarmStatus, queryDTO.getAlertStatus()); diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AlertTipRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AlertTipRepository.java index 5929ff1..1dfe88e 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/AlertTipRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AlertTipRepository.java @@ -8,6 +8,7 @@ import club.joylink.xiannccda.entity.AlertTip; import club.joylink.xiannccda.mapper.AlertTipMapper; import club.joylink.xiannccda.repository.IAlertTipRepository; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -55,8 +56,8 @@ public class AlertTipRepository extends ServiceImpl im } @Override - public IPage leftAreaPage(IPage page, AlertTipQueryDTO queryDTO) { - return this.baseMapper.selectForPage(page, queryDTO); + public IPage leftAreaPage(IPage page, QueryWrapper qw) { + return this.baseMapper.selectForPage(page, qw); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/EventLogRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/EventLogRepository.java index 6242fdb..586f4fb 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/EventLogRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/EventLogRepository.java @@ -34,7 +34,7 @@ public class EventLogRepository extends ServiceImpl im QueryWrapper qw = new QueryWrapper<>(); qw.eq("A.event_type", dto.getLogType()); - + qw.orderByDesc("A.id"); return this.baseMapper.detailPage(dto, qw); } } diff --git a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java index 40940ff..b0dddfd 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java @@ -10,6 +10,7 @@ import club.joylink.xiannccda.entity.DeviceAreaConfig; import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; import club.joylink.xiannccda.repository.IAlertTipRepository; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; @@ -94,7 +95,17 @@ public class AlertTipService { } public IPage page(AlertTipQueryDTO queryDTO) { - IPage page = this.alertTipRepository.leftAreaPage(CommonPageRequest.defaultPage(), queryDTO); + + QueryWrapper qw = new QueryWrapper<>(); + qw.eq(Objects.nonNull(queryDTO.getLineId()), "A.line_id", queryDTO.getLineId()); + qw.eq(Objects.nonNull(queryDTO.getLineType()), "A.line_type", queryDTO.getLineType()); + qw.eq(StringUtils.isNotEmpty(queryDTO.getAlertType()), "A.alert_type", queryDTO.getAlertType()); + qw.eq(StringUtils.isNotEmpty(queryDTO.getTimeType()), "A.time_type", queryDTO.getTimeType()); + qw.eq(StringUtils.isNotEmpty(queryDTO.getLocationType()), "A.location_type", queryDTO.getLocationType()); + qw.eq(Objects.nonNull(queryDTO.getAreaConfigId()), "A.area_config_id", queryDTO.getAreaConfigId()); + qw.like(StringUtils.isNotEmpty(queryDTO.getAreaConfigName()), "B.area_name", queryDTO.getAreaConfigName()); + + IPage page = this.alertTipRepository.leftAreaPage(CommonPageRequest.defaultPage(), qw); for (AlertTipInfoDto record : page.getRecords()) { if (StringUtils.isNotEmpty(record.getTipTimeRef())) { diff --git a/src/main/resources/mybatis/mapper/AlertTipMapper.xml b/src/main/resources/mybatis/mapper/AlertTipMapper.xml index bf490ef..388b8d4 100644 --- a/src/main/resources/mybatis/mapper/AlertTipMapper.xml +++ b/src/main/resources/mybatis/mapper/AlertTipMapper.xml @@ -6,22 +6,9 @@ select A.*, B.area_name as areaConfigName,A.tip_time_ref from alert_tip A left join device_area_config B on A.area_config_id = B.id where 1 = 1 - - and A.alert_type = #{tipQuery.alertType} + + and ${ew.sqlSegment} - - and A.time_type = #{timeType} - - - and A.location_type = #{locationType} - - - and A.area_config_id = #{areaConfigId} - - - AND B.area_name Like CONCAT('%',#{tipQuery.areaConfigName},'%') - -