|
@@ -24,6 +24,8 @@ using System.Net.Http.Headers;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
using HTEXLib.Helpers.ShapeHelpers;
|
|
|
+using HtmlAgilityPack;
|
|
|
+using Top.Api.Util;
|
|
|
namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
{
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
@@ -44,10 +46,8 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
}
|
|
|
|
|
|
[HttpPost("moofen/question")]
|
|
|
-#if !DEBUG
|
|
|
- [AuthToken(Roles = "teacher,admin")]
|
|
|
- [Authorize(Roles = "IES")]
|
|
|
-#endif
|
|
|
+ //[AuthToken(Roles = "teacher,admin")]
|
|
|
+ //[Authorize(Roles = "IES")]
|
|
|
public async Task<IActionResult> Question(JsonElement json)
|
|
|
{
|
|
|
try {
|
|
@@ -121,13 +121,71 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
string content = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
var data = content.ToObject<JsonElement>();
|
|
|
- if (data.TryGetProperty("data", out JsonElement _data) && _data.TryGetProperty("data", out JsonElement __data))
|
|
|
+ int count = 0;
|
|
|
+ if (data.TryGetProperty("data", out JsonElement _data) )
|
|
|
{
|
|
|
- List<MoofenQuestion> questions = __data.ToObject<List<MoofenQuestion>>();
|
|
|
+ if (_data.TryGetProperty("total", out JsonElement _total) && int.TryParse($"{_total}", out count))
|
|
|
+ if ( _data.TryGetProperty("data", out JsonElement __data))
|
|
|
+ {
|
|
|
+ List<MoofenQuestion> questions = __data.ToObject<List<MoofenQuestion>>();
|
|
|
+ items= MoofenQS(questions, $"{subject}", pquestion: null);
|
|
|
+ //foreach (var item in items)
|
|
|
+ //{
|
|
|
+ // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
|
|
+ // var contentAI = new StringContent(JsonSerializer.Serialize(new
|
|
|
+ // {
|
|
|
+ // appId = "5ac43c20-221e-4564-829d-15680ad761df",
|
|
|
+ // sessionId = "",
|
|
|
+ // text = item.description,
|
|
|
+ // }), Encoding.UTF8, "application/json");
|
|
|
+ // var httpreq = new HttpRequestMessage(HttpMethod.Post, url) { Content = contentAI };
|
|
|
+ // var authtoken = HttpContext.GetXAuth("AuthToken");
|
|
|
+ // if (!httpClient.DefaultRequestHeaders.Contains("X-Auth-Authtoken"))
|
|
|
+ // {
|
|
|
+ // httpClient.DefaultRequestHeaders.Add("X-Auth-Authtoken", authtoken);
|
|
|
+ // }
|
|
|
+ // var AuthorizationToken = HttpContext.GetAuthorization();
|
|
|
+ // if (httpClient.DefaultRequestHeaders.Contains("Authorization"))
|
|
|
+ // {
|
|
|
+ // httpClient.DefaultRequestHeaders.Remove("Authorization");
|
|
|
+ // }
|
|
|
+ // httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {AuthorizationToken}");
|
|
|
+ // httpClient.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));
|
|
|
+ // var responseAI = await httpClient.SendAsync(httpreq, HttpCompletionOption.ResponseHeadersRead);
|
|
|
+ // StringBuilder dataAI = new StringBuilder();
|
|
|
+ // // 读取响应内容的异步流
|
|
|
+ // using (var responseStream = await response.Content.ReadAsStreamAsync())
|
|
|
+ // {
|
|
|
+ // //Debug.Print("============start response use minseconds=" + (DateTime.Now - d).TotalMilliseconds + " =================\r\n");
|
|
|
+ // // 逐块读取并处理响应内容
|
|
|
+ // var buffer = new byte[1024];
|
|
|
+ // int bytesRead;
|
|
|
+ // while ((bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
|
|
+ // {
|
|
|
+ // // 处理响应内容
|
|
|
+ // string contentData = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead);
|
|
|
+
|
|
|
+
|
|
|
+ // if (contentData.Contains("data:"))
|
|
|
+ // {
|
|
|
+ // contentData = contentData.Replace("data:", "").Replace("[DONE]", "");
|
|
|
|
|
|
- items= MoofenQS(questions,$"{subject}");
|
|
|
+ // }
|
|
|
+ // if (contentData.Contains("[DONE]"))
|
|
|
+ // {
|
|
|
+ // contentData = contentData.Replace("data:", "").Replace("[DONE]", "");
|
|
|
+
|
|
|
+ // }
|
|
|
+ // dataAI.Append(contentData);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // item.explain=dataAI.ToString();
|
|
|
+ //}
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
- return Ok(new { code = 200, data, items });
|
|
|
+
|
|
|
+ return Ok(new { code = 200, data, items , count });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -140,7 +198,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
return Ok(new { code = 500,msg=$"{ex.Message}" });
|
|
|
}
|
|
|
}
|
|
|
- private List<MoofenItemInfo> MoofenQS(List<MoofenQuestion> questions, string subject, string pid = null)
|
|
|
+ private List<MoofenItemInfo> MoofenQS(List<MoofenQuestion> questions, string subject,string pquestion, string pid = null)
|
|
|
{
|
|
|
List<MoofenItemInfo> items = new List<MoofenItemInfo>();
|
|
|
|
|
@@ -152,6 +210,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
foreach (MoofenQuestion question in questions) {
|
|
|
question.questionCode= $"{pid}_{index}";
|
|
|
index++;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
Parallel.ForEach(questions, x => {
|
|
@@ -169,6 +228,10 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
pid=pid
|
|
|
|
|
|
};
|
|
|
+ StringBuilder description = new StringBuilder($"科目:{subject}") ;
|
|
|
+ if (!string.IsNullOrWhiteSpace(pquestion)) {
|
|
|
+ description.AppendLine($"综合题:{pquestion}");
|
|
|
+ }
|
|
|
//处理年级转换
|
|
|
if (!string.IsNullOrWhiteSpace(x.scope?.grade?.code) ) {
|
|
|
item.gradeIds= new List<string>() { x.scope?.grade?.code };
|
|
@@ -195,6 +258,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
item.opts=x.options.Count();
|
|
|
}
|
|
|
item.field=1;
|
|
|
+ description.AppendLine("题型:选择题");
|
|
|
break;
|
|
|
//填空
|
|
|
case "F":
|
|
@@ -206,6 +270,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
}
|
|
|
item.type="complete";
|
|
|
item.field=2;
|
|
|
+ description.AppendLine("题型:填空题");
|
|
|
break;
|
|
|
//问答
|
|
|
case "Q":
|
|
@@ -214,6 +279,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
item.answer=new List<string>() { x.content };
|
|
|
}
|
|
|
item.type="subjective";
|
|
|
+ description.AppendLine("题型:问答题");
|
|
|
item.field=4;
|
|
|
break;
|
|
|
//写作
|
|
@@ -223,15 +289,18 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
item.answer=new List<string>() { x.content };
|
|
|
}
|
|
|
item.type="subjective";
|
|
|
+ description.AppendLine("题型:写作题");
|
|
|
item.field=6;
|
|
|
break;
|
|
|
//综合
|
|
|
case "S":
|
|
|
item.type="compose";
|
|
|
+
|
|
|
item.field=3;
|
|
|
if (x.questions.IsNotEmpty() && x.questions.Count>0) {
|
|
|
- item.children.AddRange(MoofenQS(x.questions, subject,item.id));
|
|
|
+ item.children.AddRange(MoofenQS(x.questions,subject: subject,pquestion: item.question,pid: item.id));
|
|
|
}
|
|
|
+ description.AppendLine("题型:综合题");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -256,6 +325,24 @@ namespace TEAMModelOS.Controllers.Third.Moofen
|
|
|
}
|
|
|
}
|
|
|
string unhtml = HtmlHelper.DoUselessTag(sb.ToString());
|
|
|
+ description.AppendLine($"题干:{item.question}");
|
|
|
+ if (item.option.IsNotEmpty())
|
|
|
+ {
|
|
|
+ description.AppendLine($"选项:");
|
|
|
+ foreach (var option in item.option) {
|
|
|
+ description.AppendLine($"{option.code}:{option.value}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(item.answer.IsNotEmpty())
|
|
|
+ {
|
|
|
+ description.AppendLine($"答案:{string.Join(",",item.answer)}");
|
|
|
+ }
|
|
|
+ if (item.knowledge.IsNotEmpty()) {
|
|
|
+ description.AppendLine($"知识点:{string.Join(",", item.knowledge)}");
|
|
|
+ }
|
|
|
+ HtmlDocument doc = new HtmlDocument();
|
|
|
+ doc.LoadHtml(description.ToString());
|
|
|
+ item.description = doc.DocumentNode.InnerText;
|
|
|
item.shaCode= ShaHashHelper.GetSHA1(unhtml);
|
|
|
items.Add(item);
|
|
|
});
|