Browse Source

历史模型接口

caixiaofeng 6 months ago
parent
commit
3d8fdcb3a6

+ 14 - 0
flow-workflow/flow-workflow-api/src/main/java/com/flow/service/FlowModelService.java

@@ -4,6 +4,7 @@ import com.flow.common.mybatis.service.BaseService;
 import com.flow.entity.DatasetField;
 import com.flow.entity.FlowDefine;
 import com.flow.entity.FlowModel;
+import com.flow.entity.FlowModelHistory;
 import com.flow.model.spreadsheet.SpreadSheet;
 
 import java.io.IOException;
@@ -67,6 +68,19 @@ public interface FlowModelService extends BaseService<FlowModel> {
      */
     FlowModel getModel(Long modelId);
 
+    /**
+     * 获取模型历史
+     * @param modelId
+     * @return
+     */
+    List<FlowModelHistory> getModelHistory(Long modelId);
+
+    /**
+     * 切换历史模型
+     * @param historyModelId
+     */
+    void switchModel(Long historyModelId);
+
     /**
      * 获取打印字段
      * @param modelId

+ 2 - 1
flow-workflow/flow-workflow-biz/src/main/java/com/flow/service/impl/FlowModelHistoryServiceImpl.java

@@ -15,7 +15,8 @@ public class FlowModelHistoryServiceImpl extends BaseServiceImpl<FlowModelHistor
 
     @Override
     public FlowModelHistory save(FlowModel flowModel) {
-        FlowModelHistory flowModelHistory = new FlowModelHistory(flowModel);
+        FlowModelHistory flowModelHistory = new FlowModelHistory();
+        flowModelHistory.toFlowModelHistory(flowModel);
         flowModelHistoryDao.insert(flowModelHistory);
         return flowModelHistory;
     }

+ 21 - 1
flow-workflow/flow-workflow-biz/src/main/java/com/flow/service/impl/FlowModelServiceImpl.java

@@ -15,6 +15,7 @@ import com.flow.service.FlowModelHistoryService;
 import com.flow.service.FlowModelService;
 import com.flow.service.ReportTemplateService;
 import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.flowable.bpmn.converter.BpmnXMLConverter;
 import org.flowable.bpmn.model.BpmnModel;
@@ -104,7 +105,26 @@ public class FlowModelServiceImpl extends BaseServiceImpl<FlowModelDao, FlowMode
                 .eq(FlowModel::getId, modelId)
                 .last(SqlConstant.LIMIT1)
                 .oneOpt();
-        return optional.orElse(null);
+        return optional.orElseGet(() -> flowModelHistoryService.lambdaQuery().eq(FlowModelHistory::getId, modelId).one());
+    }
+
+    @Override
+    public List<FlowModelHistory> getModelHistory(Long modelId) {
+        return flowModelHistoryService.lambdaQuery()
+                .select(FlowModelHistory.class, i -> !StringUtils.equalsAny(i.getColumn(), "process", "form", "settings"))
+                .eq(FlowModelHistory::getModelId, modelId)
+                .list();
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void switchModel(Long historyModelId) {
+        FlowModelHistory flowModelHistory = flowModelHistoryService.getById(historyModelId);
+        FlowModel flowModel = flowModelDao.selectById(flowModelHistory.getModelId());
+        flowModelHistoryService.removeById(historyModelId);
+        flowModelHistoryService.save(flowModel);
+        flowModelDao.deleteById(flowModel);
+        flowModelDao.insert(flowModelHistory);
     }
 
     @Transactional(rollbackFor = Exception.class)

+ 13 - 0
flow-workflow/flow-workflow-controller/src/main/java/com/flow/controller/FlowModelController.java

@@ -4,6 +4,7 @@ import com.flow.common.core.model.Result;
 import com.flow.entity.DatasetField;
 import com.flow.entity.FlowDefine;
 import com.flow.entity.FlowModel;
+import com.flow.entity.FlowModelHistory;
 import com.flow.model.spreadsheet.SpreadSheet;
 import com.flow.service.FlowModelService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,6 +65,18 @@ public class FlowModelController {
         return Result.success(model);
     }
 
+    @GetMapping("/history/{modelId}")
+    public Result<List<FlowModelHistory>> getModelHistory(@PathVariable Long modelId) {
+        List<FlowModelHistory> modelHistory = flowModelService.getModelHistory(modelId);
+        return Result.success(modelHistory);
+    }
+
+    @GetMapping("/switch/{historyModelId}")
+    public Result<?> switchModel(@PathVariable Long historyModelId) {
+        flowModelService.switchModel(historyModelId);
+        return Result.success();
+    }
+
     @GetMapping("/report/{modelId}")
     public Result<List<DatasetField>> getReportField(@PathVariable String modelId) {
         List<DatasetField> list = flowModelService.getReportField(modelId);

+ 3 - 3
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/FlowModelHistory.java

@@ -10,11 +10,10 @@ import lombok.EqualsAndHashCode;
 @EqualsAndHashCode(callSuper = true)
 @Data
 public class FlowModelHistory extends FlowModel {
-
     @JsonSerialize(using = ToStringSerializer.class)
     private Long modelId;
 
-    public FlowModelHistory(FlowModel flowModel) {
+    public FlowModelHistory toFlowModelHistory(FlowModel flowModel) {
         this.setModelId(flowModel.getId());
         this.setCode(flowModel.getCode());
         this.setName(flowModel.getName());
@@ -25,12 +24,13 @@ public class FlowModelHistory extends FlowModel {
         this.setVersion(flowModel.getVersion());
         this.setGroupId(flowModel.getGroupId());
         this.setAdmin(flowModel.getAdmin());
+        this.setSettings(flowModel.getSettings());
         this.setEnable(flowModel.getEnable());
         this.setRemark(flowModel.getRemark());
-        this.setAdmin(flowModel.getAdmin());
         this.setCreatedBy(flowModel.getCreatedBy());
         this.setCreateTime(flowModel.getCreateTime());
         this.setUpdatedBy(flowModel.getUpdatedBy());
         this.setUpdateTime(flowModel.getUpdateTime());
+        return this;
     }
 }