视频列表优化
This commit is contained in:
		| @@ -65,6 +65,10 @@ public class SysNutritionalVideo extends BaseEntity | ||||
|  | ||||
|     private String payLevelName; | ||||
|  | ||||
|     /** 播放次数,默认0 */ | ||||
|     @Excel(name = "播放次数,默认0") | ||||
|     private Integer playNum; | ||||
|  | ||||
|     /** 删除标识,0未删除 1已删除,默认0 */ | ||||
|     private Integer delFlag; | ||||
|  | ||||
| @@ -72,4 +76,7 @@ public class SysNutritionalVideo extends BaseEntity | ||||
|     private String fileName; | ||||
|  | ||||
|     private String key; | ||||
|  | ||||
|     //排序方式 1 按照创建时间倒序 2按照优先级、时间倒序 | ||||
|     private Integer sortType; | ||||
| } | ||||
| @@ -33,6 +33,8 @@ public class NutritionalVideoResponse implements Serializable { | ||||
|     //播放链接 | ||||
|     public String playUrl; | ||||
|  | ||||
|     //播放量 | ||||
|     private Integer playNum; | ||||
|  | ||||
|     public String createTime; | ||||
|  | ||||
|   | ||||
| @@ -75,4 +75,17 @@ public interface SysNutritionalVideoMapper | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateWxshowByIds(@Param("wxShow")Integer wxShow, @Param("array") Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 查询阿里云的视频ID,包含已删除的 | ||||
|      * @param ids | ||||
|      * @return | ||||
|      */ | ||||
|     public List<String> getVideoIdByIds(@Param("array") Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 更新视频播放量 | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateVideoPlayNum(@Param("videoId")String videoId); | ||||
| } | ||||
| @@ -4,6 +4,7 @@ import java.util.List; | ||||
| import java.util.Map; | ||||
|  | ||||
| import com.stdiet.custom.domain.SysNutritionalVideo; | ||||
| import org.apache.ibatis.annotations.Param; | ||||
|  | ||||
| /** | ||||
|  * 营养视频Service接口 | ||||
| @@ -81,4 +82,10 @@ public interface ISysNutritionalVideoService | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateWxshowByIds(Integer wxShow, Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 更新视频播放量 | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateVideoPlayNum(String videoId); | ||||
| } | ||||
| @@ -11,6 +11,7 @@ import com.stdiet.common.utils.AliyunVideoUtils; | ||||
| import com.stdiet.common.utils.DateUtils; | ||||
| import com.stdiet.common.utils.oss.AliyunOSSUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.scheduling.annotation.Async; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.stdiet.custom.mapper.SysNutritionalVideoMapper; | ||||
| import com.stdiet.custom.domain.SysNutritionalVideo; | ||||
| @@ -90,7 +91,23 @@ public class SysNutritionalVideoServiceImpl implements ISysNutritionalVideoServi | ||||
|     public int updateSysNutritionalVideo(SysNutritionalVideo sysNutritionalVideo) | ||||
|     { | ||||
|         sysNutritionalVideo.setUpdateTime(DateUtils.getNowDate()); | ||||
|         return sysNutritionalVideoMapper.updateSysNutritionalVideo(sysNutritionalVideo); | ||||
|         int row = sysNutritionalVideoMapper.updateSysNutritionalVideo(sysNutritionalVideo); | ||||
|         if(row > 0){ | ||||
|             updateAliyunVideo(sysNutritionalVideo.getId()); | ||||
|         } | ||||
|         return row; | ||||
|     } | ||||
|  | ||||
|     @Async | ||||
|     public void updateAliyunVideo(Long id){ | ||||
|         try{ | ||||
|             SysNutritionalVideo sysNutritionalVideo = selectSysNutritionalVideoById(id); | ||||
|             if(sysNutritionalVideo != null && sysNutritionalVideo.getVideoId() != null){ | ||||
|                 AliyunVideoUtils.updateVideo(sysNutritionalVideo.getVideoId(), sysNutritionalVideo.getTitle(), sysNutritionalVideo.getTags(), sysNutritionalVideo.getDescription(), null); | ||||
|             } | ||||
|         }catch (Exception e){ | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -102,7 +119,11 @@ public class SysNutritionalVideoServiceImpl implements ISysNutritionalVideoServi | ||||
|     @Override | ||||
|     public int deleteSysNutritionalVideoByIds(Long[] ids) | ||||
|     { | ||||
|         return sysNutritionalVideoMapper.deleteSysNutritionalVideoByIds(ids); | ||||
|         int row = sysNutritionalVideoMapper.deleteSysNutritionalVideoByIds(ids); | ||||
|         if(row > 0){ | ||||
|             updateAliyunVideoCateId(ids); | ||||
|         } | ||||
|         return row; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -114,7 +135,12 @@ public class SysNutritionalVideoServiceImpl implements ISysNutritionalVideoServi | ||||
|     @Override | ||||
|     public int deleteSysNutritionalVideoById(Long id) | ||||
|     { | ||||
|         return sysNutritionalVideoMapper.deleteSysNutritionalVideoById(id); | ||||
|         int row = sysNutritionalVideoMapper.deleteSysNutritionalVideoById(id); | ||||
|         if(row > 0){ | ||||
|             Long[] ids = {id}; | ||||
|             updateAliyunVideoCateId(ids); | ||||
|         } | ||||
|         return row; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -187,7 +213,33 @@ public class SysNutritionalVideoServiceImpl implements ISysNutritionalVideoServi | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateWxshowByIds(Integer wxShow, Long[] ids){ | ||||
|         return sysNutritionalVideoMapper. updateWxshowByIds(wxShow, ids); | ||||
|         return sysNutritionalVideoMapper.updateWxshowByIds(wxShow, ids); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 将删除的阿里云视频放入回收站 | ||||
|      * @param ids | ||||
|      */ | ||||
|     @Async | ||||
|     public void updateAliyunVideoCateId(Long[] ids){ | ||||
|         try { | ||||
|             List<String> videoIdList = sysNutritionalVideoMapper.getVideoIdByIds(ids); | ||||
|             if(videoIdList != null && videoIdList.size() > 0){ | ||||
|                 for (String videoId : videoIdList) { | ||||
|                     AliyunVideoUtils.delVideo(videoId); | ||||
|                 } | ||||
|             } | ||||
|         }catch (Exception e){ | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 更新视频播放量 | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateVideoPlayNum(String videoId){ | ||||
|         return sysNutritionalVideoMapper.updateVideoPlayNum(videoId); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -16,6 +16,7 @@ | ||||
|         <result property="showFlag"    column="show_flag"    /> | ||||
|         <result property="priorityLevel"    column="priority_level"    /> | ||||
|         <result property="payLevel"    column="pay_level"    /> | ||||
|         <result property="playNum"    column="play_num"    /> | ||||
|         <result property="createTime"    column="create_time"    /> | ||||
|         <result property="createBy"    column="create_by"    /> | ||||
|         <result property="updateTime"    column="update_time"    /> | ||||
| @@ -27,11 +28,11 @@ | ||||
|     </resultMap> | ||||
|  | ||||
|     <sql id="selectSysNutritionalVideoVo"> | ||||
|         select id, cate_id, video_id, cover_url, title, description, priority_level,pay_level,video_size, tags, show_flag, create_time, create_by, update_time, update_by, del_flag from sys_nutritional_video | ||||
|         select id, cate_id, video_id, cover_url, title, description, priority_level,pay_level,play_num,video_size, tags, show_flag, create_time, create_by, update_time, update_by, del_flag from sys_nutritional_video | ||||
|     </sql> | ||||
|  | ||||
|     <select id="selectSysNutritionalVideoList" parameterType="SysNutritionalVideo" resultMap="SysNutritionalVideoResult"> | ||||
|         select snv.id, snv.cate_id, snv.video_id, snv.cover_url, snv.title, snv.description, snv.priority_level,snv.pay_level,snv.video_size, snv.tags, snv.show_flag, snv.create_time, | ||||
|         select snv.id, snv.cate_id, snv.video_id, snv.cover_url, snv.title, snv.description, snv.priority_level,snv.pay_level,snv.play_num,snv.video_size, snv.tags, snv.show_flag, snv.create_time, | ||||
|         pay.dict_label as pay_level_name, svc.cate_name | ||||
|         from sys_nutritional_video snv | ||||
|         left join (SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'video_pay_level') AS pay ON pay.dict_value = snv.pay_level | ||||
| @@ -49,7 +50,12 @@ | ||||
|         <if test="key != null and key != ''"> | ||||
|             and (snv.title like concat('%',#{key},'%') or snv.description like concat('%',#{key},'%')) | ||||
|         </if> | ||||
|         order by snv.priority_level DESC,snv.create_time DESC | ||||
|         <if test="sortType == null or sortType == 1"> | ||||
|             order by snv.create_time DESC | ||||
|         </if> | ||||
|         <if test="sortType != null and sortType == 2"> | ||||
|             order by snv.priority_level DESC,snv.create_time DESC | ||||
|         </if> | ||||
|     </select> | ||||
|  | ||||
|     <select id="selectSysNutritionalVideoById" parameterType="Long" resultMap="SysNutritionalVideoResult"> | ||||
| @@ -69,6 +75,7 @@ | ||||
|             <if test="tags != null">tags,</if> | ||||
|             <if test="showFlag != null">show_flag,</if> | ||||
|             <if test="priorityLevel != null">priority_level,</if> | ||||
|             <if test="playNum != null">play_num,</if> | ||||
|             <if test="createTime != null">create_time,</if> | ||||
|             <if test="createBy != null">create_by,</if> | ||||
|             <if test="payLevel != null">pay_level,</if> | ||||
| @@ -86,6 +93,7 @@ | ||||
|             <if test="tags != null">#{tags},</if> | ||||
|             <if test="showFlag != null">#{showFlag},</if> | ||||
|             <if test="priorityLevel != null">#{priorityLevel},</if> | ||||
|             <if test="playNum != null">#{playNum},</if> | ||||
|             <if test="createTime != null">#{createTime},</if> | ||||
|             <if test="createBy != null">#{createBy},</if> | ||||
|             <if test="payLevel != null">#{payLevel},</if> | ||||
| @@ -107,6 +115,7 @@ | ||||
|             <if test="tags != null">tags = #{tags},</if> | ||||
|             <if test="showFlag != null">show_flag = #{showFlag},</if> | ||||
|             <if test="priorityLevel != null">priority_level = #{priorityLevel},</if> | ||||
|             <if test="playNum != null">play_num = #{playNum},</if> | ||||
|             <if test="createTime != null">create_time = #{createTime},</if> | ||||
|             <if test="createBy != null">create_by = #{createBy},</if> | ||||
|             <if test="payLevel != null">pay_level = #{payLevel},</if> | ||||
| @@ -139,4 +148,17 @@ | ||||
|         </foreach> | ||||
|     </update> | ||||
|  | ||||
|     <!-- 查询视频的阿里云ID,包含已删除的 --> | ||||
|     <select id="getVideoIdByIds" parameterType="String" resultType="String"> | ||||
|         select video_id from sys_nutritional_video where id in | ||||
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | ||||
|             #{id} | ||||
|         </foreach> | ||||
|     </select> | ||||
|  | ||||
|     <!-- 更新视频播放量  --> | ||||
|     <update id="updateVideoPlayNum" parameterType="String"> | ||||
|         update sys_nutritional_video set play_num = play_num + 1 where video_id = #{videoId} and del_flag = 0 | ||||
|     </update> | ||||
|  | ||||
| </mapper> | ||||
		Reference in New Issue
	
	Block a user