|
@@ -0,0 +1,134 @@
|
|
|
|
+using Grpc.Core;
|
|
|
|
+using Grpc.Extension.Abstract;
|
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using TEAMModelGrpc.Models;
|
|
|
|
+using TEAMModelOS;
|
|
|
|
+using TEAMModelOS.Models;
|
|
|
|
+using TEAMModelOS.SDK.Context.Exception;
|
|
|
|
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
|
+using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
|
|
|
|
+using TEAMModelOS.Service.Models.Learn;
|
|
|
|
+
|
|
|
|
+namespace TEAMModelGrpc.Services
|
|
|
|
+{
|
|
|
|
+ public class HomeWorkService : IGrpcService
|
|
|
|
+ {
|
|
|
|
+ private readonly IAzureCosmosDBV3Repository _cosmos;
|
|
|
|
+
|
|
|
|
+ public HomeWorkService(IAzureCosmosDBV3Repository cosmos)
|
|
|
|
+ {
|
|
|
|
+ _cosmos = cosmos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 学生作业打分评论
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="homeWorkCommentDto"></param>
|
|
|
|
+ /// <param name="context"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [Authorize]
|
|
|
|
+ public async Task<HomeWorkStudent> StudentScoring(HomeWorkCommentDto homeWorkCommentDto, ServerCallContext context)
|
|
|
|
+ {
|
|
|
|
+ List<HomeWorkStudent> homeWorkStudents = await _cosmos.FindByDict<HomeWorkStudent>(new Dictionary<string, object> { { "id", homeWorkCommentDto.id }, { "homeWorkId", homeWorkCommentDto.homeWorkId } });
|
|
|
|
+ List<HomeWork> homeWorks = await _cosmos.FindByDict<HomeWork>(new Dictionary<string, object> { { "id", homeWorkCommentDto.homeWorkId } });
|
|
|
|
+ HomeWorkStudent data = new HomeWorkStudent();
|
|
|
|
+
|
|
|
|
+ if (homeWorks.IsNotEmpty() && homeWorks[0].other.Contains("comment"))
|
|
|
|
+ {
|
|
|
|
+ if (homeWorkStudents.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrEmpty(homeWorkCommentDto.commentid))
|
|
|
|
+ {
|
|
|
|
+ //评论
|
|
|
|
+ StudentComment homeWorkComment = new StudentComment
|
|
|
|
+ {
|
|
|
|
+ commentid = Guid.NewGuid().ToString(),
|
|
|
|
+ comment = homeWorkCommentDto.comment,
|
|
|
|
+ createTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(),
|
|
|
|
+ fromId = homeWorkCommentDto.fromId,
|
|
|
|
+ score = homeWorkCommentDto.score
|
|
|
|
+ };
|
|
|
|
+ homeWorkStudents[0].studentComments.Add(homeWorkComment);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //回复评论
|
|
|
|
+ foreach (StudentComment comment in homeWorkStudents[0].studentComments)
|
|
|
|
+ {
|
|
|
|
+ if (comment.commentid == homeWorkCommentDto.commentid)
|
|
|
|
+ {
|
|
|
|
+ Reply reply = new Reply();
|
|
|
|
+ reply.fromId = homeWorkCommentDto.fromId;
|
|
|
|
+ reply.toId = homeWorkCommentDto.toId;
|
|
|
|
+ reply.identity = homeWorkCommentDto.identity;
|
|
|
|
+ reply.comment = homeWorkCommentDto.comment;
|
|
|
|
+ reply.createTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
|
|
|
|
+ comment.reply.Add(reply);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //homeWorkStudents[0].comments[request.@params.TEAMModelId] = request.@params.comment;
|
|
|
|
+ data = await _cosmos.Update(homeWorkStudents[0]);
|
|
|
|
+ }
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+ else throw new BizException("未开放互评");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 教师作业打分评论
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="homeWorkCommentDto"></param>
|
|
|
|
+ /// <param name="context"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task<HomeWorkStudent> TeacherScoring(HomeWorkScoringDto homeWorkCommentDto, ServerCallContext context)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ List<HomeWorkStudent> homeWorkStudents = await _cosmos.FindByDict<HomeWorkStudent>(new Dictionary<string, object> { { "id", homeWorkCommentDto.id }, { "homeWorkId", homeWorkCommentDto.homeWorkId } });
|
|
|
|
+ HomeWorkStudent data = new HomeWorkStudent();
|
|
|
|
+ if (homeWorkStudents.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ homeWorkStudents[0].score = homeWorkCommentDto.score ?? homeWorkStudents[0].score;
|
|
|
|
+ HomeWorkComment homeWorkComment = new HomeWorkComment
|
|
|
|
+ {
|
|
|
|
+ comment = homeWorkCommentDto.comments,
|
|
|
|
+ createTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(),
|
|
|
|
+ TEAMModelId = homeWorkCommentDto.TEAMModelId
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ homeWorkStudents[0].teacherComments = homeWorkComment;
|
|
|
|
+ data = await _cosmos.SaveOrUpdate(homeWorkStudents[0]);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 查询教师评语罐头
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="dict"></param>
|
|
|
|
+ /// <param name="context"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task FindTeacherComments(Dict dict, IServerStreamWriter<TeacherComments> responseStream, ServerCallContext context)
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, object> keyValuePairs = dict.ToDict();
|
|
|
|
+ List<TeacherComments> teacherComments = new List<TeacherComments>();
|
|
|
|
+ if (keyValuePairs.IsNotEmpty()) {
|
|
|
|
+ teacherComments = await _cosmos.FindByDict<TeacherComments>(keyValuePairs);
|
|
|
|
+ if (teacherComments.IsNotEmpty()) {
|
|
|
|
+ teacherComments.ForEach(x=> {
|
|
|
|
+ responseStream.WriteAsync(x);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|