123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.Context.Exception;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
- using TEAMModelOS.Service.Models;
- namespace TEAMModelOS.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class CommentController :BaseController
- {
- private readonly IAzureCosmosDBV3Repository _cosmos;
- public CommentController(IAzureCosmosDBV3Repository _cosmosDBV3Repository)
- {
- _cosmos = _cosmosDBV3Repository;
- }
- /// <summary>
- /// 添加教师评语快捷回复
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("addComment")]
- public async Task<BaseJosnRPCResponse> AddComment(JosnRPCRequest<CommentsDto> request)
- {
- var id = "Comment-" + request.@params.TEAMModelId.Replace("#", "");
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<Comment> Comment = await _cosmos.FindByDict<Comment>(new Dictionary<string, object> { { "code", request.@params.TEAMModelId }, { "id", id } });
- Comment comment = new Comment();
- if (Comment.IsEmpty())
- {
- comment.id = id;
- comment.code = request.@params.TEAMModelId;
- comment.comment.Add(request.@params.comment);
- Comment.Add(comment);
- }
- else {
- comment = Comment[0];
- comment.comment.Add(request.@params.comment);
- }
- builder.Data(await _cosmos.SaveOrUpdate(comment));
- return builder.build();
- }
- /// <summary>
- /// 查询教师评语罐头
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("findComment")]
- public async Task<BaseJosnRPCResponse> findComment(JosnRPCRequest<Dictionary<string, object>> request)
- {
- // request.@params.TryAdd("PartitionKey", request.lang);
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<Comment> data = new List<Comment>();
- if (request.@params.Keys.Count > 0)
- {
- data = await _cosmos.FindByDict<Comment>(request.@params);
- }
- else
- {
- return builder.Error(ResponseCode.PARAMS_ERROR, "参数异常!").build();
- }
- return builder.Data(data).build();
- }
- /// <summary>
- /// 更新保存教师评语罐头,如果评语列表为空则删除
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("upsertComment")]
- public async Task<BaseJosnRPCResponse> UpsertComment(JosnRPCRequest<Comment> request)
- {
- // request.@params.TryAdd("PartitionKey", request.lang);
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- Comment comment = null;
- if (request.@params.comment.Count > 0)
- {
- if (string.IsNullOrEmpty(request.@params.id)) {
- request.@params.id = "Comment-" + request.@params.code.Replace("#", "");
- }
- comment = await _cosmos.SaveOrUpdate<Comment>(request.@params);
- }
- else {
- if (!string.IsNullOrEmpty(request.@params.id))
- {
- IdPk idPk = await _cosmos.DeleteAsync<Comment>(request.@params.id, request.@params.code);
- }
-
- }
- return builder.Data(comment).build();
- }
-
- }
- }
|