package com.xxxx.server.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.xxxx.server.pojo.*;
import com.xxxx.server.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author zhanglishen
* @since 2020-11-14
*/
@Api(tags = "EmployeeController")
@RestController
@RequestMapping("/system/basic/employee")
public class EmployeeController {
@Autowired
private IEmployeeService employeeService;
@Autowired
private IPositionService positionService;
@Autowired
private IPoliticsStatusService politicsStatusService;
@Autowired
private IJoblevelService joblevelService;
@Autowired
private INationService nationService;
@Autowired
private IDepartmentService departmentService;
@ApiOperation(value = "获取所有员工(分页)")
@GetMapping("/")
public RespPageBean getEmployeeByPage(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size,
Employee employee, LocalDate[] beginDateScope){
return employeeService.getEmployeeByPage(currentPage,size,employee,beginDateScope);
}
@ApiOperation(value = "获取最大工号")
@GetMapping("/maxWorkID")
public RespBean maxWorkID(){
return employeeService.maxWorkId();
}
@ApiOperation(value = "添加员工")
@PostMapping("/")
public RespBean addEmp(@RequestBody Employee employee){
return employeeService.insertEmployee(employee);
}
@ApiOperation(value = "更新员工")
@PutMapping("/")
public RespBean updateEmp(@RequestBody Employee employee){
if (employeeService.updateById(employee)){
return RespBean.success("更新成功");
}
return RespBean.error("更新失败");
}
@ApiOperation(value = "删除员工")
@DeleteMapping("/{id}")
public RespBean deleteEmp(@PathVariable Integer id){
if (employeeService.removeById(id)){
return RespBean.success("删除成功");
}
return RespBean.error("删除失败");
}
@ApiOperation(value = "导出员工数据")
@GetMapping(value = "/export",produces = "application/octet-stream")
public void exportEmployee(HttpServletResponse response){
List<Employee> list = employeeService.getEmployee(null);
ExportParams params = new ExportParams("员工表","员工表", ExcelType.HSSF);
Workbook workbook = ExcelExportUtil.exportExcel(params,Employee.class,list);
ServletOutputStream outputStream = null;
try {
//流形式
response.setHeader("content-type","application/octet-stream");
//中文乱码
response.setHeader("content-disposition","attachment;filename="+ URLEncoder.encode("员工表.xls","UTF-8"));
outputStream = response.getOutputStream();
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();
}finally {
if (null != outputStream){
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@ApiOperation(value = "导入员工数据")
@ApiImplicitParams({@ApiImplicitParam(name="file",value = "上传文件",dataType = "MultipartFile")})
@PostMapping("/import")
public RespBean importEmployee(MultipartFile file){
ImportParams params = new ImportParams();
//去掉标题行
params.setTitleRows(1);
List<Nation> nations = nationService.list();
List<PoliticsStatus> politicsStatuses = politicsStatusService.list();
List<Position> positions = positionService.list();
List<Department> departments = departmentService.list();
List<Joblevel> joblevels = joblevelService.list();
try {
List<Employee> list = ExcelImportUtil.importExcel(file.getInputStream(), Employee.class, params);
list.forEach(employee ->{
//民族id
employee.setNationId(nations.get(nations.indexOf(new Nation(employee.getNation().getName()))).getId());
//政治面貌id
employee.setPoliticId(politicsStatuses.get(politicsStatuses.indexOf(new PoliticsStatus(employee.getPoliticsStatus().getName()))).getId());
//部门id
employee.setDepartmentId(departments.get(departments.indexOf(new Department(employee.getDepartment().getName()))).getId());
//职称id
employee.setJobLevelId(joblevels.get(joblevels.indexOf(new Joblevel(employee.getJoblevel().getName()))).getId());
//职位id
employee.setPosId(positions.get(positions.indexOf(new Position(employee.getPosition().getName()))).getId());
});
if (employeeService.saveBatch(list)){
return RespBean.success("导入成功");
}
return RespBean.error("导入失败");
} catch (Exception e) {
e.printStackTrace();
}
return RespBean.error("导入失败");
}
@ApiOperation(value = "获取所有政治面貌")
@GetMapping("/politicsStatus")
private List<PoliticsStatus> getAllPoliticsStatus(){
return politicsStatusService.list();
}
@ApiOperation(value = "获取所有职称")
@GetMapping("/joblevel")
public List<Joblevel> getAllJobLevel(){
return joblevelService.list();
}
@ApiOperation(value = "获取所有民族")
@GetMapping("/nation")
public List<Nation> getAllNation(){
return nationService.list();
}
@ApiOperation(value = "获取所有职位")
@GetMapping("/position")
public List<Position> getAllPosition(){
return positionService.list();
}
@ApiOperation(value = "获取所有部门")
@GetMapping("/deps")
public List<Department> getAllDepartment(){
return departmentService.getAllDepartments();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
云e办项目源码,云E办 ,在线智能办公项目-云E办的项目代码(含vue前端、springboot后端、sql数据库)
共620个文件
xml:216个
class:145个
java:142个
1星 需积分: 33 110 下载量 138 浏览量
2021-08-24
12:43:23
上传
评论 13
收藏 1.52MB ZIP 举报
温馨提示
【高配完整版】运用Springboot、Vue全家桶、Spring Security、JWT令牌、Redis完成一个前后端分离项目 说明: 前端项目,将会涉及前后端分离、Vue全家桶、Axios、ES6、Webpack、ElementUI、WebSocket、font-awesome、js-file-download、Vue-chat等知识 后端项目,将会涉及前后端分离、Spring Security安全框架、JWT令牌、Redis、EasyPOI、RabbitMQ、WebSocket、FasfDFS等知识 ---------------------------------------------------------------------------------------------------------- 整套 - 资源目录包括: yeb-web yeb-server yeb-email yeb-server yeb-generator sql
资源详情
资源评论
资源推荐
收起资源包目录
云e办项目源码,云E办 ,在线智能办公项目-云E办的项目代码(含vue前端、springboot后端、sql数据库) (620个子文件)
.babelrc 242B
Employee.class 23KB
EmployeeController.class 11KB
SecurityConfig.class 9KB
Admin.class 9KB
Salary.class 9KB
AdminServiceImpl.class 8KB
Menu.class 8KB
EmployeeServiceImpl.class 7KB
CodeGenerator.class 7KB
MailLog.class 6KB
RabbitMQConfig.class 6KB
MailReceiver.class 5KB
FastDFSUtils.class 5KB
Department.class 5KB
SwaggerConfig.class 5KB
permissionController.class 5KB
EmployeeRemove.class 5KB
SalaryAdjust.class 5KB
EmployeeEc.class 5KB
JwtTokenUtil.class 5KB
Appraise.class 4KB
WebSocketConfig$1.class 4KB
AdminInfoController.class 4KB
MailTask.class 4KB
Joblevel.class 4KB
EmployeeTrain.class 4KB
Position.class 4KB
SysMsg.class 4KB
CustomFilter.class 4KB
JwtAuthenticationTokenFilter.class 4KB
SysMsgContent.class 3KB
WebSocketConfig.class 3KB
Oplog.class 3KB
ChatMsg.class 3KB
JoblevelController.class 3KB
PositionController.class 3KB
CaptchaController.class 3KB
CustomUrlDecisionManager.class 3KB
AdminController.class 3KB
MenuServiceImpl.class 3KB
PoliticsStatus.class 3KB
RespBean.class 3KB
Nation.class 3KB
Role.class 3KB
AdminRole.class 3KB
MenuRole.class 3KB
SalaryController.class 3KB
AdminLoginController.class 3KB
SalarySobCfgController.class 3KB
DepartmentServiceImpl.class 3KB
AdminLogin.class 3KB
RespPageBean.class 2KB
CustomAuthorityDeserializer.class 2KB
SecurityConfig$1.class 2KB
DepartmentController.class 2KB
MenuRoleServiceImpl.class 2KB
RestAuthorizationEntryPoint.class 2KB
RestfulAccessDeniedHandler.class 2KB
WenSocketController.class 2KB
RedisConfig.class 2KB
CaptchaConfig.class 2KB
DateConverter.class 2KB
CodeGenerator$2.class 2KB
IAdminService.class 1KB
EmployeeMapper.class 1KB
GlobalCorsConfig.class 1KB
ChatController.class 1KB
MailApplication.class 1KB
MenuController.class 1KB
IEmployeeService.class 1016B
GlobalException.class 927B
YebServerApplication.class 903B
HelloController.class 896B
MailConstants.class 855B
PoliticsStatusServiceImpl.class 754B
EmployeeRemoveServiceImpl.class 754B
SysMsgContentServiceImpl.class 747B
EmployeeTrainServiceImpl.class 747B
SalaryAdjustServiceImpl.class 740B
MybatisPlusConfig.class 737B
EmployeeEcServiceImpl.class 726B
AdminRoleServiceImpl.class 719B
AppraiseServiceImpl.class 712B
PositionServiceImpl.class 712B
JoblevelServiceImpl.class 712B
MailLogServiceImpl.class 705B
SysMsgServiceImpl.class 698B
SalaryServiceImpl.class 698B
NationServiceImpl.class 698B
OplogServiceImpl.class 691B
RoleServiceImpl.class 684B
IDepartmentService.class 655B
AdminMapper.class 642B
DepartmentMapper.class 622B
MenuMapper.class 614B
AdminRoleMapper.class 559B
MenuRoleMapper.class 557B
PoliticsStatusController.class 548B
EmployeeRemoveController.class 548B
共 620 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
joefche
- 粉丝: 7
- 资源: 64
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2