Skip to content

Commit

Permalink
add prcess reploy
Browse files Browse the repository at this point in the history
  • Loading branch information
leelance committed Jan 19, 2017
1 parent c11a368 commit 93af7ce
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@

import com.alibaba.fastjson.annotation.JSONField;

import lombok.Data;

/**
* 定义流程
* @author Administrator
*/
@Data
public class ProcessDefineInfo implements Serializable{
private static final long serialVersionUID = -6159834621213504983L;

/**发布成功*/
public static final int DEPLOY = 2;
/**未发布*/
public static final int UNDEPLOY = 1;

/**ID*/
private int id;

Expand All @@ -24,47 +31,13 @@ public class ProcessDefineInfo implements Serializable{
/**流程File, leave.bpmn20.xml*/
private String processFile;

/**流程状态*/
private int processStatus;

/**发布流程ID*/
private String deploymentId;

/**创建时间*/
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Date createTime;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getProcessName() {
return processName;
}

public void setProcessName(String processName) {
this.processName = processName;
}

public String getProcessKey() {
return processKey;
}

public void setProcessKey(String processKey) {
this.processKey = processKey;
}

public String getProcessFile() {
return processFile;
}

public void setProcessFile(String processFile) {
this.processFile = processFile;
}

public Date getCreateTime() {
return createTime;
}

public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lance.activiti.service.process;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -30,4 +31,23 @@ public interface ProcessDefineService {
* @param id
*/
void delete(int id);

/**
* 流程发布
* @param id
*/
void deploy(int id);

/**
* 关闭发布流程
* @param id
*/
void closeDeploy(int id);

/**
* 根据流程发布id获取流程图
* @param deploymentId
* @return
*/
InputStream getProcessDefineIS(String deploymentId);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.lance.activiti.service.process;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lance.activiti.common.exception.ServiceException;
import com.lance.activiti.mapper.process.ProcessDefineMapper;
Expand All @@ -16,6 +23,8 @@ public class ProcessDefineServiceImpl implements ProcessDefineService{
private final String BPMN_XML = ".bpmn20.xml";
@Autowired
private ProcessDefineMapper processDefineMapper;
@Autowired
private RepositoryService repositoryService;

/**
* 查询所有定义的流程
Expand All @@ -42,6 +51,7 @@ public void save(ProcessDefineInfo info) {

String processKey = StringUtils.substringBefore(info.getProcessFile(), BPMN_XML);
info.setProcessKey(processKey);
info.setProcessStatus(ProcessDefineInfo.UNDEPLOY);
processDefineMapper.save(info);
}

Expand All @@ -62,6 +72,55 @@ public void update(ProcessDefineInfo info) {
*/
@Override
public void delete(int id) {
ProcessDefineInfo info = processDefineMapper.findOne(id);
if(info.getProcessStatus() == ProcessDefineInfo.DEPLOY) {
repositoryService.deleteDeployment(info.getDeploymentId(), true);
}

processDefineMapper.delete(id);
}

/**
* 流程发布
* @param id
*/
@Override
public void deploy(int id) {
ProcessDefineInfo info = processDefineMapper.findOne(id);
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("processes/"+info.getProcessFile())
.name(info.getProcessKey())
.deploy();
info.setDeploymentId(deployment.getId());
info.setProcessStatus(ProcessDefineInfo.DEPLOY);
processDefineMapper.update(info);
}

/**
* 关闭发布流程
* @param id
*/
@Transactional
public void closeDeploy(int id) {
ProcessDefineInfo info = processDefineMapper.findOne(id);
if(info.getProcessStatus() == ProcessDefineInfo.UNDEPLOY) {
throw new ServiceException("流程尚未发布, 无须关闭流程");
}

repositoryService.deleteDeployment(info.getDeploymentId(), true);
info.setDeploymentId("0");
info.setProcessStatus(ProcessDefineInfo.UNDEPLOY);
processDefineMapper.update(info);
}

/**
* 根据流程发布id获取流程图
* @param deploymentId
* @return
*/
public InputStream getProcessDefineIS(String deploymentId) {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
return new DefaultProcessDiagramGenerator().generatePngDiagram(bpmnModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/admin/process/deploy/")
public class ProcessDeployController {

/**
* 跳转列表页面
* @return
*/
@RequestMapping(value="list", method=RequestMethod.GET)
public String list(){
return "admin/process/process-deploy-list.jsp";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.lance.activiti.web.process;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -87,4 +93,50 @@ public String delete(@PathVariable int id){
}
return ResultInfo.success();
}

/**
* 流程发布
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value="deploy/{id}", produces = "application/json; charset=UTF-8")
public String deploy(@PathVariable int id) {
try {
processDefineService.deploy(id);
} catch (ServiceException e) {
return ResultInfo.error(-1, e.getMessage());
}
return ResultInfo.success();
}

/**
* 关闭流程
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value="closeDeploy/{id}", produces = "application/json; charset=UTF-8")
public String closeDeploy(@PathVariable int id) {
try {
processDefineService.closeDeploy(id);
} catch (ServiceException e) {
return ResultInfo.error(-1, e.getMessage());
}
return ResultInfo.success();
}

@RequestMapping(value="showDeployImg/{deploymentId}", produces = "application/json; charset=UTF-8")
public void showDeployImg(@PathVariable String deploymentId, HttpServletResponse response) {
InputStream is = null;
try {
ServletOutputStream output = response.getOutputStream();
is = processDefineService.getProcessDefineIS(deploymentId);
IOUtils.copy(is, output);
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(is);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<!-- save -->
<insert id="save" parameterType="ProcessDefineInfo">
insert into t_process_define(process_name,process_key,process_file, create_time)values(
#{processName},#{processKey},#{processFile},now()
insert into t_process_define(process_name,process_key,process_file,process_status, create_time)values(
#{processName},#{processKey},#{processFile},#{processStatus},now()
)
</insert>

Expand All @@ -32,6 +32,12 @@
process_name=#{processName},
process_key=#{processKey},
process_file=#{processFile},
<if test="processStatus!=null and processStatus!=''">
process_status=#{processStatus},
</if>
<if test="deploymentId!=null and deploymentId!=''">
deployment_id=#{deploymentId},
</if>
update_time=now()
where id=#{id}
</update>
Expand Down
Loading

0 comments on commit 93af7ce

Please sign in to comment.