提交 fa5e030f authored 作者: 黄承天's avatar 黄承天

[模型模块]新增检查是否已在运行中的机制

上级 304442fd
...@@ -10,6 +10,7 @@ import com.tykj.workflowcore.model.entity.TableInfoEx; ...@@ -10,6 +10,7 @@ import com.tykj.workflowcore.model.entity.TableInfoEx;
import com.tykj.workflowcore.model.repository.BindRepository; import com.tykj.workflowcore.model.repository.BindRepository;
import com.tykj.workflowcore.model.repository.TableInfoExRepository; import com.tykj.workflowcore.model.repository.TableInfoExRepository;
import com.tykj.workflowcore.model.repository.TableInfoRepository; import com.tykj.workflowcore.model.repository.TableInfoRepository;
import com.tykj.workflowcore.workflow_editer.service.FormPageService;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -31,7 +32,8 @@ public class TableInfoExService { ...@@ -31,7 +32,8 @@ public class TableInfoExService {
BindRepository bindRepository; BindRepository bindRepository;
@Autowired @Autowired
TableInfoService tableInfoService; TableInfoService tableInfoService;
@Autowired
FormPageService formPageService;
public void save(TableInfoEx tableInfoEx) { public void save(TableInfoEx tableInfoEx) {
//数据检查 //数据检查
boolean exists = tableInfoExRepository.existsByName(tableInfoEx.getName()); boolean exists = tableInfoExRepository.existsByName(tableInfoEx.getName());
...@@ -63,11 +65,14 @@ public class TableInfoExService { ...@@ -63,11 +65,14 @@ public class TableInfoExService {
if (nonNull(tableInfoEx.getId())) { if (nonNull(tableInfoEx.getId())) {
throw new RuntimeException("修改操作不可附带id"); throw new RuntimeException("修改操作不可附带id");
} }
Integer count = tableInfoExRepository.countByName(tableInfoEx.getName()); //检查是否已在运行中
formPageService.checkIfWorking(tableInfoEx.getProcessKey());
//设置时间 //设置时间
Date date = new Date(); Date date = new Date();
tableInfoEx.setCreatedTime(date); tableInfoEx.setCreatedTime(date);
tableInfoEx.setUpdatedTime(date); tableInfoEx.setUpdatedTime(date);
//设置版本号
Integer count = tableInfoExRepository.countByName(tableInfoEx.getName());
tableInfoEx.setVersion(count + 1); tableInfoEx.setVersion(count + 1);
//保存数据 //保存数据
Integer id = tableInfoExRepository.save(tableInfoEx).getId(); Integer id = tableInfoExRepository.save(tableInfoEx).getId();
...@@ -96,6 +101,9 @@ public class TableInfoExService { ...@@ -96,6 +101,9 @@ public class TableInfoExService {
public List<TableInfoEx> findByProcessKey(String processKey) { public List<TableInfoEx> findByProcessKey(String processKey) {
return tableInfoExRepository.findByProcessKey(processKey).stream() return tableInfoExRepository.findByProcessKey(processKey).stream()
.map(TableInfoEx::getName)
.distinct()
.map(this::findLastVersion)
.map(this::getBinds) .map(this::getBinds)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
......
package com.tykj.workflowcore.model.service; package com.tykj.workflowcore.model.service;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model.entity.ColumnInfo; import com.tykj.workflowcore.model.entity.ColumnInfo;
import com.tykj.workflowcore.model.entity.Quote; import com.tykj.workflowcore.model.entity.Quote;
import com.tykj.workflowcore.model.entity.TableInfo; import com.tykj.workflowcore.model.entity.TableInfo;
import com.tykj.workflowcore.model.repository.ColumnInfoRepository; import com.tykj.workflowcore.model.repository.ColumnInfoRepository;
import com.tykj.workflowcore.model.repository.QuoteRepository; import com.tykj.workflowcore.model.repository.QuoteRepository;
import com.tykj.workflowcore.model.repository.TableInfoRepository; import com.tykj.workflowcore.model.repository.TableInfoRepository;
import com.tykj.workflowcore.workflow_editer.entity.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.service.FormPageService;
import com.tykj.workflowcore.workflow_editer.service.WorkFlowService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -30,6 +35,8 @@ public class TableInfoService { ...@@ -30,6 +35,8 @@ public class TableInfoService {
private ColumnInfoRepository columnInfoRepository; private ColumnInfoRepository columnInfoRepository;
@Autowired @Autowired
private QuoteRepository quoteRepository; private QuoteRepository quoteRepository;
@Autowired
private FormPageService formPageService;
public void save(TableInfo tableInfo) { public void save(TableInfo tableInfo) {
//数据检查 //数据检查
...@@ -62,11 +69,14 @@ public class TableInfoService { ...@@ -62,11 +69,14 @@ public class TableInfoService {
if (nonNull(tableInfo.getId())) { if (nonNull(tableInfo.getId())) {
throw new RuntimeException("修改操作不可附带id"); throw new RuntimeException("修改操作不可附带id");
} }
Integer count = tableInfoRepository.countByName(tableInfo.getName()); //检查是否已经在运行中
formPageService.checkIfWorking(tableInfo.getProcessKey());
//设置时间 //设置时间
Date date = new Date(); Date date = new Date();
tableInfo.setCreatedTime(date); tableInfo.setCreatedTime(date);
tableInfo.setUpdatedTime(date); tableInfo.setUpdatedTime(date);
//设置版本号
Integer count = tableInfoRepository.countByName(tableInfo.getName());
tableInfo.setVersion(count + 1); tableInfo.setVersion(count + 1);
//保存数据 //保存数据
Integer tableInfoId = tableInfoRepository.save(tableInfo).getId(); Integer tableInfoId = tableInfoRepository.save(tableInfo).getId();
......
...@@ -57,5 +57,10 @@ public interface FormPageService { ...@@ -57,5 +57,10 @@ public interface FormPageService {
Specification<FormPage> specificationBuild(PageFormPageVo pageFormPageVo); Specification<FormPage> specificationBuild(PageFormPageVo pageFormPageVo);
/**
* 根据processKey检查是否已在运行中
* @param processKey
*/
void checkIfWorking(String processKey);
} }
...@@ -117,5 +117,21 @@ public class FormPageServiceImpl implements FormPageService { ...@@ -117,5 +117,21 @@ public class FormPageServiceImpl implements FormPageService {
return and.build(); return and.build();
} }
@Override
public void checkIfWorking(String processKey) {
//查询对应的processKey
FlowsInfo byFlowKey = flowInfoService.findByFlowKey(processKey);
//判断 byFlowKey 是否正在运行
Integer state = byFlowKey.getState();
// 0代表这个流程正在运行过程中
if (state == 0) {
throw new ApiException("该页面正在流程中运行,无法被修改");
}
//判断该流程是否存在正在运行的流程实例如果存在将不允许修改页面
List<ProcessInstance> processInstances = workFlowService.queryUnfinishedProcessInstance(processKey);
if (processInstances.size() > 0) {
throw new ApiException("该页面正在流程中运行,无法被修改.请先停止所有正在运行的流程实例");
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论