Kaynağa Gözat

add:步兵数据初始化v1

tujidelv 3 yıl önce
ebeveyn
işleme
b3e25267a2

+ 6 - 2
src/main/java/top/lvzhiqiang/controller/BgController.java

@@ -35,16 +35,20 @@ public class BgController {
      */
     @RequestMapping("/initVideoInfoData")
     @ResponseBody
-    public String initVideoInfoData(Integer type, Integer isDel) {
+    public String initVideoInfoData(Integer type, Integer isDel, String infantryType) {
         if (null == type) {
             throw new ParameterException("type不能为空!");
         }
 
+        if (2 == type && StringUtils.isEmpty(infantryType)) {
+            throw new ParameterException("选择步兵时infantryType不能为空!");
+        }
+
         if (null == isDel) {
             isDel = 2;
         }
 
-        bgService.initVideoInfoData(type, isDel);
+        bgService.initVideoInfoData(type, isDel, infantryType);
         return "success";
     }
 

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

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

+ 115 - 0
src/main/java/top/lvzhiqiang/entity/VideoInfoInfantry.java

@@ -0,0 +1,115 @@
+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/6 17:34
+ */
+@Data
+public class VideoInfoInfantry 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;
+
+    /**
+     * 类型
+     */
+    private String type;
+
+    /**
+     * 状态(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;
+}

+ 106 - 0
src/main/java/top/lvzhiqiang/mapper/VideoInfoInfantryMapper.java

@@ -0,0 +1,106 @@
+package top.lvzhiqiang.mapper;
+
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import top.lvzhiqiang.entity.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 电影信息流出Mapper
+ *
+ * @author lvzhiqiang
+ * 2022/5/6 17:34
+ */
+public interface VideoInfoInfantryMapper {
+
+    /**
+     * 删除所有
+     */
+    @Delete("DELETE FROM video_info_infantry where 1=1")
+    void deleteAll();
+
+    /**
+     * 批量新增
+     *
+     * @param videoInfoInfantryList
+     */
+    @Insert({"<script>" +
+            "INSERT INTO video_info_infantry(name, identification_code, issue_date, img_url, video_url, main_who, type, status, create_time, modify_time) " +
+            "VALUES " +
+            "<foreach collection='list' item='vii' index=\"index\" separator=\",\">" +
+            "   (#{vii.name}, #{vii.identificationCode}, #{vii.issueDate}, #{vii.imgUrl}, #{vii.videoUrl}, #{vii.mainWho}, #{vii.type}, #{vii.status}, #{vii.createTime}, now())" +
+            " </foreach>" +
+            "</script>"})
+    int insertList(List<VideoInfoInfantry> videoInfoInfantryList);
+
+    /**
+     * 根据状态查询识别码
+     */
+    @Select("SELECT identification_code FROM video_info_infantry WHERE delete_flag = 1 and status = #{status}")
+    List<String> findIcodeByStatus(Integer status);
+
+    /**
+     * 更新状态
+     *
+     * @param identificationCode
+     * @param status
+     * @return
+     */
+    @Update("update video_info_infantry set status = #{status},modify_time = now() where identification_code = #{identificationCode}")
+    int updateStatus(String identificationCode, Integer status);
+
+    /**
+     * 查询所有识别码
+     */
+    @Select("select distinct identification_code from video_info_infantry")
+    List<String> findAllIcode();
+
+    /**
+     * 根据条件查询
+     */
+    List<VideoInfo> getVideoInfoInfantryList(Map<String, Object> params);
+
+    /**
+     * 根据识别码和类型查询
+     *
+     * @return
+     */
+    @Select({"<script>" +
+            "select vi.*,vio.score,vio.comment from video_info_infantry 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=\"status != null and type != ''\">" +
+            "   and vi.status = #{status}" +
+            "</if>" +
+            "<if test=\"order != null and order != ''\">" +
+            "   order by vi.issue_date ${order}" +
+            "</if>" +
+            "</script>"})
+    List<VideoInfoUncensored> findByCodeAndType(String identificationCode, Integer status, String order);
+
+    @Update("update video_info_infantry set delete_flag = 2,modify_time = now() where identification_code = #{identificationCode}")
+    void delByCode(String identificationCode);
+
+    @Update("update video_info_infantry set length = #{length}, director = #{director}, maker = #{maker}, issuer = #{issuer}, genres = #{genres}, cast = #{cast}, status = #{status}, modify_time = now() where identification_code = #{identificationCode}")
+    void updateJsoupInfoByCode(VideoInfoUncensored videoInfoUncensored);
+
+    @Select("SELECT M.cast name,COUNT(M.cast) count " +
+            "FROM (" +
+            "         SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(viu.cast, ',', B.HELP_TOPIC_ID + 1), ',', - 1) AS cast" +
+            "         FROM video_info_infantry viu" +
+            "                  JOIN MYSQL.HELP_TOPIC B" +
+            "                       ON B.HELP_TOPIC_ID < (LENGTH(viu.cast) - LENGTH(REPLACE(viu.cast, ',', '')) + 1)" +
+            "         WHERE genres != ''" +
+            "     ) M " +
+            "GROUP BY M.cast " +
+            "ORDER BY COUNT(M.cast) DESC LIMIT 30")
+    List<VideoCast> findCast();
+
+    @Select("select main_who AS name, count(id) AS count from video_info_infantry group by main_who order by count(id) desc")
+    List<VideoGenres> findGenres();
+}

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

@@ -14,7 +14,7 @@ public interface BgService {
     /**
      * 初始化影片数据
      */
-    void initVideoInfoData(Integer type, Integer isDel);
+    void initVideoInfoData(Integer type, Integer isDel, String infantryType);
 
     /**
      * 上传识别码文件

+ 93 - 1
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.JavAllInfo4Infantry;
 import top.lvzhiqiang.dto.JavAllInfo4Uncensored;
 import top.lvzhiqiang.entity.*;
 import top.lvzhiqiang.enumeration.ResultCodeEnum;
@@ -65,6 +66,8 @@ public class BgServiceImpl implements BgService {
     private VideoInfoOtherMapper videoInfoOtherMapper;
     @Resource
     private VideoInfoUncensoredMapper videoInfoUncensoredMapper;
+    @Resource
+    private VideoInfoInfantryMapper videoInfoInfantryMapper;
 
     /**
      * findDicCode
@@ -406,7 +409,7 @@ public class BgServiceImpl implements BgService {
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     @Async
-    public void initVideoInfoData(Integer type, Integer isDel) {
+    public void initVideoInfoData(Integer type, Integer isDel, String infantryType) {
         long startTime = System.currentTimeMillis();
 
         DicCode dicCode = null;
@@ -414,6 +417,8 @@ public class BgServiceImpl implements BgService {
             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();
+        } else if (type == 2) {
+            dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "bubing_path".equals(x.getCodeKey())).findFirst().get();
         }
         if (dicCode == null) {
             return;
@@ -430,6 +435,12 @@ public class BgServiceImpl implements BgService {
             getAllFilePaths4Uncensored(picPath, javAllInfo4Uncensored);
 
             saveInfo4Uncensored(javAllInfo4Uncensored, isDel);
+        } else if (type == 2) {
+            JavAllInfo4Infantry javAllInfo4Infantry = new JavAllInfo4Infantry();
+            picPath = picPath.concat(infantryType);
+            getAllFilePaths4Infantry(picPath, javAllInfo4Infantry, infantryType);
+
+            saveInfo4Infantry(javAllInfo4Infantry, isDel);
         }
 
         long endTime = System.currentTimeMillis();
@@ -987,6 +998,66 @@ public class BgServiceImpl implements BgService {
         }
     }
 
+    private void getAllFilePaths4Infantry(String filePath, JavAllInfo4Infantry javAllInfo4Infantry, String infantryType) {
+        File[] files = new File(filePath).listFiles();
+        if (files == null) {
+            return;
+        }
+
+        for (File file : files) {
+            if (file.isDirectory()) {
+                // 文件夹
+                getAllFilePaths4Infantry(file.getAbsolutePath(), javAllInfo4Infantry, infantryType);
+            } 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 {
+                        // 获取正片信息
+                        VideoInfoInfantry videoInfoInfantry = new VideoInfoInfantry();
+                        // 发行日期
+                        String issueDate = fileName.substring(0, 10);
+                        videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
+                        videoInfoInfantry.setIdentificationCode(nameArr[0]);
+                        // 名称
+                        if (nameArr.length > 1) {
+                            videoInfoInfantry.setName(name.substring(nameArr[0].length()).trim());
+                        } else {
+                            videoInfoInfantry.setName(nameArr[0]);
+                        }
+
+                        // 状态
+                        videoInfoInfantry.setStatus(1);
+                        // 类型
+                        videoInfoInfantry.setType(infantryType);
+                        // 图片URL
+                        videoInfoInfantry.setImgUrl(parentName.concat("/").concat(fileName));
+                        // 创建时间 TODO
+                        // 修改时间
+                        videoInfoInfantry.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
+
+                        // 主体是谁
+                        videoInfoInfantry.setMainWho(parentName);
+
+                        javAllInfo4Infantry.getVideoInfoInfantryList().add(videoInfoInfantry);
+                        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") && !fileName.endsWith(".txt")) {
+                    String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
+                    String parentName = file.getParentFile().getName();
+
+                    javAllInfo4Infantry.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
+                }
+            }
+        }
+    }
+
     // 保存所有文件
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void saveInfo(JavAllInfo javAllInfo) {
@@ -1068,6 +1139,27 @@ public class BgServiceImpl implements BgService {
         System.out.println("videoInfoCount:" + videoInfoCount);
     }
 
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+    public void saveInfo4Infantry(JavAllInfo4Infantry javAllInfo4Infantry, Integer isDel) {
+        // 删除所有
+        if (isDel == 1) {
+            videoInfoInfantryMapper.deleteAll();
+        }
+
+        // 保存影片信息
+        List<VideoInfoInfantry> videoInfoInfantryList = javAllInfo4Infantry.getVideoInfoInfantryList();
+        Map<String, String> videoUrlMap = javAllInfo4Infantry.getVideoUrlMap();
+        videoInfoInfantryList.parallelStream().forEach(e -> {
+            e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
+        });
+
+        int videoInfoCount = 0;
+        if (videoInfoInfantryList.size() > 0) {
+            videoInfoCount = videoInfoInfantryMapper.insertList(videoInfoInfantryList);
+        }
+        System.out.println("videoInfoCount:" + videoInfoCount);
+    }
+
     private List<String> readFromIcodeStream(InputStream inputStream) {
         List<String> list = new ArrayList<>();
         BufferedReader br = null;

+ 23 - 0
src/main/resources/mapper/VideoInfoInfantryMapper.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+
+<!-- 当Mapper接口和XML文件关联的时候,namespace的值就需要配置成接口的全限定名称 -->
+<mapper namespace="top.lvzhiqiang.mapper.VideoInfoInfantryMapper">
+
+    <select id="getVideoInfoInfantryList" resultType="top.lvzhiqiang.entity.VideoInfo">
+        select vi.id,vi.name,vi.identification_code,vi.issue_date,vi.modify_time,vi.img_url,vi.video_url,concat_ws('||', vi.cast, vi.genres) main_who,IFNULL(vio.score, 0) AS score, IFNULL(vio.comment, '暂无评论') AS comment
+        from video_info_infantry 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="keyword != null and keyword != ''">
+            and (vi.name like #{keyword} or vi.identification_code like #{keyword})
+        </if>
+        <if test="genres != null and genres != ''">
+            and vi.main_who = #{genres}
+        </if>
+        <if test="cast != null and cast != ''">
+            and vi.cast like concat('%',#{cast},'%')
+        </if>
+    </select>
+</mapper>

+ 3 - 0
src/main/resources/static/bg.html

@@ -107,10 +107,13 @@
             <select name="type" style="height: 21.43px;">
                 <option value="">请选择</option>
                 <option value="1">骑兵</option>
+                <option value="2">步兵</option>
                 <option value="3">流出</option>
             </select>
             <span>isDel</span>
             <input type="text" name="isDel" placeholder="1:是,2:否。默认否"/>
+            <span>infantryType</span>
+            <input type="text" name="infantryType" placeholder="选择步兵时需填"/>
             <input type="submit" value="提交">
         </form>
     </div>