|
@@ -0,0 +1,148 @@
|
|
|
+using DocumentFormat.OpenXml.Drawing;
|
|
|
+using Exam.Infrastructure.Data.Entity;
|
|
|
+using FluentValidation;
|
|
|
+using Hotline.Application.Exam.Constants.Messages;
|
|
|
+using Hotline.Application.Exam.Interface.ExamManages;
|
|
|
+using Hotline.Application.Exam.QueryExtensions.ExamManages;
|
|
|
+using Hotline.Exams.ExamManages;
|
|
|
+using Hotline.Exams.Questions;
|
|
|
+using Hotline.Repository.SqlSugar;
|
|
|
+using Hotline.Repository.SqlSugar.DataPermissions;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Interface;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Interfaces.ExamManages;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Interfaces.Questions;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Service;
|
|
|
+using Hotline.Share.Dtos.ExamManages;
|
|
|
+using Hotline.Share.Dtos.TestPapers;
|
|
|
+using Hotline.Share.Enums.Exams;
|
|
|
+using Hotline.Share.Requests.Exam;
|
|
|
+using Hotline.Share.ViewResponses.Exam;
|
|
|
+using Hotline.Tools;
|
|
|
+using JiebaNet.Segmenter.Common;
|
|
|
+using MapsterMapper;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using SqlSugar;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Dynamic;
|
|
|
+using System.Linq;
|
|
|
+using System.Linq.Expressions;
|
|
|
+using System.Text;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Dependency;
|
|
|
+
|
|
|
+namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
+{
|
|
|
+ public class OfflineExamAnalysisService : ApiService<ExamOfflineExamAnalysis, AddOfflineExamAnalysisDto, UpdateOfflineExamAnalysisDto, HotlineDbContext>, IOfflineExamAnalysisService, IScopeDependency
|
|
|
+ {
|
|
|
+ private readonly IOfflineExamAnalysisRepository _repository;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IDataPermissionFilterBuilder _dataPermissionFilterBuilder;
|
|
|
+ private readonly IServiceProvider _serviceProvider;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+
|
|
|
+ public OfflineExamAnalysisService(IOfflineExamAnalysisRepository repository,
|
|
|
+ ISessionContext sessionContext,
|
|
|
+ IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider,
|
|
|
+ IMapper mapper) : base(repository, mapper, sessionContext)
|
|
|
+ {
|
|
|
+ this._repository = repository;
|
|
|
+ this._sessionContext = sessionContext;
|
|
|
+ this._dataPermissionFilterBuilder = dataPermissionFilterBuilder;
|
|
|
+ this._serviceProvider = serviceProvider;
|
|
|
+ this._mapper = mapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region public method
|
|
|
+ public Task<OfflineExamAnalysisDto> GetAsync(EntityQueryRequest entityQueryRequest)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Task<(int, List<OfflineExamAnalysisViewResponse>)> GetListAsync(OfflineExamAnalysisPagedRequest queryRequest)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<PageViewResponse<OfflineExamAnalysisViewResponse>> GetPagedListAsync(OfflineExamAnalysisPagedRequest queryRequest)
|
|
|
+ {
|
|
|
+ var expression = queryRequest.GetExpression();
|
|
|
+ var offlineExamAnalysisTable = _repository.Queryable().Where(expression);
|
|
|
+
|
|
|
+ var queryable = offlineExamAnalysisTable.Select(x => new OfflineExamAnalysisViewResponse
|
|
|
+ {
|
|
|
+ CutoffScore = x.CutoffScore,
|
|
|
+ ExamName = x.ExamName,
|
|
|
+ DepartmentName = x.DepartmentName,
|
|
|
+ Id = x.Id,
|
|
|
+ Score = x.Score,
|
|
|
+ TotalScore = x.TotalScore,
|
|
|
+ UserName = x.UserName
|
|
|
+ }).OrderByPropertyNameIF(!string.IsNullOrEmpty(queryRequest.SortField), queryRequest.SortField, (OrderByType)(queryRequest.SortRule ?? 0));
|
|
|
+
|
|
|
+ var total = await offlineExamAnalysisTable.CountAsync();
|
|
|
+ var items = queryRequest.IsPaged ? await queryable.ToPageListAsync(queryRequest.PageIndex, queryRequest.PageSize) : await queryable.ToListAsync();
|
|
|
+
|
|
|
+ var result = new PageViewResponse<OfflineExamAnalysisViewResponse>
|
|
|
+ {
|
|
|
+ Items = items,
|
|
|
+ Pagination = new Pagination(queryRequest.PageIndex, queryRequest.PageSize, total)
|
|
|
+ };
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task ImportExcel(IFormFile file, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var stream = file.OpenReadStream();
|
|
|
+ var contents = ExcelHelper.Read(stream, true);
|
|
|
+
|
|
|
+ var offlineExamAnalysisDtos = new List<AddOfflineExamAnalysisDto>();
|
|
|
+
|
|
|
+ contents.ForEach(async item =>
|
|
|
+ {
|
|
|
+ var value = (item as ExpandoObject).GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[0]);
|
|
|
+
|
|
|
+ if (value == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var offlineExamAnalysisDto = BuildOfflineExamAnalysis(item as ExpandoObject);
|
|
|
+
|
|
|
+ if (offlineExamAnalysisDto != null)
|
|
|
+ offlineExamAnalysisDtos.Add(offlineExamAnalysisDto);
|
|
|
+ });
|
|
|
+
|
|
|
+ await base.AddAsync(offlineExamAnalysisDtos, cancellationToken);
|
|
|
+
|
|
|
+ stream.Close();
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region private method
|
|
|
+ private OfflineExamAnalysisDto BuildOfflineExamAnalysis(ExpandoObject? item)
|
|
|
+ {
|
|
|
+ var totalScore = 0;
|
|
|
+ var cutoffScore = 0;
|
|
|
+ var score = 0;
|
|
|
+
|
|
|
+ var offlineExamAnalysisDto = new OfflineExamAnalysisDto
|
|
|
+ {
|
|
|
+ UserName = item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[0]) != null ? item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[0]).ToString() : string.Empty,
|
|
|
+ DepartmentName= item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[1]) != null ? item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[1]).ToString() : string.Empty,
|
|
|
+ ExamName = item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[2]) != null ? item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[2]).ToString() : string.Empty,
|
|
|
+ StartTime = DateTime.TryParse(item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[3])?.ToString(),out DateTime startTime) ? startTime : DateTime.MinValue,
|
|
|
+ EndTime = item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[4])!=null? (DateTime.TryParse(item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[4])?.ToString(),out DateTime dateTime) ? dateTime : null):null,
|
|
|
+ TotalScore = int.TryParse(item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[5])?.ToString(),out totalScore)?totalScore:0,
|
|
|
+ CutoffScore = int.TryParse(item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[6])?.ToString(),out cutoffScore)? cutoffScore:0,
|
|
|
+ Score = int.TryParse(item.GetValueOrDefault(OfflineExamSystemConstants.ColumnNames[7])?.ToString(), out score) ? score : 0,
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ return offlineExamAnalysisDto;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|