|
@@ -5,6 +5,7 @@ import com.sp.director.exception.ParamException;
|
|
|
import com.sp.director.ienum.OperationTypeEnum;
|
|
|
import com.sp.director.module.script.entity.ScriptContentVersionHistory;
|
|
|
import com.sp.director.module.script.model.LineInfoModel;
|
|
|
+import com.sp.director.module.script.model.OperatorModel;
|
|
|
import com.sp.director.utils.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
@@ -41,8 +42,10 @@ public class ScriptContentVersionOperator {
|
|
|
*/
|
|
|
private Integer docSubscriptionSize = 70;
|
|
|
|
|
|
+ private Map<Long, Integer> lineNumMap = new HashMap<>();
|
|
|
+
|
|
|
/**
|
|
|
- * 章节行列表,index 为行号 -1
|
|
|
+ * 章节行列表,
|
|
|
*/
|
|
|
private List<LineInfoModel> chapterLineList = new ArrayList<>();
|
|
|
|
|
@@ -67,6 +70,31 @@ public class ScriptContentVersionOperator {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取整个文档的操作流程
|
|
|
+ */
|
|
|
+ public List<OperatorModel> getAndSortHistoryOperator(){
|
|
|
+ // 将剧本内容按照版本进行分发排序,从小到大
|
|
|
+ contentVersionHistoryList = sortBySerialNum(contentVersionHistoryList);
|
|
|
+ List<OperatorModel> resultList = new ArrayList<>(contentVersionHistoryList.size());
|
|
|
+ for (ScriptContentVersionHistory record : contentVersionHistoryList) {
|
|
|
+ OperatorModel model = new OperatorModel();
|
|
|
+ model.setModel(JSON.parseObject(record.getContent(), LineInfoModel.class));
|
|
|
+ model.setBeforeLineId(record.getBeforeLineId().toString());
|
|
|
+ model.setOperationType(record.getType());
|
|
|
+ model.setSerialNumber(record.getSerialNum());
|
|
|
+ resultList.add(model);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ScriptContentVersionHistory> sortBySerialNum(List<ScriptContentVersionHistory> list){
|
|
|
+ return contentVersionHistoryList
|
|
|
+ .stream()
|
|
|
+ .sorted(Comparator.comparing(ScriptContentVersionHistory::getSerialNum))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 解析出文档内容,以行为单位
|
|
|
* @return
|
|
|
*/
|
|
@@ -75,10 +103,7 @@ public class ScriptContentVersionOperator {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
// 将剧本内容按照版本进行分发排序,从小到大
|
|
|
- contentVersionHistoryList = contentVersionHistoryList
|
|
|
- .stream()
|
|
|
- .sorted(Comparator.comparing(ScriptContentVersionHistory::getSerialNum))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ contentVersionHistoryList = sortBySerialNum(contentVersionHistoryList);
|
|
|
int version = 0;
|
|
|
for (ScriptContentVersionHistory contentHistory : contentVersionHistoryList) {
|
|
|
String content = contentHistory.getContent();
|
|
@@ -89,29 +114,37 @@ public class ScriptContentVersionOperator {
|
|
|
}
|
|
|
|
|
|
version ++;
|
|
|
- Integer lineId = contentHistory.getLineId();
|
|
|
- int index = lineId - 1;
|
|
|
- LineInfoModel lineInfoModel = chapterLineList.get(index);
|
|
|
+ Long beforeLineId = contentHistory.getBeforeLineId();
|
|
|
+ Integer beforeLineIdIndex = lineNumMap.get(beforeLineId);
|
|
|
+
|
|
|
+ if(beforeLineIdIndex == null){
|
|
|
+ beforeLineIdIndex = -1;
|
|
|
+ }
|
|
|
serialNum = contentHistory.getSerialNum();
|
|
|
+
|
|
|
// 判断是新增还是删除
|
|
|
if (OperationTypeEnum.ADD.equals(contentHistory.getType())) {
|
|
|
- if( Objects.nonNull(lineInfoModel) ){
|
|
|
- log.error("操作记录的顺序异常,剧本{}的新增行{}已存在",chapterId,lineId);
|
|
|
+ Integer index = beforeLineIdIndex + 1;
|
|
|
+ // 判断beforeLineId的记录是否存在
|
|
|
+ if (beforeLineIdIndex != -1 && chapterLineList.get(beforeLineIdIndex) == null) {
|
|
|
+ log.error("操作记录的顺序异常,新增行{}上一行记录不存在存在",chapterId,contentHistory.getLineId());
|
|
|
throw new ParamException();
|
|
|
}
|
|
|
chapterLineList.add(index,model);
|
|
|
+ lineNumMap.put(contentHistory.getLineId(), index);
|
|
|
}else{
|
|
|
+ Integer index = lineNumMap.get(contentHistory.getLineId());
|
|
|
+ LineInfoModel lineInfoModel = chapterLineList.get(index);
|
|
|
+ // 判断删除的行是否存在
|
|
|
if( Objects.nonNull(lineInfoModel) ){
|
|
|
- log.error("操作记录的顺序异常,剧本{}的删除的行{}不存在",chapterId,lineId);
|
|
|
+ log.error("操作记录的顺序异常,剧本{}的删除的行{}不存在",chapterId,contentHistory.getLineId());
|
|
|
throw new ParamException();
|
|
|
}
|
|
|
chapterLineList.remove(index);
|
|
|
+ lineNumMap.remove(contentHistory.getLineId());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- return null;
|
|
|
+ return chapterLineList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -147,4 +180,5 @@ public class ScriptContentVersionOperator {
|
|
|
LineInfoModel model = JSON.parseObject(str, LineInfoModel.class);
|
|
|
return model;
|
|
|
}
|
|
|
+
|
|
|
}
|