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

员工表:

关联表:外键id

  • 1.员工表:名族类型是int,所以说是通过id找到民族表【t_nation】
  • 2.政治面貌类型是int,通过id找到政治面貌表t_politics_status
  • 3.还有部门、职称、职位等等
  • 工龄:入职日期-离职日期
  • 还有合同期限需要我们自己算出(结束日期-开始日期)
  • 在数据库写好的区间。比如:已婚、未婚、离异

前端页面功能介绍:

普通搜索功能:

高级搜索:

并需要进行分页处理

查询所有员工:

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类修改:

外界id,都要对应到单独的表,表需要对应到POJO类中,对应到对象中。


@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 是为了前端的格式化@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) 说明在员工表不存在的。@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;}

5.controller

/*** <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);}
}

6.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;}

7.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>

添加员工

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

1.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);}
}

2.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("删除失败!");}

云e办(后端)——员工管理相关推荐

  1. 027-云E办_员工管理

    027-云E办_员工管理 一.员工管理基础介绍 1.数据库表介绍 2.页面功能介绍: 二.员工查询 1.前期工作: 1.mybatis分页配置类,分页插件 2. 分页公共返回对象 3.转换类:日期转换 ...

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

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

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

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

  4. 云e办(后端)——项目介绍及搭载项目

    云e办 项目介绍 本项目目的是实现中小型企业的在线办公系统,云E办在线办公系统是一个用来管理日常的办公事务的一个系统,他能够管的内容有:日常的各种流程审批,新闻,通知,公告,文件信息,财务,人事,费用 ...

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

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

  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. 云e办学习笔记(三十一)工资账套功能实现

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

最新文章

  1. excel另存为没有dbf_PDF转Excel怎么做的?节省工作时间,你要学会的办公技巧
  2. 算法基础课-动态规划-区间dp-AcWing 282. 石子合并:区间dp
  3. 【SpringBoot】项目实现热部署的两种方式
  4. CodeForces - 137D Palindromes(dp+路径输出)
  5. 爆牙齿的世界杯日记(阿根疼啦)
  6. jQuery07源码 (3803 , 4299) attr() prop() val() addClass()等 : 对元素属性的操作
  7. 梯度下降:求线性回归
  8. Qt应用程序只运行一个实例
  9. 【BZOJ1415】【codevs1784】聪聪与可可,概率DP
  10. JavaBean规范、EL、JSTL、
  11. Oracle 发布基于 VS Code 的开发者工具,轻松使用 Oracle 数据库
  12. Axios和Ajax处理后台返回文件流实现文件下载(图片和Excel)
  13. 主数据——共享数据的核心,数据资产的灵魂
  14. video.js的使用,打造自定义视频播放器(综合详解,可收藏)
  15. Linux学习笔记Day01-03 Xshell,Xfpt下载安装,使用
  16. uCOS事件相关函数代码理解
  17. pyqt5,波形进度条
  18. 4K网络视频下载器:4K Video Downloader mac汉化教程
  19. 内存测试软件 ddr4,DDR4内存测试软件
  20. 2021年C证(安全员)复审模拟考试及C证(安全员)作业模拟考试

热门文章

  1. 【Kotlin基础系列】第7章 类与对象(2)--- 继承
  2. php头文件是什么,c++万能头文件是什么?
  3. Maven清理本地仓库lastUpdate、error文件夹和无效jar包
  4. Java实现 蓝桥杯 历届试题 核桃的数量
  5. 寄售和委托代销的区别
  6. CV5200自组网远程WiFi模组,无人机无线图传应用,高清低时延方案
  7. P2085 最小函数值(优先队列 分组法运用)
  8. 2021-2027全球与中国热电堆红外传感器市场现状及未来发展趋势
  9. ZOJ 1973 Just Pour the Water(矩阵快速幂)
  10. 时钟指针(python3)