其实审批的本质就是两张表,一个审批状态表,一个审批表本身,审批流程的过程就是状态管理的过程。
为实现完整的请假申请流程,需要引入审批流的概念。这个流程不仅包括申请人提交申请,还包括选择审批人、审批操作(同意/驳回)以及状态的变更等功能。下面将详细介绍如何通过若依框架的 MVC 模式来实现请假申请和审批流程。 ### 1. 需求分析 完整的业务流程包含以下步骤: 1. 用户填写请假申请。 2. 用户选择审批人,并提交申请。 3. 审批人查看待审批的申请,并决定批准或驳回。 4. 若审批通过,申请状态变为“已通过”;若驳回,状态变为“已驳回”。 ### 2. 数据库表设计 为了支持审批功能,除了基本的请假申请数据表,还需要一个审批记录表来跟踪每个审批过程的状态。 **表1:`sys_leave_request`** (请假申请表) ```sql CREATE TABLE sys_leave_request ( request_id BIGINT PRIMARY KEY AUTO_INCREMENT, leave_type VARCHAR(50), -- 请假类型 start_time DATETIME, -- 开始时间 end_time DATETIME, -- 结束时间 reason TEXT, -- 请假原因 applicant VARCHAR(50), -- 申请人 status VARCHAR(20), -- 状态(待审批、已通过、已驳回) approver VARCHAR(50), -- 审批人 create_time DATETIME DEFAULT CURRENT_TIMESTAMP ); ``` **表2:`sys_leave_approval`** (审批记录表) ```sql CREATE TABLE sys_leave_approval ( approval_id BIGINT PRIMARY KEY AUTO_INCREMENT, request_id BIGINT, -- 对应的请假申请ID approver VARCHAR(50), -- 审批人 approval_status VARCHAR(20), -- 审批状态(同意、驳回) approval_time DATETIME, -- 审批时间 comments TEXT -- 审批意见 ); ``` ### 3. 数据模型(Model) **请假申请实体类:`LeaveRequest`** ```java package com.ruoyi.project.system.leave.domain; import java.util.Date; public class LeaveRequest { private Long requestId; private String leaveType; private Date startTime; private Date endTime; private String reason; private String applicant; private String status; private String approver; // Getters 和 Setters 略 } ``` **审批记录实体类:`LeaveApproval`** ```java package com.ruoyi.project.system.leave.domain; import java.util.Date; public class LeaveApproval { private Long approvalId; private Long requestId; private String approver; private String approvalStatus; private Date approvalTime; private String comments; // Getters 和 Setters 略 } ``` ### 4. 数据库操作(Mapper) #### 4.1 请假申请 Mapper ```java package com.ruoyi.project.system.leave.mapper; import com.ruoyi.project.system.leave.domain.LeaveRequest; import java.util.List; public interface LeaveRequestMapper { List<LeaveRequest> selectAllRequests(); LeaveRequest selectRequestById(Long requestId); int insertLeaveRequest(LeaveRequest leaveRequest); int updateLeaveRequest(LeaveRequest leaveRequest); int deleteLeaveRequestById(Long requestId); // 查询待审批的申请 List<LeaveRequest> selectPendingRequests(String approver); } ``` #### 4.2 审批记录 Mapper ```java package com.ruoyi.project.system.leave.mapper; import com.ruoyi.project.system.leave.domain.LeaveApproval; import java.util.List; public interface LeaveApprovalMapper { List<LeaveApproval> selectApprovalsByRequestId(Long requestId); int insertLeaveApproval(LeaveApproval leaveApproval); } ``` ### 5. 服务层(Service) #### 5.1 请假申请服务接口 ```java package com.ruoyi.project.system.leave.service; import com.ruoyi.project.system.leave.domain.LeaveRequest; import java.util.List; public interface ILeaveRequestService { List<LeaveRequest> selectAllRequests(); LeaveRequest selectRequestById(Long requestId); int insertLeaveRequest(LeaveRequest leaveRequest); int updateLeaveRequest(LeaveRequest leaveRequest); int deleteLeaveRequestById(Long requestId); List<LeaveRequest> selectPendingRequests(String approver); } ``` #### 5.2 审批记录服务接口 ```java package com.ruoyi.project.system.leave.service; import com.ruoyi.project.system.leave.domain.LeaveApproval; import java.util.List; public interface ILeaveApprovalService { List<LeaveApproval> selectApprovalsByRequestId(Long requestId); int insertLeaveApproval(LeaveApproval leaveApproval); } ``` ### 6. 控制器(Controller) #### 6.1 请假申请控制器 ```java package com.ruoyi.project.system.leave.controller; import com.ruoyi.project.system.leave.domain.LeaveRequest; import com.ruoyi.project.system.leave.service.ILeaveRequestService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/system/leave") public class LeaveRequestController { @Autowired private ILeaveRequestService leaveRequestService; // 获取所有请假申请 @GetMapping("/list") public List<LeaveRequest> list() { return leaveRequestService.selectAllRequests(); } // 根据ID查询请假申请 @GetMapping("/{requestId}") public LeaveRequest getInfo(@PathVariable Long requestId) { return leaveRequestService.selectRequestById(requestId); } // 提交请假申请 @PostMapping public int add(@RequestBody LeaveRequest leaveRequest) { leaveRequest.setStatus("待审批"); return leaveRequestService.insertLeaveRequest(leaveRequest); } // 获取待审批的申请列表 @GetMapping("/pending/{approver}") public List<LeaveRequest> pending(@PathVariable String approver) { return leaveRequestService.selectPendingRequests(approver); } // 删除请假申请 @DeleteMapping("/{requestId}") public int remove(@PathVariable Long requestId) { return leaveRequestService.deleteLeaveRequestById(requestId); } } ``` #### 6.2 审批记录控制器 ```java package com.ruoyi.project.system.leave.controller; import com.ruoyi.project.system.leave.domain.LeaveApproval; import com.ruoyi.project.system.leave.domain.LeaveRequest; import com.ruoyi.project.system.leave.service.ILeaveApprovalService; import com.ruoyi.project.system.leave.service.ILeaveRequestService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/system/leave/approval") public class LeaveApprovalController { @Autowired private ILeaveApprovalService leaveApprovalService; @Autowired private ILeaveRequestService leaveRequestService; // 审批请假申请 @PostMapping public int approve(@RequestBody LeaveApproval leaveApproval) { LeaveRequest leaveRequest = leaveRequestService.selectRequestById(leaveApproval.getRequestId()); // 更新审批状态 leaveApproval.setApprovalTime(new Date()); leaveApprovalService.insertLeaveApproval(leaveApproval); // 更新请假申请状态 if ("同意".equals(leaveApproval.getApprovalStatus())) { leaveRequest.setStatus("已通过"); } else { leaveRequest.setStatus("已驳回"); } return leaveRequestService.updateLeaveRequest(leaveRequest); } } ``` ### 7. 前端页面开发(Vue.js) #### 7.1 请假申请页面 ```html <template> <div> <a-form @submit="submitForm"> <a-form-item label="请假类型"> <a-select v-model="form.leaveType"> <a-select-option value="事假">事假</a-select-option> <a-select-option value="病假">病假</a-select-option> <a-select-option value="年假">年假</a-select-option> <a-select-option value="调休假">调休假</a-select-option> </a-select> </a-form-item> <a-form-item label="请假时间"> <a-date-picker v-model="form.startTime" /> 至 <a-date-picker v-model="form.endTime" /> </a-form-item> <a-form-item label="请假原因"> <a-textarea v-model="form.reason" /> </a-form-item> <a-form-item label="审批人"> <a-input v-model="form.approver" /> </a-form-item> <a-form-item> <a-button type="primary" @click="submitForm">提交</a-button> </a-form-item> </a-form> </div> </template> <script> import { submitLeaveRequest } from '@/api/system/leave'; export default { data() { return { form: { leaveType: '', startTime: '', endTime: '', reason: '', approver: '', }, }; }, methods: { submitForm() { submitLeaveRequest(this.form).then(() => { this.$message.success('提交成功'); }); }, }, }; </ script> ``` #### 7.2 审批页面 ```html <template> <div> <a-table :columns="columns" :dataSource="pendingList" rowKey="requestId"> <template slot="action" slot-scope="text, record"> <a-button type="link" @click="approveRequest(record, '同意')">同意</a-button> <a-button type="link" @click="approveRequest(record, '驳回')">驳回</a-button> </template> </a-table> </div> </template> <script> import { getPendingRequests, approveLeaveRequest } from '@/api/system/leave'; export default { data() { return { pendingList: [], columns: [ { title: '请假类型', dataIndex: 'leaveType' }, { title: '申请人', dataIndex: 'applicant' }, { title: '状态', dataIndex: 'status' }, { title: '操作', key: 'action', scopedSlots: { customRender: 'action' } }, ], }; }, mounted() { this.loadPendingRequests(); }, methods: { loadPendingRequests() { getPendingRequests().then((response) => { this.pendingList = response; }); }, approveRequest(record, status) { approveLeaveRequest({ requestId: record.requestId, approver: this.$store.state.user.name, approvalStatus: status, comments: '审批意见', }).then(() => { this.$message.success(`${status}成功`); this.loadPendingRequests(); }); }, }, }; </script> ``` ### 8. 接口对接 ```javascript import request from '@/utils/request'; // 提交请假申请 export function submitLeaveRequest(data) { return request({ url: '/system/leave', method: 'post', data, }); } // 获取待审批的申请 export function getPendingRequests(approver) { return request({ url: `/system/leave/pending/${approver}`, method: 'get', }); } // 审批请假申请 export function approveLeaveRequest(data) { return request({ url: '/system/leave/approval', method: 'post', data, }); } ``` ### 总结 这个版本实现了完整的请假申请与审批流程,包括提交请假申请、选择审批人、审批操作以及通过/驳回状态的处理。审批人与申请人之间的互动通过数据库的请假申请和审批记录表进行管理,前端用户界面提供了申请提交和审批功能。
为实现完整的请假申请流程,需要引入审批流的概念。这个流程不仅包括申请人提交申请,还包括选择审批人、审批操作(同意/驳回)以及状态的变更等功能。下面将详细介绍如何通过若依框架的 MVC 模式来实现请假申请和审批流程。
### 1. 需求分析
完整的业务流程包含以下步骤:
1. 用户填写请假申请。2. 用户选择审批人,并提交申请。3. 审批人查看待审批的申请,并决定批准或驳回。4. 若审批通过,申请状态变为“已通过”;若驳回,状态变为“已驳回”。
### 2. 数据库表设计
为了支持审批功能,除了基本的请假申请数据表,还需要一个审批记录表来跟踪每个审批过程的状态。
**表1:`sys_leave_request`** (请假申请表)```sqlCREATE TABLE sys_leave_request ( request_id BIGINT PRIMARY KEY AUTO_INCREMENT, leave_type VARCHAR(50), -- 请假类型 start_time DATETIME, -- 开始时间 end_time DATETIME, -- 结束时间 reason TEXT, -- 请假原因 applicant VARCHAR(50), -- 申请人 status VARCHAR(20), -- 状态(待审批、已通过、已驳回) approver VARCHAR(50), -- 审批人 create_time DATETIME DEFAULT CURRENT_TIMESTAMP);```
**表2:`sys_leave_approval`** (审批记录表)```sqlCREATE TABLE sys_leave_approval ( approval_id BIGINT PRIMARY KEY AUTO_INCREMENT, request_id BIGINT, -- 对应的请假申请ID approver VARCHAR(50), -- 审批人 approval_status VARCHAR(20), -- 审批状态(同意、驳回) approval_time DATETIME, -- 审批时间 comments TEXT -- 审批意见);```
### 3. 数据模型(Model)
**请假申请实体类:`LeaveRequest`**```javapackage com.ruoyi.project.system.leave.domain;
import java.util.Date;
public class LeaveRequest { private Long requestId; private String leaveType; private Date startTime; private Date endTime; private String reason; private String applicant; private String status; private String approver;
// Getters 和 Setters 略}```
**审批记录实体类:`LeaveApproval`**```javapackage com.ruoyi.project.system.leave.domain;
import java.util.Date;
public class LeaveApproval { private Long approvalId; private Long requestId; private String approver; private String approvalStatus; private Date approvalTime; private String comments;
// Getters 和 Setters 略}```
### 4. 数据库操作(Mapper)
#### 4.1 请假申请 Mapper
```javapackage com.ruoyi.project.system.leave.mapper;
import com.ruoyi.project.system.leave.domain.LeaveRequest;import java.util.List;
public interface LeaveRequestMapper { List<LeaveRequest> selectAllRequests(); LeaveRequest selectRequestById(Long requestId); int insertLeaveRequest(LeaveRequest leaveRequest); int updateLeaveRequest(LeaveRequest leaveRequest); int deleteLeaveRequestById(Long requestId); // 查询待审批的申请 List<LeaveRequest> selectPendingRequests(String approver);}```
#### 4.2 审批记录 Mapper
```javapackage com.ruoyi.project.system.leave.mapper;
import com.ruoyi.project.system.leave.domain.LeaveApproval;import java.util.List;
public interface LeaveApprovalMapper { List<LeaveApproval> selectApprovalsByRequestId(Long requestId); int insertLeaveApproval(LeaveApproval leaveApproval);}```
### 5. 服务层(Service)
#### 5.1 请假申请服务接口
```javapackage com.ruoyi.project.system.leave.service;
import com.ruoyi.project.system.leave.domain.LeaveRequest;import java.util.List;
public interface ILeaveRequestService { List<LeaveRequest> selectAllRequests(); LeaveRequest selectRequestById(Long requestId); int insertLeaveRequest(LeaveRequest leaveRequest); int updateLeaveRequest(LeaveRequest leaveRequest); int deleteLeaveRequestById(Long requestId); List<LeaveRequest> selectPendingRequests(String approver);}```
#### 5.2 审批记录服务接口
```javapackage com.ruoyi.project.system.leave.service;
import com.ruoyi.project.system.leave.domain.LeaveApproval;import java.util.List;
public interface ILeaveApprovalService { List<LeaveApproval> selectApprovalsByRequestId(Long requestId); int insertLeaveApproval(LeaveApproval leaveApproval);}```
### 6. 控制器(Controller)
#### 6.1 请假申请控制器
```javapackage com.ruoyi.project.system.leave.controller;
import com.ruoyi.project.system.leave.domain.LeaveRequest;import com.ruoyi.project.system.leave.service.ILeaveRequestService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController@RequestMapping("/system/leave")public class LeaveRequestController { @Autowired private ILeaveRequestService leaveRequestService;
// 获取所有请假申请 @GetMapping("/list") public List<LeaveRequest> list() { return leaveRequestService.selectAllRequests(); }
// 根据ID查询请假申请 @GetMapping("/{requestId}") public LeaveRequest getInfo(@PathVariable Long requestId) { return leaveRequestService.selectRequestById(requestId); }
// 提交请假申请 @PostMapping public int add(@RequestBody LeaveRequest leaveRequest) { leaveRequest.setStatus("待审批"); return leaveRequestService.insertLeaveRequest(leaveRequest); }
// 获取待审批的申请列表 @GetMapping("/pending/{approver}") public List<LeaveRequest> pending(@PathVariable String approver) { return leaveRequestService.selectPendingRequests(approver); }
// 删除请假申请 @DeleteMapping("/{requestId}") public int remove(@PathVariable Long requestId) { return leaveRequestService.deleteLeaveRequestById(requestId); }}```
#### 6.2 审批记录控制器
```javapackage com.ruoyi.project.system.leave.controller;
import com.ruoyi.project.system.leave.domain.LeaveApproval;import com.ruoyi.project.system.leave.domain.LeaveRequest;import com.ruoyi.project.system.leave.service.ILeaveApprovalService;import com.ruoyi.project.system.leave.service.ILeaveRequestService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.*;
@RestController@RequestMapping("/system/leave/approval")public class LeaveApprovalController { @Autowired private ILeaveApprovalService leaveApprovalService;
@Autowired private ILeaveRequestService leaveRequestService;
// 审批请假申请 @PostMapping public int approve(@RequestBody LeaveApproval leaveApproval) { LeaveRequest leaveRequest = leaveRequestService.selectRequestById(leaveApproval.getRequestId());
// 更新审批状态 leaveApproval.setApprovalTime(new Date()); leaveApprovalService.insertLeaveApproval(leaveApproval);
// 更新请假申请状态 if ("同意".equals(leaveApproval.getApprovalStatus())) { leaveRequest.setStatus("已通过"); } else { leaveRequest.setStatus("已驳回"); }
return leaveRequestService.updateLeaveRequest(leaveRequest); }}```
### 7. 前端页面开发(Vue.js)
#### 7.1 请假申请页面
```html<template> <div> <a-form @submit="submitForm"> <a-form-item label="请假类型"> <a-select v-model="form.leaveType"> <a-select-option value="事假">事假</a-select-option> <a-select-option value="病假">病假</a-select-option> <a-select-option value="年假">年假</a-select-option> <a-select-option value="调休假">调休假</a-select-option> </a-select> </a-form-item>
<a-form-item label="请假时间"> <a-date-picker v-model="form.startTime" /> 至 <a-date-picker v-model="form.endTime" /> </a-form-item>
<a-form-item label="请假原因"> <a-textarea v-model="form.reason" /> </a-form-item>
<a-form-item label="审批人"> <a-input v-model="form.approver" /> </a-form-item>
<a-form-item> <a-button type="primary" @click="submitForm">提交</a-button> </a-form-item> </a-form> </div></template>
<script>import { submitLeaveRequest } from '@/api/system/leave';
export default { data() { return { form: { leaveType: '', startTime: '', endTime: '', reason: '', approver: '', }, }; }, methods: { submitForm() { submitLeaveRequest(this.form).then(() => { this.$message.success('提交成功'); }); }, },};</
script>```
#### 7.2 审批页面
```html<template> <div> <a-table :columns="columns" :dataSource="pendingList" rowKey="requestId"> <template slot="action" slot-scope="text, record"> <a-button type="link" @click="approveRequest(record, '同意')">同意</a-button> <a-button type="link" @click="approveRequest(record, '驳回')">驳回</a-button> </template> </a-table> </div></template>
<script>import { getPendingRequests, approveLeaveRequest } from '@/api/system/leave';
export default { data() { return { pendingList: [], columns: [ { title: '请假类型', dataIndex: 'leaveType' }, { title: '申请人', dataIndex: 'applicant' }, { title: '状态', dataIndex: 'status' }, { title: '操作', key: 'action', scopedSlots: { customRender: 'action' } }, ], }; }, mounted() { this.loadPendingRequests(); }, methods: { loadPendingRequests() { getPendingRequests().then((response) => { this.pendingList = response; }); }, approveRequest(record, status) { approveLeaveRequest({ requestId: record.requestId, approver: this.$store.state.user.name, approvalStatus: status, comments: '审批意见', }).then(() => { this.$message.success(`${status}成功`); this.loadPendingRequests(); }); }, },};</script>```
### 8. 接口对接
```javascriptimport request from '@/utils/request';
// 提交请假申请export function submitLeaveRequest(data) { return request({ url: '/system/leave', method: 'post', data, });}
// 获取待审批的申请export function getPendingRequests(approver) { return request({ url: `/system/leave/pending/${approver}`, method: 'get', });}
// 审批请假申请export function approveLeaveRequest(data) { return request({ url: '/system/leave/approval', method: 'post', data, });}```
### 总结
这个版本实现了完整的请假申请与审批流程,包括提交请假申请、选择审批人、审批操作以及通过/驳回状态的处理。审批人与申请人之间的互动通过数据库的请假申请和审批记录表进行管理,前端用户界面提供了申请提交和审批功能。 标签:请假,若依,软件开发,leave,system,---,审批,import,com From: https://www.cnblogs.com/GKLBB/p/18461518