Browse Source

修改章节时更新层级章节名称

批量添加资源
tags/正式3.2.0
雍文秀 2 years ago
parent
commit
f922cffee4

+ 6
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/controller/resource/ResourceController.java View File

@@ -42,6 +42,12 @@ public class ResourceController {
42 42
         return new ResultVo(0, "保存成功",id);
43 43
     }
44 44
 
45
+    @PostMapping("/batch_add")
46
+    public ResultVo batchAdd(@RequestBody List<TResource> resources) {
47
+        resourceService.batchAdd(resources);
48
+        return new ResultVo(0, "批量保存成功");
49
+    }
50
+
45 51
     @PostMapping("/delete")
46 52
     public ResultVo delete(@RequestBody TResource tResource) {
47 53
         String resourceid = tResource.getResourceid();

+ 4
- 1
sstudy/src/main/java/com/xhkjedu/sstudy/controller/subjectbook/DirectorController.java View File

@@ -72,7 +72,10 @@ public class DirectorController {
72 72
     public ResultVo update(@RequestBody TDirector director){
73 73
         N_Utils.validation(new Object[]{director.getDirectorid(),"章节id",2,director.getDirectorname(),"章节名称",2});
74 74
         int result = directorService.updateDirector(director);
75
-        if (result > 0) return new ResultVo(0,"修改成功");
75
+        if (result > 0) {
76
+            directorService.updateDirectorAll(director.getDirectorid());
77
+            return new ResultVo(0, "修改成功");
78
+        }
76 79
         else return new ResultVo(1,"修改失败");
77 80
     }
78 81
 

+ 7
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/mapper/subjectbook/DirectorMapper.java View File

@@ -2,6 +2,7 @@ package com.xhkjedu.sstudy.mapper.subjectbook;
2 2
 
3 3
 import com.xhkjedu.sstudy.base.TkMapper;
4 4
 import com.xhkjedu.sstudy.model.subjectbook.TDirector;
5
+import com.xhkjedu.sstudy.vo.subjectbook.DirectorVo;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 import org.springframework.stereotype.Repository;
7 8
 
@@ -36,4 +37,10 @@ public interface DirectorMapper extends TkMapper<TDirector> {
36 37
 
37 38
     //查找使用章节的模块
38 39
     String findUseModule(String directorid);
40
+
41
+    //获取章节层级名称和章节层级
42
+    DirectorVo getNameAndLevelById(String directorid);
43
+
44
+    //修改层级章节
45
+    void updateDirectorAll(String directorid, String directorname, Integer level);
39 46
 }

+ 3
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/model/subjectbook/TDirector.java View File

@@ -34,6 +34,9 @@ public class TDirector extends BaseBean {
34 34
     //章节归属层级
35 35
     private Integer directorlevel;
36 36
 
37
+    //所有层级章节拼接,用;隔开
38
+    private String directorall;
39
+
37 40
     //创建人
38 41
     private Integer createid;
39 42
 

+ 13
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/service/resource/ResourceService.java View File

@@ -308,4 +308,17 @@ public class ResourceService {
308 308
     public ResourceVo findById2(String resourceid) {
309 309
         return resourceMapper.findById2(resourceid);
310 310
     }
311
+
312
+    /**
313
+     * 批量保存
314
+     * @Param [resources]
315
+     * @Author ywx
316
+     * @Date 2022/3/14 11:28
317
+     * @return void
318
+     **/
319
+    public void batchAdd(List<TResource> resources) {
320
+        for (TResource resource : resources) {
321
+            save(resource);
322
+        }
323
+    }
311 324
 }

+ 15
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/service/subjectbook/DirectorService.java View File

@@ -4,6 +4,7 @@ package com.xhkjedu.sstudy.service.subjectbook;
4 4
 import com.xhkjedu.sstudy.mapper.subjectbook.DirectorMapper;
5 5
 import com.xhkjedu.sstudy.model.subjectbook.TDirector;
6 6
 import com.xhkjedu.sstudy.utils.StudyUtil;
7
+import com.xhkjedu.sstudy.vo.subjectbook.DirectorVo;
7 8
 import com.xhkjedu.utils.N_Utils;
8 9
 import org.springframework.beans.factory.annotation.Autowired;
9 10
 import org.springframework.stereotype.Service;
@@ -131,4 +132,18 @@ public class DirectorService {
131 132
         }
132 133
         return useModule;
133 134
     }
135
+
136
+    /**
137
+     * 修改层级章节
138
+     * @Param [directorid, directorname]
139
+     * @Author ywx
140
+     * @Date 2022/3/14 15:14
141
+     * @return void
142
+     **/
143
+    public void updateDirectorAll(String directorid) {
144
+        DirectorVo vo = directorMapper.getNameAndLevelById(directorid);
145
+        Integer level = vo.getLevel();
146
+        if (level.equals(4)) return;
147
+        directorMapper.updateDirectorAll(directorid, vo.getDirectorname(), level);
148
+    }
134 149
 }

+ 23
- 1
sstudy/src/main/resources/mapper/subjectbook/DirectorMapper.xml View File

@@ -5,7 +5,7 @@
5 5
     <!-- 根据科目获取章节-->
6 6
     <select id="listDirectors" resultType="com.xhkjedu.sstudy.model.subjectbook.TDirector">
7 7
        SELECT d.directorid,d.directorname,d.directorpid,d.directororder,d.leaf,d.lsbid,d.belong,
8
-        d.directorlevel,d.createid,d.createtime,u.username AS createname
8
+        d.directorlevel,d.createid,d.createtime,d.directorall,u.username AS createname
9 9
         FROM t_director d LEFT JOIN t_user u ON d.createid=u.userid
10 10
         WHERE d.lsbid=#{director.lsbid}
11 11
         <if test="director.belong!=null and director.belong==1">
@@ -31,4 +31,26 @@
31 31
         ,(select (case when count(*)>0 then ',资源' else '' end) from t_resource_director where directorid=#{directorid})
32 32
         )
33 33
     </select>
34
+    <!--获取章节层级名称和章节层级-->
35
+    <select id="getNameAndLevelById" resultType="com.xhkjedu.sstudy.vo.subjectbook.DirectorVo">
36
+        select directorall directorname,directorlevel level from t_director where directorid=#{directorid}
37
+    </select>
38
+    <!--修改层级章节-->
39
+    <update id="updateDirectorAll">
40
+        UPDATE t_director d2
41
+        <if test="3>level">
42
+            LEFT JOIN t_director d3 ON d3.directorpid=d2.directorid
43
+        </if>
44
+        <if test="2>level">
45
+            LEFT JOIN t_director d4 ON d4.directorpid=d3.directorid
46
+        </if>
47
+        SET d2.directorall=CONCAT(#{directorname},';',d2.directorname)
48
+        <if test="3>level">
49
+            ,d3.directorall=CONCAT(#{directorname},';',d2.directorname,';',d3.directorname)
50
+        </if>
51
+        <if test="2>level">
52
+            ,d4.directorall=CONCAT(#{directorname},';',d2.directorname,';',d3.directorname,';',d4.directorname)
53
+        </if>
54
+        WHERE d2.directorpid=#{directorid}
55
+    </update>
34 56
 </mapper>

Loading…
Cancel
Save