1.创建请假单服务(com.imooc.oa.service)LeaveFormService.java
package com.imooc.oa.service; import com.imooc.oa.entity.Employee; import com.imooc.oa.entity.LeaveForm; import com.imooc.oa.entity.ProcessFlow; import com.imooc.oa.mapper.EmployeeMapper; import com.imooc.oa.mapper.LeaveFormMapper; import com.imooc.oa.mapper.ProcessFlowMapper; import com.imooc.oa.utils.MybatisUtils; import java.util.Date; public class LeaveFormService { /** * 创建请假单 * @param form 前端输入的请假单数据 * @return 持久化后的请假单对象 */ public LeaveForm createLeaveForm(LeaveForm form){ MybatisUtils.executeUpdate(sqlSession -> { //1.持久化form表单数据,8级以下员工表单状态为processing,8级(总经理)状态为approved EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Employee employee = employeeMapper.selectById(form.getEmployeeId()); if(employee.getLevel() == 8){ form.setState("approved"); }else{ form.setState("processing"); } LeaveFormMapper leaveFormMapper = sqlSession.getMapper(LeaveFormMapper.class); leaveFormMapper.insert(form); //2.增加第一条流程数据,说明表单已提交,状态为complete ProcessFlowMapper processFlowMapper = sqlSession.getMapper(ProcessFlowMapper.class); ProcessFlow flow1 = new ProcessFlow(); flow1.setFormId(form.getFormId()); flow1.setOperatorId(employee.getEmployeeId()); flow1.setAction("apply"); flow1.setCreateTime(new Date()); flow1.setOrderNo(1); flow1.setState("complete"); flow1.setIsLast(0); processFlowMapper.insert(flow1); //3.分情况创建其余流程数据 //3.1 7级以下员工,生成部门经理审批任务,请假时间大于72小时,还需生成总经理审批任务 //3.2 7级员工,仅生成总经理审批任务 //3.3 8级员工,生成总经理审批任务,系统自动通过 return null; }); return null; } }
2.获取上级领导
2.1 EmployeeService.java
public Employee selectLeader(Long employeeId){ Employee l = (Employee)MybatisUtils.executeQuery(sqlSession -> { EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class); Employee employee = mapper.selectById(employeeId); Map params = new HashMap<>(); Employee leader = null; if(employee.getLevel() < 7 ){ //查询部门经理 params.put("level", 7); params.put("departmentId", employee.getDepartmentId()); List<Employee> employees = mapper.selectByParams(params); leader = employees.get(0); }else if(employee.getLevel() == 7 ){ //查询总经理 params.put("level", 8); List<Employee> employees = mapper.selectByParams(params); leader = employees.get(0); }else if(employee.getLevel() == 8){ //返回自己 leader = employee; } return leader; }); return l; }
2.2 EmployeeMapper.java
public List<Employee> selectByParams(Map params);
2.3 employee.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.oa.mapper.EmployeeMapper"> <select id="selectById" parameterType="Long" resultType="com.imooc.oa.entity.Employee"> select * from adm_employee where employee_id = #{value} </select> <select id="selectByParams" parameterType="java.util.Map" resultType="com.imooc.oa.entity.Employee"> select * from adm_employee where 1=1 <if test="level != null"> and level = #{level} </if> <if test="departmentId != null"> and department_id = #{departmentId} </if> <if test="title != null"> and title = #{title} </if> </select> </mapper>
标签:请假,Service,flow1,oa,employee,018,import,com,imooc From: https://www.cnblogs.com/LLL0617/p/16980751.html