ChangeController.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using TEAMModelOS.Helper.Common.FileHelper;
  8. using TEAMModelOS.Model.Evaluation.Models;
  9. using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
  10. using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
  11. using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
  12. using TEAMModelOS.Service.Models.Core;
  13. namespace TEAMModelOS.Controllers.Analysis
  14. {
  15. [Route("api/[controller]")]
  16. [ApiController]
  17. public class ChangeController : Controller
  18. {
  19. private readonly IWebHostEnvironment _hostingEnvironment;
  20. public IAzureCosmosDBRepository _cosmosrepository;
  21. public ChangeController(IWebHostEnvironment hostingEnvironment, IAzureCosmosDBRepository cosmosDBRepository)
  22. {
  23. _hostingEnvironment = hostingEnvironment;
  24. _cosmosrepository = cosmosDBRepository;
  25. }
  26. [HttpGet("SaveObjectAdas")]
  27. public BaseJosnRPCResponse SaveObjectAdas(string identity)
  28. {
  29. // 获取系统路径
  30. string contentRootPath = _hostingEnvironment.ContentRootPath;
  31. identity = "IES/adas";
  32. //string query = "$.info";
  33. //int countClasses = 0;
  34. //string queryClass = "$member.1.item_answer[*]";
  35. string query = "$.exercise[*]";
  36. string queryInfo = "$.info";
  37. string queryPoint = "$.testpaper.item[*]";
  38. //string queryInfo = "$.exercise.info[*]";
  39. string data = FileTool.getJson(contentRootPath, identity);
  40. data = FileTool.UnicodeToString(data);
  41. JObject parsedJson = JObject.Parse(data);
  42. JsonPathContext context = new JsonPathContext
  43. { ValueSystem = new JsonNetValueSystem() };
  44. List<dynamic> papers = context.SelectNodes(parsedJson,
  45. query).Select(node => node.Value).ToList();
  46. List<dynamic> info = context.SelectNodes(parsedJson,
  47. queryInfo).Select(node => node.Value).ToList();
  48. List<dynamic> Itempoint = context.SelectNodes(parsedJson,
  49. queryPoint).Select(node => node.Value).ToList();
  50. int m = 0;
  51. //人数总和
  52. int Count = 0;
  53. //起始坐标
  54. int Strat = 0;
  55. // 初始化学生人数
  56. int Stus = 0;
  57. SimpleExam simple = new SimpleExam();
  58. List<Student> students = new List<Student>();
  59. List<Classroom> classrooms = new List<Classroom>();
  60. List<List<List<int>>> ClassPoint = new List<List<List<int>>>();
  61. List<List<int>> StuPoint = new List<List<int>>();
  62. List<string> StuIds = new List<string>();
  63. List<Dictionary<string, int[]>> Classes = new List<Dictionary<string, int[]>>();
  64. Dictionary<object, object> ListInfo = new Dictionary<object, object>();
  65. List<int> points = new List<int>();
  66. //配分数组
  67. Itempoint.ForEach(p =>
  68. {
  69. string pt = p.point;
  70. points.Add(int.Parse(pt.Trim()));
  71. });
  72. //基本信息
  73. info.ForEach(e => {
  74. simple.Name = e.test_name;
  75. simple.Time = e.test_date;
  76. });
  77. School sc = new School
  78. {
  79. schoolCode = "qcs",
  80. schoolName = "青城山",
  81. period = new List<Period> { new Period {periodName = "中专" , periodCode = "zz",grades= new List<Grade> {
  82. new Grade { gradeName = "初中一年级" ,gradeCode = "7"} } } }
  83. };
  84. papers.ForEach(x =>
  85. {
  86. //var c = papers[i].member;
  87. string stu = x.info.stucount;
  88. int k = int.Parse(stu);
  89. string key = x.info.class_name;
  90. string schoolName = x.info.school_name;
  91. Classroom classInfo = new Classroom
  92. {
  93. id = System.Guid.NewGuid().ToString(),
  94. classroomName = key,
  95. schoolCode = schoolName,
  96. studentCount = k,
  97. classroomCode = "qcs"
  98. };
  99. classrooms.Add(classInfo);
  100. Classroom classInfoOfStudent = new Classroom
  101. {
  102. classroomName = key,
  103. schoolCode = schoolName,
  104. //studentCount = k,
  105. classroomCode = "qcs"
  106. };
  107. Dictionary<string, int[]> map = new Dictionary<string, int[]>();
  108. int[] Range = new int[2];
  109. for (int j = 1; j <= k; j++)
  110. {
  111. Student stus = new Student
  112. {
  113. type = 2,
  114. schoolCode = schoolName
  115. };
  116. //stus.classroom = "";
  117. string men = x.member + "";
  118. JObject jArray = JObject.Parse(men);
  119. List<int> point = new List<int>();
  120. //List<string> stuId = new List<string>();
  121. string queryClass = "$." + j + ".item_answer[*]";
  122. string queryStu = "$." + j + ".info";
  123. List<dynamic> answers = context.SelectNodes(jArray,
  124. queryClass).Select(node => node.Value).ToList();
  125. //学生ID集合
  126. List<dynamic> studentIds = context.SelectNodes(jArray,
  127. queryStu).Select(node => node.Value).ToList();
  128. if (answers.Count == 0)
  129. {
  130. StuIds.Add("0");
  131. k++;
  132. }
  133. else {
  134. studentIds.ToList<dynamic>().ForEach(s =>
  135. {
  136. string id = s.studentid;
  137. //id = System.Guid.NewGuid().ToString();
  138. stus.id = id.Trim();
  139. stus.name = s.name;
  140. stus.studentId = id.Trim();
  141. stus.seatNo = s.seatno;
  142. stus.classroom = classInfoOfStudent;
  143. StuIds.Add(id.Trim());
  144. });
  145. students.Add(stus);
  146. }
  147. answers.ToList<dynamic>().ForEach(p =>
  148. {
  149. string pt = p.ans_point;
  150. point.Add(int.Parse(pt.Trim()));
  151. });
  152. StuPoint.Add(point);
  153. Stus++;
  154. }
  155. //每次人数累加得到实际总人数
  156. Count += Stus;
  157. if (m == 0)
  158. {
  159. Strat = Stus;
  160. Range[0] = 0;
  161. Range[1] = Stus - 1;
  162. }
  163. else
  164. {
  165. Range[0] = Count - Stus;
  166. Range[1] = Count - 1;
  167. }
  168. map.Add(key, Range);
  169. Classes.Add(map);
  170. m++;
  171. //初始化每个班级人数
  172. Stus = 0;
  173. //ClassPoint.Add(StuPoint);
  174. });
  175. simple.Classes = Classes;
  176. simple.Ids = StuIds;
  177. simple.Point = points;
  178. simple.Result = StuPoint;
  179. JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
  180. //_examInfoService.SaveToCosmos(simple);
  181. //_cosmosrepository.Save(sc);
  182. //_cosmosrepository.Save(simple);
  183. //_cosmosrepository.SaveAll(classrooms);
  184. _cosmosrepository.SaveAll(students);
  185. //_examInfoService.SaveListToCosmos(students);
  186. return builder.Data(sc).build();
  187. //return builder.build();
  188. }
  189. }
  190. }