The front-end code
<template>
<div>
<el-table :data="tableData" style="width: 100%" max-height="250">
<el-table-column fixed prop="id" label="ID" width="150">
</el-table-column>
<el-table-column prop="processInstanceId" label=" flow id" width="120">
</el-table-column>
<el-table-column prop="processInstanceStatus" label=" Flow state " width="120">
</el-table-column>
<el-table-column prop="businessKey" label=" Business key" width="120">
</el-table-column>
<el-table-column label=" operation ">
<template slot-scope="scope">
<span v-if="scope.row.processInstanceStatus==''">
<el-button type="primary" size="mini" @click="commit(scope.row)"> Submit </el-button>
</span>
<span v-if="scope.row.processInstanceStatus==' Under approval '||scope.row.processInstanceStatus==' Audit completed '">
<el-button type="primary" size="mini" @click="look(scope.row)"> see </el-button>
</span>
</template>
</el-table-column>
</el-table>
<!-- New pop-up window -->
<el-dialog title=" Edit information " :visible.sync="dialogVisible" width="30%">
<el-form ref="form" :model="form" label-width="100px">
<el-form-item label="ID">
<el-input v-model="form.id" :disabled="true" style="width: 200px;"></el-input>
</el-form-item>
<el-form-item label=" flow id">
<el-input v-model="form.processInstanceId" :disabled="true" style="width: 200px;"></el-input>
</el-form-item>
<el-form-item label=" Flow state ">
<el-input v-model="form.processInstanceStatus" :disabled="true" style="width: 200px;"></el-input>
</el-form-item>
<el-form-item label=" Business key">
<el-input v-model="form.businessKey" :disabled="true" style="width: 200px;"></el-input>
</el-form-item>
</el-form>
</el-dialog>
</div>
</template>
<script>
import axios from '@/axios';
export default {
data() {
return {
tableData: [],
dialogVisible: false,
form: {
id: '',
processInstanceId: '',
processInstanceStatus: '',
businessKey: ''
}
}
},
mounted() {
this.queryObject()
},
methods: {
queryObject() {
var url = 'wzhB/queryObject.do'
var param = {}
axios.get(url, param).then(response => {
if (response.data.code == '0') {
this.tableData = response.data.data
console.log(response.data.data)
} else {
this.$message({
type: 'error',
message: ' operation failed !' + response.data.msg
});
}
});
},
look(row) {
this.dialogVisible = true
this.form = row
},
commit(row) {
var url = 'wzhB/start.do'
var param = {
id: row.id
}
axios.get(url, param).then(response => {
if (response.data.code == '0') {
this.queryObject();
} else {
this.$message({
type: 'error',
message: ' operation failed !' + response.data.msg
});
}
});
}
}
}
</script>
<style>
</style>
Back end
controller
package com.slxx.controller.develop;
import com.slxx.model.system.Type;
import com.slxx.service.develop.WangZhaoHuiDemoBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(value = "/wzhB")
public class wangZhaoHuiDemoBController {
@Autowired
WangZhaoHuiDemoBService wangZhaoHuiDemoBService;
@RequestMapping(value = "/queryObject.do")
public String queryObject(){
String result = "";
try {
result = wangZhaoHuiDemoBService.queryObject();
} catch (Exception ex) {
result = Type.FAIL + ex.getMessage();
ex.printStackTrace();
} finally {
return result;
}
}
@RequestMapping(value = "/start.do")
public String start(String id, HttpServletRequest request) {
String result = "";
String userId = (String) request.getAttribute("userId");
try {
result = wangZhaoHuiDemoBService.start(id,userId);
} catch (Exception ex) {
result = Type.FAIL + ex.getMessage();
ex.printStackTrace();
} finally {
return result;
}
}
}
serviceImpl
package com.slxx.service.impl.develop;
import com.alibaba.druid.proxy.jdbc.JdbcParameter;
import com.alibaba.fastjson.JSON;
import com.slxx.mapping.develop.WangZhaoHuiDemoBMapper;
import com.slxx.model.develop.WangZhaoHuiDemo;
import com.slxx.model.develop.WangZhaoHuiDemoB;
import com.slxx.model.process.ProcessInfo;
import com.slxx.model.system.Type;
import com.slxx.service.develop.WangZhaoHuiDemoBService;
import com.slxx.service.process.ProcessService;
import com.slxx.tools.JSONTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("WangZhaoHuiDemoBService")
public class WangZhaoHuiDemoBServiceImpl implements WangZhaoHuiDemoBService {
@Autowired
WangZhaoHuiDemoBMapper wangZhaoHuiDemoBMapper;
@Autowired
ProcessService processService;
String result = Type.FAIL;
@Override
public String queryObject() {
List<WangZhaoHuiDemoB> list = wangZhaoHuiDemoBMapper.queryObject();
result = JSONTools.toStringyyyyMMddHHmmss(list);
return result;
}
@Override
public String start(String id, String userId) throws Exception {
WangZhaoHuiDemoB demo = wangZhaoHuiDemoBMapper.selectPrimaryKeyId(id);
Map<String, Object> map = new HashMap<>();
String processInstanceId= processService.startWithProcessKeyWithOutFirstTask("test2", userId, map);
demo.setProcessInstanceId(processInstanceId);
demo.setProcessInstanceStatus(" Under approval ");
wangZhaoHuiDemoBMapper.updateByPrimaryKey(demo);
processService.completeFirstTask(processInstanceId,userId);
return JSONTools.toString(Type.SUCCESS);
}
@Override
public String selectPrimaryKey(String id) {
WangZhaoHuiDemoB demoB = wangZhaoHuiDemoBMapper.selectPrimaryKeyId(id);
result = JSONTools.toStringyyyyMMddHHmmss(demoB);
return result;
}
}
service
package com.slxx.service.develop;
public interface WangZhaoHuiDemoBService {
String queryObject();
String start(String id,String userId) throws Exception;
String selectPrimaryKey(String id);
}
Mapper
package com.slxx.mapping.develop;
import com.slxx.model.develop.WangZhaoHuiDemoB;
import java.util.List;
public interface WangZhaoHuiDemoBMapper {
List<WangZhaoHuiDemoB> queryObject();
WangZhaoHuiDemoB selectPrimaryKeyId(String id);
WangZhaoHuiDemoB selectPrimaryKey(String processInstanceId);
int updateByPrimaryKey(WangZhaoHuiDemoB record);
}
Monitor
package com.slxx.service.impl.develop;
import com.slxx.mapping.develop.WangZhaoHuiDemoBMapper;
import com.slxx.model.develop.WangZhaoHuiDemo;
import com.slxx.model.develop.WangZhaoHuiDemoB;
import com.slxx.service.common.CommonWaitToDoService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("wangZhaoHuiDemoBListener")
public class WangZhaoHuiDemoBListener implements ExecutionListener, TaskListener {
@Autowired
WangZhaoHuiDemoBMapper wangZhaoHuiDemoBMapper;
@Autowired
CommonWaitToDoService commonWaitToDoService;
@Autowired
RuntimeService runtimeService;
@Override
public void notify(DelegateExecution delegateExecution) throws Exception {
try {
String status = "";
if (delegateExecution.getEventName().equals("start")) {
} else if (delegateExecution.getEventName().equals("end")) {
WangZhaoHuiDemoB payReq = wangZhaoHuiDemoBMapper.selectPrimaryKey(delegateExecution.getProcessInstanceId());
if (payReq != null) {
String deleteType = (String) (runtimeService.getVariable(delegateExecution.getProcessInstanceId(), "deleteType") == null ? "" : runtimeService.getVariable(delegateExecution.getProcessInstanceId(), "deleteType"));
if (payReq.getProcessInstanceStatus().equals(" rejected ")) {
if (deleteType.equals("manual")) {
status = " Manually shut down ";
payReq.setProcessInstanceStatus("");
} else {
status = " rejected ";
//payReq.setStatus("");
payReq.setProcessInstanceStatus("");
}
} else if (deleteType.equals("manual")) {
status = " Manually shut down ";
} else {
status = " Approved ";
}
payReq.setProcessInstanceStatus(status);
wangZhaoHuiDemoBMapper.updateByPrimaryKey(payReq);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void notify(DelegateTask delegateTask) {
WangZhaoHuiDemoB payReq = wangZhaoHuiDemoBMapper.selectPrimaryKey(delegateTask.getProcessInstanceId());
if (payReq != null) {
//draft step1
if (delegateTask.getTaskDefinitionKey().equals("step1")) {
if (payReq.getProcessInstanceStatus().equals(" rejected ")) {
if (delegateTask.getEventName().equals("create")) {
payReq.setProcessInstanceStatus(" rejected ");
} else if (delegateTask.getEventName().equals("complete")) {
payReq.setProcessInstanceStatus(" Under approval ");
}
} else if (delegateTask.getEventName().equals("create")) {
payReq.setProcessInstanceStatus(" rejected ");
} else if (delegateTask.getEventName().equals("complete")) {
payReq.setProcessInstanceStatus(" Under approval ");
}
wangZhaoHuiDemoBMapper.updateByPrimaryKey(payReq);
}
if (delegateTask.getEventName().equals("create")) {
commonWaitToDoService.beforeDeal(delegateTask);
} else if (delegateTask.getEventName().equals("complete")) {
commonWaitToDoService.afterDeal(delegateTask);
}
}
}
}
mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.slxx.mapping.develop.WangZhaoHuiDemoBMapper">
<resultMap id="resultMap" type="com.slxx.model.develop.WangZhaoHuiDemoB">
<id column="ID" property="id"></id>
<result column="PROCESS_INSTANCE_ID" property="processInstanceId"></result>
<result column="PROCESS_INSTANCE_STATUS" property="processInstanceStatus"></result>
<result column="BUSINESS_KEY" property="businessKey"></result>
</resultMap>
<select id="queryObject" resultMap="resultMap">
select * from W_ZH_DEMO_B
</select>
<select id="selectPrimaryKeyId" resultMap="resultMap">
select * from W_ZH_DEMO_B where ID = #{id.jdbcType=VARCHAR}
</select>
<select id="selectPrimaryKey" resultMap="resultMap">
select * from W_ZH_DEMO_B where PROCESS_INSTANCE_ID=#{processInstanceId,jdbcType=VARCHAR}
</select>
<update id="updateByPrimaryKey" parameterType="com.slxx.model.develop.WangZhaoHuiDemoB">
update W_ZH_DEMO_B
set PROCESS_INSTANCE_ID = #{processInstanceId,jdbcType=VARCHAR},
PROCESS_INSTANCE_STATUS = #{processInstanceStatus,jdbcType=VARCHAR},
BUSINESS_KEY = #{businessKey,jdbcType=VARCHAR}
where ID = #{id,jdbcType=VARCHAR}
</update>
</mapper>
summary : Each field created must have the following fields , technological process key Must be unique
ID PROCESS_INSTANCE_ID PROCESS_INSTANCE_STATUS BUSINESS_KEY( Business )
dev Table fields
05E4B0553B1B4F2A1EDA34CED0CD0430 demo2 W_ZH_DEMO_B test2 com.th.demo 2020-11-05 00:00:00 2020-11-05 00:00:00 0 0 /externalproj/tender/externalprojTenderShow.vue select t.BUSINESS_KEY from W_ZH_DEMO_B t where t.PROCESS_INSTANCE_ID=#{param2,jdbcType=VARCHAR} /pages/externalproj/tender/process/process demoB