public int countByCriteria(User paramUser) { if ("1".equals(SessionUtils.getUserRole())) paramUser.setRole("'2','3'"); else { paramUser.setRole("'3'"); } int count = this.userDao.countByCriteria(paramUser); return count; }
public List<User> selectByCriteriaForPaging(User paramUser) { if ("1".equals(SessionUtils.getUserRole())) paramUser.setRole("'2','3'"); else { paramUser.setRole("'3'"); } List userList = this.userDao.selectByCriteriaForPaging( paramUser, paramUser.getStart(), paramUser.getLimit()); List results = new ArrayList(); if (userList != null) { for (int i = 0; i < userList.size(); i++) { User user = (User) userList.get(i); user.setBirthdayStr(DateUtils.formatDate2Str(user.getBirthday(), "yyyy-MM-dd")); user.setRole((String) Constants.ROLE_MAP.get(user.getRole())); user.setSex((String) Constants.SEX_MAP.get(user.getSex())); user.setStatus((String) Constants.USER_STATUS_MAP.get(user.getStatus())); results.add(user); } } return results; }
public JSONObject register(Map map) throws Exception { boolean isSuccess = true; String errorMsg = ""; User paramUser = new User(); BeanUtils.populate(paramUser, map); paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd")); paramUser.setStatus("1"); if ((StringUtils.isEmpty(SessionUtils.getUserRole())) || ("3".equals(SessionUtils.getUserRole()))) { paramUser.setRole("3"); } String userId = map.get("userId").toString(); String password = map.get("password").toString(); String repassword = map.get("repassword").toString(); String verifyCode = map.get("verifyCode").toString(); String verifyCodeInSession = map.get("verifyCodeInSession").toString(); if ("1".equals(SessionUtils.getUserRole())) { if ((!"2".equals(paramUser.getRole())) && (!"3".equals(paramUser.getRole()))) { isSuccess = false; errorMsg = "角色设置错误."; } } else if (!"3".equals(paramUser.getRole())) { isSuccess = false; errorMsg = "角色设置错误."; } if (!password.equals(repassword)) { isSuccess = false; errorMsg = "两次输入的密码不一致."; } if (!verifyCode.equals(verifyCodeInSession)) { isSuccess = false; errorMsg = "验证码错误."; } List<User> userList = selectByCriteria(new User()); if (userList != null) { for (User user : userList) { if (userId.equals(user.getUserId())) { isSuccess = false; errorMsg = "账号已存在."; break; } if (paramUser.getEmail().equals(user.getEmail())) { isSuccess = false; errorMsg = "邮箱已被使用."; break; } } } if (isSuccess) { insert(paramUser); Map userMetaMap = new HashMap(); userMetaMap.put("theme", (String) map.get("theme")); userMetaMap.put("homePage", (String) map.get("homePage")); userMetaMap.put("showTodo", (String) map.get("showTodo")); userMetaMap.put("showNote", (String) map.get("showNote")); userMetaMap.put("showPicture", (String) map.get("showPicture")); userMetaMap.put("showAccount", (String) map.get("showAccount")); userMetaMap.put("showFeed", (String) map.get("showFeed")); userMetaMap.put("showDocument", (String) map.get("showDocument")); if ("3".equals(paramUser.getRole())) userMetaMap.put("showSystem", "off"); else { userMetaMap.put("showSystem", "on"); } this.userMetaService.insert(userId, userMetaMap); String uploadFilePath = ServletHelp.getRealPath( (HttpServletRequest) map.get("request"), MessageUtils.setParamMessage("/websrc/file/{0}/document", new String[] {userId})); FileUtils.createDirs(uploadFilePath); String uploadPicturePath = ServletHelp.getRealPath( (HttpServletRequest) map.get("request"), MessageUtils.setParamMessage("/websrc/file/{0}/picture", new String[] {userId})); FileUtils.createDirs(uploadPicturePath); FileUtils.createDirs(uploadPicturePath + "/" + "thumbnail"); String feedFilePath = ServletHelp.getRealPath( (HttpServletRequest) map.get("request"), MessageUtils.setParamMessage("/websrc/file/{0}/feed", new String[] {userId})); FileUtils.createDirs(feedFilePath); } JSONObject res = new JSONObject(); res.put("success", Boolean.valueOf(isSuccess)); res.put("message", errorMsg); return res; }