1、清理功能修复;2、device在线状态放redis;3、viid传入时重查redis缓存,避免关闭的设备传入素材
This commit is contained in:
parent
ec4df2eb50
commit
f8ec52b78a
@ -209,6 +209,10 @@ public class ViidController {
|
||||
if (device == null) {
|
||||
continue;
|
||||
}
|
||||
if (!Integer.valueOf(1).equals(device.getStatus())) {
|
||||
log.info("设备状态为关闭,跳过该设备。deviceId:{}", deviceID);
|
||||
continue;
|
||||
}
|
||||
DeviceConfigEntity deviceConfig = deviceRepository.getDeviceConfig(device.getId());
|
||||
int viidMode = 0;
|
||||
if (deviceConfig != null && deviceConfig.getViidType() != null) {
|
||||
|
@ -8,6 +8,7 @@ import com.ycwl.basic.device.operator.VptPassiveStorageOperator;
|
||||
import com.ycwl.basic.model.wvp.WvpSyncReqVo;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.storage.utils.StorageUtil;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@ -35,7 +37,7 @@ public class VptController {
|
||||
@PostMapping("/scenic/{scenicId}/{taskId}/uploadUrl")
|
||||
public String uploadUrl(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId) {
|
||||
IStorageAdapter adapter = StorageFactory.use("assets-ext");
|
||||
return adapter.getUrlForUpload(VptPassiveStorageOperator.getUrlForTask(taskId));
|
||||
return adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", StorageUtil.joinPath("video-source", taskId.toString() + ".mp4"));
|
||||
}
|
||||
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
||||
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
||||
|
@ -50,4 +50,6 @@ public interface VideoMapper {
|
||||
List<MemberVideoEntity> listRelationByCreateTime(Date startTime, Date endTime);
|
||||
|
||||
VideoEntity getEntity(Long videoId);
|
||||
|
||||
int deleteNotBuyRelations(Long scenicId, Date endDate);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public class DeviceRepository {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
public static final String DEVICE_ONLINE_CACHE_KEY = "device:online_status:%s";
|
||||
public static final String DEVICE_CACHE_KEY = "device:%s";
|
||||
public static final String DEVICE_CONFIG_CACHE_KEY = "device:%s:config";
|
||||
|
||||
@ -29,9 +30,6 @@ public class DeviceRepository {
|
||||
DeviceEntity device = deviceMapper.getByDeviceId(deviceId);
|
||||
if (null != device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JSONObject.toJSONString(device));
|
||||
if (!Integer.valueOf(1).equals(device.getStatus())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return device;
|
||||
}
|
||||
@ -46,9 +44,7 @@ public class DeviceRepository {
|
||||
}
|
||||
if (null != device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device));
|
||||
if (!Integer.valueOf(1).equals(device.getStatus())) {
|
||||
return null;
|
||||
}
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device));
|
||||
} else {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS);
|
||||
}
|
||||
@ -112,10 +108,20 @@ public class DeviceRepository {
|
||||
}
|
||||
device.setOnline(online);
|
||||
device.setKeepaliveAt(keepaliveAt);
|
||||
deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
|
||||
device.setIpAddr(ipAddr);
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 60L, TimeUnit.SECONDS);
|
||||
// deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
|
||||
updateDeviceCache(device);
|
||||
}
|
||||
|
||||
public DeviceEntity getOnlineStatus(Long deviceId) {
|
||||
if (redisTemplate.hasKey(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId)), DeviceEntity.class);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDeviceCache(DeviceEntity device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device));
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getNo()), JSONObject.toJSONString(device));
|
||||
|
@ -33,6 +33,16 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
public ApiResponse<PageInfo<DeviceRespVO>> pageQuery(DeviceReqQuery deviceReqQuery) {
|
||||
PageHelper.startPage(deviceReqQuery.getPageNum(), deviceReqQuery.getPageSize());
|
||||
List<DeviceRespVO> list = deviceMapper.list(deviceReqQuery);
|
||||
for (DeviceRespVO deviceRespVO : list) {
|
||||
DeviceEntity onlineStatus = deviceRepository.getOnlineStatus(deviceRespVO.getId());
|
||||
if (onlineStatus != null) {
|
||||
deviceRespVO.setOnline(onlineStatus.getOnline());
|
||||
deviceRespVO.setKeepaliveAt(onlineStatus.getKeepaliveAt());
|
||||
} else {
|
||||
deviceRespVO.setOnline(0);
|
||||
deviceRespVO.setKeepaliveAt(null);
|
||||
}
|
||||
}
|
||||
PageInfo<DeviceRespVO> pageInfo = new PageInfo<>(list);
|
||||
return ApiResponse.success(pageInfo);
|
||||
}
|
||||
|
@ -206,30 +206,22 @@ public class FaceServiceImpl implements FaceService {
|
||||
SearchFaceRespVo scenicDbSearchResult = faceService.searchFace(face.getScenicId(), face.getFaceUrl());
|
||||
// 写死逻辑
|
||||
if (scenicDbSearchResult.getSampleListIds() != null && scenicDbSearchResult.getFirstMatchRate() != null && !scenicDbSearchResult.getSampleListIds().isEmpty()) {
|
||||
if (scenicDbSearchResult.getSampleListIds().size() < 2) {
|
||||
if (scenicDbSearchResult.getSampleListIds().size() < 5) {
|
||||
// 补救逻辑
|
||||
Long faceSampleId = scenicDbSearchResult.getSampleListIds().get(0);
|
||||
FaceSampleEntity faceSample = faceRepository.getFaceSample(faceSampleId);
|
||||
if (faceSample != null) {
|
||||
// 以这个结果为人脸库的匹配结果
|
||||
scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施1:人脸数太少只有一张");
|
||||
scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施1:人脸数太少少于5");
|
||||
}
|
||||
} else if (scenicDbSearchResult.getFirstMatchRate() > 0.75 && scenicDbSearchResult.getSampleListIds().size() < 2) {
|
||||
} else if (scenicDbSearchResult.getFirstMatchRate() > 0.7) {
|
||||
// 如果匹配度高于阈值,则使用景区第一张人脸去匹配景区库
|
||||
// 找第一张人脸
|
||||
Long faceSampleId = scenicDbSearchResult.getSampleListIds().get(0);
|
||||
FaceSampleEntity faceSample = faceRepository.getFaceSample(faceSampleId);
|
||||
if (faceSample != null) {
|
||||
// 以这个结果为人脸库的匹配结果
|
||||
scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施2:存在得分够高但是结果少");
|
||||
}
|
||||
} else if (scenicDbSearchResult.getSampleListIds().size() > 5) {
|
||||
// 补救逻辑
|
||||
Long faceSampleId = scenicDbSearchResult.getSampleListIds().get(0);
|
||||
FaceSampleEntity faceSample = faceRepository.getFaceSample(faceSampleId);
|
||||
if (faceSample != null) {
|
||||
// 以这个结果为人脸库的匹配结果
|
||||
scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施3:人脸数过多大于5");
|
||||
scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施2:存在得分够高");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,27 @@ public class FaceCleaner {
|
||||
});
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 3 * * ?")
|
||||
public void deleteNotBuyVideos(){
|
||||
ScenicReqQuery scenicQuery = new ScenicReqQuery();
|
||||
List<ScenicRespVO> scenicList = scenicMapper.list(scenicQuery);
|
||||
scenicList.parallelStream().forEach(scenic -> {
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenic.getId());
|
||||
if (scenicConfig == null) {
|
||||
log.info("当前景区{},无配置信息", scenic.getName());
|
||||
return;
|
||||
}
|
||||
if (scenicConfig.getVideoStoreDay() == null) {
|
||||
log.info("当前景区{},VLOG过期天数未设置", scenic.getName());
|
||||
return;
|
||||
}
|
||||
int expireDay = scenicConfig.getVideoStoreDay();
|
||||
Date endDate = DateUtil.offsetDay(DateUtil.beginOfDay(new Date()), -expireDay);
|
||||
int deleteCount = videoMapper.deleteNotBuyRelations(scenic.getId(), endDate);
|
||||
log.info("当前景区{},删除VLOG{}个", scenic.getName(), deleteCount);
|
||||
});
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 30 3 * * ?")
|
||||
public void deleteExpiredSource(){
|
||||
ScenicReqQuery scenicQuery = new ScenicReqQuery();
|
||||
@ -141,17 +162,17 @@ public class FaceCleaner {
|
||||
List<StorageFileObject> fileObjectList = adapter.listDir("video-source");
|
||||
fileObjectList.parallelStream().forEach(fileObject -> {
|
||||
if (list.parallelStream().filter(videoRespVO -> Objects.nonNull(videoRespVO.getVideoUrl())).noneMatch(videoRespVO -> videoRespVO.getVideoUrl().contains(fileObject.getFullPath()))){
|
||||
log.info("删除视频文件:{}", fileObject);
|
||||
log.info("删除源视频素材文件:{}", fileObject);
|
||||
adapter.deleteFile(fileObject.getFullPath());
|
||||
} else {
|
||||
log.info("视频文件存在关系:{},未删除", fileObject);
|
||||
log.info("源视频素材文件存在关系:{},未删除", fileObject);
|
||||
}
|
||||
});
|
||||
log.info("开始清理源图片素材文件");
|
||||
IStorageAdapter imageAdapter = StorageFactory.use("faces");
|
||||
List<StorageFileObject> imageFileObjectList = imageAdapter.listDir("user-photo");
|
||||
imageFileObjectList.parallelStream().forEach(fileObject -> {
|
||||
if (list.parallelStream().noneMatch(videoRespVO -> videoRespVO.getUrl().contains(fileObject.getFullPath()))){
|
||||
if (list.parallelStream().filter(videoRespVO -> Objects.nonNull(videoRespVO.getUrl())).noneMatch(videoRespVO -> videoRespVO.getUrl().contains(fileObject.getFullPath()))){
|
||||
log.info("删除图片文件:{}", fileObject);
|
||||
imageAdapter.deleteFile(fileObject.getFullPath());
|
||||
} else {
|
||||
|
@ -96,7 +96,7 @@ public class JwtTokenUtil {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JwtInfo jwtInfo = new JwtInfo();
|
||||
jwtInfo.setUserId(3950649683084447744L);
|
||||
jwtInfo.setUserId(3954940354104528896L);
|
||||
jwtInfo.setName("微信用户");
|
||||
System.out.println(generateToken(jwtInfo, 86400));
|
||||
}
|
||||
|
@ -137,6 +137,16 @@ storage:
|
||||
prefix: "user-assets/"
|
||||
url: "https://oss.zhentuai.com"
|
||||
region: "cn-shanghai"
|
||||
- name: "assets-ext"
|
||||
type: "ALI_OSS"
|
||||
config:
|
||||
endpoint: "https://oss-cn-shanghai.aliyuncs.com"
|
||||
accessKeyId: "LTAI5tCa641QdNHH9Ybg9u7V"
|
||||
accessKeySecret: "RRVIgekoqx96Fgm2Gs7eQshMShcEpk"
|
||||
bucketName: "frametour-assets"
|
||||
prefix: "user-assets/"
|
||||
url: "https://oss.zhentuai.com"
|
||||
region: "cn-shanghai"
|
||||
- name: "video"
|
||||
type: "ALI_OSS"
|
||||
config:
|
||||
|
@ -49,7 +49,7 @@
|
||||
</delete>
|
||||
<delete id="deleteNotBuyRelations">
|
||||
delete from member_source
|
||||
where member_id = #{memberId} and scenic_id = #{scenicId} and is_buy = 0 and create_time <= #{endDate}
|
||||
where scenic_id = #{scenicId} and is_buy = 0 and create_time <= #{endDate}
|
||||
</delete>
|
||||
|
||||
<select id="list" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
|
||||
|
@ -71,13 +71,13 @@
|
||||
IFNULL(count(1), 0) AS count
|
||||
FROM (
|
||||
select count(1) as count
|
||||
from `order`
|
||||
where scenic_id = #{scenicId} and pay_at is not null
|
||||
from `statistics`
|
||||
where scenic_id = #{scenicId} and type in (3,4)
|
||||
<if test="startTime!= null">
|
||||
and create_at >= #{startTime}
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime!= null">
|
||||
and create_at <= #{endTime}
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
group by member_id
|
||||
)a
|
||||
|
@ -53,6 +53,10 @@
|
||||
<delete id="deleteById">
|
||||
delete from video where id = #{id}
|
||||
</delete>
|
||||
<delete id="deleteNotBuyRelations">
|
||||
delete from member_video
|
||||
where scenic_id = #{scenicId} and is_buy = 0 and create_time < #{endTime}
|
||||
</delete>
|
||||
<select id="list" resultType="com.ycwl.basic.model.pc.video.resp.VideoRespVO">
|
||||
select v.id, v.scenic_id, template_id, task_id, worker_id, video_url, v.create_time, v.update_time,
|
||||
s.name scenicName, s.latitude, s.longitude, t.name templateName, t.price templatePrice,t.cover_url templateCoverUrl
|
||||
|
Loading…
x
Reference in New Issue
Block a user