|
@@ -57,27 +57,28 @@ namespace TEAMModelOS.Controllers.Evaluation
|
|
|
}
|
|
|
}
|
|
|
dict.Add("lite",false);
|
|
|
+ List<ItemInfo> retnInfos = new List<ItemInfo>();
|
|
|
List<ItemInfo> itemInfos = new List<ItemInfo>();
|
|
|
+ List<TempItem> tempItems = new List<TempItem>();
|
|
|
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) {
|
|
|
-
|
|
|
+ for (int i = 0; i < custom.count; i++) {
|
|
|
+ tempItems.Add(new TempItem { level = custom.level, type = quInfo.type });
|
|
|
+ }
|
|
|
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 {
|
|
@@ -85,33 +86,60 @@ namespace TEAMModelOS.Controllers.Evaluation
|
|
|
List<ItemInfo> items = await cosmosDBV3Repository.FindByDict<ItemInfo>(dict);
|
|
|
//id去重
|
|
|
items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
|
|
|
+ itemInfos.AddRange(items);
|
|
|
//均分
|
|
|
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));
|
|
|
+ int count = quInfo.count / lvls.Count;
|
|
|
+ for (int j = 0; j < count; j++)
|
|
|
+ {
|
|
|
+ tempItems.Add(new TempItem { level = i, type = quInfo.type });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 余数 取模 随机处理
|
|
|
+ int mod = quInfo.count % lvls.Count;
|
|
|
+ for (int m = 0; m < mod; m++) {
|
|
|
+ int lv = lvls.OrderBy(x => Guid.NewGuid()).Take(1).FirstOrDefault();
|
|
|
+ tempItems.Add(new TempItem { level = lv, type = quInfo.type });
|
|
|
+ lvls.Remove(lv);
|
|
|
}
|
|
|
}
|
|
|
//随机
|
|
|
if (quInfo.policy.Equals("random"))
|
|
|
{
|
|
|
- items = items.OrderBy(x => Guid.NewGuid()).Take(quInfo.count).ToList();
|
|
|
-
|
|
|
- itemInfos.AddRange(items);
|
|
|
- }
|
|
|
+ List<int> lvls = items.Where((x, i) => items.FindIndex(z => z.level == x.level) == i).Select(x => x.level).ToList();
|
|
|
+ for (int n = 0; n < quInfo.count; n++) {
|
|
|
+ int lv = lvls.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
|
|
+ tempItems.Add(new TempItem { level = lv, type = quInfo.type });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return builder.Data(null).build();
|
|
|
+ itemInfos = itemInfos.OrderBy(x=>Guid.NewGuid()).ToList();
|
|
|
+ tempItems =tempItems.OrderBy(x => Guid.NewGuid()).ToList();
|
|
|
+ foreach (TempItem temp in tempItems) {
|
|
|
+ ItemInfo itemInfo= itemInfos.Where(x => x.level == temp.level && x.type==temp.type).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
|
|
+ if (itemInfo != null) {
|
|
|
+ retnInfos.Add(itemInfo);
|
|
|
+ itemInfos.Remove(itemInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return builder.Data(retnInfos).build();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public class TempItem {
|
|
|
+ public string type { get; set; }
|
|
|
+ public int level { get; set; }
|
|
|
+ public ItemInfo itemInfo { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public class Compose {
|
|
|
/// <summary>
|
|
|
/// 科目
|