Permalink
Browse files

添加了作业管理、用户与组、流程引擎信息查看、引擎数据库表查询

  • Loading branch information...
1 parent 54944fd commit 1181423610b6f6c5db9ec8c62879459009e68ff8 @henryyan committed Nov 25, 2015
Showing with 1,076 additions and 45 deletions.
  1. +7 −0 README.md
  2. +1 −1 pom.xml
  3. +1 −1 src/main/java/me/kafeitu/demo/activiti/conf/DemoDataInitConfig.java
  4. +66 −0 src/main/java/me/kafeitu/demo/activiti/web/management/DatabaseController.java
  5. +205 −0 src/main/java/me/kafeitu/demo/activiti/web/management/IdentityController.java
  6. +123 −0 src/main/java/me/kafeitu/demo/activiti/web/management/JobController.java
  7. +41 −0 src/main/java/me/kafeitu/demo/activiti/web/management/ProcessEngineInfoController.java
  8. +1 −1 src/main/resources/applicationContext.xml
  9. BIN src/main/resources/deployments/timerExample.zip
  10. +66 −0 src/main/resources/diagrams/timer/timerExample.bpmn
  11. BIN src/main/resources/diagrams/timer/timerExample.png
  12. +26 −26 src/main/webapp/WEB-INF/tags/pagination.tag
  13. +1 −1 src/main/webapp/WEB-INF/views/login.jsp
  14. +1 −1 src/main/webapp/WEB-INF/views/main/index.jsp
  15. +13 −4 src/main/webapp/WEB-INF/views/main/menu.jsp
  16. +8 −7 src/main/webapp/WEB-INF/views/main/welcome.jsp
  17. +62 −0 src/main/webapp/WEB-INF/views/management/database.jsp
  18. +42 −0 src/main/webapp/WEB-INF/views/management/engine-info.jsp
  19. +115 −0 src/main/webapp/WEB-INF/views/management/group-list.jsp
  20. +85 −0 src/main/webapp/WEB-INF/views/management/job-list.jsp
  21. +184 −0 src/main/webapp/WEB-INF/views/management/user-list.jsp
  22. +1 −0 src/main/webapp/common/global.jsp
  23. +9 −0 src/main/webapp/css/bootstrap-responsive.min.css
  24. +9 −0 src/main/webapp/css/bootstrap.min.css
  25. BIN src/main/webapp/img/glyphicons-halflings-white.png
  26. BIN src/main/webapp/img/glyphicons-halflings.png
  27. +6 −0 src/main/webapp/js/common/bootstrap.min.js
  28. +3 −3 src/main/webapp/js/module/main/welcome-portlet.js
View
@@ -51,6 +51,13 @@ Demo提供Maven版本和no-maven版本,分别适用于会用mavne和不会用m
## Changelog
+### 1.14.0(2015-11-26)
+1. 添加查看引擎参数功能
+2. 添加查看引擎数据库功能
+3. 添加管理用户与组功能
+4. 添加作业管理功能
+5. 5.17+方式嵌入Rest服务
+
### 1.13.0(2015-11-23)
1. 集成基于5.17+的流程设计器(Activiti Modeler,很漂亮),demo依赖的版本支持5.17以上
2. 数据库配置属性转移到pom.xml里面,可以直接修改`pom.xml`文件的参数,也可以在运行时通过`-Djdbc.password=111111`参数覆盖
View
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.kafeitu.demo</groupId>
<artifactId>kft-activiti-demo</artifactId>
- <version>1.13.0</version>
+ <version>1.14.0</version>
<packaging>war</packaging>
<name>Activiti demo</name>
<description>activiti demo for version 5.17+</description>
@@ -190,7 +190,7 @@ protected void createModelData(String name, String description, String jsonFile)
repositoryService.saveModel(model);
try {
- InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/explorer/demo/model/test.svg");
+ InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("models/leave.model.svg");
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(svgStream));
} catch (Exception e) {
LOGGER.warn("Failed to read SVG", e);
@@ -0,0 +1,66 @@
+package me.kafeitu.demo.activiti.web.management;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import javax.servlet.http.HttpServletRequest;
+
+import me.kafeitu.demo.activiti.util.Page;
+import me.kafeitu.demo.activiti.util.PageUtil;
+import org.activiti.engine.ManagementService;
+import org.activiti.engine.management.TableMetaData;
+import org.activiti.engine.management.TablePage;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * 数据库查询控制器
+ * User: henryyan
+ */
+@Controller
+@RequestMapping("/management/database")
+public class DatabaseController {
+
+ @Autowired
+ ManagementService managementService;
+
+ @RequestMapping("")
+ public ModelAndView index(@RequestParam(value = "tableName", required = false) String tableName, HttpServletRequest request) {
+ ModelAndView mav = new ModelAndView("management/database");
+
+ // 读取表
+ Map<String, Long> tableCount = managementService.getTableCount();
+ List<String> keys = new ArrayList<>();
+ keys.addAll(tableCount.keySet());
+ Collections.sort(keys);
+
+ TreeMap<String, Long> sortedTableCount = new TreeMap<>();
+
+ for (String key : keys) {
+ sortedTableCount.put(key, tableCount.get(key));
+ }
+
+ mav.addObject("tableCount", sortedTableCount);
+
+ // 读取表记录
+ if (StringUtils.isNotBlank(tableName)) {
+ TableMetaData tableMetaData = managementService.getTableMetaData(tableName);
+ mav.addObject("tableMetaData", tableMetaData);
+ Page<Map<String, Object>> page = new Page<>(10);
+ int[] pageParams = PageUtil.init(page, request);
+ TablePage tablePages = managementService.createTablePageQuery().tableName(tableName).listPage(pageParams[0], pageParams[1]);
+
+ page.setResult(tablePages.getRows());
+ page.setTotalCount(tableCount.get(tableName));
+ mav.addObject("page", page);
+ }
+ return mav;
+ }
+
+}
@@ -0,0 +1,205 @@
+package me.kafeitu.demo.activiti.web.management;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+
+import me.kafeitu.demo.activiti.util.Page;
+import me.kafeitu.demo.activiti.util.PageUtil;
+import org.activiti.engine.IdentityService;
+import org.activiti.engine.identity.Group;
+import org.activiti.engine.identity.GroupQuery;
+import org.activiti.engine.identity.User;
+import org.activiti.engine.identity.UserQuery;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+
+/**
+ * 用户、组控制器
+ * User: henry
+ */
+@Controller
+@RequestMapping("/management/identity")
+public class IdentityController {
+
+ @Autowired
+ IdentityService identityService;
+
+ private static final String[] INNER_GROUPS = {"admin", "user", "hr", "deptLeader"};
+
+ private static final String[] INNER_USERS = {"admin", "kafeitu", "hruser", "leaderuser"};
+
+ /**
+ * 组列表
+ *
+ * @param request
+ * @return
+ */
+ @RequestMapping("group/list")
+ public ModelAndView groupList(HttpServletRequest request) {
+ ModelAndView mav = new ModelAndView("management/group-list");
+
+ Page<Group> page = new Page<Group>(PageUtil.PAGE_SIZE);
+ int[] pageParams = PageUtil.init(page, request);
+
+ GroupQuery groupQuery = identityService.createGroupQuery();
+ List<Group> groupList = groupQuery.listPage(pageParams[0], pageParams[1]);
+
+ page.setResult(groupList);
+ page.setTotalCount(groupQuery.count());
+ mav.addObject("page", page);
+
+ return mav;
+ }
+
+ /**
+ * 保存Group
+ *
+ * @return
+ */
+ @RequestMapping(value = "group/save", method = RequestMethod.POST)
+ public String saveGroup(@RequestParam("groupId") String groupId,
+ @RequestParam("groupName") String groupName,
+ @RequestParam("type") String type,
+ RedirectAttributes redirectAttributes) {
+ Group group = identityService.createGroupQuery().groupId(groupId).singleResult();
+ if (group == null) {
+ group = identityService.newGroup(groupId);
+ }
+ group.setName(groupName);
+ group.setType(type);
+ identityService.saveGroup(group);
+ redirectAttributes.addFlashAttribute("message", "成功添加组[" + groupName + "]");
+ return "redirect:/management/identity/group/list";
+ }
+
+ /**
+ * 删除Group
+ */
+ @RequestMapping(value = "group/delete/{groupId}", method = RequestMethod.GET)
+ public String deleteGroup(@PathVariable("groupId") String groupId,
+ RedirectAttributes redirectAttributes) {
+ if (ArrayUtils.contains(INNER_GROUPS, groupId)) {
+ redirectAttributes.addFlashAttribute("errorMsg", "组[" + groupId + "]属于Demo固定数据不可删除!");
+ return "redirect:/management/identity/group/list";
+ }
+
+ identityService.deleteGroup(groupId);
+ redirectAttributes.addFlashAttribute("message", "成功删除组[" + groupId + "]");
+ return "redirect:/management/identity/group/list";
+ }
+
+ /**
+ * 用户列表
+ *
+ * @param request
+ * @return
+ */
+ @RequestMapping("user/list")
+ public ModelAndView userList(HttpServletRequest request) {
+ ModelAndView mav = new ModelAndView("management/user-list");
+
+ Page<User> page = new Page<User>(PageUtil.PAGE_SIZE);
+ int[] pageParams = PageUtil.init(page, request);
+
+ UserQuery userQuery = identityService.createUserQuery();
+ List<User> userList = userQuery.listPage(pageParams[0], pageParams[1]);
+
+ // 查询每个人的分组,这样的写法比较耗费性能、时间,仅供读者参考
+ Map<String, List<Group>> groupOfUserMap = new HashMap<String, List<Group>>();
+ for (User user : userList) {
+ List<Group> groupList = identityService.createGroupQuery().groupMember(user.getId()).list();
+ groupOfUserMap.put(user.getId(), groupList);
+ }
+
+ page.setResult(userList);
+ page.setTotalCount(userQuery.count());
+ mav.addObject("page", page);
+ mav.addObject("groupOfUserMap", groupOfUserMap);
+
+ // 读取所有组
+ List<Group> groups = identityService.createGroupQuery().list();
+ mav.addObject("allGroup", groups);
+
+ return mav;
+ }
+
+ /**
+ * 保存User
+ *
+ * @param redirectAttributes
+ * @return
+ */
+ @RequestMapping(value = "user/save", method = RequestMethod.POST)
+ public String saveUser(@RequestParam("userId") String userId,
+ @RequestParam("firstName") String firstName,
+ @RequestParam("lastName") String lastName,
+ @RequestParam(value = "password", required = false) String password,
+ @RequestParam(value = "email", required = false) String email,
+ RedirectAttributes redirectAttributes) {
+ User user = identityService.createUserQuery().userId(userId).singleResult();
+ if (user == null) {
+ user = identityService.newUser(userId);
+ }
+ user.setFirstName(firstName);
+ user.setLastName(lastName);
+ user.setEmail(email);
+ if (StringUtils.isNotBlank(password)) {
+ user.setPassword(password);
+ }
+ identityService.saveUser(user);
+ redirectAttributes.addFlashAttribute("message", "成功添加用户[" + firstName + " " + lastName + "]");
+ return "redirect:/management/identity/user/list";
+ }
+
+ /**
+ * 删除User
+ */
+ @RequestMapping(value = "user/delete/{userId}", method = RequestMethod.GET)
+ public String deleteUser(@PathVariable("userId") String userId,
+ RedirectAttributes redirectAttributes) {
+ if (ArrayUtils.contains(INNER_USERS, userId)) {
+ redirectAttributes.addFlashAttribute("errorMsg", "用户[" + userId + "]属于Demo固定数据不可删除!");
+ return "redirect:/management/identity/user/list";
+ }
+
+ identityService.deleteUser(userId);
+ redirectAttributes.addFlashAttribute("message", "成功删除用户[" + userId + "]");
+ return "redirect:/management/identity/user/list";
+ }
+
+ /**
+ * 为用户设置所属组
+ * @param userId
+ * @param groupIds
+ * @return
+ */
+ @RequestMapping(value = "group/set", method = RequestMethod.POST)
+ public String groupForUser(@RequestParam("userId") String userId, @RequestParam("group") String[] groupIds,
+ RedirectAttributes redirectAttributes) {
+
+ if (ArrayUtils.contains(INNER_USERS, userId)) {
+ redirectAttributes.addFlashAttribute("errorMsg", "用户[" + userId + "]属于Demo固定数据不可更改!");
+ return "redirect:/management/identity/user/list";
+ }
+
+ List<Group> groupInDb = identityService.createGroupQuery().groupMember(userId).list();
+ for (Group group : groupInDb) {
+ identityService.deleteMembership(userId, group.getId());
+ }
+ for (String group : groupIds) {
+ identityService.createMembership(userId, group);
+ }
+ return "redirect:/management/identity/user/list";
+ }
+
+}
Oops, something went wrong.

0 comments on commit 1181423

Please sign in to comment.