|
@@ -0,0 +1,169 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
|
|
|
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
|
|
|
+using TEAMModelOS.Service.Models.Evaluation.Models;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers.Evaluation
|
|
|
+{
|
|
|
+ [Route("api/[controller]")]
|
|
|
+ [ApiController]
|
|
|
+ public class ExamController : BaseController
|
|
|
+ {
|
|
|
+ private readonly IAzureCosmosDBV3Repository cosmosDBV3Repository;
|
|
|
+ public ExamController(IAzureCosmosDBV3Repository _cosmosDBV3Repository) {
|
|
|
+ cosmosDBV3Repository = _cosmosDBV3Repository;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 手动挑题
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("Manual")]
|
|
|
+ public async Task<BaseJosnRPCResponse> Manual(JosnRPCRequest<Compose> request) {
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ return builder.Data(null).build();
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 自动组题
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("Automatic")]
|
|
|
+ public async Task<BaseJosnRPCResponse> Automatic(JosnRPCRequest<Compose> request) {
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
+ if (request.@params.scopeCode.IsNotEmpty()) {
|
|
|
+ dict.Add("scopeCode", request.@params.scopeCode.ToArray());
|
|
|
+ }
|
|
|
+ if (request.@params.period.IsNotEmpty())
|
|
|
+ {
|
|
|
+ dict.Add("period", request.@params.period.ToArray());
|
|
|
+ }
|
|
|
+ ///处理知识点均分问题
|
|
|
+ int avg = 0;
|
|
|
+ Dictionary<string, int> point = new Dictionary<string, int>();
|
|
|
+ if (request.@params.points.IsNotEmpty())
|
|
|
+ {
|
|
|
+ avg=(int) Math.Ceiling( request.@params.count * 1.0 / request.@params.points.Count);
|
|
|
+ dict.Add("points", request.@params.points.ToArray());
|
|
|
+ foreach (string p in request.@params.points) {
|
|
|
+ point.TryAdd(p, avg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dict.Add("lite",false);
|
|
|
+ List<ItemInfo> itemInfos = new List<ItemInfo>();
|
|
|
+ if (request.@params.quInfos.IsNotEmpty())
|
|
|
+ {
|
|
|
+ List<string> types = new List<string>();
|
|
|
+ List<int> levels = new List<int>();
|
|
|
+ foreach (QuInfo quInfo in request.@params.quInfos) {
|
|
|
+ // types.Add(quInfo.type);
|
|
|
+ if (quInfo.custom.IsNotEmpty() && quInfo.policy.Equals("custom"))
|
|
|
+ {
|
|
|
+ foreach (Custom custom in quInfo.custom) {
|
|
|
+
|
|
|
+ dict.Add("type", quInfo.type);
|
|
|
+ dict.Add("level", custom.level);
|
|
|
+ List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
|
|
|
+ //id去重
|
|
|
+ items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
|
|
|
+ items = items.OrderBy(x => Guid.NewGuid()).Take(custom.count).ToList();
|
|
|
+ ////均分知识点题目
|
|
|
+ itemInfos.AddRange(items);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dict.Add("type", quInfo.type);
|
|
|
+ List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
|
|
|
+ //id去重
|
|
|
+ items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
|
|
|
+ //均分
|
|
|
+ if (quInfo.policy.Equals("average"))
|
|
|
+ {
|
|
|
+ //按等级去重 获取所有等级
|
|
|
+ List<int> lvls = items.Where((x, i) => items.FindIndex(z => z.level == x.level) == i).Select(x => x.level).ToList();
|
|
|
+
|
|
|
+ foreach (int i in lvls)
|
|
|
+ {
|
|
|
+ ////均分知识点题目
|
|
|
+ itemInfos.AddRange(items.Where(x => x.level == i).OrderBy(x => Guid.NewGuid()).Take(quInfo.count / lvls.Count));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //随机
|
|
|
+ if (quInfo.policy.Equals("random"))
|
|
|
+ {
|
|
|
+ items = items.OrderBy(x => Guid.NewGuid()).Take(quInfo.count).ToList();
|
|
|
+
|
|
|
+ itemInfos.AddRange(items);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return builder.Data(null).build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class Compose {
|
|
|
+ /// <summary>
|
|
|
+ /// 科目
|
|
|
+ /// </summary>
|
|
|
+ public string subject { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 来源,个人题库,校本题库
|
|
|
+ /// </summary>
|
|
|
+ public List<string> scopeCode { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 适用学段,小学,初中,高中
|
|
|
+ /// </summary>
|
|
|
+ public List<string> period { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 关联知识点
|
|
|
+ /// </summary>
|
|
|
+ public List<string> points { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 题目组合
|
|
|
+ /// </summary>
|
|
|
+ public List<QuInfo> quInfos { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 题目总数
|
|
|
+ /// </summary>
|
|
|
+ public int count { get; set; }
|
|
|
+ }
|
|
|
+ public class QuInfo{
|
|
|
+ /// <summary>
|
|
|
+ /// 题目类型,单选,多选,判断,填空,问答,综合
|
|
|
+ /// </summary>
|
|
|
+ public string type { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 随机 random 平均的 average ,自定义 custom
|
|
|
+ /// </summary>
|
|
|
+ public string policy { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 自定义题目类型
|
|
|
+ /// </summary>
|
|
|
+ public List<Custom> custom { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 总题
|
|
|
+ /// </summary>
|
|
|
+ public int count { get; set; }
|
|
|
+ }
|
|
|
+ public class Custom {
|
|
|
+ /// <summary>
|
|
|
+ /// 难易程度
|
|
|
+ /// </summary>
|
|
|
+ public int level { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 数量
|
|
|
+ /// </summary>
|
|
|
+ public int count { get; set; }
|
|
|
+ }
|
|
|
+}
|