Ver Fonte

add:流出数据初始化v1

tujidelv há 3 anos atrás
pai
commit
811acde708

+ 11 - 4
src/main/java/top/lvzhiqiang/controller/BgController.java

@@ -33,12 +33,19 @@ public class BgController {
      * @author lvzhiqiang
      * 2022/4/16 16:10
      */
-    @RequestMapping("/initQibingData")
+    @RequestMapping("/initVideoInfoData")
     @ResponseBody
-    public R initQibingData() {
-        bgService.initQibingData();
+    public String initVideoInfoData(Integer type, Integer isDel) {
+        if (null == type) {
+            throw new ParameterException("type不能为空!");
+        }
 
-        return R.ok();
+        if (null == isDel) {
+            isDel = 2;
+        }
+
+        bgService.initVideoInfoData(type, isDel);
+        return "success";
     }
 
     @RequestMapping("/ftlIndex")

+ 20 - 0
src/main/java/top/lvzhiqiang/dto/JavAllInfo4Uncensored.java

@@ -0,0 +1,20 @@
+package top.lvzhiqiang.dto;
+
+import lombok.Data;
+import top.lvzhiqiang.entity.VideoInfoUncensored;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Data
+public class JavAllInfo4Uncensored implements Serializable {
+
+    // 影片信息
+    private List<VideoInfoUncensored> videoInfoUncensoredList = new ArrayList<>();
+
+    // 影片视频路径
+    private Map<String, String> videoUrlMap = new ConcurrentHashMap<>();
+}

+ 110 - 0
src/main/java/top/lvzhiqiang/entity/VideoInfoUncensored.java

@@ -0,0 +1,110 @@
+package top.lvzhiqiang.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import top.lvzhiqiang.util.DateUtils;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ * 电影信息流出
+ *
+ * @author lvzhiqiang
+ * 2022/5/4 18:38
+ */
+@Data
+public class VideoInfoUncensored implements Serializable {
+
+    /**
+     * 主键
+     */
+    private Long id;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 识别码
+     */
+    private String identificationCode;
+
+    /**
+     * 发行日期
+     */
+    @JsonFormat(pattern = DateUtils.PATTERN_TO_DAYS, timezone = "GMT+8")
+    private LocalDate issueDate;
+
+    /**
+     * 长度
+     */
+    private String length;
+
+    /**
+     * 导演
+     */
+    private String director;
+
+    /**
+     * 制作商
+     */
+    private String maker;
+
+    /**
+     * 发行商
+     */
+    private String issuer;
+
+    /**
+     * 类别
+     */
+    private String genres;
+
+    /**
+     * 演员
+     */
+    private String cast;
+
+    /**
+     * 图片URL
+     */
+    private String imgUrl;
+
+    /**
+     * 影片URL
+     */
+    private String videoUrl;
+
+    /**
+     * 主体是谁
+     */
+    private String mainWho;
+
+    /**
+     * 状态(1:待爬取,2:爬取成功,3:爬取失败)
+     */
+    private Integer status;
+
+    /**
+     * 删除标志{1:正常,2:已删除}
+     */
+    private Integer deleteFlag;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(pattern = DateUtils.PATTERN_TO_SECONDS, timezone = "GMT+8")
+    private LocalDateTime createTime;
+
+    /**
+     * 最后修改时间
+     */
+    @JsonFormat(pattern = DateUtils.PATTERN_TO_SECONDS, timezone = "GMT+8")
+    private LocalDateTime modifyTime;
+
+    private String score;
+    private String comment;
+}

+ 88 - 0
src/main/java/top/lvzhiqiang/mapper/VideoInfoUncensoredMapper.java

@@ -0,0 +1,88 @@
+package top.lvzhiqiang.mapper;
+
+import org.apache.ibatis.annotations.*;
+import top.lvzhiqiang.entity.VideoInfo;
+import top.lvzhiqiang.entity.VideoInfoUncensored;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 电影信息流出Mapper
+ *
+ * @author lvzhiqiang
+ * 2022/5/4 18:38
+ */
+public interface VideoInfoUncensoredMapper {
+
+    /**
+     * 删除所有
+     */
+    @Delete("DELETE FROM video_info_uncensored where 1=1")
+    void deleteAll();
+
+    /**
+     * 批量新增
+     *
+     * @param videoInfoUncensoredList
+     */
+    @Insert({"<script>" +
+            "INSERT INTO video_info_uncensored(name, identification_code, issue_date, img_url, video_url, main_who, status, create_time, modify_time) " +
+            "VALUES " +
+            "<foreach collection='list' item='viu' index=\"index\" separator=\",\">" +
+            "   (#{viu.name}, #{viu.identificationCode}, #{viu.issueDate}, #{viu.imgUrl}, #{viu.videoUrl}, #{viu.mainWho}, #{viu.status}, #{viu.createTime}, now())" +
+            " </foreach>" +
+            "</script>"})
+    int insertList(List<VideoInfoUncensored> videoInfoUncensoredList);
+
+    /**
+     * 新增
+     *
+     * @param videoInfo
+     */
+    @Insert("INSERT INTO video_info(name, identification_code, issue_date, length, director, maker, issuer, img_url, video_url, type, main_who, create_time, modify_time) " +
+            "VALUES (#{name}, #{identificationCode}, #{issueDate}, #{length}, #{director}, #{maker}, #{issuer}, #{imgUrl}, #{videoUrl}, #{type}, #{mainWho} ,#{createTime}, now())")
+    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
+    int insert(VideoInfo videoInfo);
+
+    /**
+     * 查询所有
+     */
+    @Select("select vi.*, IFNULL(vio.score, 0) AS score from video_info vi " +
+            "left join video_info_other vio on vi.identification_code = vio.identification_code and vio.delete_flag = 1 " +
+            "where vi.delete_flag = 1 ORDER BY vi.issue_date desc")
+    List<VideoInfo> findAll();
+
+    /**
+     * 查询所有识别码
+     */
+    @Select("select distinct identification_code from video_info")
+    List<String> findAllIcode();
+
+    /**
+     * 根据条件查询
+     */
+    List<VideoInfo> getVideoInfoList(Map<String, Object> params);
+
+    /**
+     * 根据识别码和类型查询
+     *
+     * @return
+     */
+    @Select({"<script>" +
+            "select vi.*,vio.score,vio.comment from video_info vi left join video_info_other vio on vi.identification_code = vio.identification_code and vio.delete_flag = 1 WHERE vi.delete_flag = 1" +
+            "<if test=\"identificationCode != null and identificationCode != ''\">" +
+            "   and vi.identification_code like concat('%',#{identificationCode},'%')" +
+            "</if>" +
+            "<if test=\"type != null and type != ''\">" +
+            "   and vi.type = #{type}" +
+            "</if>" +
+            "<if test=\"order != null and order != ''\">" +
+            "   order by vi.issue_date ${order}" +
+            "</if>" +
+            "</script>"})
+    List<VideoInfo> findByCodeAndType(String identificationCode, Integer type, String order);
+
+    @Update("update video_info set delete_flag = 2,modify_time = now() where identification_code = #{identificationCode}")
+    void delByCode(String identificationCode);
+}

+ 2 - 2
src/main/java/top/lvzhiqiang/service/BgService.java

@@ -12,9 +12,9 @@ public interface BgService {
 
 
     /**
-     * 初始化骑兵数据
+     * 初始化影片数据
      */
-    void initQibingData();
+    void initVideoInfoData(Integer type, Integer isDel);
 
     /**
      * 上传识别码文件

+ 97 - 5
src/main/java/top/lvzhiqiang/service/impl/BgServiceImpl.java

@@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import top.lvzhiqiang.config.WebAppConfig;
 import top.lvzhiqiang.dto.JavAllInfo;
+import top.lvzhiqiang.dto.JavAllInfo4Uncensored;
 import top.lvzhiqiang.entity.*;
 import top.lvzhiqiang.enumeration.ResultCodeEnum;
 import top.lvzhiqiang.exception.BusinessException;
@@ -62,6 +63,8 @@ public class BgServiceImpl implements BgService {
     private DicCodeMapper dicCodeMapper;
     @Resource
     private VideoInfoOtherMapper videoInfoOtherMapper;
+    @Resource
+    private VideoInfoUncensoredMapper videoInfoUncensoredMapper;
 
     /**
      * findDicCode
@@ -258,19 +261,31 @@ public class BgServiceImpl implements BgService {
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     @Async
-    public void initQibingData() {
+    public void initVideoInfoData(Integer type, Integer isDel) {
         long startTime = System.currentTimeMillis();
 
-        DicCode dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "qibing_path".equals(x.getCodeKey())).findFirst().get();
+        DicCode dicCode = null;
+        if (type == 1) {
+            dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "qibing_path".equals(x.getCodeKey())).findFirst().get();
+        } else if (type == 3) {
+            dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get();
+        }
         if (dicCode == null) {
             return;
         }
         String picPath = dicCode.getCodeValue();
 
-        JavAllInfo javAllInfo = new JavAllInfo();
-        getAllFilePaths(picPath, javAllInfo);
+        if (type == 1) {
+            JavAllInfo javAllInfo = new JavAllInfo();
+            getAllFilePaths(picPath, javAllInfo);
+
+            saveInfo(javAllInfo);
+        } else if (type == 3) {
+            JavAllInfo4Uncensored javAllInfo4Uncensored = new JavAllInfo4Uncensored();
+            getAllFilePaths4Uncensored(picPath, javAllInfo4Uncensored);
 
-        saveInfo(javAllInfo);
+            saveInfo4Uncensored(javAllInfo4Uncensored, isDel);
+        }
 
         long endTime = System.currentTimeMillis();
         System.err.println((endTime - startTime) / 1000);
@@ -662,6 +677,64 @@ public class BgServiceImpl implements BgService {
         }
     }
 
+    private void getAllFilePaths4Uncensored(String filePath, JavAllInfo4Uncensored javAllInfo4Uncensored) {
+        File[] files = new File(filePath).listFiles();
+        if (files == null) {
+            return;
+        }
+
+        for (File file : files) {
+            if (file.isDirectory()) {
+                // 文件夹
+                getAllFilePaths4Uncensored(file.getAbsolutePath(), javAllInfo4Uncensored);
+            } else {
+                String fileName = file.getName();
+                if (fileName.endsWith(".jpg")) {
+                    String parentName = file.getParentFile().getName();
+                    // 识别码
+                    String name = fileName.substring(10).replace(".jpg", "").trim();
+                    String[] nameArr = name.split("\\s+");
+                    try {
+                        // 获取正片信息
+                        VideoInfoUncensored videoInfoUncensored = new VideoInfoUncensored();
+                        // 发行日期
+                        String issueDate = fileName.substring(0, 10);
+                        videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
+                        videoInfoUncensored.setIdentificationCode(nameArr[0]);
+                        // 名称
+                        if (nameArr.length > 1) {
+                            videoInfoUncensored.setName(name.substring(nameArr[0].length()).trim());
+                        } else {
+                            videoInfoUncensored.setName(nameArr[0]);
+                        }
+
+                        // 类型
+                        videoInfoUncensored.setStatus(1);
+                        // 图片URL
+                        videoInfoUncensored.setImgUrl(parentName.concat("/").concat(fileName));
+                        // 创建时间 TODO
+                        // 修改时间
+                        videoInfoUncensored.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
+
+                        // 主体是谁
+                        videoInfoUncensored.setMainWho(parentName);
+
+                        javAllInfo4Uncensored.getVideoInfoUncensoredList().add(videoInfoUncensored);
+                        System.out.println("success:" + file.getAbsolutePath());
+                    } catch (Exception e) {
+                        System.err.println("error:" + file.getAbsolutePath());
+                        System.err.println("error reason:" + e.getMessage());
+                    }
+                } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt")) {
+                    String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
+                    String parentName = file.getParentFile().getName();
+
+                    javAllInfo4Uncensored.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
+                }
+            }
+        }
+    }
+
     // 保存所有文件
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void saveInfo(JavAllInfo javAllInfo) {
@@ -724,6 +797,25 @@ public class BgServiceImpl implements BgService {
         videoInfoCastMapper.insertList(videoInfoCastSet);
     }
 
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+    public void saveInfo4Uncensored(JavAllInfo4Uncensored javAllInfo4Uncensored, Integer isDel) {
+        // 删除所有
+        if (isDel == 1) {
+            videoInfoUncensoredMapper.deleteAll();
+        }
+
+
+        // 保存影片信息
+        List<VideoInfoUncensored> videoInfoUncensoredList = javAllInfo4Uncensored.getVideoInfoUncensoredList();
+        Map<String, String> videoUrlMap = javAllInfo4Uncensored.getVideoUrlMap();
+        videoInfoUncensoredList.parallelStream().forEach(e -> {
+            e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
+        });
+
+        int videoInfoCount = videoInfoUncensoredMapper.insertList(videoInfoUncensoredList);
+        System.out.println("videoInfoCount:" + videoInfoCount);
+    }
+
     private List<String> readFromIcodeStream(InputStream inputStream) {
         List<String> list = new ArrayList<>();
         BufferedReader br = null;

+ 12 - 4
src/main/resources/static/bg.html

@@ -101,8 +101,16 @@
     </div>
     <hr/>
     <div style="margin-right:20px;">
-        <span class="font">initQibingData</span>
-        <form method="post" action="bg/initQibingData">
+        <span class="font">initVideoInfoData</span>
+        <form method="post" action="bg/initVideoInfoData">
+            <span>type</span>
+            <select name="type" style="height: 21.43px;">
+                <option value="">请选择</option>
+                <option value="1">骑兵</option>
+                <option value="3">流出</option>
+            </select>
+            <span>isDel</span>
+            <input type="text" name="isDel" placeholder="1:是,2:否。默认否"/>
             <input type="submit" value="提交">
         </form>
     </div>
@@ -144,9 +152,9 @@
             <span>identificationCode</span>
             <input type="text" name="identificationCode" placeholder="识别码,不可为空"/>
             <span>score</span>
-            <input type="text" name="score"/>
+            <input type="text" name="score" placeholder="和comment不能同时为空"/>
             <span>comment</span>
-            <input type="text" name="comment"/>
+            <input type="text" name="comment" placeholder="和score不能同时为空"/>
             <input type="submit" value="提交">
         </form>
     </div>