视频分类删除接口优化,存在视频不能删除

This commit is contained in:
xiezhijun 2021-06-18 18:10:30 +08:00
parent a0b0bd5eaa
commit 81453e91ab
8 changed files with 87 additions and 25 deletions

View File

@ -1,5 +1,6 @@
package com.stdiet.web.controller;
import com.stdiet.common.utils.AliyunVideoUtils;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.poi.ExcelUtil;
import com.stdiet.custom.domain.SysNutritionQuestion;
@ -43,6 +44,27 @@ public class MyApplicationRunner implements ApplicationRunner {
System.out.println("--------------项目启动调用方法结束-------------");
}
/**
* 给现有视频更新截图图片
*/
public void getVideoSn(){
List<SysNutritionalVideo> list = sysNutritionalVideoService.selectSysNutritionalVideoList(new SysNutritionalVideo(), false);
int success = 0;
if(list != null && list.size() > 0){
for (SysNutritionalVideo video : list) {
try{
Thread.sleep(500);
}catch (Exception e){
e.printStackTrace();
}
if(AliyunVideoUtils.submitVideoSnapshot(video.getVideoId())){
success ++;
}
}
}
System.out.println("成功数量:" + success);
}
/**
* 从微信用户表中查询openid更新到用户打卡日志表中

View File

@ -1,6 +1,8 @@
package com.stdiet.web.controller.custom;
import java.util.List;
import com.stdiet.custom.typehandler.ArrayJsonHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -92,7 +94,11 @@ public class SysVideoClassifyController extends BaseController
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(sysVideoClassifyService.deleteSysVideoClassifyByIds(ids));
if(ids != null && ids.length == 1){
//只支持单个删除
return sysVideoClassifyService.deleteSysVideoClassifyById(ids[0]);
}
return AjaxResult.error();
}
/**

View File

@ -88,4 +88,11 @@ public interface SysNutritionalVideoMapper
* @return
*/
public int updateVideoPlayNum(@Param("videoId")String videoId);
/**
* 根据视频分类ID查询该分类下存在视频数量
* @param cateId
* @return
*/
public int getVideoCountByCateId(@Param("cateId")Long cateId);
}

View File

@ -3,6 +3,7 @@ package com.stdiet.custom.mapper;
import java.util.List;
import com.stdiet.custom.domain.SysVideoClassify;
import com.stdiet.custom.dto.response.VideoClassifyResponse;
import org.apache.ibatis.annotations.Param;
/**
* 视频分类Mapper接口
@ -72,4 +73,11 @@ public interface SysVideoClassifyMapper
* @return
*/
public List<VideoClassifyResponse> getOneAllClassifyAndVideo(SysVideoClassify sysVideoClassify);
/**
* 根据分类ID查询分类以及分类下的子类ID
* @param id
* @return
*/
public List<Long> getVideoClassifyIdsById(@Param("id")Long id);
}

View File

@ -1,6 +1,8 @@
package com.stdiet.custom.service;
import java.util.List;
import com.stdiet.common.core.domain.AjaxResult;
import com.stdiet.custom.domain.SysVideoClassify;
import com.stdiet.custom.dto.response.VideoClassifyResponse;
@ -44,13 +46,6 @@ public interface ISysVideoClassifyService
*/
public int updateSysVideoClassify(SysVideoClassify sysVideoClassify);
/**
* 批量删除视频分类
*
* @param ids 需要删除的视频分类ID
* @return 结果
*/
public int deleteSysVideoClassifyByIds(Long[] ids);
/**
* 删除视频分类信息
@ -58,7 +53,7 @@ public interface ISysVideoClassifyService
* @param id 视频分类ID
* @return 结果
*/
public int deleteSysVideoClassifyById(Long id);
public AjaxResult deleteSysVideoClassifyById(Long id);
/**
* 获取所有类别

View File

@ -1,6 +1,8 @@
package com.stdiet.custom.service.impl;
import java.util.List;
import com.stdiet.common.core.domain.AjaxResult;
import com.stdiet.common.utils.DateUtils;
import com.stdiet.custom.dto.response.VideoClassifyResponse;
import com.stdiet.custom.mapper.SysNutritionalVideoMapper;
@ -75,17 +77,6 @@ public class SysVideoClassifyServiceImpl implements ISysVideoClassifyService
return sysVideoClassifyMapper.updateSysVideoClassify(sysVideoClassify);
}
/**
* 批量删除视频分类
*
* @param ids 需要删除的视频分类ID
* @return 结果
*/
@Override
public int deleteSysVideoClassifyByIds(Long[] ids)
{
return sysVideoClassifyMapper.deleteSysVideoClassifyByIds(ids);
}
/**
* 删除视频分类信息
@ -94,15 +85,31 @@ public class SysVideoClassifyServiceImpl implements ISysVideoClassifyService
* @return 结果
*/
@Override
public int deleteSysVideoClassifyById(Long id)
public AjaxResult deleteSysVideoClassifyById(Long id)
{
return sysVideoClassifyMapper.deleteSysVideoClassifyById(id);
return delChildrenClassify(id);
}
private boolean delChildrenClassify(Long id){
/**
* 删除分类以及子分类删除之前需要判断分类下是否存在视频
* @param id
* @return
*/
private AjaxResult delChildrenClassify(Long id){
//判断分类下是否存在视频存在视频不能删除
return true;
int videoNum = sysNutritionalVideoMapper.getVideoCountByCateId(id);
if(videoNum > 0){
return AjaxResult.error("该分类下存在视频,无法直接删除");
}
//删除该分类以及全部子分类
List<Long> childrenIds = sysVideoClassifyMapper.getVideoClassifyIdsById(id);
if(childrenIds != null && childrenIds.size() > 0){
Long[] ids = new Long[childrenIds.size()];
if(sysVideoClassifyMapper.deleteSysVideoClassifyByIds(childrenIds.toArray(ids)) > 0) {
return AjaxResult.success();
}
}
return AjaxResult.error();
}
/**

View File

@ -173,4 +173,14 @@
update sys_nutritional_video set play_num = play_num + 1 where video_id = #{videoId} and del_flag = 0
</update>
<!-- 根据视频分类ID查询该分类下视频总量 -->
<select id="getVideoCountByCateId" parameterType="Long" resultType="int">
select count(snv.id) from sys_nutritional_video snv where snv.del_flag = 0
and snv.cate_id in (
select id from sys_video_classify where del_flag = 0
and (id = #{cateId} or id in (select s.id from sys_video_classify s where s.parent_id = #{cateId} and s.del_flag = 0)
or id in (select ss.id from sys_video_classify ss where ss.del_flag = 0 and ss.parent_id in (select a.id from sys_video_classify a where a.parent_id = #{cateId} and a.del_flag = 0 )))
)
</select>
</mapper>

View File

@ -159,4 +159,11 @@
order by priority_level desc,id asc
</select>
<!-- 根据分类ID查询该分类ID以及分类下的子类ID -->
<select id="getVideoClassifyIdsById" parameterType="Long" resultType="Long">
select id from sys_video_classify where del_flag = 0
and (id = #{id} or id in (select s.id from sys_video_classify s where s.parent_id = #{id} and s.del_flag = 0)
or id in (select ss.id from sys_video_classify ss where ss.del_flag = 0 and ss.parent_id in (select a.id from sys_video_classify a where a.parent_id = #{id} and a.del_flag = 0 )))
</select>
</mapper>