Beispiel #1
0
        /// <summary>
        /// 把流程实体新增到数据库
        /// </summary>
        /// <returns></returns>
        public bool Create()
        {
            ISqlMapper      mapper      = MapperHelper.GetMapper();
            WorkflowDao     workflowdao = new WorkflowDao(mapper);
            ActivityDao     activitydao = new ActivityDao(mapper);
            LinkDao         linkdao     = new LinkDao(mapper);
            ActivityAuthDao authdao     = new ActivityAuthDao(mapper);

            workflowdao.Add(this.Value);
            var         activities = this.Root.GetList();
            List <Link> linkList   = new List <Link>();

            //保存节点
            foreach (var activity in activities)
            {
                activitydao.Add(activity.Value);
                var activityinstance = activity as ActivityModel;
                //保存连接
                if (activityinstance.PreLinks != null)
                {
                    foreach (var link in activityinstance.PreLinks)
                    {
                        if (!linkList.Contains(link.Value))
                        {
                            linkList.Add(link.Value);
                        }
                    }
                }
                if (activityinstance.NextLinks != null)
                {
                    foreach (var link in activityinstance.NextLinks)
                    {
                        if (!linkList.Contains(link.Value))
                        {
                            linkList.Add(link.Value);
                        }
                    }
                }
                //保存权限
                foreach (var auth in activityinstance.Auth)
                {
                    authdao.Add(auth);
                }
            }
            foreach (var link in linkList)
            {
                linkdao.Add(link);
            }
            return(true);
        }
        public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth)
        {
            var             mapper      = MapperHelper.GetMapper();
            WorkflowDao     workflowdao = new WorkflowDao(mapper);
            ActivityDao     activitydao = new ActivityDao(mapper);
            LinkDao         linkdao     = new LinkDao(mapper);
            ActivityAuthDao aadd        = new ActivityAuthDao(mapper);
            TaskDao         taskdao     = new TaskDao(mapper);
            WorkflowModel   model       = null;
            Workflow        wf          = this.value.ConvertTo <Workflow>();

            wf.ID      = null;
            wf.Creator = creator;
            wf.Status  = (int)WorkflowProcessStatus.Started;
            wf.WorkflowDefinitionID = this.value.ID;
            wf.ProcessID            = processid;
            workflowdao.Add(wf);

            var             activites        = this.ActivityDefinitionList;
            var             links            = this.LinkDefinitionList;
            List <Activity> activityEntities = new List <Activity>();

            foreach (var a in activites)
            {
                Activity activity = a.Value.ConvertTo <Activity>();
                activity.Creator              = creator;
                activity.ID                   = null;
                activity.WorkflowID           = wf.ID;
                activity.ActivityDefinitionID = a.Value.ID;
                activity.Title                = a.Value.Title;
                activity.Status               = (int)ActivityProcessStatus.Started;

                List <ActivityAuth> authList = new List <ActivityAuth>();

                //如果是开始节点,就设置为已处理
                if (this.Root.Equals(a))
                {
                    activity.Status      = (int)ActivityProcessStatus.Processed;
                    activity.ProcessTime = DateTime.Now;
                }
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    activity.Status = (int)ActivityProcessStatus.Processing;
                }
                activitydao.Add(activity);
                activityEntities.Add(activity);

                //权限处理
                foreach (var ad in a.AuthDefinition)
                {
                    ActivityAuth auth = ad.ConvertTo <ActivityAuth>();
                    auth.Creator    = creator;
                    auth.WorkflowID = wf.ID;
                    auth.ActivityID = activity.ID;
                    auth.ID         = null;
                    auth.ActivityAuthDefinitionID = ad.ID;
                    aadd.Add(auth);
                    authList.Add(auth);
                }

                //如果是第二节点,就设置成正在处理
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    ActivityModel activitymodel = new ActivityModel
                    {
                        Value = activity,
                    };
                    var idlist   = iauth.GetUserIDList(authList);
                    var tasklist = activitymodel.GetTask(creator, idlist);
                    foreach (var task in tasklist)
                    {
                        taskdao.Add(task);
                    }
                }
            }

            foreach (var l in links)
            {
                Link link = l.Value.ConvertTo <Link>();
                link.Creator          = creator;
                link.WorkflowID       = wf.ID;
                link.ID               = null;
                link.LinkDefinitionID = l.Value.ID;
                var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID);
                var totactivity  = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID);
                if (fromactivity != null)
                {
                    link.FromActivityID = fromactivity.ID;
                }
                if (totactivity != null)
                {
                    link.ToAcivityID = totactivity.ID;
                }
                linkdao.Add(link);
            }

            model = WorkflowModel.Load(wf.ID);
            return(model);
        }
 /// <summary>
 /// 把流程实体新增到数据库
 /// </summary>
 /// <returns></returns>
 public bool Create()
 {
     ISqlMapper mapper = MapperHelper.GetMapper();
     WorkflowDao workflowdao = new WorkflowDao(mapper);
     ActivityDao activitydao = new ActivityDao(mapper);
     LinkDao linkdao = new LinkDao(mapper);
     ActivityAuthDao authdao = new ActivityAuthDao(mapper);
     workflowdao.Add(this.Value);
     var activities = this.Root.GetList();
     List<Link> linkList = new List<Link>();
     //保存节点
     foreach (var activity in activities)
     {
         activitydao.Add(activity.Value);
         var activityinstance = activity as ActivityModel;
         //保存连接
         if (activityinstance.PreLinks != null)
         {
             foreach (var link in activityinstance.PreLinks)
             {
                 if (!linkList.Contains(link.Value))
                 {
                     linkList.Add(link.Value);
                 }
             }
         }
         if (activityinstance.NextLinks != null)
         {
             foreach (var link in activityinstance.NextLinks)
             {
                 if (!linkList.Contains(link.Value))
                 {
                     linkList.Add(link.Value);
                 }
             }
         }
         //保存权限
         foreach (var auth in activityinstance.Auth)
         {
             authdao.Add(auth);
         }
     }
     foreach (var link in linkList)
     {
         linkdao.Add(link);
     }
     return true;
 }
 public static bool ManageWinningResult(int UserId, ActivityInfo Info, int AwardGrade, ref int FreeTimes)
 {
     lock (ActivityHelper.oWinning)
     {
         Database    database    = DatabaseFactory.CreateDatabase();
         ActivityDao activityDao = new ActivityDao();
         using (DbConnection dbConnection = database.CreateConnection())
         {
             dbConnection.Open();
             DbTransaction dbTransaction = dbConnection.BeginTransaction();
             try
             {
                 bool flag  = false;
                 bool flag2 = false;
                 ActivityJoinStatisticsInfo activityJoinStatisticsInfo = activityDao.GetCurrUserActivityStatisticsInfo(UserId, Info.ActivityId, dbTransaction);
                 MemberInfo memberInfo = new MemberDao().Get <MemberInfo>(UserId);
                 if (activityJoinStatisticsInfo != null)
                 {
                     if (Info.ResetType == 2)
                     {
                         DateTime lastJoinDate = activityJoinStatisticsInfo.LastJoinDate;
                         if (DateTime.Now.Date == lastJoinDate.Date)
                         {
                             if (activityJoinStatisticsInfo.FreeNum < Info.FreeTimes)
                             {
                                 flag = true;
                                 activityJoinStatisticsInfo.FreeNum++;
                                 FreeTimes = Info.FreeTimes - activityJoinStatisticsInfo.FreeNum;
                             }
                             else
                             {
                                 activityJoinStatisticsInfo.IntegralTotal += Info.ConsumptionIntegral;
                                 activityJoinStatisticsInfo.IntegralNum++;
                                 FreeTimes = 0;
                             }
                         }
                         else
                         {
                             flag = true;
                             activityJoinStatisticsInfo.FreeNum = 1;
                             FreeTimes = Info.FreeTimes - 1;
                         }
                     }
                     else if (activityJoinStatisticsInfo.FreeNum < Info.FreeTimes)
                     {
                         flag = true;
                         activityJoinStatisticsInfo.FreeNum++;
                         FreeTimes = Info.FreeTimes - activityJoinStatisticsInfo.FreeNum;
                     }
                     else
                     {
                         activityJoinStatisticsInfo.IntegralTotal += Info.ConsumptionIntegral;
                         activityJoinStatisticsInfo.IntegralNum++;
                         FreeTimes = 0;
                     }
                 }
                 else
                 {
                     flag2 = true;
                     activityJoinStatisticsInfo            = new ActivityJoinStatisticsInfo();
                     activityJoinStatisticsInfo.ActivityId = Info.ActivityId;
                     activityJoinStatisticsInfo.UserId     = UserId;
                     if (Info.FreeTimes > 0)
                     {
                         flag = true;
                         activityJoinStatisticsInfo.FreeNum       = 1;
                         activityJoinStatisticsInfo.IntegralTotal = 0;
                         activityJoinStatisticsInfo.IntegralNum   = 0;
                         FreeTimes = Info.FreeTimes - 1;
                     }
                     else
                     {
                         activityJoinStatisticsInfo.IntegralTotal = Info.ConsumptionIntegral;
                         activityJoinStatisticsInfo.IntegralNum   = 1;
                         activityJoinStatisticsInfo.FreeNum       = 0;
                         FreeTimes = 0;
                     }
                 }
                 activityJoinStatisticsInfo.JoinNum++;
                 activityJoinStatisticsInfo.LastJoinDate = DateTime.Now;
                 bool                  flag3                 = false;
                 CouponInfo            couponInfo            = null;
                 GiftInfo              giftInfo              = null;
                 ActivityAwardItemInfo activityAwardItemInfo = null;
                 if (AwardGrade > 0)
                 {
                     activityAwardItemInfo = activityDao.GetActivityItem(Info.ActivityId, AwardGrade, dbTransaction);
                     if (activityAwardItemInfo.WinningNum < activityAwardItemInfo.AwardNum)
                     {
                         if (activityAwardItemInfo.PrizeType == 2)
                         {
                             couponInfo = new CouponDao().Get <CouponInfo>(activityAwardItemInfo.PrizeValue);
                             if (couponInfo != null)
                             {
                                 int couponSurplus = new CouponDao().GetCouponSurplus(activityAwardItemInfo.PrizeValue);
                                 if (couponSurplus > 0 && couponInfo.ClosingTime > DateTime.Now)
                                 {
                                     flag3 = true;
                                 }
                             }
                         }
                         else if (activityAwardItemInfo.PrizeType == 3)
                         {
                             giftInfo = new GiftDao().Get <GiftInfo>(activityAwardItemInfo.PrizeValue);
                             if (giftInfo != null)
                             {
                                 flag3 = true;
                             }
                         }
                         else
                         {
                             flag3 = true;
                         }
                     }
                 }
                 else
                 {
                     flag3 = false;
                 }
                 if (!flag)
                 {
                     PointDetailInfo pointDetailInfo = new PointDetailInfo();
                     pointDetailInfo.Increased    = 0;
                     pointDetailInfo.OrderId      = "";
                     pointDetailInfo.Points       = memberInfo.Points - Info.ConsumptionIntegral;
                     pointDetailInfo.Reduced      = Info.ConsumptionIntegral;
                     pointDetailInfo.Remark       = "抽奖消耗积分";
                     pointDetailInfo.SignInSource = 0;
                     pointDetailInfo.TradeDate    = DateTime.Now;
                     if (Info.ActivityType == 1)
                     {
                         pointDetailInfo.TradeType = PointTradeType.JoinRotaryTable;
                     }
                     else if (Info.ActivityType == 3)
                     {
                         pointDetailInfo.TradeType = PointTradeType.JoinSmashingGoldenEgg;
                     }
                     else
                     {
                         pointDetailInfo.TradeType = PointTradeType.JoinScratchCard;
                     }
                     pointDetailInfo.UserId = UserId;
                     if (new PointDetailDao().Add(pointDetailInfo, dbTransaction) <= 0)
                     {
                         dbTransaction.Rollback();
                         return(false);
                     }
                 }
                 if (!flag3)
                 {
                     if (flag2)
                     {
                         if (activityDao.Add(activityJoinStatisticsInfo, dbTransaction) <= 0)
                         {
                             dbTransaction.Rollback();
                         }
                     }
                     else if (!activityDao.UpdateActivityStatisticsInfo(activityJoinStatisticsInfo, dbTransaction))
                     {
                         dbTransaction.Rollback();
                     }
                     dbTransaction.Commit();
                     return(false);
                 }
                 activityJoinStatisticsInfo.WinningNum++;
                 if (flag2)
                 {
                     if (activityDao.Add(activityJoinStatisticsInfo, dbTransaction) <= 0)
                     {
                         dbTransaction.Rollback();
                     }
                 }
                 else if (!activityDao.UpdateActivityStatisticsInfo(activityJoinStatisticsInfo, dbTransaction))
                 {
                     dbTransaction.Rollback();
                 }
                 activityAwardItemInfo.WinningNum++;
                 if (!activityDao.Update(activityAwardItemInfo, dbTransaction))
                 {
                     dbTransaction.Rollback();
                     return(false);
                 }
                 UserAwardRecordsInfo userAwardRecordsInfo = new UserAwardRecordsInfo();
                 userAwardRecordsInfo.ActivityId = Info.ActivityId;
                 if (activityAwardItemInfo.PrizeType == 2)
                 {
                     userAwardRecordsInfo.AwardName = couponInfo.CouponName;
                     userAwardRecordsInfo.AwardDate = DateTime.Now;
                     userAwardRecordsInfo.Status    = 2;
                     CouponItemInfo couponItemInfo = new CouponItemInfo();
                     couponItemInfo.UserId             = UserId;
                     couponItemInfo.UserName           = memberInfo.UserName;
                     couponItemInfo.CanUseProducts     = couponInfo.CanUseProducts;
                     couponItemInfo.ClosingTime        = couponInfo.ClosingTime;
                     couponItemInfo.CouponId           = couponInfo.CouponId;
                     couponItemInfo.CouponName         = couponInfo.CouponName;
                     couponItemInfo.OrderUseLimit      = couponInfo.OrderUseLimit;
                     couponItemInfo.Price              = couponInfo.Price;
                     couponItemInfo.StartTime          = couponInfo.StartTime;
                     couponItemInfo.UseWithGroup       = couponInfo.UseWithGroup;
                     couponItemInfo.UseWithPanicBuying = couponInfo.UseWithPanicBuying;
                     couponItemInfo.UseWithFireGroup   = couponInfo.UseWithFireGroup;
                     couponItemInfo.GetDate            = DateTime.Now;
                     couponItemInfo.ClaimCode          = Guid.NewGuid().ToString();
                     if (new CouponDao().Add(couponItemInfo, dbTransaction) <= 0)
                     {
                         dbTransaction.Rollback();
                         return(false);
                     }
                 }
                 else if (activityAwardItemInfo.PrizeType == 3)
                 {
                     userAwardRecordsInfo.AwardDate = null;
                     userAwardRecordsInfo.AwardName = giftInfo.Name;
                     userAwardRecordsInfo.AwardPic  = giftInfo.ThumbnailUrl160;
                     userAwardRecordsInfo.Status    = 1;
                 }
                 else
                 {
                     userAwardRecordsInfo.AwardName = activityAwardItemInfo.PrizeValue + "积分";
                     userAwardRecordsInfo.AwardDate = DateTime.Now;
                     userAwardRecordsInfo.Status    = 2;
                     PointDetailInfo pointDetailInfo2 = new PointDetailInfo();
                     pointDetailInfo2.Increased = activityAwardItemInfo.PrizeValue;
                     pointDetailInfo2.OrderId   = "";
                     if (flag)
                     {
                         pointDetailInfo2.Points = memberInfo.Points + activityAwardItemInfo.PrizeValue;
                     }
                     else
                     {
                         pointDetailInfo2.Points = memberInfo.Points - Info.ConsumptionIntegral + activityAwardItemInfo.PrizeValue;
                     }
                     pointDetailInfo2.Reduced      = 0;
                     pointDetailInfo2.Remark       = "抽奖获得积分";
                     pointDetailInfo2.SignInSource = 0;
                     pointDetailInfo2.TradeDate    = DateTime.Now;
                     if (Info.ActivityType == 1)
                     {
                         pointDetailInfo2.TradeType = PointTradeType.JoinRotaryTable;
                     }
                     else if (Info.ActivityType == 3)
                     {
                         pointDetailInfo2.TradeType = PointTradeType.JoinSmashingGoldenEgg;
                     }
                     else
                     {
                         pointDetailInfo2.TradeType = PointTradeType.JoinScratchCard;
                     }
                     pointDetailInfo2.UserId = UserId;
                     if (new PointDetailDao().Add(pointDetailInfo2, dbTransaction) <= 0)
                     {
                         dbTransaction.Rollback();
                         return(false);
                     }
                 }
                 userAwardRecordsInfo.AwardGrade = AwardGrade;
                 userAwardRecordsInfo.AwardId    = activityAwardItemInfo.AwardId;
                 userAwardRecordsInfo.CreateDate = DateTime.Now;
                 userAwardRecordsInfo.PrizeType  = activityAwardItemInfo.PrizeType;
                 userAwardRecordsInfo.PrizeValue = activityAwardItemInfo.PrizeValue;
                 userAwardRecordsInfo.UserId     = UserId;
                 if (activityDao.Add(userAwardRecordsInfo, dbTransaction) <= 0)
                 {
                     dbTransaction.Rollback();
                     return(false);
                 }
                 dbTransaction.Commit();
                 return(true);
             }
             catch (Exception ex)
             {
                 dbTransaction.Rollback();
                 Globals.WriteLog("ActivityLog.txt", "Methed:ManageWinningResult , Id:" + Info.ActivityId + " , Msg:" + ex.Message);
                 return(false);
             }
             finally
             {
                 dbConnection.Close();
             }
         }
     }
 }
        public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth)
        {
            var mapper = MapperHelper.GetMapper();
            WorkflowDao workflowdao = new WorkflowDao(mapper);
            ActivityDao activitydao = new ActivityDao(mapper);
            LinkDao linkdao = new LinkDao(mapper);
            ActivityAuthDao aadd = new ActivityAuthDao(mapper);
            TaskDao taskdao = new TaskDao(mapper);
            WorkflowModel model = null;
            Workflow wf = this.value.ConvertTo<Workflow>();
            wf.ID = null;
            wf.Creator = creator;
            wf.Status = (int)WorkflowProcessStatus.Started;
            wf.WorkflowDefinitionID = this.value.ID;
            wf.ProcessID = processid;
            workflowdao.Add(wf);

            var activites = this.ActivityDefinitionList;
            var links = this.LinkDefinitionList;
            List<Activity> activityEntities = new List<Activity>();
            foreach (var a in activites)
            {
                Activity activity = a.Value.ConvertTo<Activity>();
                activity.Creator = creator;
                activity.ID = null;
                activity.WorkflowID = wf.ID;
                activity.ActivityDefinitionID = a.Value.ID;
                activity.Title = a.Value.Title;
                activity.Status = (int)ActivityProcessStatus.Started;

                List<ActivityAuth> authList = new List<ActivityAuth>();

                //如果是开始节点,就设置为已处理
                if (this.Root.Equals(a))
                {
                    activity.Status = (int)ActivityProcessStatus.Processed;
                    activity.ProcessTime = DateTime.Now;
                }
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    activity.Status = (int)ActivityProcessStatus.Processing;
                }
                activitydao.Add(activity);
                activityEntities.Add(activity);

                //权限处理
                foreach (var ad in a.AuthDefinition)
                {
                    ActivityAuth auth = ad.ConvertTo<ActivityAuth>();
                    auth.Creator = creator;
                    auth.WorkflowID = wf.ID;
                    auth.ActivityID = activity.ID;
                    auth.ID = null;
                    auth.ActivityAuthDefinitionID = ad.ID;
                    aadd.Add(auth);
                    authList.Add(auth);
                }

                //如果是第二节点,就设置成正在处理
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    ActivityModel activitymodel = new ActivityModel
                    {
                        Value = activity,
                    };
                    var idlist = iauth.GetUserIDList(authList);
                    var tasklist = activitymodel.GetTask(creator, idlist);
                    foreach (var task in tasklist)
                    {
                        taskdao.Add(task);
                    }
                }
            }

            foreach (var l in links)
            {
                Link link = l.Value.ConvertTo<Link>();
                link.Creator = creator;
                link.WorkflowID = wf.ID;
                link.ID = null;
                link.LinkDefinitionID = l.Value.ID;
                var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID);
                var totactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID);
                if (fromactivity != null)
                {
                    link.FromActivityID = fromactivity.ID;
                }
                if (totactivity != null)
                {
                    link.ToAcivityID = totactivity.ID;
                }
                linkdao.Add(link);
            }

            model = WorkflowModel.Load(wf.ID);
            return model;
        }