|
@@ -0,0 +1,318 @@
|
|
|
+using DocumentFormat.OpenXml.Office2010.ExcelAc;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using TEAMModelOS.Helper.Common.FileHelper;
|
|
|
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
|
|
|
+using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
|
|
|
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
|
|
|
+using TEAMModelOS.Service.Models;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers.Analysis
|
|
|
+{
|
|
|
+ [Route("api/[controller]")]
|
|
|
+ [ApiController]
|
|
|
+ public class ChangeController : Controller
|
|
|
+ {
|
|
|
+
|
|
|
+ private readonly IWebHostEnvironment _hostingEnvironment;
|
|
|
+ public IAzureCosmosDBV3Repository _cosmosrepository;
|
|
|
+ public ChangeController(IWebHostEnvironment hostingEnvironment, IAzureCosmosDBV3Repository cosmosDBRepository)
|
|
|
+ {
|
|
|
+ _hostingEnvironment = hostingEnvironment;
|
|
|
+ _cosmosrepository = cosmosDBRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [HttpGet("SaveObjectAdas")]
|
|
|
+ public BaseJosnRPCResponse SaveObjectAdas(string identity)
|
|
|
+
|
|
|
+ {
|
|
|
+ // 获取系统路径
|
|
|
+ string contentRootPath = _hostingEnvironment.ContentRootPath;
|
|
|
+ identity = "IES/20200716";
|
|
|
+ //string query = "$.info";
|
|
|
+ //int countClasses = 0;
|
|
|
+ //string queryClass = "$member.1.item_answer[*]";
|
|
|
+ string query = "$.exercises[*]";
|
|
|
+ string queryInfo = "$.info";
|
|
|
+ string queryPoint = "$.testpaper.items[*]";
|
|
|
+ string querySchoolInfo = "$.exercises[0].info";
|
|
|
+ string data = FileTool.getJson(contentRootPath, identity);
|
|
|
+ data = FileTool.UnicodeToString(data);
|
|
|
+ JObject parsedJson = JObject.Parse(data);
|
|
|
+ JsonPathContext context = new JsonPathContext
|
|
|
+ { ValueSystem = new JsonNetValueSystem() };
|
|
|
+ //解析试卷作答详情
|
|
|
+ List<dynamic> papers = context.SelectNodes(parsedJson,
|
|
|
+ query).Select(node => node.Value).ToList();
|
|
|
+ //解析试卷基本信息
|
|
|
+ List<dynamic> info = context.SelectNodes(parsedJson,
|
|
|
+ queryInfo).Select(node => node.Value).ToList();
|
|
|
+ //解析题库信息
|
|
|
+ List<dynamic> Itempoint = context.SelectNodes(parsedJson,
|
|
|
+ queryPoint).Select(node => node.Value).ToList();
|
|
|
+ //解析学校信息
|
|
|
+ List<dynamic> SchoolInfo = context.SelectNodes(parsedJson,
|
|
|
+ querySchoolInfo).Select(node => node.Value).ToList();
|
|
|
+
|
|
|
+ int m = 0;
|
|
|
+ //人数总和
|
|
|
+ int Count = 0;
|
|
|
+ //起始坐标
|
|
|
+ int Strat = 0;
|
|
|
+ // 初始化学生人数
|
|
|
+ int Stus = 0;
|
|
|
+ ExamResult simple = new ExamResult();
|
|
|
+ ExamAnswer examAnswer = new ExamAnswer();
|
|
|
+
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
+ List<Classroom> classrooms = new List<Classroom>();
|
|
|
+ //List<ExamAnswer> examAnswers = new List<ExamAnswer>();
|
|
|
+ List<List<List<int>>> ClassPoint = new List<List<List<int>>>();
|
|
|
+ List<List<double>> StuPoint = new List<List<double>>();
|
|
|
+ List<string> StuIds = new List<string>();
|
|
|
+ List<List<string>> stuAnswers = new List<List<string>>();
|
|
|
+ List<Dictionary<string, int[]>> Classes = new List<Dictionary<string, int[]>>();
|
|
|
+ Dictionary<object, object> ListInfo = new Dictionary<object, object>();
|
|
|
+ List<double> points = new List<double>();
|
|
|
+ //配分数组
|
|
|
+ Paper paper = new Paper();
|
|
|
+ List<ItemInfo> items = new List<ItemInfo>();
|
|
|
+ int k = 0;
|
|
|
+ Itempoint.ForEach(p =>
|
|
|
+ {
|
|
|
+ string pt = p.point;
|
|
|
+ string OpenTracing = p+"";
|
|
|
+ JObject jArray = JObject.Parse(OpenTracing);
|
|
|
+ string queryOptions = "$.options[*]";
|
|
|
+ List<dynamic> itemOption = context.SelectNodes(jArray,
|
|
|
+ queryOptions).Select(node => node.Value).ToList();
|
|
|
+ List<CodeValue> codeValues = new List<CodeValue> ();
|
|
|
+ itemOption.ToList<dynamic>().ForEach(i =>
|
|
|
+ {
|
|
|
+ CodeValue code = new CodeValue
|
|
|
+ {
|
|
|
+ code = i.data,
|
|
|
+ value = i.type
|
|
|
+ };
|
|
|
+ codeValues.Add(code);
|
|
|
+ });
|
|
|
+ //题序
|
|
|
+ string order = p.itemindex;
|
|
|
+ string ans = p.answer;
|
|
|
+ string knowlege = p.idx_desc;
|
|
|
+ ItemInfo item = new ItemInfo
|
|
|
+ {
|
|
|
+ question = p.content,
|
|
|
+ score = double.Parse(pt),
|
|
|
+ answer = new List<string> {
|
|
|
+ ans
|
|
|
+ },
|
|
|
+ type = p.type,
|
|
|
+ order = int.Parse(order),
|
|
|
+ //level = p.edu_goal,
|
|
|
+ option = codeValues,
|
|
|
+ points = new List<string> {
|
|
|
+ knowlege
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ };
|
|
|
+ items.Add(item);
|
|
|
+ k++;
|
|
|
+ points.Add(double.Parse(pt.Trim()));
|
|
|
+ });
|
|
|
+ //处理试卷信息
|
|
|
+ paper.item = items;
|
|
|
+ paper.subjectCode = "Subject_Math";
|
|
|
+ //基本信息
|
|
|
+ info.ForEach(e => {
|
|
|
+ simple.name = e.test_name;
|
|
|
+ simple.time = e.test_date;
|
|
|
+ paper.name = e.test_name;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ School sc = null;
|
|
|
+ ExamInfo examInfo = null;
|
|
|
+ SchoolInfo.ForEach(s => {
|
|
|
+ string count = s.stucount;
|
|
|
+ string st = s.ex_time;
|
|
|
+ string ed = s.ex_endtime;
|
|
|
+ DateTime.TryParse(st, out DateTime tt);
|
|
|
+ DateTime.TryParse(ed, out DateTime etime);
|
|
|
+ long time = DateTimeHelper.ToUnixTimestamp(tt);
|
|
|
+ long edtime = DateTimeHelper.ToUnixTimestamp(etime);
|
|
|
+ sc = new School
|
|
|
+ {
|
|
|
+ schoolCode = "88924E4C-F00D-4A1D-B2C3-234F930F29D4",
|
|
|
+ schoolName = s.school_name,
|
|
|
+ period = new List<Period> { new Period {periodName = "小学" , periodCode = "c3e1e95a-561e-fabf-cce3-3a564782e443",grades= new List<Grade> {
|
|
|
+ new Grade { gradeName = "四年级" ,gradeCode = "4"} } } }
|
|
|
+ };
|
|
|
+ //考试基本信息
|
|
|
+ examInfo = new ExamInfo
|
|
|
+ {
|
|
|
+ id = System.Guid.NewGuid().ToString(),
|
|
|
+ code = "88924E4C-F00D-4A1D-B2C3-234F930F29D4",
|
|
|
+ name = s.ex_name,
|
|
|
+ type = s.ex_type,
|
|
|
+ startTime = time,
|
|
|
+ endTime = edtime,
|
|
|
+ stuCount = int.Parse(count),
|
|
|
+ conditions = new Condition {
|
|
|
+ period = "c3e1e95a-561e-fabf-cce3-3a564782e443",
|
|
|
+ grade = s.grade_name,
|
|
|
+ semester = s.semester,
|
|
|
+ subject = new List<string> { "Subject_Math" }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ });
|
|
|
+ papers.ForEach(x =>
|
|
|
+ {
|
|
|
+
|
|
|
+ //var c = papers[i].member;
|
|
|
+ string stu = x.info.stucount;
|
|
|
+ int k = int.Parse(stu);
|
|
|
+ string key = x.info.class_name;
|
|
|
+ string schoolName = x.info.school_name;
|
|
|
+ Classroom classInfo = new Classroom
|
|
|
+ {
|
|
|
+ id = System.Guid.NewGuid().ToString(),
|
|
|
+ classroomName = key,
|
|
|
+ //classroomType = schoolName,
|
|
|
+ studentCount = k,
|
|
|
+ classroomCode = "qcs"
|
|
|
+ };
|
|
|
+ classrooms.Add(classInfo);
|
|
|
+ Classroom classInfoOfStudent = new Classroom
|
|
|
+ {
|
|
|
+ classroomName = key,
|
|
|
+ //schoolCode = schoolName,
|
|
|
+ //studentCount = k,
|
|
|
+ classroomCode = "qcs"
|
|
|
+ };
|
|
|
+ Dictionary<string, int[]> map = new Dictionary<string, int[]>();
|
|
|
+ int[] Range = new int[2];
|
|
|
+ //处理学生作答数据
|
|
|
+
|
|
|
+
|
|
|
+ for (int j = 0; j < 22; j++)
|
|
|
+ {
|
|
|
+ Student stus = new Student
|
|
|
+ {
|
|
|
+ type = 2,
|
|
|
+ //schoolCode = schoolName
|
|
|
+ };
|
|
|
+ string men = x.members[j] + "";
|
|
|
+ JObject jArray = JObject.Parse(men);
|
|
|
+ string queryClass = "$.item_answers[*]";
|
|
|
+ string queryStu = "$.info";
|
|
|
+ List<string> ans = new List<string>();
|
|
|
+ List<dynamic> answers = context.SelectNodes(jArray,
|
|
|
+ queryClass).Select(node => node.Value).ToList();
|
|
|
+ //学生ID集合
|
|
|
+ List<dynamic> studentIds = context.SelectNodes(jArray,
|
|
|
+ queryStu).Select(node => node.Value).ToList();
|
|
|
+ List<double> point = new List<double>();
|
|
|
+ if (answers.Count == 0)
|
|
|
+ {
|
|
|
+ StuIds.Add("0");
|
|
|
+ k++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //处理学生信息
|
|
|
+ studentIds.ToList<dynamic>().ForEach(s =>
|
|
|
+ {
|
|
|
+
|
|
|
+ string id = s.student_id;
|
|
|
+ //id = System.Guid.NewGuid().ToString();
|
|
|
+ stus.id = id.Trim();
|
|
|
+ stus.name = s.name;
|
|
|
+ stus.studentId = id.Trim();
|
|
|
+ string sno = s.seatno;
|
|
|
+ if (sno.Equals(""))
|
|
|
+ {
|
|
|
+ stus.seatNo = 0;
|
|
|
+ } else {
|
|
|
+ stus.seatNo = int.Parse(sno);
|
|
|
+ }
|
|
|
+
|
|
|
+ //stus.classroom = classInfoOfStudent;
|
|
|
+ StuIds.Add(id.Trim());
|
|
|
+ });
|
|
|
+ students.Add(stus);
|
|
|
+ }
|
|
|
+
|
|
|
+ answers.ToList<dynamic>().ForEach(p =>
|
|
|
+ {
|
|
|
+ string pt = p.real_point;
|
|
|
+ string ansContent = p.ans_content;
|
|
|
+ if (ans.Equals(""))
|
|
|
+ {
|
|
|
+ ansContent = "无";
|
|
|
+ }
|
|
|
+ ans.Add(ansContent);
|
|
|
+ point.Add(double.Parse(pt.Trim()));
|
|
|
+ });
|
|
|
+ stuAnswers.Add(ans);
|
|
|
+ StuPoint.Add(point);
|
|
|
+ Stus++;
|
|
|
+ }
|
|
|
+ //每次人数累加得到实际总人数
|
|
|
+ Count += Stus;
|
|
|
+ if (m == 0)
|
|
|
+ {
|
|
|
+ Strat = Stus;
|
|
|
+ Range[0] = 0;
|
|
|
+ Range[1] = Stus - 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Range[0] = Count - Stus;
|
|
|
+ Range[1] = Count - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ map.Add(key, Range);
|
|
|
+ Classes.Add(map);
|
|
|
+ m++;
|
|
|
+ //初始化每个班级人数
|
|
|
+ Stus = 0;
|
|
|
+
|
|
|
+ //ClassPoint.Add(StuPoint);
|
|
|
+ });
|
|
|
+ examAnswer.answer = stuAnswers;
|
|
|
+ examAnswer.code = examInfo.id;
|
|
|
+ paper.code = examInfo.id;
|
|
|
+ simple.code = examInfo.id;
|
|
|
+ simple.classes = Classes;
|
|
|
+ simple.ids = StuIds;
|
|
|
+ simple.point = points;
|
|
|
+ simple.result = StuPoint;
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ //_examInfoService.SaveToCosmos(simple);
|
|
|
+ //_cosmosrepository.Save(sc);
|
|
|
+ /*_cosmosrepository.Save(simple);
|
|
|
+ _cosmosrepository.Save(examAnswer);
|
|
|
+ _cosmosrepository.Save(examInfo);*/
|
|
|
+ //_cosmosrepository.SaveAll(classrooms);
|
|
|
+ //_cosmosrepository.SaveOrUpdateAll(students);
|
|
|
+ //_examInfoService.SaveListToCosmos(students);
|
|
|
+
|
|
|
+
|
|
|
+ return builder.Data(sc).build();
|
|
|
+ //return builder.build();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|