/** * 修改密码 * * @return */ public String editPassword() { User dbResult = userManager.getById(getCurrUser().getUserID()); User user = this.userManager.getById(getCurrUser().getUserID()); String pwd = getRequest().getParameter("password"); String pwdold = getRequest().getParameter("password_old"); String msg = "修改密码成功"; int type = 1; if (pwdold.equals(dbResult.getPassword())) { dbResult.setPassword(pwd); try { userManager.saveOrUpdate(dbResult); // 提示信息 Flash.current().success(RESET_PASSWORD_SUCCESS); } catch (Exception e) { e.printStackTrace(); msg = "修改密码失败!"; type = 2; // 提示信息 // Flash.current().success(RESET_PASSWORD_FAILURE); } } else { msg = "原始密码错误!"; type = 3; } getRequest().setAttribute("type", type); getRequest().setAttribute("msg", msg); return "update_password"; }
/** * 删除对象 * * @return */ public String delete() { String deleteMessage = ""; for (int i = 0; i < items.length; i++) { Hashtable params = HttpUtils.parseQueryString(items[i]); String id = (String) params.get("id"); User user = userManager.getById(id); try { } catch (Exception e) { } // 超级管理员禁止删除 if (user.getLoginname() != null && user.getLoginname().equals("admin")) { deleteMessage = "超级管理员禁止删除"; } else { // 删除时,置换删除标记 user.setDf("1"); // 删除人员时 需要把人员与角色的关系 以及管理员与分区的关系删除 user.setRoles(new HashSet<Role>(0)); user.setOuRelations(null); user.setPartitions(new HashSet<Partition>(0)); userManager.delete(user); } } if (deleteMessage != null && !deleteMessage.equals("")) { Flash.current().success(deleteMessage); } else { Flash.current().success(DELETE_SUCCESS); } return LIST_ACTION; }
/** * 更改用户类型 * * @return */ public String updatetype() { String ids = getRequest().getParameter("ids"); String[] userIds = ids.split(","); String source = this.getRequest().getParameter("source"); if (!isNullOrEmptyString(source)) { for (String uid : userIds) { User user = userManager.getById(uid); user.setSource(source); userManager.update(user); } } return LIST_ACTION; }
/** 保存新增草稿 */ public String saveadd() { String title = getRequest().getParameter("title"); String content = getRequest().getParameter("content"); String receids = getRequest().getParameter("receids"); String[] rids = receids.split(","); for (String rid : rids) { User user = userManager.getById(rid); Message mess = new Message(); mess.setTitle(title); mess.setContent(content); mess.setReceiverId(user.getId()); mess.setReceiver(user.getUsername()); mess.setStatus("0"); // 未发送 mess.setTime(new Date()); mess.setState("0"); // 消息状态 0为未查看 mess.setTs(new Date()); mess.setSponsor(this.getCurrUser().getUserName()); mess.setSponsorId(this.getCurrUser().getUserID()); this.messageManager.save(mess); if (file != null) { uploadFile(mess.getId()); // 上传附件 } } return "sendAction"; }
/** * 批量 启用/停用 0/1 * * @return */ public String batchAble() { String message = ""; for (int i = 0; i < items.length; i++) { Hashtable params = HttpUtils.parseQueryString(items[i]); String id = (String) params.get("id"); User user = userManager.getById(id); // 超级管理员不允许禁用 if (user.getLoginname() != null && user.getLoginname().equals("admin")) { message = "超级管理员禁止执行当前操作"; } else { if (ableFlag != null && ableFlag.equals("enabled")) { if (user.getIsLeave().equals("0")) // 判断是否离职,如果已离职,则不允许启用该用户 { message = "该员工已离职!不允许做操作!"; } else { user.setAbledFlag("0"); } } if (ableFlag != null && ableFlag.equals("disabled")) { user.setAbledFlag("1"); } this.userManager.save(user); } } if (message != null && !message.equals("")) { Flash.current().success(message); } else { Flash.current().success(ADMIT_SUCCESS); } return LIST_ACTION; }
public void prepare() throws Exception { if (isNullOrEmptyString(id)) { user = new User(); } else { user = (User) userManager.getById(id); } }
/** * 修改个人设置 * * @return */ public String editPerson() { User dbResult = userManager.getById(getCurrUser().getUserID()); // dbResult.setPhone(user.getPhone()); // dbResult.setBirthday(user.getBirthday()); // dbResult.setSex(user.getSex()); // dbResult.setMail(user.getMail()); // dbResult.setQq(user.getQq()); // dbResult.setMsn(user.getMsn()); // dbResult.setWblog(user.getWblog()); /*// 维护组织机构信息 this.organizationUserRelationManager.removeOURByUserId(getCurrUser().getUserID()); if (user.getDeptIDs() != null && !user.getDeptIDs().equals("")) { String[] organizationIds = user.getDeptIDs().split(","); for (String organizationId : organizationIds) { OrganizationUserRelation our = new OrganizationUserRelation(); our.setOrganizationId(organizationId); our.setUserId(getCurrUser().getUserID()); this.organizationUserRelationManager.save(our); } }*/ /* * 判断图片是否被更改,以优化程序,不必每次都调用webservice String fileName = getRequest().getParameter(FILE_NAME); if (StringUtils.isNotEmpty(fileName)) { // 创建一个webservice ClientAttachmentService clientAttach = new ClientAttachmentService(); clientAttach.deleteAttach(dbResult.getId(), "true", null, getRequest().getParameter("attach_client_id")); clientAttach.saveAttach(dbResult.getId(), getRequest() .getParameter("attach_client_id"), getRequest() .getParameter("attach_form_key"), FILE_NAME, FILE_MODEL); System.out.println(getRequest().getParameter("attach_client_id")); System.out.println(getRequest().getParameter("attach_form_key")); }*/ userManager.saveOrUpdate(dbResult); Flash.current().success("修改个人信息成功!"); return "editPersonPage"; }
/** * 角色授予 * * @return */ public String grantRole() { Set<Role> roles = new HashSet<Role>(0); if (items != null) { for (String roleID : items) { Role role = roleManager.getById(roleID); roles.add(role); } } user.setRoles(roles); userManager.saveOrUpdate(user); // Flash.current().success(UPDATE_SUCCESS); return "closeDialog"; }
/** * 修改个人设置页面 * * @return */ public String editPersonPage() { user = userManager.getById(getCurrUser().getUserID()); // getRequest().setAttribute("depts", deptManager.findAll()); // getRequest().setAttribute(DEPTS, organizationManager.findAllByDf()); // 性别 this.sexMap = dicUtil.getDicList("DICT_SEX"); // 组织机构IDS StringBuffer sbId = new StringBuffer(); StringBuffer sbText = new StringBuffer(); for (OrganizationUserRelation our : user.getOuRelations()) { sbId.append(our.getOrganization().getId() + ","); sbText.append(our.getOrganization().getName() + ","); } String ids = sbId.toString(); String texts = sbText.toString(); if (ids != null && !ids.equals("")) { user.setDeptIDs(ids.substring(0, ids.length() - 1)); user.setDeptsString(texts.substring(0, texts.length() - 1)); } return EDIT_PERSON_INFO; }
/** * 加载用户列表,用于选择用户组件 * * @return */ @SuppressWarnings("unchecked") public String loadUserList() { query.setDf("0"); // 如果是取某分区下的用户,根据分区下的组织机构取得所有用户 if (partitionId != null && !"".equals(partitionId)) { Partition partition = partitionManager.getById(partitionId); if (partition != null) { query.setOrganizIds(organizationManager.findAllChildByPartition(partition)); } } Page page = this.organizationUserRelationManager.findByUserPage(query); page = userManager.findPage(query); List<User> users = page.getResult(); // 处理部门列表 for (User user : users) { user.setDeptsString(""); if (user.getOuRelations() != null) { StringBuffer sb = new StringBuffer(); for (OrganizationUserRelation our : user.getOuRelations()) { if (our.getOrganization() != null) { sb.append(our.getOrganization().getName() + ","); } } user.setDeptsString(sb.toString()); } } // 性别 for (User user : users) { /*if (user.getSex() != null && !user.getSex().equals("")) { this.sexMap = this.dicUtil.getDicList("DICT_SEX"); user.setSexString(this.sexMap.get(user.getSex())); }*/ } this.saveCurrentPage(page, query); return "loadUserList"; }
/** * 修改用户继教号 * * @return */ public String changeUserNum() { try { InputStream templatInputStream = this.getClass().getResourceAsStream("/com/opendata/organiz/action/teacher.xls"); BufferedInputStream in = new BufferedInputStream(templatInputStream); POIFSFileSystem fs = new POIFSFileSystem(in); HSSFWorkbook book = new HSSFWorkbook(fs); HSSFSheet sheet = book.getSheetAt(0); int num = sheet.getLastRowNum(); List<Map<String, String>> l = new ArrayList<Map<String, String>>(); for (int i = 1; i < num; i++) { HSSFRow row = sheet.getRow(i); HSSFCell c1 = row.getCell(1); if (c1 != null) { // 继教号 String userNum = c1.toString(); HSSFCell c5 = row.getCell(5); if (c5 != null) { // 身份证号 String IDNum = c5.toString(); Map<String, String> map = new HashMap<String, String>(); map.put("userNum", userNum); map.put("IDNum", IDNum); l.add(map); } } } userManager.batchUpdateUserNum(l); Flash.current().success("继教号同步成功!"); } catch (Exception e) { e.printStackTrace(); Flash.current().success("继教号同步失败!"); } return LIST_ACTION; }
/* * 根据用户ID查询所有用户名 */ public String findAllUser() { List<User> userList = userManager.findAll(); getRequest().setAttribute("userList", userList); return "findAllUser"; }
/** * 进入修改密码页面 * * @return */ public String editPasswordPage() { user = userManager.getById(getCurrUser().getUserID()); return "edit_password"; }
/** * 保存新增对象 * * @return */ public String save() { if (partitionId != null && !"".equals(partitionId) && (user.getDeptIDs() == null || "".equals(user.getDeptIDs()))) { Flash.current().error("分区下用户必须选择组织机构!"); return CREATE_JSP; } // 校验登录名是否重复 User _user = this.userManager.findByName(user.getLoginname()); if (_user != null) { // 性别 this.sexMap = dicUtil.getDicList("DICT_SEX"); // 部门列表 // getRequest().setAttribute(DEPTS, deptManager.findAll()); getRequest().setAttribute(DEPTS, organizationManager.findAllByDf()); // 登录名重复 Flash.current().error("登录名已经存在,请重新填写!"); return CREATE_JSP; } user.setTs(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); // 设置删除标记 user.setDf("0"); // 默认启用 if (user.getIsLeave().equals("0")) // 已离职 账户禁用 0 启用 1 { user.setAbledFlag("1"); } else { user.setAbledFlag("0"); } // user.setPhoto(getRequest().getParameter("articleAttachPic")); userManager.save(user); // 创建一个webservice /* * WebApplicationContext wac = * WebApplicationContextUtils.getRequiredWebApplicationContext * (getRequest().getSession().getServletContext()); PictureService * pictureService = (PictureService)wac.getBean("pictureService"); * pictureService * .saveAttach(user.getId(),getRequest().getParameter("attach_client_id" * ), getRequest().getParameter("attach_form_key"), FILE_NAME,FILE_MODEL * ); */ ClientAttachmentService clientAttach = new ClientAttachmentService(); clientAttach.saveAttach( user.getId(), getRequest().getParameter("attach_client_id"), getRequest().getParameter("attach_form_key"), FILE_NAME, FILE_MODEL); // 用户和组织机构的这种关系需要清除了 if (user.getDeptIDs() != null && !user.getDeptIDs().equals("")) { String[] organizationIds = user.getDeptIDs().split(","); for (String organizationId : organizationIds) { OrganizationUserRelation our = new OrganizationUserRelation(); our.setUserId(user.getId()); our.setOrganizationId(organizationId); this.organizationUserRelationManager.save(our); } } Flash.current().success(CREATED_SUCCESS); // 存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息 return LIST_ACTION; }