@Override
 public String save() throws Exception {
   workGroupManager.saveWorkGroup(workGroup);
   addActionMessage("保存工作组成功");
   ApiFactory.getBussinessLogService().log("工作组管理", "保存工作组信息", ContextUtils.getSystemId("acs"));
   return RELOAD;
 }
  /**
   * 保存工作组添加用户
   *
   * @return
   * @throws Exception
   */
  @Action("work-group-workgroupAddUser")
  public String workgroupAddUser() throws Exception {
    if (StringUtils.isNotEmpty(ids)) {
      userIds = new ArrayList<Long>();
      User user = userManager.getUserById(ContextUtils.getUserId());
      if ("ALLCOMPANYID".equals(ids)) { // 全公司
        userIds.add(0l);
      } else {
        if (roleManager.hasSystemAdminRole(user)) {
          for (String str : ids.split(",")) {
            userIds.add(Long.valueOf(str));
          }
        } else if (roleManager.hasBranchAdminRole(user)) {
          userIds = ApiFactory.getAcsService().getTreeUserIds(ids);
        }
      }

      String addUsers = workGroupManager.workgroupAddUser(workGroupId, userIds, 0);

      if (StringUtils.isNotEmpty(addUsers))
        ApiFactory.getBussinessLogService()
            .log("工作组管理", "工作组添加人员:" + addUsers, ContextUtils.getSystemId("acs"));
    }
    this.renderText("ok");
    return null;
  }
 @Override
 protected void prepareModel() throws Exception {
   if (id != null) {
     workGroup = workGroupManager.getWorkGroup(id);
   } else {
     workGroup = new Workgroup();
   }
 }
 /**
  * 工作组去除用户(小写字母g)
  *
  * @return
  * @throws Exception
  */
 @Action("work-group-removeWorkgroupToUsers")
 public String removeWorkgroupToUsers() throws Exception {
   String removeUsers = workGroupManager.workgroupAddUser(workGroupId, userIds, 1);
   if (StringUtils.isNotEmpty(removeUsers))
     ApiFactory.getBussinessLogService()
         .log("工作组管理", "工作组移除人员:" + removeUsers, ContextUtils.getSystemId("acs"));
   return getUserByWorkGroup();
 }
 @Override
 @Action("work-group-delete")
 public String delete() throws Exception {
   String logSign = ""; // 该字段只是为了标识日志信息:工作组名称
   String[] str = ides.split(",");
   for (String sid : str) {
     workGroup = workGroupManager.getWorkGroup(Long.valueOf(sid));
     workGroupManager.cleanWorkGroup(workGroup.getId());
     if (StringUtils.isNotEmpty(logSign)) {
       logSign += ",";
     }
     logSign += workGroup.getName();
     workGroupManager.deleteWorkGroup(Long.valueOf(sid));
   }
   ApiFactory.getBussinessLogService()
       .log("工作组管理", "删除工作组:" + logSign, ContextUtils.getSystemId("acs"));
   this.renderText("ok");
   return null;
 }
 @Override
 @Action("work-group")
 public String list() throws Exception {
   if (page.getPageSize() > 1) {
     page = workGroupManager.getAllWorkGroupByBranchesId(page, branchesId);
     //			ApiFactory.getBussinessLogService().log("工作组管理",
     //					"查看工作组列表",ContextUtils.getSystemId("acs"));
     this.renderText(PageUtils.pageToJson(page));
     return null;
   }
   return "work-group";
 }
 /** 唯一验证。工作组编号和名称 liudongxia */
 @Action("work-group-checkWorkCode")
 public String checkWorkCode() throws Exception {
   List<Workgroup> workgroupCodeList = workGroupManager.getWorkgroupsByCode(workGroupCode);
   List<Workgroup> workgroupNameList =
       workGroupManager.getWorkgroupsByName(branchesId, workGroupName);
   boolean codeRepeat = validateOnly(workgroupCodeList, id);
   boolean nameRepeat = validateOnly(workgroupNameList, id);
   if (codeRepeat) {
     if (nameRepeat) {
       this.renderText("codeNameRepeat"); // 表示工作组编号和工作组名称都不唯一
     } else {
       this.renderText("codeRepeat"); // 表示工作组编号不唯一
     }
   } else {
     if (nameRepeat) {
       this.renderText("nameRepeat"); // 表示工作组名称不唯一
     } else {
       this.renderText("ok"); // 表示工作组编号和工作组名称都唯一
     }
   }
   return null;
 }
  /** 保存新建工作组信息 */
  @Action("work-group-saveWorkGroup")
  public String saveWorkGroup() throws Exception {
    boolean logSign = true; // 该字段只是为了标识日志信息:true表示新建工作组、false表示修改工作组
    if (id == null) {
      Company company = companyManager.getCompany(companyId);
      workGroup.setCompany(company);
      workGroupManager.saveWorkGroup(workGroup);
    } else {
      workGroupManager.saveWorkGroup(workGroup);
      logSign = false;
    }

    if (logSign) {
      ApiFactory.getBussinessLogService()
          .log("工作组管理", "新建工作组:" + workGroup.getName(), ContextUtils.getSystemId("acs"));
    } else {
      ApiFactory.getBussinessLogService()
          .log("工作组管理", "修改工作组:" + workGroup.getName(), ContextUtils.getSystemId("acs"));
    }
    addSuccessMessage("保存成功");
    return null;
  }
 private String createWorkGroupCode() {
   int num = 0;
   List<Workgroup> Workgroups = workGroupManager.getDefaultCodeWorkGroups();
   if (Workgroups != null && Workgroups.size() > 0) {
     for (Workgroup w : Workgroups) {
       String codeNum = w.getCode().replace("workgroup-", "");
       if (codeNum.matches("^-?\\d+$") && Integer.valueOf(codeNum) > num) {
         num = Integer.valueOf(codeNum);
       }
     }
   } else {
     return "workgroup-1";
   }
   return "workgroup-" + (num + 1);
 }