Example #1
0
        public static async Task <WfiItem> Create(
            long p_atviID,
            DateTime p_date,
            bool p_isRole,
            long p_receiver,
            string p_note,
            bool p_isBack)
        {
            WfiItem item = new WfiItem(
                ID: await AtCm.NewID(),
                AtviID: p_atviID,
                AssignKind: (p_isBack ? WfiItemAssignKind.回退 : WfiItemAssignKind.普通指派),
                Status: WfiItemStatus.活动,
                IsAccept: false,
                Sender: Kit.UserName,
                Stime: p_date,
                Ctime: p_date,
                Mtime: p_date,
                Note: p_note,
                Dispidx: await AtCm.NewSeq("sq_wfi_item"));

            if (p_isRole)
            {
                item.RoleID = p_receiver;
            }
            else
            {
                item.UserID = p_receiver;
            }
            return(item);
        }
Example #2
0
        /// <summary>
        /// 执行发送
        /// </summary>
        /// <param name="p_manualSend">是否手动选择接收者</param>
        async void DoSend(bool p_manualSend)
        {
            #region 后续活动
            // 生成后续活动的活动实例、工作项、迁移实例,一个或多个
            var tblAtvs = Table <WfiAtv> .Create();

            var tblItems = Table <WfiItem> .Create();

            var tblTrs = Table <WfiTrs> .Create();

            DateTime time = Kit.Now;

            if (_info.NextRecvs.FinishedAtv != null &&
                (!p_manualSend || _info.NextRecvs.FinishedAtv.IsSelected))
            {
                // 完成
                _info.PrcInst.Status = WfiAtvStatus.结束;
                _info.PrcInst.Mtime  = time;
            }
            else
            {
                // 普通活动
                foreach (AtvRecv ar in _info.NextRecvs.Atvs)
                {
                    // 手动无选择时
                    if (p_manualSend &&
                        (ar.SelectedRecvs == null || ar.SelectedRecvs.Count == 0))
                    {
                        continue;
                    }

                    var atvInst = new WfiAtv(
                        ID: await AtCm.NewID(),
                        PrciID: _info.PrcInst.ID,
                        AtvdID: ar.Def.ID,
                        Status: WfiAtvStatus.活动,
                        Ctime: time,
                        Mtime: time);
                    tblAtvs.Add(atvInst);

                    if (p_manualSend)
                    {
                        // 手动发送,已选择项可能为用户或角色
                        atvInst.InstCount = ar.SelectedRecvs.Count;
                        foreach (var recvID in ar.SelectedRecvs)
                        {
                            var wi = await WfiItem.Create(atvInst.ID, time, ar.IsRole, recvID, ar.Note, false);

                            tblItems.Add(wi);
                        }
                    }
                    else
                    {
                        // 自动发送,按角色
                        atvInst.InstCount = ar.Recvs.Count;
                        foreach (var row in ar.Recvs)
                        {
                            var wi = await WfiItem.Create(atvInst.ID, time, ar.IsRole, row.ID, ar.Note, false);

                            tblItems.Add(wi);
                        }
                    }

                    // 增加迁移实例
                    var trs = await _info.CreateAtvTrs(ar.Def.ID, atvInst.ID, time, false);

                    tblTrs.Add(trs);
                }

                // 同步活动
                var syncAtv = _info.NextRecvs.SyncAtv;
                if (syncAtv != null &&
                    (!p_manualSend || (syncAtv.SelectedRecvs != null && syncAtv.SelectedRecvs.Count > 0)))
                {
                    // 同步实例
                    var syncInst = new WfiAtv(
                        ID: await AtCm.NewID(),
                        PrciID: _info.PrcInst.ID,
                        AtvdID: syncAtv.SyncDef.ID,
                        Status: WfiAtvStatus.步,
                        InstCount: 1,
                        Ctime: time,
                        Mtime: time);
                    tblAtvs.Add(syncInst);

                    // 同步工作项
                    WfiItem item = new WfiItem(
                        ID: await AtCm.NewID(),
                        AtviID: syncInst.ID,
                        AssignKind: WfiItemAssignKind.普通指派,
                        Status: WfiItemStatus.步,
                        IsAccept: false,
                        UserID: Kit.UserID,
                        Sender: Kit.UserName,
                        Stime: time,
                        Ctime: time,
                        Mtime: time,
                        Dispidx: await AtCm.NewSeq("sq_wfi_item"));
                    tblItems.Add(item);

                    // 同步迁移实例
                    Dict dt = new Dict();
                    dt["prcid"]      = _info.PrcInst.PrcdID;
                    dt["SrcAtvID"]   = _info.AtvInst.AtvdID;
                    dt["TgtAtvID"]   = syncAtv.SyncDef.ID;
                    dt["IsRollback"] = false;
                    long trsdid = await AtCm.GetScalar <long>("流程-迁移模板ID", dt);

                    var trs = new WfiTrs(
                        ID: await AtCm.NewID(),
                        TrsdID: trsdid,
                        SrcAtviID: _info.AtvInst.ID,
                        TgtAtviID: syncInst.ID,
                        IsRollback: false,
                        Ctime: time);
                    tblTrs.Add(trs);

                    // 同步活动的后续活动实例
                    var nextInst = new WfiAtv(
                        ID: await AtCm.NewID(),
                        PrciID: _info.PrcInst.ID,
                        AtvdID: syncAtv.Def.ID,
                        Status: WfiAtvStatus.活动,
                        Ctime: time,
                        Mtime: time);
                    tblAtvs.Add(nextInst);

                    if (p_manualSend)
                    {
                        // 手动发送,已选择项可能为用户或角色
                        nextInst.InstCount = syncAtv.SelectedRecvs.Count;
                        foreach (var recvID in syncAtv.SelectedRecvs)
                        {
                            var wi = await WfiItem.Create(nextInst.ID, time, syncAtv.IsRole, recvID, "", false);

                            tblItems.Add(wi);
                        }
                    }
                    else
                    {
                        // 自动发送,按角色
                        nextInst.InstCount = syncAtv.Recvs.Count;
                        foreach (var row in syncAtv.Recvs)
                        {
                            var wi = await WfiItem.Create(nextInst.ID, time, syncAtv.IsRole, row.ID, "", false);

                            tblItems.Add(wi);
                        }
                    }

                    // 增加迁移实例
                    dt               = new Dict();
                    dt["prcid"]      = _info.PrcInst.PrcdID;
                    dt["SrcAtvID"]   = syncAtv.SyncDef.ID;
                    dt["TgtAtvID"]   = syncAtv.Def.ID;
                    dt["IsRollback"] = false;
                    trsdid           = await AtCm.GetScalar <long>("流程-迁移模板ID", dt);

                    trs = new WfiTrs(
                        ID: await AtCm.NewID(),
                        TrsdID: trsdid,
                        SrcAtviID: syncInst.ID,
                        TgtAtviID: nextInst.ID,
                        IsRollback: false,
                        Ctime: time);
                    tblTrs.Add(trs);
                }
            }

            // 发送是否有效
            // 1. 只有'完成'时有效
            // 2. 至少含有一个活动实例时有效
            if (tblAtvs.Count == 0 && _info.PrcInst.Status != WfiAtvStatus.结束)
            {
                Kit.Msg("所有后续活动均无接收者,发送失败!");
                return;
            }
            #endregion

            #region 整理待保存数据
            List <object> data = new List <object>();
            if (_info.PrcInst.IsChanged)
            {
                data.Add(_info.PrcInst);
            }

            _info.AtvInst.Finished();
            data.Add(_info.AtvInst);

            _info.WorkItem.Finished();
            data.Add(_info.WorkItem);

            if (tblAtvs.Count > 0)
            {
                data.Add(tblAtvs);
                data.Add(tblItems);
                data.Add(tblTrs);
            }
            #endregion

            if (await AtCm.BatchSave(data, false))
            {
                Kit.Msg("发送成功!");
                _info.CloseWin();
                // 推送客户端提醒
            }
            else
            {
                // 避免保存失败后,再次点击发送时和保存表单一起被保存,造成状态错误!
                _info.PrcInst.RejectChanges();
                _info.AtvInst.RejectChanges();
                _info.WorkItem.RejectChanges();
                Kit.Warn("发送失败!");
            }
        }
Example #3
0
        async void OnRetrieve(object sender, Mi e)
        {
            Row row    = e.Row;
            var status = (WfiPrcStatus)row.Int("status");

            if (status != WfiPrcStatus.活动)
            {
                Kit.Warn($"该任务已{status},无法追回");
                return;
            }
            if (row.Int("reCount") > 0)
            {
                Kit.Warn("含回退,无法追回");
                return;
            }

            var tbl = await AtCm.Query("流程-后续活动工作项", new { atvdid = row.Long("atvdid"), prciid = row.Long("prciid") });

            if (tbl.Count == 0)
            {
                Kit.Warn("无后续活动,无法追回");
                return;
            }

            HashSet <long> ls = new HashSet <long>();

            foreach (var r in tbl)
            {
                var itemState = (WfiItemStatus)r.Int("Status");
                if (itemState == WfiItemStatus.步)
                {
                    Kit.Warn("后续活动包含同步,无法追回");
                    return;
                }

                if (itemState != WfiItemStatus.活动 ||
                    r.Bool("IsAccept"))
                {
                    Kit.Warn("已签收无法追回!");
                    return;
                }
                ls.Add(r.Long("atviid"));
            }

            // 更新当前实例状态为活动
            DateTime time    = Kit.Now;
            WfiAtv   curAtvi = await AtCm.GetByID <WfiAtv>(row.Long("atviid"));

            curAtvi.Status     = WfiAtvStatus.活动;
            curAtvi.InstCount += 1;
            curAtvi.Mtime      = time;

            // 根据当前工作项创建新工作项并更改指派方式
            var curItem = await AtCm.GetByID <WfiItem>(row.Long("itemid"));

            var newItem = new WfiItem(
                ID: await AtCm.NewID(),
                AtviID: curItem.AtviID,
                Status: WfiItemStatus.活动,
                AssignKind: WfiItemAssignKind.追回,
                Sender: curItem.Sender,
                Stime: curItem.Stime,
                IsAccept: false,
                RoleID: curItem.RoleID,
                UserID: curItem.UserID,
                Note: curItem.Note,
                Dispidx: await AtCm.NewSeq("sq_wfi_item"),
                Ctime: time,
                Mtime: time);

            // 删除已发送的后续活动实例,关联删除工作项及迁移实例
            Table <WfiAtv> nextAtvs = new Table <WfiAtv>();

            nextAtvs.StartRecordDelRows();
            foreach (var id in ls)
            {
                nextAtvs.DeletedRows.Add(new WfiAtv(id));
            }

            // 一个事务批量保存
            List <object> data = new List <object>();

            data.Add(nextAtvs);
            data.Add(curAtvi);
            data.Add(newItem);
            bool suc = await AtCm.BatchSave(data, false);

            if (suc)
            {
                Kit.Msg("追回成功");
                OnSearch(null, null);
            }
            else
            {
                Kit.Warn("追回失败");
            }
        }
Example #4
0
        async Task Rollback()
        {
            // 活动执行者多于一人时,不允许进行回退
            if (_info.AtvInst.InstCount > 1)
            {
                Kit.Msg("该活动执行者多于一人,不允许回退!");
                return;
            }

            // 获得前一活动实例
            var pre = await _info.AtvInst.GetRollbackAtv();

            if (pre == null)
            {
                Kit.Msg("该活动不允许回退!");
                return;
            }

            if (!await Kit.Confirm("确认要回退吗?"))
            {
                return;
            }

            DateTime time       = Kit.Now;
            var      newAtvInst = new WfiAtv(
                ID: await AtCm.NewID(),
                PrciID: _info.PrcInst.ID,
                AtvdID: pre.AtvdID,
                Status: WfiAtvStatus.活动,
                InstCount: 1,
                Ctime: time,
                Mtime: time);

            // 创建迁移实例
            var newTrs = await _info.CreateAtvTrs(pre.AtvdID, newAtvInst.ID, time, true);

            // 当前活动完成状态
            _info.AtvInst.Finished();

            // 当前工作项置成完成状态
            _info.WorkItem.Finished();

            Dict dict = new Dict();

            dict["name"] = await GetSender();

            long userId = await AtCm.GetScalar <long>("流程-获取用户ID", dict);

            var newItem = await WfiItem.Create(newAtvInst.ID, time, false, userId, null, true);

            List <object> ls = new List <object>();

            if (_info.AtvInst.IsChanged)
            {
                ls.Add(_info.AtvInst);
            }
            ls.Add(_info.WorkItem);
            ls.Add(newAtvInst);
            ls.Add(newItem);
            ls.Add(newTrs);

            if (await AtCm.BatchSave(ls, false))
            {
                Kit.Msg("回退成功!");
                _info.CloseWin();
            }
            else
            {
                Kit.Msg("回退失败!");
            }
        }