优化流程 Model 的更新逻辑

This commit is contained in:
YunaiV 2022-01-01 19:31:16 +08:00
parent df91c3ceff
commit 1294506a95
10 changed files with 146 additions and 148 deletions

View File

@ -1,9 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.model;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -49,16 +46,19 @@ public class BpmModelController {
return success(bpmModelService.createModel(createRetVO));
}
@PostMapping("/update")
@ApiOperation(value = "修改模型属性")
public CommonResult<String> updateModel(@RequestBody BpmModelCreateReqVO modelVO) {
return bpmModelService.updateModel(modelVO);
@PutMapping("/update")
@ApiOperation(value = "修改模型")
public CommonResult<Boolean> updateModel(@RequestBody BpmModelUpdateReqVO modelVO) {
bpmModelService.updateModel(modelVO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation(value = "删除模型")
public CommonResult<String> deleteModel(@RequestParam String modelId) {
return bpmModelService.deleteModel(modelId);
@DeleteMapping("/delete")
@ApiOperation("删除模型")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
public CommonResult<Boolean> deleteModel(@RequestParam("id") String id) {
bpmModelService.deleteModel(id);
return success(true);
}
@PostMapping("/deploy")

View File

@ -6,14 +6,15 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotEmpty;
@ApiModel("流程模型的创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmModelRespVO extends BpmModelBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1024")
private String id;
@ApiModelProperty(value = "BPMN XML", required = true)
private String bpmnXml;

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotEmpty;
@ApiModel("流程模型的更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmModelUpdateReqVO extends BpmModelBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1024")
@NotEmpty(message = "编号不能为空")
private String id;
@ApiModelProperty(value = "BPMN XML", required = true)
@NotEmpty(message = "BPMN XML 不能为空")
private String bpmnXml;
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.model;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
@ -64,6 +65,12 @@ public interface ModelConvert {
model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId())));
}
default void copy(Model model, BpmModelUpdateReqVO bean) {
model.setName(bean.getName());
model.setCategory(bean.getCategory());
model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId())));
}
default BpmModelMetaInfoRespDTO buildMetaInfo(String description, Long formId) {
BpmModelMetaInfoRespDTO metaInfo = new BpmModelMetaInfoRespDTO();
metaInfo.setDescription(description);

View File

@ -25,8 +25,8 @@ public interface BpmErrorCodeConstants {
// ========== OA 工作流模块 1-009-002-000 ==========
ErrorCode BPM_MODEL_KEY_EXISTS = new ErrorCode(1009002000, "已经存在流程标识为【{}】的流程");
ErrorCode BPMN_MODEL_NOT_EXISTS = new ErrorCode(1009002001, "流程模型不存在");
ErrorCode BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS = new ErrorCode(1004001001, "模型数据为空,请先成功设计流程并保存");
ErrorCode BPMN_MODEL_ERROR = new ErrorCode(1004001002, "工作流模型异常");
ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001009, "流程数据为空");
ErrorCode BPMN_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1004001004, "流程定义不存在");

View File

@ -1,12 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.model;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
/**
* 流程模型接口
*
@ -30,22 +29,20 @@ public interface BpmModelService {
*/
BpmModelRespVO getModel(String id);
// TODO @Li不用返回 CommonResult
// TODO @LicreateBpmModal
/**
* 创建流程模型
*
* @param modelVO 创建信息
* @return 创建的流程模型的编号
*/
String createModel(BpmModelCreateReqVO modelVO);
String createModel(@Valid BpmModelCreateReqVO modelVO);
/**
* 修改模型属性填充bpmn数据
* @param modelVO 模型对象
* @return 返回成功
* 修改流程模型
*
* @param updateReqVO 更新信息
*/
CommonResult<String> updateModel(BpmModelCreateReqVO modelVO);
void updateModel(@Valid BpmModelUpdateReqVO updateReqVO);
/**
* 部署模型 使模型成为一个 process
@ -56,9 +53,9 @@ public interface BpmModelService {
/**
* 删除模型
* @param modelId 模型Id
* @return 返回成功
*
* @param id 编号
*/
CommonResult<String> deleteModel(String modelId);
void deleteModel(String id);
}

View File

@ -2,10 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.ModelConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
@ -115,6 +112,7 @@ public class BpmModelServiceImpl implements BpmModelService {
if (keyModel != null) {
throw exception(BPM_MODEL_KEY_EXISTS);
}
// TODO @芋艿需要校验下 key 的格式
// 创建流程定义
Model model = repositoryService.newModel();
@ -137,55 +135,24 @@ public class BpmModelServiceImpl implements BpmModelService {
// ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
// repositoryService.setProcessDefinitionCategory(definition.getId(), createReqVO.getCategory());
// return definition.getId();
// }
// @Override
// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作所以开启事务
// public String createModel(BpmModelCreateReqVO createReqVO) {
// // 校验流程标识已经存在
// Model keyModel = this.getModelByKey(createReqVO.getKey());
// if (keyModel != null) {
// throw exception(BPM_MODEL_KEY_EXISTS);
// }
//
// // 创建流程定义
// Model model = repositoryService.newModel();
// ModelConvert.INSTANCE.copy(model, createReqVO);
// // 保存流程定义
// repositoryService.saveModel(model);
// // 添加 BPMN XML
// repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml()));
// return model.getId();
// }
@Override
public CommonResult<String> updateModel(BpmModelCreateReqVO modelVO) {
// try {
// Model model = repositoryService.getModel(modelVO.getId());
// if (ObjectUtils.isEmpty(model)) {
// throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
// }
// // 只能修改名字跟描述
// BpmModelCreateReqVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), BpmModelCreateReqVO.class);
// if (ObjectUtils.isEmpty(modelCreateVO)) {
// modelCreateVO = new BpmModelCreateReqVO();
// }
// modelCreateVO.setName(modelVO.getName());
// modelCreateVO.setDescription(modelVO.getDescription());
// model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
// model.setName(modelVO.getName());
// model.setKey(modelVO.getKey());
// // 更新模型
// repositoryService.saveModel(model);
//
// repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
//
// return CommonResult.success("保存成功");
// }catch (Exception e){
// log.info("模型更新失败modelVO = {}", modelVO, e);
// throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
// }
return null;
@Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作所以开启事务
public void updateModel(BpmModelUpdateReqVO updateReqVO) {
// 校验流程模型存在
Model model = repositoryService.getModel(updateReqVO.getId());
if (model == null) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
}
// TODO @芋艿需要校验下 key 的格式
// 修改流程定义
ModelConvert.INSTANCE.copy(model, updateReqVO);
// 更新模型
repositoryService.saveModel(model);
// 更新 BPMN XML
repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml()));
}
@Override
@ -193,11 +160,11 @@ public class BpmModelServiceImpl implements BpmModelService {
try {
Model modelData = repositoryService.getModel(modelId);
if (ObjectUtils.isEmpty(modelData)) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
}
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
if (bytes == null) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
}
// 将xml转换为流
// TODO @Li这里是标准逻辑看看 hutool 有没工具类提供如果没有咱自己封装一个
@ -226,10 +193,14 @@ public class BpmModelServiceImpl implements BpmModelService {
}
@Override
public CommonResult<String> deleteModel(String modelId) {
// TODO @Liactivitie 是逻辑删除么
repositoryService.deleteModel(modelId);
return CommonResult.success("删除成功");
public void deleteModel(String id) {
// 校验流程模型存在
Model model = repositoryService.getModel(id);
if (model == null) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
}
// 执行删除
repositoryService.deleteModel(id);
}
private Model getModelByKey(String key) {

View File

@ -1,6 +1,6 @@
import request from '@/utils/request'
export function page(query) {
export function getModelPage(query) {
return request({
url: '/bpm/model/page',
method: 'get',
@ -15,15 +15,15 @@ export function getModel(id) {
})
}
export function modelUpdate(data) {
export function updateModel(data) {
return request({
url: '/bpm/model/update',
method: 'POST',
method: 'PUT',
data: data
})
}
export function modelSave(data) {
export function createModel(data) {
return request({
url: '/bpm/model/create',
method: 'POST',
@ -31,15 +31,14 @@ export function modelSave(data) {
})
}
export function modelDelete(data) {
export function deleteModel(id) {
return request({
url: '/bpm/model/delete?modelId='+ data.modelId,
method: 'POST',
data: data
url: '/bpm/model/delete?id=' + id,
method: 'DELETE'
})
}
export function modelDeploy(data) {
export function deployModel(data) {
return request({
url: '/bpm/model/deploy?modelId='+ data.modelId,
method: 'POST',

View File

@ -16,7 +16,7 @@
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="el-icon-plus" size="mini" @click="openBpmn"
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['infra:config:create']">新建流程</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -38,26 +38,26 @@
</el-table-column>
<el-table-column label="操作" align="center" width="240">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-setting" @click="change(scope.row)">设计流程</el-button>
<el-button size="mini" type="text" icon="el-icon-setting" @click="handleUpdate(scope.row)">设计流程</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="modelDelete(scope.row)">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-thumb" @click="modelDeploy(scope.row)">发布</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
<el-dialog class="bpmnclass dialogClass" :visible.sync="showBpmnBool" :before-close="close" :fullscreen="true">
<vue-bpmn v-if="showBpmnBool" product="activiti" @processSave="processSave"
:bpmnXml="bpmnXML" :bpmnData="bpmnData" @beforeClose="close" />
<!-- 流程编辑器 -->
<el-dialog class="bpmnclass dialogClass" :visible.sync="showBpmnOpen" :before-cancel="cancel" :fullscreen="true">
<vue-bpmn v-if="showBpmnOpen" product="activiti" @processSave="processSave"
:bpmnXml="bpmnXML" :bpmnData="bpmnData" @beforeClose="cancel" />
</el-dialog>
</div>
</template>
<script>
import {modelDelete, modelDeploy, modelSave, modelUpdate, page, getModel} from "@/api/bpm/model";
import {deleteModel, deployModel, createModel, updateModel, getModelPage, getModel} from "@/api/bpm/model";
import VueBpmn from "@/components/bpmn/VueBpmn";
export default {
@ -68,7 +68,6 @@ export default {
loading: true,
//
showSearch: true,
showBpmnBool: false,
//
total: 0,
//
@ -79,6 +78,7 @@ export default {
pageSize: 10
},
// BPMN
showBpmnOpen: false,
bpmnXML: null,
bpmnData: {},
};
@ -88,19 +88,20 @@ export default {
this.getList();
},
methods: {
/** 查询登录日志列表 */
/** 查询流程模型列表 */
getList() {
this.loading = true;
page(this.queryParams).then(response => {
getModelPage(this.queryParams).then(response => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
}
);
},
//
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
//
reset() {
this.bpmnData = {}
this.bpmnXML = ""
},
/** 搜索按钮操作 */
handleQuery() {
@ -114,49 +115,48 @@ export default {
this.handleQuery();
},
processSave(data) {
const that = this;
// id
//
if (data.id) {
let postData = JSON.parse(data.metaInfo)
postData.bpmnXml = data.bpmnXml
postData.id = data.id
postData.name = data.name
postData.key = data.key
postData.description = data.description
modelUpdate(postData).then(response => {
this.msgSuccess("保存成功");
updateModel(data).then(response => {
this.msgSuccess("修改成功");
//
this.showBpmnOpen = false
this.getList();
})
this.showBpmnBool = false
this.getList();
return
}
modelSave(data).then(response => {
that.bpmnData.id = response.data
//
createModel(data).then(response => {
this.bpmnData.id = response.data
this.msgSuccess("保存成功");
//
this.showBpmnOpen = false
this.getList();
})
this.showBpmnBool = false
this.getList();
},
openBpmn() {
this.bpmnData = {}
this.bpmnXML = ""
this.showBpmnBool = true
},
close() {
this.showBpmnBool = false
this.getList();
},
change(row) {
handleAdd() {
// Model
this.bpmnXML = ""
this.bpmnData = {}
this.reset()
//
this.showBpmnOpen = true
},
cancel() {
//
this.showBpmnOpen = false
// Model
this.reset()
//
this.getList()
},
handleUpdate(row) {
// Model
this.reset()
// Model
getModel(row.id).then(response => {
this.bpmnXML = response.data.bpmnXml
this.bpmnData = response.data
//
this.showBpmnBool = true
this.showBpmnOpen = true
})
},
modelDelete(row) {
@ -166,9 +166,7 @@ export default {
cancelButtonText: "取消",
type: "warning"
}).then(function() {
modelDelete({
modelId: row.id
}).then(response => {
deleteModel(row.id).then(response => {
that.getList();
that.msgSuccess("删除成功");
})
@ -181,7 +179,7 @@ export default {
cancelButtonText: "取消",
type: "success"
}).then(function() {
modelDeploy({
deployModel({
modelId: row.id
}).then(response => {
that.getList();

View File

@ -33,8 +33,8 @@
<el-table-column label="操作" align="center" >
<template slot-scope="scope">
<!-- <el-button size="mini" type="text" icon="el-icon-setting" @click="change(scope.row)">设计流程</el-button>-->
<!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="modelDelete(scope.row)">删除</el-button>-->
<!-- <el-button size="mini" type="text" icon="el-icon-thumb" @click="modelDeploy(scope.row)">发布</el-button>-->
<!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="deleteModel(scope.row)">删除</el-button>-->
<!-- <el-button size="mini" type="text" icon="el-icon-thumb" @click="deployModel(scope.row)">发布</el-button>-->
</template>
</el-table-column>
</el-table>
@ -114,14 +114,14 @@ export default {
postData.name = data.name
postData.key = data.key
postData.description = data.description
modelUpdate(postData).then(response => {
updateModel(postData).then(response => {
this.msgSuccess("保存成功");
})
this.showBpmnBool = false
this.getList();
return
}
modelSave(data).then(response => {
createModel(data).then(response => {
that.bpmnData.id = response.data
this.msgSuccess("保存成功");
})
@ -151,7 +151,7 @@ export default {
cancelButtonText: "取消",
type: "warning"
}).then(function() {
modelDelete({
deleteModel({
modelId: row.id
}).then(response => {
that.getList();
@ -166,7 +166,7 @@ export default {
cancelButtonText: "取消",
type: "success"
}).then(function() {
modelDeploy({
deployModel({
modelId: row.id
}).then(response => {
that.getList();