优化收藏功能

pull/1242/head
648540858 2023-10-25 14:45:45 +08:00
parent cccfdace5b
commit 79f3ca9791
8 changed files with 20 additions and 55 deletions

View File

@ -280,7 +280,6 @@ create table wvp_cloud_record (
folder character varying(255), folder character varying(255),
file_path character varying(255), file_path character varying(255),
collect bool default false, collect bool default false,
reserve bool default false,
file_size bigint, file_size bigint,
time_len bigint, time_len bigint,
constraint uk_stream_push_app_stream_path unique (app, stream, file_path) constraint uk_stream_push_app_stream_path unique (app, stream, file_path)

View File

@ -280,7 +280,6 @@ create table wvp_cloud_record (
folder character varying(255), folder character varying(255),
file_path character varying(255), file_path character varying(255),
collect bool default false, collect bool default false,
reserve bool default false,
file_size int8, file_size int8,
time_len int8, time_len int8,
constraint uk_stream_push_app_stream_path unique (app, stream, file_path) constraint uk_stream_push_app_stream_path unique (app, stream, file_path)

View File

@ -19,7 +19,6 @@ create table wvp_cloud_record (
folder character varying(255), folder character varying(255),
file_path character varying(255), file_path character varying(255),
collect bool default false, collect bool default false,
reserve bool default false,
file_size bigint, file_size bigint,
time_len bigint, time_len bigint,
constraint uk_stream_push_app_stream_path unique (app, stream, file_path) constraint uk_stream_push_app_stream_path unique (app, stream, file_path)

View File

@ -19,7 +19,6 @@ create table wvp_cloud_record (
folder character varying(255), folder character varying(255),
file_path character varying(255), file_path character varying(255),
collect bool default false, collect bool default false,
reserve bool default false,
file_size int8, file_size int8,
time_len int8, time_len int8,
constraint uk_stream_push_app_stream_path unique (app, stream, file_path) constraint uk_stream_push_app_stream_path unique (app, stream, file_path)

View File

@ -43,11 +43,11 @@ public interface ICloudRecordService {
/** /**
* *
*/ */
void changeCollect(String type, boolean result, String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String collectType); int changeCollect(boolean result, String app, String stream, String mediaServerId, String startTime, String endTime, String callId);
/** /**
* *
*/ */
void changeCollectById(Integer recordId, String collectType, boolean result); int changeCollectById(Integer recordId, boolean result);
} }

View File

@ -166,7 +166,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
} }
@Override @Override
public void changeCollect(String type, boolean result, String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String collectType) { public int changeCollect(boolean result, String app, String stream, String mediaServerId, String startTime, String endTime, String callId) {
// 开始时间和结束时间在数据库中都是以秒为单位的 // 开始时间和结束时间在数据库中都是以秒为单位的
Long startTimeStamp = null; Long startTimeStamp = null;
Long endTimeStamp = null; Long endTimeStamp = null;
@ -203,34 +203,24 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到待收藏的视频"); throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到待收藏的视频");
} }
int limitCount = 50; int limitCount = 50;
int resultCount = 0;
if (all.size() > limitCount) { if (all.size() > limitCount) {
for (int i = 0; i < all.size(); i += limitCount) { for (int i = 0; i < all.size(); i += limitCount) {
int toIndex = i + limitCount; int toIndex = i + limitCount;
if (i + limitCount > all.size()) { if (i + limitCount > all.size()) {
toIndex = all.size(); toIndex = all.size();
} }
if ("collect".equals(collectType)) { resultCount += cloudRecordServiceMapper.updateCollectList(result, all.subList(i, toIndex));
cloudRecordServiceMapper.updateCollectList(result, all.subList(i, toIndex));
}else if ("reserve".equals(collectType)) {
cloudRecordServiceMapper.updateReserveList(result, all.subList(i, toIndex));
}
} }
}else { }else {
if ("collect".equals(collectType)) { resultCount = cloudRecordServiceMapper.updateCollectList(result, all);
cloudRecordServiceMapper.updateCollectList(result, all);
}else if ("reserve".equals(collectType)) {
cloudRecordServiceMapper.updateReserveList(result, all);
}
} }
return resultCount;
} }
@Override @Override
public void changeCollectById(Integer recordId, String collectType, boolean result) { public int changeCollectById(Integer recordId, boolean result) {
if ("collect".equals(collectType)) { return cloudRecordServiceMapper.changeCollectById(result, recordId);
cloudRecordServiceMapper.changeCollectById(result, recordId);
}else if ("reserve".equals(collectType)) {
cloudRecordServiceMapper.changeReserveById(result, recordId);
}
} }
} }

View File

@ -79,7 +79,7 @@ public interface CloudRecordServiceMapper {
"update wvp_cloud_record set collect = #{collect} where file_path in " + "update wvp_cloud_record set collect = #{collect} where file_path in " +
" <foreach collection='cloudRecordItemList' item='item' open='(' separator=',' close=')' > #{item.filePath}</foreach>" + " <foreach collection='cloudRecordItemList' item='item' open='(' separator=',' close=')' > #{item.filePath}</foreach>" +
" </script>") " </script>")
void updateCollectList(@Param("collect") boolean collect, List<CloudRecordItem> cloudRecordItemList); int updateCollectList(@Param("collect") boolean collect, List<CloudRecordItem> cloudRecordItemList);
@Delete(" <script>" + @Delete(" <script>" +
"delete from wvp_cloud_record where media_server_id=#{mediaServerId} file_path in " + "delete from wvp_cloud_record where media_server_id=#{mediaServerId} file_path in " +
@ -91,26 +91,16 @@ public interface CloudRecordServiceMapper {
@Select(" <script>" + @Select(" <script>" +
"select file_path" + "select file_path" +
" from wvp_cloud_record " + " from wvp_cloud_record " +
" where collect = false and reserve = false " + " where collect = false " +
" <if test= 'endTimeStamp != null '> and start_time &lt;= #{endTimeStamp}</if>" + " <if test= 'endTimeStamp != null '> and start_time &lt;= #{endTimeStamp}</if>" +
" <if test= 'callId != null '> and call_id = #{callId}</if>" + " <if test= 'callId != null '> and call_id = #{callId}</if>" +
" <if test= 'mediaServerId != null ' > and media_server_id = #{mediaServerId} </if>" + " <if test= 'mediaServerId != null ' > and media_server_id = #{mediaServerId} </if>" +
" </script>") " </script>")
List<String> queryRecordFilePathListForDelete(@Param("endTimeStamp")Long endTimeStamp, String mediaServerId); List<String> queryRecordFilePathListForDelete(@Param("endTimeStamp")Long endTimeStamp, String mediaServerId);
@Update(" <script>" +
"update wvp_cloud_record set reserve = #{reserve} where file_path in " +
" <foreach collection='cloudRecordItems' item='item' open='(' separator=',' close=')' > #{item.filePath}</foreach>" +
" </script>")
void updateReserveList(@Param("reserve") boolean reserve,List<CloudRecordItem> cloudRecordItems);
@Update(" <script>" + @Update(" <script>" +
"update wvp_cloud_record set collect = #{collect} where id = #{recordId} " + "update wvp_cloud_record set collect = #{collect} where id = #{recordId} " +
" </script>") " </script>")
void changeCollectById(@Param("collect") boolean collect, @Param("recordId") Integer recordId); int changeCollectById(@Param("collect") boolean collect, @Param("recordId") Integer recordId);
@Update(" <script>" +
"update wvp_cloud_record set reserve = #{reserve} where id = #{recordId} " +
" </script>")
void changeReserveById(@Param("reserve") boolean reserve, Integer recordId);
} }

View File

@ -188,24 +188,20 @@ public class CloudRecordController {
@Parameter(name = "startTime", description = "鉴权ID", required = false) @Parameter(name = "startTime", description = "鉴权ID", required = false)
@Parameter(name = "endTime", description = "鉴权ID", required = false) @Parameter(name = "endTime", description = "鉴权ID", required = false)
@Parameter(name = "callId", description = "鉴权ID", required = false) @Parameter(name = "callId", description = "鉴权ID", required = false)
@Parameter(name = "collectType", description = "收藏类型, collect/reserve", required = false) @Parameter(name = "recordId", description = "录像记录的ID用于精准收藏一个视频文件", required = false)
public void addCollect( public int addCollect(
@RequestParam(required = false) String app, @RequestParam(required = false) String app,
@RequestParam(required = false) String stream, @RequestParam(required = false) String stream,
@RequestParam(required = false) String mediaServerId, @RequestParam(required = false) String mediaServerId,
@RequestParam(required = false) String startTime, @RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String callId, @RequestParam(required = false) String callId,
@RequestParam(required = false) String collectType,
@RequestParam(required = false) Integer recordId @RequestParam(required = false) Integer recordId
){ ){
if (!"collect".equals(collectType) && !"reserve".equals(collectType)) {
collectType = "collect";
}
if (recordId != null) { if (recordId != null) {
cloudRecordService.changeCollectById(recordId, collectType, true); return cloudRecordService.changeCollectById(recordId, true);
}else { }else {
cloudRecordService.changeCollect(collectType, true, app, stream, mediaServerId, startTime, endTime, callId, collectType); return cloudRecordService.changeCollect(true, app, stream, mediaServerId, startTime, endTime, callId);
} }
} }
@ -218,27 +214,20 @@ public class CloudRecordController {
@Parameter(name = "startTime", description = "鉴权ID", required = false) @Parameter(name = "startTime", description = "鉴权ID", required = false)
@Parameter(name = "endTime", description = "鉴权ID", required = false) @Parameter(name = "endTime", description = "鉴权ID", required = false)
@Parameter(name = "callId", description = "鉴权ID", required = false) @Parameter(name = "callId", description = "鉴权ID", required = false)
@Parameter(name = "collectType", description = "收藏类型, collect/reserve", required = false) @Parameter(name = "recordId", description = "录像记录的ID用于精准精准移除一个视频文件的收藏", required = false)
public void deleteCollect( public int deleteCollect(
@RequestParam(required = false) String app, @RequestParam(required = false) String app,
@RequestParam(required = false) String stream, @RequestParam(required = false) String stream,
@RequestParam(required = false) String mediaServerId, @RequestParam(required = false) String mediaServerId,
@RequestParam(required = false) String startTime, @RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) String callId, @RequestParam(required = false) String callId,
@RequestParam(required = false) String collectType,
@RequestParam(required = false) Integer recordId @RequestParam(required = false) Integer recordId
){ ){
if (!"collect".equals(collectType) && !"reserve".equals(collectType)) {
collectType = "collect";
}
if (recordId != null) { if (recordId != null) {
cloudRecordService.changeCollectById(recordId, collectType, false); return cloudRecordService.changeCollectById(recordId, false);
}else { }else {
cloudRecordService.changeCollect(collectType, false, app, stream, mediaServerId, startTime, endTime, callId, collectType); return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId);
} }
} }
} }