欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

工作流设计过程

程序员文章站 2022-04-09 21:26:25
1.业务场景:用户登录,收到消息通知,审批业务,根据配置的流程继续流转,最终审核发送回给申请人(终审同意结束,终审不同意申请人可以继续修改提交)。 2.思路过程: 3..数据库设计: 4.代码过程: ......

1.业务场景:用户登录,收到消息通知,审批业务,根据配置的流程继续流转,最终审核发送回给申请人(终审同意结束,终审不同意申请人可以继续修改提交)。

2.思路过程:

--用户登录首先获取未处理的消息记录,提醒处理预审批记录。
--1.配置流程主表和关联的步骤明细表(根据序号流转)
--2.提交业务审批的时候创建预审批记录(关联流程和步骤),发送消息到第一步骤的评审人,修改业务主表状态,
--3.步骤评审人同意:更新这个节点所有人的审批记录、如果流程明细还有下一步审批则继续发送消息给下一个,创建下一个预审批记录,修改业务主表状态,更新自己和这个节点所有人的消息记录状态
--4.步骤评审人不同意:终止发送下一个,发送回给申请人,更新自己和这个节点所有人的消息记录状态和审批记录
-- 每一个节点可以配置多个审批人,第一个审批节点必须是同一个部门的才可以审批(可以配置多个部门领导,但是申请发送的时候只发送给同部门的领导)
-- 登录人审批要根据预审批记录表查询是否有要审批的记录和判断是否有下一个步骤,审批完成后继续向下一个发送

3..数据库设计:

-------------------流程审批设计--------------------------创建流程表 flow:id、编号、流程名称、类别、制定人、制定日期、状态(是否启用)、备注
select * from [dbo].[flow]
--创建流程审批明细表(关联流程表,一对多) flowdetail:id、流程主表编号、序号、步骤名称、评审人账号(多个)、评审人名字(多个)、状态(是否启用)、
select *  from flowdetail
--创建审批记录表 flowrecords:id、流程主表编号、流程步骤序号、业务编号、评审人账号、评审人名字、审批状态(1同意,2不同意,3审核中)、审批日期、备注、
select * from flowrecords where businessnum='4c4ced8e3f8d42c997e2424d83c447b8'
--创建消息通知表 message :id、标题、内容、业务编号、接收人账号、接收人名字、发送人账号、发送人名字、发送时间、状态(1未处理,2已处理)
select * from flowmessage where businessnum='4c4ced8e3f8d42c997e2424d83c447b8'
 --业务主表 (增加字段关联审批流程:流程主表编号、流程明细序号)

4.代码过程:

        /// <summary>
        /// 审核单据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override string audite(receiveorderentity entity)
        {
            using (transactionscope ts = new transactionscope())
            {
                //1.获取自己当前业务需要审核的记录,没有则不能审核
                flowrecordsentity record = new flowrecordsentity();
                record.includeall();
                record.where(a => a.businessnum == entity.snnum).and(a => a.approverusernum == entity.username);
                var myrecord = this.flowrecords.getlist(record).firstordefault();
                if (myrecord == null) return "1003";
                if(myrecord.approverresult!=3) return "1004";
                //2.获取是否有下一步的流程步骤
                flowprovider provider = new flowprovider(companyid);
                list<flowdetailentity> flowdetails = provider
                    .getflowdetail(new flowdetailentity {flowsnnum = entity.flowsnnum}).orderby(x => x.seq).tolist();
                flowdetailentity nextflowdeail = null;
                int line = 0;
                if (flowdetails != null && flowdetails.count > 0)
                {
                    int count = 0;
                    foreach (var obj in flowdetails)
                    {
                        if (obj.seq == myrecord.flowdtlseq)
                            break;
                        else
                            count++;
                    }
                    //是否有下一步的流程
                    if (flowdetails.count > count && flowdetails.count!=count+1)
                    {
                        nextflowdeail = flowdetails[count + 1];
                    }
                }
                #region 不同意流程
                if (entity.status == (int) eaudite.notpass)
                {
                    entity.flowdtlseq = myrecord.flowdtlseq;
                    entity.includestatus(true).includereason(true).includeflowdtlseq(true)
                        .where(a => a.snnum == entity.snnum)
                        .and(a => a.companyid == this.companyid)
                        ;
                    line += this.receiveorder.update(entity);
                    //1.更新自己的审批记录
                    myrecord.approverresult = 2;
                    myrecord.approverdate = datetime.now;
                    myrecord.includeapproverresult(true).includeapproverdate(true);
                    line += this.flowrecords.update(myrecord);
                    //2.更新自己(这一个步骤所有人)的消息记录
                    flowmessageentity msg = new flowmessageentity();
                    msg.status = 2;
                    msg.includestatus(true);
                    msg.where(a => a.businessnum == entity.snnum).and(a => a.flowsnnum == entity.flowsnnum)
                        .and(a => a.flowdtlseq == myrecord.flowdtlseq);
                    line += this.flowmessage.update(msg);
                    //3.只发送消息回给申请人
                    flowmessageentity nextmsg = new flowmessageentity()
                    {
                        sendusernum = entity.username,
                        sendusername = entity.realname,
                        acceptusernum = entity.cusnum,
                        acceptusername = entity.cusname,
                        businessnum = entity.snnum,
                        flowsnnum = entity.flowsnnum,
                        flowdtlseq = myrecord.flowdtlseq,
                        status = 1,
                        senddate = datetime.now,
                        title = "物品领用申请审核",
                        notice = "您的编号为:"+entity.ordernum+"的物品领用申审核已被拒绝!"
                    };
                    nextmsg.includeall();
                    line += this.flowmessage.add(nextmsg);
                    ts.complete();
                    return line > 0 ? "1000" : string.empty;
                }
                #endregion
                #region 同意流程
                else if (entity.status == (int) eaudite.pass) 
                {
                    //1.更新自己的审批记录
                    myrecord.approverresult = 1;
                    myrecord.approverdate = datetime.now;
                    myrecord.includeapproverresult(true).includeapproverdate(true);
                    line += this.flowrecords.update(myrecord);
                    //2.更新自己(这一个步骤所有人)的消息记录
                    flowmessageentity msg = new flowmessageentity();
                    msg.status = 2;
                    msg.includestatus(true);
                    msg.where(a => a.businessnum == entity.snnum).and(a => a.flowsnnum == entity.flowsnnum)
                        .and(a => a.flowdtlseq == myrecord.flowdtlseq);
                    line += this.flowmessage.update(msg);
                    //如果有下一步的审核
                    if (nextflowdeail != null)
                    {
                        //1.修改业务状态
                        entity.status = 5;
                        //2.获取下一步骤的审批人账号列表
                        var users = nextflowdeail.approverusernum.split(',')
                            .where(x => string.isnullorempty(x) == false).tolist();
                        list<adminentity> senduser = new list<adminentity>();
                        users.foreach(x =>
                        {
                            adminentity model = new adminentity();
                            model.includeall();
                            model.where(a => a.isdelete == (int)eisdelete.notdelete).and(item => item.username == x);
                            var user = this.admin.getsingle(model);
                            if (user != null)
                            {
                                senduser.add(user);
                            }
                        });
                        foreach (var user in senduser)
                        {
                            //3.创建下一个审批人的预审批记录
                            flowrecordsentity nextrecord = new flowrecordsentity()
                            {
                                approverusername = user.realname,
                                approverusernum = user.username,
                                businessnum = entity.snnum,
                                flowsnnum = entity.flowsnnum,
                                flowdtlseq = nextflowdeail.seq,
                                approverresult = 3
                            };
                            nextrecord.includeall();
                            line += this.flowrecords.add(nextrecord);
                            //4.发送下一个审批人的消息通知
                            flowmessageentity nextmsg = new flowmessageentity()
                            {
                                sendusernum = entity.username,
                                sendusername = entity.realname,
                                acceptusernum = user.username,
                                acceptusername = user.realname,
                                businessnum = entity.snnum,
                                flowsnnum = entity.flowsnnum,
                                flowdtlseq = nextflowdeail.seq,
                                status = 1,
                                senddate = datetime.now,
                                title = "物品领用申请审核",
                                notice = "有编号为:" + entity.ordernum + "的物品领用申请需要您审核!"
                            };
                            nextmsg.includeall();
                            line += this.flowmessage.add(nextmsg);
                        }
                    }
                    else
                    {
                        //流程结束
                        entity.status = (int) eaudite.pass;
                        //发送消息回给申请人
                        flowmessageentity fristmsg = new flowmessageentity()
                        {
                            sendusernum = entity.username,
                            sendusername = entity.realname,
                            acceptusernum = entity.cusnum,
                            acceptusername = entity.cusname,
                            businessnum = entity.snnum,
                            flowsnnum = entity.flowsnnum,
                            flowdtlseq = myrecord.flowdtlseq,
                            status = 1,
                            senddate = datetime.now,
                            title = "物品领用申请审核",
                            notice = "您的编号为:" + entity.ordernum + "的物品领用申审核已经通过!"
                        };
                        fristmsg.includeall();
                        line += this.flowmessage.add(fristmsg);
                    }
                    entity.flowdtlseq = myrecord.flowdtlseq;
                    entity.auditetime = datetime.now;
                    entity.include(a => new {a.status, a.audituser, a.auditetime, a.reason, a.remark,a.flowdtlseq});
                    entity.where(a => a.snnum == entity.snnum).and(a => a.companyid == this.companyid);
                    line += this.receiveorder.update(entity);
                    ts.complete();
                    return line > 0 ? enumhelper.getenumdesc<ereturnstatus>(ereturnstatus.success) : string.empty;
                }
                #endregion
               
            }
            return string.empty;
        }

工作流设计过程

 

 

 

工作流设计过程