IEnumerator GetAPaperInfo(ClassPaper classPaper)
    {
        string url = GetPermisson.GetServerAddress +
                     "/Paper/GetAPaper.php?token=" +
                     UnityWebRequest.EscapeURL(LoginToKaoShi.userLoginCallback.data.token) +
                     "&paperID=" + classPaper.id;
        UnityWebRequest uwr = UnityWebRequest.Get(url);

        //Debug.Log(LoginToKaoShi.userLoginCallback.data.token);
        //Debug.Log(url);
        textLog.text += "\n请求试卷信息...";
        textInfo.text = "正在寻找试卷信息...";
        uwr.SendWebRequest();
        while (true)
        {
            textProcess.text      = GetProcess(uwr.downloadProgress);
            imgProcess.fillAmount = uwr.downloadProgress;
            if (uwr.isDone)
            {
                break;
            }
            yield return(new WaitForSeconds(0.02f));
        }

        if (uwr.error == "" || uwr.error == null)
        {
            try
            {
                apaper = JsonUtility.FromJson <APaper>(uwr.downloadHandler.text);
                // Debug.Log(uwr.downloadHandler.text);
                switch (apaper.code)
                {
                case 0:
                    textLog.text += "\n试卷信息请求成功!";



                    /*创建文件夹*/

                    PaperManager.CreateBaseDir(apaper.data.id.ToString() + "EP");
                    textLog.text += "\n创建基文件夹成功!";
                    StartCoroutine(FileDownloadManager());

                    break;

                default:
                    GlobalUIManager.guim.CreateNewDialogBox(apaper.msg);
                    ShowCloseUI();
                    break;
                }
            }
            catch (System.Exception e)
            {
                textLog.text += "\n试卷信息请求失败!" + e.Message;
                GlobalUIManager.guim.CreateNewDialogBox("发生异常!请联系开发者!" + e.Message);
                ShowCloseUI();
            }
        }
        else
        {
            GlobalUIManager.guim.CreateNewDialogBox(uwr.error);
            textLog.text += "\n发生异常!" + uwr.error;
            ShowCloseUI();
        }
    }
예제 #2
0
        /// <summary>
        /// 保存答卷信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public override async Task <RpcResult <SaveAPaperRsp> > SaveAPaperAsync(SaveAPaperReq req)
        {
            var res = new RpcResult <SaveAPaperRsp>();

            res.Data = new SaveAPaperRsp();

            if (req.Answers.Count == 0)
            {
                res.Code = ErrorCodes.PARAMS_VALIDATION_FAIL;
                res.Data.ReturnMessage = "答案不能为空";
                return(res);
            }
            var          qpaperService = _proxy.GetClient <QPaperInnerServiceClient>();
            GetQPaperReq getQPRep      = new GetQPaperReq();

            getQPRep.XRequestId = req.XRequestId;
            getQPRep.Identity   = req.Identity;
            getQPRep.ClientIp   = req.ClientIp;
            getQPRep.CheckRole  = false;
            getQPRep.QpaperId   = req.QpaperId;

            var getQPRes = await qpaperService.GetQPaperAsync(getQPRep);

            if (getQPRes.Code != 0)
            {
                res.Code = getQPRes.Code;
                if (getQPRes.Data != null)
                {
                    res.Data.ReturnMessage = getQPRes.Data.ReturnMessage;
                }

                return(res);
            }
            if (getQPRes.Data == null)
            {
                res.Code = ErrorCodes.DATA_NOT_FOUND;
                res.Data.ReturnMessage = "问卷不存在";
                return(res);
            }

            using (TransScope scope = this._apaperRepo.BeginTransScope())
            {
                var apaper = new APaper();
                apaper.CreateTime    = DateTime.Now;
                apaper.QpaperId      = req.QpaperId;
                apaper.QpaperSubject = getQPRes.Data.Subject;
                apaper.QpaperUserId  = getQPRes.Data.CreateUserId;
                apaper.Remark        = req.Remark;
                apaper.UserId        = string.IsNullOrEmpty(req.UserId) ? req.Identity : req.UserId;

                bool hasA = await this._apaperRepo.CheckAPaperAsync(apaper.QpaperId, apaper.UserId);

                if (hasA)
                {
                    res.Code = ErrorCodes.BIZ_RULE_FAIL;
                    res.Data.ReturnMessage = "该用户已经回答过该问卷了";
                    return(res);
                }

                var newId = await this._apaperRepo.InsertAsync(apaper);

                if (newId < 0)
                {
                    res.Code = ErrorCodes.INTERNAL_ERROR;
                    res.Data.ReturnMessage = "新增问卷失败,请稍后重试";
                    return(res);
                }
                var apaperId = (int)newId;

                var alist = new List <Answer>();
                foreach (var a in req.Answers)
                {
                    var answer = new Answer();
                    answer.AnswerId         = Guid.NewGuid().ToString("N");
                    answer.ApaperId         = apaperId;
                    answer.ObjectiveAnswer  = a.ObjectiveAnswer;
                    answer.SubjectiveAnswer = a.SubjectiveAnswer;
                    answer.QuestionId       = a.QuestionId;

                    alist.Add(answer);
                }
                await this._apaperRepo.AddAnswers(alist);

                res.Data.ApaperId = apaperId;

                scope.Complete();// 提交事务
            }


            // 异步执行不管是否成功
            var addReq = new AddAPaperReq();

            addReq.ClientIp   = req.ClientIp;
            addReq.Identity   = req.Identity;
            addReq.XRequestId = req.XRequestId;
            addReq.QpaperId   = req.QpaperId;
            addReq.Count      = 1;
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
            qpaperService.AddAPaperCountAsync(addReq);
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法

            return(res);
        }