From ec69eebe6517db7071aeacda0bdace223f03e7e0 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Mon, 21 Oct 2024 15:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=8F=92=E5=85=A5=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=B8=8D=E8=83=BD=E6=9F=A5=E8=AF=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/alert/AlertListenerJob.java | 1 + .../joylink/xiannccda/alert/NccAlertInfo.java | 3 + .../xiannccda/aop/SystemEventAspect.java | 44 ++++++--- .../controller/AlertRecordController.java | 4 +- .../joylink/xiannccda/dto/CommonPage.java | 30 ++++++ .../xiannccda/dto/CommonPageRequest.java | 78 +++++++++++++++ .../dto/alertTip/AlertTipQueryDTO.java | 3 +- .../dto/config/DeviceAreaConfigQueryDto.java | 3 +- .../dto/record/AlertRecordQueryDTO.java | 5 +- .../xiannccda/dto/user/UserQueryDTO.java | 7 +- .../joylink/xiannccda/entity/AlertRecord.java | 3 + .../joylink/xiannccda/entity/AuthRole.java | 28 +++++- .../xiannccda/mapper/AlertTipMapper.java | 2 +- .../joylink/xiannccda/mapper/UserMapper.java | 3 +- .../repository/IAlertRecordRepository.java | 2 +- .../repository/IAlertTipRepository.java | 2 +- .../impl/AlertRecordRepository.java | 4 +- .../repository/impl/AlertTipRepository.java | 4 +- .../repository/impl/UserRepository.java | 15 ++- .../xiannccda/service/AlertRecordService.java | 7 +- .../xiannccda/service/AlertTipService.java | 3 +- .../xiannccda/service/UserService.java | 1 + .../config/DeviceAreaConfigService.java | 3 +- .../club/joylink/xiannccda/task/InitTask.java | 56 +++++++++++ .../xiannccda/util/CommonServletUtil.java | 99 +++++++++++++++++++ .../resources/mybatis/mapper/UserMapper.xml | 12 +-- 26 files changed, 378 insertions(+), 44 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/dto/CommonPage.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/CommonPageRequest.java create mode 100644 src/main/java/club/joylink/xiannccda/task/InitTask.java create mode 100644 src/main/java/club/joylink/xiannccda/util/CommonServletUtil.java diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java index df91826..05b11c8 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java @@ -70,6 +70,7 @@ public class AlertListenerJob implements ApplicationRunner { record.setAlertDeviceId(nccAlertInfo.getLocatorDeviceId()); record.setMock(nccAlertInfo.isMock()); record.setAlarmStatus(AlertStatus.NOT_DO); + record.setLineType(nccAlertInfo.getLineType()); // record.setAlertLocation(nccAlertInfo.getAlertLocationName()); return record; } diff --git a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java index c2df5a7..a24c5f3 100644 --- a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java +++ b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java @@ -2,6 +2,7 @@ package club.joylink.xiannccda.alert; import club.joylink.xiannccda.alert.core.AlertDeviceType; import club.joylink.xiannccda.alert.core.AlertInfo; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertLocation; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; @@ -32,6 +33,8 @@ public class NccAlertInfo implements AlertInfo { @Setter private Integer alarmStatus; private AlertDeviceType alertDeviceType; + @Setter + private LineTypeEnum lineType; // private AlertType confirmAlertType; public NccAlertInfo(LocalDateTime alertTime, AlertType alertType, diff --git a/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java b/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java index f5bcf03..d58603c 100644 --- a/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java +++ b/src/main/java/club/joylink/xiannccda/aop/SystemEventAspect.java @@ -5,13 +5,16 @@ import club.joylink.xiannccda.constants.common.CommonLogTypeEnum; import club.joylink.xiannccda.constants.common.CommonLogTypeEnum.SubEventType; import club.joylink.xiannccda.constants.SystemContext; import club.joylink.xiannccda.event.OperateEvent; +import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; import com.google.common.collect.Maps; import jakarta.servlet.http.HttpServletRequest; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; @@ -62,24 +65,39 @@ public class SystemEventAspect { } } + private String getUri(String[] uriMapping, String requestUri) { + if (ArrayUtils.isEmpty(uriMapping)) { + return requestUri; + } + if (Arrays.stream(uriMapping).anyMatch(StringUtils::isEmpty)) { + return requestUri; + } + return uriMapping[0]; + } + private OperateEvent parseRequestParameter(JoinPoint joinPoint) { MethodSignature ms = (MethodSignature) joinPoint.getSignature(); CommonLogAnno commonLogAnno = ms.getMethod().getDeclaredAnnotation(CommonLogAnno.class); if (Objects.nonNull(commonLogAnno)) { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); + String uri = request.getRequestURI(); GetMapping getMapping = ms.getMethod().getDeclaredAnnotation(GetMapping.class); PostMapping postMapping = ms.getMethod().getDeclaredAnnotation(PostMapping.class); DeleteMapping deleteMapping = ms.getMethod().getDeclaredAnnotation(DeleteMapping.class); Map params = Map.of(); if (Objects.nonNull(getMapping)) { - params = getRequestParam(getMapping.value(), joinPoint.getArgs()); + String requestURI = this.getUri(getMapping.value(), uri); + params = getRequestParam(requestURI, joinPoint.getArgs()); } else if (Objects.nonNull(postMapping)) { - params = getRequestParam(postMapping.value(), joinPoint.getArgs()); + String requestURI = this.getUri(postMapping.value(), uri); + params = getRequestParam(requestURI, joinPoint.getArgs()); + } else if (Objects.nonNull(deleteMapping)) { - params = getRequestParam(deleteMapping.value(), joinPoint.getArgs()); + String requestURI = this.getUri(deleteMapping.value(), uri); + params = getRequestParam(requestURI, joinPoint.getArgs()); } - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); - String uri = request.getRequestURI(); + String method = request.getMethod(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = null; @@ -91,18 +109,16 @@ public class SystemEventAspect { return null; } - private Map getRequestParam(String[] mappingUri, Object[] args) { + private Map getRequestParam(String uriMap, Object[] args) { Map params = new HashMap<>(); int argsIndex = 0; - if (ArrayUtils.isNotEmpty(mappingUri)) { - Map uriParamMap = new HashMap<>(); - UriTemplate ut = new UriTemplate(mappingUri[0]); - for (String vn : ut.getVariableNames()) { - uriParamMap.put(vn, args[argsIndex]); - argsIndex++; - } - params.put("uriParam", uriParamMap); + Map uriParamMap = new HashMap<>(); + UriTemplate ut = new UriTemplate(uriMap); + for (String vn : ut.getVariableNames()) { + uriParamMap.put(vn, args[argsIndex]); + argsIndex++; } + params.put("uriParam", uriParamMap); for (; argsIndex < args.length; argsIndex++) { params.put("param", args[argsIndex]); } diff --git a/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java b/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java index 19c9fd9..725c1d9 100644 --- a/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java +++ b/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java @@ -5,6 +5,7 @@ import club.joylink.xiannccda.alert.NccAlertInfo.AlertStatus; import club.joylink.xiannccda.constants.common.CommonLogAnno; import club.joylink.xiannccda.constants.common.CommonLogTypeEnum; import club.joylink.xiannccda.constants.common.CommonLogTypeEnum.SubEventType; +import club.joylink.xiannccda.dto.CommonPageRequest; import club.joylink.xiannccda.dto.record.AlertRecordQueryDTO; import club.joylink.xiannccda.dto.record.AlertRecordReportDTO; import club.joylink.xiannccda.dto.record.AlertRecordReportResponseDTO; @@ -79,7 +80,8 @@ public class AlertRecordController { @ApiResponse(description = "报警记录") @CommonLogAnno(name = "报警信息-列表数据", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) public Page pageQuery(@RequestBody AlertRecordQueryDTO queryDTO) { - return alertRecordRepository.page(queryDTO); + + return alertRecordRepository.newPage(CommonPageRequest.defaultPage(), queryDTO); } diff --git a/src/main/java/club/joylink/xiannccda/dto/CommonPage.java b/src/main/java/club/joylink/xiannccda/dto/CommonPage.java new file mode 100644 index 0000000..81de4cd --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/CommonPage.java @@ -0,0 +1,30 @@ +package club.joylink.xiannccda.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class CommonPage { + + @Schema(description = "当前页码") + private Integer current; + + /** + * 每页条数 + */ + @Schema(description = "每页条数") + private Integer size; + + /** + * 排序字段 + */ + @Schema(description = "排序字段,字段驼峰名称,如:userName") + private String sortField; + + /** + * 排序方式 + */ + @Schema(description = "排序方式,升序:ASCEND;降序:DESCEND") + private String sortOrder; + +} diff --git a/src/main/java/club/joylink/xiannccda/dto/CommonPageRequest.java b/src/main/java/club/joylink/xiannccda/dto/CommonPageRequest.java new file mode 100644 index 0000000..864cf10 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/CommonPageRequest.java @@ -0,0 +1,78 @@ +/* + * Copyright [2022] [https://www.xiaonuo.vip] + * + * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Snowy源码头部的版权声明。 + * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip + * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。 + * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package club.joylink.xiannccda.dto; + +import club.joylink.xiannccda.util.CommonServletUtil; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import java.util.List; +import java.util.Objects; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +/** + * 通用分页请求 + * + * @author xuyuxiang + * @date 2021/12/18 14:43 + */ +@Slf4j +public class CommonPageRequest { + + private static final String PAGE_SIZE_PARAM_NAME = "size"; + + private static final String PAGE_PARAM_NAME = "current"; + + private static final Integer PAGE_SIZE_MAX_VALUE = 100; + + public static Page defaultPage() { + return defaultPage(null); + } + + public static Page defaultPage(List orderItemList) { + + int size = 20; + + int page = 1; + + //每页条数 + String pageSizeString = CommonServletUtil.getParamFromRequest(PAGE_SIZE_PARAM_NAME); + if (StringUtils.isNotEmpty(pageSizeString)) { + try { + size = Integer.parseInt(pageSizeString); + if (size > PAGE_SIZE_MAX_VALUE) { + size = PAGE_SIZE_MAX_VALUE; + } + } catch (Exception e) { + log.error(">>> 分页条数转换异常:", e); + size = 20; + } + } + + //第几页 + String pageString = CommonServletUtil.getParamFromRequest(PAGE_PARAM_NAME); + if (StringUtils.isNotEmpty(pageString)) { + try { + page = Integer.parseInt(pageString); + } catch (Exception e) { + log.error(">>> 分页页数转换异常:", e); + page = 1; + } + } + Page objectPage = new Page<>(page, size); + if (Objects.nonNull(orderItemList)) { + objectPage.setOrders(orderItemList); + } + return objectPage; + } +} 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 717c91a..c89e72a 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.dto.CommonPage; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertLocation; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.entity.AlertTip; @@ -13,7 +14,7 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -public class AlertTipQueryDTO extends PageDTO { +public class AlertTipQueryDTO extends CommonPage { @Schema(description = "告警类型") private String alertType; diff --git a/src/main/java/club/joylink/xiannccda/dto/config/DeviceAreaConfigQueryDto.java b/src/main/java/club/joylink/xiannccda/dto/config/DeviceAreaConfigQueryDto.java index 34615f5..40832fd 100644 --- a/src/main/java/club/joylink/xiannccda/dto/config/DeviceAreaConfigQueryDto.java +++ b/src/main/java/club/joylink/xiannccda/dto/config/DeviceAreaConfigQueryDto.java @@ -1,6 +1,7 @@ package club.joylink.xiannccda.dto.config; import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import club.joylink.xiannccda.dto.CommonPage; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.entity.DeviceAreaConfig; import club.joylink.xiannccda.entity.DeviceGuardConfig; @@ -9,7 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data -public class DeviceAreaConfigQueryDto extends PageDTO { +public class DeviceAreaConfigQueryDto extends CommonPage { @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 c34bf6e..1c2f986 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.dto.CommonPage; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.entity.AlertRecord; import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; @@ -7,13 +8,13 @@ import java.time.LocalDateTime; import lombok.Data; @Data -public class AlertRecordQueryDTO extends PageDTO { +public class AlertRecordQueryDTO extends CommonPage { private AlertType alertType; private Integer lineId; private LocalDateTime beginDateTime; private LocalDateTime endDateTime; - + private Integer alertStatus; } diff --git a/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java b/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java index a7b8e41..b1fe1f1 100644 --- a/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java +++ b/src/main/java/club/joylink/xiannccda/dto/user/UserQueryDTO.java @@ -1,5 +1,6 @@ package club.joylink.xiannccda.dto.user; +import club.joylink.xiannccda.dto.CommonPage; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.entity.AlertRecord; import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; @@ -12,10 +13,12 @@ import lombok.experimental.Accessors; @Data @Builder -public class UserQueryDTO extends PageDTO { +public class UserQueryDTO extends CommonPage { + - private String mobile; private String password; + private String name; + } diff --git a/src/main/java/club/joylink/xiannccda/entity/AlertRecord.java b/src/main/java/club/joylink/xiannccda/entity/AlertRecord.java index 50d29e5..29131bc 100644 --- a/src/main/java/club/joylink/xiannccda/entity/AlertRecord.java +++ b/src/main/java/club/joylink/xiannccda/entity/AlertRecord.java @@ -1,5 +1,6 @@ package club.joylink.xiannccda.entity; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -44,6 +45,8 @@ public class AlertRecord { private String alertDeviceType; private String alertDeviceId; private Boolean mock; + //线路类型 + private LineTypeEnum lineType; // private String confirmAlertType; public static final String ID = "id"; diff --git a/src/main/java/club/joylink/xiannccda/entity/AuthRole.java b/src/main/java/club/joylink/xiannccda/entity/AuthRole.java index 9b99f9b..6e3d6cc 100644 --- a/src/main/java/club/joylink/xiannccda/entity/AuthRole.java +++ b/src/main/java/club/joylink/xiannccda/entity/AuthRole.java @@ -3,6 +3,7 @@ package club.joylink.xiannccda.entity; import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.entity.AuthApiPath.AuthApi; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -10,6 +11,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; +import java.util.List; import lombok.Data; import lombok.Getter; import lombok.Setter; @@ -23,6 +25,15 @@ import org.apache.commons.lang3.StringUtils; @Schema(name = "authRole", description = "用户角色") public class AuthRole { + public AuthRole() { + + } + + public AuthRole(Long id, String name) { + this.id = id; + this.name = name; + } + @TableId(value = "id", type = IdType.AUTO) private Long id; @@ -36,14 +47,17 @@ public class AuthRole { @Schema(description = "角色配置") @TableField(exist = false) - private RoleConfig roleConfig; + private List roleConfig; - public RoleConfig getRoleConfig() { + public List getRoleConfig() { if (StringUtils.isNotEmpty(this.roleConfigStr)) { - return JSON.parseObject(this.roleConfigStr, RoleConfig.class); + return JSONArray.parseArray(this.roleConfigStr, RoleConfig.class); } return null; + } + public List tmpRoleConfig() { + return this.roleConfig; } public static final String ID = "id"; @@ -58,5 +72,13 @@ public class AuthRole { @Schema(description = "线路类型") private LineTypeEnum lineType; + public RoleConfig() { + + } + + public RoleConfig(Integer lineId, LineTypeEnum lineType) { + this.lineId = lineId; + this.lineType = lineType; + } } } diff --git a/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java b/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java index 6364e7a..ecda0b6 100644 --- a/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java +++ b/src/main/java/club/joylink/xiannccda/mapper/AlertTipMapper.java @@ -20,5 +20,5 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface AlertTipMapper extends BaseMapper { - IPage selectForPage(@Param("tipQuery") AlertTipQueryDTO dto); + IPage selectForPage(IPage page, @Param("tipQuery") AlertTipQueryDTO dto); } diff --git a/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java b/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java index 06123cc..9c0b295 100644 --- a/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java +++ b/src/main/java/club/joylink/xiannccda/mapper/UserMapper.java @@ -3,6 +3,7 @@ package club.joylink.xiannccda.mapper; import club.joylink.xiannccda.dto.user.UserDetailDTO; import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.entity.User; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; @@ -19,6 +20,6 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface UserMapper extends BaseMapper { - Page detailQuery(@Param("dto") UserQueryDTO dto); + Page detailQuery(Page page, @Param("ew") QueryWrapper qw); } diff --git a/src/main/java/club/joylink/xiannccda/repository/IAlertRecordRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAlertRecordRepository.java index 456f83d..67bd308 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IAlertRecordRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IAlertRecordRepository.java @@ -18,7 +18,7 @@ import java.util.List; */ public interface IAlertRecordRepository extends IService { - Page page(AlertRecordQueryDTO queryDTO); + Page newPage(Page page, AlertRecordQueryDTO queryDTO); List report(Integer lineId, AlertRecordReportDTO reportDTO); } diff --git a/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java index 56580b1..900d0b0 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IAlertTipRepository.java @@ -22,5 +22,5 @@ public interface IAlertTipRepository extends IService { Map findBindAreaConfigId(List areaConfigList); - IPage leftAreaPage(AlertTipQueryDTO queryDTO); + IPage leftAreaPage(IPage page, AlertTipQueryDTO queryDTO); } 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 b1c86d6..dcb5922 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/AlertRecordRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AlertRecordRepository.java @@ -27,7 +27,7 @@ import org.springframework.stereotype.Service; public class AlertRecordRepository extends ServiceImpl implements IAlertRecordRepository { @Override - public Page page(AlertRecordQueryDTO queryDTO) { + public Page newPage(Page page, AlertRecordQueryDTO queryDTO) { if (Objects.nonNull(queryDTO.getBeginDateTime()) && Objects.nonNull(queryDTO.getEndDateTime())) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(queryDTO.getBeginDateTime().isAfter(queryDTO.getEndDateTime()), "查询开始时间不能小于结束时间"); } @@ -41,7 +41,7 @@ public class AlertRecordRepository extends ServiceImpl im } @Override - public IPage leftAreaPage(AlertTipQueryDTO queryDTO) { - return this.baseMapper.selectForPage(queryDTO); + public IPage leftAreaPage(IPage page, AlertTipQueryDTO queryDTO) { + return this.baseMapper.selectForPage(page, queryDTO); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java index 3f6e3e5..eb7f3ca 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/UserRepository.java @@ -1,11 +1,13 @@ package club.joylink.xiannccda.repository.impl; +import club.joylink.xiannccda.dto.CommonPageRequest; import club.joylink.xiannccda.dto.user.UserDetailDTO; import club.joylink.xiannccda.dto.user.UserDetailDTO.UserRoleDetail; import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.entity.User; import club.joylink.xiannccda.mapper.UserMapper; import club.joylink.xiannccda.repository.IUserRepository; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; @@ -28,7 +30,18 @@ public class UserRepository extends ServiceImpl implements IUs @Override public Page userRolePage(UserQueryDTO dto) { - Page page = this.baseMapper.detailQuery(dto); + + QueryWrapper qw = new QueryWrapper<>(); + if (StringUtils.isNotEmpty(dto.getMobile())) { + qw.eq("A.mobile", dto.getMobile()); + } + if (StringUtils.isNotEmpty(dto.getPassword())) { + qw.eq("A.password", dto.getPassword()); + } + if (StringUtils.isNotEmpty(dto.getName())) { + qw.like("A.name", dto.getName()); + } + Page page = this.baseMapper.detailQuery(CommonPageRequest.defaultPage(), qw); for (UserDetailDTO record : page.getRecords()) { List userRoleList = Lists.newArrayList(); if (StringUtils.isNotEmpty(record.getUserRoles())) { diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index 28537f1..c1eed20 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -3,6 +3,8 @@ package club.joylink.xiannccda.service; import club.joylink.xiannccda.alert.NccAlertInfo; import club.joylink.xiannccda.alert.NccAlertInfo.AlertStatus; import club.joylink.xiannccda.alert.core.AlertDeviceType; +import club.joylink.xiannccda.dto.CommonPage; +import club.joylink.xiannccda.dto.CommonPageRequest; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.AlertConstProto.TipTimeConfig; import club.joylink.xiannccda.dto.record.AlertRecordQueryDTO; @@ -13,6 +15,7 @@ import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; import club.joylink.xiannccda.repository.IAlertRecordRepository; import club.joylink.xiannccda.repository.impl.AlertTipRepository; import club.joylink.xiannccda.service.config.DeviceAreaConfigService; +import club.joylink.xiannccda.util.CommonServletUtil; import club.joylink.xiannccda.vo.AreaConfigVO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; @@ -184,6 +187,7 @@ public class AlertRecordService { AlertType.valueOf(record.getAlertType()), Objects.isNull(record.getAlertTipId()) ? null : record.getAlertTipId().intValue(), record.getLineId(), record.getAlertObject(), "", record.getAlertLocationId(), deviceType); nccAlertInfo.setId(record.getId()); + nccAlertInfo.setLineType(record.getLineType()); nccAlertInfo.setAlarmStatus(record.getAlarmStatus()); // if (StringUtils.isNotEmpty(record.getConfirmAlertType())) { // nccAlertInfo.setAlertType(AlertType.valueOf(record.getConfirmAlertType())); @@ -195,7 +199,8 @@ public class AlertRecordService { } public Page pageQueryAlertDetail(AlertRecordQueryDTO queryDTO) { - Page recordPage = alertRecordRepository.page(queryDTO); + + Page recordPage = alertRecordRepository.newPage(CommonPageRequest.defaultPage(), queryDTO); List collect = this.changeData(recordPage.getRecords()); Page nccPage = Page.of(recordPage.getCurrent(), recordPage.getSize(), recordPage.getTotal()); diff --git a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java index 677f32f..bcfb7c1 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java @@ -1,5 +1,6 @@ package club.joylink.xiannccda.service; +import club.joylink.xiannccda.dto.CommonPageRequest; import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto; import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO; import club.joylink.xiannccda.dto.alertTip.AlertTipSaveDTO; @@ -92,7 +93,7 @@ public class AlertTipService { } public IPage page(AlertTipQueryDTO queryDTO) { - IPage page = this.alertTipRepository.leftAreaPage(queryDTO); + IPage page = this.alertTipRepository.leftAreaPage(CommonPageRequest.defaultPage(), queryDTO); for (AlertTipInfoDto record : page.getRecords()) { if (StringUtils.isNotEmpty(record.getTipTimeRef())) { diff --git a/src/main/java/club/joylink/xiannccda/service/UserService.java b/src/main/java/club/joylink/xiannccda/service/UserService.java index 2af195a..c91f79a 100644 --- a/src/main/java/club/joylink/xiannccda/service/UserService.java +++ b/src/main/java/club/joylink/xiannccda/service/UserService.java @@ -37,6 +37,7 @@ public class UserService { final IAuthRoleUserRefRepository authRoleUserRefRepository; final IAuthRoleRepository authRoleRepository; private final static long EXPIRY = 3 * 24 * 60 * 60;//3天过期时间 +// private final static long EXPIRY = 180;//3天过期时间 public UserService(IUserRepository userRepository, JwtEncoder jwtEncoder, IAuthRoleUserRefRepository authRoleUserRefRepository, IAuthRoleRepository authRoleRepository) { this.userRepository = userRepository; diff --git a/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java b/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java index 6ded5e7..55abd2b 100644 --- a/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java +++ b/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java @@ -3,6 +3,7 @@ package club.joylink.xiannccda.service.config; import club.joylink.xiannccda.alert.core.AlertDeviceType; import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; +import club.joylink.xiannccda.dto.CommonPageRequest; import club.joylink.xiannccda.dto.config.DeviceAreaConfigDto; import club.joylink.xiannccda.dto.config.DeviceAreaConfigPageDto; import club.joylink.xiannccda.dto.config.DeviceAreaConfigQueryDto; @@ -176,7 +177,7 @@ public class DeviceAreaConfigService { queryWrapper.last(String.format(" and find_in_set('%s',%s) > 0", queryDTO.getAlertType().name(), DeviceAreaConfig.ALERT_TYPES)); } - Page pageConfig = deviceAreaConfigRepository.page(queryDTO, queryWrapper); + Page pageConfig = deviceAreaConfigRepository.page(CommonPageRequest.defaultPage(), queryWrapper); return this.convertPage(pageConfig); } diff --git a/src/main/java/club/joylink/xiannccda/task/InitTask.java b/src/main/java/club/joylink/xiannccda/task/InitTask.java new file mode 100644 index 0000000..3431a74 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/task/InitTask.java @@ -0,0 +1,56 @@ +package club.joylink.xiannccda.task; + +import club.joylink.xiannccda.constants.common.LineTypeEnum; +import club.joylink.xiannccda.entity.AuthRole; +import club.joylink.xiannccda.entity.AuthRole.RoleConfig; +import club.joylink.xiannccda.repository.IAuthRoleRepository; +import com.alibaba.fastjson2.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +@Component +public class InitTask implements ApplicationRunner { + + @Autowired + private IAuthRoleRepository authRoleRepository; + + private Map staticInitialData() { + Map roleMap = new HashMap<>(); + AuthRole r1 = new AuthRole(1L, "超级管理员"); + r1.setRoleConfig(List.of(initRoleConfig(3, LineTypeEnum.NCC), + initRoleConfig(4, LineTypeEnum.NCC))); + roleMap.put("超级管理员", r1); + r1 = new AuthRole(2L, "3号线ATS"); + r1.setRoleConfig(List.of(initRoleConfig(3, LineTypeEnum.OCC))); + roleMap.put("3号线ATS", r1); + r1 = new AuthRole(3L, "4号线ATS"); + r1.setRoleConfig(List.of(initRoleConfig(4, LineTypeEnum.OCC))); + roleMap.put("4号线ATS", r1); + return roleMap; + } + + private RoleConfig initRoleConfig(int lineId, LineTypeEnum lineType) { + return new RoleConfig(lineId, lineType); + + } + + @Override + public void run(ApplicationArguments args) throws Exception { + Map initRoleMap = this.staticInitialData(); + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().in(AuthRole::getName, List.of(initRoleMap.keySet())); +// List authRoles = this.authRoleRepository.list(qw); + initRoleMap.forEach((k, v) -> { + + v.setRoleConfigStr(JSON.toJSONString(v.tmpRoleConfig())); + this.authRoleRepository.saveOrUpdate(v); + }); + } +} diff --git a/src/main/java/club/joylink/xiannccda/util/CommonServletUtil.java b/src/main/java/club/joylink/xiannccda/util/CommonServletUtil.java new file mode 100644 index 0000000..b5e2652 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/util/CommonServletUtil.java @@ -0,0 +1,99 @@ +/* + * Copyright [2022] [https://www.xiaonuo.vip] + * + * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Snowy源码头部的版权声明。 + * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip + * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。 + * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip + */ +package club.joylink.xiannccda.util; + +import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.util.Objects; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +/** + * HttpServlet工具类,获取当前request和response + * + * @author xuyuxiang + * @date 2020/3/30 15:09 + */ +@Slf4j +public class CommonServletUtil { + + /** + * 从请求中中获取参数 + * + * @author xuyuxiang + * @date 2021/10/14 10:44 + **/ + public static String getParamFromRequest(String paramName) { + HttpServletRequest request = getRequest(); + + // 1. 尝试从请求体里面读取 + String paramValue = request.getParameter(paramName); + + // 2. 尝试从header里读取 + if (StringUtils.isEmpty(paramValue)) { + paramValue = request.getHeader(paramName); + } + // 3. 尝试从cookie里读取 + if (Objects.isNull(paramValue)) { + Cookie[] cookies = request.getCookies(); + if (ArrayUtils.isNotEmpty(cookies)) { + for (Cookie cookie : cookies) { + String cookieName = cookie.getName(); + if (cookieName.equals(paramName)) { + return cookie.getValue(); + } + } + } + } + // 4. 返回 + return paramValue; + } + + public static HttpServletRequest getRequest() { + ServletRequestAttributes servletRequestAttributes; + try { + servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + } catch (Exception e) { + throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception(); + } + if (servletRequestAttributes == null) { + throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception(); + } else { + return servletRequestAttributes.getRequest(); + } + } + + public static HttpServletResponse getResponse() { + ServletRequestAttributes servletRequestAttributes; + try { + servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + } catch (Exception e) { + log.error(">>> 非Web上下文无法获取Response:", e); + throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception(); + } + if (servletRequestAttributes == null) { + throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception(); + } else { + return servletRequestAttributes.getResponse(); + } + } + + public static boolean isWeb() { + return RequestContextHolder.getRequestAttributes() != null; + } +} diff --git a/src/main/resources/mybatis/mapper/UserMapper.xml b/src/main/resources/mybatis/mapper/UserMapper.xml index 273455c..3bf3710 100644 --- a/src/main/resources/mybatis/mapper/UserMapper.xml +++ b/src/main/resources/mybatis/mapper/UserMapper.xml @@ -15,20 +15,16 @@ id, name, mobile, password, register_time - select A.id, A.name, A.mobile, A.register_time, B.user_roles,A.default_role from user A left join (select A.user_id, GROUP_CONCAT(A.role_id, '|', B.`name`) as user_roles from auth_role_user_ref A left join auth_role B on A.role_id = B.id - GROUP BY user_id) B - on A.id = B.user_id + GROUP BY user_id) B on A.id = B.user_id where 1 = 1 - - and A.mobile = #{dto.mobile} - - - and A.password = #{dto.password} + + and ${ew.sqlSegment}