返回顶部
首页 > 资讯 > 后端开发 > Python >Java毕业设计实战之工作管理系统的实现
  • 441
分享到

Java毕业设计实战之工作管理系统的实现

2024-04-02 19:04:59 441人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

前台用户和后台管理员两种角色: 前台用户功能有:发布兼职、发布帖子、查看公告、个人中心、投诉等。 后台管理员功能有:用户管理、兼职管理、帖子管理、聊天管理、广告管理、投诉管理、收藏管

前台用户和后台管理员两种角色:

前台用户功能有:发布兼职、发布帖子、查看公告、个人中心、投诉等。

后台管理员功能有:用户管理、兼职管理、帖子管理、聊天管理、广告管理、投诉管理、收藏管理、系统管理等。

运行环境:jdk1.8、Tomcat7.0\8.5、Eclipse、Mysql5.x。

后台角色管理控制器:



@RequestMapping("/admin/role")
@Controller
public class RoleController {
 
	
	private Logger log = LoggerFactory.getLogger(RoleController.class);
	
	@Autowired
	private MenuService menuService;
	
	@Autowired
	private OperaterLogService operaterLogService;
	
	@Autowired
	private RoleService roleService;
	
	
	@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";
	}
	
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
		return "admin/role/add";
	}
	
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(Role role){
		//用统一验证实体方法验证是否合法
		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);
	}
	
	
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(@RequestParam(name="id",required=true)Long id,Model model){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
		Role role = roleService.find(id);
		model.addAttribute("role", role);
		model.addAttribute("authorities",JSONArray.tojsON(role.getAuthorities()).toString());
		return "admin/role/edit";
	}
	
	
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> edit(Role role){
		//用统一验证实体方法验证是否合法
		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);
	}
	
	
	@RequestMapping(value="delete",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
		try {
			roleService.delete(id);
		} catch (Exception e) {
			// TODO: handle exception
			return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
		}
		log.info("编辑角色ID【"+id+"】");
		operaterLogService.add("删除角色ID【"+id+"】");
		return Result.success(true);
	}
}

后台用户管理控制器:



@RequestMapping("/admin/user")
@Controller
public class UserController {
 
	@Autowired
	private UserService userService;
	@Autowired
	private RoleService roleService;
	@Autowired
	private OperaterLogService operaterLogService;
	
	@RequestMapping(value="/list")
	public String list(Model model,User user,PageBean<User> pageBean){
		model.addAttribute("title", "用户列表");
		model.addAttribute("username", user.getUsername());
		model.addAttribute("pageBean", userService.findList(user, pageBean));
		return "admin/user/list";
	}
	
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		model.addAttribute("roles", roleService.findAll());
		return "admin/user/add";
	}
	
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(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(userService.isExistUsername(user.getUsername(), 0l)){
			return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
		}
		//到这说明一切符合条件,进行数据库新增
		if(userService.save(user) == null){
			return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
		}
		operaterLogService.add("添加用户,用户名:" + user.getUsername());
		return Result.success(true);
	}
	
	
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(Model model,@RequestParam(name="id",required=true)Long id){
		model.addAttribute("roles", roleService.findAll());
		model.addAttribute("user", userService.find(id));
		return "admin/user/edit";
	}
	
	
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	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_USE_NO_EXIST);
		}
		if(userService.isExistUsername(user.getUsername(), user.getId())){
			return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
		}
		//到这说明一切符合条件,进行数据库保存
		User findById = userService.find(user.getId());
		//讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
		BeanUtils.copyProperties(user, findById, "id","createTime","updateTime");
		if(userService.save(findById) == null){
			return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR);
		}
		operaterLogService.add("编辑用户,用户名:" + user.getUsername());
		return Result.success(true);
	}
	
	
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
		try {
			userService.delete(id);
		} catch (Exception e) {
			return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
		}
		operaterLogService.add("删除用户,用户ID:" + id);
		return Result.success(true);
	}
}

系统控制器:



@RequestMapping("/system")
@Controller
public class SystemController {
 
	
	
	@Autowired
	private OperaterLogService operaterLogService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private DatabaseBakService databaseBakService;
 
	@Autowired
	private StaffService staffService;
	@Autowired
	private OrderAuthService orderAuthService;
 
	private Logger log = LoggerFactory.getLogger(SystemController.class);
	
	
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login(Model model){
		model.addAttribute("loginTypes", LoginType.values());
		return "admin/system/login";
	}
	
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> login(httpservletRequest request,String username,String passWord,String cpacha,Integer type){
		if(StringUtils.isEmpty(username)){
			return Result.error(CodeMsg.ADMIN_USERNAME_EMPTY);
		}
		if(StringUtils.isEmpty(password)){
			return Result.error(CodeMsg.ADMIN_PASSWORD_EMPTY);
		}
 
		//表示实体信息合法,开始验证验证码是否为空
		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);
		}
 
		if(type == LoginType.ADMINISTRATOR.getCode()){
			//表示验证码正确,开始查询数据库,检验密码是否正确
			User findByUsername = userService.findByUsername(username);
			//判断是否为空
			if(findByUsername == null){
				return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
			}
			//表示用户存在,进一步对比密码是否正确
			if(!findByUsername.getPassword().equals(password)){
				return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
			}
			//表示密码正确,接下来判断用户状态是否可用
			if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
				return Result.error(CodeMsg.ADMIN_USER_UNABLE);
			}
			//检查用户所属角色状态是否可用
			if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
				return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
			}
			//检查用户所属角色的权限是否存在
			if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
				return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
			}
			//检查一切符合,可以登录,将用户信息存放至session
			request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, findByUsername);
			request.getSession().setAttribute("loginType",type);
 
			//销毁session中的验证码
			request.getSession().setAttribute("admin_login", null);
			//将登陆记录写入日志库
			operaterLogService.add("用户【"+username+"】于【" + StringUtil.getFORMatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");
			log.info("用户成功登录,user = " + findByUsername);
		}else{
			Staff byJobNumber = staffService.findByNameAndIsStatus(username);
			//判断是否为空
			if(byJobNumber == null){
				return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
			}
 
			//表示用户存在,进一步对比密码是否正确
			if(!byJobNumber.getPassword().equals(password)){
				return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
			}
 
			//检查用户所属角色状态是否可用
			if(byJobNumber.getRole() == null || byJobNumber.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
				return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
			}
 
			//检查用户所属角色的权限是否存在
			if(byJobNumber.getRole().getAuthorities() == null || byJobNumber.getRole().getAuthorities().size() == 0){
				return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
			}
			//检查一切符合,可以登录,将用户信息存放至session
			request.getSession().setAttribute(SessionConstant.SESSION_STAFF_LOGIN_KEY, byJobNumber);
			request.getSession().setAttribute("loginType",type);
			//销毁session中的验证码
			request.getSession().setAttribute("admin_login", null);
			//将登陆记录写入日志库
			operaterLogService.add("用户【"+username+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");
			log.info("员工成功登录,user = " + byJobNumber);
		}
 
		return Result.success(true);
	}
	
	
	@RequestMapping(value="/index")
	public String index(Model model){
		model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10));
		model.addAttribute("userTotal", userService.total());
		model.addAttribute("operatorLogTotal", operaterLogService.total());
		model.addAttribute("databaseBackupTotal", databaseBakService.total());
		model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);
		return "admin/system/index";
	}
	
	
	@RequestMapping(value="/loGout")
	public String logout(){
		Integer loginType = (Integer) SessionUtil.get("loginType");
		if(loginType == LoginType.ADMINISTRATOR.getCode()){
			User loginedUser = SessionUtil.getLoginedUser();
			if(loginedUser != null){
				SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
			}
		}else if(loginType == LoginType.STAFF.getCode()){
			Staff loginedStaff = SessionUtil.getLoginedStaff();
			if(loginedStaff != null){
				SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,null);
			}
		}
		return "redirect:login";
	}
	
	
	@RequestMapping(value="/no_right")
	public String noRight(){
		return "admin/system/no_right";
	}
	
	
	@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
	public String updateUserInfo(){
		return "admin/system/update_userinfo";
	}
	
	
	@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
	public String updateUserInfo(User user){
		User loginedUser = SessionUtil.getLoginedUser();
		loginedUser.setEmail(user.getEmail());
		loginedUser.setMobile(user.getMobile());
		loginedUser.setHeadPic(user.getHeadPic());
		//首先保存到数据库
		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";
	}
	
	
	@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
			@RequestParam(name="newPwd",required=true)String newPwd
			){
		Integer loginType = (Integer) SessionUtil.get("loginType");
		if(loginType == LoginType.ADMINISTRATOR.getCode()){
			User loginedUser = SessionUtil.getLoginedUser();
			if(!loginedUser.getPassword().equals(oldPwd)){
				return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
			}
			if(StringUtils.isEmpty(newPwd)){
				return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
			}
			if(newPwd.length()<4 || newPwd.length()>32){
				return Result.error(CodeMsg.ADMIN_USER_PWD_LENGTH_ERROR);
			}
			loginedUser.setPassword(newPwd);
			//保存数据库
			userService.save(loginedUser);
			//更新session
			SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
		}else{
			Staff loginedStaff = SessionUtil.getLoginedStaff();
 
			Staff staff = staffService.find(loginedStaff.getId());
			if(!staff.getPassword().equals(oldPwd)){
				return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
			}
			if(StringUtils.isEmpty(newPwd)){
				return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
			}
 
			staff.setPassword(newPwd);
 
			CodeMsg codeMsg = ValidateEntityUtil.validate(staff);
			if (codeMsg.getCode() != CodeMsg.SUCCESS.getCode()){
				return Result.error(codeMsg);
			}
 
			loginedStaff.setPassword(newPwd);
			//保存数据库
			staffService.save(loginedStaff);
			//更新session
			SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY, loginedStaff);
		}
 
		return Result.success(true);
	}
	
	
	@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";
	}
	
	@RequestMapping(value="/auth_order",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){
 
		OrderAuth orderAuth = new OrderAuth();
		orderAuth.setMac(StringUtil.getMac());
		orderAuth.setOrderSn(orderSn);
		orderAuth.setPhone(phone);
		orderAuthService.save(orderAuth);
		AppConfig.ORDER_AUTH = 1;
		return Result.success(true);
	}
 
	
	@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);
	}
	
	
	@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> deleteAll(){
		operaterLogService.deleteAll();
		return Result.success(true);
	}
}

到此这篇关于Java毕业设计实战之工作管理系统的实现的文章就介绍到这了,更多相关Java 工作管理系统内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Java毕业设计实战之工作管理系统的实现

本文链接: https://lsjlt.com/news/138177.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作