public async Task <RpcResult <SaveQPaperRsp> > SaveQPaperAsync(SaveQPaperReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(20001, 1);

            message.FriendlyServiceName = "QPaperInnerService.SaveQPaper";
            message.Data = req.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <SaveQPaperRsp>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }
            else if (response.Data == null)
            {
                result.Code = ErrorCodes.CODE_INTERNAL_ERROR;
            }
            else
            {
                result.Data = SaveQPaperRsp.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
        //同步方法
        public RpcResult <SaveQPaperRsp> SaveQPaper(SaveQPaperReq req)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(20001, 1);

            message.FriendlyServiceName = "QPaperService.SaveQPaper";


            message.Data = req.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <SaveQPaperRsp>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }

            if (response.Data == null)
            {
                result.Data = new SaveQPaperRsp();
            }
            else
            {
                result.Data = SaveQPaperRsp.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Beispiel #3
0
        //调用委托
        private async Task <AmpMessage> ProcessSaveQPaperAsync(AmpMessage req)
        {
            SaveQPaperReq request = null;

            if (req.Data == null)
            {
                request = new SaveQPaperReq();
            }
            else
            {
                request = SaveQPaperReq.Parser.ParseFrom(req.Data);
            }

            req.FriendlyServiceName = "SurveyGateService.SaveQPaper";

            var result = await SaveQPaperAsync(request);

            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.FriendlyServiceName = "SurveyGateService.SaveQPaper";
            response.Code = result.Code;
            if (result.Data != null)
            {
                response.Data = result.Data.ToByteArray();
            }
            return(response);
        }
Beispiel #4
0
        public override Task <RpcResult <SaveQPaperRsp> > SaveQPaperAsync(SaveQPaperReq request)
        {
            var res = new RpcResult <SaveQPaperRsp>();

            res.Data = new SaveQPaperRsp();
            if (string.IsNullOrEmpty(request.Identity))
            {
                res.Code = ErrorCodes.AUTHORIZATION_REQUIRED;
                res.Data.ReturnMessage = "请先登录";
                return(Task.FromResult(res));
            }


            var client = _proxy.GetClient <QPaperInnerServiceClient>();

            return(client.SaveQPaperAsync(request));
        }
        /// <summary>
        /// 保存问卷信息
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public override async Task <RpcResult <SaveQPaperRsp> > SaveQPaperAsync(SaveQPaperReq req)
        {
            var res = new RpcResult <SaveQPaperRsp>();

            if (req.Questions.Count == 0)
            {
                res.Code = ErrorCodes.PARAMS_VALIDATION_FAIL;
                return(res);
            }
            res.Data = new SaveQPaperRsp();

            using (TransScope scope = this._qpaperRepo.BeginTransScope())
            {
                int paperId = 0;

                var qpaper = new QPaper();
                qpaper.QpaperId    = req.QpaperId;
                qpaper.Description = req.Description;
                //数据校验
                if (!string.IsNullOrEmpty(req.StartTime))
                {
                    qpaper.StartTime = Convert.ToDateTime(req.StartTime);
                }

                if (!string.IsNullOrEmpty(req.EndTime))
                {
                    qpaper.EndTime = Convert.ToDateTime(req.EndTime);
                }
                qpaper.Subject    = req.Subject;
                qpaper.UpdateTime = DateTime.Now;
                if (req.QpaperId > 0) // 更新
                {
                    paperId = req.QpaperId;

                    //更新时需判断是否存在答卷
                    bool hasAPaper = await this._qpaperRepo.CheckHasAPaper(paperId);

                    if (hasAPaper)
                    {
                        res.Code = ErrorCodes.INVALID_OPERATION;
                        res.Data.ReturnMessage = "该问卷已存在答卷,不能修改了!";
                        return(res);
                    }

                    var t1 = this._qpaperRepo.UpdateAsync(qpaper);
                    //删除旧题目
                    var t2 = this._qpaperRepo.DeleteQuestionsByPId(paperId);

                    await Task.WhenAll(t1, t2); //两个任务可以并行
                }
                else
                {
                    qpaper.CreateUserId = req.Identity;
                    var newId = await this._qpaperRepo.InsertAsync(qpaper);

                    paperId = (int)newId;
                }

                if (paperId <= 0)
                {
                    //Internal error;
                    res.Code = ErrorCodes.INTERNAL_ERROR;
                    res.Data.ReturnMessage = "操作失败,请稍后重试";
                    return(res);
                }
                res.Data.QpaperId = paperId;
                //重新保存问题
                int i     = 0;
                var qlist = new List <Question>();
                foreach (var q in req.Questions)
                {
                    var question = new Question();
                    question.Id           = q.Id;
                    question.PaperId      = paperId;
                    question.Sequence     = ++i;
                    question.ExtendInput  = q.ExtendInput;
                    question.ItemDetail   = q.ItemDetail;
                    question.QuestionType = (sbyte)q.QuestionType.GetHashCode();
                    question.Topic        = q.Topic;
                    qlist.Add(question);
                }
                await this._qpaperRepo.AddQuestions(qlist);

                scope.Complete();// 提交事务
            }
            return(res);
        }
Beispiel #6
0
 //抽象方法
 public abstract Task <RpcResult <SaveQPaperRsp> > SaveQPaperAsync(SaveQPaperReq req);