shiyi лет назад: 3
Родитель
Сommit
0e98e62739

+ 1 - 1
base/src/main/java/com/sp/director/utils/DateUtil.java

@@ -16,7 +16,7 @@ import java.util.Date;
 
 
 public class DateUtil {
-	
+
 	//格式转化相关
 	/**
 	 * 生成毫秒内的时间串 (长度16) <br>

+ 35 - 0
core/src/main/java/com/sp/director/ienum/RelativePositionEnum.java

@@ -0,0 +1,35 @@
+package com.sp.director.ienum;
+
+import com.baomidou.mybatisplus.annotation.EnumValue;
+
+/**
+ * @Descrption
+ * @Author: 十一
+ * @Date: 2021/4/6
+ * @Version V1.0
+ **/
+public enum RelativePositionEnum implements IEnum {
+
+    BEFORE(0, "before"),
+    AFTER(1, "after");
+
+    private String name;
+
+    @EnumValue
+    private Integer num;
+
+    RelativePositionEnum(Integer num, String name) {
+        this.name = name;
+        this.num = num;
+    }
+
+    @Override
+    public int getNum() {
+        return this.num;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+    }

+ 7 - 1
core/src/main/java/com/sp/director/module/script/entity/ScriptContentVersionHistory.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.sp.director.ienum.OperationTypeEnum;
+import com.sp.director.ienum.RelativePositionEnum;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -54,7 +55,12 @@ public class ScriptContentVersionHistory extends Model<ScriptContentVersionHisto
     /**
      * 前面一条记录的行号
      */
-    private Long beforeLineId;
+    private Long baseLineId;
+
+    /**
+     * 相对位置
+     */
+    private RelativePositionEnum position;
 
     /**
      * 行号id

+ 15 - 9
core/src/main/java/com/sp/director/module/script/help/ScriptContentVersionOperator.java

@@ -3,6 +3,7 @@ package com.sp.director.module.script.help;
 import com.alibaba.fastjson.JSON;
 import com.sp.director.exception.ParamException;
 import com.sp.director.ienum.OperationTypeEnum;
+import com.sp.director.ienum.RelativePositionEnum;
 import com.sp.director.module.script.entity.ScriptContentVersionHistory;
 import com.sp.director.module.script.model.LineInfoModel;
 import com.sp.director.module.script.model.OperatorModel;
@@ -79,7 +80,8 @@ public class ScriptContentVersionOperator {
         for (ScriptContentVersionHistory record : contentVersionHistoryList) {
             OperatorModel model = new OperatorModel();
             model.setModel(JSON.parseObject(record.getContent(), LineInfoModel.class));
-            model.setBeforeLineId(record.getBeforeLineId() == null ? null : record.getBeforeLineId().toString());
+            model.setBaseLineId(record.getBaseLineId() == null ? null : record.getBaseLineId().toString());
+            model.setPosition(record.getPosition());
             model.setOperationType(record.getType());
             model.setSerialNumber(record.getSerialNum());
             model.setChapterId(record.getChapterId().toString());
@@ -114,21 +116,25 @@ public class ScriptContentVersionOperator {
                 log.error("解析异常,行号版本异常:{}",contentHistory.getSerialNum());
                 throw new ParamException();
             }
-
             version ++;
-            Long beforeLineId = contentHistory.getBeforeLineId();
-            Integer beforeLineIdIndex = lineNumMap.get(beforeLineId);
+            Long baseLineId = contentHistory.getBaseLineId();
+            Integer baseLineIdIndex = lineNumMap.get(baseLineId);
 
-            if(beforeLineIdIndex == null){
-                beforeLineIdIndex = -1;
+            if(baseLineIdIndex == null){
+                baseLineIdIndex = -1;
             }
             serialNum = contentHistory.getSerialNum();
-
+            RelativePositionEnum position = contentHistory.getPosition();
             // 判断是新增还是删除
             if (OperationTypeEnum.ADD.equals(contentHistory.getType())) {
-                Integer index = beforeLineIdIndex + 1;
+                Integer index = 0;
+                if( RelativePositionEnum.AFTER.equals(position) ){
+                    index = baseLineIdIndex + 1;
+                }else if( RelativePositionEnum.BEFORE.equals(position) ) {
+                    index = baseLineIdIndex;
+                }
                 // 判断beforeLineId的记录是否存在
-                if (beforeLineIdIndex != -1 && chapterLineList.get(beforeLineIdIndex) == null) {
+                if (baseLineIdIndex != -1 && chapterLineList.get(baseLineIdIndex) == null) {
                     log.error("操作记录的顺序异常,新增行{}上一行记录不存在存在",chapterId,contentHistory.getLineId());
                     throw new ParamException();
                 }

+ 4 - 1
core/src/main/java/com/sp/director/module/script/model/OperatorModel.java

@@ -2,6 +2,7 @@ package com.sp.director.module.script.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
 import com.sp.director.ienum.OperationTypeEnum;
+import com.sp.director.ienum.RelativePositionEnum;
 import com.sp.director.utils.FastJsonCustomSerializer;
 import lombok.Data;
 
@@ -21,6 +22,8 @@ public class OperatorModel implements Serializable {
     @JSONField(serializeUsing = FastJsonCustomSerializer.class)
     private OperationTypeEnum operationType;
     private LineInfoModel model;
-    private String beforeLineId;
+    private String baseLineId;
     private String chapterId;
+    @JSONField(serializeUsing = FastJsonCustomSerializer.class)
+    private RelativePositionEnum position;
 }

+ 4 - 2
core/src/main/resources/com/sp/director/module/script/dao/xml/ScriptContentVersionHistoryMapper.xml

@@ -31,7 +31,8 @@
         select
                h.content,
                h.serial_num serialNum,
-               h.before_line_id beforeLineId,
+               h.base_line_id baseLineId,
+               h.position,
                h.type
         from t_script_content_version_history h
         <where>
@@ -50,7 +51,8 @@
             resultType="com.sp.director.module.script.entity.ScriptContentVersionHistory">
         select  h.content,
                 h.serial_num serialNum,
-                h.before_line_id beforeLineId,
+                h.base_line_id baseLineId,
+                h.position,
                 h.line_id lineId,
                 h.chapter_id chapterId,
                 h.type type

Разница между файлами не показана из-за своего большого размера
+ 1479 - 5
core/src/main/resources/sdfasdf.html


+ 13 - 8
logic/src/test/java/com/sp/module/script/ScriptTest.java

@@ -5,6 +5,7 @@ import com.sp.LogicApplication;
 import com.sp.director.http.MJson;
 import com.sp.director.ienum.ContentTypeEnum;
 import com.sp.director.ienum.OperationTypeEnum;
+import com.sp.director.ienum.RelativePositionEnum;
 import com.sp.director.module.appsign.controller.OperatorNodeBo;
 import com.sp.director.module.script.entity.ScriptContentVersionHistory;
 import com.sp.director.module.script.model.LineContentModel;
@@ -194,7 +195,7 @@ public class ScriptTest {
 
     public void insertNode(Long chapterId) throws JMSException {
         int contentIndex = 1;
-        Long beforeLineId = null;
+        Long baseLineId = null;
         List<ScriptContentVersionHistory> persistenceNodeList = new ArrayList<>(30);
         for (int i = 0; i < 10; i++) {
             OperatorModel operatorModel = new OperatorModel();
@@ -211,12 +212,14 @@ public class ScriptTest {
             lineInfoModel.setColorName(contentModel.getColorName());
             operatorModel.setModel(lineInfoModel);
             operatorModel.setOperationType(OperationTypeEnum.ADD);
-            if(beforeLineId == null){
-                operatorModel.setBeforeLineId(null);
-                beforeLineId = 0L;
+            if(baseLineId == null){
+                operatorModel.setBaseLineId(null);
+                operatorModel.setPosition(null);
+                baseLineId = 0L;
             }else{
-                beforeLineId++;
-                operatorModel.setBeforeLineId(beforeLineId.toString());
+                baseLineId++;
+                operatorModel.setBaseLineId(baseLineId.toString());
+                operatorModel.setPosition(RelativePositionEnum.AFTER);
             }
 
             operatorModel.setChapterId(chapterId.toString());
@@ -246,15 +249,17 @@ public class ScriptTest {
             bo.setModifyUserId(10001001L);
             bo.setSerialNumber(operatorModel.getSerialNumber());
             bo.setModel(model);
+            bo.setPosition(operatorModel.getPosition());
             bo.setOperationType(operatorModel.getOperationType());
-            bo.setBeforeLineId(operatorModel.getBeforeLineId());
+            bo.setBaseLineId(operatorModel.getBaseLineId());
             bo.setModifyDateTime(LocalDateTime.now());
 
             ScriptContentVersionHistory history = new ScriptContentVersionHistory();
             history.setChapterId(Long.valueOf(bo.getChapterId()));
             history.setContent(JSON.toJSONString(bo.getModel()));
             history.setType(bo.getOperationType());
-            history.setBeforeLineId(bo.getBeforeLineId() != null ? Long.valueOf(bo.getBeforeLineId()) : null);
+            history.setBaseLineId(bo.getBaseLineId() != null ? Long.valueOf(bo.getBaseLineId()) : null);
+            history.setPosition(bo.getPosition());
             history.setSerialNum(bo.getSerialNumber());
             history.setLineId(Long.valueOf(bo.getModel().getLineId()));
             history.setModifyUserId(bo.getModifyUserId());

+ 2 - 1
socket/src/main/java/com/sp/socket/handler/PersistenceChapterNodeModifyHistoryHandler.java

@@ -80,7 +80,8 @@ public class PersistenceChapterNodeModifyHistoryHandler implements Runnable{
         history.setChapterId(Long.valueOf(bo.getChapterId()));
         history.setContent(JSON.toJSONString(bo.getModel()));
         history.setType(bo.getOperationType());
-        history.setBeforeLineId(bo.getBeforeLineId() != null ? Long.valueOf(bo.getBeforeLineId()) : null);
+        history.setBaseLineId(bo.getBaseLineId() != null ? Long.valueOf(bo.getBaseLineId()) : null);
+        history.setPosition(bo.getPosition());
         history.setSerialNum(bo.getSerialNumber());
         history.setLineId(Long.valueOf(bo.getModel().getLineId()));
         history.setModifyUserId(bo.getModifyUserId());

+ 2 - 1
socket/src/main/java/com/sp/socket/util/ClientUtil.java

@@ -64,7 +64,8 @@ public class ClientUtil {
         for (ScriptContentVersionHistory record : records) {
             OperatorModel model = new OperatorModel();
             model.setModel(JSON.parseObject(record.getContent(), LineInfoModel.class));
-            model.setBeforeLineId(record.getBeforeLineId() == null ? null : record.getBeforeLineId().toString());
+            model.setBaseLineId(record.getBaseLineId() == null ? null : record.getBaseLineId().toString());
+            model.setPosition(record.getPosition());
             model.setOperationType(record.getType());
             Long serialNum = record.getSerialNum();
             model.setSerialNumber(serialNum);

+ 50 - 8
socket/src/test/java/com/sp/socket/script/ScriptOperator.java

@@ -1,10 +1,14 @@
 package com.sp.socket.script;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.sp.SocketApplication;
 import com.sp.director.ienum.ContentTypeEnum;
 import com.sp.director.ienum.OperationTypeEnum;
+import com.sp.director.ienum.RelativePositionEnum;
+import com.sp.director.module.script.dao.ScriptContentVersionHistoryDao;
 import com.sp.director.module.script.entity.ScriptContentVersionHistory;
+import com.sp.director.module.script.help.ScriptContentVersionOperator;
 import com.sp.director.module.script.model.LineContentModel;
 import com.sp.director.module.script.model.LineInfoModel;
 import com.sp.director.module.script.model.OperatorModel;
@@ -24,6 +28,7 @@ import javax.jms.JMSException;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @Descrption
@@ -43,10 +48,21 @@ public class ScriptOperator {
     @Autowired
     private DefaultCacheManager defaultCacheManager;
 
+    @Autowired
+    private ScriptContentVersionHistoryDao scriptContentVersionHistoryDao;
+
     @Test
+    public void insert() throws JMSException, InterruptedException {
+        insertNode(11111111L);
+        TimeUnit.SECONDS.sleep(10);
+        System.out.println("done");
+        chapterContent();
+    }
+
+//    @Test
     public void insertNode(Long chapterId) throws JMSException {
         int contentIndex = 1;
-        Long beforeLineId = null;
+        Long baseLineId = null;
         List<ScriptContentVersionHistory> persistenceNodeList = new ArrayList<>(30);
         for (int i = 0; i < 10; i++) {
             OperatorModel operatorModel = new OperatorModel();
@@ -63,12 +79,13 @@ public class ScriptOperator {
             lineInfoModel.setColorName(contentModel.getColorName());
             operatorModel.setModel(lineInfoModel);
             operatorModel.setOperationType(OperationTypeEnum.ADD);
-            if(beforeLineId == null){
-                operatorModel.setBeforeLineId(null);
-                beforeLineId = 0L;
+            if(baseLineId == null){
+                operatorModel.setBaseLineId(null);
+                operatorModel.setPosition(null);
+                baseLineId = 0L;
             }else{
-                beforeLineId++;
-                operatorModel.setBeforeLineId(beforeLineId.toString());
+                operatorModel.setBaseLineId(baseLineId.toString());
+                operatorModel.setPosition(RelativePositionEnum.AFTER);
             }
 
             operatorModel.setChapterId(chapterId.toString());
@@ -83,6 +100,7 @@ public class ScriptOperator {
                 scriptContentVersionHistoryService.evictCacheChapterLineNum(chapterId);
                 scriptContentVersionHistoryService.queryOrSaveCacheChapterLineNum(chapterId, lineNum);
                 model.setLineId(lineNum.toString());
+                baseLineId = lineNum;
             }
             String latestSerialNumStr = scriptContentVersionHistoryService.queryOrSaveCacheChapterSerialNum(chapterId, null);
             System.err.println("serialNum" + latestSerialNumStr);
@@ -99,14 +117,15 @@ public class ScriptOperator {
             bo.setSerialNumber(operatorModel.getSerialNumber());
             bo.setModel(model);
             bo.setOperationType(operatorModel.getOperationType());
-            bo.setBeforeLineId(operatorModel.getBeforeLineId());
+            bo.setBaseLineId(operatorModel.getBaseLineId());
             bo.setModifyDateTime(LocalDateTime.now());
 
             ScriptContentVersionHistory history = new ScriptContentVersionHistory();
             history.setChapterId(Long.valueOf(bo.getChapterId()));
             history.setContent(JSON.toJSONString(bo.getModel()));
             history.setType(bo.getOperationType());
-            history.setBeforeLineId(bo.getBeforeLineId() != null ? Long.valueOf(bo.getBeforeLineId()) : null);
+            history.setBaseLineId(bo.getBaseLineId() != null ? Long.valueOf(bo.getBaseLineId()) : null);
+            history.setPosition(bo.getPosition());
             history.setSerialNum(bo.getSerialNumber());
             history.setLineId(Long.valueOf(bo.getModel().getLineId()));
             history.setModifyUserId(bo.getModifyUserId());
@@ -118,5 +137,28 @@ public class ScriptOperator {
     }
 
 
+    @Test
+    public void chapterContent(){
+        QueryWrapper<ScriptContentVersionHistory> qw = new QueryWrapper<>();
+        qw.lambda().eq(ScriptContentVersionHistory::getChapterId, 11111111L);
+        List<ScriptContentVersionHistory> list = scriptContentVersionHistoryDao.list(qw);
+        ScriptContentVersionOperator op = new ScriptContentVersionOperator(11111111L);
+        op.mergeVersion(list);
+        List<LineInfoModel> lineInfoModels = op.parseScriptContent();
+        for (LineInfoModel lineInfoModel : lineInfoModels) {
+            System.out.println(JSON.toJSONString(lineInfoModel));
+        }
+    }
+
+    @Test
+    public void operatorList() {
+        List<OperatorModel> operatorModels =
+                scriptContentVersionHistoryService.listAndSortChapterEditHistory(11111111L, 50L);
+        for (OperatorModel operatorModel : operatorModels) {
+            LineInfoModel model = operatorModel.getModel();
+            String content = model.getContent();
+        }
+        System.out.println(JSON.toJSONString(operatorModels));
+    }
 
 }