You've already forked FrameTour-BE
feat(device): 集成 zt-device 服务
- 移除 DeviceController、DeviceService 相关代码 - 更新 ViidController、WvpController 使用 DeviceIntegrationService - 修改 DeviceFactory 创建 DeviceEntity 的方式 - 更新 DeviceRepository 使用 DeviceV2DTO -调整 CustomUploadTaskService、AppScenicServiceImpl 中的设备相关逻辑 - 移除 DeviceServiceImpl 类 - 更新 VideoPieceCleaner、VideoPieceGetter 任务类,使用 DeviceIntegrationService 获取设备信息
This commit is contained in:
@@ -3,11 +3,16 @@ package com.ycwl.basic.task;
|
||||
|
||||
import com.ycwl.basic.device.DeviceFactory;
|
||||
import com.ycwl.basic.device.operator.IDeviceStorageOperator;
|
||||
import com.ycwl.basic.mapper.DeviceMapper;
|
||||
import com.ycwl.basic.integration.common.manager.DeviceConfigManager;
|
||||
import com.ycwl.basic.integration.device.service.DeviceIntegrationService;
|
||||
import com.ycwl.basic.integration.device.dto.device.DeviceV2ListResponse;
|
||||
import com.ycwl.basic.integration.device.dto.device.DeviceV2DTO;
|
||||
import java.util.stream.Collectors;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
|
||||
import com.ycwl.basic.model.pc.device.req.DeviceReqQuery;
|
||||
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
|
||||
import com.ycwl.basic.repository.DeviceRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
@@ -24,29 +29,33 @@ import java.util.List;
|
||||
@Profile("prod")
|
||||
public class VideoPieceCleaner {
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
private DeviceIntegrationService deviceIntegrationService;
|
||||
@Autowired
|
||||
private DeviceRepository deviceRepository;
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
public void clean() {
|
||||
log.info("开始删除视频文件");
|
||||
List<DeviceEntity> deviceList = deviceMapper.listAll();
|
||||
for (DeviceEntity device : deviceList) {
|
||||
DeviceConfigEntity config = deviceMapper.getConfigByDeviceId(device.getId());
|
||||
if (config == null) {
|
||||
// 通过zt-device服务获取所有激活设备
|
||||
DeviceV2ListResponse deviceListResponse = deviceIntegrationService.listDevices(1, 10000, null, null, null, 1, null);
|
||||
List<DeviceEntity> deviceList;
|
||||
if (deviceListResponse == null) {
|
||||
return;
|
||||
}
|
||||
for (DeviceV2DTO device : deviceListResponse.getList()) {
|
||||
DeviceConfigManager config = deviceRepository.getDeviceConfigManager(device.getId());
|
||||
DeviceConfigEntity dConfig = deviceRepository.getDeviceConfig(device.getId());
|
||||
Integer storeExpireDay = config.getInteger("store_expire_day");
|
||||
if (storeExpireDay == null || storeExpireDay <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (config.getStoreExpireDay() == null) {
|
||||
continue;
|
||||
}
|
||||
if (config.getStoreExpireDay() <= 0) {
|
||||
continue;
|
||||
}
|
||||
IDeviceStorageOperator storageOperator = DeviceFactory.getDeviceStorageOperator(device, config);
|
||||
IDeviceStorageOperator storageOperator = DeviceFactory.getDeviceStorageOperator(device, dConfig);
|
||||
if (storageOperator == null) {
|
||||
continue;
|
||||
}
|
||||
storageOperator.removeFilesBeforeDate(new Date(System.currentTimeMillis() - config.getStoreExpireDay() * 24 * 60 * 60 * 1000));
|
||||
storageOperator.removeFilesBeforeDate(new Date(System.currentTimeMillis() - storeExpireDay * 24 * 60 * 60 * 1000));
|
||||
log.info("删除视频文件完成");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,6 +16,8 @@ import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||
import com.ycwl.basic.mapper.SourceMapper;
|
||||
import com.ycwl.basic.model.mobile.order.IsBuyRespVO;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
|
||||
import com.ycwl.basic.integration.device.service.DeviceIntegrationService;
|
||||
import com.ycwl.basic.integration.device.dto.device.DeviceV2DTO;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
|
||||
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
|
||||
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
||||
@@ -77,6 +79,8 @@ public class VideoPieceGetter {
|
||||
private VideoReUploader videoReUploader;
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
@Autowired
|
||||
private DeviceIntegrationService deviceIntegrationService;
|
||||
|
||||
@Data
|
||||
public static class Task {
|
||||
@@ -145,7 +149,7 @@ public class VideoPieceGetter {
|
||||
Map<Long, Long> pairDeviceMap = new ConcurrentHashMap<>();
|
||||
if (!list.isEmpty()) {
|
||||
Long scenicId = list.getFirst().getScenicId();
|
||||
List<DeviceEntity> allDeviceByScenicId = deviceRepository.getAllDeviceByScenicId(scenicId);
|
||||
List<DeviceV2DTO> allDeviceByScenicId = deviceRepository.getAllDeviceByScenicId(scenicId);
|
||||
allDeviceByScenicId.forEach(device -> {
|
||||
Long deviceId = device.getId();
|
||||
DeviceConfigManager deviceConfig = deviceRepository.getDeviceConfigManager(deviceId);
|
||||
@@ -256,16 +260,21 @@ public class VideoPieceGetter {
|
||||
}
|
||||
|
||||
private boolean doCut(Long deviceId, Long faceSampleId, Date baseTime, Task task) {
|
||||
DeviceEntity device = deviceRepository.getDevice(deviceId);
|
||||
// 通过zt-device服务获取设备信息
|
||||
DeviceV2DTO deviceV2 = deviceIntegrationService.getDevice(deviceId);
|
||||
if (deviceV2 == null) {
|
||||
log.warn("设备不存在,设备ID: {}", deviceId);
|
||||
return false;
|
||||
}
|
||||
DeviceConfigManager config = deviceRepository.getDeviceConfigManager(deviceId);
|
||||
DeviceConfigEntity dConfig = deviceRepository.getDeviceConfig(deviceId);
|
||||
|
||||
SourceEntity source = sourceMapper.querySameVideo(faceSampleId, device.getId());
|
||||
SourceEntity source = sourceMapper.querySameVideo(faceSampleId, deviceV2.getId());
|
||||
|
||||
if (source == null || task.force) {
|
||||
BigDecimal cutPre = config.getBigDecimal("cut_pre", BigDecimal.valueOf(5L));
|
||||
BigDecimal cutPost = config.getBigDecimal("cut_post", BigDecimal.valueOf(5L));
|
||||
IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, dConfig);
|
||||
IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(deviceV2, dConfig);
|
||||
if (pieceGetter == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -316,7 +325,7 @@ public class VideoPieceGetter {
|
||||
}
|
||||
sourceEntity.setVideoUrl(url);
|
||||
sourceEntity.setFaceSampleId(faceSampleId);
|
||||
sourceEntity.setScenicId(device.getScenicId());
|
||||
sourceEntity.setScenicId(deviceV2.getScenicId());
|
||||
sourceEntity.setDeviceId(deviceId);
|
||||
sourceEntity.setType(1);
|
||||
if (task.memberId != null && task.faceId != null) {
|
||||
@@ -324,9 +333,9 @@ public class VideoPieceGetter {
|
||||
videoSource.setMemberId(task.getMemberId());
|
||||
videoSource.setType(1);
|
||||
videoSource.setFaceId(task.getFaceId());
|
||||
videoSource.setScenicId(device.getScenicId());
|
||||
videoSource.setScenicId(deviceV2.getScenicId());
|
||||
videoSource.setSourceId(sourceEntity.getId());
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), device.getScenicId(), 1, task.getFaceId());
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), deviceV2.getScenicId(), 1, task.getFaceId());
|
||||
if (isBuy.isBuy()) { // 如果用户买过
|
||||
videoSource.setIsBuy(1);
|
||||
} else if (isBuy.isFree()) { // 全免费逻辑
|
||||
@@ -352,10 +361,10 @@ public class VideoPieceGetter {
|
||||
int count = sourceMapper.hasRelationTo(task.getMemberId(), source.getId(), 1);
|
||||
if (count <= 0) {
|
||||
// 没有关联
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), device.getScenicId(), 1, task.getFaceId());
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), deviceV2.getScenicId(), 1, task.getFaceId());
|
||||
MemberSourceEntity videoSource = new MemberSourceEntity();
|
||||
videoSource.setId(SnowFlakeUtil.getLongId());
|
||||
videoSource.setScenicId(device.getScenicId());
|
||||
videoSource.setScenicId(deviceV2.getScenicId());
|
||||
videoSource.setFaceId(task.getFaceId());
|
||||
videoSource.setMemberId(task.getMemberId());
|
||||
videoSource.setType(1);
|
||||
|
Reference in New Issue
Block a user