Bladeren bron

add:bg页面加入insertOrUpdateScoreOrComment

tujidelv 3 jaren geleden
bovenliggende
commit
a74a504a0c

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

@@ -186,4 +186,24 @@ public class BgController {
 
         return bgService.findVideoInfo(identificationCode, type, order, crudT);
     }
+
+    /**
+     * insetOrupdateScoreOrComment
+     *
+     * @author lvzhiqiang
+     * 2022/5/4 9:54
+     */
+    @RequestMapping("/insertOrUpdateScoreOrComment")
+    @ResponseBody
+    public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) throws IllegalAccessException {
+        if (StringUtils.isEmpty(identificationCode)) {
+            throw new ParameterException("identificationCode为空!");
+        }
+
+        if (StringUtils.isEmpty(score) && StringUtils.isEmpty(comment)) {
+            throw new ParameterException("score和comment不能都为空!");
+        }
+
+        return bgService.insertOrUpdateScoreOrComment(identificationCode.toUpperCase(), score, comment);
+    }
 }

+ 46 - 0
src/main/java/top/lvzhiqiang/mapper/VideoInfoOtherMapper.java

@@ -0,0 +1,46 @@
+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.VideoInfoPool;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 电影信息其他Mapper
+ *
+ * @author lvzhiqiang
+ * 2022/5/4 9:54
+ */
+public interface VideoInfoOtherMapper {
+
+    /**
+     * 删除所有
+     */
+    @Delete("DELETE FROM video_info_other where 1=1")
+    void deleteAll();
+
+    @Update({"<script>" +
+            "update video_info_other " +
+            "<set>" +
+            "<if test=\"score != null\">" +
+            "  score = #{score}," +
+            "</if>" +
+            "<if test=\"comment != null and comment != ''\">" +
+            "   comment = #{comment}," +
+            "</if>" +
+            "</set>" +
+            "where identification_code = #{identificationCode}" +
+            "</script>"})
+    void updateScoreOrComment(String identificationCode, BigDecimal score, String comment);
+
+    @Select("select count(*) from video_info_other where identification_code=#{identification_code}")
+    int findByCode(String identificationCode);
+
+    @Insert("INSERT INTO video_info_other(identification_code, score, comment, create_time, modify_time) " +
+            "VALUES (#{identificationCode},#{score},#{comment}, now(), now())")
+    void insertScoreOrComment(String identificationCode, BigDecimal score, String comment);
+}

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

@@ -76,4 +76,12 @@ public interface BgService {
      * 2022/5/3 17:37
      */
     String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException;
+
+    /**
+     * updateScoreOrComment
+     *
+     * @author lvzhiqiang
+     * 2022/5/4 9:54
+     */
+    String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment);
 }

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

@@ -23,6 +23,7 @@ import top.lvzhiqiang.util.StringUtils;
 import javax.annotation.Resource;
 import java.io.*;
 import java.lang.reflect.Field;
+import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.time.Instant;
 import java.time.LocalDate;
@@ -59,6 +60,8 @@ public class BgServiceImpl implements BgService {
     private VideoSitePoolMapper videoSitePoolMapper;
     @Resource
     private DicCodeMapper dicCodeMapper;
+    @Resource
+    private VideoInfoOtherMapper videoInfoOtherMapper;
 
     /**
      * findDicCode
@@ -227,6 +230,29 @@ public class BgServiceImpl implements BgService {
     }
 
     /**
+     * updateScoreOrComment
+     *
+     * @author lvzhiqiang
+     * 2022/5/4 9:54
+     */
+    @Override
+    public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
+        BigDecimal scoreBD = null;
+        if (StringUtils.isNotEmpty(score)) {
+            scoreBD = new BigDecimal(score);
+        }
+
+        int num = videoInfoOtherMapper.findByCode(identificationCode);
+        if (num == 0) {
+            videoInfoOtherMapper.insertScoreOrComment(identificationCode, scoreBD, comment);
+            return "insert success";
+        }
+
+        videoInfoOtherMapper.updateScoreOrComment(identificationCode, scoreBD, comment);
+        return "update success";
+    }
+
+    /**
      * 初始化骑兵数据
      */
     @Override

+ 14 - 1
src/main/resources/static/bg.html

@@ -129,7 +129,7 @@
     <br/>
     <div style="margin-right:20px;">
         <span class="font">jsoupIcodePool</span>
-        <form method="post" action="bg/jsoupIcodePool" enctype="multipart/form-data">
+        <form method="post" action="bg/jsoupIcodePool">
             <span>status</span>
             <input type="text" name="status" placeholder="1:未爬取,3:爬取失败。默认是未爬取" style="width: 300px;"/>
             <span>isDel</span>
@@ -137,6 +137,19 @@
             <input type="submit" value="提交">
         </form>
     </div>
+    <br/>
+    <div style="margin-right:20px;">
+        <span class="font">insertOrUpdateScoreOrComment</span>
+        <form method="post" action="bg/insertOrUpdateScoreOrComment">
+            <span>identificationCode</span>
+            <input type="text" name="identificationCode" placeholder="识别码,不可为空"/>
+            <span>score</span>
+            <input type="text" name="score"/>
+            <span>comment</span>
+            <input type="text" name="comment"/>
+            <input type="submit" value="提交">
+        </form>
+    </div>
 </div>
 </body>
 </html>