在线审批流实现

平时的请假、合同申请、采购单申请、发货单申请等流程如果均可实现在线审批,将会很大程度上节省资源,下面就是一个实现流程。

一、审批流数据模型设计(使用power designer)

二、实现的存储过程

审批通过功能:

-- =============================================
-- Notes:        流程审批--通过
-- =============================================
Create proc [dbo].[WorkFlowToDoAudit]
@WTDId int,
@UId int,
@Operation int,
@OperationWord nvarchar(200)
as 
begin
	declare @sql NVARCHAR(1000),@TableName nvarchar(100),@TableField NVARCHAR(100),@FormId int,@TableIdName NVARCHAR(50),@WFId int,@WFNId int,@WFATId int,@WFARId int,@NextNodeId int,@WFNName nvarchar(50),@YWUId int
	select @WFId=WFId,@WFNId=CurrentNodeId,@WFNName=CurrentNodeName,@TableName=TableName,@FormId=FormId,@YWUId=[UId] from WorkToDo where WTDId=@WTDId
	select @WFARId=WFARId,@WFATId=WFATId from WorkFlowNode where WFNId=@WFNId
	--获取表单的id名称,获取表单条件字段名称
	select @TableIdName=TableIdName,@TableField=TableField from WorkFlowForm where [TabelName]=@TableName
	declare @Count int
	---开始一个事务
	begin transaction T
	--@Count检测是否插入成功的变量
	set @Count=0
	--写入审批词
	update WorkNodeApprover set Operation=@Operation,OperationWord=@OperationWord,AddDate=getdate() where WTDId=@WTDId and WFNId=@WFNId and UId=@UId
	set @Count=@Count+@@error
	----添加抄送人
	--select count(1) from WorkViewUser where WTDId=@WTDId and UId=@UId
	--insert into WorkViewUser (WTDId,[UId],UName)
	--select @WTDId,Id,name from users where department>0 and charindex(','+ltrim(Id)+',',','+@ViewUsers+',')>0
	--set @Count=@Count+@@error
	--添加工作流程节点(日志)
	insert into WorkToDoNode values(@WTDId,@WFNId,@WFNName,@WFATId,@WFARId,@UId,@Operation)
	set @Count=@Count+@@error
	if(@WFARId=1)
	begin
		--其他审批人状态为3,即表示当前结点别人已审批通过
		update WorkNodeApprover set Operation=3 where WTDId=@WTDId and WFNId=@WFNId and Operation=0
		set @Count=@Count+@@error
		--查询下一个节点
		exec WorkFlowGetNextNote @WFId,@WFNId,@TableName,@TableIdName,@FormId,@NextNodeId output
		if(@NextNodeId>0)
		begin
			exec WorkFlowNextAdd @WFId,@WTDId,@NextNodeId,@YWUId,@Count out
		end
		else--结束
		begin
			update WorkToDo set WTDStatus=4,CurrentNodeId=0,CurrentNodeName='结束' where WTDId=@WTDId
			set @Count=@Count+@@error
		end
	end
	else
	begin
		declare @NoApprCount int
		set @NoApprCount=0
		select @NoApprCount=COUNT(0) FROM WorkNodeApprover WHERE WTDId=@WTDId AND Operation=0
		if(@NoApprCount=0)
		begin
			--查询下一个节点
			exec WorkFlowGetNextNote @WFId,@WFNId,@TableName,@TableIdName,@FormId,@NextNodeId output
			if(@NextNodeId>0)
				exec WorkFlowNextAdd @WFId,@WTDId,@NextNodeId,@YWUId,@Count out
			else--结束
				update WorkToDo set WTDStatus=4,CurrentNodeId=0,CurrentNodeName='结束' where WTDId=@WTDId
		end
		else
			update WorkToDo set WTDStatus=2 where WTDId=@WTDId
	end
	if(@Count>0)
		RollBack transaction T
	else
		commit transaction T
end
-- =============================================
-- Notes:        根据条件查询某个流程的下一个节点
-- =============================================
ALTER proc [dbo].[WorkFlowGetNextNote]
@WFId int,
@NodeId int,
@TableName nvarchar(100),
@TableIdName NVARCHAR(50),
@FormId int,
@JumpNode1 int out
as
begin
	declare @sql NVARCHAR(1000),@ConditionSign NVARCHAR(50),@ConditionValue NVARCHAR(50),@JumpNode int,@TiaoJian nvarchar(50),@TableField NVARCHAR(100),@DataVal NVARCHAR(100),@CondCount int,@Flag int,@NodeIndex int
	set @JumpNode1=0
	set @Flag=0
	select @CondCount=COUNT(0) from WorkFlowCondition where WFNId=@NodeId
	if(@CondCount>0)
	begin
		declare cursor1 cursor for
		select ConditionSign,ConditionValue,JumpNode,TiaoJian,TableField from WorkFlowCondition where WFNId=@NodeId and TableName=@TableName order by OrderID asc
		open cursor1                       
			fetch next from cursor1 into @ConditionSign,@ConditionValue,@JumpNode,@TiaoJian,@TableField
			while @@fetch_status=0
			begin
				--获取对应的表对应字段的值@DataVal
				set @sql='select @DataVal='+@TableField+' FROM '+@TableName+' where '+@TableIdName+'='+cast(@FormId as NVARCHAR(50))
				exec sp_executesql @sql,N'@DataVal NVARCHAR(100) out',@DataVal out
				select @NodeIndex=CHARINDEX(',',NextNodes) from WorkFlowNode where WFNId=@NodeId and IsDelete=0
				if(@ConditionSign='>' and cast(@DataVal as int)>cast(@ConditionValue as int))
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)--多个跳转节点
						break
				end
				else if(@ConditionSign='>=' and cast(@DataVal as int)>=cast(@ConditionValue as int))
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				else if(@ConditionSign='<' and cast(@DataVal as int)<cast(@ConditionValue as int))
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				else if(@ConditionSign='<=' and cast(@DataVal as int)<=cast(@ConditionValue as int))
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				else if(@ConditionSign='=' and cast(@DataVal as int)=cast(@ConditionValue as int))
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				else if(@ConditionSign='!=' and cast(@DataVal as int)!=cast(@ConditionValue as int))
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				else if(@ConditionSign='包含' and CHARINDEX(cast(@ConditionValue as nvarchar(50)),cast(@DataVal as nvarchar(50)))>-1)
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				else if(@ConditionSign='不包含' and CHARINDEX(cast(@ConditionValue as nvarchar(50)),cast(@DataVal as nvarchar(50)))<1)
				begin
					set @Flag=@Flag+1
					if(@NodeIndex>0)
						break
				end
				fetch next from cursor1 into @ConditionSign,@ConditionValue,@JumpNode,@TiaoJian,@TableField
			end
		close cursor1  
		deallocate cursor1
		if(@TiaoJian='AND' and @CondCount=@Flag)
			set @JumpNode1=@JumpNode
		else if(@TiaoJian='OR' and @Flag>0)
			set @JumpNode1=@JumpNode
	end
	else
	begin
		select @JumpNode1=WFNId from WorkFlowNode where WFId=@WFId and NodeNum=cast((select NextNodes from WorkFlowNode where WFNId=@NodeId and IsDelete=0) as int)
	end	
end

 

-- =============================================
-- Notes:        跳到下一节点时插入流程相关表
-- =============================================
ALTER PROC [dbo].[WorkFlowNextAdd]
@WFId int,
@WTDId int,
@NextNodeId int,
@YWUId int,
@Count int out
as
begin
	declare @NextNodeName nvarchar(50),@WFARId int,@WFATId int,@Agent nvarchar(max),@YWDeptId int,@AgentNames nvarchar(max)
	select @NextNodeName=WFNName,@WFARId=WFARId,@WFATId=WFATId,@Agent=Agent,@AgentNames=AgentNames from WorkFlowNode where WFNId=@NextNodeId
	set @YWDeptId=dbo.GetDeptIdByUId(@YWUId)
	--查询添加节点审批人
	if(@WFATId=1)--角色
	begin
		if(charindex('业务组长',@AgentNames)>0)
		begin
			insert into WorkNodeApprover (WFId,WFNId,WFNName,WTDId,UId,UName,Operation,AddDate)
			select @WFId,@NextNodeId,@NextNodeName,@WTDId,id,name,0,getdate() from dbo.users a left join dbo.CRM_UserRole b on a.id=b.[UID] where a.department>0 and charindex(','+ltrim(b.RID)+',',','+@Agent+',')>0 and a.department=@YWDeptId
		end
		else
		begin
			insert into WorkNodeApprover (WFId,WFNId,WFNName,WTDId,UId,UName,Operation,AddDate)
			select @WFId,@NextNodeId,@NextNodeName,@WTDId,id,name,0,getdate() from dbo.users a left join dbo.CRM_UserRole b on a.id=b.[UID] where a.department>0 and charindex(','+ltrim(b.RID)+',',','+@Agent+',')>0
		end			
	end
	else if(@WFATId=2)--部门
	begin
		insert into WorkNodeApprover (WFId,WFNId,WFNName,WTDId,UId,UName,Operation,AddDate)
		select @WFId,@NextNodeId,@NextNodeName,@WTDId,id,name,0,getdate() from users where department>0 and charindex(','+ltrim(department)+',',','+@Agent+',')>0	
	end
	else if(@WFATId=3)--人员
	begin
		insert into WorkNodeApprover (WFId,WFNId,WFNName,WTDId,UId,UName,Operation,AddDate)
		select @WFId,@NextNodeId,@NextNodeName,@WTDId,id,name,0,getdate() from users where department>0 and charindex(','+ltrim(id)+',',','+@Agent+',')>0	
	end
	else if(@WFATId=4)--职务
	begin
		insert into WorkNodeApprover (WFId,WFNId,WFNName,WTDId,UId,UName,Operation,AddDate)
		select @WFId,@NextNodeId,@NextNodeName,@WTDId,id,name,0,getdate() from users where department>0 and charindex(','+ltrim(duty)+',',','+@Agent+',')>0	
	end
	set @Count=@Count+@@error
	update WorkToDo set CurrentNodeId=@NextNodeId,CurrentNodeName=@NextNodeName where WTDId=@WTDId
	set @Count=@Count+@@error
end

审批不通过功能:

-- =============================================
-- Notes:        流程审批--驳回
-- =============================================
ALTER proc [dbo].[WorkFlowToDoNotThrough]
@WTDId int,
@UId int,
@OperationWord nvarchar(200)
as 
begin
	declare @Count int,@WFNId int,@WFNName nvarchar(50),@WFATId int,@WFARId int
	select @WFNId=CurrentNodeId,@WFNName=CurrentNodeName from WorkToDo where WTDId=@WTDId
	select @WFATId=WFATId,@WFARId=WFARId from WorkFlowNode where WFNId=@WFNId
	---开始一个事务
	begin transaction T
	--@Count检测是否插入成功的变量
	set @Count=0
	update WorkNodeApprover set Operation=2,OperationWord=@OperationWord,AddDate=getdate() where WTDId=@WTDId and WFNId=@WFNId and UId=@UId and Operation=0
	set @Count=@Count+@@error
	update WorkNodeApprover set Operation=3 where WTDId=@WTDId and WFNId=@WFNId and Operation=0
	set @Count=@Count+@@error
	insert into WorkToDoNode values(@WTDId,@WFNId,@WFNName,@WFATId,@WFARId,@UId,2)
	set @Count=@Count+@@error
	update WorkToDo set WTDStatus=5 where WTDId=@WTDId
	set @Count=@Count+@@error
	if(@Count>0)
		RollBack transaction T
	else
		commit transaction T
end

当前工作所走的流程图例:

-- =============================================
-- Notes:        查询某个流程的节点列表
-- =============================================
ALTER proc [dbo].[WorkFlowGetNodeList]
@WTDId int,
@NodeList nvarchar(500) out
as 
begin
	declare @TableName nvarchar(100),@TableField NVARCHAR(100),@WFNId int,@JumpNode1 int,@returnVal nvarchar(500),@NodeId int,@WFId int,@TableIdName NVARCHAR(50),@FormId int
	set @JumpNode1=0	
	--获取工作文档内容	
	select @TableName=TableName,@FormId=FormId,@WFId=WFId from WorkToDo where WTDId=@WTDId
	--获取审批流程的第一个节点
	select top 1 @NodeId=WFNId from WorkFlowNode where WFId=@WFId order by NodeNum asc
	--获取表单的id名称,获取表单条件字段名称
	select @TableIdName=TableIdName,@TableField=TableField from WorkFlowForm where [TabelName]=@TableName
	exec WorkFlowGetNotes @WFId,@NodeId,@TableName,@TableIdName,@FormId,@JumpNode1,@returnVal output
	set @NodeList=@returnVal
	print @NodeList
end
-- =============================================
-- Notes:        根据条件查询某个流程的流转节点(递归)
-- =============================================
ALTER proc [dbo].[WorkFlowGetNotes]
@WFId int,
@NodeId int,
@TableName nvarchar(100),
@TableIdName NVARCHAR(50),
@FormId int,
@JumpNode1 int,
@returnVal nvarchar(500) output
as
begin
	exec WorkFlowGetNextNote @WFId,@NodeId,@TableName,@TableIdName,@FormId,@JumpNode1 output
	declare @WFNName nvarchar(50)	
    if(@returnVal is null)
    begin
		select @WFNName=WFNName from WorkFlowNode where WFNId=@NodeId
		set @returnVal=@WFNName
	end
	if(@JumpNode1>0)
	begin
		select @WFNName=WFNName from WorkFlowNode where WFNId=@JumpNode1
		set @returnVal=@returnVal+' → '+@WFNName
		exec WorkFlowGetNotes @WFId,@JumpNode1,@TableName,@TableIdName,@FormId,@JumpNode1,@returnVal output
	end
end

工作流程表触发器:

-- =============================================
-- Notes:        流程审批完成触发器
-- =============================================
ALTER trigger [dbo].[WorkToDo_trg]
on [dbo].[WorkToDo]
after update 
as 
begin
	declare @Id int,@Status int,@TableName nvarchar(200)
	select @Status=WTDStatus,@TableName=TableName,@Id=FormId from inserted
	if(@Status=4)--完成
	begin
		if(@TableName='Agreement')
			update Agreement set CState=2 where Id=@Id
		else if(@TableName='Leave')
			update Leave set IsApprove=1 where Id=@Id
	end
	else if(@Status=5)--退回
	begin
		if(@TableName='Agreement')--合同
		begin
			update Agreement set CState=3 where Id=@Id
		end
		else if(@TableName='PurchaseOrder')--采购单
		begin
			update PurchaseOrder set OrderState=7 where Id=@Id
		end
		else if(@TableName='DeliveryInformation')--发货单
		begin
			update DeliveryInformation set [State]=0 where Id=@Id
		end
		else if(@TableName='Leave')--请假
			update Leave set IsApprove=2 where Id=@Id
	end
end

三、相关界面

 

 

 

### 回答1: 可以使用Activiti或者Flowable框架来实现Spring Boot的简单审批。这些框架提供了程引擎和相关的API,可以轻松地定义和管理程,包括审批程。可以使用这些框架来定义程模型、任务和用户,然后使用Spring Boot集成这些框架来实现审批。 ### 回答2: Spring Boot是一款基于Spring框架的开发工具,用于简化Java应用程序的开发和部署。要实现一个简单的审批程,可以借助Spring Boot提供的一些功能和技术。 首先,我们需要定义审批程的各个环节和参与者。可以使用数据库表或其他方式来存储这些信息,例如审批环节的名称、参与者的角色等。 接下来,可以使用Spring Boot的Web组件来实现用户界面,用于显示待审批的申请和处理审批。可以使用Thymeleaf等模板引擎来构建页面,同时使用Spring MVC来处理用户的请求。 在后端逻辑中,可以利用Spring Boot的数据访问技术来读取和保存审批信息。可以使用JPA或MyBatis等持久化框架来操作数据库,并且可以定义相应的实体类和数据访问接口。 为了实现审批程的转,可以使用Spring Boot提供的异步处理、消息队列或定时任务等功能。例如,可以使用Spring的异步注解来实现审批环节的自动转移,或者使用消息队列来发送通知和处理结果。 此外,为了确保审批程的正确性和安全性,可以使用Spring Security来控制系统的访问权限。可以定义角色和权限,并通过认证和授权来限制用户的操作。 最后,为了方便日志记录和监控,可以使用Spring Boot提供的日志框架和管理工具。可以配置日志级别和输出格式,以及使用Actuator来监控系统的运行状态。 综上所述,通过借助Spring Boot的各种功能和技术,我们可以实现一个简单的审批程。从前端用户界面到后端数据存储,再到程控制和监控,Spring Boot提供了全面的解决方案,使得开发和维护审批程变得简单和高效。 ### 回答3: Spring Boot是一个用于快速开发Java应用程序的框架。要实现一个简单的审批,可以按照以下步骤进行: 1. 初始化Spring Boot项目:首先,我们需要在IDE中创建一个新的Spring Boot项目。可以使用Spring Initializr或自定义项目设置来初始化项目。 2. 定义实体类:创建必要的实体类,例如用户、审批请求和审批程等。实体类应包含必要的属性和关联关系。 3. 设计数据库表结构:根据实体类的定义,创建相应的数据库表结构。可以使用关系型数据库如MySQL或非关系型数据库如MongoDB等。 4. 创建数据访问对象(DAO):为每个实体类创建数据访问对象,用于与数据库进行交互。使用Spring Data JPA等技术简化操作。 5. 实现审批逻辑:根据业务需求,定义审批逻辑。可能包括创建审批请求、发送审批通知、处理审批意见、更新审批状态等。 6. 创建控制器:使用Spring MVC创建控制器层,处理HTTP请求和响应。定义审批请求的接口,包括创建请求、查询请求状态等。 7. 编写业务逻辑服务:实现审批程的业务逻辑,包括处理审批请求、发送审批结果通知等。可以使用Spring Boot的依赖注入和事务管理特性。 8. 实现前端界面:创建前端界面,用于提交审批请求、查询审批状态等。可以使用HTML、CSS和JavaScript等技术。可以选择框架如Vue.js或React等提高开发效率。 9. 配置权限控制:根据需求,设置不同角色的权限控制。例如,只有管理员能够创建审批请求,普通用户只能查询请求状态等。 10. 测试和调试:完成代码编写后,进行测试和调试,确保审批程能够正常运行。可以使用单元测试、集成测试和端到端测试等方式。 以上是实现一个简单审批程的大致步骤。根据实际需求,可能需要做一些调整和扩展。Spring Boot提供了很多便捷的功能和工具,可以简化开发过程,提高开发效率。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值