Jelajahi Sumber

update:添加删除影片接口v1

tujidelv 3 tahun lalu
induk
melakukan
80a65cd3f4

+ 23 - 0
src/main/java/top/lvzhiqiang/controller/BgController.java

@@ -254,4 +254,27 @@ public class BgController {
 
         return bgService.findVideoInfo(identificationCode, type, order, crudT);
     }
+
+    /**
+     * 删除影片
+     *
+     * @param identificationCode
+     * @param parentTypeName
+     * @param allFlag            {1:是2:否}
+     * @author lvzhiqiang
+     * 2022/5/29 12:59
+     */
+    @RequestMapping("/delVideoInfo")
+    @ResponseBody
+    public R delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
+        if (StringUtils.isEmpty(identificationCode)) {
+            throw new ParameterException("识别码不能为空");
+        }
+        if (StringUtils.isEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
+            throw new ParameterException("上级类型名称与所有不能同时为空");
+        }
+
+        bgService.delVideoInfo(identificationCode, parentTypeName, allFlag);
+        return R.ok();
+    }
 }

+ 10 - 0
src/main/java/top/lvzhiqiang/mapper/VideoInfoCastMapper.java

@@ -2,6 +2,7 @@ package top.lvzhiqiang.mapper;
 
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Select;
 import top.lvzhiqiang.entity.VideoInfoCast;
 
 import java.util.Set;
@@ -57,4 +58,13 @@ public interface VideoInfoCastMapper {
     @Insert("INSERT INTO video_info_cast(identification_code, name , type, create_time) " +
             "VALUES (#{identificationCode}, #{name}, #{type}, now())")
     int insert(VideoInfoCast videoInfoCast);
+
+    @Select("SELECT * FROM video_info_cast WHERE identification_code = #{identificationCode} and name = #{name}")
+    VideoInfoCast findVideoInfoCastByCodeAndName(String identificationCode, String name);
+
+    @Delete("DELETE FROM video_info_cast where id = #{id}")
+    void deleteById(Long id);
+
+    @Delete("DELETE FROM video_info_cast where identification_code = #{identificationCode}")
+    void deleteByCode(String identificationCode);
 }

+ 10 - 0
src/main/java/top/lvzhiqiang/mapper/VideoInfoGenresMapper.java

@@ -2,6 +2,7 @@ package top.lvzhiqiang.mapper;
 
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Select;
 import top.lvzhiqiang.entity.VideoInfoGenres;
 
 import java.util.List;
@@ -58,4 +59,13 @@ public interface VideoInfoGenresMapper {
     @Insert("INSERT INTO video_info_genres(identification_code, name , type, create_time) " +
             "VALUES (#{identificationCode}, #{name}, #{type}, now())")
     int insert(VideoInfoGenres videoInfoGenres);
+
+    @Select("SELECT * FROM video_info_genres WHERE identification_code = #{identificationCode} and name = #{name}")
+    VideoInfoGenres findVideoInfoGenresByCodeAndName(String identificationCode, String name);
+
+    @Delete("DELETE FROM video_info_genres where id = #{id}")
+    void deleteById(Long id);
+
+    @Delete("DELETE FROM video_info_genres where identification_code = #{identificationCode}")
+    void deleteByCode(String identificationCode);
 }

+ 3 - 0
src/main/java/top/lvzhiqiang/mapper/VideoInfoMapper.java

@@ -115,4 +115,7 @@ public interface VideoInfoMapper {
             "        left join video_info_other vio on vi.identification_code = vio.identification_code and vio.delete_flag = 1" +
             "        where vi.delete_flag = 1 and vi.identification_code=#{code}")
     VideoInfo getVideoInfoDetail(String code);
+
+    @Update("update video_info set delete_flag = 2 where identification_code = #{identificationCode}")
+    void delByIdentificationCode(String identificationCode);
 }

+ 10 - 0
src/main/java/top/lvzhiqiang/service/BgService.java

@@ -100,4 +100,14 @@ public interface BgService {
      * 2022/5/5 18:21
      */
     void jsoupVideoInfo(Integer status);
+
+    /**
+     * 删除影片
+     *
+     * @param identificationCode
+     * @param parentTypeName
+     * @author lvzhiqiang
+     * 2022/5/29 12:59
+     */
+    void delVideoInfo(String identificationCode, String parentTypeName, String allFlag);
 }

+ 50 - 0
src/main/java/top/lvzhiqiang/service/impl/BgServiceImpl.java

@@ -18,6 +18,7 @@ import top.lvzhiqiang.dto.JavAllInfo4Uncensored;
 import top.lvzhiqiang.entity.*;
 import top.lvzhiqiang.enumeration.ResultCodeEnum;
 import top.lvzhiqiang.exception.BusinessException;
+import top.lvzhiqiang.exception.ParameterException;
 import top.lvzhiqiang.mapper.*;
 import top.lvzhiqiang.service.BgService;
 import top.lvzhiqiang.util.DateUtils;
@@ -412,6 +413,55 @@ public class BgServiceImpl implements BgService {
     }
 
     /**
+     * 删除影片
+     *
+     * @param identificationCode
+     * @param parentTypeName
+     * @author lvzhiqiang
+     * 2022/5/29 12:59
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+    public void delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
+        if (StringUtils.isNotEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
+            if (parentTypeName.contains("类别")) {
+                String videoGenres = parentTypeName.replace("(类别)", "");
+                VideoInfoGenres videoInfoGenres = videoInfoGenresMapper.findVideoInfoGenresByCodeAndName(identificationCode, videoGenres);
+                if ("1".equals(videoInfoGenres.getType())) {
+                    // 主体
+                    throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
+                } else {
+                    // 链接
+                    videoInfoGenresMapper.deleteById(videoInfoGenres.getId());
+                }
+            } else if (parentTypeName.contains("优")) {
+                String videoCast = "";
+                if (parentTypeName.contains("(男")) {
+                    videoCast = parentTypeName.replace("(男优)", "");
+                } else if (parentTypeName.contains("(女")) {
+                    videoCast = parentTypeName.replace("(女优)", "");
+                }
+                VideoInfoCast videoInfoCast = videoInfoCastMapper.findVideoInfoCastByCodeAndName(identificationCode, videoCast);
+                if ("1".equals(videoInfoCast.getType())) {
+                    // 主体
+                    throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
+                } else {
+                    // 链接
+                    videoInfoCastMapper.deleteById(videoInfoCast.getId());
+                }
+            } else {
+                throw new ParameterException("直属类型不存在");
+            }
+        } else if (StringUtils.isEmpty(parentTypeName) && StringUtils.isNotEmpty(allFlag)) {
+            videoInfoMapper.delByIdentificationCode(identificationCode);
+            videoInfoCastMapper.deleteByCode(identificationCode);
+            videoInfoGenresMapper.deleteByCode(identificationCode);
+        } else {
+            throw new ParameterException("参数有误");
+        }
+    }
+
+    /**
      * 初始化骑兵数据
      */
     @Override