浏览代码

知识点添加拼接字段并更新

tags/正式3.14.1
王宁 3 个月前
父节点
当前提交
799a5ff354

+ 1
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/controller/subjectbook/PointController.java 查看文件

@@ -69,6 +69,7 @@ public class PointController {
69 69
         if (point.getPointlevel() > 5) {
70 70
             return new ResultVo(1,"超过层级限制");
71 71
         }
72
+
72 73
         int result = pointService.addPoint(point);
73 74
         if (result > 0) {
74 75
             return new ResultVo(0, "保存成功");

+ 6
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/mapper/subjectbook/PointMapper.java 查看文件

@@ -27,4 +27,10 @@ public interface PointMapper extends TkMapper<TPoint> {
27 27
 
28 28
     //根据知识点ID获取知识点信息
29 29
     TPoint getPointInfoById(@Param("pointid")String pointid);
30
+
31
+    //获取知识点全拼接字段
32
+    String getPointallByPointid(@Param("pointid")String pointid);
33
+
34
+    //修改拼接字段
35
+    void updatePointAll(@Param("pointid")String pointid, @Param("pointname")String pointname,@Param("pointlevel")Integer pointlevel);
30 36
 }

+ 24
- 1
sstudy/src/main/java/com/xhkjedu/sstudy/service/subjectbook/PointService.java 查看文件

@@ -3,10 +3,11 @@ package com.xhkjedu.sstudy.service.subjectbook;
3 3
 import com.xhkjedu.sstudy.mapper.subjectbook.PointMapper;
4 4
 import com.xhkjedu.sstudy.model.subjectbook.TPoint;
5 5
 import com.xhkjedu.sstudy.utils.StudyUtil;
6
-import com.xhkjedu.utils.N_Utils;
7 6
 import com.xhkjedu.sstudy.vo.subjectbook.PointVo;
7
+import com.xhkjedu.utils.N_Utils;
8 8
 import org.springframework.beans.factory.annotation.Autowired;
9 9
 import org.springframework.stereotype.Service;
10
+import org.springframework.transaction.annotation.Transactional;
10 11
 
11 12
 import java.util.ArrayList;
12 13
 import java.util.List;
@@ -35,7 +36,18 @@ public class PointService {
35 36
         if ("".equals(point.getPointpid())) {
36 37
             point.setPointpid(null);
37 38
         }
39
+
38 40
         point.setCreatetime(N_Utils.getSecondTimestamp());
41
+
42
+        if (N_Utils.isEmpty(point.getPointpid())) {
43
+            //说明是1级知识点
44
+            point.setPointall(point.getPointname());
45
+        }else{
46
+            //非1级知识点,获取该父知识点的pointall字段值
47
+            String pointall = pointMapper.getPointallByPointid(point.getPointpid());
48
+            point.setPointall(pointall + ";" + point.getPointname());
49
+        }
50
+
39 51
         return pointMapper.insertSelective(point);
40 52
     }
41 53
 
@@ -46,7 +58,18 @@ public class PointService {
46 58
      * @param  * @param point
47 59
      * @return java.lang.Integer
48 60
      */
61
+    @Transactional(rollbackFor = Exception.class)
49 62
     public Integer updatePoint(TPoint point){
63
+        TPoint oldPoint = pointMapper.selectByPrimaryKey(point.getPointid());
64
+        if(oldPoint.getPointlevel() == 1){
65
+            //说明第一层
66
+            point.setPointall(point.getPointname());
67
+        }else{
68
+            //设置本层pointall字段
69
+            String pointall = oldPoint.getPointall().replaceAll(oldPoint.getPointname(),point.getPointname());
70
+            point.setPointall(pointall);
71
+        }
72
+        pointMapper.updatePointAll(point.getPointid(),point.getPointall(),oldPoint.getPointlevel());
50 73
         point.setCreatetime(N_Utils.getSecondTimestamp());
51 74
         return pointMapper.updateByPrimaryKeySelective(point);
52 75
     }

+ 29
- 1
sstudy/src/main/resources/mapper/subjectbook/PointMapper.xml 查看文件

@@ -37,9 +37,37 @@
37 37
 
38 38
     <!--根据知识点ID获取知识点信息-->
39 39
     <select id="getPointInfoById" resultType="com.xhkjedu.sstudy.model.subjectbook.TPoint">
40
-        select pointid,pointname,pointall,
40
+        select pointid,pointname,pointall,pointlevel,
41 41
          (select count(*) from t_point p where p.pointpid=#{pointid}) sonnum
42 42
         from t_point where pointid=#{pointid}
43 43
     </select>
44 44
 
45
+    <!--获取知识点全拼接字段-->
46
+    <select id="getPointallByPointid" resultType="java.lang.String">
47
+        select pointall from t_point where pointid=#{pointid}
48
+    </select>
49
+
50
+    <!--修改层级知识点-->
51
+    <update id="updatePointAll">
52
+        UPDATE t_point d1
53
+        <if test ="4 > pointlevel">LEFT JOIN t_point d2 ON d2.pointpid=d1.pointid</if>
54
+        <if test="3 > pointlevel">
55
+            LEFT JOIN t_point d3 ON d3.pointpid=d2.pointid
56
+        </if>
57
+        <if test="2 > pointlevel">
58
+            LEFT JOIN t_point d4 ON d4.pointpid=d3.pointid
59
+        </if>
60
+        SET d1.pointall=CONCAT(#{pointname},';',d1.pointname)
61
+        <if test="4 > pointlevel">
62
+            ,d2.pointall=CONCAT(#{pointname},';',d1.pointname,';',d2.pointname)
63
+        </if>
64
+        <if test="3 > pointlevel">
65
+            ,d3.pointall=CONCAT(#{pointname},';',d1.pointname,';',d2.pointname,';',d3.pointname)
66
+        </if>
67
+        <if test="2 > pointlevel">
68
+            ,d4.pointall=CONCAT(#{pointname},';',d1.pointname,';',d2.pointname,';',d3.pointname,';',d4.pointname)
69
+        </if>
70
+        WHERE d1.pointpid=#{pointid}
71
+    </update>
72
+
45 73
 </mapper>

正在加载...
取消
保存