|
@@ -5,10 +5,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fjhx.flow.entity.flow.dto.FlowDefinitionDto;
|
|
import com.fjhx.flow.entity.flow.dto.FlowDefinitionDto;
|
|
import com.fjhx.flow.entity.flow.po.FlowDefinition;
|
|
import com.fjhx.flow.entity.flow.po.FlowDefinition;
|
|
import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
|
|
import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
|
|
|
|
+import com.fjhx.flow.entity.flow.po.FlowInfo;
|
|
|
|
+import com.fjhx.flow.enums.NodeTypeEnum;
|
|
import com.fjhx.flow.mapper.flow.FlowDefinitionMapper;
|
|
import com.fjhx.flow.mapper.flow.FlowDefinitionMapper;
|
|
|
|
+import com.fjhx.flow.service.flow.FlowDefinitionNodeService;
|
|
import com.fjhx.flow.service.flow.FlowDefinitionService;
|
|
import com.fjhx.flow.service.flow.FlowDefinitionService;
|
|
|
|
+import com.fjhx.flow.service.flow.FlowInfoService;
|
|
|
|
+import com.ruoyi.common.constant.StatusConstant;
|
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@@ -23,20 +32,79 @@ import java.util.List;
|
|
@Service
|
|
@Service
|
|
public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper, FlowDefinition> implements FlowDefinitionService {
|
|
public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper, FlowDefinition> implements FlowDefinitionService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FlowInfoService flowInfoService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FlowDefinitionNodeService flowDefinitionNodeService;
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
public void add(FlowDefinition flowDefinition) {
|
|
public void add(FlowDefinition flowDefinition) {
|
|
- // todo 判断是否已添加
|
|
|
|
|
|
+ Long flowInfoId = flowDefinition.getFlowInfoId();
|
|
|
|
+ String tenantId = flowDefinition.getTenantId();
|
|
|
|
+
|
|
|
|
+ long count = count(q -> q.eq(FlowDefinition::getFlowInfoId, flowInfoId).eq(FlowDefinition::getTenantId, tenantId));
|
|
|
|
+
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ throw new ServiceException("流程已添加");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FlowInfo flowInfo = flowInfoService.getById(flowInfoId);
|
|
|
|
+ if (flowInfo == null) {
|
|
|
|
+ throw new ServiceException("没有找到流程定义");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ flowDefinition.setId(IdWorker.getId());
|
|
|
|
+ flowDefinition.setFlowKey(flowInfo.getFlowKey());
|
|
|
|
+ flowDefinition.setVersionNumber(1);
|
|
|
|
+ flowDefinition.setCurrentVersion(StatusConstant.YES);
|
|
this.save(flowDefinition);
|
|
this.save(flowDefinition);
|
|
|
|
+
|
|
|
|
+ // 添加默认流程节点
|
|
|
|
+ FlowDefinitionNode startNode = new FlowDefinitionNode();
|
|
|
|
+ startNode.setId(IdWorker.getId());
|
|
|
|
+ startNode.setFlowDefinitionId(flowDefinition.getId());
|
|
|
|
+ startNode.setNodeName("发起申请");
|
|
|
|
+ startNode.setNodeType(NodeTypeEnum.START.getKey());
|
|
|
|
+ startNode.setParentId(0L);
|
|
|
|
+
|
|
|
|
+ FlowDefinitionNode endNode = new FlowDefinitionNode();
|
|
|
|
+ endNode.setId(IdWorker.getId());
|
|
|
|
+ endNode.setFlowDefinitionId(flowDefinition.getId());
|
|
|
|
+ endNode.setNodeName("结束");
|
|
|
|
+ endNode.setNodeType(NodeTypeEnum.END.getKey());
|
|
|
|
+ endNode.setParentId(startNode.getId());
|
|
|
|
+
|
|
|
|
+ flowDefinitionNodeService.saveBatch(Arrays.asList(startNode, endNode));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void addVersion(FlowDefinitionDto dto) {
|
|
public void addVersion(FlowDefinitionDto dto) {
|
|
- // todo 判断是否已添加
|
|
|
|
|
|
+ Long flowInfoId = dto.getFlowInfoId();
|
|
|
|
+ String tenantId = dto.getTenantId();
|
|
|
|
+
|
|
|
|
+ FlowDefinition flowDefinition = getOne(q -> q
|
|
|
|
+ .eq(FlowDefinition::getFlowInfoId, flowInfoId)
|
|
|
|
+ .eq(FlowDefinition::getTenantId, tenantId)
|
|
|
|
+ .orderByDesc(FlowDefinition::getVersionNumber));
|
|
|
|
+
|
|
|
|
+ if (flowDefinition == null) {
|
|
|
|
+ throw new ServiceException("未添加流程,无法新增流程版本");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dto.setId(IdWorker.getId());
|
|
|
|
+ dto.setFlowKey(flowDefinition.getFlowKey());
|
|
|
|
+ dto.setVersionNumber(flowDefinition.getVersionNumber() + 1);
|
|
|
|
+ dto.setCurrentVersion(StatusConstant.NO);
|
|
this.save(dto);
|
|
this.save(dto);
|
|
|
|
|
|
|
|
+ // 添加流程节点
|
|
List<FlowDefinitionNode> flowDefinitionNodeList = dto.getFlowDefinitionNodeList();
|
|
List<FlowDefinitionNode> flowDefinitionNodeList = dto.getFlowDefinitionNodeList();
|
|
|
|
|
|
for (FlowDefinitionNode flowDefinitionNode : flowDefinitionNodeList) {
|
|
for (FlowDefinitionNode flowDefinitionNode : flowDefinitionNodeList) {
|
|
|
|
+ flowDefinitionNode.setFlowDefinitionId(flowDefinition.getId());
|
|
|
|
+
|
|
Long oldId = flowDefinitionNode.getId();
|
|
Long oldId = flowDefinitionNode.getId();
|
|
long newId = IdWorker.getId();
|
|
long newId = IdWorker.getId();
|
|
flowDefinitionNode.setId(newId);
|
|
flowDefinitionNode.setId(newId);
|
|
@@ -48,6 +116,7 @@ public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ flowDefinitionNodeService.saveBatch(flowDefinitionNodeList);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|