Java project: employee attendance management system (java+ssm+jsp+bootstrap+mysql)

pastclouds 2022-06-23 14:46:39 阅读数:242

javaprojectemployeeattendancemanagement

The source code for : My blog home page " resources " Download !

Project introduction


This project includes administrators 、 division manager 、 Three roles of employees ;

The Department Manager role includes the following functions :
Personal information management , Leave information approval , Department attendance record , Attendance system management and other functions .

The administrator role includes the following functions :
Administrator login , Employee management , Leave statistics and other functions .

Employee roles include the following functions :
Employee login , Staff sign in , Attendance records , Ask for leave , Leave record query and other functions .

Environmental needs

1. Running environment : It is best to java jdk 1.8, We run on this platform . Other versions can, in theory .
2.IDE Environmental Science :IDEA,Eclipse,Myeclipse Fine . recommend IDEA;
3.tomcat Environmental Science :Tomcat 7.x,8.x,9.x All versions are available
4. Hardware environment :windows 7/8/10 1G Above memory ; perhaps Mac OS; 
5. database :MySql 5.7 edition ;
6. whether Maven project : yes ;


Technology stack

1. Back end :Spring+SpringMVC+Mybatis
2. front end :JSP+CSS+JavaScript+jquery+bootstrap


Instructions

1. Use Navicat Or other tools , stay mysql Create a database with the corresponding name in , And import the sql file ;
2. Use IDEA/Eclipse/MyEclipse Import the project ,Eclipse/MyEclipse Import time , if maven Item, please select maven;
if maven project , After importing successfully, please execute maven clean;maven install command , And then run ;
3. In the project mysql.properties Change the database configuration in the configuration file to your own configuration ;
4. Run the project , Input localhost:8080/ Sign in

 

 

 

 

 

 

Administrator management control layer : 

@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource(name = "staffCustomServiceImpl")
private StaffCustomService staffCustomService;
@Resource(name = "departmentServiceImpl")
private DepartmentService departmentService;
@Resource(name = "loginServiceImpl")
private LoginService loginService;
@Resource(name = "adminServiceImpl")
private AdminService adminService;
// Employee information display
@RequestMapping("/showStaff")
public String showStudent(Model model, Integer page) throws Exception {
List<StaffCustom> list = null;
// Page number object
PagingVO pagingVO = new PagingVO();
// Set the total number of pages
pagingVO.setTotalCount(staffCustomService.getStaffCount());
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
list = staffCustomService.findByPaging(1);
} else {
pagingVO.setToPageNo(page);
list = staffCustomService.findByPaging(page);
}
model.addAttribute("staffList", list);
model.addAttribute("pagingVO", pagingVO);
return "/admin/showStaff";
}
// Show employee details
@RequestMapping("/showStaffDetail")
public String showStaffDetail(String staffId, Model model) throws Exception{
StaffCustom staffDetail = staffCustomService.findById(staffId);
model.addAttribute("staffDetail", staffDetail);
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
return "/admin/showStaffDetail";
}
// The add employee information page displays
@RequestMapping(value = "/addStaff", method = {RequestMethod.GET})
public String addStudentUI(Model model) throws Exception {
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
return "/admin/addStaff";
}
// Add employee information
@RequestMapping(value = "/addStaff", method = {RequestMethod.POST})
public String addStudent(StaffCustom staffCustom, Model model) throws Exception {
/*System.out.println(staffCustom.getRole());*/
Boolean result = staffCustomService.save(staffCustom);
if (!result) {
model.addAttribute("message", " Duplicate employee number ");
return "/error";
}
// After successful addition , Also added to the login table
// Redirect
return "redirect:/admin/showStaff";
}
// Modify employee information processing
@RequestMapping(value = "/editStaff", method = {RequestMethod.POST})
@ResponseBody
public boolean editStaff(int role,int department,String staffId) throws Exception {
Map<String,Object> paramMap = new HashMap<String, Object>();
paramMap.put("staffId",staffId);
paramMap.put("department",department);
paramMap.put("role",role);
staffCustomService.editStaff(paramMap);
return true;
}
// Delete employee
@RequestMapping(value = "/removeStaff"/*, method = {RequestMethod.GET} */)
public String removeStaff(String id) throws Exception {
if (id == null) {
// Join without employees id If you come in, you will return to the employee display page
return "/admin/showStaff";
}
staffCustomService.removeById(id);
loginService.removeById(id);
return "redirect:/admin/showStaff";
}
// Search employees
@RequestMapping(value = "/selectStaff")
public String selectStaff(String findByName, Model model) throws Exception {
List<StaffCustom> list = staffCustomService.findByName(findByName);
model.addAttribute("staffList", list);
return "/admin/showStaff";
}
// The attendance record statistics query page displays
@RequestMapping(value = "/showSign")
public String showSign() throws Exception {
return "/admin/showSign";
}
// Attendance record statistics query
@RequestMapping(value = "/loadReportInfoData")
public String loadReportInfoData(Model model,ReportInfo reportInfo) throws Exception {
List<ReportInfo> reportInfoList = new ArrayList<ReportInfo>();
try {
reportInfoList = adminService.loadReportInfoData(reportInfo);
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("reportInfoList", reportInfoList);
return "/admin/showSign";
}
// Attendance record details are displayed
@RequestMapping(value = "/loadReportDetailData")
public void loadReportDetailData(PrintWriter printWriter,String reportId, Model model) throws Exception {
List<ReportDetail> reportDetailList = new ArrayList<ReportDetail>();
try {
reportDetailList = adminService.loadReportDetailData(reportId);
} catch (Exception e) {
e.printStackTrace();
}
/*model.addAttribute("reportDetailList", reportDetailList);*/
/*System.out.println(reportDetailList.size());*/
String resultJson = JSON.toJSONString(reportDetailList);
printWriter.write(resultJson);
printWriter.flush();
printWriter.close();
}
// The leave record query page displays
@RequestMapping(value = "/showLeave")
public String showLeave() throws Exception {
return "/admin/showLeave";
}
// The leave record query page displays
@RequestMapping(value = "/showLeaveRecord")
@ResponseBody
public Map<String, Object> showLeaveRecord(String searchText) throws Exception {
List<Leave> leaveList = new ArrayList<Leave>();
List<Leave> returnLeaves = new ArrayList<Leave>();
try {
leaveList = adminService.loadLeaveList();
} catch (Exception e) {
e.printStackTrace();
}
for(Leave leave:leaveList) {
if(String.valueOf(leave.getStaffId()).contains(searchText)) {
returnLeaves.add(leave);
}
}
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
JSONArray jarray = JSONArray.fromObject(returnLeaves,jsonConfig);
for (int i = 0; i < jarray.size(); i++) {
JSONObject json=new JSONObject();
json=jarray.getJSONObject(i);
if(json.get("handleTime")==null||!"".equals(json.get("handleTime"))){// Because only this value can be... When adding NULL So I judged this .
json.put("handleTime", "--");
jarray.set(i,json);
}
}
Map<String, Object> map = new HashMap<String, Object>();
if(returnLeaves != null) {
map.put("total", jarray.size());
map.put("rows", jarray);
}
/*String resultJson = JSON.toJSONString(leaveList);
System.out.println(resultJson);*/
return map;
}
// The password of this account is reset
@RequestMapping("/passwordReset")
public String passwordRestUI() throws Exception {
return "/admin/passwordReset";
}
}

Login management control layer :

@Controller
public class LoginController {
// Login jump
@RequestMapping(value = "/login", method = {RequestMethod.GET})
public String loginUI() throws Exception {
return "/login";
}
@RequestMapping(value="/logout",method = {RequestMethod.GET})
public String logout() throws Exception{
return "/login";
}
// Login form processing
@RequestMapping(value = "/login", method = {RequestMethod.POST})
public String login(Model model,Staff staff) throws Exception {
//Shiro To realize the login
UsernamePasswordToken token = new UsernamePasswordToken(staff.getStaffId(),
staff.getPassword());
Subject subject = SecurityUtils.getSubject();
// If the user name cannot be obtained, the login fails , But if the login fails , Will throw an exception directly
subject.login(token);
if (subject.hasRole("admin")) {
return "redirect:/admin/showStaff";
} else if (subject.hasRole("manager")) {
return "redirect:/managers/showMassage";
} else if (subject.hasRole("staff")) {
return "redirect:/staff/sign";
}
return "/login";
}
}

Employee management control : 

@Controller
@RequestMapping(value = "/staff")
public class StaffController {
@Resource(name = "staffServiceImpl")
private StaffService staffService;
@Resource(name = "signServiceImpl")
private SignService signService;
@Resource(name = "leaveServiceImpl")
private LeaveService leaveService;
@Resource(name = "departmentServiceImpl")
private DepartmentService departmentService;
// Check in and check out
@RequestMapping(value="/sign")
public String staffSign() throws Exception {
return "/staff/sign";
}
// Sign in
@RequestMapping(value="/signIn")
public void staffSignIn(HttpServletResponse response) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
Staff staff = staffService.findById(id);
// Get the current time
Date sign_in_time = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("HH:mm:ss");
String time=dateFormat.format(sign_in_time);
Sign signIn= new Sign();
signIn.setStaffId(id);
signIn.setDepartmentId(staff.getDepartmentId());
signIn.setSignInTime(sign_in_time);
// Judge whether the current day has been signed in
int isSignIn = signService.isSignIn(signIn);
if (isSignIn !=0){
response.getWriter().println(" Signed in today !");
}
else {
// Judge the check-in time status ,8:00 Before 0- normal , after 1- late
Date beginTime = dateFormat.parse("09:00:00");
Calendar date = Calendar.getInstance();
date.setTime(dateFormat.parse(time));
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
if (date.after(begin)) {
signIn.setSignInState("1");
} else
signIn.setSignInState("0");
// Sign in record insert table sign_record
signService.signIn(signIn);
// The check-in time is returned to the front page
response.getWriter().println(time);
}
}
// Sign off
@RequestMapping(value="/signOut")
public void staffSignOut(HttpServletResponse response) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
Staff staff = staffService.findById(id);
// Get the current time
Date sign_out_time = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("HH:mm:ss");
String time=dateFormat.format(sign_out_time);
Sign signOut= new Sign();
signOut.setStaffId(id);
signOut.setDepartmentId(staff.getDepartmentId());
signOut.setSignOutTime(sign_out_time);
// Judge whether the current day has been signed in
int isSignIn = signService.isSignIn(signOut);
if(isSignIn == 0){
response.getWriter().println(" I haven't signed in today , Please sign in first ");
}else {
// Judge the check-in time status ,18:00 after 0- normal , Before 1- late
Date endTime = dateFormat.parse("18:00:00");
Calendar date = Calendar.getInstance();
date.setTime(dateFormat.parse(time));
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.before(end)) {
signOut.setSignOutState("1");
} else signOut.setSignOutState("0");
// Update the sign out record to the existing sign in record
signService.signOut(signOut);
// Return to the front page
response.getWriter().println(" Sign out succeeded \n"+" Sign out time :"+time);
}
}
// Display personal information
@RequestMapping(value="/showMassage", method = {RequestMethod.GET})
public String staffMassageShow(Model model) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
// adopt id Get employee information
Staff staff = staffService.findById(id);
if (staff == null) {
throw new CustomException(" Employee information not found ");
}
List<Department> list = departmentService.finAll();
model.addAttribute("departmentList", list);
model.addAttribute("staff", staff);
return "/staff/showMassage";
}
// Update personal information
@RequestMapping(value="/showMassage", method = {RequestMethod.POST})
public String staffMassageUpdate(String tel,String email,String hobby) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("id",id);
paramMap.put("tel",tel);
paramMap.put("email",email);
paramMap.put("hobby",hobby);
staffService.updateMassage(paramMap);
return "redirect:/staff/showMassage";
}
// Query attendance records
@RequestMapping(value = "/signRecord")
public String signRecordShow(Model model, Integer page) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
List<Sign> list = null;
// Page number object
PagingVO pagingVO = new PagingVO();
// Set the total number of pages
pagingVO.setTotalCount(signService.getCountSign(id));
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
// By page and user id Query attendance records
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("toPageNo", pagingVO.getTopageNo());
paramMap.put("pageSize", pagingVO.getPageSize());
paramMap.put("id", id);
list = signService.findByPaging(paramMap);
} else {
pagingVO.setToPageNo(page);
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("toPageNo", pagingVO.getTopageNo());
paramMap.put("pageSize", pagingVO.getPageSize());
paramMap.put("id", id);
list = signService.findByPaging(paramMap);
}
model.addAttribute("signList", list);
model.addAttribute("pagingVO", pagingVO);
return "/staff/signRecord";
}
// Application for leave
@RequestMapping(value="/leave")
public String leave() throws Exception {
return "/staff/leave";
}
@RequestMapping(value="/handinLeave")
public String handinLeave(String leavetime,String reason) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
Staff staff = staffService.findById(id);
// Write the leave application to the database
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("leavetime", leavetime);
paramMap.put("reason", reason);
paramMap.put("id", id);
paramMap.put("departmentId",staff.getDepartmentId());
/*System.out.println(reason);*/
leaveService.handinLeave(paramMap);
return "redirect:/staff/leaveRecord";
}
// Query leave records and status
@RequestMapping(value = "/leaveRecord")
public String leaveRecordShow(Model model, Integer page) throws Exception {
// Get the current user id
Subject subject = SecurityUtils.getSubject();
String id = (String) subject.getPrincipal();
List<Leave> list = null;
// Page number object
PagingVO pagingVO = new PagingVO();
// Set the total number of pages
pagingVO.setTotalCount(leaveService.getCountLeave(id));
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
// By page and user id Query leave records
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("toPageNo", pagingVO.getTopageNo());
paramMap.put("pageSize", pagingVO.getPageSize());
paramMap.put("id", id);
list = leaveService.findByPaging(paramMap);
} else {
pagingVO.setToPageNo(page);
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("toPageNo", pagingVO.getTopageNo());
paramMap.put("pageSize", pagingVO.getPageSize());
paramMap.put("id", id);
list = leaveService.findByPaging(paramMap);
}
model.addAttribute("leaveList", list);
model.addAttribute("pagingVO", pagingVO);
return "/staff/leaveRecord";
}
// Show leave application details
@RequestMapping(value = "/leaveDetail")
public String gradeCourse(Integer recordId, Model model) throws Exception {
if (recordId == null) {
return "";
}
Leave leaveDetail= leaveService.findByRecordId(recordId);
model.addAttribute("leaveDetail", leaveDetail);
return "/staff/showLeaveDetail";
}
// Change Password
@RequestMapping(value = "/passwordReset")
public String passwordRest() throws Exception {
return "/staff/passwordReset";
}
}

The source code for : My blog home page " resources " Download !

版权声明:本文为[pastclouds]所创,转载请带上原文链接,感谢。 https://qdmana.com/2022/174/202206231350448220.html