Ejemplo n.º 1
0
        public async static void Start()
        {
            while (true)
            {
                var waittime = 24 * 60 * 60 * 1000;
                try
                {
                    using (var db = new BizDataContext())
                    {
                        var temp = db.Set <T_Configuration>().Where(p => p.Configuration_Key == CommonHelper.SERVERKEY).FirstOrDefault();
                        if (temp != null)
                        {
                            waittime = Int32.Parse(temp.Configuration_Value);
                        }

                        var servers = db.Set <T_HTZ_Server>().Where(p => p.State == v_common.YesState).Select(p => new v_server(p));

                        foreach (var item in servers)
                        {
                            await SaveData(item);
                        }
                    }
                }
                catch (Exception e)
                {
                }
                finally
                {
                    Thread.Sleep(waittime);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 启动方法
        /// </summary>
        public async static void Start()
        {
            while (true)
            {
                var waitTime = milliscond_OneDay;

                var infoCrawlers = new List <v_crawler>();

                using (var db = new BizDataContext())
                {
                    var dbWaitTime = db.Set <T_Configuration>().Where(p => p.Configuration_Key == INFORMATIONKEY).FirstOrDefault();
                    if (dbWaitTime != null)
                    {
                        waitTime = Int32.Parse(dbWaitTime.Configuration_Value);
                    }

                    infoCrawlers = await db.Set <T_HTZ_CrawlerService>().Where(p => p.State == v_common.YesState && p.ServiceType == (int)HTZ_CrawlerService_ServiceTypeEnum.Information && p.IsEnable.Value).Select(p => new v_crawler
                    {
                        id          = p.HTZ_CrawlerService_Id,
                        infotype    = p.InfoType ?? 0,
                        name        = p.HTZ_CrawlerService_Name,
                        xmlfile     = p.XMLFilePath,
                        crawlertype = (int)HTZ_CrawlerService_ServiceTypeEnum.Information
                    }).ToListAsync();
                }

                foreach (var item in infoCrawlers)
                {
                    InfomationCrawler(item);
                }

                Thread.Sleep(waitTime);
            }
        }
Ejemplo n.º 3
0
        private List <AppFunc> GetAppList(BizDataContext context, IUserIdentity user)
        {
            int appUserState = 1;

            return((from s in context.Set <SysFunction>()
                    join a in context.Set <T_Application_User>() on s.AppId equals(long?) a.Application_ID
                    where ((a.State == appUserState) && (a.OwnerId == user.User_ID)) && ((s.Permission_Type == null) || (s.Permission_Type == 0L))
                    select new AppFunc {
                AppId = a.Application_ID, FuncId = s.Function_ID.ToInt(), FuncName = s.Permission_Name
            }).ToList <AppFunc>());
        }
Ejemplo n.º 4
0
        public async static void Start()
        {
            while (true)
            {
                var waittime = 24 * 60 * 60 * 1000;

                try
                {
                    using (var db = new BizDataContext())
                    {
                        var temp = db.Set <T_Configuration>().Where(p => p.Configuration_Key == CommonHelper.LINKKEY).FirstOrDefault();
                        if (temp != null)
                        {
                            waittime = Int32.Parse(temp.Configuration_Value);
                        }

                        var services = await db.Set <T_HTZ_ServiceApp>().Where(p => p.State == v_common.YesState).ToListAsync();

                        foreach (var item in services)
                        {
                            if (item.App_IsEnable ?? false)
                            {
                                LinkValidate(item.HTZ_ServiceApp_Id, item.App_URL, (int)ServiceType.App, item.HTZ_ServiceApp_Name);
                            }

                            if (item.Web_IsEnable ?? false)
                            {
                                LinkValidate(item.HTZ_ServiceApp_Id, item.Web_URL, (int)ServiceType.Web, item.HTZ_ServiceApp_Name);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var e = new CrawlerException()
                    {
                        crawlertype      = (int)HTZ_ExceptionHandler_ServiceTypeEnum.Service,
                        exceptionbrief   = "应用服务链路异常",
                        exceptionmessage = ex.Message,
                        statuscode       = 501,
                        serviceid        = 1
                    };
                    await CommonHelper.SaveException(e);
                }
                finally
                {
                    Thread.Sleep(waittime);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 保存最新服务状态
        /// </summary>
        /// <param name="servicestate">服务状态</param>
        /// <param name="serviceid">服务id</param>
        /// <param name="costTime">花费时间</param>
        /// <param name="serverAppType">链接服务监控时,是App还是web</param>
        /// <returns></returns>
        public async static Task SaveNewState(int servicestate, int serviceid, int?costTime = null, int?serverAppType = null)
        {
            using (var db = new BizDataContext())
            {
                var entity = await db.Set <T_HTZ_ServiceState>().Where(p => p.State == v_common.YesState && p.ObjectId == serviceid && p.ServiceType == serverAppType).FirstOrDefaultAsync();

                if (entity == null)
                {
                    entity                     = new T_HTZ_ServiceState();
                    entity.CreateTime          = DateTime.Now;
                    entity.HTZ_ServiceState_Id = await db.GetNextIdentity_IntAsync();

                    entity.ServiceState    = servicestate;
                    entity.ServiceType     = serverAppType;//链接服务监控时,是App还是web
                    entity.State           = v_common.YesState;
                    entity.ObjectId        = serviceid;
                    entity.RequestCostTime = costTime;
                    entity.UpdateTime      = entity.CreateTime;

                    await db.InsertAsync(entity);
                }
                else
                {
                    entity.UpdateTime      = DateTime.Now;
                    entity.ServiceState    = servicestate;
                    entity.RequestCostTime = costTime;

                    await db.UpdatePartialAsync(entity, p => new { p.UpdateTime, p.ServiceState, p.RequestCostTime });
                }
            }
        }
Ejemplo n.º 6
0
        public static async Task SaveServerDisks(BizDataContext db, v_server server)
        {
            var dbdisks = await db.Set <T_HTZ_ServerHardDisk>().Where(p => p.State == v_common.YesState && p.HTZ_ServerId == server.id).ToListAsync();

            foreach (var item in server.disks)
            {
                var disk = dbdisks.Where(p => p.HTZ_ServerHardDisk_Name == item.name && p.State == v_common.YesState).FirstOrDefault();

                if (disk == null)
                {
                    disk = new T_HTZ_ServerHardDisk();
                    disk.HTZ_ServerHardDisk_Name = item.name;
                    disk.CreateTime            = DateTime.Now;
                    disk.UpdateTime            = DateTime.Now;
                    disk.TotalCapacity         = (int)(item.Size / 1024 / 1024 / 1024);
                    disk.UserCapacity          = (int)(item.FreeSpace / 1024 / 1024 / 1024);
                    disk.State                 = v_common.YesState;
                    disk.UpdateTime            = disk.CreateTime;
                    disk.HTZ_ServerHardDisk_Id = await db.GetNextIdentity_IntAsync();

                    disk.HTZ_ServerId = server.id;

                    await db.InsertAsync(disk);
                }
                else
                {
                    disk.UpdateTime    = DateTime.Now;
                    disk.TotalCapacity = (int)(item.Size / 1024 / 1024 / 1024);
                    disk.UserCapacity  = (int)(item.FreeSpace / 1024 / 1024 / 1024);
                    await db.UpdatePartialAsync(disk, p => new { p.UpdateTime, p.TotalCapacity, p.UserCapacity });
                }
            }
        }
Ejemplo n.º 7
0
        private void BindWorkItem()
        {
            using (BizDataContext context = new BizDataContext())
            {
                var wibList = context.Set <T_WorkItemBase>().Where(p =>
                                                                   p.WorkItemTypeID == null && p.Entity_Trace_PlanID == null &&
                                                                   p.OwnerId == LoginUserID && p.State == (int)WorkItemStatus.Created).OrderByDescending(p => p.CreateTime);

                var result = wibList.Skip(this.PageIndex_WorkItem * this.PageSize_WorkItem).Take(this.PageSize_WorkItem).ToList();

                var source = from wi in result
                             orderby wi.CreateTime descending
                             select new
                {
                    wi.Title,
                    wi.CreateTime,
                    wi.CompletePageUrl,
                    wi.WorkItemId,
                    wi.WorkItemBase_Id,
                    User_Name = GetStartUserName(context, wi.WorkItemId),
                };

                gcWorkItem.DataSource = source.ToList();
                gcWorkItem.PagerSettings.DataCount = wibList.Count();
                gcWorkItem.DataBind();
            }
        }
        /// <summary>
        /// 启用流程,只有“停用”状态的可以启用
        /// </summary>
        public void StartProcess()
        {
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
            {
                using (BizDataContext db = new BizDataContext())
                {
                    if (_process != null && _process.ProcessStatus == (int)ProcessState.Stoped)
                    {
                        int count = db.Set <SysProcess>().Count(p => p.ProcessType == _process.ProcessType &&
                                                                p.ProcessStatus == (int)ProcessState.StartUsed);
                        if (count > 0)
                        {
                            throw new Exception("该流程已经存在已启用的版本,请先停用");
                        }

                        _process.ProcessStatus = (int)ProcessState.StartUsed;
                        db.UpdatePartial(_process, p => new { p.ProcessStatus });
                    }
                    else
                    {
                        throw new Exception("流程不存在或当前流程状态不能启用");
                    }
                }
                ts.Complete();
            }
        }
Ejemplo n.º 9
0
        private void BindRemind()
        {
            using (BizDataContext context = new BizDataContext())
            {
                var query = context.Set <SysRemind>().Where(p => p.State == (int)RemindStausEnum.New &&
                                                            p.OwnerId == LoginUserID).OrderByDescending(p => p.CreateTime);

                var result = query.Skip(this.PageIndex_Remind * this.PageSize_Remind).Take(this.PageSize_Remind).ToList();

                var source = result.Select(p => new
                {
                    p.RemindId,
                    p.RemindName,
                    p.RemindURL,
                    CreateUserName = GetUserName(context, p.CreateUserId),
                    p.CreateTime,
                    p.DeadLine,
                    RemindUrl = CreateUrl(p.RemindURL, p.RemindId),
                }).ToList();

                gcRemind.DataSource = source;
                gcRemind.PagerSettings.DataCount = query.Count();
                gcRemind.DataBind();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 旧的提醒,已抛弃
        /// </summary>
        private void BindRemind_Old()
        {
            using (BizDataContext context = new BizDataContext())
            {
                var query = context.Set <SysRemind>().Where(item => item.State == (int)RemindStausEnum.New &&
                                                            item.OwnerId == this.LoginUserID).OrderByDescending(x => x.CreateTime);

                var result = query.Take(6).ToList();
                var source = result.Select(item => new
                {
                    item.RemindId,
                    RemindName = GetString(item.RemindName, 35),
                    item.RemindURL,
                    OwnerUserName = GetUserName(context, item.OwnerId),
                    item.CreateTime,
                    item.DeadLine,
                }).ToList();


                this.RemindCount        = query.Count();
                this.rRemind.DataSource = source.Select(item => new
                {
                    item.RemindId,
                    item.RemindName,
                    RemindUrl = GetRemindUrl(item.RemindURL, item.RemindId),
                    item.OwnerUserName,
                    CreateTime = GetDate(item.CreateTime),
                    item.DeadLine,
                }).ToList();
                this.rRemind.DataBind();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 查询所有工作流
        /// </summary>
        /// <returns></returns>
        public IEnumerable <WfProcess> GetWorkFlowList()
        {
            Drision.Framework.Entity.EntityCache cache = Drision.Framework.Entity.EntityCache.New();
            using (BizDataContext context = new BizDataContext())
            {
                var processList = context.Set <SysProcess>().Where(p => p.ProcessCategory != (int)ProcessCategory.FormApprove).ToList();
                foreach (var p in processList)
                {
                    p.ActivityEntity = cache.FindById <SysEntity>(p.ActivityEntityId); // context.FindById<SysEntity>(p.ActivityEntityId);
                    p.ProcessEntity  = cache.FindById <SysEntity>(p.EntityId);         // context.FindById<SysEntity>(p.EntityId);
                }

                return(processList.Select(p => new
                {
                    ActivityEntityName = p.ActivityEntity != null ? p.ActivityEntity.EntityName : "",
                    EntityName = p.ProcessEntity != null ? p.ProcessEntity.EntityName : "",
                    p.ProcessName,
                    p.ProcessId,
                    p.ProcessStatus,
                    p.ProcessCategory,
                    p.ProcessVersion,
                    CanDelete = p.ProcessStatus == (int)ProcessState.Created,
                }).ConvertTo <WfProcess>());
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 新,站内信
        /// </summary>
        private void BindRemind()
        {
            using (BizDataContext context = new BizDataContext())
            {
                //查询SysInternalMailReceiver表中UserId为当前登录人,并且State为1-已接收
                //并且关联的SysInternalMailSender表的State不为0-草稿的记录
                //并且未读
                var list = from mailReceiver in context.Set <SysInternalMailReceiver>()
                           join mailSender in context.Set <SysInternalMailSender>()
                           on mailReceiver.SenderId equals mailSender.SenderId
                           join mail in context.Set <SysInternalMail>()
                           on mailSender.MailId equals mail.MailId
                           where mailReceiver.UserId == this.LoginUserID && mailReceiver.State == (int)InternalMailReceiverState.IsReceived &&
                           mailSender.State != (int)InternalMailSenderState.Draft &&
                           mailReceiver.IsRead != true
                           orderby mailReceiver.ReceiveTime descending
                           select new
                {
                    mailReceiver.ReceiverId,
                    mailReceiver.ReceiveTime,
                    mail.Subject,
                    mailSender.UserId,
                    mailReceiver.IsRead,
                };
                var result = list.Take(6).ToList();
                var source = result.Select(item => new
                {
                    ReceiverId  = item.ReceiverId,
                    Subject     = GetString(item.Subject, 35),
                    Url         = string.Format("../InternalMail/InternalMailDetail.aspx?type=receiver&id={0}", item.ReceiverId),
                    ReceiveTime = GetDate(item.ReceiveTime),
                }).ToList();


                this.RemindCount        = list.Count();
                this.rRemind.DataSource = source;
                this.rRemind.DataBind();
            }
        }
 internal static ConnectionInfo GetConnectionInfoFromWebFoundation(int companyId)
 {
     using (BizDataContext context = new BizDataContext("WebFoundation", true))
     {
         T_Company_AppDb db = (from p in context.Set <T_Company_AppDb>()
                               where p.CompanyId == companyId
                               select p).FirstOrDefault <T_Company_AppDb>();
         if (db == null)
         {
             throw new ApplicationException("未指定企业的数据库连接:id=" + companyId.ToString());
         }
         return(new ConnectionInfo(db.DbConnString, db.DbPrivider));
     }
 }
Ejemplo n.º 14
0
        public async static Task SendErrorMessage(BizDataContext db, CrawlerException e)
        {
            string msg = string.Format("{0},发生了异常,异常信息为:<br/>{1}<br/>更多信息请打开高新区智慧生活后台查看。", e.servicename, e.exceptionbrief);

            var handlers = await db.Set <T_HTZ_ExceptionHandler>().Where(p => p.ServiceType == e.crawlertype && p.State == v_common.YesState).ToListAsync();

            var nearLog = await db.Set <T_HTZ_ExceptionHandlerLog>().Where(p => p.ObjectId == e.serviceid && p.State == v_common.YesState).OrderByDescending(p => p.HTZ_ExceptionHandlerLog_Id).FirstOrDefaultAsync();

            if (nearLog != null && nearLog.CreateTime > DateTime.Now.AddHours(-8))
            {
                return;
            }

            var mails = handlers.Where(p => !string.IsNullOrEmpty(p.Email)).Select(p => p.Email).ToArray();

            if (mails.Length < 1)
            {
                return;
            }

            var mail = new MyMailManager();

            mail.SetMailMessageAndSend(msg, mails);

            var log = new T_HTZ_ExceptionHandlerLog();

            log.CreateTime   = DateTime.Now;
            log.HandlerIdStr = string.Join(",", handlers.Select(p => p.HTZ_ExceptionHandler_Id).ToArray());
            log.HTZ_ExceptionHandlerLog_Id = await db.GetNextIdentity_IntAsync();

            log.Message     = msg;
            log.MessageType = (int)HTZ_ExceptionHandlerLog_MessageTypeEnum.Mail;
            log.ObjectId    = e.serviceid;
            log.State       = v_common.YesState;
            await db.InsertAsync(log);
        }
Ejemplo n.º 15
0
        public async static Task SaveLivingIndexData(string html, XmlNode xmlRoot, BizDataContext db)
        {
            var rootNode = CommonHelper.GetRootNode(html);

            //获取对实体解析的配置节点
            var infoConfig = xmlRoot.SelectSingleNode("LivingIndexConfig");

            var date = DateTime.Now;


            var entity = new T_HTZ_LivingIndex();


            //解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
            foreach (XmlNode property in infoConfig.ChildNodes)
            {
                entity = CommonHelper.GetProperty(entity, rootNode, property);
            }

            //查询天气数据
            var dbentity = (from a in db.Set<T_HTZ_LivingIndex>()

                            where a.CreateTime == DateTime.Now.Date

                            select a).FirstOrDefault();

            if (dbentity != null)
            {
                entity.HTZ_LivingIndex_Id = dbentity.HTZ_LivingIndex_Id;
                entity.CreateTime = dbentity.CreateTime;
                entity.UpdateTime = DateTime.Now;

                await db.UpdateAsync(entity);
            }
            else
            {
                entity.HTZ_LivingIndex_Id = db.GetNextIdentity_Int();
                entity.CreateTime = DateTime.Now.Date;

                await db.InsertAsync(entity);
            }

        }
Ejemplo n.º 16
0
 public List <T_Role> QueryRoles(string roleName = null, int pageIndex = 1, int pageSize = 10)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         IQueryable <T_Role> source = context.Set <T_Role>();
         if (!string.IsNullOrWhiteSpace(roleName))
         {
             source = from t in source
                      where t.Role_Name.Contains(roleName)
                      select t;
         }
         source = from t in source
                  orderby t.Role_Name
                  select t;
         if (pageIndex <= 1)
         {
             pageIndex = 1;
         }
         return(source.Skip <T_Role>(((pageIndex - 1) * pageSize)).Take <T_Role>(pageSize).ToList <T_Role>());
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 绑定角色ID号
        /// </summary>
        private void BingDataToRoleId(string roleId)
        {
            //如果传入ID号有误,则变成下拉菜单来处理
            bool nextSetp = true;

            using (BizDataContext Context = new BizDataContext())
            {
                if (!string.IsNullOrEmpty(roleId))
                {
                    this.RoleId = Convert.ToInt32(roleId);

                    var role = Context.FindById <T_Role>(RoleId);
                    if (null != role)
                    {
                        this.lblRoleName.Text    = role.Role_Name;
                        this.lblRoleName.Visible = true;
                        this.ddlRoleList.Visible = false;
                        nextSetp = false;
                        BingDataToDataList();
                    }
                }

                if (nextSetp)
                {
                    var roleList = Context.Set <T_Role>().ToList();
                    this.ddlRoleList.DataSource     = roleList;
                    this.ddlRoleList.DataValueField = "Role_ID";
                    this.ddlRoleList.DataTextField  = "Role_Name";
                    this.ddlRoleList.DataBind();

                    this.RoleId = Convert.ToInt32(this.ddlRoleList.SelectedValue);

                    this.ddlRoleList.Visible = true;
                    this.lblRoleName.Visible = false;
                }
            }
        }
Ejemplo n.º 18
0
        private void BindWorkItem()
        {
            using (BizDataContext context = new BizDataContext())
            {
                var source = context
                             .Set <T_WorkItemBase>().Where(p => p.State == (int)WorkItemStatus.Created &&
                                                           p.OwnerId == this.LoginUserID)
                             .OrderByDescending(p => p.CreateTime);

                var list = source.Take(6).ToList().Select(p => new
                {
                    p.WorkItemId,
                    CreateTime  = GetDate(p.CreateTime),
                    DisplayText = GetString(p.Title, 35),
                    WorkItemURL = p.CompletePageUrl,
                    EndTime     = GetDate(p.EndTime),
                }).ToList();

                this.WorkItemCount = source.Count();

                this.rWorkItem.DataSource = list;
                this.rWorkItem.DataBind();
            }
        }
Ejemplo n.º 19
0
        private void BindSchedule()
        {
            using (BizDataContext context = new BizDataContext())
            {
                var source = context.Set <T_WorkItemBase>().Where(p =>
                                                                  p.WorkItemTypeID != null && p.Entity_Trace_PlanID != null &&
                                                                  p.OwnerId == LoginUserID && p.State == (int)WorkItemStatus.Created)
                             .OrderByDescending(p => p.CreateTime);

                var result = source.Skip(this.PageIndex_Schedule * this.PageSize_Schedule).Take(this.PageSize_Schedule).ToList();

                var list = result.Select(p => new
                {
                    p.WorkItemId,
                    p.CreateTime,
                    p.Title,
                    ProcessPageUrl = p.CompletePageUrl,
                    DeadLine       = p.EndTime,
                }).ToList();
                gcSchedule.DataSource = list;
                gcSchedule.PagerSettings.DataCount = source.Count();
                gcSchedule.DataBind();
            }
        }
        /// <summary>
        /// 复制流程,从“已启用”或“已升级”的流程进入设计,需要先复制一份流程供设计
        /// 状态为“新增”,版本为当前最高版本 + 1
        /// </summary>
        public SysProcess CopyProcess()
        {
            SysProcess result;

            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
            {
                using (BizDataContext db = new BizDataContext())
                {
                    //新流程
                    SysProcess newP = _process.ConvertTo <SysProcess>();
                    newP.ProcessId = db.GetNextIdentity();

                    //版本处理
                    newP.ProcessStatus = (int)ProcessState.Created;
                    string maxVersion = db.Set <SysProcess>().Where(p => p.ProcessType == _process.ProcessType).OrderByDescending(p => p.ProcessVersion).First().ProcessVersion;
                    newP.ProcessVersion = (maxVersion.ToInt() + 1).ToString();

                    result = newP;
                    db.Insert(newP);

                    //新流程参与人
                    var ppList = db.Set <SysProcessParticipant>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    Dictionary <long?, SysProcessParticipant> tempPpDict = new Dictionary <long?, SysProcessParticipant>();
                    foreach (var pp in ppList)
                    {
                        SysProcessParticipant newPp = pp.ConvertTo <SysProcessParticipant>();
                        newPp.ParticipantId = db.GetNextIdentity();
                        newPp.ProcessId     = newP.ProcessId;

                        tempPpDict[pp.ParticipantId] = newPp; //记录原始ID和新对象的关系
                    }
                    foreach (var newPp in tempPpDict.Values)
                    {
                        if (newPp.Param_ParticipantId != null) //通过刚才记录的关系找到实际的值
                        {
                            newPp.Param_ParticipantId = tempPpDict[newPp.Param_ParticipantId].ParticipantId;
                        }
                        db.Insert(newPp);
                    }

                    //新活动
                    var aList = db.Set <SysActivity>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    Dictionary <long?, SysActivity> tempADict = new Dictionary <long?, SysActivity>();
                    foreach (var a in aList)
                    {
                        SysActivity newA = a.ConvertTo <SysActivity>();
                        newA.ActivityId = db.GetNextIdentity();
                        newA.ProcessId  = newP.ProcessId;

                        tempADict[a.ActivityId] = newA;//记录原始ID和新对象的关系
                        db.Insert(newA);

                        //新活动参与人
                        var apList = db.Set <SysActivityParticipant>().Where(p => p.ActivityId == a.ActivityId).ToList();
                        foreach (var ap in apList)
                        {
                            SysActivityParticipant newAp = ap.ConvertTo <SysActivityParticipant>();
                            newAp.ActivityParticipantId = db.GetNextIdentity();
                            newAp.ActivityId            = newA.ActivityId;
                            newAp.ParticipantId         = tempPpDict[newAp.ParticipantId].ParticipantId; //通过刚才记录的关系找到实际的值
                            db.Insert(newAp);
                        }
                    }

                    //连接线
                    var tList = db.Set <SysTransition>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    foreach (var t in tList)
                    {
                        SysTransition newT = t.ConvertTo <SysTransition>();
                        newT.TransitionId = db.GetNextIdentity();
                        newT.ProcessId    = newP.ProcessId;

                        //通过刚才记录的关系找到实际的值
                        newT.PreActivityId  = tempADict[newT.PreActivityId].ActivityId;
                        newT.PostActivityId = tempADict[newT.PostActivityId].ActivityId;

                        db.Insert(newT);
                    }

                    //表单活动权限
                    var fpList = db.Set <SysFormPrivilege>().Where(p => p.ProcessId == _process.ProcessId).ToList();
                    foreach (var fp in fpList)
                    {
                        SysFormPrivilege newFp = fp.ConvertTo <SysFormPrivilege>();
                        newFp.PrivilegeId = db.GetNextIdentity();
                        newFp.ProcessId   = newP.ProcessId;
                        newFp.ActivityId  = tempADict[newFp.ActivityId].ActivityId;//通过刚才记录的关系找到实际的值

                        db.Insert(newFp);
                    }
                }
                ts.Complete();
            }
            return(result);
        }
Ejemplo n.º 21
0
        public async void ActiveUsersByMonth()
        {
            try
            {
                using (var db = new BizDataContext())
                {
                    var query = await db.Set <T_GW_LoginLog>().Where(p => p.State == v_common.YesState).Select(p => new
                    {
                        createtime   = p.CreateTime,
                        cretetimestr = p.CreateTime.Value.ToString(),
                        year_int     = p.CreateTime.Value.Year,
                        month_int    = p.CreateTime.Value.Month,
                        ownerid      = p.OwnerId,
                        monthval     = p.CreateTime.Value.Month.ToString()
                    }).ToListAsync();


                    #region 用户表用户统计
                    string sql2 = @"select a.area_id, a.area_name, u.createtime ,u.loginname 
from T_user u
left join t_area a on u.opaccountcode = a.area_id
where u.state <> 9999";

                    DataTable dt2 = db.ExecuteDataTable(sql2);

                    var queryuser = dt2.Rows.OfType <DataRow>()
                                    .Select(p => new
                    {
                        areaid     = p["area_id"].ToString(),
                        areaname   = p["area_name"].ToString(),
                        createtime = p["createtime"].ToString(),
                        loginname  = p["loginname"].ToString(),
                    });

                    var modeluser = queryuser.ToList();
                    //用户表
                    var queryuser2 = modeluser.GroupBy(x => new { x.areaid, x.areaname }).
                                     Select(x => new v_areauser {
                        areaid = x.Key.areaid, areaname = x.Key.areaname, mulist = x.Select(p => new v_mu {
                            createtime = Convert.ToDateTime(p.createtime)
                        }).ToList()
                    });

                    var modeluser2 = queryuser2.ToList();
                    #endregion

                    var model  = query.ToList();
                    var query2 = model.GroupBy(x => new { x.area_id, x.area_name }).Select(x => new v_activeusers
                    {
                        areaid   = x.Key.area_id,
                        areaname = x.Key.area_name,
                        users    = x.GroupBy(p => new { p.month_int, p.createtimestr }).Select(p => new v_monthusers {
                            month = p.Key.month_int, createtimestr = p.Key.createtimestr, countusers = p.Count()
                        }).ToList()
                    }
                                                                                           );


                    var model2 = query2.ToList();
                    List <v_activeusers> aulist = new List <v_activeusers>();
                    List <v_monthusers>  mulist = null;;
                    v_activeusers        au     = null;
                    v_monthusers         mu     = null;

                    foreach (var x in model2)
                    {
                        au          = new v_activeusers();
                        au.areaid   = x.areaid;
                        au.areaname = x.areaname;
                        mulist      = new List <v_monthusers>();

                        for (int i = 2; i <= 4; i++)
                        {
                            mu               = new v_monthusers();
                            mu.month         = i;
                            mu.createtimestr = new DateTime(2017, i, 1).ToString("yyyy-MM");
                            int mcount      = 0;
                            int mtotalcount = x.users.Count();
                            foreach (var item in x.users)
                            {
                                mcount++;
                                if (item.month == i)
                                {
                                    mu.countusers = item.countusers;
                                    break;
                                }
                                else if (mcount == mtotalcount)
                                {
                                    mu.countusers = 0;
                                }
                            }
                            mulist.Add(mu);
                        }
                        au.users = mulist;
                        aulist.Add(au);
                    }
                    ///获取用户总数


                    List <T_GW_UserStatistics> entitylist = new List <T_GW_UserStatistics>();
                    T_GW_UserStatistics        entity     = null;
                    foreach (var item in aulist)
                    {
                        if (item.areaname == "")
                        {
                            var M = modeluser2.Where(x => x.areaname == item.areaname).FirstOrDefault().mulist;
                            foreach (var x in item.users)
                            {
                                entity = new T_GW_UserStatistics();
                                entity.GW_UserStatistics_Id = db.GetNextIdentity_Int();
                                entity.AreaId          = 0;
                                entity.AreaName        = "未填写";
                                entity.YearMonth       = x.createtimestr;
                                entity.MonthVal        = x.month;
                                entity.ActiveUserCount = x.countusers;
                                DateTime nextmonth = Convert.ToDateTime(x.createtimestr).AddMonths(1);
                                entity.UserCount  = M.Where(p => p.createtime < nextmonth).Count();
                                entity.CreateTime = DateTime.Now;
                                entitylist.Add(entity);
                            }
                        }
                        else
                        {
                            var M = modeluser2.Where(x => x.areaname == item.areaname).FirstOrDefault().mulist;
                            foreach (var x in item.users)
                            {
                                entity = new T_GW_UserStatistics();
                                entity.GW_UserStatistics_Id = db.GetNextIdentity_Int();
                                entity.AreaId          = item.areaid.ToInt();
                                entity.AreaName        = item.areaname;
                                entity.YearMonth       = x.createtimestr;
                                entity.MonthVal        = x.month;
                                entity.ActiveUserCount = x.countusers;
                                DateTime nextmonth = Convert.ToDateTime(x.createtimestr).AddMonths(1);
                                entity.UserCount  = M.Where(p => p.createtime < nextmonth).Count();
                                entity.CreateTime = DateTime.Now;
                                entitylist.Add(entity);
                            }
                        }
                    }
                    db.BatchInsert(entitylist);
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "FirstStatistics", rootdir);
            }
        }
Ejemplo n.º 22
0
        public void DoStatisticsMobile()
        {
            try
            {
                using (var db = new BizDataContext())
                {
                    string sql = @"select t2.equipmenttype,t2.osversion from 
    (
      select row_number() over(partition by t0.ownerid order by  t0.createtime desc) rownumb, t0.equipmenttype, t0.osversion from t_Gw_Loginlog t0 
      inner join T_user t1 on (t1.state <> 9999 and t0.ownerid = t1.user_id)
        
      order by t0.ownerid, t0.createtime desc 
    ) t2 where t2.rownumb = 1";

                    DataTable dt = db.ExecuteDataTable(sql);

                    var query = dt.Rows.OfType <DataRow>()
                                .Select(p => new
                    {
                        equipmenttype = p["equipmenttype"].ToString(),
                        osversion     = p["osversion"].ToString(),
                    });

                    var model = query.GroupBy(x => x.equipmenttype).Select(x => new
                    {
                        ostype = x.Key,
                        count  = x.Count(),
                        vals   = x
                    });
                    //获取所有数据
                    var modelList = db.Set <T_GW_MobileStatistics>().ToList();


                    List <T_GW_MobileStatistics> addlist    = new List <T_GW_MobileStatistics>();
                    List <T_GW_MobileStatistics> updatelist = new List <T_GW_MobileStatistics>();
                    foreach (var x in model)
                    {
                        T_GW_MobileStatistics entity = new T_GW_MobileStatistics();
                        string ostype = x.ostype;
                        if (string.IsNullOrEmpty(x.ostype))
                        {
                            ostype = null;
                        }

                        entity.OSType         = ostype;
                        entity.TotalCount     = x.count;
                        entity.StatisticsType = "os";


                        if (modelList.Where(p => p.StatisticsType == "os" && p.OSType == ostype).FirstOrDefault() != null)
                        {
                            updatelist.Add(entity);
                        }
                        else
                        {
                            entity.GW_MobileStatistics_Id = db.GetNextIdentity_Int();
                            entity.CreateTime             = DateTime.Now;
                            entity.State = 1;
                            addlist.Add(entity);
                        }


                        //string ostype = x.ostype;
                        foreach (var item in x.vals.GroupBy(p => p.osversion).Select(p => new { osvertion = p.Key, count = p.Count() }))
                        {
                            T_GW_MobileStatistics entity2 = new T_GW_MobileStatistics();
                            string osversion = item.osvertion;
                            if (string.IsNullOrEmpty(item.osvertion))
                            {
                                osversion = null;
                            }
                            entity2.OSType         = ostype;
                            entity2.OSVersion      = osversion;
                            entity2.TotalCount     = item.count;
                            entity2.StatisticsType = "ver";


                            if (modelList.Where(p => p.StatisticsType == "ver" && p.OSType == ostype && p.OSVersion == osversion).FirstOrDefault() != null)
                            {
                                updatelist.Add(entity2);
                            }
                            else
                            {
                                entity2.GW_MobileStatistics_Id = db.GetNextIdentity_Int();
                                entity2.CreateTime             = DateTime.Now;
                                entity2.State = 1;
                                addlist.Add(entity2);
                            }
                        }
                    }


                    foreach (var x in updatelist)
                    {
                        if (x.StatisticsType == "os")
                        {
                            var entity = db.Set <T_GW_MobileStatistics>().Where(p => p.StatisticsType == x.StatisticsType && p.OSType == x.OSType).FirstOrDefault();
                            if (entity != null)
                            {
                                entity.TotalCount = x.TotalCount;
                                entity.UpdateTime = DateTime.Now;
                                db.UpdatePartial(entity, xx => new { xx.TotalCount, xx.UpdateTime });
                            }
                        }
                        else if (x.StatisticsType == "ver")
                        {
                            var entity = db.Set <T_GW_MobileStatistics>().Where(p => p.StatisticsType == x.StatisticsType && p.OSType == x.OSType && p.OSVersion == x.OSVersion).FirstOrDefault();
                            if (entity != null)
                            {
                                entity.TotalCount = x.TotalCount;
                                entity.UpdateTime = DateTime.Now;
                                db.UpdatePartial(entity, xx => new { xx.TotalCount, xx.UpdateTime });
                            }
                        }
                    }

                    db.BatchInsert(addlist);
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "手机app版本号统计", rootdir);
            }
        }
Ejemplo n.º 23
0
        public void ActiveUsersByMonth_Update()
        {
            try
            {
                using (var db = new BizDataContext())
                {
                    string currenttime = DateTime.Now.ToString("yyyy-MM");

                    string sql = string.Format(@"select t6.year_int,t6.month_int,t6.createtimestr,t6.opaccountcode,t6.ownerid,t6.createtime,t7.area_name from 
  (
    select * from 
      (
        select to_number(to_char(t4.createtime, 'yyyy')) year_int,to_number(to_char(t4.createtime, 'mm')) month_int,to_char(t4.createtime, 'yyyy-mm')createtimestr,  t4.* from
          (
            select t3.opaccountcode,t2.ownerid, t2.createtime from t_user t3 
             inner join 
             (select t1.* from 
            (select row_number() over(partition by t0.ownerid, to_char(t0.createtime, 'yyyy-mm') order by  t0.createtime desc) rownumb, t0.ownerid, t0.phone, t0.createtime from t_Gw_Loginlog t0 
            order by t0.phone, t0.createtime desc) t1 where t1.rownumb = 1
            ) t2 on (t3.state <> 9999 and t2.ownerid = t3.user_id)
          ) t4
       ) t5 where t5.createtimestr = '{0}' 
   ) t6 
   left join T_area t7 on t6.opaccountcode = t7.area_id 
   order by t6.month_int", currenttime);



                    DataTable dt    = db.ExecuteDataTable(sql);
                    var       query = dt.Rows.OfType <DataRow>()
                                      .Select(p => new
                    {
                        createtime    = Convert.ToDateTime(p["createtime"]),
                        createtimestr = p["createtimestr"].ToString(),
                        year_int      = Convert.ToInt32(p["year_int"]),
                        month_int     = Convert.ToInt32(p["month_int"]),
                        ownerid       = p["ownerid"].ToString(),
                        area_id       = p["opaccountcode"].ToString(),
                        area_name     = p["area_name"].ToString(),
                        monthval      = p["month_int"].ToString(),
                    });


                    #region 用户表用户统计
                    string sql2 = @"select a.area_id, a.area_name, u.createtime ,u.loginname 
from T_user u
left join t_area a on u.opaccountcode = a.area_id
where u.state <> 9999";

                    DataTable dt2 = db.ExecuteDataTable(sql2);

                    var queryuser = dt2.Rows.OfType <DataRow>()
                                    .Select(p => new
                    {
                        areaid     = p["area_id"].ToString(),
                        areaname   = p["area_name"].ToString(),
                        createtime = p["createtime"].ToString(),
                        loginname  = p["loginname"].ToString(),
                    });

                    var modeluser  = queryuser.ToList();
                    var queryuser2 = modeluser.GroupBy(x => new { x.areaid, x.areaname }).
                                     Select(x => new v_areauser {
                        areaid = x.Key.areaid, areaname = x.Key.areaname, mulist = x.Select(p => new v_mu {
                            createtime = Convert.ToDateTime(p.createtime)
                        }).ToList()
                    });

                    var modeluser2 = queryuser2.ToList();
                    #endregion

                    var model  = query.ToList();
                    var query2 = model.GroupBy(x => new { x.area_id, x.area_name }).Select(x => new v_activeusers
                    {
                        areaid   = x.Key.area_id,
                        areaname = x.Key.area_name,
                        users    = x.GroupBy(p => new { p.month_int, p.createtimestr }).Select(p => new v_monthusers {
                            month = p.Key.month_int, createtimestr = p.Key.createtimestr, countusers = p.Count()
                        }).ToList()
                    }
                                                                                           );


                    var model2 = query2.ToList();
                    List <v_activeusers> aulist = new List <v_activeusers>();
                    List <v_monthusers>  mulist = null;;
                    v_activeusers        au     = null;
                    v_monthusers         mu     = null;

                    foreach (var x in model2)
                    {
                        au          = new v_activeusers();
                        au.areaid   = x.areaid;
                        au.areaname = x.areaname;
                        mulist      = new List <v_monthusers>();
                        foreach (var item in x.users)
                        {
                            mu               = new v_monthusers();
                            mu.month         = item.month;
                            mu.createtimestr = item.createtimestr;
                            mu.countusers    = item.countusers;
                            mulist.Add(mu);
                        }
                        au.users = mulist;
                        aulist.Add(au);
                    }
                    ///获取用户总数


                    List <T_GW_UserStatistics> addlist        = new List <T_GW_UserStatistics>();
                    List <T_GW_UserStatistics> updatelist     = new List <T_GW_UserStatistics>();
                    T_GW_UserStatistics        userstatistics = null;
                    foreach (var item in aulist)
                    {
                        if (item.areaname == "")
                        {
                            var M = modeluser2.Where(x => x.areaname == item.areaname).FirstOrDefault().mulist;
                            foreach (var x in item.users)
                            {
                                userstatistics = new T_GW_UserStatistics();

                                userstatistics.AreaId          = 0;
                                userstatistics.AreaName        = "未填写";
                                userstatistics.YearMonth       = x.createtimestr;
                                userstatistics.MonthVal        = x.month;
                                userstatistics.ActiveUserCount = x.countusers;
                                userstatistics.UserCount       = M.Count();
                                var entity = db.Set <T_GW_UserStatistics>().Where(p => p.AreaId == 0 && p.AreaName == "未填写" && p.YearMonth == x.createtimestr).FirstOrDefault();
                                if (entity != null)
                                {
                                    entity.ActiveUserCount = userstatistics.ActiveUserCount;
                                    entity.UserCount       = userstatistics.UserCount;
                                    entity.UpdateTime      = DateTime.Now;
                                    db.UpdatePartial(entity, xx => new { xx.ActiveUserCount, xx.UserCount, xx.UpdateTime });
                                }
                                else
                                {
                                    userstatistics.GW_UserStatistics_Id = db.GetNextIdentity_Int();
                                    userstatistics.CreateTime           = DateTime.Now;
                                    addlist.Add(userstatistics);
                                }
                            }
                        }
                        else
                        {
                            var M = modeluser2.Where(x => x.areaname == item.areaname).FirstOrDefault().mulist;
                            foreach (var x in item.users)
                            {
                                userstatistics                 = new T_GW_UserStatistics();
                                userstatistics.AreaId          = item.areaid.ToInt();
                                userstatistics.AreaName        = item.areaname;
                                userstatistics.YearMonth       = x.createtimestr;
                                userstatistics.MonthVal        = x.month;
                                userstatistics.ActiveUserCount = x.countusers;
                                userstatistics.UserCount       = M.Count();

                                var entity = db.Set <T_GW_UserStatistics>().Where(p => p.AreaId == item.areaid.ToInt() && p.AreaName == item.areaname && p.YearMonth == x.createtimestr).FirstOrDefault();
                                if (entity != null)
                                {
                                    entity.ActiveUserCount = userstatistics.ActiveUserCount;
                                    entity.UserCount       = userstatistics.UserCount;
                                    entity.UpdateTime      = DateTime.Now;
                                    db.UpdatePartial(entity, xx => new { xx.ActiveUserCount, xx.UserCount, xx.UpdateTime });
                                }
                                else
                                {
                                    userstatistics.GW_UserStatistics_Id = db.GetNextIdentity_Int();
                                    userstatistics.CreateTime           = DateTime.Now;
                                    addlist.Add(userstatistics);
                                }
                            }
                        }
                    }

                    db.BatchInsert(addlist);
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "每天统计用户活跃度", rootdir);
            }
        }
Ejemplo n.º 24
0
        public async static Task SaveWeekData(string html, XmlNode xmlRoot, BizDataContext db)
        {
            var rootNode = CommonHelper.GetRootNode(html);

            //获取信息列表的配置节点
            var listConfig = xmlRoot.SelectSingleNode("ListConfig");

            //这里是为了最终找到modelListNodes变量的值,也就是列表
            //在此之前可能需要多次的剥离无效数据,因此使用了foreach循环
            //正常流程应该是多次SelectSingleNode后,进行一次SelectNodes,获取到列表
            HtmlNode modelNode = null;
            HtmlNodeCollection modelListNodes = null;
            foreach (XmlNode item in listConfig.ChildNodes)
            {
                if (modelNode == null)
                {
                    modelNode = rootNode;
                }

                if (item.Attributes["issingleselect"].Value.ToBool())
                {
                    //多次剥离无效数据
                    modelNode = modelNode.SelectSingleNode(item.Attributes["signstr"].Value);
                }
                else
                {
                    //最终获取到列表,此时应该循环结束
                    modelListNodes = modelNode.SelectNodes(item.Attributes["signstr"].Value);
                    break;
                }
            }

            //获取对实体解析的配置节点
            var infoConfig = xmlRoot.SelectSingleNode("WeatherConfig");

            var date = DateTime.Now;

            var weatherList = await db.Set<T_TemperatureHumidity>().Where(p => p.ActionDate >= DateTime.Now.Date).ToListAsync();

            //对上面获取到的列表循环处理
            foreach (HtmlNode info in modelListNodes)
            {

                T_TemperatureHumidity entity = new T_TemperatureHumidity();

                var detailUrl = string.Empty;

                //解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
                foreach (XmlNode property in infoConfig.ChildNodes)
                {
                    entity = CommonHelper.GetProperty(entity, info, property);
                }

                entity.State = v_common.YesState;
                entity.ActionDate = date.Date;
                entity.ActionYear = date.Year.ToString();
                entity.CreateTime = DateTime.Now;

                var id = weatherList.Where(p => p.ActionDate == date.Date).Select(p => p.TemperatureHumidity_Id).FirstOrDefault();

                if (id > 0)
                {
                    entity.TemperatureHumidity_Id = id;
                    entity.UpdateTime = DateTime.Now;

                    await db.UpdatePartialAsync(entity, p => new { p.TemperatureStr, p.Wheather, p.Wind, p.WindDirection, p.UpdateTime });
                }
                else
                {
                    entity.TemperatureHumidity_Id = await db.GetNextIdentity_IntAsync();
                    await db.InsertAsync(entity);
                }

                date = date.AddDays(1);
            }
        }
Ejemplo n.º 25
0
        public async static void Start()
        {
            while (true)
            {
                var waittime = 24 * 60 * 60 * 1000;
                try
                {
                    var crawler = new v_crawler();

                    using (var db = new BizDataContext())
                    {
                        //从数据库获取抓取间隔
                        var temp = db.Set<T_Configuration>().Where(p => p.Configuration_Key == CommonHelper.WEATHERKEY).FirstOrDefault();
                        if (temp != null)
                        {
                            waittime = Int32.Parse(temp.Configuration_Value);
                        }

                        //从数据库获取抓取服务的配置
                        crawler = await db.Set<T_HTZ_CrawlerService>().Where(p => p.State == v_common.YesState && p.ServiceType == (int)HTZ_CrawlerService_ServiceTypeEnum.Weather && p.IsEnable.Value).Select(p => new v_crawler
                        {
                            id = p.HTZ_CrawlerService_Id,
                            infotype = p.InfoType ?? 0,
                            name = p.HTZ_CrawlerService_Name,
                            xmlfile = p.XMLFilePath,
                            crawlertype = (int)HTZ_CrawlerService_ServiceTypeEnum.Weather
                        }).FirstOrDefaultAsync();
                    }


                    //开始天气抓取
                    WeatherCrawler(crawler);

                    //开始生活指数抓取
                    LivingIndexCrawler(crawler);

                    //记录服务状态
                    await CommonHelper.SaveNewState((int)HTZ_ServiceState_ServiceStateEnum.Fine, crawler.id);
                }
                catch (CrawlerException ex)
                {
                    await CommonHelper.SaveException(ex);
                }
                catch (Exception ex)
                {
                    var e = new CrawlerException()
                    {
                        crawlertype = (int)HTZ_ExceptionHandler_ServiceTypeEnum.DataGrab,
                        exceptionbrief = "天气抓取服务错误",
                        exceptionmessage = ex.Message,
                        statuscode = 501,
                        serviceid = 2
                    };
                    await CommonHelper.SaveException(e);
                }
                finally
                {
                    Thread.Sleep(waittime);
                }
            }
        }
Ejemplo n.º 26
0
 public IQueryable <T_Role> Query(BizDataContext db)
 {
     return(from p in db.Set <T_Role>()
            where p.State != 0x270f
            select p);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="html">原始html</param>
        /// <param name="crawler">抓取服务配置</param>
        /// <param name="infoNode">xml配置数据</param>
        /// <param name="db">数据库链接</param>
        /// <param name="encode">html编码格式</param>
        /// <param name="url">抓取原始url</param>
        /// <returns></returns>
        public static void SaveInfomation(string html, v_crawler crawler, XmlDocument infoNode, BizDataContext db)
        {
            //页面数据的根节点
            var rootNode = CommonHelper.GetRootNode(html);

            //配置数据的根节点
            var xmlRoot = infoNode.SelectSingleNode("data");

            //获取信息列表的配置节点
            var listConfig = xmlRoot.SelectSingleNode("ListConfig");

            //这里是为了最终找到modelListNodes变量的值,也就是新闻列表
            //在此之前可能需要多次的剥离无效数据,因此使用了foreach循环
            //正常流程应该是多次SelectSingleNode后,进行一次SelectNodes,获取到新闻列表
            HtmlNode           modelNode      = null;
            HtmlNodeCollection modelListNodes = null;

            foreach (XmlNode item in listConfig.ChildNodes)
            {
                if (modelNode == null)
                {
                    modelNode = rootNode;
                }

                if (item.Attributes["issingleselect"].Value.ToBool())
                {
                    //多次剥离无效数据
                    modelNode = modelNode.SelectSingleNode(item.Attributes["signstr"].Value);
                }
                else
                {
                    //最终获取到信息列表,此时应该循环结束
                    modelListNodes = modelNode.SelectNodes(item.Attributes["signstr"].Value);
                    break;
                }
            }

            //获取对新闻实体解析的配置节点
            var infoConfig = xmlRoot.SelectSingleNode("InfoConfig");

            //对上面获取到的新闻列表循环处理
            foreach (HtmlNode info in modelListNodes)
            {
                T_Information entity = new T_Information();

                var detailUrl = string.Empty;

                //新闻解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
                foreach (XmlNode property in infoConfig.ChildNodes)
                {
                    if (property.Name == "property")
                    {
                        entity = CommonHelper.GetProperty(entity, info, property);
                    }
                    else if (property.Name == "DetailUrl")
                    {
                        detailUrl = GetUrl(info, property, crawler.url);
                    }
                }

                var count = db.Set <T_Information>().Where(p => p.Information_Id == entity.Information_Id).Select(p => 1).Count();

                if (count >= 1)
                {
                    return;
                }

                entity.State           = (int)T_InformationStateEnum.Publish;
                entity.InformationType = (int)t_informationtypeenum.customcontent;
                entity.InfoTypeIds     = crawler.infotype + ",";


                if (!string.IsNullOrEmpty(detailUrl))
                {
                    //循环赋值完成后,前往新闻详情页获取新闻详情,完善新闻实体
                    InfomationDetailCrawler(detailUrl, xmlRoot, entity, crawler, crawler.encode);
                }

                entity.OriginalSourceUrl = detailUrl;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 根据ID查询工作流
        /// </summary>
        /// <param name="processId"></param>
        /// <returns></returns>
        public WfWorkflowData GetWorkFlow(long processId)
        {
            using (BizDataContext context = new BizDataContext())
            {
                var            pCache  = new ProcessCacheFactory(context);
                WfWorkflowData data    = new WfWorkflowData();
                SysProcess     process = pCache.GetProcessCache(processId);
                if (process != null)
                {
                    //流程定义
                    data.Process = process.ConvertTo <WfProcess>();
                    if (data.Process.TemplateId != null)
                    {
                        data.Process.ProcessTemplate = Convert.ToBase64String(data.Process.TemplateId);
                        data.Process.TemplateId      = null;
                    }

                    //2013-9-11 zhumin 这里的版本号直接返回当前最高版本 + 1,否则从“已升级”的载入,会版本错误
                    //载入“新增”状态的流程,版本不变
                    //载入其它状态的流程,复制一份为“新增”,版本为当前最高+1
                    //发布流程,版本不变
                    //新增第一个流程,版本为1
                    if (data.Process.ProcessStatus != (int)ProcessState.Created)
                    {
                        string maxVersion = context.Set <SysProcess>().Where(p => p.ProcessType == process.ProcessType).OrderByDescending(p => p.ProcessVersion).First().ProcessVersion;
                        data.Process.ProcessVersion = (maxVersion.ToInt() + 1).ToString();
                    }


                    //流程提醒
                    data.ProcessRemindList = process.ProcessReminds.ConvertTo <WfProcessRemind>();
                    var prpList = new List <SysProcessRemindParticipant>();
                    foreach (var pr in process.ProcessReminds)
                    {
                        prpList = prpList.Union(pr.RemindParticipants).ToList();
                    }
                    data.ProcessRemindParticipantList = prpList.ConvertTo <WfProcessRemindParticipant>();

                    //活动
                    data.ActivityList = process.Activities.ConvertTo <WfActivity>();

                    //活动参与人和活动提醒
                    var arList  = new List <SysActivityRemind>();
                    var apList  = new List <SysActivityParticipant>();
                    var arpList = new List <SysActivityRemindParticipant>();
                    var aoList  = new List <SysActivityOperation>();
                    var aosList = new List <SysActivityStep>();
                    foreach (var a in process.Activities)
                    {
                        arList = arList.Union(a.ActivityReminds).ToList();
                        apList = apList.Union(a.ActivityParticipants).ToList();
                        aoList = aoList.Union(a.ActivityOperations).ToList();

                        foreach (var ar in a.ActivityReminds)
                        {
                            arpList = arpList.Union(ar.RemindParticipants).ToList();
                        }

                        foreach (var ao in a.ActivityOperations)
                        {
                            aosList = aosList.Union(ao.ActivitySteps).ToList();
                        }
                    }
                    data.ActivityRemindList            = arList.ConvertTo <WfActivityRemind>();
                    data.ActivityParticipantList       = apList.ConvertTo <WfActivityParticipant>();
                    data.ActivityRemindParticipantList = arpList.ConvertTo <WfActivityRemindParticipant>();

                    //活动操作
                    data.ActivityOperationList = aoList.ConvertTo <WfActivityOperation>();
                    data.ActivityStepList      = aosList.ConvertTo <WfActivityStep>();

                    //条件、参与人、连接线
                    data.ExpressionList  = process.Expressions.ConvertTo <WfExpression>();
                    data.ParticipantList = process.ProcessParticipants.ConvertTo <WfProcessParticipant>();
                    data.TransitionList  = process.Transitions.ConvertTo <WfTransition>();
                }

                pCache.ClearCache(processId);

                return(data);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 保存流程参与人
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cbc_CallBack(object sender, CallBackEventArgs e)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            string errorMsg         = string.Empty; //错误消息
            bool   isError          = false;

            try
            {
                int?   functionType    = e.Context["FunctionType"].ToStringNullable().ToIntNullable();
                int?   userId          = e.Context["UserId"].ToStringNullable().ToIntNullable();
                int?   roleId          = e.Context["RoleId"].ToStringNullable().ToIntNullable();
                long   processId       = e.Context["ProcessId"].ToLong();
                string participantName = string.Empty;

                if (functionType == null)
                {
                    throw new Exception("参与人类型不能为空");
                }
                if (functionType == (int)ParticipantFunctionType.SpecialUser)
                {
                    T_User user = this.DataHelper.FindById <T_User>(userId);
                    if (user == null)
                    {
                        throw new Exception("请指定具体人员");
                    }
                    participantName = user.User_Name;
                }
                if (functionType == (int)ParticipantFunctionType.SpecialRole)
                {
                    T_Role role = this.DataHelper.FindById <T_Role>(roleId);
                    if (role == null)
                    {
                        throw new Exception("请指定具体角色");
                    }
                    participantName = string.Format("{0}角色", role.Role_Name);
                }
                if (functionType == (int)ParticipantFunctionType.DIRECT_MANAGER)
                {
                    participantName = "直属主管";
                }

                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                {
                    using (BizDataContext db = new BizDataContext())
                    {
                        int count = db.Set <SysProcessParticipant>().Where(p =>
                                                                           p.ProcessId == processId && p.FunctionType == functionType && p.Param_RoleId == roleId && p.Param_UserId == userId).Count();
                        if (count > 0)
                        {
                            throw new Exception("已存在相同的流程参与人");
                        }

                        long?param_partId = null;
                        if (functionType == (int)ParticipantFunctionType.DIRECT_MANAGER)
                        {
                            SysProcessParticipant pStartUser = new SysProcessParticipant()
                            {
                                ParticipantId   = db.GetNextIdentity(),
                                ProcessId       = processId,
                                FunctionType    = (int)ParticipantFunctionType.StartUser,
                                ParticipantName = "流程启动人",
                            };
                            param_partId = pStartUser.ParticipantId;
                            db.Insert(pStartUser);
                        }

                        SysProcessParticipant pCurrent = new SysProcessParticipant()
                        {
                            ParticipantId       = db.GetNextIdentity(),
                            ProcessId           = processId,
                            FunctionType        = functionType,
                            Param_UserId        = userId,
                            Param_RoleId        = roleId,
                            Param_ParticipantId = param_partId,
                            ParticipantName     = participantName,
                        };
                        db.Insert(pCurrent);
                    }
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                isError  = true;
                errorMsg = ex.Message;
            }

            string result = js.Serialize(new
            {
                IsError = isError,
                Error   = errorMsg,
            });

            e.Result = result;
        }
        public static List <SelectControlData> GetData(DataType DataType, Type t, object parameter, int currentUseID)
        {
            List <SelectControlData> list     = new List <SelectControlData>();
            List <NameValues>        userList = new List <NameValues>();

            using (BizDataContext context = new BizDataContext(true))
            {
                if (DataType == DataType.All)
                {
                    List <T_User> list3 = context.Set <T_User>().ToList <T_User>();
                    userList = (from user in context.Set <T_User>()
                                join dep in context.Set <T_Department>() on user.Department_ID equals(int?) dep.Department_ID
                                where (user.State == 0) && (dep.State == 0)
                                orderby user.User_Name
                                select new NameValues {
                        Id = user.User_ID, Name = user.User_Name, DepID = user.Department_ID.ToInt(), DepName = dep.Department_Name, ParentDepID = dep.Parent_ID
                    }).ToList <NameValues>();
                }
                if (DataType == DataType.CurrentDep)
                {
                    T_User currentUserModel = context.FindById <T_User>(new object[] { currentUseID });
                    if ((currentUserModel != null) && (currentUserModel.User_ID > 0))
                    {
                        userList = (from dep in context.Set <T_Department>()
                                    join user in context.Set <T_User>() on dep.Department_ID equals user.Department_ID
                                    where (((dep.Department_ID == currentUserModel.Department_ID) && (user.State == 0)) && (dep.State == 0)) && (user.Department_ID != null)
                                    orderby user.User_Name
                                    select new NameValues {
                            Id = user.User_ID, Name = user.User_Name, DepID = user.Department_ID.ToInt(), DepName = dep.Department_Name, ParentDepID = dep.Parent_ID
                        }).ToList <NameValues>();
                    }
                }
                if (DataType == DataType.SubDep)
                {
                    T_User t_user = context.FindById <T_User>(new object[] { currentUseID });
                    if ((t_user != null) && (t_user.User_ID > 0))
                    {
                        T_Department currentDepModel = context.FindById <T_Department>(new object[] { t_user.Department_ID });
                        if ((currentDepModel != null) && (currentDepModel.Department_ID > 0))
                        {
                            userList = (from dep in context.Set <T_Department>()
                                        join user in context.Set <T_User>() on dep.Department_ID equals user.Department_ID into user
                                        where dep.SystemLevelCode.StartsWith(currentDepModel.SystemLevelCode)
                                        select new NameValues {
                                Id = t_user.User_ID, Name = t_user.User_Name, DepID = t_user.Department_ID.ToInt(), DepName = dep.Department_Name, ParentDepID = dep.Parent_ID
                            }).ToList <NameValues>();
                        }
                    }
                }
                if (DataType == DataType.Custom)
                {
                    try
                    {
                        userList = ((ICustomSelectUser)Activator.CreateInstance(t)).GetCustomData(parameter);
                    }
                    catch (Exception exception)
                    {
                        AppLogHelper.Error(exception);
                    }
                }
            }
            List <SelectControlData> depList = new List <SelectControlData>();

            if ((userList != null) && (userList.Count > 0))
            {
                depList = (from p in userList select new SelectControlData {
                    id = p.DepID, name = p.DepName, pId = p.ParentDepID, open = true, userlist = new List <NameValues>(), icon = "/Content/metro/images/selectuser_icon.png"
                }).ToList <SelectControlData>().Distinct <SelectControlData>(new List_DepId()).ToList <SelectControlData>();
                GetSelectControlData(userList, depList);
            }
            return(depList);
        }