123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- 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.Model.Evaluation.Models;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
- using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
- using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
- using TEAMModelOS.Service.Models.Core;
- namespace TEAMModelOS.Controllers.Analysis
- {
- [Route("api/[controller]")]
- [ApiController]
- public class ChangeController : Controller
- {
-
- private readonly IWebHostEnvironment _hostingEnvironment;
- public IAzureCosmosDBRepository _cosmosrepository;
- public ChangeController(IWebHostEnvironment hostingEnvironment, IAzureCosmosDBRepository cosmosDBRepository)
- {
- _hostingEnvironment = hostingEnvironment;
- _cosmosrepository = cosmosDBRepository;
- }
-
- [HttpGet("SaveObjectAdas")]
- public BaseJosnRPCResponse SaveObjectAdas(string identity)
- {
- // 获取系统路径
- string contentRootPath = _hostingEnvironment.ContentRootPath;
- identity = "IES/adas";
- //string query = "$.info";
- //int countClasses = 0;
- //string queryClass = "$member.1.item_answer[*]";
- string query = "$.exercise[*]";
- string queryInfo = "$.info";
- string queryPoint = "$.testpaper.item[*]";
- //string queryInfo = "$.exercise.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();
- int m = 0;
- //人数总和
- int Count = 0;
- //起始坐标
- int Strat = 0;
- // 初始化学生人数
- int Stus = 0;
- SimpleExam simple = new SimpleExam();
- List<Student> students = new List<Student>();
- List<Classroom> classrooms = new List<Classroom>();
- List<List<List<int>>> ClassPoint = new List<List<List<int>>>();
- List<List<int>> StuPoint = new List<List<int>>();
- List<string> StuIds = new List<string>();
- List<Dictionary<string, int[]>> Classes = new List<Dictionary<string, int[]>>();
- Dictionary<object, object> ListInfo = new Dictionary<object, object>();
- List<int> points = new List<int>();
- //配分数组
- Itempoint.ForEach(p =>
- {
- string pt = p.point;
- points.Add(int.Parse(pt.Trim()));
- });
- //基本信息
- info.ForEach(e => {
- simple.Name = e.test_name;
- simple.Time = e.test_date;
- });
- School sc = new School
- {
- schoolCode = "qcs",
- schoolName = "青城山",
- period = new List<Period> { new Period {periodName = "中专" , periodCode = "zz",grades= new List<Grade> {
- new Grade { gradeName = "初中一年级" ,gradeCode = "7"} } } }
- };
- 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,
- schoolCode = 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 = 1; j <= k; j++)
- {
- Student stus = new Student
- {
- type = 2,
- schoolCode = schoolName
- };
- //stus.classroom = "";
- string men = x.member + "";
- JObject jArray = JObject.Parse(men);
- List<int> point = new List<int>();
- //List<string> stuId = new List<string>();
- string queryClass = "$." + j + ".item_answer[*]";
- string queryStu = "$." + j + ".info";
- 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();
- if (answers.Count == 0)
- {
- StuIds.Add("0");
- k++;
- }
- else {
- studentIds.ToList<dynamic>().ForEach(s =>
- {
-
- string id = s.studentid;
- //id = System.Guid.NewGuid().ToString();
- stus.id = id.Trim();
- stus.name = s.name;
- stus.studentId = id.Trim();
- stus.seatNo = s.seatno;
- stus.classroom = classInfoOfStudent;
- StuIds.Add(id.Trim());
- });
- students.Add(stus);
- }
- answers.ToList<dynamic>().ForEach(p =>
- {
- string pt = p.ans_point;
- point.Add(int.Parse(pt.Trim()));
- });
- 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);
- });
- 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.SaveAll(classrooms);
- _cosmosrepository.SaveAll(students);
- //_examInfoService.SaveListToCosmos(students);
- return builder.Data(sc).build();
- //return builder.build();
- }
-
- }
- }
|