|
@@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowPageReqVO;
|
|
|
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowTestReqVO;
|
|
|
-import cn.iocoder.yudao.module.ai.controller.admin.workflow.vo.AiWorkflowUpdateModelReqVO;
|
|
|
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO;
|
|
|
import cn.iocoder.yudao.module.ai.dal.dataobject.workflow.AiWorkflowDO;
|
|
|
import cn.iocoder.yudao.module.ai.dal.mysql.workflow.AiWorkflowMapper;
|
|
@@ -22,7 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WORKFLOW_KEY_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WORKFLOW_CODE_EXISTS;
|
|
|
import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WORKFLOW_NOT_EXISTS;
|
|
|
|
|
|
/**
|
|
@@ -42,16 +41,15 @@ public class AiWorkflowServiceImpl implements AiWorkflowService {
|
|
|
|
|
|
@Override
|
|
|
public Long createWorkflow(AiWorkflowSaveReqVO createReqVO) {
|
|
|
- validateWorkflowForCreateOrUpdate(null, createReqVO.getDefinitionKey());
|
|
|
+ validateWorkflowForCreateOrUpdate(null, createReqVO.getCode());
|
|
|
AiWorkflowDO workflow = BeanUtils.toBean(createReqVO, AiWorkflowDO.class);
|
|
|
- workflow.setModel(StrUtil.EMPTY);
|
|
|
workflowMapper.insert(workflow);
|
|
|
return workflow.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateWorkflow(AiWorkflowSaveReqVO updateReqVO) {
|
|
|
- validateWorkflowForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getDefinitionKey());
|
|
|
+ validateWorkflowForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getCode());
|
|
|
AiWorkflowDO workflow = BeanUtils.toBean(updateReqVO, AiWorkflowDO.class);
|
|
|
workflowMapper.updateById(workflow);
|
|
|
}
|
|
@@ -72,22 +70,16 @@ public class AiWorkflowServiceImpl implements AiWorkflowService {
|
|
|
return workflowMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updateWorkflowModel(AiWorkflowUpdateModelReqVO updateReqVO) {
|
|
|
- validateWorkflowExists(updateReqVO.getId());
|
|
|
- workflowMapper.updateById(new AiWorkflowDO().setId(updateReqVO.getId()).setModel(updateReqVO.getModel()));
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Object testWorkflow(AiWorkflowTestReqVO testReqVO) {
|
|
|
Map<String, Object> variables = testReqVO.getParams();
|
|
|
- Tinyflow tinyflow = parseFlowParam(testReqVO.getModel());
|
|
|
+ Tinyflow tinyflow = parseFlowParam(testReqVO.getGraph());
|
|
|
return tinyflow.toChain().executeForResult(variables);
|
|
|
}
|
|
|
|
|
|
- private void validateWorkflowForCreateOrUpdate(Long id, String key) {
|
|
|
+ private void validateWorkflowForCreateOrUpdate(Long id, String code) {
|
|
|
validateWorkflowExists(id);
|
|
|
- validateKeyUnique(id, key);
|
|
|
+ validateCodeUnique(id, code);
|
|
|
}
|
|
|
|
|
|
private void validateWorkflowExists(Long id) {
|
|
@@ -100,27 +92,27 @@ public class AiWorkflowServiceImpl implements AiWorkflowService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void validateKeyUnique(Long id, String key) {
|
|
|
- if (StrUtil.isBlank(key)) {
|
|
|
+ private void validateCodeUnique(Long id, String code) {
|
|
|
+ if (StrUtil.isBlank(code)) {
|
|
|
return;
|
|
|
}
|
|
|
- AiWorkflowDO workflow = workflowMapper.selectByKey(key);
|
|
|
+ AiWorkflowDO workflow = workflowMapper.selectByCode(code);
|
|
|
if (ObjUtil.isNull(workflow)) {
|
|
|
return;
|
|
|
}
|
|
|
if (ObjUtil.isNull(id)) {
|
|
|
- throw exception(WORKFLOW_KEY_EXISTS);
|
|
|
+ throw exception(WORKFLOW_CODE_EXISTS);
|
|
|
}
|
|
|
if (ObjUtil.notEqual(workflow.getId(), id)) {
|
|
|
- throw exception(WORKFLOW_KEY_EXISTS);
|
|
|
+ throw exception(WORKFLOW_CODE_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Tinyflow parseFlowParam(String model) {
|
|
|
+ private Tinyflow parseFlowParam(String graph) {
|
|
|
// TODO @lesan:可以使用 jackson 哇?
|
|
|
- JSONObject json = JSONObject.parseObject(model);
|
|
|
+ JSONObject json = JSONObject.parseObject(graph);
|
|
|
JSONArray nodeArr = json.getJSONArray("nodes");
|
|
|
- Tinyflow tinyflow = new Tinyflow(json.toJSONString());
|
|
|
+ Tinyflow tinyflow = new Tinyflow(json.toJSONString());
|
|
|
for (int i = 0; i < nodeArr.size(); i++) {
|
|
|
JSONObject node = nodeArr.getJSONObject(i);
|
|
|
switch (node.getString("type")) {
|