Пример #1
0
        /// <summary>
        /// 将日志转成字符串
        /// </summary>
        /// <param name="log">日志信息</param>
        /// <returns>字符串</returns>
        private string GetLogString(LogInfo log)
        {
            List <string> infos = new List <string>();

            try
            {
                //客户端IP
                if (string.IsNullOrEmpty(log.ClientIP) == false)
                {
                    infos.Add(log.ClientIP);
                }
                else
                {
                    infos.Add("null");
                }

                //登录用户名
                if (string.IsNullOrEmpty(log.UserName) == false)
                {
                    infos.Add(log.UserName);
                }
                else
                {
                    infos.Add("null");
                }

                //动作信息
                if (string.IsNullOrEmpty(log.Info) == false)
                {
                    infos.Add(log.Info);
                }
                else
                {
                    infos.Add("null");
                }

                //数据
                if (log.Tag != null)
                {
                    infos.Add(JsonConvertHelper.GetSerializes(log.Tag));
                }

                else
                {
                    infos.Add("null");
                }


                return(string.Join(" ", infos));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        /// <summary>
        /// 获取数据并调用服务保存
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="OrganID"></param>
        /// <param name="DeviceSN"></param>
        /// <param name="st"></param>
        /// <param name="et"></param>
        /// <returns></returns>
        public bool doSaveData(ServiceReference1.Service1Client sc, string OrganID, string DeviceSN, DateTime st, DateTime et)
        {
            //从指定日期开始到指定日期结束的数据
            List <InspectItemData> itemDataList = getInspectItemData(DeviceSN, st, et);

            //保存结果
            bool saveResult = false;

            //采集列表不为空时
            if (itemDataList != null && itemDataList.Count > 0)
            {
                //设置企业信息机构ID及更新时间
                foreach (InspectItemData iid in itemDataList)
                {
                    iid.ID         = Guid.NewGuid().ToString();
                    iid.OrganID    = OrganID;
                    iid.UpdateTime = DateTime.Now;
                }
            }

            //获取计算结果
            List <InspectResultData> culResultList = null;

            //从mysql取出计算结果
            using (IDataSession session = AppDataFactory.CreateMainSession())
            {
                string sql = @"SELECT * FROM aifishingep.inspectcalcresult T 
                                        WHERE T.ORGANID = @OrganID AND T.DeviceCode = @DeviceSN AND T.UpdateTime > @ST AND T.UpdateTime <= @ET ";
                //此处查询不能使用InspectTime.InspectTime存放的是对应的月份.天或者小时数.结果统计时以更新时间为主
                List <DataParameter> dataParameter = new List <DataParameter>();
                dataParameter.Add(new DataParameter {
                    ParameterName = "OrganID", DataType = DbType.String, Value = OrganID
                });
                dataParameter.Add(new DataParameter {
                    ParameterName = "DeviceSN", DataType = DbType.String, Value = DeviceSN
                });
                dataParameter.Add(new DataParameter {
                    ParameterName = "ST", DataType = DbType.String, Value = st
                });
                dataParameter.Add(new DataParameter {
                    ParameterName = "ET", DataType = DbType.String, Value = et
                });
                //插入基本信息
                culResultList = session.GetList <InspectResultData>(sql, dataParameter.ToArray()).ToList();
            }

            if (itemDataList.Count > 0 || culResultList.Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.WriteLine("转发企业(" + OrganID + ")-设备("
                              + DeviceSN + ")-起始时间(" + st.ToString("yyyy-MM-dd HH:mm:ss")
                              + ")-结束时间(" + et.ToString("yyyy-MM-dd HH:mm:ss")
                              + ")-采集记录条数(" + itemDataList.Count
                              + ")-计算结果记录条数(" + culResultList.Count + ")");


            //调用WCF保存数据到企业端
            saveResult = sc.saveItemAndCalResultData(JsonConvertHelper.GetSerializes(itemDataList), JsonConvertHelper.GetSerializes(culResultList));

            //保存成功
            if (saveResult)
            {
                //将本次执行记录保存到数据
                HandleResult handelResult = new HandleResult()
                {
                    Id              = Guid.NewGuid().ToString(),
                    OrganId         = OrganID,
                    HandleTime      = DateTime.Now,
                    DeviceSN        = DeviceSN,
                    HandleStartTime = st,
                    HandleEndTime   = et,
                    HandleCountMdb  = itemDataList.Count,
                    HandleCountMs   = culResultList.Count
                };

                //处理记录保存到数据库中
                using (IDataSession session = AppDataFactory.CreateMainSession())
                {
                    session.Insert <HandleResult>(handelResult);
                }
            }

            return(saveResult);
        }