基于javaweb+mysql的springbootoa人事管理系统(java+springboot+layui+html+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBootoa人事管理系统(java+springboot+layui+html+mysql)
项目介绍:
员工管理、部门管理、职位管理、薪资管理、考勤管理、请假管理、奖惩管理、日志管理、文件下载、文件上传、图表展示
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:是;
技术栈
JSP +SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目
}
//添加部门页面跳转
@RequestMapping("/deptAdd")
public String toDeptAdd(){
return "dept/deptadd";
}
//删除部门
@PostMapping("/delete/{ids}")
@ResponseBody
public Result<Object> deleteDeptById(@PathVariable("ids") String ids)
{
departmentService.deleteDeptById(ids);
return Result.success("删除部门成功");
}
//获取单个部门信息
@GetMapping("/{id}")
public String queryDeptById(@PathVariable("id") String id,Model model){
model.addAttribute("dept",departmentService.queryById(id));
return "dept/deptedit";
}
//更新部门
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateDept(Department department)
{
System.out.println(department);
departmentService.updateDept(department);
return Result.success("修改成功");
}
}
package com.xlk.controller;
/**
* @Title: HealthController
* @Package com.xlk.controller
* @Description: HealthController
*/
@Controller
@RequestMapping("/health2")
public class HealthController2 {
@Autowired
HealthService healthService;
@Autowired
EmployeeService employeeService;
@GetMapping("")
public String toHealthListUI() {
return "health/healthList2";
}
@GetMapping("/list")
@ResponseBody
public Result<Object> getHealthList(HealthQuery param,HttpSession session) {
Employee loginUser = (Employee) session.getAttribute("loginUser");
@ResponseBody
public Result<Object> uploadImage(@RequestParam("file") MultipartFile file) {
xlkFile sqlfile=new xlkFile();
String filename = file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf("."));
String[] fileTyle = file.getOriginalFilename().split("\\.");
int suffixIndex = fileTyle.length -1;
sqlfile.setFilename(filename);
sqlfile.setFilesize(file.getSize());
sqlfile.setFilesrc(UPLOAD_FILE_PATH+"\\"+file.getOriginalFilename());
sqlfile.setFiletype(fileTyle[suffixIndex]);
System.out.println(sqlfile);
xlkFileService.addXlkFile(sqlfile);
if (!file.isEmpty()) {
Map<String, String> resObj = new HashMap<>(MAP_SIZE);
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(UPLOAD_FILE_PATH, file.getOriginalFilename())));
out.write(file.getBytes());
out.flush();
out.close();
} catch (IOException e) {
return Result.fail("上传失败");
}
return Result.success("上传成功");
} else {
return null;
}
}
}
package com.xlk.controller;
}
package com.xlk.controller;
@RequestMapping("/reward")
@Controller
public class RewardController {
@Autowired
DepartmentService departmentService;
@Autowired
RewardService rewardService;
@Autowired
EmployeeService employeeService;
@RequestMapping("")
public String toRewardUi(Model model){
model.addAttribute("deptList",departmentService.queryAll());
return "reward/rewardList";
}
@GetMapping("/list")
@ResponseBody
public Result<Object> getRewardList(RewardQuery param) {
List<Reward> list = rewardService.getRewardList(param);
@Controller
@RequestMapping("/attendance")
public class AttendanceController {
@Autowired
AttendanceService attendanceService;
@Autowired
EmployeeService employeeService;
@GetMapping("")
public String toAttendanceListUI() {
return "attendance/attendanceList";
}
@GetMapping("/list")
@ResponseBody//返回Json
public Result<Object> getAttendanceList(AttendanceQuery param) {
System.out.println(param);
List<Attendance> list = attendanceService.getAttendanceList(param);
System.out.println(list);
Long count = attendanceService.countAttendanceList(param);
return Result.success("success", list, count);
}
//添加部门页面跳转
@RequestMapping("/AttendanceAdd")
public String toAttendanceAdd(Model model) {
model.addAttribute("empList", employeeService.queryAll());
return "attendance/attendanceadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addaAttendance(Attendance attendance, String start, String end) throws ParseException {
Date starttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(start);
Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateAttendance(String id, String startDate, String starttime, String endtime, String employee_name, String status) throws ParseException {
Attendance attendance = attendanceService.queryById(Integer.valueOf(id));
Date startDate1 = new SimpleDateFormat("yyyy-MM-dd").parse(startDate);
Date starttime1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(starttime);
Date endtime1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endtime);
Long time = endtime1.getTime() - starttime1.getTime();
Double worktime = time / 1000.0 / 60.0 / 60.0;
if (worktime <= 0) {
return Result.fail("工作时长不能为0或小于0");
} else {
attendance.setStarttime(startDate1);
attendance.setEmployee_name(employee_name);
attendance.setWorktime(DoubleFX.getDoubleToString(worktime, 2));
attendance.setStarttime(starttime1);
attendance.setEndtime(endtime1);
attendance.setStatus(Integer.parseInt(status));
attendanceService.updateAttendance(attendance);
return Result.success("修改成功");
}
}
@RequestMapping("/empupdate")
@ResponseBody
public Result<Object> EmpupdateAttendance(HttpSession session) throws ParseException {
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Employee employee = (Employee) session.getAttribute("loginUser");
Attendance attendance = attendanceService.queryByEmpAndDate(employee.getName(), new java.sql.Date(new Date().getTime()));
Date date = time.parse(time.format(new Date()));
if (attendance == null) {
return Result.fail("你今日还未打卡");
} else {
Long time1 = date.getTime() - attendance.getStarttime().getTime();
Double worktime = time1 / 1000.0 / 60.0 / 60.0;
if (worktime <= 0) {
return Result.fail("工作时长不能为0或小于0");
} else {
if (attendance.getStatus() == 2) {
attendance.setStatus(1);
attendance.setWorktime(DoubleFX.getDoubleToString(worktime, 2));
attendance.setEndtime(date);
attendanceService.updateAttendance(attendance);
return Result.success("下班成功");
} else {
return Result.fail("您今日已打卡下班,如打卡有误,请联系管理员修改");
}
}
}
}
@PostMapping("/delete/{ids}")
@Controller
@RequestMapping("/empsalary")
public class SalaryController2 {
@Autowired
EmployeeService employeeService;
@Autowired
SalaryService salaryService;
@Autowired
DepartmentService departmentService;
@RequestMapping("")
public String toSalaryUi(Model model){
return "salary/salarylist2";
}
@GetMapping("/list")
@ResponseBody//返回Json
public Result<Object> getSalaryList(SalaryQuery param, HttpSession session) {
Employee loginUser = (Employee) session.getAttribute("loginUser");
param.setEmployee_name(loginUser.getName());
List<Salary> list = salaryService.getSalaryList(param);
System.out.println(list);
Long count = salaryService.countSalaryList(param);
System.out.println(count);
return Result.success("success", list, count);
}
//添加部门页面跳转
@RequestMapping("/salaryAdd")
public String toSalaryAdd(Model model) {
model.addAttribute("deptList",departmentService.queryAll());
return "salary/salaryadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addSalary(Salary salary)
{
public Object Login(User param, HttpSession session, @RequestParam("captcha") String captcha, HttpServletRequest request){
if(!CaptchaUtil.ver(captcha,request))
{
return Result.fail("验证码错误");
}
User user= userService.login(param);//通过用户名查询用户
if(user!=null)
{
BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();//新建springSecurity验证
boolean matches = passwordEncoder.matches(param.getPassword(), user.getPassword());//验证密码
if (matches) {
if(user.getStatus()==1)
{
session.setAttribute("loginUser",user);
return Result.success();
}
else
{
return Result.fail("用户已被禁止登陆");
}
}
}
return Result.fail("用户名或密码错误");
}
@RequestMapping("/loginout")
@ResponseBody
public Result<Object> loginout(HttpSession session){
session.removeAttribute("loginUser");
return Result.success("退出成功");
}
@RequestMapping("/updatePassword")
public Result<Object> updatePassword(HttpSession session,String old_password,String new_password,String again_password){
User loginUser = (User) session.getAttribute("loginUser");
//验证密码
BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();//新建springSecurity验证
boolean matches = passwordEncoder.matches(old_password, loginUser.getPassword());//验证密码
System.out.println(matches);
if(matches)
{
if(new_password.equals(again_password))
{
loginUser.setPassword(passwordEncoder.encode(new_password));
leaveService.addLeave(leave);
// Date starttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(start);
// Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
return Result.success("提交申请成功");
}
}
package com.xlk.emp.controller;
@RequestMapping("/empreward")
@Controller
public class RewardController2 {
@Autowired
DepartmentService departmentService;
@Autowired
RewardService rewardService;
@Autowired
EmployeeService employeeService;
@RequestMapping("")
public String toRewardUi(Model model){
model.addAttribute("deptList",departmentService.queryAll());
return "reward/rewardList2";
}
@GetMapping("/list")
@ResponseBody
public Result<Object> getRewardList(RewardQuery param, HttpSession session) {
Employee loginUser = (Employee) session.getAttribute("loginUser");
param.setEmployee_name(loginUser.getName());
List<Reward> list = rewardService.getRewardList(param);
Long count = rewardService.countRewardList(param);
//添加部门页面跳转
@RequestMapping("/AttendanceAdd")
public String toAttendanceAdd(Model model) {
model.addAttribute("empList", employeeService.queryAll());
return "attendance/attendanceadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addaAttendance(Attendance attendance, String start, String end) throws ParseException {
Date starttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(start);
Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
Long time = endtime.getTime() - starttime.getTime();
Double worktime = time / 1000.0 / 60.0 / 60.0;
attendance.setWorktime(DoubleFX.getDoubleToString(worktime, 2));
attendance.setStarttime(starttime);
attendance.setEndtime(endtime);
attendanceService.addAttendance(attendance);
return Result.success("考勤补录成功");
}
@RequestMapping("/empadd")
@ResponseBody
public Result<Object> EmpAddaAttendance(HttpSession session) throws ParseException {
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Employee employee = (Employee) session.getAttribute("loginUser");
boolean flag = attendanceService.queryByEmpAndDate(employee.getName(), new java.sql.Date(new Date().getTime())) == null;
if (!flag) {
return Result.fail("你今日已打过卡了");
} else {
Attendance attendance = new Attendance();
attendance.setStatus(2);
attendance.setEmployee_name(employee.getName());
attendance.setStartDate(new java.sql.Date(new Date().getTime()));
attendance.setStarttime(time.parse(time.format(new Date())));
attendanceService.addAttendance(attendance);
return Result.success(employee.getName() + "打卡成功");
}
}
@GetMapping("/{id}")
public String queryAttendanceById(@PathVariable("id") Integer id, Model model) {
model.addAttribute("empList", employeeService.queryAll());
model.addAttribute("attendance", attendanceService.queryById(id));
return "attendance/attendanceedit";
}
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateAttendance(String id, String startDate, String starttime, String endtime, String employee_name, String status) throws ParseException {
String[] a=salary.getAd_salary().split("/");
salary.setAd_salary(a[0]);
if(a[1].equals("1"))
{
salary.setEnd_salary(salary.getBase_salary()+Double.valueOf(a[0]));
}
else
{
salary.setEnd_salary(salary.getBase_salary()-Double.valueOf(a[0]));
}
}
else
{
salary.setAd_salary(String.valueOf(0));
salary.setEnd_salary(salary.getBase_salary());
}
System.out.println(salary);
salaryService.updateSalary(salary);
return Result.success("修改成功");
}
}
package com.xlk.emp.controller;
/**
* @Title: HealthController
* @Package com.xlk.controller
* @Description: HealthController
*/
@Controller
@RequestMapping("/health")
public class HealthController {
@Autowired
HealthService healthService;
@Autowired
EmployeeService employeeService;
@GetMapping("")
public String toHealthListUI() {
return "health/healthList";
public Result<Object> getAttendanceList(AttendanceQuery param,HttpSession session) {
Employee loginUser = (Employee) session.getAttribute("loginUser");
param.setEmployee_name(loginUser.getName());
List<Attendance> list = attendanceService.getAttendanceList(param);
Long count = attendanceService.countAttendanceList(param);
return Result.success("success", list, count);
}
//添加部门页面跳转
@RequestMapping("/AttendanceAdd")
public String toAttendanceAdd(Model model) {
model.addAttribute("empList", employeeService.queryAll());
return "attendance/attendanceadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addaAttendance(Attendance attendance, String start, String end) throws ParseException {
Date starttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(start);
Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
Long time = endtime.getTime() - starttime.getTime();
Double worktime = time / 1000.0 / 60.0 / 60.0;
attendance.setWorktime(DoubleFX.getDoubleToString(worktime, 2));
attendance.setStarttime(starttime);
attendance.setEndtime(endtime);
attendanceService.addAttendance(attendance);
return Result.success("考勤补录成功");
}
@RequestMapping("/empadd")
@ResponseBody
public Result<Object> EmpAddaAttendance(HttpSession session) throws ParseException {
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Employee employee = (Employee) session.getAttribute("loginUser");
boolean flag = attendanceService.queryByEmpAndDate(employee.getName(), new java.sql.Date(new Date().getTime())) == null;
if (!flag) {
return Result.fail("你今日已打过卡了");
} else {
Attendance attendance = new Attendance();
attendance.setStatus(2);
attendance.setEmployee_name(employee.getName());
attendance.setStartDate(new java.sql.Date(new Date().getTime()));
attendance.setStarttime(time.parse(time.format(new Date())));
attendanceService.addAttendance(attendance);
return Result.success(employee.getName() + "打卡成功");
Attendance attendance = new Attendance();
attendance.setStatus(2);
attendance.setEmployee_name(employee.getName());
attendance.setStartDate(new java.sql.Date(new java.util.Date().getTime()));
attendance.setStarttime(time.parse(time.format(new Date())));
attendanceService.addAttendance(attendance);
return Result.success(employee.getName() + "打卡成功");
}
}
@GetMapping("/{id}")
public String queryAttendanceById(@PathVariable("id") Integer id, Model model) {
model.addAttribute("empList", employeeService.queryAll());
model.addAttribute("attendance", attendanceService.queryById(id));
return "attendance/attendanceedit";
}
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateAttendance(String id, String startDate, String starttime, String endtime, String employee_name, String status) throws ParseException {
Attendance attendance = attendanceService.queryById(Integer.valueOf(id));
Date startDate1 = new SimpleDateFormat("yyyy-MM-dd").parse(startDate);
Date starttime1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(starttime);
Date endtime1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endtime);
Long time = endtime1.getTime() - starttime1.getTime();
Double worktime = time / 1000.0 / 60.0 / 60.0;
if (worktime <= 0) {
return Result.fail("工作时长不能为0或小于0");
} else {
attendance.setStarttime(startDate1);
attendance.setEmployee_name(employee_name);
attendance.setWorktime(DoubleFX.getDoubleToString(worktime, 2));
attendance.setStarttime(starttime1);
attendance.setEndtime(endtime1);
attendance.setStatus(Integer.parseInt(status));
attendanceService.updateAttendance(attendance);
return Result.success("修改成功");
}
}
@RequestMapping("/empupdate")
@ResponseBody
public Result<Object> EmpupdateAttendance(HttpSession session) throws ParseException {
@GetMapping("")
public String toAttendanceListUI() {
return "attendance/attendanceList";
}
@GetMapping("/list")
@ResponseBody//返回Json
public Result<Object> getAttendanceList(AttendanceQuery param) {
System.out.println(param);
List<Attendance> list = attendanceService.getAttendanceList(param);
System.out.println(list);
Long count = attendanceService.countAttendanceList(param);
return Result.success("success", list, count);
}
//添加部门页面跳转
@RequestMapping("/AttendanceAdd")
public String toAttendanceAdd(Model model) {
model.addAttribute("empList", employeeService.queryAll());
return "attendance/attendanceadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addaAttendance(Attendance attendance, String start, String end) throws ParseException {
Date starttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(start);
Date endtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(end);
Long time = endtime.getTime() - starttime.getTime();
Double worktime = time / 1000.0 / 60.0 / 60.0;
attendance.setWorktime(DoubleFX.getDoubleToString(worktime, 2));
attendance.setStarttime(starttime);
attendance.setEndtime(endtime);
attendanceService.addAttendance(attendance);
return Result.success("考勤补录成功");
}
@RequestMapping("/empadd")
@ResponseBody
public Result<Object> EmpAddaAttendance(HttpSession session) throws ParseException {
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Employee employee = (Employee) session.getAttribute("loginUser");
boolean flag = attendanceService.queryByEmpAndDate(employee.getName(), new java.sql.Date(new java.util.Date().getTime())) == null;
if (!flag) {
List<Health> list = healthService.getHealthList(param);
Long count = healthService.countHealthList(param);
return Result.success("success", list, count);
}
@PostMapping("/delete/{ids}")
@ResponseBody
public Result<Object> deleteHealth(@PathVariable("ids") String ids) {
healthService.deleteHealthById(ids);
return Result.success("删除日报成功");
}
@GetMapping("/get/{id}")
public String queryHealthById(@PathVariable("id") Integer id, Model model) {
model.addAttribute("empList", employeeService.queryAll());
model.addAttribute("health", healthService.queryById(id));
return "health/healthedit";
}
@ResponseBody
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public Map<String, Object> uploadFile(HttpServletRequest servletRequest, @RequestParam("file") MultipartFile file, HttpSession session, String emp, String date)
throws IOException {
// 如果文件内容不为空,则写入上传路径
if (!file.isEmpty()) {
// 上传文件路径
String UploadPath = FileUtil.projectRootDir + "\\src\\main\\resources\\static\\health";
//取得原文件名字
String fileName = file.getOriginalFilename();
//取得文件扩展名
String suffix = fileName.substring(fileName.lastIndexOf("."));
//提取系统时间作为新文件名
String prefix = date.replaceAll("-", "");
System.out.println(prefix);
//保存路径
// 上传文件名
String filename = emp + prefix + "jk" + UUID.randomUUID() + suffix;
File filepath = new File(UploadPath, filename);
// 判断路径是否存在,没有创建
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
// 将上传文件保存到一个目标文档中
File file1 = new File(UploadPath + File.separator + filename);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file1));
out.write(file.getBytes());
out.flush();
List<Employee> list=departmentService.getDeptList(param);
Long count=departmentService.countDeptList(param);
return Result.success("success",list,count);
}
//添加部门
@PostMapping("/add")
@ResponseBody
public Result<Object> addDept(Department department)
{
System.out.println(department);
departmentService.addDept(department);
return Result.success("添加部门成功");
}
//添加部门页面跳转
@RequestMapping("/deptAdd")
public String toDeptAdd(){
return "dept/deptadd";
}
//删除部门
@PostMapping("/delete/{ids}")
@ResponseBody
public Result<Object> deleteDeptById(@PathVariable("ids") String ids)
{
departmentService.deleteDeptById(ids);
return Result.success("删除部门成功");
}
//获取单个部门信息
@GetMapping("/{id}")
public String queryDeptById(@PathVariable("id") String id,Model model){
model.addAttribute("dept",departmentService.queryById(id));
return "dept/deptedit";
}
//更新部门
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateDept(Department department)
{
System.out.println(department);
departmentService.updateDept(department);
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public Map<String, Object> uploadFile(HttpServletRequest servletRequest, @RequestParam("file") MultipartFile file, HttpSession session, String emp, String date)
throws IOException {
// 如果文件内容不为空,则写入上传路径
if (!file.isEmpty()) {
// 上传文件路径
String UploadPath = FileUtil.projectRootDir + "\\src\\main\\resources\\static\\health";
//取得原文件名字
String fileName = file.getOriginalFilename();
//取得文件扩展名
String suffix = fileName.substring(fileName.lastIndexOf("."));
//提取系统时间作为新文件名
String prefix = date.replaceAll("-", "");
System.out.println(prefix);
//保存路径
// 上传文件名
String filename = emp + prefix + "jk" + UUID.randomUUID() + suffix;
File filepath = new File(UploadPath, filename);
// 判断路径是否存在,没有创建
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
// 将上传文件保存到一个目标文档中
File file1 = new File(UploadPath + File.separator + filename);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file1));
out.write(file.getBytes());
out.flush();
out.close();
// file.transferTo(file1);
Map<String, Object> res = new HashMap<>();
// 返回的是一个url对象,图片名称
res.put("url", filename);
return res;
} else {
return null;
}
}
@ResponseBody
@RequestMapping(value = "/uploadFile2", method = RequestMethod.POST)