文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Java实战员工绩效管理系统的实现流程

2024-04-02 19:55

关注

基于SSM+Mysql+Maven+HTML实现的员工绩效管理系统。该系统只有后台页面,后台前端框架使用的是layui官网推荐后台界面。

角色分为管理员和员工

管理员功能有:员工管理、职位管理、部门管理、岗位管理、工资管理、工龄管理、考勤管理、工资项管理等。

员工功能有:考勤管理、工资管理、个人信息。

运行环境:jdk1.8、tomcat7.0\8.5、maven3.5\3.6、eclipse、mysql5.x。

后台员工管理控制器代码:


@RequestMapping("/admin/staff")
@Controller
public class StaffController {
 
	@Autowired
	private StaffService staffService;
	@Autowired
	private JobTitleService jobTitleService;
	@Autowired
	private RoleService roleService;
 
	@Autowired
	private PositionService positionService;
 
	@Autowired
	private DepartmentService departmentService;
 
	@Autowired
	private OperaterLogService operaterLogService;
 
	@Autowired
	private AttendanceService attendanceService;
 
 
	
	@RequestMapping(value="/list")
	public String list(Model model, Staff staff, PageBean<Staff> pageBean){
        model.addAttribute("title", "员工列表");
		model.addAttribute("jobNumber", staff.getJobNumber()==null?"":staff.getJobNumber());
		model.addAttribute("pageBean", staffService.findList(staff, pageBean));
		return "admin/staff/list";
	}
	
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		model.addAttribute("roles", roleService.findAll());
		model.addAttribute("educationEnum",EducationEnum.values());
		model.addAttribute("jobTitleList",jobTitleService.findAll());
		model.addAttribute("positionList",positionService.findAll());
		model.addAttribute("departmentList",departmentService.findAll());
		return "admin/staff/add";
	}
	
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(Staff staff){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(staff);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(staff.getRole() == null || staff.getRole().getId() == null){
			return Result.error(CodeMsg.ADMIN_STAFF_ROLE_ERROR);
		}
		if(!StringUtil.isMobile(staff.getMobile())){
			return Result.error(CodeMsg.ADMIN_STAFF_MOBILE_ERROR);
		}
		if(!StringUtil.isMobile(staff.getEmergencyMobile())){
			return Result.error(CodeMsg.ADMIN_STAFF_EMERGENCY_MOBILE_ERROR);
		}
		//自动生成工号
        int maxId = staffService.findMaxId()+1;
        String jobNumber = DateUtil.getCurrentDateTime("yyyyMMdd");
		if(maxId<10){
            jobNumber=jobNumber+"0"+maxId;
        }else{
            jobNumber=jobNumber+maxId;
        }
        staff.setJobNumber(jobNumber);
        //到这说明一切符合条件,进行数据库新增
		if(staffService.save(staff) == null){
			return Result.error(CodeMsg.ADMIN_STAFF_ADD_ERROR);
		}
		operaterLogService.add("添加员工,员工名:" + staff.getName());
		return Result.success(true);
	}
 
	@RequestMapping(value="/edit_self",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> edit_self(Staff staff, HttpServletRequest request){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(staff);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(!StringUtil.isMobile(staff.getMobile())){
			return Result.error(CodeMsg.ADMIN_STAFF_MOBILE_ERROR);
		}
		if(!StringUtil.isMobile(staff.getEmergencyMobile())){
			return Result.error(CodeMsg.ADMIN_STAFF_EMERGENCY_MOBILE_ERROR);
		}
		if(staff.getId() == null || staff.getId().longValue() <= 0){
			return Result.error(CodeMsg.ADMIN_STAFF_NOT_EXIST_ERROR);
		}
		//到这说明一切符合条件,进行数据库保存
		Staff findById = staffService.find(staff.getId());
		//讲提交的员工信息指定字段复制到已存在的staff对象中,该方法会覆盖新字段内容
		BeanUtils.copyProperties(staff, findById, "id","createTime","updateTime","jobNumber",
				"role","educationEnum","jobTitle",
				"position","department","entryTime");
		Staff saveStaff = staffService.save(findById);
		if(saveStaff == null){
			return Result.error(CodeMsg.ADMIN_STAFF_EDIT_ERROR);
		}
		Staff loginedStaff = SessionUtil.getLoginedStaff();
		if(loginedStaff != null){
			if(loginedStaff.getId().longValue() == findById.getId().longValue()){
				loginedStaff.setHeadPic(saveStaff.getHeadPic());
				loginedStaff.setName(saveStaff.getName());
				loginedStaff.setMobile(saveStaff.getMobile());
				loginedStaff.setEmergencyContact(saveStaff.getEmergencyContact());
				loginedStaff.setEmergencyMobile(saveStaff.getEmergencyMobile());
				loginedStaff.setAge(saveStaff.getAge());
				loginedStaff.setSex(saveStaff.getSex());
				SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,loginedStaff);
			}
		}
 
		operaterLogService.add("编辑员工,员工名:" + staff.getName());
		return Result.success(true);
	}
 
	
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(Model model,@RequestParam(name="id",required=true)Long id){
		model.addAttribute("staff", staffService.find(id));
		model.addAttribute("roles", roleService.findAll());
		model.addAttribute("educationEnum",EducationEnum.values());
		model.addAttribute("jobTitleList",jobTitleService.findAll());
		model.addAttribute("positionList",positionService.findAll());
		model.addAttribute("departmentList",departmentService.findAll());
		return "admin/staff/edit";
	}
	
	
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> edit(Staff staff, HttpServletRequest request){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(staff);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
 
 
		if(staff.getRole() == null || staff.getRole().getId() == null){
			return Result.error(CodeMsg.ADMIN_STAFF_ROLE_ERROR);
		}
		if(!StringUtil.isMobile(staff.getMobile())){
			return Result.error(CodeMsg.ADMIN_STAFF_MOBILE_ERROR);
		}
		if(!StringUtil.isMobile(staff.getEmergencyMobile())){
			return Result.error(CodeMsg.ADMIN_STAFF_EMERGENCY_MOBILE_ERROR);
		}
		if(staff.getId() == null || staff.getId().longValue() <= 0){
			return Result.error(CodeMsg.ADMIN_STAFF_NOT_EXIST_ERROR);
		}
		//到这说明一切符合条件,进行数据库保存
		Staff findById = staffService.find(staff.getId());
		//讲提交的员工信息指定字段复制到已存在的staff对象中,该方法会覆盖新字段内容
		BeanUtils.copyProperties(staff, findById, "id","createTime","updateTime","jobNumber");
		Staff saveStaff = staffService.save(findById);
		if(saveStaff == null){
			return Result.error(CodeMsg.ADMIN_STAFF_EDIT_ERROR);
		}
		Staff loginedStaff = SessionUtil.getLoginedStaff();
		if(loginedStaff != null){
			if(loginedStaff.getId().longValue() == findById.getId().longValue()){
				loginedStaff.setHeadPic(saveStaff.getHeadPic());
				loginedStaff.setName(saveStaff.getName());
				loginedStaff.setMobile(saveStaff.getMobile());
				loginedStaff.setEmergencyContact(saveStaff.getEmergencyContact());
				loginedStaff.setEmergencyMobile(saveStaff.getEmergencyMobile());
				loginedStaff.setAge(saveStaff.getAge());
				loginedStaff.setSex(saveStaff.getSex());
				SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,loginedStaff);
			}
		}
 
		operaterLogService.add("编辑员工,员工名:" + staff.getName());
		return Result.success(true);
	}
	
	
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
		if(staffService.updateStatus(StaffStatus.QUIT.getCode(), id)<=0){
			return Result.error(CodeMsg.ADMIN_STAFF_STATUS_ERROR);
		}
		operaterLogService.add("员工离职,员工ID:" + id);
		return Result.success(true);
	}
 
	
	@RequestMapping("/self")
	public String self(Model model){
		Staff loginedStaff = SessionUtil.getLoginedStaff();
		Staff staff = staffService.find(loginedStaff.getId());
		model.addAttribute("roles", roleService.findAll());
		model.addAttribute("educationEnum",EducationEnum.values());
		model.addAttribute("jobTitleList",jobTitleService.findAll());
		model.addAttribute("positionList",positionService.findAll());
		model.addAttribute("departmentList",departmentService.findAll());
		model.addAttribute("staff",staff);
		return "admin/staff/self";
	}
 
}

后台角色管理控制器:


@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);
	}
}

后台工龄管理Controller:


@Controller
@RequestMapping("/admin/work_years")
public class WorkingYearsController {
 
    @Autowired
    private WorkingYearsService workingYearsService;
 
    @Autowired
    private OperaterLogService operaterLogService;
 
    
    @RequestMapping("/list")
    public String list(Model model, PageBean<WorkingYears> pageBean, WorkingYears workingYears){
        model.addAttribute("title","工龄列表");
        model.addAttribute("years",workingYears.getYears());
        model.addAttribute("pageBean",workingYearsService.findList(workingYears, pageBean));
        return "/admin/working_years/list";
    }
 
    
    @RequestMapping("/add")
    public String add(){
        return "/admin/working_years/add";
    }
 
    
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> add(WorkingYears workingYears){
        //用统一验证实体方法验证是否合法
        CodeMsg validate = ValidateEntityUtil.validate(workingYears);
        if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }
        if(workingYearsService.findByYears(workingYears.getYears())!=null){
            return Result.error(CodeMsg.ADMIN_WORKING_YEARS_EXIST_ERROR);
        }
        if(workingYearsService.save(workingYears) == null){
            return Result.error(CodeMsg.ADMIN_WORKING_YEARS_ADD_ERROR);
        }
        operaterLogService.add("添加工龄,工龄补贴为:" + workingYears.getSubsidy());
        return Result.success(true);
    }
 
    
    @RequestMapping("/edit")
    public String edit(Model model,@RequestParam(name="id",required=true)Long id){
        model.addAttribute("workYears",workingYearsService.find(id));
        return "/admin/working_years/edit";
    }
 
    
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> edit(WorkingYears workingYears){
        //用统一验证实体方法验证是否合法
        CodeMsg validate = ValidateEntityUtil.validate(workingYears);
        if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }
        if(workingYearsService.isExistYear(workingYears.getYears(),workingYears.getId())){
            return Result.error(CodeMsg.ADMIN_WORKING_YEARS_EXIST_ERROR);
        }
        //到这说明一切符合条件,进行数据库保存
        WorkingYears findById = workingYearsService.find(workingYears.getId());
        //讲提交的用户信息指定字段复制到已存在的department对象中,该方法会覆盖新字段内容
        BeanUtils.copyProperties(workingYears, findById, "id","createTime","updateTime");
        if(workingYearsService.save(findById) == null){
            return Result.error(CodeMsg.ADMIN_WORKING_YEARS_EDIT_ERROR);
        }
        operaterLogService.add("编辑工龄,工龄补贴为:" + workingYears.getSubsidy());
        return Result.success(true);
    }
 
    
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
        try{
            workingYearsService.delete(id);
        }catch (Exception e){
            return Result.error(CodeMsg.ADMIN_WORKING_YEARS_DELETE_ERROR);
        }
        operaterLogService.add("删除工龄补贴,工龄ID:" + id);
        return Result.success(true);
    }
}

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

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯