Parcourir la source

保存抓取规则功能

qitz il y a 2 ans
Parent
révision
a24b78473f

+ 27
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/DeptIdentifyController.java Voir le fichier

@@ -177,4 +177,31 @@ public class DeptIdentifyController extends BaseController {
177 177
     public AjaxResult bindHandler(DeptIdentify deptIdentify){
178 178
         return deptIdentifyService.bindHandler(deptIdentify);
179 179
     }
180
+
181
+    /**
182
+     * 根据模板id查询抓取规则
183
+     * @param templateManage
184
+     * @return
185
+     */
186
+    @PostMapping("/getFatchRuleByTemplateid")
187
+    public AjaxResult getFatchRuleByTemplateid(@RequestBody  TemplateManage templateManage){
188
+        List<FatchRule> fatchRuleList = deptIdentifyService.getFatchRuleByTemplateid(templateManage);
189
+        return AjaxResult.success(fatchRuleList);
190
+    }
191
+
192
+    /**
193
+     * 保存抓取规则
194
+     * @param templateManage
195
+     * @return
196
+     */
197
+    @PostMapping("/saveFatchRules")
198
+    public AjaxResult saveFatchRules(@RequestBody  TemplateManage templateManage){
199
+        return deptIdentifyService.saveFatchRules(templateManage);
200
+    }
201
+
202
+
203
+
204
+
205
+
206
+
180 207
 }

+ 6
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/FatchRule.java Voir le fichier

@@ -20,4 +20,10 @@ public class FatchRule extends BaseEntity {
20 20
     private String startContent;
21 21
     private String endContent;
22 22
 
23
+    private String column;
24
+    private String columnName;
25
+    private Integer isDefault;
26
+
27
+    private Long templateId;
28
+
23 29
 }

+ 5
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/TemplateManage.java Voir le fichier

@@ -3,6 +3,8 @@ package com.ruoyi.wisdomarbitrate.domain;
3 3
 import com.ruoyi.common.core.domain.BaseEntity;
4 4
 import lombok.Data;
5 5
 
6
+import java.util.List;
7
+
6 8
 @Data
7 9
 public class TemplateManage extends BaseEntity {
8 10
     private static final long serialVersionUID = 1L;
@@ -49,4 +51,7 @@ public class TemplateManage extends BaseEntity {
49 51
      * 机构关联id
50 52
      */
51 53
     private String identifyName;
54
+
55
+    List<FatchRule> fatchRules;
56
+
52 57
 }

+ 17
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/TemplateFatchRule.java Voir le fichier

@@ -0,0 +1,17 @@
1
+package com.ruoyi.wisdomarbitrate.domain.vo;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 模板抓取规则关联表
7
+ */
8
+@Data
9
+public class TemplateFatchRule {
10
+    private static final long serialVersionUID = 1L;
11
+    private Long id;
12
+    private Long templateId;
13
+    private Long fatchRuleId;
14
+
15
+
16
+
17
+}

+ 9
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/FatchRuleMapper.java Voir le fichier

@@ -3,6 +3,7 @@ package com.ruoyi.wisdomarbitrate.mapper;
3 3
 import com.ruoyi.wisdomarbitrate.domain.CaseAffiliate;
4 4
 import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
5 5
 import com.ruoyi.wisdomarbitrate.domain.FatchRule;
6
+import com.ruoyi.wisdomarbitrate.domain.TemplateManage;
6 7
 import org.apache.ibatis.annotations.Param;
7 8
 import org.springframework.stereotype.Repository;
8 9
 
@@ -16,4 +17,12 @@ public interface FatchRuleMapper {
16 17
  */
17 18
    List<FatchRule> list(@Param("batchNumber")String batchNumber);
18 19
 
20
+   List<FatchRule> selectFatchRuleList(FatchRule fatchRule);
21
+
22
+
23
+   List<FatchRule> selectFatchRuleListIsDefault(FatchRule fatchRule);
24
+
25
+   void deletebatchFatchRule(@Param("fatchRuleIds")  List<Long> fatchRuleIds);
26
+
27
+   int insertFatchRule(FatchRule fatchRule);
19 28
 }

+ 19
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/mapper/TemplateFatchRuleMapper.java Voir le fichier

@@ -0,0 +1,19 @@
1
+package com.ruoyi.wisdomarbitrate.mapper;
2
+
3
+
4
+import com.ruoyi.wisdomarbitrate.domain.vo.TemplateFatchRule;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+import java.util.List;
8
+
9
+@Mapper
10
+public interface TemplateFatchRuleMapper {
11
+    int selectTemplateFatchRulecount(TemplateFatchRule templateFatchRule);
12
+
13
+
14
+    List<TemplateFatchRule> selectTemplateFatchRuleList(TemplateFatchRule templateFatchRule);
15
+
16
+    void deleteTemplateFatchRule(Long id);
17
+
18
+    int insertTemplateFatchRule(TemplateFatchRule templateFatchRule);
19
+}

+ 4
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IDeptIdentifyService.java Voir le fichier

@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
4 4
 import com.ruoyi.common.core.domain.entity.SysUser;
5 5
 import com.ruoyi.common.exception.EsignDemoException;
6 6
 import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
7
+import com.ruoyi.wisdomarbitrate.domain.FatchRule;
7 8
 import com.ruoyi.wisdomarbitrate.domain.SealManage;
8 9
 import com.ruoyi.wisdomarbitrate.domain.TemplateManage;
9 10
 import com.ruoyi.wisdomarbitrate.domain.vo.SealListVO;
@@ -51,4 +52,7 @@ public interface IDeptIdentifyService {
51 52
 
52 53
     AjaxResult bindHandler(DeptIdentify deptIdentify);
53 54
 
55
+    List<FatchRule> getFatchRuleByTemplateid(TemplateManage templateManage);
56
+
57
+    AjaxResult saveFatchRules(TemplateManage templateManage);
54 58
 }

+ 57
- 8
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/DeptIdentifyServiceImpl.java Voir le fichier

@@ -18,15 +18,10 @@ import com.ruoyi.system.domain.SysUserPost;
18 18
 import com.ruoyi.system.mapper.SysDeptMapper;
19 19
 import com.ruoyi.system.mapper.SysUserMapper;
20 20
 import com.ruoyi.system.mapper.SysUserPostMapper;
21
-import com.ruoyi.wisdomarbitrate.domain.CaseAttach;
22
-import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
23
-import com.ruoyi.wisdomarbitrate.domain.SealManage;
24
-import com.ruoyi.wisdomarbitrate.domain.TemplateManage;
21
+import com.ruoyi.wisdomarbitrate.domain.*;
25 22
 import com.ruoyi.wisdomarbitrate.domain.vo.SealListVO;
26
-import com.ruoyi.wisdomarbitrate.mapper.CaseAttachMapper;
27
-import com.ruoyi.wisdomarbitrate.mapper.DeptIdentifyMapper;
28
-import com.ruoyi.wisdomarbitrate.mapper.SealManageMapper;
29
-import com.ruoyi.wisdomarbitrate.mapper.TemplateManageMapper;
23
+import com.ruoyi.wisdomarbitrate.domain.vo.TemplateFatchRule;
24
+import com.ruoyi.wisdomarbitrate.mapper.*;
30 25
 import com.ruoyi.wisdomarbitrate.service.IDeptIdentifyService;
31 26
 import com.ruoyi.wisdomarbitrate.utils.SignAward;
32 27
 import org.springframework.beans.BeanUtils;
@@ -34,11 +29,13 @@ import org.springframework.beans.factory.annotation.Autowired;
34 29
 import org.springframework.stereotype.Service;
35 30
 import org.springframework.transaction.annotation.Transactional;
36 31
 import org.springframework.web.multipart.MultipartFile;
32
+import com.ruoyi.wisdomarbitrate.mapper.TemplateFatchRuleMapper;
37 33
 
38 34
 import java.io.File;
39 35
 import java.io.IOException;
40 36
 import java.time.LocalDate;
41 37
 import java.util.*;
38
+import java.util.stream.Collectors;
42 39
 
43 40
 import static com.ruoyi.common.utils.PageUtils.startPage;
44 41
 import static com.ruoyi.common.utils.SecurityUtils.getUsername;
@@ -60,6 +57,10 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
60 57
     private TemplateManageMapper templateManageMapper;
61 58
     @Autowired
62 59
     private SysUserPostMapper sysUserPostMapper;
60
+    @Autowired
61
+    private TemplateFatchRuleMapper templateFatchRuleMapper;
62
+    @Autowired
63
+    private  FatchRuleMapper fatchRuleMapper;
63 64
 
64 65
 
65 66
     @Override
@@ -530,6 +531,54 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
530 531
         return null;
531 532
     }
532 533
 
534
+    @Override
535
+    public List<FatchRule> getFatchRuleByTemplateid(TemplateManage templateManage) {
536
+        TemplateFatchRule templateFatchRule = new TemplateFatchRule();
537
+        templateFatchRule.setTemplateId(templateManage.getId());
538
+        List<FatchRule>  fatchRules = new ArrayList<>();
539
+        int countTemplateFatchRule = templateFatchRuleMapper.selectTemplateFatchRulecount(templateFatchRule);
540
+        if(countTemplateFatchRule!=0){
541
+            FatchRule fatchRule = new FatchRule();
542
+            fatchRule.setTemplateId(templateManage.getId());
543
+            fatchRules = fatchRuleMapper.selectFatchRuleList(fatchRule);
544
+            return fatchRules;
545
+        }else {
546
+            FatchRule fatchRule = new FatchRule();
547
+            fatchRule.setIsDefault(1);
548
+            fatchRules = fatchRuleMapper.selectFatchRuleListIsDefault(fatchRule);
549
+            return fatchRules;
550
+        }
551
+    }
552
+
553
+    @Override
554
+    @Transactional
555
+    public AjaxResult saveFatchRules(TemplateManage templateManage) {
556
+        TemplateFatchRule templateFatchRule = new TemplateFatchRule();
557
+        templateFatchRule.setTemplateId(templateManage.getId());
558
+        List<TemplateFatchRule> templateFatchRulelist = templateFatchRuleMapper.selectTemplateFatchRuleList(templateFatchRule);
559
+        if(templateFatchRulelist!=null&&templateFatchRulelist.size()>0){
560
+            List<Long> fatchRuleIds   = templateFatchRulelist.stream().map(TemplateFatchRule::getFatchRuleId).collect(Collectors.toList());
561
+            fatchRuleMapper.deletebatchFatchRule(fatchRuleIds);
562
+            templateFatchRuleMapper.deleteTemplateFatchRule(templateManage.getId());
563
+        }
564
+        List<FatchRule> fatchRules = templateManage.getFatchRules();
565
+        if(fatchRules!=null&&fatchRules.size()>0){
566
+            for (FatchRule fatchRule : fatchRules) {
567
+                //保存抓取规则数据
568
+                fatchRule.setIsDefault(0);
569
+                fatchRuleMapper.insertFatchRule(fatchRule);
570
+                //保存模板抓取规则关联关系
571
+                Long fatchRuleId = fatchRule.getId();
572
+                if(fatchRuleId!=null){
573
+                    templateFatchRule.setFatchRuleId(fatchRuleId);
574
+                    templateFatchRuleMapper.insertTemplateFatchRule(templateFatchRule);
575
+                }
576
+            }
577
+            return AjaxResult.success("新增成功");
578
+        }
579
+        return AjaxResult.error();
580
+    }
581
+
533 582
     private String getFileExtension(String fileName) {
534 583
         int lastDotIndex = fileName.lastIndexOf(".");
535 584
         if (lastDotIndex > 0 && lastDotIndex < fileName.length() - 1) {

+ 58
- 1
ruoyi-system/src/main/resources/mapper/wisdomarbitrate/FatchRuleMapper.xml Voir le fichier

@@ -5,14 +5,71 @@
5 5
 <mapper namespace="com.ruoyi.wisdomarbitrate.mapper.FatchRuleMapper">
6 6
     <resultMap id="BaseResultMap" type="com.ruoyi.wisdomarbitrate.domain.FatchRule" >
7 7
         <result column="id" property="id" />
8
-        <result column="batch_number" property="batchNumber" />
9 8
         <result column="file_name" property="fileName" />
10 9
         <result column="start_content" property="startContent" />
11 10
         <result column="end_content" property="endContent" />
11
+
12
+        <result column="column" property="column" />
13
+        <result column="is_default" property="isDefault" />
14
+        <result column="columnName" property="columnName" />
12 15
     </resultMap>
13 16
     <select id="list" resultMap="BaseResultMap">
14 17
         select * from fatch_rule where batch_number=#{batchNumber}
15 18
     </select>
16 19
 
20
+    <select id="selectFatchRuleList" parameterType="FatchRule" resultMap="BaseResultMap">
21
+        SELECT f.id ,f.file_name ,f.start_content ,f.end_content ,
22
+        f.`column` ,f.is_default ,f.columnName
23
+        FROM template_fatch_rule tf
24
+        left join template_manage t on tf.template_id  = t.id
25
+        LEFT JOIN fatch_rule f on tf.fatch_rule_id  = f.id
26
+        <where>
27
+            <if test="templateId != null">
28
+                AND tf.template_id  = #{templateId}
29
+            </if>
30
+        </where>
31
+    </select>
32
+
33
+    <select id="selectFatchRuleListIsDefault" parameterType="FatchRule" resultMap="BaseResultMap">
34
+        SELECT f.id ,f.file_name ,f.start_content ,f.end_content ,
35
+        f.`column` ,f.is_default ,f.columnName
36
+        FROM fatch_rule f
37
+        <where>
38
+            <if test="isDefault != null">
39
+                AND f.is_default  = #{isDefault}
40
+            </if>
41
+        </where>
42
+    </select>
43
+
44
+    <delete id="deletebatchFatchRule">
45
+        delete from fatch_rule where id in
46
+        <foreach collection="fatchRuleIds" item="item" open="(" separator="," close=")">
47
+            #{item}
48
+        </foreach>
49
+    </delete>
50
+
51
+    <insert id="insertFatchRule" parameterType="FatchRule" useGeneratedKeys="true" keyProperty="id">
52
+        insert into fatch_rule(
53
+        <if test="fileName != null and fileName != ''">file_name,</if>
54
+        <if test="startContent != null and startContent != ''">start_content,</if>
55
+        <if test="endContent != null and endContent != ''">end_content,</if>
56
+        <if test="column != null and column != ''">`column`,</if>
57
+        <if test="columnName != null and columnName != ''">columnName,</if>
58
+        <if test="isDefault != null">is_default</if>
59
+        )values(
60
+        <if test="fileName != null and fileName != ''">#{fileName},</if>
61
+        <if test="startContent != null and startContent != ''">#{startContent},</if>
62
+        <if test="endContent != null and endContent != ''">#{endContent},</if>
63
+        <if test="column != null and column != ''">#{column},</if>
64
+        <if test="columnName != null and columnName != ''">#{columnName},</if>
65
+        <if test="isDefault != null">#{isDefault}</if>
66
+        )
67
+    </insert>
68
+
69
+
70
+
71
+
72
+
73
+
17 74
 
18 75
 </mapper>

+ 49
- 0
ruoyi-system/src/main/resources/mapper/wisdomarbitrate/TemplateFatchRuleMapper.xml Voir le fichier

@@ -0,0 +1,49 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper
3
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5
+<mapper namespace="com.ruoyi.wisdomarbitrate.mapper.TemplateFatchRuleMapper">
6
+
7
+    <resultMap id="BaseResultMap" type="com.ruoyi.wisdomarbitrate.domain.vo.TemplateFatchRule" >
8
+        <result column="id" property="id" />
9
+        <result column="template_id" property="templateId" />
10
+        <result column="fatch_rule_id" property="fatchRuleId" />
11
+    </resultMap>
12
+
13
+    <select id="selectTemplateFatchRulecount" parameterType="TemplateFatchRule"   resultType="Integer">
14
+        select count(1) from  template_fatch_rule t
15
+        <where>
16
+            <if test="templateId != null">
17
+                AND t.template_id = #{templateId}
18
+            </if>
19
+        </where>
20
+    </select>
21
+
22
+    <select id="selectTemplateFatchRuleList" parameterType="TemplateFatchRule" resultMap="BaseResultMap">
23
+        SELECT t.id ,t.template_id ,t.fatch_rule_id
24
+        from template_fatch_rule t
25
+        <where>
26
+            <if test="templateId != null">
27
+                AND t.template_id = #{templateId}
28
+            </if>
29
+        </where>
30
+
31
+
32
+    </select>
33
+
34
+    <delete id="deleteTemplateFatchRule" parameterType="Long">
35
+		delete from template_fatch_rule where template_id=#{id}
36
+	</delete>
37
+
38
+    <insert id="insertTemplateFatchRule" parameterType="TemplateFatchRule" useGeneratedKeys="true" keyProperty="id">
39
+        insert into template_fatch_rule(
40
+        <if test="templateId != null">template_id,</if>
41
+        <if test="fatchRuleId != null">fatch_rule_id</if>
42
+        )values(
43
+        <if test="templateId != null">#{templateId},</if>
44
+        <if test="fatchRuleId != null">#{fatchRuleId}</if>
45
+        )
46
+    </insert>
47
+
48
+
49
+</mapper>