diff --git a/Src/CodeSpirit.ExamApi/Controllers/QuestionsController.cs b/Src/CodeSpirit.ExamApi/Controllers/QuestionsController.cs index f7f887609f219391c8595b0a22ffb8a43ed7c16d..b62453dd477bc42ecf3348595064b4ab7d8ec45c 100644 --- a/Src/CodeSpirit.ExamApi/Controllers/QuestionsController.cs +++ b/Src/CodeSpirit.ExamApi/Controllers/QuestionsController.cs @@ -102,7 +102,7 @@ public class QuestionsController : ApiControllerBase /// 题目ID /// 题目历史版本列表 [HttpGet("{id:long}/versions")] - [Operation("历史版本", "link", "/questions/${id}/versions", null)] + [Operation("历史版本", "link", "/exam/questionVersions?questionId=${id}", null)] public async Task>>> GetQuestionVersions(long id) { var versions = await _questionService.GetQuestionVersionsAsync(id); diff --git a/Src/CodeSpirit.ExamApi/Dtos/Question/CreateQuestionDto.cs b/Src/CodeSpirit.ExamApi/Dtos/Question/CreateQuestionDto.cs index e21c467152eecc2a4137d09f45d4686b6a3cd5c6..d0cacddc5eb13f3157c8d03eb6d2ec77e4b44e77 100644 --- a/Src/CodeSpirit.ExamApi/Dtos/Question/CreateQuestionDto.cs +++ b/Src/CodeSpirit.ExamApi/Dtos/Question/CreateQuestionDto.cs @@ -1,5 +1,7 @@ using CodeSpirit.Amis.Attributes.FormFields; using CodeSpirit.ExamApi.Data.Models; +using Newtonsoft.Json; +using System.Text.Json.Serialization; /// /// 创建题目DTO @@ -12,7 +14,7 @@ public class CreateQuestionDto [Required(ErrorMessage = "题目内容不能为空")] [StringLength(2000, ErrorMessage = "题目内容最多2000字符")] [DisplayName("题目内容")] - [AmisTextareaField(MaxLength = 2000, ShowCounter = true)] + [AmisTextareaField(MaxLength = 2000, ShowCounter = true, Required = true)] public string Content { get; set; } = string.Empty; /// @@ -70,15 +72,13 @@ public class CreateQuestionDto /// [Required(ErrorMessage = "请选择题目分类")] [DisplayName("分类")] - [AmisInputTreeField( + [AmisTreeSelectField( DataSource = "${ROOT_API}/api/exam/QuestionCategories/tree", - LabelField = "name", - ValueField = "id", Multiple = false, - JoinValues = false, - ExtractValue = true, - Required = true, - Placeholder = "请选择题目分类" + Cascade = true, + ShowOutline = true, + LabelField = "name", + ValueField = "id" )] public long CategoryId { get; set; } diff --git a/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionDto.cs b/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionDto.cs index 91689048b840e46c2484e644fd85a1fe1f783c08..bb049d90d966bfdff5b8c12f2d6c1fae208e0c42 100644 --- a/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionDto.cs +++ b/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionDto.cs @@ -39,7 +39,7 @@ public class QuestionDto [DisplayName("知识点")] [AmisColumn(Type = "json", Hidden = true)] [AmisFormField(Type = "json")] - public List? KnowledgePoints { get; set; } + public string? KnowledgePoints { get; set; } [DisplayName("分类")] public string CategoryName { get; set; } = string.Empty; diff --git a/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionVersionDto.cs b/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionVersionDto.cs index eaa48e530826d904b7778792617b27dff67f2258..0b735d3f4a5fcaa38ffe15c31b832762d0c78cf6 100644 --- a/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionVersionDto.cs +++ b/Src/CodeSpirit.ExamApi/Dtos/Question/QuestionVersionDto.cs @@ -43,7 +43,7 @@ public class QuestionVersionDto /// [DisplayName("知识点")] [AmisColumn(Type = "json")] - public List? KnowledgePoints { get; set; } + public string? KnowledgePoints { get; set; } /// /// 题目分值 diff --git a/Src/CodeSpirit.ExamApi/Dtos/Question/UpdateQuestionDto.cs b/Src/CodeSpirit.ExamApi/Dtos/Question/UpdateQuestionDto.cs index d97b51a7889fd4d7001ea8f0e2ca8d6eb812c8f2..3ffc6cb180af9e50092cef4ec995d8e5078a8d9f 100644 --- a/Src/CodeSpirit.ExamApi/Dtos/Question/UpdateQuestionDto.cs +++ b/Src/CodeSpirit.ExamApi/Dtos/Question/UpdateQuestionDto.cs @@ -13,6 +13,6 @@ public class UpdateQuestionDto : CreateQuestionDto [Required(ErrorMessage = "请填写修改原因")] [StringLength(500, ErrorMessage = "修改原因最多500字符")] [DisplayName("修改原因")] - [AmisTextareaField(MaxLength = 500, ShowCounter = true)] + [AmisTextareaField(MaxLength = 500, ShowCounter = true, Required = true)] public string ChangeReason { get; set; } = string.Empty; } \ No newline at end of file diff --git a/Src/CodeSpirit.ExamApi/MappingProfiles/QuestionVersionProfile.cs b/Src/CodeSpirit.ExamApi/MappingProfiles/QuestionVersionProfile.cs index 0c95ab72a8beb2de2a4d303f08c07284a1ad44ed..cd7e88d413abbbe0805052b86ef1c13ef76f6fdf 100644 --- a/Src/CodeSpirit.ExamApi/MappingProfiles/QuestionVersionProfile.cs +++ b/Src/CodeSpirit.ExamApi/MappingProfiles/QuestionVersionProfile.cs @@ -2,6 +2,7 @@ using AutoMapper; using CodeSpirit.ExamApi.Data.Models; using CodeSpirit.ExamApi.Dtos.QuestionVersion; using CodeSpirit.Shared.Extensions; +using System.Text.Json; namespace CodeSpirit.ExamApi.MappingProfiles; @@ -17,16 +18,29 @@ public class QuestionVersionProfile : Profile { // 配置基本CRUD映射 this.ConfigureBaseCRUDIMappings< - QuestionVersion, - QuestionVersionDto, - long, - CreateQuestionVersionDto, + QuestionVersion, + QuestionVersionDto, + long, + CreateQuestionVersionDto, UpdateQuestionVersionDto, CreateQuestionVersionDto>(); // 自定义映射 CreateMap() .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(src => src.CreatedAt)) - .ForMember(dest => dest.CreatedBy, opt => opt.MapFrom(src => src.CreatedBy)); + .ForMember(dest => dest.CreatedBy, opt => opt.MapFrom(src => src.CreatedBy)) + .ForMember(dest => dest.Tags, opt => opt.MapFrom(src => src.Tags != null && src.Tags.Any() ? JsonSerializer.Deserialize>(src.Tags, new JsonSerializerOptions()) : null)); + + CreateMap, PageList>() + .ForMember(dest => dest.Items, opt => opt.MapFrom(src => + src.Items.Select(q => new QuestionVersionDto + { + CreatedAt = q.CreatedAt, + CreatedBy = q.CreatedBy.ToString(), + Tags = !string.IsNullOrEmpty(q.Tags) + ? JsonSerializer.Deserialize>(q.Tags, new JsonSerializerOptions()) + : null, + }).ToList() + )); } } \ No newline at end of file diff --git a/Src/CodeSpirit.ExamApi/Mappings/QuestionProfile.cs b/Src/CodeSpirit.ExamApi/Mappings/QuestionProfile.cs index 11ee9e0f929c6701ccf5e47d00988ecd47bda4a4..36d8e1e3f7175ef43babbaa18cab905fcc5d4940 100644 --- a/Src/CodeSpirit.ExamApi/Mappings/QuestionProfile.cs +++ b/Src/CodeSpirit.ExamApi/Mappings/QuestionProfile.cs @@ -15,20 +15,30 @@ public class QuestionProfile : Profile { CreateMap() .ForMember(dest => dest.CategoryName, opt => opt.MapFrom(src => src.Category.Name)) - .ForMember(dest => dest.KnowledgePoints, opt => opt.MapFrom(src => - !string.IsNullOrEmpty(src.KnowledgePoints) - ? JsonSerializer.Deserialize>(src.KnowledgePoints, new JsonSerializerOptions()) - : null)) + .ForMember(dest => dest.KnowledgePoints, opt => opt.MapFrom(src => src.KnowledgePoints)) .ForMember(dest => dest.Tags, opt => opt.MapFrom(src => !string.IsNullOrEmpty(src.Tags) ? JsonSerializer.Deserialize>(src.Tags, new JsonSerializerOptions()) : null)); - CreateMap(); - CreateMap(); - CreateMap(); + CreateMap() + .ForMember(dest => dest.Tags, opt => opt.MapFrom(src => src.Tags != null && src.Tags.Any() ? JsonSerializer.Serialize(src.Tags, new JsonSerializerOptions()) : null)); + CreateMap() + .ForMember(dest => dest.Tags, opt => opt.MapFrom(src => src.Tags != null && src.Tags.Any() ? JsonSerializer.Serialize(src.Tags, new JsonSerializerOptions()) : null)); + CreateMap() + .ForMember(dest => dest.Tags, opt => opt.MapFrom(src => src.Tags != null && src.Tags.Any() ? JsonSerializer.Serialize(src.Tags, new JsonSerializerOptions()) : null)); // 添加 PageList 映射配置 - CreateMap, PageList>(); + CreateMap, PageList>() + .ForMember(dest => dest.Items, opt => opt.MapFrom(src => + src.Items.Select(q => new QuestionDto + { + CategoryName = q.Category.Name, + KnowledgePoints = q.KnowledgePoints, + Tags = !string.IsNullOrEmpty(q.Tags) + ? JsonSerializer.Deserialize>(q.Tags, new JsonSerializerOptions()) + : null, + }).ToList() + )); } } \ No newline at end of file diff --git a/Src/CodeSpirit.ExamApi/Services/Implementations/QuestionService.cs b/Src/CodeSpirit.ExamApi/Services/Implementations/QuestionService.cs index 9c2af0f061c1595ec4648fddb6589f0dbdd1716f..12efd2857ffba1ac5e9f0d4cf1495db53b8684bd 100644 --- a/Src/CodeSpirit.ExamApi/Services/Implementations/QuestionService.cs +++ b/Src/CodeSpirit.ExamApi/Services/Implementations/QuestionService.cs @@ -220,14 +220,14 @@ public class QuestionService : BaseCRUDIService idList.Contains(q.Id)) .Include(q => q.ExamPaperQuestions) - .Where(q => q.IsReferenced) + .Where(q => q.ExamPaperQuestions.Any()) .Select(q => q.Id) .ToListAsync();