public void AsyncPaper() { while (true) { try { var jsonText = RedisHelper.BlockPopItemFromList("async_write_paper_list"); Program.MyFrm.SetTextMessage("【试卷生成】发现一张试卷需要生成..."); var o = (JObject)JsonConvert.DeserializeObject(jsonText); var paperId = o["paper_id"].ToString(); var version = int.Parse(o["version"].ToString()); var paperType = o["paper_type"].ToString(); var juanType = o["juan_type"].ToString(); var guid = o["guid"].ToString(); var paperName = o["paper_name"].ToString(); //要生成的文件位置 var currentdate = DateTime.Now.ToString("yyyyMMdd"); var ext = version == 1 ? "docx" : "doc"; //生成试卷 var savedocpath = GeneratePaper(paperId, paperType, juanType, version); var forUrlencoderUrl = ""; var forIsoUrl = ""; if (GlobalVar.Version == "1") { var uploadkey = "down/Paper/" + currentdate + "/" + guid + "." + ext; //上传到云存储中去 var targetbucket = GlobalVar.WorkingBucket; OssUtil.SimpleUpload(savedocpath, targetbucket, uploadkey); OssUtil.GetOssFileUrl(targetbucket, uploadkey, paperName + "." + ext, out forUrlencoderUrl,out forIsoUrl); } else { var di = new DirectoryInfo(GlobalVar.LocalPath + "Paper\\" + currentdate ); if (!di.Exists) { di.Create(); } var uploadkey =di.FullName + "\\" + guid + "." + ext; var fi = new FileInfo(savedocpath); string command = @"copy "+ savedocpath +" "+uploadkey; Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardError = true; p.Start(); p.StandardInput.WriteLine(command); p.StandardInput.WriteLine("exit"); p.Close(); //回写缓存JuDuanPaperDownPrex var Url = "/dsideal_yy/html/down/Paper/" + currentdate + "/" + guid + "." + ext + "?flag=download&n=" + paperName + "." + ext; var bytes = Encoding.UTF8.GetBytes(Url); forIsoUrl = Convert.ToBase64String(bytes); RedisHelper.Hash_Set("paper_down_" + guid, "forIsoUrl", forIsoUrl); Url = "/dsideal_yy/html/down/Paper/" + currentdate + "/" + guid + "." + ext + "?flag=download&n=" + HttpUtility.UrlEncode(paperName, Encoding.UTF8).ToUpper() + "." + ext; bytes = Encoding.UTF8.GetBytes(Url); forUrlencoderUrl = Convert.ToBase64String(bytes); } RedisHelper.Hash_Set("paper_down_" + guid, "forUrlencoderUrl", forUrlencoderUrl); RedisHelper.Hash_Set("paper_down_" + guid, "forIsoUrl", forIsoUrl); Program.MyFrm.SetTextMessage("【试卷生成】成功生成一张试卷!"); } catch (Exception err) { Program.MyFrm.SetTextMessage("【试卷生成】错误原因:" + err); } } }
时间: 2024-10-12 16:17:35