1、社团信息浏览搜索、社团活动风采、新闻信息浏览搜索。
2、学生注册登录。
3、登录后可自己申请创建社团,也可申请加入其他社团活动。
4、管理自己社团的申请人员。
5个人信息修改及留言等。
后台管理员除了基本的系统管理功能(脚手架里的功能,这里不赘述)外,还有社团审核管理、活动新闻管理、学生管理、留言管理、活动申请审核、活动经费管理等等。
@RequestMapping("/system") @Controller public class SystemController { @Autowired private SiteConfig siteConfig; @Autowired private OperaterLogService operaterLogService; @Autowired private UserService userService; private Logger log= LoggerFactory.getLogger(SiteConfig.class); @Autowired private DatabaseBakService databaseBakService; @Autowired private SmsService smsService; @Autowired private RedisTemplate<String,String> redisTemplate; @Autowired private AssociationService associationService; @Autowired private ActivitiesService activitiesService; @Autowired private StyleService styleService; @Autowired private OrderAuthService orderAuthService; @Autowired private StudentService studentService; /** * 登录页面 * @param model * @return */ @RequestMapping(value = "/login",method = RequestMethod.GET) public String index(Model model){ model.addAttribute("siteName",siteConfig.getSiteName()); model.addAttribute("siteUrl",siteConfig.getSiteUrl()); return "admin/system/login"; } //登录成功后主页 @RequestMapping(value = "/index") public String indext(Model model){ model.addAttribute("operatorLogs",operaterLogService.findLastLog(10)); model.addAttribute("userTotal",userService.total()); model.addAttribute("logTotal",operaterLogService.total()); model.addAttribute("dataTotal",databaseBakService.total()); model.addAttribute("onlineUserTotal", HttpSessionS.onlineUserCount); model.addAttribute("associationTotal",associationService.count(Association.TEAM_AUDIT_SUCCESS)); model.addAttribute("activitesTotal",activitiesService.count(Activities.ACTIVITIES_AUDIT_SUCCESS)); model.addAttribute("styleTotal",styleService.count(Style.STYLE_AUDIT_SUCCESS)); model.addAttribute("studentTotal",studentService.count()); return "admin/system/index"; } @ResponseBody @RequestMapping(value = "/login",method = RequestMethod.POST) public Result<Boolean> login(HttpServletRequest request,User user, String cpacha){ Map<String,String>ret=new HashMap<String,String>(); if(user==null) { return Result.error(CodeMsg.DATA_ERROR); } //用统一验证实体方法验证是否合法 CodeMsg validate = ValidateEntityUtil.validate(user); if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } //表示实体信息合法,开始验证验证码是否为空、 if(StringUtils.isEmpty(cpacha)){ return Result.error(CodeMsg.CPACHA_EMPTY); } //说明验证码不为空,从session里获取验证码 Object attribute = request.getSession().getAttribute("admin_login"); if(attribute==null){ return Result.error(CodeMsg.SESSION_EXPIRED); } //表示session未失效,进一步判断用户填写的验证码是否正确 if(!cpacha.equalsIgnoreCase(attribute.toString())){ return Result.error(CodeMsg.CPACHA_ERROR); } //表示验证码正确,开始查询数据库,检验密码是否正确 User byUsername = userService.findByUsername(user.getUsername()); if(byUsername==null){ return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST); } //表示用户存在 进一步对比密码是否正确 if(!byUsername.getPassword().equals(user.getPassword())){ return Result.error(CodeMsg.ADMIN_PASSWORD_NO_ERROR); } //表示密码正确,将登录信息放入session中 并判断状态是否可用 if(byUsername.getStatus()!=byUsername.ADMIN_USER_STATUS_ENABLE){ return Result.error(CodeMsg.ADMIN_USER_STATUS_ERROR); } //检查用户是否有角色 状态是否被冻结 if(byUsername.getRole()==null||byUsername.getRole().getStatus()!= Role.ADMIN_ROLE_STATUS_ENABLE){ return Result.error(CodeMsg.ADMIN_USER_ROLE_STATUS_ERROR); } //检查用户有哪些权限 if(byUsername.getRole().getAuthorities()==null ||byUsername.getRole().getAuthorities().size()==0){ return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY); } //检查一切符合 可以登录 request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY,byUsername); //销毁session中的验证码 request.getSession().setAttribute("admin_login",null); //将登录日志写入日志库 OperaterLog operaterLog=new OperaterLog(); operaterLog.setOperator(user.getUsername()); operaterLog.setContent("用户["+user.getUsername()+"]与["+ StringUtil.getFormatterDate(new Date(),"yyyy-MM-dd HH:mm:ss")+"]登录系统"); operaterLogService.save(operaterLog); log.info("用户成功登录,user="+byUsername); return Result.success(true); } /** * 注销登录 * @return */ @RequestMapping(value = "/logout") public String logout(){ User loginedUser = SessionUtil.getLoginedUser(); if(loginedUser!=null){ SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,""); } return "redirect:login"; } /** * 无权限提示页面 * @return */ @RequestMapping(value = "/no_right") public String noRight(){ return "admin/system/no_right"; } /** * 修改用户个人信息 * @return */ @RequestMapping(value = "/update_userInfo",method = RequestMethod.GET) public String updateUserInfo(){ return "admin/system/update_userinfo"; } /** * 修改信息保存 * @param user * @return */ @RequestMapping(value = "/update_userInfo",method = RequestMethod.POST) public String updateUserInfo(User user){ User loginedUser = SessionUtil.getLoginedUser(); loginedUser.setHeadPic(user.getHeadPic()); loginedUser.setEmail(user.getEmail()); loginedUser.setMobile(user.getMobile()); //首先保存到数据库 userService.save(loginedUser); //更新session里的值 SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser); return "redirect:update_userInfo"; } @RequestMapping(value = "/update_pwd",method = RequestMethod.GET) public String updatePwd(){ return "admin/system/update_pwd"; } /** * 修改密码表单提交 * @param oldPwd * @param newPwd * @return */ @ResponseBody @RequestMapping(value = "/update_pwd",method = RequestMethod.POST) public Result<Boolean> updatePwd(@RequestParam(name = "oldPwd",required = true) String oldPwd, @RequestParam(name = "newPwd",required = true)String newPwd){ User loginedUser = SessionUtil.getLoginedUser(); if(!loginedUser.getPassword().equals(oldPwd)){ return Result.error(CodeMsg.ADMIN_USER_PASSWORD_OLD_ERROR); } if(StringUtils.isEmpty(newPwd)){ return Result.error(CodeMsg.ADMIN_USER_PASSWORD_NEW_ERROR); } //设置新密码 loginedUser.setPassword(newPwd); //更新数据库 userService.save(loginedUser); //更新session //更新session里的值 SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser); return Result.success(true); } /** * 日志管理页面 * @param model * @param operaterLog * @param pageBean * @return */ @RequestMapping(value = "/operator_log_list") public String operatorLogList(Model model,OperaterLog operaterLog, PageBean<OperaterLog> pageBean){ model.addAttribute("pageBean",operaterLogService.findList(operaterLog,pageBean)); model.addAttribute("operator",operaterLog.getOperator()); model.addAttribute("title","日志列表"); return "admin/system/operator_log_list"; } /** * 删除操作日志,可删除多个 * @param ids * @return */ @RequestMapping(value = "/delete_operator_log",method = RequestMethod.POST) @ResponseBody public Result<Boolean> delete(String ids){ if(!StringUtils.isEmpty(ids)){ String[] splitIds = ids.split(","); for(String id:splitIds){ operaterLogService.delete(Long.valueOf(id)); } } return Result.success(true); } /** * 清空整个日志 * @return */ @RequestMapping(value ="/delete_all_log",method = RequestMethod.POST) @ResponseBody public Result<Boolean> deleteAll(){ operaterLogService.deleteAll(); return Result.success(true); } @ResponseBody @RequestMapping(value = "/send",method = RequestMethod.POST) public Result<Boolean> code(@RequestParam(name ="phoneName")String phone){ //调用方法 String code = redisTemplate.opsForValue().get(phone); if(!StringUtils.isEmpty(code)){ return Result.error(CodeMsg.ADMIN_PHONE_SMS_EXIST); } //生成验证码并存储到redis中 code = UUID.randomUUID().toString().substring(0, 4); HashMap<String, Object> param = new HashMap<>(); param.put("code",code); boolean isSend = smsService.send(phone, "", param); if(isSend){ redisTemplate.opsForValue().set(phone,code,5, TimeUnit.SECONDS); return Result.success(true); }else { return Result.error(CodeMsg.ADMIN_PHONE_SMS_ERROR); } } }
/** * 后台角色管理控制器 */ @RequestMapping("/admin/role") @Controller public class RoleController { @Autowired private MenuService menuService; private Logger log= LoggerFactory.getLogger(RoleController.class); @Autowired private OperaterLogService operaterLogService; @Autowired private RoleService roleService; /** * 分页搜索角色列表 * @param model * @param role * @param pageBean * @return */ @RequestMapping(value = "/list") public String list(Model model, Role role, PageBean<Role> pageBean){ model.addAttribute("title","角色列表"); model.addAttribute("name",role.getName()); model.addAttribute("pageBean",roleService.findByName(role,pageBean)); return "admin/role/list"; } /** * 角色添加页面 * @param model * @return */ @RequestMapping(value = "/add",method = RequestMethod.GET) public String add(Model model){ List<Menu> all = menuService.findAll(); model.addAttribute("title","添加角色"); model.addAttribute("topMenus", MenuUtil.getTopMenus(all)); model.addAttribute("secondMenus", MenuUtil.getSecondMenus(all)); model.addAttribute("thirdMenus", MenuUtil.getThirdMenus(all)); return "admin/role/add"; } /** * 角色添加表单提交处理 * @param role * @return */ @ResponseBody @RequestMapping(value = "/add",method = RequestMethod.POST) public Result<Boolean> add(Role role, HttpServletRequest request){ CodeMsg validate = ValidateEntityUtil.validate(role); if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } if(roleService.save(role)==null){ return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR); } log.info("添加角色["+role+"]"); operaterLogService.add("添加角色["+role.getName()+"]"); return Result.success(true); } /** * 角色编辑页面 * @param id * @param model * @return */ @RequestMapping(value = "/edit",method = RequestMethod.GET) public String edit(@RequestParam(name = "id",required = true) Long id, Model model){ List<Menu> all = menuService.findAll(); model.addAttribute("title","添加角色"); model.addAttribute("topMenus", MenuUtil.getTopMenus(all)); model.addAttribute("secondMenus", MenuUtil.getSecondMenus(all)); model.addAttribute("thirdMenus", MenuUtil.getThirdMenus(all)); Role role = roleService.find(id); model.addAttribute("role",role); //list转换为数组 model.addAttribute("authorities", JSONArray.toJSON(role.getAuthorities()).toString()); return "admin/role/edit"; } /** * 角色修改表单提交处理 * @param role * @param request * @return */ @ResponseBody @RequestMapping(value = "/edit",method = RequestMethod.POST) public Result<Boolean> edit(Role role, HttpServletRequest request){ CodeMsg validate = ValidateEntityUtil.validate(role); if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } Role existRole = roleService.find(role.getId()); if(existRole==null){ return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST); } existRole.setName(role.getName()); existRole.setRemark(role.getRemark()); existRole.setStatus(role.getStatus()); existRole.setAuthorities(role.getAuthorities()); if(roleService.save(existRole)==null){ return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR); } log.info("编辑角色["+role+"]"); operaterLogService.add("编辑角色["+role.getName()+"]"); return Result.success(true); } @ResponseBody @RequestMapping(value = "/delete",method = RequestMethod.POST) public Result<Boolean> delete(@RequestParam(name = "id",required = true) Long id,HttpServletRequest request){ try { roleService.delete(id); }catch (Exception e){ return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR); } log.info("删除角色ID["+id+"]"); operaterLogService.add("删除角色ID["+id+"]"); return Result.success(true); } }
/** * 后台用户管理控制器 */ @RequestMapping("/admin/user") @Component public class UserController { @Autowired private UserService userService; @Autowired private RoleService roleService; @Autowired private OperaterLogService operaterLogService; /** * 用户列表页面 * @param model * @return */ @RequestMapping("/list") public String list(Model model, User user, PageBean<User> pageBean){ model.addAttribute("usernmae",user.getUsername()); model.addAttribute("pageBean",userService.findList(user,pageBean)); model.addAttribute("title","用户列表"); return "admin/user/list"; } /** * 用户添加页面 * @param model * @param * @return */ @RequestMapping(value = "/add",method = RequestMethod.GET) public String add(Model model){ List<Role> all = roleService.findAll(); model.addAttribute("roles",all); return "admin/user/add"; } @ResponseBody @RequestMapping(value = "/add",method = RequestMethod.POST) public Result<Boolean> add(Model model,User user){ //用统一验证实体方法验证是否合法 CodeMsg validate = ValidateEntityUtil.validate(user); if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } //判断用户的角色是否选择 if(user.getRole()==null ||user.getRole().getId()==null){ return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY); } //没有ID 传个0进去 0不是Long类型 所以加个0l L if(userService.isExistUsername(user.getUsername(),0l)){ return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST); } //到这说明一切符合条件进行数据库新增 if(userService.save(user)==null){ return Result.error(CodeMsg.ADMIN_USER_ADD_ERROR); } operaterLogService.add("添加用户,用户名:"+user.getUsername()); return Result.success(true); } /** * 用户编辑页面 * @param model * @param id * @return */ @RequestMapping(value = "/edit",method = RequestMethod.GET) public String edit(Model model,@RequestParam(name = "id",required = true) Long id){ model.addAttribute("user",userService.find(id)); model.addAttribute("roles",roleService.findAll()); return "admin/user/edit"; } /** * 编辑用户信息表单提交处理 * @param user * @return */ @ResponseBody @RequestMapping(value = "/edit",method = RequestMethod.POST) public Result<Boolean> edit(User user){ //用统一验证实体方法验证是否合法 CodeMsg validate = ValidateEntityUtil.validate(user); if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } //判断用户的角色是否选择 if(user.getRole()==null ||user.getRole().getId()==null){ return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY); } if(user.getId()==null||user.getId().longValue()<=0){ return Result.error(CodeMsg.ADMIN_USER_NO_EXIST); } //判断数据库user表有没有这个用户名 if(userService.isExistUsername(user.getUsername(),user.getId().longValue())){ return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST); } //将提交的用户信息指定字段复制到已存在的user对象中 User findbyId = userService.find(user.getId()); //把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容 BeanUtils.copyProperties(user,findbyId,"id","createTime","updateTime"); //到这说明一切通过 开始进行数据库编辑 if(userService.save(findbyId)==null){ return Result.error(CodeMsg.ADMIN_USER_EDIT_ERROR); } operaterLogService.add("编辑用户,用户名:"+user.getUsername()); return Result.success(true); } @ResponseBody @RequestMapping(value = "/delete",method = RequestMethod.POST) public Result<Boolean> delete(@RequestParam(name = "id",required = true) Long id) { try { userService.delete(id); } catch (Exception e){ return Result.error(CodeMsg.ADMIN_USER_DELETE_ERROR); } operaterLogService.add("删除用户,id为:"+id); return Result.success(true); } }