Преглед на файлове

add:单个识别码插入v1

tujidelv преди 3 години
родител
ревизия
16a58fe06a

+ 18 - 1
src/main/java/top/lvzhiqiang/controller/BgController.java

@@ -65,7 +65,7 @@ public class BgController {
         }
 
         if (null == isDel) {
-            isDel = 1;
+            isDel = 2;
         }
 
         bgService.uploadFile4IdentificationCode(file.getInputStream(), isDel);
@@ -73,6 +73,23 @@ public class BgController {
     }
 
     /**
+     * 上传识别码文件
+     *
+     * @author lvzhiqiang
+     * 2022/4/16 16:10
+     */
+    @RequestMapping("/single4IdentificationCode")
+    @ResponseBody
+    public R single4IdentificationCode(String identificationCode) {
+        if (StringUtils.isEmpty(identificationCode)) {
+            throw new ParameterException("identificationCode为空!");
+        }
+
+        bgService.single4IdentificationCode(identificationCode);
+        return R.ok();
+    }
+
+    /**
      * Jsoup IcodePool
      *
      * @author lvzhiqiang

+ 1 - 0
src/main/java/top/lvzhiqiang/enumeration/ResultCodeEnum.java

@@ -13,6 +13,7 @@ public enum ResultCodeEnum {
     SUCCESS(true, 20000, "成功"),
     UNKNOWN_ERROR(false, 20001, "未知错误"),
     PARAM_ERROR(false, 20002, "参数错误"),
+    PARAM_DATA_EXIST_ERROR(false, 20003, "参数数据已存在"),
     ;
 
     // 响应是否成功

+ 9 - 0
src/main/java/top/lvzhiqiang/mapper/IcodePoolMapper.java

@@ -37,6 +37,15 @@ public interface IcodePoolMapper {
     int insertList(List<String> icodePoolList);
 
     /**
+     * 新增
+     *
+     * @param identificationCode
+     */
+    @Insert("INSERT INTO icode_pool(identification_code, create_time, modify_time) " +
+            "VALUES (#{identificationCode}, now(), now())")
+    int insert(String identificationCode);
+
+    /**
      * 根据状态查询识别码
      */
     @Select("SELECT identification_code FROM icode_pool WHERE delete_flag = 1 and status = #{status} and retry_count < 3")

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

@@ -29,4 +29,11 @@ public interface BgService {
      * @param status
      */
     void jsoupIcodePool(Integer status, Integer isDel);
+
+    /**
+     * 单个识别码
+     *
+     * @param identificationCode
+     */
+    void single4IdentificationCode(String identificationCode);
 }

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

@@ -13,6 +13,8 @@ import org.springframework.transaction.annotation.Transactional;
 import top.lvzhiqiang.config.WebAppConfig;
 import top.lvzhiqiang.dto.JavAllInfo;
 import top.lvzhiqiang.entity.*;
+import top.lvzhiqiang.enumeration.ResultCodeEnum;
+import top.lvzhiqiang.exception.BusinessException;
 import top.lvzhiqiang.mapper.*;
 import top.lvzhiqiang.service.BgService;
 import top.lvzhiqiang.util.DateUtils;
@@ -109,6 +111,23 @@ public class BgServiceImpl implements BgService {
     }
 
     /**
+     * 单个识别码
+     *
+     * @param identificationCode
+     */
+    @Override
+    public void single4IdentificationCode(String identificationCode) {
+        List<String> icodePoolList = icodePoolMapper.findIcode();
+
+        identificationCode = identificationCode.trim().toUpperCase();
+        if (icodePoolList.contains(identificationCode)) {
+            throw new BusinessException(ResultCodeEnum.PARAM_DATA_EXIST_ERROR);
+        }
+
+        icodePoolMapper.insert(identificationCode);
+    }
+
+    /**
      * Jsoup IcodePool
      *
      * @param status

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

@@ -34,6 +34,15 @@
     </div>
     <br/>
     <div style="margin-right:20px;">
+        <span class="font">single4IdentificationCode</span>
+        <form method="post" action="bg/single4IdentificationCode">
+            <span>identificationCode</span>
+            <input type="text" name="identificationCode" placeholder="识别码"/>
+            <input type="submit" value="提交">
+        </form>
+    </div>
+    <br/>
+    <div style="margin-right:20px;">
         <span class="font">uploadFile4IdentificationCode</span>
         <form method="post" action="bg/uploadFile4IdentificationCode" enctype="multipart/form-data">
             <span>file</span>
@@ -50,7 +59,7 @@
             <span>status</span>
             <input type="text" name="status" placeholder="1:未爬取,3:爬取失败。默认是未爬取" style="width: 300px;"/>
             <span>isDel</span>
-            <input type="text" name="isDel" placeholder="1:是,2:否。默认"/>
+            <input type="text" name="isDel" placeholder="1:是,2:否。默认"/>
             <input type="submit" value="提交">
         </form>
     </div>