From 3c6595e591317c6181408fb6e8957bf2e0766e4e Mon Sep 17 00:00:00 2001 From: 15683799673 Date: Sat, 30 Aug 2025 06:36:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8B=E4=BB=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=8C=87=E6=B4=BE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/api/RemoteAttendanceService.java | 11 ++- .../vo/RemoteAttendanceUserGroupVo.java | 1 - .../dubbo/RemoteAttendanceServiceImpl.java | 11 +++ .../AttendanceUserGroupMapper.java | 14 +++- .../IAttendanceAreaDeviceService.java | 2 + .../IAttendanceUserGroupService.java | 9 +++ .../AttendanceUserGroupServiceImpl.java | 5 ++ .../Property/AttendanceUserGroupMapper.xml | 16 +++++ .../sis/service/ISisAlarmEventsService.java | 3 +- .../service/IZeroSensationPassageService.java | 2 - .../impl/SisAlarmEventsServiceImpl.java | 9 +-- .../impl/ZeroSensationPassageServiceImpl.java | 71 ++++++++++++++++--- .../resource/controller/SysOssController.java | 27 ++++--- .../resource/service/ISysOssService.java | 1 + .../service/impl/SysOssServiceImpl.java | 1 - 15 files changed, 150 insertions(+), 33 deletions(-) diff --git a/ruoyi-api/property-api/src/main/java/org/dromara/property/api/RemoteAttendanceService.java b/ruoyi-api/property-api/src/main/java/org/dromara/property/api/RemoteAttendanceService.java index 94e6e2a8..fb1a0bbe 100644 --- a/ruoyi-api/property-api/src/main/java/org/dromara/property/api/RemoteAttendanceService.java +++ b/ruoyi-api/property-api/src/main/java/org/dromara/property/api/RemoteAttendanceService.java @@ -18,6 +18,15 @@ public interface RemoteAttendanceService { * @param date 查询时间 * @return 返回排班人员信息 */ - public List queryAttendPersonInfo(Date date); + List queryAttendPersonInfo(Date date); + + /** + * 根据时间和设备ip查询当前设备所处区域的排班人员信息 + * + * @param date 查询时间 + * @param deviceIp 设备ip + * @return 返回排班人员信息 + */ + List queryAttendByCurrDateAndDeviceIp(Date date, String deviceIp); } diff --git a/ruoyi-api/property-api/src/main/java/org/dromara/property/api/domain/vo/RemoteAttendanceUserGroupVo.java b/ruoyi-api/property-api/src/main/java/org/dromara/property/api/domain/vo/RemoteAttendanceUserGroupVo.java index 1146533a..1916b5d1 100644 --- a/ruoyi-api/property-api/src/main/java/org/dromara/property/api/domain/vo/RemoteAttendanceUserGroupVo.java +++ b/ruoyi-api/property-api/src/main/java/org/dromara/property/api/domain/vo/RemoteAttendanceUserGroupVo.java @@ -49,5 +49,4 @@ public class RemoteAttendanceUserGroupVo implements Serializable { */ private LocalDate endDate; - } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteAttendanceServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteAttendanceServiceImpl.java index 0acb754b..060749d7 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteAttendanceServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/dubbo/RemoteAttendanceServiceImpl.java @@ -6,7 +6,9 @@ import lombok.RequiredArgsConstructor; import org.apache.dubbo.config.annotation.DubboService; import org.dromara.property.api.RemoteAttendanceService; import org.dromara.property.api.domain.vo.RemoteAttendanceUserGroupVo; +import org.dromara.property.domain.vo.attendanceVo.AttendanceAreaDeviceVo; import org.dromara.property.domain.vo.attendanceVo.AttendanceUserGroupVo; +import org.dromara.property.service.attendanceService.IAttendanceAreaDeviceService; import org.dromara.property.service.attendanceService.IAttendanceUserGroupService; import java.util.Date; @@ -23,6 +25,7 @@ public class RemoteAttendanceServiceImpl implements RemoteAttendanceService { private final IAttendanceUserGroupService attendanceUserGroupService; + private final IAttendanceAreaDeviceService attendanceAreaDeviceService; public List queryAttendPersonInfo(Date date) { @@ -33,4 +36,12 @@ public class RemoteAttendanceServiceImpl implements RemoteAttendanceService { return null; } + @Override + public List queryAttendByCurrDateAndDeviceIp(Date date, String deviceIp) { + List ls = attendanceUserGroupService.queryAttendByCurrDateAndDeviceIp(date, deviceIp); + if (CollUtil.isNotEmpty(ls)) { + return BeanUtil.copyToList(ls, RemoteAttendanceUserGroupVo.class); + } + return null; + } } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/attendanceMapper/AttendanceUserGroupMapper.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/attendanceMapper/AttendanceUserGroupMapper.java index 209320db..69076ad5 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/attendanceMapper/AttendanceUserGroupMapper.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/attendanceMapper/AttendanceUserGroupMapper.java @@ -1,8 +1,12 @@ package org.dromara.property.mapper.attendanceMapper; +import org.apache.ibatis.annotations.Param; +import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; import org.dromara.property.domain.AttendanceUserGroup; import org.dromara.property.domain.vo.attendanceVo.AttendanceUserGroupVo; -import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; + +import java.util.Date; +import java.util.List; /** * 排班明细Mapper接口 @@ -12,4 +16,12 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; */ public interface AttendanceUserGroupMapper extends BaseMapperPlus { + /** + * 根据日期和设备ip 查询当前设备所在区域的排班人员信息 + * + * @param date 查询日期 + * @param deviceIp 设备ip + * @return 返回排班人员列表 + */ + List queryAttendByCurrDateAndDeviceIp(@Param("currDate") Date currDate, @Param("deviceIp") String deviceIp); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceAreaDeviceService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceAreaDeviceService.java index e230c275..0889ce12 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceAreaDeviceService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceAreaDeviceService.java @@ -6,6 +6,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.PageQuery; import java.util.Collection; +import java.util.Date; import java.util.List; /** @@ -65,4 +66,5 @@ public interface IAttendanceAreaDeviceService { * @return 是否删除成功 */ Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceUserGroupService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceUserGroupService.java index b3855ffa..c32e340b 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceUserGroupService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/attendanceService/IAttendanceUserGroupService.java @@ -75,6 +75,15 @@ public interface IAttendanceUserGroupService { */ List queryAttendPersonInfo(Date date); + TableDataInfo queryScheduleView(AttendanceUserGroupBo bo, PageQuery pageQuery); + /** + * 根据日期和设备ip 查询当前设备所在区域的排班人员信息 + * + * @param date 查询日期 + * @param deviceIp 设备ip + * @return 返回排班人员列表 + */ + List queryAttendByCurrDateAndDeviceIp(Date date, String deviceIp); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/attendanceImpl/AttendanceUserGroupServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/attendanceImpl/AttendanceUserGroupServiceImpl.java index 8221157f..6dd3a696 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/attendanceImpl/AttendanceUserGroupServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/attendanceImpl/AttendanceUserGroupServiceImpl.java @@ -299,4 +299,9 @@ public class AttendanceUserGroupServiceImpl implements IAttendanceUserGroupServi return TableDataInfo.build(attendanceArrangementVoPage); } + + @Override + public List queryAttendByCurrDateAndDeviceIp(Date date, String deviceIp) { + return this.baseMapper.queryAttendByCurrDateAndDeviceIp(date, deviceIp); + } } diff --git a/ruoyi-modules/Property/src/main/resources/mapper/Property/AttendanceUserGroupMapper.xml b/ruoyi-modules/Property/src/main/resources/mapper/Property/AttendanceUserGroupMapper.xml index b38100ed..dd6edb9b 100644 --- a/ruoyi-modules/Property/src/main/resources/mapper/Property/AttendanceUserGroupMapper.xml +++ b/ruoyi-modules/Property/src/main/resources/mapper/Property/AttendanceUserGroupMapper.xml @@ -4,4 +4,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisAlarmEventsService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisAlarmEventsService.java index f65b1a29..cda3143d 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisAlarmEventsService.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/ISisAlarmEventsService.java @@ -2,6 +2,7 @@ package org.dromara.sis.service; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.sis.domain.SisAlarmEvents; import org.dromara.sis.domain.bo.SisAlarmEventsBo; import org.dromara.sis.domain.bo.alarm.AlarmAssignmentBo; import org.dromara.sis.domain.bo.alarm.AlarmCompleteBo; @@ -79,7 +80,7 @@ public interface ISisAlarmEventsService { /** * 异步生成告警记录 */ - void createAlarmRecord(String deviceIp, Integer level, EventSmallTypeEnum type, String msg, byte[] smallImg, byte[] bigImg); + SisAlarmEvents createAlarmRecord(String deviceIp, Integer level, EventSmallTypeEnum type, String msg, byte[] smallImg, byte[] bigImg); /** * 任务分配操作 diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/IZeroSensationPassageService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/IZeroSensationPassageService.java index d5c5e353..6d8788a8 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/IZeroSensationPassageService.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/IZeroSensationPassageService.java @@ -1,7 +1,5 @@ package org.dromara.sis.service; -import cn.hutool.core.date.TimeInterval; - public interface IZeroSensationPassageService { /** diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java index efe5de5b..221113ae 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/SisAlarmEventsServiceImpl.java @@ -37,7 +37,6 @@ import org.dromara.sis.service.ISisAlarmEventProcessService; import org.dromara.sis.service.ISisAlarmEventsService; import org.dromara.sis.service.ISisDeviceManageService; import org.dromara.system.api.model.LoginUser; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -179,15 +178,14 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService { return baseMapper.deleteByIds(ids) > 0; } - @Async @Override @Transactional(rollbackFor = Exception.class) - public void createAlarmRecord(String deviceIp, Integer level, EventSmallTypeEnum type, String msg, byte[] smallImg, byte[] bigImg) { + public SisAlarmEvents createAlarmRecord(String deviceIp, Integer level, EventSmallTypeEnum type, String msg, byte[] smallImg, byte[] bigImg) { // 校验设备信息 SisDeviceManage sisDeviceManage = deviceManageService.queryByDeviceIp(deviceIp); if (sisDeviceManage == null) { log.error("设备信息不存在,放弃此条告警记录。"); - return; + return null; } // 生成时间信息 Date now = new Date(); @@ -223,7 +221,6 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService { alarmEventProcess.setReceiveTaskTag(0L); alarmEventProcess.setTenantId(""); - // 写入附件表 List ls = new ArrayList<>(); if (smallImg != null && smallImg.length > 0) { @@ -234,7 +231,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService { } Boolean flag = alarmEventAttachmentsService.batchInsert(ls); log.info("写入告警事件附件表完成, reslut={}, size={}", flag, ls.size()); - + return alarmEvents; } public SisAlarmEventAttachments createEventAttachments(byte[] img, SisAlarmEvents alarmEvents, SisDeviceManage sisDeviceManage) { diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/ZeroSensationPassageServiceImpl.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/ZeroSensationPassageServiceImpl.java index 5eb7e30f..6cf5e377 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/ZeroSensationPassageServiceImpl.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/service/impl/ZeroSensationPassageServiceImpl.java @@ -9,8 +9,12 @@ import cn.hutool.core.util.ObjectUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; +import org.dromara.property.api.RemoteAttendanceService; import org.dromara.property.api.RemoteFloorService; +import org.dromara.property.api.domain.vo.RemoteAttendanceUserGroupVo; import org.dromara.property.api.domain.vo.RemoteFloorVo; +import org.dromara.sis.domain.SisAlarmEvents; +import org.dromara.sis.domain.bo.alarm.AlarmAssignmentBo; import org.dromara.sis.domain.enums.ControlTypeEnum; import org.dromara.sis.domain.enums.EventSmallTypeEnum; import org.dromara.sis.domain.enums.RosterTypeEnum; @@ -22,12 +26,12 @@ import org.dromara.sis.sdk.huawei.HuaWeiBoxApi; import org.dromara.sis.sdk.huawei.domain.HWResult; import org.dromara.sis.sdk.smartDevices.utils.ElevatorControlTcpUtil; import org.dromara.sis.service.*; +import org.dromara.system.api.RemoteUserService; +import org.dromara.system.api.domain.vo.RemoteUserVo; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; /** * 无感通行业务服务实现 @@ -54,8 +58,13 @@ public class ZeroSensationPassageServiceImpl implements IZeroSensationPassageSer @DubboReference private RemoteFloorService remoteFloorService; + @DubboReference + private RemoteAttendanceService remoteAttendanceService; + @DubboReference + private RemoteUserService remoteUserService; @Override + @Async public void pass(String deviceIp, byte[] smallImg, byte[] bigImg) { TimeInterval interval = new TimeInterval(); // 抓拍小图 @@ -64,7 +73,7 @@ public class ZeroSensationPassageServiceImpl implements IZeroSensationPassageSer if (result.getCode() != 200) { log.info("华为盒子比对失败,msg={}", result.getMessage()); // 产生告警数据 人脸比对失败,默认为 - alarmEventsService.createAlarmRecord(deviceIp, 2, EventSmallTypeEnum.SMART_REPORT_ZJCR, "人脸比对失败", smallImg, bigImg); + handleAlarm(deviceIp, smallImg, bigImg, 2, EventSmallTypeEnum.SMART_REPORT_ZJCR, "人脸比对失败"); return; } log.info("人脸比对执行完成,耗时:{}ms", interval.intervalMs()); @@ -75,20 +84,20 @@ public class ZeroSensationPassageServiceImpl implements IZeroSensationPassageSer if (authRecord == null) { log.info("人员[{}]没有授权记录,判定为陌生人", person); // 不是内部人员 产生紧急的告警信息 - alarmEventsService.createAlarmRecord(deviceIp, 2, EventSmallTypeEnum.SMART_REPORT_ZJCR, "陌生人员入内", smallImg, bigImg); + handleAlarm(deviceIp, smallImg, bigImg, 2, EventSmallTypeEnum.SMART_REPORT_ZJCR, "陌生人员入内"); return; } else { if (Objects.equals(authRecord.getRosterType(), RosterTypeEnum.BLACK_LIST.getCode())) { - log.info("人员[{}]在黑名单中,暂不处理。", person); - alarmEventsService.createAlarmRecord(deviceIp, 3, EventSmallTypeEnum.BLACK_PERSON, "黑名单人员入内", smallImg, bigImg); + log.info("黑名单人员[{}]。", person); + handleAlarm(deviceIp, smallImg, bigImg, 3, EventSmallTypeEnum.BLACK_PERSON, "黑名单人员"); return; } } Date now = new Date(); if (DateUtil.compare(now, authRecord.getEndDate()) > 0) { - alarmEventsService.createAlarmRecord(deviceIp, 1, EventSmallTypeEnum.AUTHORIZATION_EXPIRED, "人员授权信息已过期", smallImg, bigImg); - log.info("当前人脸已过期,暂不处理。"); + handleAlarm(deviceIp, smallImg, bigImg, 1, EventSmallTypeEnum.AUTHORIZATION_EXPIRED, "人员授权信息已过期"); + log.info("当前人脸已过期。person={}", person); return; } // 获取当前设备的绑定设备信息 @@ -128,6 +137,48 @@ public class ZeroSensationPassageServiceImpl implements IZeroSensationPassageSer log.info("权限下发执行完成,耗时:{}ms", interval.intervalMs()); } + /** + * 处理告警信息 + * + * @param deviceIp 设备ip + * @param smallImg 人脸小图 + * @param bigImg 人脸大图 + * @param smallType 事件类型 + */ + private void handleAlarm(String deviceIp, byte[] smallImg, byte[] bigImg, Integer level, EventSmallTypeEnum smallType, String desc) { + // 生成告警记录 + SisAlarmEvents alarmRecord = alarmEventsService.createAlarmRecord(deviceIp, level, smallType, desc, smallImg, bigImg); + SaTokenContextMockUtil.setMockContext(() -> { + // 如果当前设备区域存在排班人员,那么惊醒自动指派操作 + List userGroupVos = remoteAttendanceService.queryAttendByCurrDateAndDeviceIp(new Date(), deviceIp); + if (CollUtil.isEmpty(userGroupVos)) { + return; + } + // 进行自动指派操作 + RemoteAttendanceUserGroupVo currHandlePerson = null; + if (userGroupVos.size() == 1) { + currHandlePerson = userGroupVos.get(0); + } else { + // 生成一个排班人员课表的随机数 + Random random = new Random(); + int randomIndex = random.nextInt(userGroupVos.size()); + currHandlePerson = userGroupVos.get(randomIndex); + } + // 获取当前指派人员的详细信息 + RemoteUserVo userInfo = remoteUserService.getUserInfoById(currHandlePerson.getEmployeeId()); + // 任务指派操作 + AlarmAssignmentBo bo = new AlarmAssignmentBo(); + bo.setAlarmId(alarmRecord.getId()); + bo.setSolveId(userInfo.getUserId()); + bo.setSolveName(userInfo.getUserName()); + bo.setSolvePhone(userInfo.getPhonenumber()); + bo.setSolveEmail(userInfo.getEmail()); + bo.setRemark("系统自动指派"); + alarmEventsService.taskAssignment(bo); + }); + } + + /** * 电梯外部按键触发 * diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/controller/SysOssController.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/controller/SysOssController.java index 1a0beb8c..f02c6bc5 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/controller/SysOssController.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/controller/SysOssController.java @@ -3,20 +3,18 @@ package org.dromara.resource.controller; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.hutool.core.util.ObjectUtil; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.NotEmpty; import lombok.RequiredArgsConstructor; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.config.annotation.DubboService; -import org.dromara.common.core.constant.GlobalConstants; import org.dromara.common.core.domain.R; import org.dromara.common.core.validate.QueryGroup; -import org.dromara.common.redis.utils.RedisUtils; -import org.dromara.common.web.core.BaseController; import org.dromara.common.log.annotation.Log; import org.dromara.common.log.enums.BusinessType; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.web.core.BaseController; import org.dromara.property.api.RemoteVisitoreGetCodeInfoService; -import org.dromara.resource.domain.QrCodeInfo; import org.dromara.resource.domain.bo.SysOssBo; import org.dromara.resource.domain.vo.SysOssUploadVo; import org.dromara.resource.domain.vo.SysOssVo; @@ -26,8 +24,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.NotEmpty; import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -46,6 +42,7 @@ public class SysOssController extends BaseController { private final ISysOssService iSysOssService; @DubboReference private RemoteVisitoreGetCodeInfoService remoteVisitoreGetCodeInfoService; + /** * 查询OSS对象存储列表 */ @@ -96,17 +93,17 @@ public class SysOssController extends BaseController { // @SaCheckPermission("system:oss:upload") @Log(title = "OSS对象存储", businessType = BusinessType.INSERT) @PostMapping(value = "/qrupload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public R codeUpload(@RequestPart("file") MultipartFile file,String code) { + public R codeUpload(@RequestPart("file") MultipartFile file, String code) { if (ObjectUtil.isNull(file)) { return R.fail("上传文件不能为空"); } String codeInfo = remoteVisitoreGetCodeInfoService.getCodeInfo(code); // QrCodeInfo info = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY+"Qrcode" + code); - if (codeInfo.isEmpty()){ + if (codeInfo.isEmpty()) { return R.fail("二维码已过期"); } - SysOssVo oss = iSysOssService.qrupload(file,codeInfo); + SysOssVo oss = iSysOssService.qrupload(file, codeInfo); SysOssUploadVo uploadVo = new SysOssUploadVo(); uploadVo.setUrl(oss.getUrl()); uploadVo.setFileName(oss.getOriginalName()); @@ -125,6 +122,16 @@ public class SysOssController extends BaseController { iSysOssService.download(ossId, response); } + /** + * 输出图片到浏览器 + * + * @param ossId OSS对象ID + */ + @GetMapping(value = "/preview/{ossId}", produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE}) + public byte [] preview(@PathVariable Long ossId) throws IOException { + return iSysOssService.downloadToByteArray(ossId); + } + /** * 删除OSS对象存储 * diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/ISysOssService.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/ISysOssService.java index 1b2a2b9c..f0957feb 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/ISysOssService.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/ISysOssService.java @@ -109,4 +109,5 @@ public interface ISysOssService { * @return byte[] 返回下载的字节数组 */ byte[] downloadToByteArray(Long ossId) throws IOException; + } diff --git a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/impl/SysOssServiceImpl.java index 48ab3a39..dc8359bc 100644 --- a/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-resource/src/main/java/org/dromara/resource/service/impl/SysOssServiceImpl.java @@ -306,5 +306,4 @@ public class SysOssServiceImpl implements ISysOssService { } return oss; } - }