基于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. 运行项目
{
for (xlkFile file : files) {
File filedelete=new File(file.getFilesrc());
if(filedelete.exists()&&filedelete.isFile())
{
// filedelete.delete();
xlkFileService.deleteFileById(ids);
}
}
return Result.success("删除文件成功");
}
else
{
return Result.fail("未查询到文件数据,请刷新重试");
}
}
@RequestMapping(value="/down", produces = {"application/text;charset=UTF-8"})
@ResponseBody
public Result<Object> down(HttpServletResponse response, String id){
try {
System.out.println(id);
//根据文件id查询文件路径
String filePath = xlkFileService.queryFileById(id).getFilesrc();
//根据文件路径下载文件信息
FileUtil.down(response, filePath);
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
return Result.success("下载成功");
} catch (IOException e) {
e.printStackTrace();
}
return Result.fail("下载失败");
}
}
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);
return Result.success("success", list, count);
}
@RequestMapping("/rewardAdd")
public String toRewardAdd(Model model){
model.addAttribute("deptList",departmentService.queryAll());
return "reward/rewardadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addReward(Reward reward)
{
reward.setDepartment_name(departmentService.queryById(reward.getDepartment_name()).getName());
reward.setEmployee_name(employeeService.queryEmpById(Integer.valueOf(reward.getEmployee_name())).getName());
rewardService.addReward(reward);
return Result.success("添加奖惩成功");
}
//获取单个员工信息
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 + "xc" + 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;
}
}
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateHealth(String id, String employee_name, String temperature, String pic,String pic2) throws ParseException {
Health health = healthService.queryById(Integer.valueOf(id));
if (health.getEmployee_name().equals(employee_name)) {
health.setTemperature(Double.valueOf(temperature));
health.setImage("image\\" + pic);
health.setImage2("image\\" + pic2);
healthService.updateHealth(health);
public Result queryLogList(LogExample logExample) {
LogExample.Criteria criteria = logExample.createCriteria();
criteria.andCreatedByIsNotNull();
List<Log> logsList = logService.queryLogList(logExample);
return Result.success(LOG_QUERY_SUCCESS, logsList);
}
/**
* @param msg
* @return ApiResult
* @throws UnknownHostException 插入日志 insertLog
*/
@RequestMapping("/add")
@ResponseBody
public Result insertLog(Employee employee, String msg) throws UnknownHostException {
Log log = new Log();
InetAddress addr = InetAddress.getLocalHost();
log.setLoginIp(addr.getHostAddress());
log.setLoginName(employee.getUsername());
log.setLoginMsg(msg);
log.setCreatedBy(Long.valueOf(1));
log.setCreatedDate(new java.sql.Date(new java.util.Date().getTime()));
log.setOwner("zcx");
logService.insertLog(log);
return Result.success(LOG_INSERT_SUCCESS);
}
/**
* 删除日志 deleteLogById
* @param ids
* @return ApiResult
*/
@RequestMapping("/delete/{ids}")
@ResponseBody
public Result deleteLogById(@PathVariable("ids") String ids) {
logService.deleteLogById(ids);
return Result.success(LOG_DELETE_SUCCESS);
}
}
return "level/leveladd";
}
//删除部门
@PostMapping("/delete/{ids}")
@ResponseBody
public Result<Object> deleteLevelById(@PathVariable("ids") String ids)
{
levelService.deleteLevelById(ids);
return Result.success("删除职位成功");
}
//获取单个职位信息
@GetMapping("/{id}")
public String queryLevelById(@PathVariable("id") String id, Model model){
model.addAttribute("level",levelService.queryById(id));
model.addAttribute("deptList",departmentService.queryAll());
return "level/leveledit";
}
//更新职位
@RequestMapping("/update")
@ResponseBody
public Result<Object> updateLevel(Level level)
{
System.out.println(level);
levelService.updateLevel(level);
return Result.success("修改成功");
}
@RequestMapping("/queryLevelByDept")
@ResponseBody
public List<Level> queryLevelByDept(String department_name){
Department department = departmentService.queryById(department_name);
List<Level> levels = levelService.queryLevelByDept(department.getName());
return levels;
}
}
return null;
}
}
@ResponseBody
@RequestMapping(value = "/uploadFile2", method = RequestMethod.POST)
public Map<String, Object> uploadFile2(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 + "xc" + 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;
@Controller
@RequestMapping("/emp")
public class EmpController {
@Autowired
private EmployeeService employeeService;
@Autowired
DepartmentService departmentService;
@Autowired
LevelService levelService;
//员工UI显示
@GetMapping("")
public String toEmpListUI(){
return "emp/emptable";
}
//添加员工页面跳转
@RequestMapping("/empAdd")
public String toEmpAdd(Model model){
List<Department> deptList=departmentService.queryAll();
List<Level> levelList=levelService.queryAll();
model.addAttribute("levelList",levelList);
model.addAttribute("deptList",deptList);
return "emp/empadd";
}
//查询员工
@GetMapping("/list")
@ResponseBody//返回Json
public Result<Object> getEmpList(EmpQuery param){
List<Employee> list=employeeService.getEmpList(param);
}
}
@Controller
@RequestMapping("/emp")
public class EmpController {
@Autowired
private EmployeeService employeeService;
@Autowired
DepartmentService departmentService;
@Autowired
LevelService levelService;
//员工UI显示
@GetMapping("")
public String toEmpListUI(){
return "emp/emptable";
}
//添加员工页面跳转
@RequestMapping("/empAdd")
public String toEmpAdd(Model model){
List<Department> deptList=departmentService.queryAll();
List<Level> levelList=levelService.queryAll();
model.addAttribute("levelList",levelList);
model.addAttribute("deptList",deptList);
return "emp/empadd";
}
//查询员工
@GetMapping("/list")
@ResponseBody//返回Json
leave.setSubtime(date);
System.out.println(leave);
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("提交申请成功");
}
}
@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);
Map<String, Object> res = new HashMap<>();
// 返回的是一个url对象,图片名称
res.put("url", filename);
return res;
} else {
return null;
}
}
@ResponseBody
@RequestMapping(value = "/uploadFile2", method = RequestMethod.POST)
public Map<String, Object> uploadFile2(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 + "xc" + 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);
@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);
return Result.success("success", list, count);
}
@RequestMapping("/rewardAdd")
public String toRewardAdd(Model model){
model.addAttribute("deptList",departmentService.queryAll());
return "reward/rewardadd";
}
@PostMapping("/add")
@ResponseBody
public Result<Object> addReward(Reward reward)
{
reward.setDepartment_name(departmentService.queryById(reward.getDepartment_name()).getName());
reward.setEmployee_name(employeeService.queryEmpById(Integer.valueOf(reward.getEmployee_name())).getName());
rewardService.addReward(reward);
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;
}
}
}
return "health/healthadd";
}
}
@Controller
@RequestMapping("/empattendance")
public class AttendanceController2 {
@Autowired
AttendanceService attendanceService;
@Autowired
EmployeeService employeeService;
@GetMapping("")
public String toAttendanceListUI() {
return "attendance/attendanceList2";
}
@GetMapping("/list")
@ResponseBody//返回Json
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")
return Result.fail("下载失败");
}
}
/**
* 日志控制层
*/
@Controller
@RequestMapping("/log")
public class LogController {
//常量定义
private static final String LOG_QUERY_SUCCESS = "查询完毕";
private static final String LOG_INSERT_SUCCESS = "插入成功";
private static final String LOG_DELETE_SUCCESS = "删除成功";
@Autowired
LogService logService;
@RequestMapping("")
public String toLogUi(){
return "log/loglist";
}
/**
* queryLogList 查询所有日志信息
* @param logExample
* @return
*/
@RequestMapping("/list")
@ResponseBody
}
return Result.success("删除文件成功");
}
else
{
return Result.fail("未查询到文件数据,请刷新重试");
}
}
@RequestMapping(value="/down", produces = {"application/text;charset=UTF-8"})
@ResponseBody
public Result<Object> down(HttpServletResponse response, String id){
try {
System.out.println(id);
//根据文件id查询文件路径
String filePath = xlkFileService.queryFileById(id).getFilesrc();
//根据文件路径下载文件信息
FileUtil.down(response, filePath);
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
return Result.success("下载成功");
} catch (IOException e) {
e.printStackTrace();
}
return Result.fail("下载失败");
}
}
/**
* 日志控制层
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));
userService.updatePassword(loginUser);
return Result.success("修改密码成功");
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));
userService.updatePassword(loginUser);
return Result.success("修改密码成功");
}
else
{
return Result.fail("二次重复密码不一致");
}
}
return Result.success("老密码错误");
}
}
@Controller
@RequestMapping("/level")
public class LevelController {
@Autowired
LevelService levelService;
@Autowired
DepartmentService departmentService;
@GetMapping("")
public String toLevelListUI(Model model){
model.addAttribute("deptList",departmentService.queryAll());
return "level/levelList";
}