/**
   * 验证用户
   *
   * @param request
   * @param response
   * @param model
   * @return
   */
  @RequestMapping("/checkLogin.do")
  public String checkLogin(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("userName") String userName,
      @RequestParam("passWord") String passWord,
      Model model) {
    logger.debug("logon request: {username={}, password={}}", userName, passWord);
    boolean checkPassword = identityService.checkPassword(userName, passWord);

    HttpSession session = request.getSession(true);

    if (checkPassword) {
      User user = identityService.createUserQuery().userId(userName).singleResult();
      session.setAttribute("user", user);
      GroupQuery groupQuery = identityService.createGroupQuery();
      List<Group> groupList = groupQuery.groupMember(userName).list();

      session.setAttribute("groups", groupList);

      String[] groupNames = new String[groupList.size()];

      for (int i = 0; i < groupNames.length; i++) {
        groupNames[i] = groupList.get(i).getName();
      }

      session.setAttribute("groupNames", ArrayUtils.toString(groupNames));
      return "redirect:/simple/index.do";
    } else {
      return "redirect:/simple/login.do";
    }
  }
  /**
   * 跳转到任务执行页面
   *
   * @param request
   * @return
   */
  @RequestMapping(value = "/form.do")
  public String from(
      HttpServletRequest request, @RequestParam("taskId") String taskId, Model model) {

    List<Task> taskList = taskService.createTaskQuery().taskId(taskId).list();
    Task task = taskList.get(0);
    // 获取表单数据
    TaskFormData tfd = formService.getTaskFormData(taskId);
    List<FormProperty> fpList = tfd.getFormProperties();

    Map map = runtimeService.getVariables(task.getExecutionId());

    List<ActivityImpl> activityList = new ArrayList<ActivityImpl>();

    try {
      // 查找所有可驳回的节点
      activityList = processExtensionService.findBackActivity(taskId);
      // model.addAttribute("activityList",activityList);
    } catch (Exception e) {
      e.printStackTrace();
    }

    //        model.addAttribute("task",task);
    //        model.addAttribute("fpList",fpList);
    //        model.addAttribute("map",map);
    //        model.addAttribute("taskId",taskId);

    request.setAttribute("task", task);
    request.setAttribute("fpList", fpList);
    request.setAttribute("map", map);
    request.setAttribute("taskId", taskId);
    request.setAttribute("activityList", activityList);

    return "/simple/form";
  }
  /**
   * 提交流程
   *
   * @return
   */
  @RequestMapping(value = "/submit.do")
  public String submit(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(value = "taskId", required = false) String taskId,
      @RequestParam(value = "day", required = false) String day,
      @RequestParam(value = "type", required = false) String type,
      @RequestParam(value = "reason", required = false) String reason,
      @RequestParam(value = "result", required = false) String result,
      @RequestParam(value = "toSign", required = false) String toSign,
      @RequestParam(value = "backActivityId", required = false) String backActivityId)
      throws Exception {
    List<Task> taskList = taskService.createTaskQuery().taskId(taskId).list();
    Task task = taskList.get(0);
    String taskName = task.getName();

    // result = new String(result.getBytes("ISO-8859-1"), "UTF-8");

    if (result.equals("同意")) {
      Map map = new HashMap();
      if (StringUtils.isNotBlank(day)) {
        map.put("day", day);
        map.put("reason", reason);
        map.put("type", 0);
        taskService.complete(taskId, map);
      } else {
        taskService.complete(taskId);
      }
    } else if (result.equals("驳回")) {
      ProcessInstance processInstance = processExtensionService.findProcessInstanceByTaskId(taskId);

      Map<String, Object> map = runtimeService.getVariables(processInstance.getId());

      processExtensionService.backProcess(taskId, backActivityId, map);
    } else if (result.equals("转签")) {

      if (processExtensionService.isPermissionInActivity(taskId, toSign)) {
        taskService.setAssignee(taskId, toSign);
      }
    }
    return "redirect:/simple/index.do";
  }