コード例 #1
0
        public async Task GetAsync_EmptyOkWithUnmatchedParams()
        {
            // Arrange
            // N/A; empty service layer response will produce no results by default

            // Act
            ActionResult <MessageListResponse> controllerResponse = await this._controller
                                                                    .GetAsync(
                10.1234,
                -10.1234,
                4,
                DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                CancellationToken.None
                );

            // Assert
            Assert.IsNotNull(controllerResponse);
            Assert.IsInstanceOfType(controllerResponse.Result, typeof(OkObjectResult));
            OkObjectResult castedResult = controllerResponse.Result as OkObjectResult;

            Assert.IsInstanceOfType(castedResult.Value, typeof(MessageListResponse));
            MessageListResponse responseResult = castedResult.Value as MessageListResponse;

            Assert.AreEqual(responseResult.MessageInfoes.Count, 0);
        }
コード例 #2
0
        public async Task <ActionResult <MessageListResponse> > GetAsync([Required] double lat, [Required] double lon, [Required] int precision, [Required] long lastTimestamp, CancellationToken cancellationToken = default)
        {
            try
            {
                // Pull queries matching parameters
                var region = new Region {
                    LatitudePrefix = lat, LongitudePrefix = lon, Precision = precision
                };
                IEnumerable <MessageInfo> results = await this._messageService
                                                    .GetLatestInfoAsync(region, lastTimestamp, cancellationToken);

                // Convert to response proto
                MessageListResponse response = new MessageListResponse();

                if (results.Count() > 0)
                {
                    response.MessageInfoes.AddRange(results);

                    // Get maximum timestamp from resultset
                    response.MaxResponseTimestamp = response.MessageInfoes.Max(m => m.MessageTimestamp);
                }

                return(Ok(response));
            }
            catch (RequestValidationFailedException ex)
            {
                return(BadRequest(ex.ValidationResult));
            }
            catch (ArgumentNullException)
            {
                return(BadRequest());
            }
        }
コード例 #3
0
        public MessageListResponse GetMessageList(PagingParameters pagingParameters)
        {
            int rowsCount = 0;
            MessageListResponse result = new MessageListResponse
            {
                MessageList = _messagesRepository.GetMessages(pagingParameters, out rowsCount),
                RowsCount   = rowsCount
            };

            return(result);
        }
コード例 #4
0
        public async Task GetAsync_OkWithMatchedParams()
        {
            // Arrange
            Region requestedRegion = new Region
            {
                LatitudePrefix  = 10.1234,
                LongitudePrefix = -10.1234,
                Precision       = 4
            };
            int requestedTimestamp = 0;

            IEnumerable <MessageInfo> response = new List <MessageInfo>
            {
                new MessageInfo
                {
                    MessageId        = "00000000-0000-0000-0000-0000000000",
                    MessageTimestamp = 0
                }
            };

            this._repo
            .Setup(s => s.GetLatestAsync(
                       It.IsAny <Region>(),
                       It.IsAny <long>(),
                       CancellationToken.None
                       ))
            .Returns(Task.FromResult(response));

            // Act
            ActionResult <MessageListResponse> controllerResponse = await this._controller
                                                                    .GetAsync(
                requestedRegion.LatitudePrefix,
                requestedRegion.LongitudePrefix,
                requestedRegion.Precision,
                requestedTimestamp,
                CancellationToken.None
                );

            // Assert
            Assert.IsNotNull(controllerResponse);
            Assert.IsInstanceOfType(controllerResponse.Result, typeof(OkObjectResult));
            OkObjectResult castedResult = controllerResponse.Result as OkObjectResult;

            Assert.IsInstanceOfType(castedResult.Value, typeof(MessageListResponse));
            MessageListResponse responseResult = castedResult.Value as MessageListResponse;

            Assert.AreEqual(responseResult.MessageInfoes.Count(), response.Count());
        }
コード例 #5
0
        public async Task GetAsync_OkWithMatchedParams()
        {
            // Arrange
            v20200505.Protos.Region requestedRegion = new Region
            {
                LatitudePrefix  = 10.1234,
                LongitudePrefix = -10.1234,
                Precision       = 4
            };

            IEnumerable <InfectionReportMetadata> response = new List <InfectionReportMetadata>
            {
                new InfectionReportMetadata
                {
                    Id        = "00000000-0000-0000-0000-0000000001",
                    Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                }
            };

            this._repo
            .Setup(s => s.GetLatestAsync(
                       It.IsAny <Entities.Geospatial.Region>(),
                       It.IsAny <long>(),
                       CancellationToken.None
                       ))
            .Returns(Task.FromResult(response));

            // Act
            ActionResult <MessageListResponse> controllerResponse = await this._controller
                                                                    .GetAsync(
                requestedRegion.LatitudePrefix,
                requestedRegion.LongitudePrefix,
                requestedRegion.Precision,
                DateTimeOffset.UtcNow.AddHours(-1).ToUnixTimeMilliseconds(),
                CancellationToken.None
                );

            // Assert
            Assert.IsNotNull(controllerResponse);
            Assert.IsInstanceOfType(controllerResponse.Result, typeof(OkObjectResult));
            OkObjectResult castedResult = controllerResponse.Result as OkObjectResult;

            Assert.IsInstanceOfType(castedResult.Value, typeof(MessageListResponse));
            MessageListResponse responseResult = castedResult.Value as MessageListResponse;

            Assert.AreEqual(responseResult.MessageInfoes.Count(), response.Count());
        }
コード例 #6
0
        public MessageListResponse MessageListNew(MessageListRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new MessageListResponse();

            //bhToken校验
            if (!AppTokenValidateReqest(request.BhToken, request.ChildAgent))
            {
                response.ErrCode = -300;
                response.ErrMsg  = "登录信息已过期,请重新登录";
                return(response);
            }
            IBxAgent agentModel = GetAgentModelFactory(request.Agent);

            //参数校验
            if (!agentModel.AgentCanUse())
            {
                response.ErrCode = -10001;
                response.ErrMsg  = "参数校验错误,请检查您的校验码";
                return(response);
            }
            if (!AppValidateReqest(pairs, request.SecCode))
            {
                response.ErrCode = -10001;
                response.ErrMsg  = "参数校验错误,请检查您的校验码";
                return(response);
            }
            var msgList = new List <BxMessage>();
            int total   = 0;//消息表的记录数

            msgList          = _messageRepository.FindNoReadAllList(request.ChildAgent, out total).ConvertToViewModel();
            response.MsgList =
                msgList.OrderByDescending(o => o.CreateTime)
                .Take(request.PageSize * request.CurPage)
                .Skip(request.PageSize * (request.CurPage - 1))
                .ToList();
            response.TotalCount = total;
            return(response);
        }
コード例 #7
0
        public MessageListResponse MessageList(MessageListRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new MessageListResponse();

            //bhToken校验
            if (!AppTokenValidateReqest(request.BhToken, request.ChildAgent))
            {
                response.ErrCode = -300;
                response.ErrMsg  = "登录信息已过期,请重新登录";
                return(response);
            }
            IBxAgent agentModel = GetAgentModelFactory(request.Agent);

            //参数校验
            if (!agentModel.AgentCanUse())
            {
                response.ErrCode = -10001;
                response.ErrMsg  = "参数校验错误,请检查您的校验码";
                return(response);
            }
            if (!AppValidateReqest(pairs, request.SecCode))
            {
                response.ErrCode = -10001;
                response.ErrMsg  = "参数校验错误,请检查您的校验码";
                return(response);
            }

            var         msgList = new List <BxMessage>();
            BxMessage   bmsg;
            bx_agent    bxAgent;
            bx_userinfo bxUserinfo;
            int         totalmsg = 0; //消息表的记录数
            int         totalxb  = 0; //续保表的记录数
            int         totalrw  = 0; //回访通知表的记录数

            //从bx_message里取数据
            List <bx_message> listMsg = _messageRepository.FindNoReadList(request.ChildAgent, out totalmsg);
            //从bx_noticexb里取数据
            List <bx_notice_xb> listXb = _noticexbRepository.FindNoReadList(request.ChildAgent, out totalxb);
            //从bx_consumer_review里取数据
            List <bx_consumer_review> listRw = _consumerReviewRepository.FindNoReadList(request.ChildAgent, out totalrw);

            #region bx_message表数据
            if (listMsg.Any())
            {
                foreach (var itemMsg in listMsg)
                {
                    bmsg = new BxMessage
                    {
                        StrId     = "Msg_" + itemMsg.Id,
                        Id        = itemMsg.Id,
                        MsgLevel  = itemMsg.Msg_Level.HasValue ? itemMsg.Msg_Level.Value : 0,
                        MsgStatus = itemMsg.Msg_Status.HasValue ? itemMsg.Msg_Status.Value : 0,
                        MsgType   = itemMsg.Msg_Type,
                        SendTime  =
                            itemMsg.Send_Time.HasValue ? itemMsg.Send_Time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
                        Title      = itemMsg.Title,
                        Body       = itemMsg.Body,
                        UpdateTime =
                            itemMsg.Update_Time.HasValue
                                ? itemMsg.Update_Time.Value.ToString("yyyy-MM-dd HH:mm:ss")
                                : "",
                        Url     = itemMsg.Url,
                        AgentId = itemMsg.Agent_Id.HasValue ? itemMsg.Agent_Id.Value : 0
                    };
                    //Agent
                    bxAgent        = _agentRepository.GetAgent(bmsg.AgentId);
                    bmsg.AgentName = bxAgent != null ? bxAgent.AgentName : "";
                    //CreateAgent
                    bmsg.CreateAgentId   = itemMsg.Create_Agent_Id;
                    bxAgent              = _agentRepository.GetAgent(bmsg.CreateAgentId);
                    bmsg.CreateAgentName = bxAgent != null ? bxAgent.AgentName : "";

                    bmsg.CreateTime = itemMsg.Create_Time.HasValue ? itemMsg.Create_Time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";

                    if (itemMsg.Buid.HasValue)
                    {
                        bmsg.Buid       = itemMsg.Buid.Value;
                        bmsg.LicenseNo  = itemMsg.License_No;
                        bxUserinfo      = new bx_userinfo();
                        bxUserinfo      = _userInfoRepository.FindByBuid(itemMsg.Buid.Value);
                        bmsg.OwnerAgent = bxUserinfo != null?int.Parse(bxUserinfo.Agent) : 0;
                    }
                    msgList.Add(bmsg);
                }
            }
            #endregion
            #region bx_noticexb表数据
            if (listXb.Any())
            {
                foreach (var itemXb in listXb)
                {
                    bmsg = new BxMessage
                    {
                        StrId      = "Xb_" + itemXb.id,
                        Id         = itemXb.id,
                        MsgLevel   = 1,
                        MsgStatus  = itemXb.stauts,
                        MsgType    = 1,
                        SendTime   = itemXb.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
                        Title      = "到期通知",
                        Body       = string.Format("{0},车险{1}天后到期", itemXb.license_no, itemXb.day_num.Value.ToString()),
                        UpdateTime = "",
                        Url        = "",
                        AgentId    = itemXb.agent_id
                    };
                    //Agent
                    bxAgent        = _agentRepository.GetAgent(bmsg.AgentId);
                    bmsg.AgentName = bxAgent != null ? bxAgent.AgentName : "";
                    //CreateAgent
                    bmsg.CreateAgentId   = itemXb.agent_id;
                    bmsg.CreateAgentName = bxAgent != null ? bxAgent.AgentName : "";
                    bmsg.CreateTime      = itemXb.create_time.ToString("yyyy-MM-dd HH:mm:ss");

                    bmsg.LicenseNo          = itemXb.license_no;
                    bmsg.LastForceEndDate   = itemXb.last_force_end_date.HasValue ? itemXb.last_force_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
                    bmsg.LastBizEndDate     = itemXb.Last_biz_end_date.HasValue ? itemXb.Last_biz_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
                    bmsg.NextForceStartDate = itemXb.next_force_start_date.HasValue ? itemXb.next_force_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
                    bmsg.NextBizStartDate   = itemXb.next_biz_start_date.HasValue ? itemXb.next_biz_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
                    bmsg.Source             = itemXb.source;
                    bmsg.Days = itemXb.days.HasValue ? itemXb.days.Value : 0;
                    bmsg.Buid = itemXb.b_uid;

                    //根据buid获取当前的userinfo的agent,方便查看详情
                    bxUserinfo      = new bx_userinfo();
                    bxUserinfo      = _userInfoRepository.FindByBuid(itemXb.b_uid);
                    bmsg.OwnerAgent = bxUserinfo != null?int.Parse(bxUserinfo.Agent) : 0;

                    msgList.Add(bmsg);
                }
            }
            #endregion
            #region bx_consumer_review表数据
            if (listRw.Any())
            {
                foreach (var itemRw in listRw)
                {
                    bmsg = new BxMessage
                    {
                        StrId     = "Rw_" + itemRw.id,
                        Id        = itemRw.id,
                        MsgLevel  = 1,
                        MsgStatus = itemRw.read_status.Value,
                        MsgType   = 2,
                        SendTime  = itemRw.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                        Title     = "回访通知"
                    };
                    if (itemRw.b_uid.HasValue)
                    {
                        bmsg.Buid       = itemRw.b_uid.Value;
                        bxUserinfo      = new bx_userinfo();
                        bxUserinfo      = _userInfoRepository.FindByBuid(itemRw.b_uid.Value);
                        bmsg.LicenseNo  = bxUserinfo != null ? bxUserinfo.LicenseNo : "";
                        bmsg.OwnerAgent = bxUserinfo != null?int.Parse(bxUserinfo.Agent) : 0;
                    }
                    DateTime dt = itemRw.next_review_date.Value;
                    bmsg.Body       = string.Format("{0}月{1}日{2} 需回访{3}", dt.Month, dt.Day, dt.ToString("hh:mm"), bmsg.LicenseNo);
                    bmsg.UpdateTime = "";
                    bmsg.Url        = "";
                    //Agent
                    bmsg.AgentId   = itemRw.operatorId.Value;
                    bmsg.AgentName = itemRw.operatorName;
                    //CreateAgent
                    bmsg.CreateAgentId   = itemRw.operatorId.Value;
                    bmsg.CreateAgentName = itemRw.operatorName;
                    bmsg.CreateTime      = itemRw.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss");

                    bmsg.Buid = itemRw.b_uid.Value;

                    msgList.Add(bmsg);
                }
            }
            #endregion
            response.MsgList =
                msgList.OrderByDescending(o => o.CreateTime)
                .Take(request.PageSize * request.CurPage)
                .Skip(request.PageSize * (request.CurPage - 1))
                .ToList();
            response.TotalCount = totalmsg + totalxb + totalrw;
            return(response);
        }
コード例 #8
0
 private void OnMessageList(object sender, MessageListResponse message)
 {
     MessageManager.Instance.MessageInit(message.Messages);
 }