027-云E办_员工管理

  • 一、员工管理基础介绍
    • 1、数据库表介绍
    • 2、页面功能介绍:
  • 二、员工查询
    • 1、前期工作:
      • 1.mybatis分页配置类,分页插件
      • 2. 分页公共返回对象
      • 3.转换类:日期转换
      • 4.pojo类修改:
    • 2、查询员工三层代码:
      • controller
      • service
      • mapper
  • 三、添加员工
    • 1、前期工作:
      • 1. 添加员工的字段说明
    • 2、三层代码:
      • 单独的表查出来:民族、职称、计算工号等等
      • controller
      • service
      • 测试添加:
  • 四、更新和删除

一、员工管理基础介绍

1、数据库表介绍

  1. 关联表:外键id
    1.员工表:名族类型是int,所以说是通过id找到民族表【t_nation】
    2.政治面貌类型是int,通过id找到政治面貌表t_politics_status
    3.还有部门、职称、职位等等
  2. 工龄:入职日期-离职日期
  3. 在数据库写好的区间。比如:已婚、未婚、离异

2、页面功能介绍:

  1. 搜索功能:
    员工人名搜索
    高级搜索:员工入职日期的范围。
  2. 分页处理

二、员工查询

1、前期工作:

1.mybatis分页配置类,分页插件

package com.xxxx.server.config;import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** Mybatis分页配置,分页插件** 配置Bean*/
@Configuration
public class MyBatisPlusConfig {@Beanpublic PaginationInterceptor paginationInterceptor(){return new PaginationInterceptor();}
}

2. 分页公共返回对象

package com.xxxx.server.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.util.List;/*** 分页公共返回对象*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespPageBean {//总条数private Long total;//数据private List<?> data;
}

3.转换类:日期转换

package com.xxxx.server.converter;import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;import java.time.LocalDate;
import java.time.format.DateTimeFormatter;/*** 日期转换*/
@Component
public class DateConverter implements Converter<String,LocalDate> {/**** @param source* @return LocalDate*/@Overridepublic LocalDate convert(String source) {try {return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));} catch (Exception e ){e.printStackTrace();}return null;}
}

4.pojo类修改:

  • jsonFormat 是为了前端的格式化
  • 外界id,都要对应到单独的表,表需要对应到POJO类中,对应到对象中。
  • Tablefield(exist = false) 说明在员工表不存在的。
package com.xxxx.server.pojo;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDate;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_employee")
@ApiModel(value="Employee对象", description="")
public class Employee implements Serializable {private static final long serialVersionUID = 1L;@ApiModelProperty(value = "员工编号")@TableId(value = "id", type = IdType.AUTO)private Integer id;@ApiModelProperty(value = "员工姓名")private String name;@ApiModelProperty(value = "性别")private String gender;@ApiModelProperty(value = "出生日期")@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")private LocalDate birthday;@ApiModelProperty(value = "身份证号")private String idCard;@ApiModelProperty(value = "婚姻状况")private String wedlock;@ApiModelProperty(value = "民族")private Integer nationId;@ApiModelProperty(value = "籍贯")private String nativePlace;@ApiModelProperty(value = "政治面貌")private Integer politicId;@ApiModelProperty(value = "邮箱")private String email;@ApiModelProperty(value = "电话号码")private String phone;@ApiModelProperty(value = "联系地址")private String address;@ApiModelProperty(value = "所属部门")private Integer departmentId;@ApiModelProperty(value = "职称ID")private Integer jobLevelId;@ApiModelProperty(value = "职位ID")private Integer posId;@ApiModelProperty(value = "聘用形式")private String engageForm;@ApiModelProperty(value = "最高学历")private String tiptopDegree;@ApiModelProperty(value = "所属专业")private String specialty;@ApiModelProperty(value = "毕业院校")private String school;@ApiModelProperty(value = "入职日期")@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")private LocalDate beginDate;@ApiModelProperty(value = "在职状态")private String workState;@ApiModelProperty(value = "工号")private String workID;@ApiModelProperty(value = "合同期限")private Double contractTerm;@ApiModelProperty(value = "转正日期")@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")private LocalDate conversionTime;@ApiModelProperty(value = "离职日期")@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")private LocalDate notWorkDate;@ApiModelProperty(value = "合同起始日期")@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")private LocalDate beginContract;@ApiModelProperty(value = "合同终止日期")@JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")private LocalDate endContract;@ApiModelProperty(value = "工龄")private Integer workAge;@ApiModelProperty(value = "工资账套ID")private Integer salaryId;/*** 表中有很多外界id,都需要对应外界的表中。* 表需要对应pojo的对象中*/@ApiModelProperty(value = "民族")//在正常的员工表中是不存在的@TableField(exist=false)private Nation nation;@ApiModelProperty(value = "政治面貌")@TableField(exist = false)private PoliticsStatus politicsStatus;@ApiModelProperty(value = "部门")@TableField(exist = false)private Department department;@ApiModelProperty(value = "职称")@TableField(exist = false)private Joblevel joblevel;@ApiModelProperty(value = "职位")@TableField(exist= false)private Position position;}

2、查询员工三层代码:

controller

package com.xxxx.server.controller;import com.xxxx.server.pojo.Employee;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.service.IEmployeeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.time.LocalDate;/*** <p>*  前端控制器* </p>** @author huyelin* @since 2022-01-12*/
@RestController
@RequestMapping("/employee/basic")
public class EmployeeController员工 {@Autowiredprivate IEmployeeService iEmployeeService;@ApiOperation(value = "获取所有的员工(员工)")@GetMapping("/")/*** currentPage:打开时,默认当前是第几页* size,每页有多少条数据*/public RespPageBean getEmployee(@RequestParam(defaultValue = "1" ) Integer currentPage,@RequestParam(defaultValue = "10") Integer size,Employee employee,LocalDate[] beginDateScope){return iEmployeeService.getEmployeeByPage(currentPage,size,employee,beginDateScope);}
}

service

    /*** 获取所有员工(分页)* @param currentPage* @param size* @param employee* @param beginDateScope* @return*/RespPageBean getEmployeeByPage(Integer currentPage, Integer size, Employee employee, LocalDate[] beginDateScope);
-------------------@Autowiredprivate EmployeeMapper employeeMapper;@Overridepublic RespPageBean getEmployeeByPage(Integer currentPage, Integer size, Employee employee, LocalDate[] beginDateScope) {//开启分页Page<Employee> page =  new Page<>(currentPage,size);IPage<Employee> employeeByPage = employeeMapper.getEmployeeByPage(page, employee, beginDateScope);RespPageBean respPageBean = new RespPageBean(employeeByPage.getTotal(), employeeByPage.getRecords());return respPageBean;}

mapper

public interface EmployeeMapper extends BaseMapper<Employee> {/**
* 获取所有员工(分页)
* @param page
* @param employee
* @param beginDateScope
* @return
*/
IPage<Employee> getEmployeeByPage(Page<Employee> page,@Param("employee") Employee employee,@Param("beginDateScope") LocalDate[] beginDateScope);
}
--------------<resultMap id="EmployeeInfo" type="com.xxxx.server.pojo.Employee"extends="BaseResultMap"><association property="nation" javaType="com.xxxx.server.pojo.Nation"><id column="nid" property="id"></id><result column="nname" property="name"></result></association><association property="politicsStatus"javaType="com.xxxx.server.pojo.PoliticsStatus"><id column="pid" property="id"></id><result column="pname" property="name"></result></association><association property="department"javaType="com.xxxx.server.pojo.Department"><id column="did" property="id"></id><result column="dname" property="name"></result></association><association property="joblevel"javaType="com.xxxx.server.pojo.Joblevel"><id column="jid" property="id"></id><result column="jname" property="name"></result></association><association property="position"javaType="com.xxxx.server.pojo.Position"><id column="posid" property="id"></id><result column="posname" property="name"></result></association></resultMap><!-- 通用查询结果列 --><sql id="Base_Column_List">id, name, gender, birthday, idCard, wedlock, nationId, nativePlace, politicId, email, phone, address, departmentId, jobLevelId, posId, engageForm, tiptopDegree, specialty, school, beginDate, workState, workID, contractTerm, conversionTime, notWorkDate, beginContract, endContract, workAge, salaryId</sql><!--获取所有员工(分页)--><select id="getEmployeeByPage" resultMap="EmployeeInfo">SELECTe.*,n.id AS nid,n.`name` AS nname,p.id AS pid,p.`name` AS pname,d.id AS did,d.`name` AS dname,j.id AS jid,j.`name` AS jname,pos.id AS posid,pos.`name` AS posnameFROMt_employee e,t_nation n,t_politics_status p,t_department d,t_joblevel j,t_position posWHEREe.nationId = n.idAND e.politicId = p.idAND e.departmentId = d.idAND e.jobLevelId = j.idAND e.posId = pos.id<if test="null != employee.name and '' != employee.name">AND e.`name` LIKE CONCAT( '%', #{employee.name}, '%' )</if><if test="null != employee.politicId">AND e.politicId =#{employee.politicId}</if><if test="null != employee.nationId">AND e.nationId =#{employee.nationId}</if><if test="null != employee.jobLevelId">AND e.jobLevelId =#{employee.jobLevelId}</if><if test="null != employee.posId">AND e.posId =#{employee.posId}</if><if test="null != employee.engageForm and ''!=employee.engageForm">AND e.engageForm =#{employee.engageForm}</if><if test="null != employee.departmentId">AND e.departmentId =#{employee.departmentId}</if><if test="null != beginDateScope and 2==beginDateScope.length">AND e.beginDate BETWEEN #{beginDateScope[0]} AND #{beginDateScope[1]}</if>ORDER BYe.id</select>

三、添加员工

1、前期工作:

1. 添加员工的字段说明

  1. 政治面貌、籍贯、民族等等,是需要从数据库规定好的字段,进行选择。去单独的表中去查询。 而查出来是表中的id和名字,而添加名字时,是需要传一个employee对象,而其中employee有外键id,怎么把表中的id,和employee中的外键id相关联呢?
  2. 工号:正式进入公司,工号都是唯一的,业务中,是自动带过来,是不需要填写的。一般是当最大的工号id+1,就是现在添加员工的id

2、三层代码:

单独的表查出来:民族、职称、计算工号等等

controller

package com.xxxx.server.controller;import com.xxxx.server.pojo.*;
import com.xxxx.server.service.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.time.LocalDate;
import java.util.List;@RestController
@RequestMapping("/employee/basic")
public class EmployeeController员工 {@Autowiredprivate IEmployeeService iEmployeeService;@ApiOperation(value = "获取所有的员工(员工)")@GetMapping("/")/*** currentPage:打开时,默认当前是第几页* size,每页有多少条数据*/public RespPageBean getEmployee(@RequestParam(defaultValue = "1" ) Integer currentPage,@RequestParam(defaultValue = "10") Integer size,Employee employee,LocalDate[] beginDateScope){return iEmployeeService.getEmployeeByPage(currentPage,size,employee,beginDateScope);}@Autowiredprivate IPoliticsStatusService politicsStatusService;@Autowiredprivate INationService nationService;@Autowiredprivate IJoblevelService joblevelService;@Autowiredprivate IPositionService positionService;@Autowiredprivate IDepartmentService departmentService;@ApiOperation(value = "获取所有政治面貌")@GetMapping("/politicsstatus")public List<PoliticsStatus> getAllPoliticsStatus() {return politicsStatusService.list();}@ApiOperation(value = "获取所有民族")@GetMapping("/nations")public List<Nation> getAllNations() {return nationService.list();}@ApiOperation(value = "获取所有职称")@GetMapping("/joblevels")public List<Joblevel> getAllJobLevels() {return joblevelService.list();}@ApiOperation(value = "获取所有职位")@GetMapping("/positions")public List<Position> getAllPositions() {return positionService.list();}@ApiOperation(value = "获取所有部门")@GetMapping("/deps")public List<Department> getAllDepartments(){return departmentService.getAllDepartments();}@ApiOperation(value = "获取工号")@GetMapping("/maxWorkID")public RespBean maxWorkID() {return iEmployeeService.maxWorkId();}@ApiOperation(value = "添加员工")@PostMapping("/")public RespBean addEmp(@RequestBody Employee employee) {return iEmployeeService.insertEmployee(employee);}
}

service

   /*** 获取工号* @return*/RespBean maxWorkId();/*** 添加员工* @param employee* @return*/RespBean insertEmployee(Employee employee);
---------/*** 获取工号* @return*/@Overridepublic RespBean maxWorkId() {List<Map<String, Object>> maps = employeeMapper.selectMaps(new QueryWrapper<Employee>().select("max(workID)"));return RespBean.success(null, String.format("%08d", Integer.parseInt(maps.get(0).get("max(workID)").toString()) + 1));}/*** 添加员工* @param employee* @return*/@Overridepublic RespBean insertEmployee(Employee employee) {//处理合同期限,保留2位小数//获取合同开始的时间LocalDate beginContract = employee.getBeginContract();//获取合同结束的时间LocalDate endContract = employee.getEndContract();//计算有多少天long days = beginContract.until(endContract, ChronoUnit.DAYS);// 将天数保留两位小数点DecimalFormat decimalFormat = new DecimalFormat("##.00");employee.setContractTerm(Double.parseDouble(decimalFormat.format(days/365.00)));if (1==employeeMapper.insert(employee)) {return RespBean.success("添加成功!");}return RespBean.error("添加失败!");}

测试添加:

四、更新和删除

    @ApiOperation(value = "更新员工")@PutMapping("/")public RespBean updateEmp(@RequestBody Employee employee){if(iEmployeeService.updateById(employee)){return RespBean.success("更新成功");}return RespBean.error("更新失败");}@ApiOperation(value = "删除员工")@DeleteMapping("/{id}")public RespBean deleteEmp(@PathVariable Integer id){if (iEmployeeService.removeById(id)){return RespBean.success("删除成功!");}return RespBean.error("删除失败!");}

027-云E办_员工管理相关推荐

  1. 008-云E办_操作员管理

    008-云E办_操作员管理 一.操作员管理 实现代码 用户状态更新 删除 角色更新 操作员搜索 一.操作员管理 操作员就是登陆进来的用户.用户相关信息. 实现代码 SysAdmin.vue <t ...

  2. 融云发送自定义消息_数据源管理 | Kafka集群环境搭建,消息存储机制详解

    一.Kafka集群环境 1.环境版本 版本:kafka2.11,zookeeper3.4 注意:这里zookeeper3.4也是基于集群模式部署. 2.解压重命名 tar -zxvf kafka_2. ...

  3. 云e办(后端)——员工管理

    云e办(后端)--员工管理 员工表: 关联表:外键id 1.员工表:名族类型是int,所以说是通过id找到民族表[t_nation] 2.政治面貌类型是int,通过id找到政治面貌表t_politic ...

  4. (B站云e办)SpringBoot开发项目实战记录(七)(员工管理(分页知识))

    (B站云e办)SpringBoot开发项目实战记录(七) 一.员工管理 1.1 准备工作(分页配置类.日期格式化类) 1. mybatisplus配置类分页 2. 日期格式化类(converter) ...

  5. 云e办前端学习笔记(十一)员工基本资料管理

    前言 本系列博客基于B站的云e办管理系统,前端和后端我都自己敲了一遍,这里做一个学习记录.云e办的原始视频链接如下:https://www.bilibili.com/video/BV1Ai4y1P7T ...

  6. 腾讯云发布智慧员工管理方案,支持组织360度协作

    提升组织活力和协作效率是企业打造自身竞争力的关键因素.12月1日,腾讯云发布智慧员工管理方案,融合腾讯电子签.腾讯乐享.腾讯微卡.腾讯云HiFlow.数据连接器等多款产品,打造高效.安全.共享.低碳的 ...

  7. 云E办项目之部门管理

    文章目录 云E办---部门管理 一.展示所有部门 1. 后台接口及数据格式 2. 使用Element-ui中的Tree树形控件 3. 初始化部门信息 二. 添加部门 1. 后台接口及数据格式 2. 使 ...

  8. 云e办前端学习(六)职称管理

    前言 本系列博客基于B站的云e办管理系统,前端和后端我都自己敲了一遍,这里做一个学习记录.云e办的原始视频链接如下:https://www.bilibili.com/video/BV1Ai4y1P7T ...

  9. B站云E办Vue+SpringBoot前后端分离项目——MVC三层架构搭建后台项目

    本项目来源B站云E办,笔记整理了项目搭建的过程和涉及的知识点.对于学习来说,不是复制粘贴代码即可,要知其然知其所以然.希望我的笔记能为大家提供思路,也欢迎各位伙伴的指正. 项目前端学习笔记目录 B站云 ...

最新文章

  1. 详解Spring中Bean的自动装配~
  2. MySQL知识梳理与命令操作
  3. 勒索病毒一周记:它让我们得到了什么经验教训?
  4. Linux配置keepalived实现nginx高可用安装过程记录
  5. java comparator内部类_java - Java Comparator使用.reverseOrder()但内部类 - 堆栈内存溢出...
  6. finalshell连接超时怎么解决_vncviewer连接超时,vncviewer连接超时怎么解决
  7. python split()函数
  8. 12个免费的 Twitter Bootstrap 后台模板
  9. CentOS 6.5安装Tomcat-9.0.0.M19
  10. android 音视频硬编解码
  11. Java比较器-学习
  12. UNI-APP获取手机MAC地址
  13. xy转经纬 经纬转xy 各种坐标系
  14. Android Serach框架使详解
  15. UT2011学习笔记
  16. python中e怎么计算_Python之循环结构——实战计算自然底数e,圆周率Π
  17. Object对象Configurable,Enumerable,Writable含义解读
  18. OpenCV-Python击中击不中HITMISS形态变换详解
  19. 【算法❃思维与技巧】图解牛顿迭代法(力扣题实战)
  20. Web Worker 初探

热门文章

  1. ES6-Reflect属性介绍
  2. win10系统装机(Dell)
  3. 张萌韩墨羽——android摄像头推流
  4. java string 大小空间_String的长度和储存大小
  5. 解决eclipse新建Android项目出现红色感叹号问题
  6. 5分钟搞懂“区块链”
  7. 京东携手SunLike进军LED台灯市场
  8. 计算机办公软件应用三套题目,Office办公软件高级应用第三套试卷100分
  9. matplotlib——折线图,散点图,柱状图,饼状图
  10. 个人总结的一些AD20版使用,对新入门选手很有帮助