public static Set<String> getUsersExceptRoleName(Long systemId, String roleName) { Set<String> userNames = new HashSet<String>(); for (User user : ApiFactory.getAcsService().getUsersWithoutRoleName(systemId, roleName)) { userNames.add(user.getLoginName()); } return userNames; }
public String getTrustorSubCompanyName() { User user = ApiFactory.getAcsService().getUserById(trustorId); if (user != null) { return user.getSubCompanyName(); } return ContextUtils.getCompanyName(); }
@Transactional(readOnly = false) public void run() throws Exception { List<Company> companys = acsUtils.getAllCompanys(); for (Company company : companys) { ThreadParameters parameters = new ThreadParameters(company.getId()); ParameterUtils.setParameters(parameters); String systemAdmin = ApiFactory.getAcsService().getSystemAdminLoginName(); parameters = new ThreadParameters(company.getId()); parameters.setUserName("系统"); parameters.setLoginName(systemAdmin); ParameterUtils.setParameters(parameters); // 委托 delegateMain(); // 催办 List<WorkflowTask> result = new ArrayList<WorkflowTask>(); result.addAll(workflowInstanceManager.getNeedReminderTasksByInstance()); result.addAll(taskService.getNeedReminderTasks()); reminder(result); } deleteExportTempFile(); // 清空同步处理时的实例map,见TaskService中的completeInteractiveWorkflowTask方法 TaskService.instanceIds.clear(); }
/** * 保存工作组添加用户 * * @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; }
public static Set<String> getUsersByRoleName(String roleName, Long systemId, Long companyId) { Set<String> userNames = new HashSet<String>(); for (User user : ApiFactory.getAcsService().getUsersByRoleName(systemId, roleName)) { userNames.add(user.getLoginName()); } return userNames; }
public static Set<String> getUsersByDepartment(Set<Department> departmentSet) { Set<String> userNames = new HashSet<String>(); for (Department department : departmentSet) { userNames.addAll( getUserLoginName(ApiFactory.getAcsService().getUsersByDepartmentId(department.getId()))); } return userNames; }
public static Set<String> getUsersByWorkGroup(Set<Workgroup> workgroupSet) { Set<String> userNames = new HashSet<String>(); for (Workgroup workGroup : workgroupSet) { userNames.addAll( getUserLoginName(ApiFactory.getAcsService().getUsersByWorkgroupId(workGroup.getId()))); } return userNames; }
/** * 获得可供选择的办理人 * * @return 可供选择的办理人登录名集合 */ public Collection<Long> getCanChoiceTransactorId() { if (canChoiceTransactorId.size() > 0) return canChoiceTransactorId; for (String transactor : canChoiceTransactor) { User user = ApiFactory.getAcsService().getUserByLoginName(transactor); canChoiceTransactorId.add(user.getId()); } return canChoiceTransactorId; }
/** * 获得可供选择的办理人 * * @return 可供选择的办理人登录名集合 */ public Collection<String> getCanChoiceTransactor() { if (canChoiceTransactor.size() > 0) return canChoiceTransactor; for (Long transactorId : canChoiceTransactorId) { User user = ApiFactory.getAcsService().getUserById(transactorId); canChoiceTransactor.add(user.getLoginName()); } return canChoiceTransactor; }
@Transactional(readOnly = false) public void delegateMain() { try { // 权限委托 List<TrustRecord> delegateMains = delegateMainManager.getDelegateMainsOnAssign(); for (TrustRecord dm : delegateMains) { com.norteksoft.product.api.entity.User trustee = ApiFactory.getAcsService().getUserByLoginName(dm.getTrustee()); // 受托人 com.norteksoft.product.api.entity.User trustor = ApiFactory.getAcsService().getUserByLoginName(dm.getTrustor()); // 委托人 if (needEfficient(dm)) { ApiFactory.getAcsService() .assignTrustedRole(trustor.getId(), dm.getRoleIds().split(","), trustee.getId()); dm.setState(TrustRecordState.EFFICIENT); delegateMainManager.saveDelegateMain(dm); } if (needEnd(dm)) { ApiFactory.getAcsService() .deleteTrustedRole(trustor.getId(), dm.getRoleIds().split(","), trustee.getId()); dm.setState(TrustRecordState.END); delegateMainManager.saveDelegateMain(dm); } } // 流程委托 List<TrustRecord> workflowDelegateMains = delegateMainManager.getAllStartWorkflowDelegateMain(); for (TrustRecord wfdm : workflowDelegateMains) { if (needEfficient(wfdm)) { wfdm.setState(TrustRecordState.EFFICIENT); delegateMainManager.saveDelegateMain(wfdm); } if (needEnd(wfdm)) { wfdm.setState(TrustRecordState.END); delegateMainManager.saveDelegateMain(wfdm); // 委托结束时取回任务 taskService.recieveDelegateTask(wfdm); } } } catch (Exception e) { log.error("定时委托异常:" + e.getMessage()); } }
/** * 判断用户是不是在部门里,如果在返回ture;否则,返回false。 * * @param companyId * @param loginName * @param departmentName * @return 用户在部门里,返回ture;否则,返回false。 */ public static boolean userInDepartment(Long companyId, String loginName, String departmentName) { if (ContextUtils.getCompanyId() == null) { ThreadParameters parameters = new ThreadParameters(companyId); ParameterUtils.setParameters(parameters); } List<Department> departments = ApiFactory.getAcsService().getDepartments(loginName); for (Department department : departments) { if (department.getName().equals(departmentName)) { return true; } } return false; }
/** * 判断用户是不是在工作组里,如果在返回ture;否则,返回false。 * * @param companyId * @param loginName * @param departmentName * @return 用户在工作组里,返回ture;否则,返回false。 */ public static boolean userInWorkGroup(Long companyId, String loginName, String workGroupName) { if (ContextUtils.getCompanyId() == null) { ThreadParameters parameters = new ThreadParameters(companyId); ParameterUtils.setParameters(parameters); } List<com.norteksoft.product.api.entity.Workgroup> workGroups = ApiFactory.getAcsService().getWorkgroupsByUser(loginName); for (com.norteksoft.product.api.entity.Workgroup workGroup : workGroups) { if (workGroup.getName().equals(workGroupName)) { return true; } } return false; }
/** * 没有部门的用户的树节点 * * @param companyId * @return */ public String getNoDepartmentUserNodes(Long companyId) { StringBuilder nodes = new StringBuilder(); ThreadParameters parameters = new ThreadParameters(companyId); ParameterUtils.setParameters(parameters); List<User> users = ApiFactory.getAcsService().getUsersWithoutDepartment(); for (User user : users) { if (user.isDeleted()) continue; nodes .append( JsTreeUtils.generateJsTreeNodeDefault( "USER," + user.getId() + "," + user.getLoginName(), "", user.getName(), "")) .append(","); } JsTreeUtils.removeLastComma(nodes); return nodes.toString(); }
/** * 判断用户是不是拥有某权限,如果有返回ture;否则,返回false。 * * @param companyId * @param loginName * @param departmentName * @return 用户拥有某权限,返回ture;否则,返回false。 */ public static boolean userHaveRole(Long companyId, String loginName, String roleName) { // 获得子系统的id集合 BusinessSystemManager businessSystemManager = (BusinessSystemManager) ContextUtils.getBean("businessSystemManager"); List<Long> subSystemIds = businessSystemManager.getSystemIdsByParentCode(ContextUtils.getSystemCode()); if (ContextUtils.getCompanyId() == null) { ThreadParameters parameters = new ThreadParameters(companyId); ParameterUtils.setParameters(parameters); } Set<Role> roles = ApiFactory.getAcsService().getRolesByUser(loginName); for (Role role : roles) { if (role.getName().equals(roleName)) { boolean result = validateRole(role, subSystemIds); if (result) { return result; } else { continue; } } } return false; }
public void execute(JobExecutionContext arg0) throws JobExecutionException { String url = ""; // 如果请求为绝对路径 if (!StringUtils.isEmpty(info.getJobInfo().getUrl()) && info.getJobInfo().getUrl().startsWith("http")) { url = info.getJobInfo().getUrl(); } else { // 根据系统编号获得系统 BusinessSystem currentSystem = ApiFactory.getAcsService().getSystemByCode(info.getJobInfo().getSystemCode()); if (!StringUtils.isEmpty(currentSystem.getParentCode())) { // 表示该系统是子系统 BusinessSystem parentSystem = ApiFactory.getAcsService().getSystemByCode(currentSystem.getParentCode()); url = SystemUrls.getSystemUrl(parentSystem.getCode()); } else { url = SystemUrls.getSystemUrl(info.getJobInfo().getSystemCode()); } if (url.lastIndexOf("/") == url.length() - 1) url = url.substring( 0, url.length() - 1); // 当是80端口,并且是主子系统时,imatrix的地址配置为http://192.168.1.98/,需要将最后的/去掉,因为info.getJobInfo().getUrl()得url的写法为/.../../..,例如/rest/workflow/finish,如果不去http://192.168.1.98/的最后/,拼的地址为http://192.168.1.98//rest/workflow/finish,多个/,所以一定要去 url = url + info.getJobInfo().getUrl(); } // restful请求 if (info.getJobInfo().getApplyType() == ApplyType.RESTFUL_APPLY) { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); client.setReadTimeout(info.getJobInfo().getTimeout() * 1000); WebResource service = client.resource(url); ClientResponse cr = service .entity( "runAsUser="******"&runAsUserId=" + (info.getJobInfo().getRunAsUserId() == null ? "" : info.getJobInfo().getRunAsUserId()) + "&companyId=" + info.getCompanyId(), MEDIA_TYPE) .accept(MEDIA_TYPE) .post(ClientResponse.class); if (cr != null) log.info( " =========== job execute result : [" + cr.getEntity(String.class) + "] =========== "); } else { // http请求 url = url + "?runAsUser="******"&runAsUserId=" + (info.getJobInfo().getRunAsUserId() == null ? "" : info.getJobInfo().getRunAsUserId()) + "&companyId=" + info.getCompanyId(); HttpGet httpget = new HttpGet(url); HttpClient httpclient = new DefaultHttpClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { httpclient.execute(httpget, responseHandler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); } }
/* * 根据条件选定办理人 * @param conditions * @param creator * @param _wf_transactor * @return */ public static Set<String> processCondition( Map<TaskTransactorCondition, String> conditions, OpenExecution execution, Map<String, String> param) { Long companyId = ContextUtils.getCompanyId(); if (companyId == null) { Object compIdStr = execution.getVariable(CommonStrings.COMPANY_ID); if (compIdStr != null) { companyId = Long.parseLong(compIdStr.toString()); } } String userCondition = conditions.get(TaskTransactorCondition.USER_CONDITION); if (userCondition == null) { throw new RuntimeException("办理人设置中,解析条件时,设置的条件不能为null"); } // 根据条件获取办理人 Set<String> candidates = new HashSet<String>(); if ("${documentCreator}".equals(userCondition)) { // 文档创建人 candidates.add(param.get(DOCUMENT_CREATOR)); } else if ("${previousTransactorAssignment}".equals(userCondition)) { // 上一环节办理人指定 candidates.add(CommonStrings.TRANSACTOR_ASSIGNMENT); } else if (userCondition.startsWith("${field[")) { // 文档字段中指定//${field[name_zn[name_en]]} int start = userCondition.lastIndexOf("["); int end = userCondition.indexOf("]"); String fieldName = userCondition.substring(start + 1, end); // 根据流程实例ID获取流程表单中指定字段的值 WorkflowInstanceManager manager = (WorkflowInstanceManager) ContextUtils.getBean("workflowInstanceManager"); String fieldValues = manager.getFieldValueInForm(param.get(PROCESS_INSTANCEID), fieldName); if (fieldValues == null) { throw new RuntimeException("办理人设置中,文档字段中指定时,该字段的值不能为null"); } for (String fieldValue : fieldValues.split(",")) { fieldValue = fieldValue.trim(); if (StringUtils.isNotEmpty(fieldValue)) { if ("ALLCOMPANYID".equals(fieldValue)) { // 所有人员(不包含无部门人员) List<String> loginNames = ApiFactory.getAcsService().getLoginNamesByCompany(companyId); candidates.addAll(loginNames); } else if ("ALLWORKGROUP".equals(fieldValue)) { // 所有工作组中的人员 List<String> loginNames = ApiFactory.getAcsService().getLoginNamesByWorkgroup(companyId); candidates.addAll(loginNames); } else { candidates.add(fieldValue); } } } } else { if (execution == null) { throw new RuntimeException("办理人设置中,解析条件时,execution不能为null"); } FormViewManager formManager = (FormViewManager) ContextUtils.getBean("formViewManager"); WorkflowInstanceManager workflowInstanceManager = (WorkflowInstanceManager) ContextUtils.getBean("workflowInstanceManager"); WorkflowInstance wi = workflowInstanceManager.getWorkflowInstance(param.get(PROCESS_INSTANCEID), companyId); if (wi == null) { throw new RuntimeException("办理人设置中,解析条件时,流程实例不能为null"); } FormView form = formManager.getFormView(wi.getFormId()); UserParseCalculator upc = new UserParseCalculator(); upc.setDataId(wi.getDataId()); upc.setFormView(form); upc.setDocumentCreator(param.get(DOCUMENT_CREATOR)); upc.setPreviousTransactor(param.get(PREVIOUS_TRANSACTOR)); upc.setCurrentTransactor(param.get(CURRENT_TRANSACTOR)); upc.setProcessAdmin(param.get(PROCESS_ADMIN)); candidates.addAll( processAdditionalCondition( conditions, upc.getUsers(userCondition, wi.getSystemId(), wi.getCompanyId()), param.get(DOCUMENT_CREATOR), execution)); } return candidates; }
public static Set<String> getUsersNotInDepartment(Set<Department> departmentSet) { Set<Department> allDepartment = new HashSet<Department>(ApiFactory.getAcsService().getDepartments()); allDepartment.removeAll(departmentSet); return getUsersByDepartment(allDepartment); }
public static Department getDepartmentByName(String name) { return ApiFactory.getAcsService().getDepartmentByName(name); }
public static List<Department> getDepartmentsByUser(String loginName) { return ApiFactory.getAcsService().getDepartments(loginName); }
public static Set<String> getUserExceptLoginName(String loginName) { return ApiFactory.getAcsService().getLoginNamesExclude(loginName); }