当前位置:   article > 正文

Java --- 云尚办公之审批流程模块_java实现审批流程

java实现审批流程

目录

一、审批流程

二、审批类型代码实现 

三、审批模板实现 


一、审批流程

数据库表:

  1. CREATE TABLE `oa_process_type` (
  2. `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  3. `name` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '类型名称',
  4. `description` VARCHAR(255) DEFAULT NULL COMMENT '描述',
  5. `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  6. `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  7. `is_deleted` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '删除标记(0:不可用 1:可用)',
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=INNODB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='审批类型';
  10. SELECT * FROM oa_process_type;
  11. CREATE TABLE `oa_process_template` (
  12. `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '角色id',
  13. `name` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '模板名称',
  14. `icon_url` VARCHAR(100) DEFAULT NULL COMMENT '图标路径',
  15. `process_type_id` VARCHAR(255) DEFAULT NULL,
  16. `form_props` TEXT COMMENT '表单属性',
  17. `form_options` TEXT COMMENT '表单选项',
  18. `process_definition_key` VARCHAR(20) DEFAULT NULL COMMENT '流程定义key',
  19. `process_definition_path` VARCHAR(255) DEFAULT NULL COMMENT '流程定义上传路径',
  20. `process_model_id` VARCHAR(255) DEFAULT NULL COMMENT '流程定义模型id',
  21. `description` VARCHAR(255) DEFAULT NULL COMMENT '描述',
  22. `status` TINYINT(3) NOT NULL DEFAULT '0',
  23. `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  24. `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  25. `is_deleted` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '删除标记(0:不可用 1:可用)',
  26. PRIMARY KEY (`id`)
  27. ) ENGINE=INNODB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='审批模板';
  28. SELECT * FROM oa_process_template;
  29. CREATE TABLE `oa_process` (
  30. `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  31. `process_code` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '审批code',
  32. `user_id` BIGINT(1) NOT NULL DEFAULT '0' COMMENT '用户id',
  33. `process_template_id` BIGINT(20) DEFAULT NULL COMMENT '审批模板id',
  34. `process_type_id` BIGINT(20) DEFAULT NULL COMMENT '审批类型id',
  35. `title` VARCHAR(255) DEFAULT NULL COMMENT '标题',
  36. `description` VARCHAR(255) DEFAULT NULL COMMENT '描述',
  37. `form_values` TEXT COMMENT '表单值',
  38. `process_instance_id` VARCHAR(255) DEFAULT NULL COMMENT '流程实例id',
  39. `current_auditor` VARCHAR(255) DEFAULT NULL COMMENT '当前审批人',
  40. `status` TINYINT(3) DEFAULT NULL COMMENT '状态(0:默认 1:审批中 2:审批通过 -1:驳回)',
  41. `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  42. `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  43. `is_deleted` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '删除标记(0:不可用 1:可用)',
  44. PRIMARY KEY (`id`)
  45. ) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='审批类型';
  46. CREATE TABLE `oa_process_record` (
  47. `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  48. `process_id` BIGINT(20) NOT NULL DEFAULT '0' COMMENT '审批流程id',
  49. `description` VARCHAR(255) DEFAULT NULL COMMENT '审批描述',
  50. `status` TINYINT(3) DEFAULT '0' COMMENT '状态',
  51. `operate_user_id` BIGINT(20) NOT NULL DEFAULT '0' COMMENT '操作用户id',
  52. `operate_user` VARCHAR(20) DEFAULT NULL COMMENT '操作用户',
  53. `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  54. `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  55. `is_deleted` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '删除标记(0:不可用 1:可用)',
  56. PRIMARY KEY (`id`)
  57. ) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='审批记录';

二、审批类型代码实现 

后端代码:

  1. @Api(tags = "审批类型")
  2. @RestController
  3. @RequestMapping("/admin/process/processType")
  4. public class OaProcessTypeController {
  5. @Autowired
  6. private OaProcessTypeService processTypeService;
  7. @ApiOperation("分页查询")
  8. @GetMapping("/pageProcessType/{page}/{limit}")
  9. public Result pageProcessType(@PathVariable("page") Long page,
  10. @PathVariable("limit") Long limit){
  11. Page<ProcessType> typePage = new Page<>(page,limit);
  12. return Result.ok(processTypeService.page(typePage));
  13. }
  14. @ApiOperation("根据id查询")
  15. @GetMapping("/getById/{id}")
  16. public Result getById(@PathVariable("id") Long id){
  17. return Result.ok(processTypeService.getById(id));
  18. }
  19. @ApiOperation("添加")
  20. @PostMapping("/add")
  21. public Result add(@RequestBody ProcessType processType){
  22. processTypeService.save(processType);
  23. return Result.ok();
  24. }
  25. @ApiOperation("修改")
  26. @PutMapping("/update")
  27. public Result update(@RequestBody ProcessType processType){
  28. processTypeService.updateById(processType);
  29. return Result.ok();
  30. }
  31. @ApiOperation("删除")
  32. @DeleteMapping("/delete/{id}")
  33. public Result delete(@PathVariable("id") Long id){
  34. processTypeService.removeById(id);
  35. return Result.ok();
  36. }
  37. }

 前端代码:

创建src/api/process/processType.js

  1. import request from '@/utils/request'
  2. const api_name = '/admin/process/processType'
  3. export default {
  4. getPageList(page, limit) {
  5. return request({
  6. url: `${api_name}/pageProcessType/${page}/${limit}`,
  7. method: 'get'
  8. })
  9. },
  10. getById(id) {
  11. return request({
  12. url: `${api_name}/getById/${id}`,
  13. method: 'get'
  14. })
  15. },
  16. save(role) {
  17. return request({
  18. url: `${api_name}/add`,
  19. method: 'post',
  20. data: role
  21. })
  22. },
  23. updateById(role) {
  24. return request({
  25. url: `${api_name}/update`,
  26. method: 'put',
  27. data: role
  28. })
  29. },
  30. removeById(id) {
  31. return request({
  32. url: `${api_name}/delete/${id}`,
  33. method: 'delete'
  34. })
  35. }
  36. }

创建views/processSet/processType/list.vue

  1. <template>
  2. <div class="app-container">
  3. <!-- 工具条 -->
  4. <div class="tools-div">
  5. <el-button type="success" icon="el-icon-plus" size="mini" @click="add" :disabled="$hasBP('bnt.processType.add') === false">添 加</el-button>
  6. </div>
  7. <!-- banner列表 -->
  8. <el-table
  9. v-loading="listLoading"
  10. :data="list"
  11. stripe
  12. border
  13. style="width: 100%;margin-top: 10px;"
  14. >
  15. <el-table-column
  16. type="selection"
  17. width="55"
  18. />
  19. <el-table-column
  20. label="序号"
  21. width="70"
  22. align="center"
  23. >
  24. <template slot-scope="scope">
  25. {{ (page - 1) * limit + scope.$index + 1 }}
  26. </template>
  27. </el-table-column>
  28. <el-table-column prop="name" label="类型名称"/>
  29. <el-table-column prop="description" label="描述"/>
  30. <el-table-column prop="createTime" label="创建时间"/>
  31. <el-table-column prop="updateTime" label="更新时间"/>
  32. <el-table-column label="操作" width="200" align="center">
  33. <template slot-scope="scope">
  34. <el-button type="text" size="mini" @click="edit(scope.row.id)" :disabled="$hasBP('bnt.processType.update') === false">修改</el-button>
  35. <el-button type="text" size="mini" @click="removeDataById(scope.row.id)" :disabled="$hasBP('bnt.processType.remove') === false">删除</el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <!-- 分页组件 -->
  40. <el-pagination
  41. :current-page="page"
  42. :total="total"
  43. :page-size="limit"
  44. :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
  45. style="padding: 30px 0; text-align: center;"
  46. layout="sizes, prev, pager, next, jumper, ->, total, slot"
  47. @current-change="fetchData"
  48. @size-change="changeSize"
  49. />
  50. <el-dialog title="添加/修改" :visible.sync="dialogVisible" width="40%">
  51. <el-form ref="flashPromotionForm" label-width="150px" size="small" style="padding-right: 40px;">
  52. <el-form-item label="类型名称">
  53. <el-input v-model="processType.name"/>
  54. </el-form-item>
  55. <el-form-item label="描述">
  56. <el-input v-model="processType.description"/>
  57. </el-form-item>
  58. </el-form>
  59. <span slot="footer" class="dialog-footer">
  60. <el-button @click="dialogVisible = false" size="small">取 消</el-button>
  61. <el-button type="primary" @click="saveOrUpdate()" size="small">确 定</el-button>
  62. </span>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script>
  67. import api from '@/api/process/processType'
  68. const defaultForm = {
  69. id: '',
  70. name: '',
  71. description: ''
  72. }
  73. export default {
  74. data() {
  75. return {
  76. listLoading: true, // 数据是否正在加载
  77. list: null, // banner列表
  78. total: 0, // 数据库中的总记录数
  79. page: 1, // 默认页码
  80. limit: 10, // 每页记录数
  81. searchObj: {}, // 查询表单对象
  82. dialogVisible: false,
  83. processType: defaultForm,
  84. saveBtnDisabled: false
  85. }
  86. },
  87. // 生命周期函数:内存准备完毕,页面尚未渲染
  88. created() {
  89. this.fetchData()
  90. },
  91. // 生命周期函数:内存准备完毕,页面渲染成功
  92. mounted() {
  93. },
  94. methods: {
  95. // 当页码发生改变的时候
  96. changeSize(size) {
  97. console.log(size)
  98. this.limit = size
  99. this.fetchData(1)
  100. },
  101. // 加载列表数据
  102. fetchData(page = 1) {
  103. this.page = page
  104. api.getPageList(this.page, this.limit, this.searchObj).then(response => {
  105. this.list = response.data.records
  106. this.total = response.data.total
  107. // 数据加载并绑定成功
  108. this.listLoading = false
  109. })
  110. },
  111. // 重置查询表单
  112. resetData() {
  113. console.log('重置查询表单')
  114. this.searchObj = {}
  115. this.fetchData()
  116. },
  117. // 根据id删除数据
  118. removeDataById(id) {
  119. this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
  120. confirmButtonText: '确定',
  121. cancelButtonText: '取消',
  122. type: 'warning'
  123. }).then(() => { // promise
  124. // 点击确定,远程调用ajax
  125. return api.removeById(id)
  126. }).then((response) => {
  127. this.fetchData(this.page)
  128. this.$message.success(response.message)
  129. }).catch(() => {
  130. this.$message.info('取消删除')
  131. })
  132. },
  133. add() {
  134. this.dialogVisible = true
  135. this.processType = Object.assign({}, defaultForm)
  136. },
  137. edit(id) {
  138. this.dialogVisible = true
  139. this.fetchDataById(id)
  140. },
  141. fetchDataById(id) {
  142. api.getById(id).then(response => {
  143. this.processType = response.data
  144. })
  145. },
  146. saveOrUpdate() {
  147. this.saveBtnDisabled = true // 防止表单重复提交
  148. if (!this.processType.id) {
  149. this.saveData()
  150. } else {
  151. this.updateData()
  152. }
  153. },
  154. // 新增
  155. saveData() {
  156. api.save(this.processType).then(response => {
  157. this.$message.success(response.message || '操作成功')
  158. this.dialogVisible = false
  159. this.fetchData(this.page)
  160. })
  161. },
  162. // 根据id更新记录
  163. updateData() {
  164. api.updateById(this.processType).then(response => {
  165. this.$message.success(response.message || '操作成功')
  166. this.dialogVisible = false
  167. this.fetchData(this.page)
  168. })
  169. }
  170. }
  171. }
  172. </script>

三、审批模板实现 

分页查询审批模板:

  1. @Autowired
  2. private OaProcessTypeService processTypeService;
  3. //分页查询
  4. @Override
  5. public IPage<ProcessTemplate> selectPageProcessTem(Page<ProcessTemplate> templatePage) {
  6. //调用mapper方法实现分页查询
  7. Page<ProcessTemplate> processTemplatePage = baseMapper.selectPage(templatePage, null);
  8. //从分页数据中拿到list集合
  9. List<ProcessTemplate> records = processTemplatePage.getRecords();
  10. //从集合中获取审批类型id
  11. for (ProcessTemplate processTemplate:records) {
  12. //根据list集合id查询
  13. LambdaQueryWrapper<ProcessType> wrapper = new LambdaQueryWrapper<>();
  14. wrapper.eq(ProcessType::getId,processTemplate.getProcessTypeId());
  15. ProcessType processType = processTypeService.getOne(wrapper);
  16. if (processType == null){
  17. continue;
  18. }
  19. //封装数据
  20. processTemplate.setProcessTypeName(processType.getName());
  21. }
  22. return processTemplatePage;
  23. }
  1. @ApiOperation("分页查询")
  2. @GetMapping("/pageQuery/{page}/{limit}")
  3. public Result pageQuery(@PathVariable("page") Long page,
  4. @PathVariable("limit") Long limit){
  5. Page<ProcessTemplate> templatePage = new Page<>(page,limit);
  6. return Result.ok(processTemplateService.selectPageProcessTem(templatePage));
  7. }
  8. @ApiOperation(value = "新增")
  9. @PostMapping("save")
  10. public Result save(@RequestBody ProcessTemplate processTemplate) {
  11. processTemplateService.save(processTemplate);
  12. return Result.ok();
  13. }
  14. @ApiOperation(value = "修改")
  15. @PutMapping("update")
  16. public Result updateById(@RequestBody ProcessTemplate processTemplate) {
  17. processTemplateService.updateById(processTemplate);
  18. return Result.ok();
  19. }
  20. @ApiOperation(value = "删除")
  21. @DeleteMapping("remove/{id}")
  22. public Result remove(@PathVariable Long id) {
  23. processTemplateService.removeById(id);
  24. return Result.ok();
  25. }

添加审批模板:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/545156
推荐阅读
相关标签