文章目录
5.员工奖惩
1.查询所有员工奖惩
controller
/**
* @Author lzp
* @Description: 获取所有的员工奖罚信息
* @Date: 11:51 2022/7/7
* @Param: [searchName]
* @return: com.lzp.vhrserver.utils.R
*/
@GetMapping("/getEmpEcs")
public R getEmpEcs(@RequestParam Map<String, Object>paramMap){
PageInfo<EmpEcVo> empEcs = this.empecEntityService.getEmpEcs(paramMap);
return R.ok("").setData(empEcs);
}
传入的参数:
分页参数 当前页和每页数量 也可能包含搜索参数(名字关键字)
返回数据示例
包含分页数据和实际数据( list中)
{
"msg": "",
"code": 0,
"data": {
"total": 11,
"list": [{
"id": 12,
"eid": 1944,
"ecDate": "2022-07-21",
"ecReason": "按时完成任务",
"ecPoint": 20,
"ecType": 0,
"remark": "规定时间保质保量完成开发任务,膜拜大佬",
"empName": "王五"
}, {
"id": 13,
"eid": 54,
"ecDate": "2022-07-29",
"ecReason": "接到大订单",
"ecPoint": 20,
"ecType": 0,
"remark": "接到大订单,销售大神",
"empName": "鹿存亮6"
}],
"pageNum": 1,
"pageSize": 10,
"size": 10,
"startRow": 1,
"endRow": 10,
"pages": 2,
"prePage": 0,
"nextPage": 2,
"isFirstPage": true,
"isLastPage": false,
"hasPreviousPage": false,
"hasNextPage": true,
"navigatePages": 8,
"navigatepageNums": [1, 2],
"navigateFirstPage": 1,
"navigateLastPage": 2
}
}
service
public PageInfo<EmpEcVo> getEmpEcs(Map<String, Object> paramMap) {
//获取到搜索参数(名字的关键字)
String searchName = (String)paramMap.get("searchName");
//查询分页参数
PageHelper.startPage(paramMap);
//查询数据
PageInfo<EmpEcVo> empEcVoPageInfo =
new PageInfo<>(empecEntityMapper.getEmpEcs(searchName));
//List<EmpEcVo> empEcs = this.empecEntityMapper.getEmpEcs(searchName);
return empEcVoPageInfo;
}
sql
关联查询员工表获取员工姓名,if判断如果有搜素条件加上搜索条件
<select id="getEmpEcs" resultType="com.lzp.vhrserver.vo.EmpEcVo">
SELECT ec.*,e.name as 'empName'
FROM employeeec ec
JOIN employee e
ON ec.eid=e.id
where 1=1
<if test="searchName!='' and searchName != null ">
and e.name like concat('%',#{searchName,jdbcType=VARCHAR},'%')
</if>
</select>
2.添加奖惩信息
1.获取所有员工名字
sql
<select id="getEmps" resultType="com.lzp.vhrserver.entity.EmployeeEntity">
select id,name from employee
</select>
2.执行添加
controller
参数为奖罚信息
/**
* @Author lzp
* @Description: 添加员工奖惩信息
* @Date: 14:35 2022/7/7
* @Param: [empEcVo]
* @return: com.lzp.vhrserver.utils.R
*/
@PostMapping("/addEmpEc")
public R addEmpEc(@RequestBody EmpecEntity empecEntity){
if(!this.empecEntityService.addEmpEc(empecEntity))
return R.error("添加失败");
return R.ok("添加成功!");
}
service
sql返回1说明新增成功,其他为失败
public Boolean addEmpEc(EmpecEntity empecEntity) {
Integer integer = this.empecEntityMapper.addEmpEc(empecEntity);
if(integer==1){
return true;
}
return false;
}
sql
id自增,无需指定
<insert id="addEmpEc">
insert into employeeec
values(null,#{empecEntity.eid},#{empecEntity.ecDate},#{empecEntity.ecReason},
#{empecEntity.ecPoint},#{empecEntity.ecType},#{empecEntity.remark})
</insert>
3.修改员工奖惩信息
1.根据id回显数据
无需,前端点击编辑可以获取当前行信息,赋值给empEc对象即可。
2.获取所有员工
同新增
3.执行修改
controller
/**
* @Author lzp
* @Description: 修改奖惩信息
* @Date: 17:22 2022/7/7
* @Param: [empecEntity]
* @return: com.lzp.vhrserver.utils.R
*/
@PostMapping("/updateEmpEc")
public R updateEmpEc(@RequestBody EmpecEntity empecEntity){
if(!this.empecEntityService.updateEmpEc(empecEntity)){
return R.error("修改失败");
}
return R.ok("修改成功!");
}
service
public Boolean updateEmpEc(EmpecEntity empecEntity) {
Integer integer = this.empecEntityMapper.updateEmpEc(empecEntity);
if(integer==1){
return true;
}
return false;
}
sql
<update id="updateEmpEc">
update employeeec
set
eid=#{empecEntity.eid},ecDate=#{empecEntity.ecDate},ecReason=#{empecEntity.ecReason},
ecPoint=#{empecEntity.ecPoint},remark=#{empecEntity.remark}
where id=#{empecEntity.id}
</update>
4.删除员工信息
根据id删除
/**
* @Author lzp
* @Description: 删除奖惩信息
* @Date: 17:09 2022/7/7
* @Param: [id]
* @return: com.lzp.vhrserver.utils.R
*/
@DeleteMapping("/deleteEmpEcById")
public R deleteEmpEcById(Integer id){
if(!this.empecEntityService.deleteEmpEcById(id)){
return R.error("删除失败");
}
return R.ok("删除成功!");
}
service
public Boolean deleteEmpEcById(Integer id) {
Integer integer = this.empecEntityMapper.deleteEmpEcById(id);
if(integer==1){
return true;
}
return false;
}
sql
<delete id="deleteEmpEcById">
delete from employeeec where id=#{id}
</delete>
5.实体类和增强类
@Data
public class EmpecEntity implements Serializable {
/**
*
*/
private Integer id;
/**
* 员工编号
*/
private Integer eid;
/**
* 奖罚日期
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date ecDate;
/**
* 奖罚原因
*/
private String ecReason;
/**
* 奖罚分
*/
private Integer ecPoint;
/**
* 奖罚类别,0:奖,1:罚
*/
private Integer ecType;
/**
* 备注
*/
private String remark;
private static final long serialVersionUID = 1L;
}
@Data
public class EmpEcVo extends EmpecEntity {
private String empName;
}
6.员工培训
1.获取所有培训信息
controller
/**
*@Author: lzp
*@Description: 查找所有培训
*@Date: 2022/7/7 20:48
*@Params [searchName]
*@return com.lzp.vhrserver.utils.R
**/
@GetMapping("/getEmpTrains")
public R getEmpTrains(String searchName){
List<EmpTrainVo> empTrains = this.empTrainEntityService.getEmpTrains(searchName);
return R.ok("").setData(empTrains);
}
sql
可能根据培训名称搜索
<select id="getEmpTrains" resultType="com.lzp.vhrserver.vo.EmpTrainVo">
select * from employeetrain where 1=1
<if test="searchName!='' and searchName != null ">
and trainContent like concat('%',#{searchName,jdbcType=VARCHAR},'%')
</if>
</select>
2.添加培训
只添加培训基础信息,培训人员需要单独添加
controller
/**
* @Author lzp
* @Description: 添加培训
* @Date: 11:17 2022/7/9
* @Param: [entity]
* @return: com.lzp.vhrserver.utils.R
*/
@PostMapping("/doAddTrain")
public R doAddTrain(@RequestBody EmpTrainEntity trainEntity){
if(!this.empTrainEntityService.doAddTrain(trainEntity)){
return R.error(9,"添加失败!");
}
return R.ok("添加成功");
}
sql
培训日期,培训内容,备注,培训名称,培训热度
<insert id="doAddTrain">
insert into employeetrain(trainDate,trainContent,remark,name,hot)
values (#{trainEntity.trainDate},#{trainEntity.trainContent},#{trainEntity.remark},
#{trainEntity.name},#{trainEntity.hot})
</insert>
3.删除培训
根据培训id
controller
/**
* @Author lzp
* @Description: 删除某次培训
* @Date: 13:58 2022/7/8
* @Param: [trainId]
* @return: com.lzp.vhrserver.utils.R
*/
@DeleteMapping("/deleteTrain")
public R deleteTrain(Integer trainId){
if(!this.empTrainEntityService.deleteTrain(trainId)){
return R.error("删除失败");
}
return R.ok("删除成功");
}
service
@Transactional
public Boolean deleteTrain(Integer trainId) {
//删除培训
Integer integer = this.empTrainEntityMapper.deleteTrain(trainId);
if(integer<=0){
return false;
}
//删除该培训关联的所有员工 可能该培训参与人员为0,会返回0
Integer integer1 = this.empTrainEntityMapper.deleteTrainEmps(trainId);
if(integer1<0){
return false;
}
return true;
}
sql
1.删除培训
<delete id="deleteTrain">
delete from employeetrain where id=#{trainId}
</delete>
2.删除参与该培训的人员
根据培训id
<delete id="deleteTrainEmps">
delete from emp_train where tid=#{trainId}
</delete>
4.获取培训人员
姓名和部门
controller
/**
*@Author: lzp
*@Description: 查找参加培训的员工
*@Date: 2022/7/7 21:32
*@Params [trainId]
*@return com.lzp.vhrserver.utils.R
**/
@RequestMapping("/getTrainEmps")
public R getTrainEmps(Integer trainId){
List<TrainEmpVo> trainEmps = this.empTrainEntityService.getTrainEmps(trainId);
return R.ok("").setData(trainEmps);
}
sql
<select id="getTrainEmps" resultType="com.lzp.vhrserver.vo.TrainEmpVo">
SELECT e.id as 'empId',e.name as 'EmpName' ,d.name as 'depName'
FROM emp_train t
LEFT JOIN employee e
ON e.`id`=t.eid
LEFT JOIN department d
ON d.`id`=e.`departmentId`
WHERE t.`tid`=#{trainId}
</select>
5.删除某个培训人员
根据当前培训id和该员工id
controller
/**
* @Author lzp
* @Description: 删除参与培训的某位员工
* @Date: 13:33 2022/7/8
* @Param: [trainId, empId]
* @return: com.lzp.vhrserver.utils.R
*/
@DeleteMapping("/deleteTrainEmp")
public R deleteTrainEmp(Integer trainId,Integer empId){
if(!this.empTrainEntityService.deleteTrainEmp(trainId,empId)){
return R.error("删除失败");
}
return R.ok("删除成功!");
}
service
@Transactional
public Boolean deleteTrainEmp(Integer trainId, Integer empId) {
//删除该培训人员
Integer integer = this.empTrainEntityMapper.deleteTrainEmp(trainId, empId);
if(integer<=0){
return false;
}
//获取到总培训人数
Integer total = this.empTrainEntityMapper.getTotal(trainId);
//更新总培训人数
Integer integer1 = this.empTrainEntityMapper.updateTotal(total,trainId);
if(integer1<0){
return false;
}
return true;
}
sql
1.删除培训人员
<delete id="deleteTrainEmp">
delete from emp_train where tid=#{trainId} and eid=#{empId}
</delete>
2.获取总培训人数 (emp_train表中)
<select id="getTotal" resultType="java.lang.Integer">
select count(0) from emp_train where tid=#{trainId}
</select>
3.更新总培训人数
<update id="updateTotal">
update employeetrain set total = #{total} where id=#{trainId}
</update>
6.添加培训人员第一步
先获取最后一级部门信息,然后获取每个部门的员工作为children,因为可能通过选择部门来进行添加员工
对应实体类
@Data
public class EmpTrainOptionVo {
private Integer id; //部门id
private String name; //部门名称
private List<OptionEmpVo> children;
}
@Data
public class OptionEmpVo {
private Integer id; //人员id
private String name; //人员名字
}
controller
/**
* @Author lzp
* @Description: 添加培训人员时 获取可以参加的员工
* @Date: 8:52 2022/7/8
* @Param: [trainId]
* @return: com.lzp.vhrserver.utils.R
*/
@GetMapping("/getOptions")
public R getOptions(Integer trainId) {
List<EmpTrainOptionVo> empTrainEntityServiceOptions = this.empTrainEntityService.getOptions(trainId);
return R.ok("").setData(empTrainEntityServiceOptions);
}
service
主要是填充EmpTrainOptionVo这个类的集合,作为前端的菜单
public List<EmpTrainOptionVo> getOptions(Integer trainId) {
//先获取到所有的部门 isParent=0的部门
List<DepartmentEntity> notParentDep = this.departmentEntityMapper.getNotParentDep();
//获取到已报名的员工id集合,不能重复报名
List<Integer> eidByTid = this.empTrainEntityMapper.getEidByTid(trainId);
//遍历所有的isParent=0的部门 查找该部门下未参与该培训员工
List<EmpTrainOptionVo> empTrainOptionVos = notParentDep.stream().map(item -> {
//目前遍历的信息就是每个部门信息
EmpTrainOptionVo empTrainOptionVo = new EmpTrainOptionVo();
empTrainOptionVo.setId(item.getId());
empTrainOptionVo.setName(item.getName());
//获取到每个部门的员工,排除已经包名的员工,传入当前部门id和已经报名的id集合
List<OptionEmpVo> empsByDepId = this.employeeEntityMapper.getEmpsByDepId(item.getId()
,eidByTid);
empTrainOptionVo.setChildren(empsByDepId);
return empTrainOptionVo;
}).collect(Collectors.toList());
return empTrainOptionVos;
}
sql
1.获取所有最后一级的部门信息,(不是父部门)
<select id="getNotParentDep" resultType="com.lzp.vhrserver.entity.DepartmentEntity">
SELECT id, NAME FROM department
WHERE isParent=0
</select>
2.获取所有已经报这个培训的员工id
<select id="getEidByTid" resultType="java.lang.Integer">
select eid from emp_train where tid=#{trainId}
</select>
3.获取各部门的员工信息,排除已经报名的。要判断,可能当前没有已经报名的员工
<select id="getEmpsByDepId" resultType="com.lzp.vhrserver.vo.OptionEmpVo">
SELECT id,NAME FROM employee WHERE departmentId=#{depId}
<if test="eidByTid != null and eidByTid.size()>0">
and id not in
<foreach collection="eidByTid" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</select>
7.添加培训人员第二步
执行添加培训人员,如果没选择培训人员提示选择
参数是当前培训id和选择的人员id
/**
* @Author lzp
* @Description: 新增选中的培训员工
* @Date: 10:08 2022/7/8
* @Param: [trainId, selectId]
* @return: com.lzp.vhrserver.utils.R
*/
@PostMapping("/doAddTrainEmps")
public R doAddTrainEmps(@RequestBody Map<String, Object> map){
Integer trainId = (Integer)map.get("trainId");
List<Integer> selectId = (List<Integer>) map.get("selectId");
if(selectId.size()==0){
return R.ok("请选择员工");
}
if(!this.empTrainEntityService.doAddTrainEmps(trainId,selectId)){
return R.error("添加失败");
}
return R.ok("添加成功");
}
service
执行添加,成功后更新总人数
@Transactional
public Boolean doAddTrainEmps(Integer trainId, List<Integer> selectId) {
//添加员工
Integer integer = this.empTrainEntityMapper.doAddTrainEmps(trainId, selectId);
if(integer<=0){
return false;
}
//获取总数
Integer total = this.empTrainEntityMapper.getTotal(trainId);
//更新总数
Integer integer1 = this.empTrainEntityMapper.updateTotal(total,trainId);
if(integer1<=0){
return false;
}
return true;
}
sql
遍历选择的员工id,进行添加
<insert id="doAddTrainEmps">
INSERT INTO emp_train
(eid, tid)
VALUES
<foreach collection ="selectId" item="eid" separator =",">
(#{eid}, #{trainId})
</foreach >
</insert>
7.员工调动
1.获取所有员工调动信息
controller
/**
*@Author: lzp
*@Description: 获取所有员工调动信息
*@Date: 2022/7/10 10:13
*@Params []
*@return com.lzp.vhrserver.utils.R
**/
@GetMapping("/getEmpRemoves")
public R getEmpRemoves(){
List<EmpRemoveVo> empRemoves = this.empRemoveEntityService.getEmpRemoves();
return R.ok("").setData(empRemoves);
}
sevice
遍历获取到的调动信息,根据id查找对应name
public List<EmpRemoveVo> getEmpRemoves() {
//获取到所有原调动信息
List<EmpRemoveVo> empRemoves = this.empRemoveEntityMapper.getEmpRemoves();
//遍历
List<EmpRemoveVo> empRemoveVoList = empRemoves.stream().map(item -> {
//获取原部门、原职位、新部门、新职位、员工姓名
String beforeDepName = this.departmentEntityMapper.getDepNameById(item.getBeforeDepId());
String afterDepName = this.departmentEntityMapper.getDepNameById(item.getAfterDepId());
String beforeJobName = this.positionEntityMapper.getPosNameById(item.getBeforeJobId());
String afterJobName = this.positionEntityMapper.getPosNameById(item.getAfterJobId());
String empName = this.employeeEntityMapper.getEmpNameById(item.getEid());
//添加到当前对象
item.setEmpName(empName);
item.setAfterDepName(afterDepName);
item.setAfterJobName(afterJobName);
item.setBeforeDepName(beforeDepName);
item.setBeforeJobName(beforeJobName);
return item;
}).collect(Collectors.toList());
return empRemoveVoList;
}
sql
<select id="getEmpRemoves" resultType="com.lzp.vhrserver.vo.EmpRemoveVo">
select * from employeeremove
</select>
2.添加调动信息
点击添加需要获取所有姓名、部门、职位
controller
/**
*@Author: lzp
*@Description: 新增员工调动
*@Date: 2022/7/10 14:07
*@Params [empRemoveVo]
*@return com.lzp.vhrserver.utils.R
**/
@PostMapping("/doAddEmpMove")
public R doAddEmpMove(@RequestBody EmpRemoveEntity empRemoveEntity){
Boolean aBoolean = this.empRemoveEntityService.doAddEmpMove(empRemoveEntity);
if(!aBoolean){
return R.error("添加失败");
}
return R.ok("添加成功~");
}
service
public Boolean doAddEmpMove(EmpRemoveEntity empRemoveEntity) {
//获取到当前员工的原部门信息 depAndPos:部门和职位id
DepAndPosIdVo depAndPos = this.employeeEntityMapper.getDepAndPos(empRemoveEntity.getEid());
//添加到实体类
empRemoveEntity.setBeforeDepId(depAndPos.getDepId());
empRemoveEntity.setBeforeJobId(depAndPos.getPosId());
empRemoveEntity.setRemoveDate(new Date());
depAndPos.setDepId(empRemoveEntity.getAfterDepId());
depAndPos.setPosId(empRemoveEntity.getAfterJobId());
//更新员工表中该员工的部门和职位id
Integer integer1 = this.employeeEntityMapper.updateDepAndPos(depAndPos, empRemoveEntity.getEid());
if(integer1 != 1){
return false;
}
//执行新增
Integer integer = this.empRemoveEntityMapper.doAddEmpMove(empRemoveEntity);
if(integer!=1){
return false;
}
return true;
}
sql
1.获取原部门信息,根据员工id
<select id="getDepAndPos" resultType="com.lzp.vhrserver.vo.DepAndPosIdVo">
select departmentId as 'depId',posId from employee where id =#{eid}
</select>
2.更新员工表中的部门和职位id
<update id="updateDepAndPos">
update employee set departmentId = #{depAndPos.depId},posId=#{depAndPos.posId}
where id =#{eid}
</update>
3.执行添加
id自增,无需指定
<insert id="doAddEmpMove">
insert into employeeremove
values(null,#{empRemoveEntity.eid},#{empRemoveEntity.afterDepId},
#{empRemoveEntity.afterJobId},#{empRemoveEntity.removeDate},
#{empRemoveEntity.reason},#{empRemoveEntity.remark},
#{empRemoveEntity.beforeDepId},#{empRemoveEntity.beforeJobId})
</insert>
3.删除员工调动信息
根据id删除
controller
/**
*@Author: lzp
*@Description: 删除员工调动信息
*@Date: 2022/7/10 15:08
*@Params [empRemoveId]
*@return com.lzp.vhrserver.utils.R
**/
@DeleteMapping("/deleteEmpRemove")
public R deleteEmpRemove(Integer empRemoveId){
if(!this.empRemoveEntityService.deleteEmpRemove(empRemoveId)){
return R.error("删除失败!");
}
return R.ok("删除成功");
}
service
sql返回作用条数,如果是1说明成功,其他为失败
public Boolean deleteEmpRemove(Integer empRemoveId) {
Integer integer = this.empRemoveEntityMapper.deleteEmpRemove(empRemoveId);
if(integer!=1){
return false;
}
return true;
}
sql
<delete id="deleteEmpRemove">
delete from employeeremove where id =#{empRemoveId}
</delete>
4.实体类和增强类
@Data
public class EmpRemoveEntity implements Serializable {
/**
*
*/
private Integer id;
/**
* 员工id
*/
private Integer eid;
/**
* 调动后部门
*/
private Integer afterDepId;
/**
* 调动后职位
*/
private Integer afterJobId;
/**
* 调动日期
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date removeDate;
/**
* 调动原因
*/
private String reason;
/**
* 备注
*/
private String remark;
/**
* 调动前部门
*/
private Integer beforeDepId;
/**
* 调动前部门职位
*/
private Integer beforeJobId;
private static final long serialVersionUID = 1L;
}
/**
*@author: lzp
*@create: 2022-07-10 10:15:35
*@description: 员工调动实体类增强类
*/
@Data
public class EmpRemoveVo extends EmpRemoveEntity {
public String empName;
public String beforeDepName;
public String beforeJobName;
public String afterDepName;
public String afterJobName;
}