feat(sis):
- 图像库图片改为通过ossId获取 - SisPersonLibImg 字段 imgUrl 更改为 imgOssId,类型同步更改 - 移除SisDeviceManage 中的 accessControlId 字段
This commit is contained in:
parent
d2638de4e4
commit
9a1a87800f
@ -13,6 +13,7 @@
|
||||
<module>ruoyi-api-system</module>
|
||||
<module>ruoyi-api-resource</module>
|
||||
<module>ruoyi-api-workflow</module>
|
||||
<module>property-api</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>ruoyi-api</artifactId>
|
||||
|
@ -1,8 +1,10 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.resource.api.domain.RemoteFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -35,4 +37,12 @@ public interface RemoteFileService {
|
||||
* @return 列表
|
||||
*/
|
||||
List<RemoteFile> selectByIds(String ossIds);
|
||||
|
||||
/**
|
||||
* 文件下载方法,支持一次性下载完整文件
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
* @return byte[] 返回下载的字节数组
|
||||
*/
|
||||
byte[] downloadToByteArray(Long ossId) throws IOException;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.resource.api.domain.RemoteFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -50,4 +52,14 @@ public class RemoteFileServiceMock implements RemoteFileService {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载方法,支持一次性下载完整文件
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
* @return byte[] 返回下载的字节数组
|
||||
*/
|
||||
public byte[] downloadToByteArray(Long ossId) throws IOException {
|
||||
log.warn("服务调用异常 -> 降级处理");
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
@ -265,6 +265,37 @@ public class OssClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件从 Amazon S3 到 byte[]
|
||||
*
|
||||
* @param key 文件在 Amazon S3 中的对象键
|
||||
* @return byte[] 返回下载的字节数组
|
||||
* @throws OssException 如果下载失败,抛出自定义异常
|
||||
*/
|
||||
public byte[] downloadToByteArray(String key) {
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
// 构建下载请求
|
||||
DownloadRequest<ResponseInputStream<GetObjectResponse>> downloadRequest = DownloadRequest.builder()
|
||||
// 文件对象
|
||||
.getObjectRequest(y -> y.bucket(properties.getBucketName())
|
||||
.key(key)
|
||||
.build())
|
||||
.addTransferListener(LoggingTransferListener.create())
|
||||
// 使用订阅转换器
|
||||
.responseTransformer(AsyncResponseTransformer.toBlockingInputStream())
|
||||
.build();
|
||||
// 使用 S3TransferManager 下载文件
|
||||
Download<ResponseInputStream<GetObjectResponse>> responseFuture = transferManager.download(downloadRequest);
|
||||
// 输出到流中
|
||||
try (ResponseInputStream<GetObjectResponse> responseStream = responseFuture.completionFuture().join().result()) { // auto-closeable stream
|
||||
responseStream.transferTo(out); // 阻塞调用线程 blocks the calling thread
|
||||
}
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new OssException("文件下载失败,错误信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除云存储服务中指定路径下文件
|
||||
*
|
||||
|
@ -68,11 +68,6 @@ public class SisDeviceManage extends BaseEntity {
|
||||
*/
|
||||
private Integer vcrPort;
|
||||
|
||||
/**
|
||||
* 门禁id
|
||||
*/
|
||||
private Long accessControlId;
|
||||
|
||||
/**
|
||||
* 设备账号
|
||||
*/
|
||||
|
@ -39,9 +39,9 @@ public class SisPersonLibImg extends TenantEntity {
|
||||
private String imgName;
|
||||
|
||||
/**
|
||||
* 图片的存储地址
|
||||
* 图片ossId
|
||||
*/
|
||||
private String imgUrl;
|
||||
private Long imgOssId;
|
||||
|
||||
/**
|
||||
* 性别 1:男 2:女 99:未说明
|
||||
|
@ -66,11 +66,6 @@ public class SisDeviceManageBo extends BaseEntity {
|
||||
*/
|
||||
private Long vcrPort;
|
||||
|
||||
/**
|
||||
* 门禁id
|
||||
*/
|
||||
private Long accessControlId;
|
||||
|
||||
/**
|
||||
* 设备账号
|
||||
*/
|
||||
|
@ -39,10 +39,10 @@ public class SisPersonLibImgBo extends BaseEntity {
|
||||
private String imgName;
|
||||
|
||||
/**
|
||||
* 图片的存储地址
|
||||
* 图片ossId
|
||||
*/
|
||||
@NotBlank(message = "图片的存储地址不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String imgUrl;
|
||||
@NotBlank(message = "图片ossId不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String imgOssId;
|
||||
|
||||
/**
|
||||
* 性别 1:男2:女 99:未说明
|
||||
|
@ -73,12 +73,6 @@ public class SisDeviceManageVo implements Serializable {
|
||||
@ExcelProperty(value = "录像机端口")
|
||||
private Integer vcrPort;
|
||||
|
||||
/**
|
||||
* 门禁id
|
||||
*/
|
||||
@ExcelProperty(value = "门禁id")
|
||||
private Long accessControlId;
|
||||
|
||||
/**
|
||||
* 设备账号
|
||||
*/
|
||||
|
@ -45,10 +45,10 @@ public class SisPersonLibImgVo implements Serializable {
|
||||
private String imgName;
|
||||
|
||||
/**
|
||||
* 图片的存储地址
|
||||
* 图片ossId
|
||||
*/
|
||||
@ExcelProperty(value = "图片的存储地址")
|
||||
private String imgUrl;
|
||||
@ExcelProperty(value = "图片ossId")
|
||||
private Long imgOssId;
|
||||
|
||||
/**
|
||||
* 性别 1:男
|
||||
|
@ -4,11 +4,14 @@ import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.resource.api.RemoteFileService;
|
||||
import org.dromara.sis.domain.SisAuthRecord;
|
||||
import org.dromara.sis.domain.bo.SingleAuthRecordBo;
|
||||
import org.dromara.sis.domain.bo.SisAuthRecordBo;
|
||||
@ -57,6 +60,9 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
||||
private final ISisLibDeviceImgRefService sisLibDeviceImgRefService;
|
||||
private final ISisAccessControlDeviceService sisAccessControlDeviceService;
|
||||
|
||||
@DubboReference
|
||||
private final RemoteFileService remoteFileService;
|
||||
|
||||
/**
|
||||
* 查询授权记录
|
||||
*
|
||||
@ -142,14 +148,18 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
||||
List<SisAccessControlVo> acList = sisAccessControlService.queryListByIds(bo.getAcIds());
|
||||
Assert.notEmpty(acList, "门禁设备不存在!");
|
||||
|
||||
|
||||
|
||||
try {
|
||||
log.info("开始对宇视盒子下发照片,图片:{}、设备:{}", bo.getImgIds(), eqpIds);
|
||||
|
||||
for (SisPersonLibImgVo imgVo : imgList) {
|
||||
for (Long eqpId : eqpIds) {
|
||||
long eqp_lib_id;
|
||||
Integer eqp_lib_img_id;
|
||||
byte[] imageByte = Files.readAllBytes(Paths.get(imgVo.getImgUrl()));
|
||||
|
||||
byte[] imageByte = remoteFileService.downloadToByteArray(imgVo.getImgOssId());
|
||||
Assert.notNull(imageByte, "图片下载失败");
|
||||
// byte[] imageByte = Files.readAllBytes(Paths.get(imgVo.getImgUrl()));
|
||||
|
||||
SisAccessControlDeviceVo vo = sisAccessControlDeviceService.queryById(eqpId);
|
||||
Assert.notNull(vo, "门禁控制设备不存在,id=" + eqpId);
|
||||
@ -207,7 +217,8 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
||||
|
||||
log.info("开始写入E8平台,图片:{}、门禁:{}", bo.getImgIds(), bo.getAcIds());
|
||||
for (SisPersonLibImgVo imgVo : imgList) {
|
||||
byte[] imageByte = Files.readAllBytes(Paths.get(imgVo.getImgUrl()));
|
||||
byte[] imageByte = remoteFileService.downloadToByteArray(imgVo.getImgOssId());
|
||||
Assert.notNull(imageByte, "图片下载失败");
|
||||
|
||||
log.info("E8平台上传图片,{}", imgVo.getId());
|
||||
String url = e8VouchService.uploadFace(imageByte);
|
||||
|
@ -81,7 +81,6 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
lqw.eq(bo.getParentId() != null, SisDeviceManage::getParentId, bo.getParentId());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getVcrIp()), SisDeviceManage::getVcrIp, bo.getVcrIp());
|
||||
lqw.eq(bo.getVcrPort() != null, SisDeviceManage::getVcrPort, bo.getVcrPort());
|
||||
lqw.eq(bo.getAccessControlId() != null, SisDeviceManage::getAccessControlId, bo.getAccessControlId());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
|
||||
lqw.orderByAsc(SisPersonLibImg::getId);
|
||||
lqw.eq(bo.getLibId() != null, SisPersonLibImg::getLibId, bo.getLibId());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getImgName()), SisPersonLibImg::getImgName, bo.getImgName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getImgUrl()), SisPersonLibImg::getImgUrl, bo.getImgUrl());
|
||||
lqw.eq(bo.getImgOssId() != null, SisPersonLibImg::getImgOssId, bo.getImgOssId());
|
||||
lqw.eq(bo.getSex() != null, SisPersonLibImg::getSex, bo.getSex());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getEmail()), SisPersonLibImg::getEmail, bo.getEmail());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getTel()), SisPersonLibImg::getTel, bo.getTel());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.dromara.resource.dubbo;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
@ -18,6 +19,7 @@ import org.dromara.resource.service.ISysOssService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -86,4 +88,14 @@ public class RemoteFileServiceImpl implements RemoteFileService {
|
||||
List<SysOssVo> sysOssVos = sysOssService.listByIds(StringUtils.splitTo(ossIds, Convert::toLong));
|
||||
return MapstructUtils.convert(sysOssVos, RemoteFile.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载方法,支持一次性下载完整文件
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
* @return byte[] 返回下载的字节数组
|
||||
*/
|
||||
public byte[] downloadToByteArray(Long ossId) throws IOException {
|
||||
return sysOssService.downloadToByteArray(ossId);
|
||||
}
|
||||
}
|
||||
|
@ -92,4 +92,12 @@ public interface ISysOssService {
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 文件下载方法,支持一次性下载完整文件
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
* @return byte[] 返回下载的字节数组
|
||||
*/
|
||||
byte[] downloadToByteArray(Long ossId) throws IOException;
|
||||
}
|
||||
|
@ -159,6 +159,24 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||
storage.download(sysOss.getFileName(), response.getOutputStream(), response::setContentLengthLong);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载方法,支持一次性下载完整文件
|
||||
*
|
||||
* @param ossId OSS对象ID
|
||||
* @return byte[] 返回下载的字节数组
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadToByteArray(Long ossId) throws IOException {
|
||||
SysOssVo sysOss = SpringUtils.getAopProxy(this).getById(ossId);
|
||||
if (ObjectUtil.isNull(sysOss)) {
|
||||
throw new ServiceException("文件数据不存在!");
|
||||
}
|
||||
// FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
|
||||
// response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
|
||||
OssClient storage = OssFactory.instance(sysOss.getService());
|
||||
return storage.downloadToByteArray(sysOss.getFileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传 MultipartFile 到对象存储服务,并保存文件信息到数据库
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user