126springboot人事管理系統(tǒng)java web員工信息管理系統(tǒng)
人事管理系統(tǒng),屬于ERP的一個部分。它單指匯集成功企業(yè)先進(jìn)的人力資源管理理念、人力資源管理實踐、人力資源信息化系統(tǒng)建設(shè)的經(jīng)驗,以信息技術(shù)實現(xiàn)對企業(yè)人力資源信息的高度集成化管理,為中國企業(yè)使用的人力資源管理解決方案。核心價值在于將人力資源工作者從繁重的日常瑣碎事務(wù)中解放出來,將更多的精力用于企業(yè)的人力資源職能管理和管理決策,保持企業(yè)的持續(xù)高效運(yùn)營。 集中記錄、監(jiān)測和分析所有勞動力的技能和資格,提供決策分析。提高企業(yè)整體的科技含量與管理效率,加快企業(yè)的信息化建設(shè)。
?開發(fā)工具:idea?
?數(shù)據(jù)庫mysql5.7+(mysql5.7最佳)
?數(shù)據(jù)庫鏈接工具:navcat,小海豚等
開發(fā)技術(shù): springboot ?html
?
package cn.zdxh.personnelmanage.controller;
import cn.zdxh.personnelmanage.enums.ResultEnum;
import cn.zdxh.personnelmanage.exception.MyException;
import cn.zdxh.personnelmanage.po.BirthdayRecord;
import cn.zdxh.personnelmanage.po.CertificatesInfo;
import cn.zdxh.personnelmanage.po.Contraceptive;
import cn.zdxh.personnelmanage.po.EmployeeInfo;
import cn.zdxh.personnelmanage.service.CertificatesInfoService;
import cn.zdxh.personnelmanage.service.EmployeeInfoService;
import cn.zdxh.personnelmanage.utils.*;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* <p>
* 證件情況表 前端控制器
* </p>
*
* @author Justin
* @since 2019-03-15
*/
@Controller
@RequestMapping("/CertificatesInfo")
public class CertificatesInfoController {
@Autowired
private CertificatesInfoService certificatesInfoService;
@Autowired
private EmployeeInfoService employeeInfoService;
@GetMapping("/list")
public String findCertificates(@RequestParam(value = "currentPage", defaultValue = "0") Integer currentPage, @RequestParam(value = "limit", defaultValue = "3") Integer limit, Map<String, Object> map){
List<CertificatesInfo> list = certificatesInfoService.findCertificatesInfoAll(currentPage, limit);
System.out.println(list);
Integer addCount = certificatesInfoService.findCertificatesInfoAllCount();
map.put("list", list);
map.put("currentPage", currentPage);
map.put("totalPage", limit);
map.put("operation", "health_certificate_model");
map.put("URL", "/CertificatesInfo");
return "employee/employee_list";
}
@GetMapping("/create")
public String goCertificationCreate(Map<String, Object> map, ContraceptiveUtils contraceptiveUtils){
List<EmployeeInfo> list = employeeInfoService.selectList(null);
List<Contraceptive> list1 = contraceptiveUtils.contraceptives();
map.put("type", "create");
map.put("employees", list);
map.put("contraceptive", list1);
map.put("operation", "health_certificate_model");
map.put("req_url", "/CertificatesInfo/add");
return "employee/employee_create";
}
@GetMapping("/add")
public String addCertification(CertificatesInfo certificatesInfo, Map<String, Object> map){
if (certificatesInfo != null){
System.out.println("certificatesInfo:"+certificatesInfo);
certificatesInfoService.insertCertificatesInfo(certificatesInfo);
}
map.put("operat", "success");
return "result/success";
}
@GetMapping("/update/{id}")
public String goCertificationUpda(@PathVariable("id") Integer id, Map<String, Object> map, ContraceptiveUtils contraceptiveUtils){
CertificatesInfo certificatesInfo = certificatesInfoService.findCertificatesInfo(id);
List<EmployeeInfo> list = employeeInfoService.selectList(null);
List<Contraceptive> list1 = contraceptiveUtils.contraceptives();
map.put("type", "update");
map.put("operation", "health_certificate_model");
map.put("req_url", "/CertificatesInfo/update");
map.put("employees", list);
map.put("contraceptive", list1);
map.put("certificatesInfo", certificatesInfo);
return "employee/employee_create";
}
@PostMapping("/update")
public String updateCertification(CertificatesInfo certificatesInfo, Map<String, Object> map){
CertificatesInfo certificatesInfo1 = certificatesInfoService.findCertificatesInfo(certificatesInfo.getCerId());
if (certificatesInfo1 != null){
certificatesInfoService.updateCertificatesInfo(certificatesInfo);
}
map.put("operat", "success");
return "result/success";
}
@DeleteMapping("/delete/{id}")
public String deleteCertification(@PathVariable("id") Integer id, Map<String, Object> map){
CertificatesInfo certificatesInfo = certificatesInfoService.findCertificatesInfo(id);
if (certificatesInfo != null){
certificatesInfoService.deleteCertificatesInfo(id);
}
map.put("operat", "success");
return "result/success";
}
@DeleteMapping("/batchDelete")
public String batchDeleteBirth(@RequestParam("data_id") String data_id, Map<String, Object> map){
String[] id = data_id.split(",");
for (int i = 0; i < id.length; i++){
CertificatesInfo certificatesInfo = certificatesInfoService.findCertificatesInfo(Integer.parseInt(id[i]));
if (certificatesInfo != null){
certificatesInfoService.deleteCertificatesInfo(Integer.parseInt(id[i]));
}
}
return "result/success";
}
@PostMapping("/search")
public String searchBirthRecord(@RequestParam("data") String data, Map<String, Object> map){
List<CertificatesInfo> list = certificatesInfoService.findAllCertificatesInfoBySearch(data);
map.put("list", list);
map.put("operation", "health_certificate_model");
return "employee/employee_list";
}
/**
* 功能需求:完成客戶端的Excel表數(shù)據(jù)寫入數(shù)據(jù)庫功能
*
* @param file //用戶上傳的Excel文件
* @param uploadUtils //上傳文件的工具類 cn.zdxh.personnelmanage.utils.UploadUtils
* @return
* @throws Exception
*/
@PostMapping("/updateExcel")
@ResponseBody
public JSONObject updateExcel(@RequestParam("file") MultipartFile file, UploadUtils uploadUtils) throws Exception {
JSONObject json = new JSONObject();
try {
//第一個參數(shù)為Excel表,第二個參數(shù)為從第幾行讀取Excel的內(nèi)容,返回值為一個字符串?dāng)?shù)組集合(每一個數(shù)組代表Excel表的一行數(shù)據(jù))
List<String[]> list = uploadUtils.updateExcelUtils(file, 1);
//遍歷字符串?dāng)?shù)組集合中的數(shù)據(jù)
for (String[] str:list){
//獲取實體類對象封裝數(shù)據(jù)(每一個實體類對象封裝Excel表中的一行數(shù)據(jù))
CertificatesInfo certificatesInfo = new CertificatesInfo();
//一個工具類,把字符串?dāng)?shù)組數(shù)據(jù)封裝到實體類對象中,第一個參數(shù)為實體類對象,第二個參數(shù)為字符串?dāng)?shù)組
ExcelValuesHelperUtils.setAttributeValue(certificatesInfo, str);
/**
* 在完成Excel表中數(shù)據(jù)寫入數(shù)據(jù)庫操作之前先判斷
* 該實體類對象的是否為數(shù)據(jù)庫已有(進(jìn)行更新操作)
* 該實體類對象的數(shù)據(jù)為數(shù)據(jù)庫沒有(進(jìn)行插入操作)
*/
if (certificatesInfoService.findCertificatesInfo(Integer.parseInt(str[0])) != null){
certificatesInfoService.updateCertificatesInfo(certificatesInfo);
} else {
certificatesInfoService.insertCertificatesInfo(certificatesInfo);
}
}
} catch (Exception e){
/**
* 做一個報錯檢測
*/
throw new MyException(ResultEnum.UPDATE_EXCEL_ERROR.getCode(), ResultEnum.UPDATE_EXCEL_ERROR.getMsg());
}
//返回客戶端的數(shù)據(jù)
json.put("code", 1);
json.put("data", "Excel表上傳成功!");
json.put("ret", true);
return json;
}
/**
* 需求功能:完成服務(wù)器端把數(shù)據(jù)庫中的數(shù)據(jù)讀出客戶端功能
*
* @param response //把生成的Excel表響應(yīng)到客戶端
* @throws NoSuchMethodException //報錯
* @throws IllegalAccessException //報錯
* @throws InvocationTargetException //報錯
* @throws InstantiationException //報錯
*/
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
//先把數(shù)據(jù)庫中的數(shù)據(jù)查詢出來
List<CertificatesInfo> list1 = certificatesInfoService.selectList(null);
//一個設(shè)置Excel表標(biāo)題信息的工具類,獲取Excel表標(biāo)題的字符串?dāng)?shù)組
String[] strings = ExcelTitlesHelperUtils.getCertificatesInfoTitles();
//一個能把對象集合轉(zhuǎn)換成字符串?dāng)?shù)組集合的工具類,參數(shù)為對象集合,返回字符串?dāng)?shù)組集合
List<Object[]> list = ExcelValuesHelperUtils.exportExcel(list1);
try {
//一個能創(chuàng)建Excel表并完成發(fā)送客戶端的工具類,第一個參數(shù)為字符串?dāng)?shù)組集合(Excel表內(nèi)容),第二個參數(shù)為字符串?dāng)?shù)組(Excel表標(biāo)題),第三個參數(shù)為響應(yīng)器
ExportExcelUtils.createExcelUtils(list, strings, response);
} catch (Exception e){
//導(dǎo)表發(fā)生異常的時候
throw new MyException(ResultEnum.EXPORT_EXCEL_ERROR.getCode(),ResultEnum.EXPORT_EXCEL_ERROR.getMsg());
}
}
}
package cn.zdxh.personnelmanage.controller;
import cn.zdxh.personnelmanage.enums.ResultEnum;
import cn.zdxh.personnelmanage.exception.MyException;
import cn.zdxh.personnelmanage.form.EmployeeForm;
import cn.zdxh.personnelmanage.po.EmployeeCard;
import cn.zdxh.personnelmanage.po.EmployeeInfo;
import cn.zdxh.personnelmanage.service.EmployeeInfoService;
import cn.zdxh.personnelmanage.utils.ExcelTitlesHelperUtils;
import cn.zdxh.personnelmanage.utils.ExcelValuesHelperUtils;
import cn.zdxh.personnelmanage.utils.ExportExcelUtils;
import cn.zdxh.personnelmanage.utils.UploadUtils;
import net.sf.json.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
import org.thymeleaf.util.StringUtils;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 員工信息表 前端控制器
* </p>
*
* @author Justin
* @since 2019-03-15
*/
@Controller
@RequestMapping("/employee")
public class EmployeeInfoController {
@Autowired
private EmployeeInfoService employeeInfoService;
/**
* 查詢所有的員工(默認(rèn)0到10個)
* @GetMapping 表示的是get請求
* @ResponseBody 返回的是json的格式(分頁時的ajax數(shù)據(jù)請求)
* @param currentPage 當(dāng)前頁
* @param limit 每頁顯示多少個
* @return
*/
@GetMapping("/emps")
public String employees(@RequestParam(value = "currentPage",defaultValue = "0") String currentPage, @RequestParam(value = "limit",defaultValue = "2") String limit,Map<String,Object> map){
//向數(shù)據(jù)庫查詢值
List<EmployeeInfo> allEmployees = employeeInfoService.findAllEmployees(Integer.parseInt(currentPage), Integer.parseInt(limit));
Integer allCount = employeeInfoService.findAllCount();
//存儲值,可以在引擎模板中取值(頁面中取值)
map.put("employees",allEmployees);
map.put("totalPage",allCount);//總頁數(shù)
map.put("currentPage",currentPage);//當(dāng)前頁數(shù)-1
map.put("operation","employee_list_model");//判別標(biāo)識
//employee_list的意思就是employee_list.html頁面,并在其中取值,相當(dāng)于jsp頁面
return "employee/employee_list";
}
/**
* 在修改之前需要進(jìn)行一次數(shù)據(jù)回顯,查詢某個需要修改的員工
* @GetMapping 表示的是get請求
* @param id 員工id
* @param map 存儲值
* @return
*/
@GetMapping("/emp/{id}")
public String employee(@PathVariable("id") Integer id,Map<String,Object> map){
EmployeeInfo employee = employeeInfoService.findEmployee(id);
map.put("employee",employee);
map.put("type","update");
return "employee/employee_update";
}
/**
* 更新員工信息
* @PutMapping 表示的是put請求方式
* @param employeeForm 表單傳過來的對象
* @param bindingResult 表單驗證對象
* @return
*/
@PutMapping("/emp/{id}")
public String updateEmployee(@Validated EmployeeForm employeeForm, BindingResult bindingResult,@PathVariable("id") Integer id){
//數(shù)據(jù)校驗出現(xiàn)錯誤的時候,需要拋個異常,并且異常捕獲到異常頁面
if (bindingResult.hasErrors()){
throw new MyException(ResultEnum.CHECK_ERROR.getCode(),bindingResult.getFieldError().getDefaultMessage());
}
//封裝頁面?zhèn)鬟^來的員工id
employeeForm.setEmpId(id);
EmployeeInfo employeeInfo = new EmployeeInfo();
//對象屬性轉(zhuǎn)換
BeanUtils.copyProperties(employeeForm,employeeInfo);
employeeInfoService.updateEmployee(employeeInfo);
return "result/success";
}
/**
* 僅僅作頁面跳轉(zhuǎn)的作用(跳轉(zhuǎn)到新增員工的頁面)
* @GetMapping get的請求方式
* @return
*/
@GetMapping("/emp")
public String insertEmployeeBefore(Map<String, Object> map){
map.put("type","create");
map.put("operation","employee_create_model");
return "employee/employee_create";
}
/**
* 新增員工信息
* @PostMapping post方式提交
* @param employeeForm
* @param bindingResult
* @return
*/
@PostMapping("/emp")
public String insertEmployee(@Validated EmployeeForm employeeForm, BindingResult bindingResult){
//數(shù)據(jù)校驗出現(xiàn)錯誤的時候,需要拋個異常,并且異常捕獲到異常頁面
if (bindingResult.hasErrors()){
//錯誤碼 ResultEnum.CHECK_ERROR.getCode()
//數(shù)據(jù)校驗的具體錯誤信息 bindingResult.getFieldError().getDefaultMessage()
throw new MyException(ResultEnum.CHECK_ERROR.getCode(),bindingResult.getFieldError().getDefaultMessage());
}
EmployeeInfo employeeInfo = new EmployeeInfo();
//對象屬性轉(zhuǎn)換
BeanUtils.copyProperties(employeeForm,employeeInfo);
employeeInfoService.insertEmployee(employeeInfo);
return "result/success";
}
/**
* 刪除員工
* @DeleteMapping delete請求
* @param id 員工id
* @return
*/
@DeleteMapping("emp/{id}")
public String deleteEmployee(@PathVariable("id") Integer id){
employeeInfoService.deleteEmployee(id);
return "employee/employee_list";
}
@DeleteMapping("/batchDelete")
public String batchDeleteBirth(@RequestParam("data_id") String data_id, Map<String, Object> map){
String[] id = data_id.split(",");
for (int i = 0; i < id.length; i++){
EmployeeInfo employeeInfo = employeeInfoService.findEmployee(Integer.parseInt(id[i]));
if (employeeInfo != null){
employeeInfoService.deleteEmployee(Integer.parseInt(id[i]));
}
}
return "result/success";
}
/**
* 根據(jù)員工姓名模糊查詢員工
* @param content
* @return
*/
@PostMapping("/search")
public String searchEmployees(String content,Map<String,Object> map){
List<EmployeeInfo> employeeInfos = employeeInfoService.findAllEmployeeInfosBySearch(content);
//存儲值,可以在引擎模板中取值(頁面中取值)
map.put("employees",employeeInfos);
map.put("operation", "employee_list_model");
return "employee/employee_list";
}
/**
* 功能需求:完成客戶端的Excel表數(shù)據(jù)寫入數(shù)據(jù)庫功能
*
* @param file //用戶上傳的Excel文件
* @param uploadUtils //上傳文件的工具類 cn.zdxh.personnelmanage.utils.UploadUtils
* @return
* @throws Exception
*/
@PostMapping("/updateExcel")
@ResponseBody
public JSONObject updateExcel(@RequestParam("file") MultipartFile file, UploadUtils uploadUtils) throws Exception {
JSONObject json = new JSONObject();
try {
//第一個參數(shù)為Excel表,第二個參數(shù)為從第幾行讀取Excel的內(nèi)容,返回值為一個字符串?dāng)?shù)組集合(每一個數(shù)組代表Excel表的一行數(shù)據(jù))
List<String[]> list = uploadUtils.updateExcelUtils(file, 1);
//遍歷字符串?dāng)?shù)組集合中的數(shù)據(jù)
for (String[] str:list){
//獲取實體類對象封裝數(shù)據(jù)(每一個實體類對象封裝Excel表中的一行數(shù)據(jù))
EmployeeInfo employeeCard = new EmployeeInfo();
//一個工具類,把字符串?dāng)?shù)組數(shù)據(jù)封裝到實體類對象中,第一個參數(shù)為實體類對象,第二個參數(shù)為字符串?dāng)?shù)組
ExcelValuesHelperUtils.setAttributeValue(employeeCard, str);
/**
* 在完成Excel表中數(shù)據(jù)寫入數(shù)據(jù)庫操作之前先判斷
* 該實體類對象的是否為數(shù)據(jù)庫已有(進(jìn)行更新操作)
* 該實體類對象的數(shù)據(jù)為數(shù)據(jù)庫沒有(進(jìn)行插入操作)
*/
if (employeeInfoService.findEmployee(Integer.parseInt(str[0])) != null){
employeeInfoService.updateEmployee(employeeCard);
} else {
employeeInfoService.insertEmployee(employeeCard);
}
}
} catch (Exception e){
/**
* 做一個報錯檢測
*/
throw new MyException(ResultEnum.UPDATE_EXCEL_ERROR.getCode(), ResultEnum.UPDATE_EXCEL_ERROR.getMsg());
}
//返回客戶端的數(shù)據(jù)
json.put("code", 1);
json.put("data", "Excel表上傳成功!");
json.put("ret", true);
return json;
}
/**
* 需求功能:完成服務(wù)器端把數(shù)據(jù)庫中的數(shù)據(jù)讀出客戶端功能
*
* @param response //把生成的Excel表響應(yīng)到客戶端
* @throws NoSuchMethodException //報錯
* @throws IllegalAccessException //報錯
* @throws InvocationTargetException //報錯
* @throws InstantiationException //報錯
*/
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
//先把數(shù)據(jù)庫中的數(shù)據(jù)查詢出來
List<EmployeeInfo> list1 = employeeInfoService.selectList(null);
//一個設(shè)置Excel表標(biāo)題信息的工具類,獲取Excel表標(biāo)題的字符串?dāng)?shù)組
String[] strings = ExcelTitlesHelperUtils.getEmployeeInfoTitles();
//一個能把對象集合轉(zhuǎn)換成字符串?dāng)?shù)組集合的工具類,參數(shù)為對象集合,返回字符串?dāng)?shù)組集合
List<Object[]> list = ExcelValuesHelperUtils.exportExcel(list1);
try {
//一個能創(chuàng)建Excel表并完成發(fā)送客戶端的工具類,第一個參數(shù)為字符串?dāng)?shù)組集合(Excel表內(nèi)容),第二個參數(shù)為字符串?dāng)?shù)組(Excel表標(biāo)題),第三個參數(shù)為響應(yīng)器
ExportExcelUtils.createExcelUtils(list, strings, response);
} catch (Exception e){
//導(dǎo)表發(fā)生異常的時候
throw new MyException(ResultEnum.EXPORT_EXCEL_ERROR.getCode(),ResultEnum.EXPORT_EXCEL_ERROR.getMsg());
}
}
}
文章來源:http://www.zghlxwxcb.cn/news/detail-634585.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-634585.html
到了這里,關(guān)于springboot人事管理系統(tǒng)設(shè)計與實現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!