Merge remote-tracking branch 'gitosc/master'

This commit is contained in:
jamen
2017-12-13 17:28:41 +08:00
11 changed files with 581 additions and 15 deletions
@@ -0,0 +1,77 @@
package com.slife.controller;
import com.slife.base.entity.ReturnDTO;
import com.slife.base.vo.DataTable;
import com.slife.enums.HttpCodeEnum;
import com.slife.exception.SlifeException;
import com.slife.service.ProcessService;
import com.slife.util.ReturnDTOUtil;
import com.slife.vo.ProcessVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
/**
* @author: felix.
* @createTime: 2017/12/11.
*/
@Controller
@RequestMapping("/process")
@Api(description = "流程实例的前端控制器")
public class ProcessController {
@Autowired
ProcessService processService;
@ApiOperation(value = "进入流程管理页面", notes = "进入流程管理页面")
@GetMapping(value = "")
public String list(org.springframework.ui.Model model, HttpServletRequest request) {
model.addAttribute("url", request.getContextPath()+"/process/");
return "process/list";
}
@ApiOperation(value = "获取流程列表数据", notes = "获取流程列表数据:使用约定的DataTable")
@PostMapping(value = "/list")
@ResponseBody
public DataTable<ProcessVO> list(@RequestBody DataTable dt) {
if (null == dt) {
return null;
}
return processService.getProcessByPage(dt);
}
@ApiOperation(value = "读取xml/image资源", notes = "resType为xml或者image")
@GetMapping(value = "/resource")
public void resourceRead(String procDefId, String proInsId, String resType, HttpServletResponse response) {
if ("xml".equals(resType)) {
response.setContentType("application/xml");
} else {
response.setContentType("image/png");
}
try {
InputStream resourceAsStream = processService.resourceRead(procDefId, proInsId, resType);
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
} catch (Exception e) {
throw new SlifeException(HttpCodeEnum.FAIL);
}
}
@ApiOperation(value = "激活/挂起", notes = "active为激活,suspend为挂起")
@PostMapping("/status")
@ResponseBody
public ReturnDTO updateState(@RequestParam String status, @RequestParam String procDefId) {
processService.updateStatus(status, procDefId);
return ReturnDTOUtil.success();
}
}
@@ -24,7 +24,7 @@ import java.io.UnsupportedEncodingException;
import java.util.List;
/**
* @author: felixu.
* @author: felix.
* @createTime: 2017/11/26.
*/
@Service
@@ -0,0 +1,84 @@
package com.slife.service;
import com.slife.base.vo.DataTable;
import com.slife.utils.ActivitiUtils;
import com.slife.vo.ProcessVO;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;
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 java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author: felix.
* @createTime: 2017/12/11.
*/
@Service
public class ProcessService {
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
public DataTable<ProcessVO> getProcessByPage(DataTable dt) {
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().latestVersion();
String category = (String) dt.getSearchParams().get("category");
if (StringUtils.isNotBlank(category)){
query.processDefinitionCategory(category);
}
dt.setTotal(((Long)query.count()).intValue());
query.listPage((dt.getPageNumber() - 1) * dt.getPageSize(), dt.getPageSize())
.stream()
.forEach(processDefinition -> {
Deployment deployment = repositoryService.createDeploymentQuery()
.deploymentId(processDefinition.getDeploymentId()).singleResult();
dt.getRows().add(ActivitiUtils.toProcessVO(processDefinition, deployment));
});
dt.setRows((List<ProcessVO>) dt.getRows()
.stream()
.sorted(Comparator.comparing(ProcessVO::getDeploymentTime).reversed())
.collect(Collectors.toList()));
return dt;
}
public InputStream resourceRead(String procDefId, String proInsId, String resType) throws Exception {
if (StringUtils.isBlank(procDefId)){
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(proInsId).singleResult();
procDefId = processInstance.getProcessDefinitionId();
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
String resourceName = "";
if (resType.equals("image")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resType.equals("xml")) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
return resourceAsStream;
}
@Transactional(readOnly = false)
public String updateStatus(String status, String procDefId) {
if (status.equals("active")) {
repositoryService.activateProcessDefinitionById(procDefId, true, null);
} else if (status.equals("suspend")) {
repositoryService.suspendProcessDefinitionById(procDefId, true, null);
}
return status;
}
}
@@ -0,0 +1,161 @@
package com.slife.utils;
import com.slife.enums.HttpCodeEnum;
import com.slife.exception.SlifeException;
import com.slife.vo.ProcessVO;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import java.util.HashMap;
import java.util.Map;
/**
* @author: xufei.
* @createTime: 2017/8/11.
*/
public class ActivitiUtils {
// static UserDetailDao userDetailDao = Application.getBean(UserDetailDao.class);
//
// static UserServiceClient userServiceClient = Application.getBean(UserServiceClient.class);
//
// static HistoryService historyService = Application.getBean(HistoryService.class);
/**
* 获取用户信息
* @param userId
* @return
*/
// public static UserInfo getUserInfo(String userId) {
// if (userDetailDao.has(userId)) {
// return parseUserInfo(userDetailDao.get(userId));
// }
// RespDTO resp = userServiceClient.getUser(userId);
// return Optional.ofNullable(resp.data)
// .map(data -> {
// userDetailDao.set(JSON.toJSONString(data), userId);
// return parseUserInfo(JSON.toJSONString(data));
// })
// .orElseThrow(() ->new TaiChiException(ErrorCode.FAIL, "get user from user service error"));
// }
// private static UserInfo parseUserInfo(String json) {
// return JSON.parseObject(json, UserInfo.class);
// }
// /**
// * 删除缓存
// * @param userId
// */
// public static void delUserCache(String userId) {
// if (userDetailDao.has(userId)) {
// userDetailDao.del(userId);
// }
// }
/**
* 节点对应的中文名称
* @param type
* @return
*/
public static String parseToZhType(String type) {
Map<String, String> types = new HashMap<String, String>();
types.put("userTask", "用户任务");
types.put("serviceTask", "系统任务");
types.put("startEvent", "开始节点");
types.put("endEvent", "结束节点");
types.put("exclusiveGateway", "条件判断节点(系统自动根据条件处理)");
types.put("inclusiveGateway", "并行处理任务");
types.put("callActivity", "子流程");
return types.get(type) == null ? type : types.get(type);
}
/**
* 将dto转为activiti的entity
* @param role
* @return
*/
// public static GroupEntity toActivitiGroup(SysRoleDTO role){
// GroupEntity groupEntity = new GroupEntity();
// groupEntity.setId(role.getRoleId());
// groupEntity.setName(role.getName());
// groupEntity.setType(role.getType() + "");
// groupEntity.setRevision(1);
// return groupEntity;
// }
/**
* 将dto转为activiti的entity
* @param user
* @return
*/
// public static UserEntity toActivitiUser(SysUserDTO user){
// UserEntity userEntity = new UserEntity();
// userEntity.setId(user.getUserId());
// userEntity.setFirstName(user.getRealname());
// userEntity.setLastName(StringUtils.EMPTY);
// userEntity.setPassword(user.getPassword());
// userEntity.setEmail(user.getEmail());
// userEntity.setRevision(1);
// return userEntity;
// }
/**
* 抽取流程实例需要返回的内容
* @param processDefinition
* @param deployment
* @return
*/
public static ProcessVO toProcessVO(ProcessDefinition processDefinition, Deployment deployment) {
if (null == processDefinition || null == deployment) {
throw new SlifeException(HttpCodeEnum.INVALID_REQUEST);
}
ProcessVO dto = new ProcessVO();
dto.category = processDefinition.getCategory();
dto.processonDefinitionId = processDefinition.getId();
dto.key = processDefinition.getKey();
dto.name = deployment.getName();
dto.revision = processDefinition.getVersion();
dto.deploymentTime = deployment.getDeploymentTime().getTime();
dto.xmlName = processDefinition.getResourceName();
dto.picName = processDefinition.getDiagramResourceName();
dto.deploymentId = deployment.getId();
dto.suspend = processDefinition.isSuspended();
dto.description = processDefinition.getDescription();
return dto;
}
// public static TaskDTO toTaskDTO(TaskInfo task, String status, ProcessDefinition processDefinition, Deployment deployment) {
// TaskDTO dto = new TaskDTO();
// dto.setTaskId(task.getId());
// dto.setTaskName(task.getName());
//// dto.setTime(historyService.createHistoricProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult().getStartTime().getTime());
// dto.setVariable(task.getTaskLocalVariables());
// dto.setPdName(deployment.getName());
// dto.setVersion("V:" + processDefinition.getVersion());
// dto.setProcessInstanceId(task.getProcessInstanceId());
// dto.setStatus(status);
// dto.setTitle((String) task.getProcessVariables().get("title"));
// dto.setNodeKey(task.getTaskDefinitionKey());
// dto.setProcessDefKey(processDefinition.getKey());
// return dto;
// }
// public static TaskListDTO toTaskListDTO(PageResultsDTO dto, String category) {
// TaskListDTO taskList = new TaskListDTO();
// taskList.setCategory(category);
// taskList.setPage(dto.page);
// taskList.setPageSize(dto.pageSize);
// taskList.setTotalCount((int) dto.totalCount);
// taskList.setTasks(dto.getList());
// return taskList;
// }
//
// public static TaskListDTO toTaskListDTO(List<TaskDTO> tasks, String category, int page, int pageSize, long totalCount) {
// TaskListDTO taskList = new TaskListDTO();
// taskList.setCategory(category);
// taskList.setPage(page);
// taskList.setPageSize(pageSize);
// taskList.setTotalCount((int) totalCount);
// taskList.setTasks(tasks);
// return taskList;
// }
}
@@ -0,0 +1,108 @@
package com.slife.vo;
/**
* @author: felix.
* @createTime: 2017/12/11.
*/
public class ProcessVO {
public String category;
public String processonDefinitionId;
public String key;
public String name;
public Integer revision;
public Long deploymentTime;
public String xmlName;
public String picName;
public String deploymentId;
public Boolean suspend;
public String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getSuspend() {
return suspend;
}
public void setSuspend(Boolean suspend) {
this.suspend = suspend;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getProcessonDefinitionId() {
return processonDefinitionId;
}
public void setProcessonDefinitionId(String processonDefinitionId) {
this.processonDefinitionId = processonDefinitionId;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getRevision() {
return revision;
}
public void setRevision(Integer revision) {
this.revision = revision;
}
public Long getDeploymentTime() {
return deploymentTime;
}
public void setDeploymentTime(Long deploymentTime) {
this.deploymentTime = deploymentTime;
}
public String getXmlName() {
return xmlName;
}
public void setXmlName(String xmlName) {
this.xmlName = xmlName;
}
public String getPicName() {
return picName;
}
public void setPicName(String picName) {
this.picName = picName;
}
public String getDeploymentId() {
return deploymentId;
}
public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}
}
@@ -261,7 +261,7 @@ KISBPM.TOOLBAR = {
},
closeEditor: function(services) {
window.location.href = "/model-list.html";
window.location.href = "/model";
},
/**
@@ -326,7 +326,7 @@ var SaveModelCtrl = [ '$rootScope', '$scope', '$http', '$route', '$location',
$scope.saveAndClose = function () {
$scope.save(function() {
window.location.href = "/model-list.html";
window.location.href = "/model";
});
};
$scope.save = function (successCallback) {
@@ -108,6 +108,12 @@
}
load_data( getcolumns(), {"createDate": "desc"});
function dt_edit_model_button(row) {
var uri = url.substring(0, url.length - 1);
var editO = '<a class="btn btn-primary btn-sm" href="'+ uri +'er.html?modelId=' + row.id + '" title="编辑"><i class="fa fa-edit"></i></a> ';
return editO;
}
function dt_doploy_button(row) {
var editO = '<a class="btn btn-primary btn-sm" href="#" mce_href="#" title="部署" onclick="remove(\''
+ row.id + '\')"><i class="fa fa-edit"></i></a> ';
@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html>
<head>
<title>模型管理</title>
<link href="${base}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link href="${base}/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="${base}/css/animate.css" rel="stylesheet">
<script>
var url = "${url}";
</script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
<div class="col-sm-12">
<div class="ibox">
<div class="ibox-body">
<div id="exampleToolbar" role="group">
<label style="margin-left: 10px;">
<button type="button" class="btn btn-danger" onclick="batch_remove()">
<i class="fa fa-trash" aria-hidden="true"></i>删除
</button>
</label>
</div>
<table id="exampleTable" data-mobile-responsive="true">
</table>
</div>
</div>
</div>
</div>
<!-- Bootstrap table -->
<script src="${base}/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${base}/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${base}/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${base}/js/slife/datatable.js"></script>
<script type="text/javascript">
function getcolumns() {
var c = [
{
checkbox: true
},
{
field: 'category',
title: '流程分类'
},
{
field: 'key',
title: '模型标识'
},
{
field: 'name',
title: '流程名称'
},
{
field: 'revision',
title: '版本号'
},
{
field: 'xmlName',
title: '流程XML',
align: 'center',
formatter: function (value, row, index) {
var procDefId = row.processonDefinitionId;
return '<a href=${url}resource?procDefId=' + procDefId + '&resType=xml>' + value + '</a>';
}
},
{
field: 'picName',
title: '流程图片',
align: 'center',
formatter: function (value, row, index) {
var procDefId = row.processonDefinitionId;
return '<a href=${url}resource?procDefId=' + procDefId + '&resType=image>' + value + '</a>';
}
},
{
field: 'deploymentTime',
title: '部署时间'
},
{
title: '操作',
field: 'id',
align: 'center',
formatter: function (value, row, index) {
return dt_delete_button(row)+dt_active_button(row);
}
}];
return c;
}
load_data( getcolumns(), {"createDate": "desc"});
function dt_delete_button(row) {
var deleteO = '<a class="btn btn-warning btn-sm" href="#" title="删除" mce_href="#" ' +
'onclick="remove(\'' + row.id + '\')">删除</a> ';
return deleteO;
}
function dt_active_button(row) {
var value = '';
var status = '';
if (row.suspend === false) {
value = '挂起';
status = 'suspend';
} else {
value = '激活'
status = 'active';
}
var procDefId = row.processonDefinitionId;
var deleteO = '<a class="btn btn-warning btn-sm" href="#" ' +
'title="挂起/激活" mce_href="#" onclick="active(\'' + procDefId + '\', \'' + status + '\')"> ' + value + ' </a> ';
return deleteO;
}
function active(procDefId, state) {
$.ajax({
url: url + "status",
type: "POST",
data: {
'procDefId': procDefId,
'status': state
},
success: function (r) {
dataTable_rep_message(r)
}
});
}
</script>
</body>
</html>
@@ -22,7 +22,7 @@ public class DataTable<T> implements Serializable {
/**
* 返回列表
*/
private List<T> rows;
private List<T> rows = new ArrayList<>();
/**
* 排序 条件
@@ -15,7 +15,7 @@ public class WebSiteMeshFilter extends ConfigurableSiteMeshFilter {
/** 需要装饰的访问路径 */
private String contentPath="/sys/user,/sys/menu,/sys/dict,/sys/role,/sys/office,/sys/,/index,/monitor/*," +
"/blog/content**,/404,/model";
"/blog/content**,/404,/model,/process";
/** 装饰器页面路径 */
@@ -209,16 +209,6 @@ function dt_edit_button(row) {
return editO;
}
/**
* 编辑 按钮
* @returns {string}
*/
function dt_edit_model_button(row) {
var uri = url.substring(0, url.length - 1);
var editO = '<a class="btn btn-primary btn-sm" href="'+ uri +'er.html?modelId=' + row.id + '" title="编辑"><i class="fa fa-edit"></i></a> ';
return editO;
}
/**
* 详情按钮
* @returns {*}