From 81453e91ab0f7772c20fbf4cd6139ed54a907e76 Mon Sep 17 00:00:00 2001 From: xiezhijun <15270898033@163.com> Date: Fri, 18 Jun 2021 18:10:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=88=86=E7=B1=BB=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96=EF=BC=8C=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E8=A7=86=E9=A2=91=E4=B8=8D=E8=83=BD=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/MyApplicationRunner.java | 22 +++++++++++ .../custom/SysVideoClassifyController.java | 8 +++- .../mapper/SysNutritionalVideoMapper.java | 7 ++++ .../custom/mapper/SysVideoClassifyMapper.java | 8 ++++ .../service/ISysVideoClassifyService.java | 11 ++---- .../impl/SysVideoClassifyServiceImpl.java | 39 +++++++++++-------- .../custom/SysNutritionalVideoMapper.xml | 10 +++++ .../mapper/custom/SysVideoClassifyMapper.xml | 7 ++++ 8 files changed, 87 insertions(+), 25 deletions(-) diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/MyApplicationRunner.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/MyApplicationRunner.java index c1fa43118..0d2cda41c 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/MyApplicationRunner.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/MyApplicationRunner.java @@ -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 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更新到用户打卡日志表中 diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysVideoClassifyController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysVideoClassifyController.java index b677d5491..83eb4e04e 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysVideoClassifyController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysVideoClassifyController.java @@ -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(); } /** diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysNutritionalVideoMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysNutritionalVideoMapper.java index 1fd6a2670..189713082 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysNutritionalVideoMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysNutritionalVideoMapper.java @@ -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); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysVideoClassifyMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysVideoClassifyMapper.java index 0e00d8a56..ffa2a4be3 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysVideoClassifyMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysVideoClassifyMapper.java @@ -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 getOneAllClassifyAndVideo(SysVideoClassify sysVideoClassify); + + /** + * 根据分类ID查询分类以及分类下的子类ID + * @param id + * @return + */ + public List getVideoClassifyIdsById(@Param("id")Long id); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysVideoClassifyService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysVideoClassifyService.java index 8290de7fe..be16cc737 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysVideoClassifyService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysVideoClassifyService.java @@ -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); /** * 获取所有类别 diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysVideoClassifyServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysVideoClassifyServiceImpl.java index 14f791aa3..baa249127 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysVideoClassifyServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysVideoClassifyServiceImpl.java @@ -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 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(); } /** diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysNutritionalVideoMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysNutritionalVideoMapper.xml index 59d21ec58..791dd6d38 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysNutritionalVideoMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysNutritionalVideoMapper.xml @@ -173,4 +173,14 @@ update sys_nutritional_video set play_num = play_num + 1 where video_id = #{videoId} and del_flag = 0 + + + \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysVideoClassifyMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysVideoClassifyMapper.xml index 3259c594c..dda67592a 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysVideoClassifyMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysVideoClassifyMapper.xml @@ -159,4 +159,11 @@ order by priority_level desc,id asc + + + \ No newline at end of file