|
@@ -4,21 +4,26 @@ import cn.reghao.file.api.iface.OssService;
|
|
|
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
import cn.reghao.jutil.jdk.db.Page;
|
|
import cn.reghao.jutil.jdk.db.Page;
|
|
|
import cn.reghao.jutil.jdk.result.Result;
|
|
import cn.reghao.jutil.jdk.result.Result;
|
|
|
-import cn.reghao.jutil.tool.id.SnowFlake;
|
|
|
|
|
|
|
+import cn.reghao.jutil.jdk.result.ResultStatus;
|
|
|
import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
|
|
import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
|
|
|
|
|
+import cn.reghao.tnb.common.auth.UserContext;
|
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.CamDeviceMapper;
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.CamDeviceMapper;
|
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.CamRecordMapper;
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.CamRecordMapper;
|
|
|
|
|
+import cn.reghao.tnb.content.app.disk.model.constant.AlbumType;
|
|
|
import cn.reghao.tnb.content.app.disk.model.dto.CamRecordDto;
|
|
import cn.reghao.tnb.content.app.disk.model.dto.CamRecordDto;
|
|
|
import cn.reghao.tnb.content.app.disk.model.po.CamDevice;
|
|
import cn.reghao.tnb.content.app.disk.model.po.CamDevice;
|
|
|
import cn.reghao.tnb.content.app.disk.model.po.CamRecord;
|
|
import cn.reghao.tnb.content.app.disk.model.po.CamRecord;
|
|
|
import cn.reghao.tnb.content.app.disk.model.query.CamDeviceQuery;
|
|
import cn.reghao.tnb.content.app.disk.model.query.CamDeviceQuery;
|
|
|
import cn.reghao.tnb.content.app.disk.model.vo.*;
|
|
import cn.reghao.tnb.content.app.disk.model.vo.*;
|
|
|
|
|
+import cn.reghao.tnb.content.app.util.IdService;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
@@ -28,16 +33,19 @@ import java.util.stream.Collectors;
|
|
|
public class CamRecordService {
|
|
public class CamRecordService {
|
|
|
@DubboReference(check = false, timeout = 60_000)
|
|
@DubboReference(check = false, timeout = 60_000)
|
|
|
private OssService ossService;
|
|
private OssService ossService;
|
|
|
- private int channelCode = 107;
|
|
|
|
|
|
|
+ private int camChannelCode = 107;
|
|
|
|
|
|
|
|
- private final SnowFlake idGenerator;
|
|
|
|
|
|
|
+ private final IdService idService;
|
|
|
private final CamDeviceMapper camDeviceMapper;
|
|
private final CamDeviceMapper camDeviceMapper;
|
|
|
private final CamRecordMapper camRecordMapper;
|
|
private final CamRecordMapper camRecordMapper;
|
|
|
|
|
+ private final DiskShareService diskShareService;
|
|
|
|
|
|
|
|
- public CamRecordService(CamDeviceMapper camDeviceMapper, CamRecordMapper camRecordMapper) {
|
|
|
|
|
- this.idGenerator = new SnowFlake(1L, 1L);
|
|
|
|
|
|
|
+ public CamRecordService(IdService idService, CamDeviceMapper camDeviceMapper,
|
|
|
|
|
+ CamRecordMapper camRecordMapper, DiskShareService diskShareService) {
|
|
|
|
|
+ this.idService = idService;
|
|
|
this.camDeviceMapper = camDeviceMapper;
|
|
this.camDeviceMapper = camDeviceMapper;
|
|
|
this.camRecordMapper = camRecordMapper;
|
|
this.camRecordMapper = camRecordMapper;
|
|
|
|
|
+ this.diskShareService = diskShareService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Result addCamRecord(CamRecordDto camRecordDto) {
|
|
public Result addCamRecord(CamRecordDto camRecordDto) {
|
|
@@ -51,14 +59,20 @@ public class CamRecordService {
|
|
|
return Result.fail("cam not exist");
|
|
return Result.fail("cam not exist");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- long camId = camDeviceList.get(0).getCamId();
|
|
|
|
|
|
|
+ CamDevice camDevice = camDeviceList.get(0);
|
|
|
|
|
+ long loginUser = UserContext.getUserId();
|
|
|
|
|
+ if (camDevice.getAddBy() != loginUser) {
|
|
|
|
|
+ return Result.fail("not owner");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ long camId = camDevice.getCamId();
|
|
|
try {
|
|
try {
|
|
|
int videoChannelCode = camRecordDto.getVideoChannelCode();
|
|
int videoChannelCode = camRecordDto.getVideoChannelCode();
|
|
|
String videoFileId = camRecordDto.getVideoFileId();
|
|
String videoFileId = camRecordDto.getVideoFileId();
|
|
|
VideoInfo videoInfo = ossService.getVideoInfo(videoChannelCode, videoFileId);
|
|
VideoInfo videoInfo = ossService.getVideoInfo(videoChannelCode, videoFileId);
|
|
|
|
|
|
|
|
int duration = videoInfo.getDuration();
|
|
int duration = videoInfo.getDuration();
|
|
|
- long recordId = idGenerator.nextId();
|
|
|
|
|
|
|
+ long recordId = idService.getLongId();
|
|
|
long startAt = camRecordDto.getStartAt();
|
|
long startAt = camRecordDto.getStartAt();
|
|
|
LocalDateTime startAt1 = DateTimeConverter.localDateTime(startAt);
|
|
LocalDateTime startAt1 = DateTimeConverter.localDateTime(startAt);
|
|
|
CamRecord camRecord = new CamRecord(camId, recordId, videoFileId, duration, startAt1);
|
|
CamRecord camRecord = new CamRecord(camId, recordId, videoFileId, duration, startAt1);
|
|
@@ -71,6 +85,26 @@ public class CamRecordService {
|
|
|
return Result.fail("");
|
|
return Result.fail("");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private Result checkCamOwner(long camId) {
|
|
|
|
|
+ CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
|
|
|
|
|
+ .camId(camId)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Page page = new Page(1, 1);
|
|
|
|
|
+ List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
|
|
|
|
|
+ if (camDeviceList.isEmpty()) {
|
|
|
|
|
+ return Result.fail("cam not exist");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CamDevice camDevice = camDeviceList.get(0);
|
|
|
|
|
+ long loginUser = UserContext.getUserId();
|
|
|
|
|
+ Set<Long> sharedCamIds = new HashSet<>(diskShareService.getSharedAlbumIds(AlbumType.cam.getValue(), loginUser));
|
|
|
|
|
+ if (camDevice.getAddBy() != loginUser && !sharedCamIds.contains(camId)) {
|
|
|
|
|
+ return Result.fail("not owner");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取某天的监控录像
|
|
* 获取某天的监控录像
|
|
|
*
|
|
*
|
|
@@ -79,12 +113,21 @@ public class CamRecordService {
|
|
|
* @date 2024-08-31 18:08:972
|
|
* @date 2024-08-31 18:08:972
|
|
|
*/
|
|
*/
|
|
|
public List<CamRecordInfo> getCamRecordByDay(Long camId, String dayStr) {
|
|
public List<CamRecordInfo> getCamRecordByDay(Long camId, String dayStr) {
|
|
|
|
|
+ Result result = checkCamOwner(camId);
|
|
|
|
|
+ if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return camRecordMapper.findByCamIdAndStartAt(camId, dayStr);
|
|
return camRecordMapper.findByCamIdAndStartAt(camId, dayStr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public CamRecordDetail getCamRecordDetail(long recordId) {
|
|
public CamRecordDetail getCamRecordDetail(long recordId) {
|
|
|
CamRecord camRecord = camRecordMapper.findByRecordId(recordId);
|
|
CamRecord camRecord = camRecordMapper.findByRecordId(recordId);
|
|
|
- return camRecord == null ? null : getCamRecordDetail(camRecord);
|
|
|
|
|
|
|
+ if (camRecord != null && checkCamOwner(camRecord.getCamId()).getCode() == ResultStatus.SUCCESS.getCode()) {
|
|
|
|
|
+ return getCamRecordDetail(camRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -95,13 +138,24 @@ public class CamRecordService {
|
|
|
* @date 2024-08-31 20:08:873
|
|
* @date 2024-08-31 20:08:873
|
|
|
*/
|
|
*/
|
|
|
public List<String> getDaysInMonth(Long camId, String yearMonth) {
|
|
public List<String> getDaysInMonth(Long camId, String yearMonth) {
|
|
|
|
|
+ Result result = checkCamOwner(camId);
|
|
|
|
|
+ if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return camRecordMapper.findGroupByYearMonth(camId, yearMonth);
|
|
return camRecordMapper.findGroupByYearMonth(camId, yearMonth);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private CamRecordDetail getCamRecordDetail(CamRecord camRecord) {
|
|
private CamRecordDetail getCamRecordDetail(CamRecord camRecord) {
|
|
|
|
|
+ long camId = camRecord.getCamId();
|
|
|
|
|
+ Result result = checkCamOwner(camId);
|
|
|
|
|
+ if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
String videoFileId = camRecord.getVideoFileId();
|
|
String videoFileId = camRecord.getVideoFileId();
|
|
|
try {
|
|
try {
|
|
|
- String signedUrl = ossService.getSignedUrl(channelCode, videoFileId);
|
|
|
|
|
|
|
+ String signedUrl = ossService.getSignedUrl(camChannelCode, videoFileId);
|
|
|
return new CamRecordDetail(camRecord, signedUrl);
|
|
return new CamRecordDetail(camRecord, signedUrl);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|