From 1c7a87122fe5bf1f2b5a12484d66c5e9b1020a0e Mon Sep 17 00:00:00 2001 From: lyndonliu Date: Mon, 25 Mar 2024 17:46:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=9F=E5=8D=B7=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Exams/ExamManager.cs | 41 ++++++++++++++++--- .../Domains/Biz/ExamSubjectSchoolStudent.cs | 1 + .../DolphinExamPictureCutHttpApiHostModule.cs | 10 +++-- .../appsettings.json | 2 +- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs b/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs index e98d88a..bf18c09 100644 --- a/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs +++ b/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs @@ -83,10 +83,10 @@ public class ExamManager : DomainService, IExamManager }).ToListAsync(); var DbBiz = await GetTenantDb(eto.SchoolId); - await DbBiz.Updateable().SetColumns(s => s.CollectStatus == 2).Where(w => w.ExamSubjectSchoolId == eto.ExamSubjectSchoolId && w.StudentExamNum == penSerial).ExecuteCommandAsync(); if (lattices.Count == 0) { + await DbBiz.Updateable().SetColumns(s => s.CollectStatus == 2).Where(w => w.ExamSubjectSchoolId == eto.ExamSubjectSchoolId && w.StudentExamNum == penSerial).ExecuteCommandAsync(); Logger.LogInformation("{ExamSubjectId} {penSerial} 无点阵数据", eto.ExamSubjectId, penSerial); return; } @@ -228,12 +228,44 @@ public class ExamManager : DomainService, IExamManager IsExcess = s.IsExcess, }).ToList(); + var paperAnswers = new List(); var kgt = new List>(); var zgt = new List>(); // 纸张Id, 题号, 是否跨页 var pageSerials = new List(); // 需要计算的页 foreach (var paper in paperInfo) { var paperLatts = lattices.Where(w => w.PageSerial == paper.PaperId).ToList(); + + // 原卷生成 + var imgBytes = await paper.ImgUrl.GetBytesAsync(); + var bitmap = SKBitmap.Decode(imgBytes); + var pxLatts = paperLatts.Select(s => new SubjectiveLatt() + { + Stroke = s.strokeIndex, + X = s.CX.AUToPX(), + Y = s.CY.AUToPX(), + Time = s.Time, + }).ToList(); + using (var canvas = new SKCanvas(bitmap)) + { + // 一笔一笔的画上去 + var strokeIndexs = pxLatts.GroupBy(g => g.Stroke).Select(s => s.Key).ToList(); + foreach (var stroke in strokeIndexs) + { + var points = pxLatts.Where(w => w.Stroke == stroke).OrderBy(s => s.Time).Select(s => new SKPoint(s.X, s.Y)).ToArray(); + var skPointMode = SKPointMode.Polygon; + if (points.Length == 1) + skPointMode = SKPointMode.Points; + else if (points.Length == 2) + skPointMode = SKPointMode.Lines; + + canvas.DrawPoints(skPointMode, points, skPaint); + } + var paperAnswer = $"origin-paper/{eto.ExamSubjectId}/{penSerial}/{paper.PageIndex}.jpg"; + await _blobContainer.SaveAsync(paperAnswer, bitmap.Encode(SKEncodedImageFormat.Jpeg, 100).ToArray(), true); + paperAnswers.Add($"\"{_aliyunOption.Host}/{paperAnswer}\""); + } + foreach (var que in paper.QueData) { if (que.type == "1") // 客观题 @@ -268,10 +300,6 @@ public class ExamManager : DomainService, IExamManager } } - foreach (var _kgtDtl in kgtDtls) - { - _kgtDtl.Id = YitIdHelper.NextId(); - } var kgtPapers = kgt.GroupBy(s => s.Item1).Select(s => s.Key).ToList(); // 客观题处理 foreach (var paperId in kgtPapers) { @@ -394,6 +422,9 @@ public class ExamManager : DomainService, IExamManager await DbBiz.Insertable(kgtDtls).ExecuteCommandAsync(); await DbBiz.Insertable(zgtDtls).ExecuteCommandAsync(); + var paperAnswersStr = $"[{string.Join(",", paperAnswers)}]"; + await DbBiz.Updateable().SetColumns(s => new ExamSubjectSchoolStudent { CollectStatus = 2, DotPenOriginalImg = paperAnswersStr }).Where(w => w.ExamSubjectSchoolId == eto.ExamSubjectSchoolId && w.StudentExamNum == penSerial).ExecuteCommandAsync(); + await DbBiz.CommitTranAsync(); Logger.LogInformation("{ExamSubjectId} {penSerial} 收集成功", eto.ExamSubjectId, penSerial); } diff --git a/Dolphin.ExamPictureCut.Core/Domains/Biz/ExamSubjectSchoolStudent.cs b/Dolphin.ExamPictureCut.Core/Domains/Biz/ExamSubjectSchoolStudent.cs index c82eb8c..e5ad576 100644 --- a/Dolphin.ExamPictureCut.Core/Domains/Biz/ExamSubjectSchoolStudent.cs +++ b/Dolphin.ExamPictureCut.Core/Domains/Biz/ExamSubjectSchoolStudent.cs @@ -9,4 +9,5 @@ public class ExamSubjectSchoolStudent public long ExamSubjectSchoolId { get; set; } public string StudentExamNum { get; set; } public int CollectStatus { get; set; } + public string DotPenOriginalImg { get; set; } } diff --git a/Dolphin.ExamPictureCut.HttpApi.Host/DolphinExamPictureCutHttpApiHostModule.cs b/Dolphin.ExamPictureCut.HttpApi.Host/DolphinExamPictureCutHttpApiHostModule.cs index a5fa2f5..d441447 100644 --- a/Dolphin.ExamPictureCut.HttpApi.Host/DolphinExamPictureCutHttpApiHostModule.cs +++ b/Dolphin.ExamPictureCut.HttpApi.Host/DolphinExamPictureCutHttpApiHostModule.cs @@ -1,17 +1,14 @@ using Dolphin.ExamPictureCut.Constants; using Dolphin.ExamPictureCut.Domains; using Dolphin.ExamPictureCut.Extensions; -using Dolphin.ExamPictureCut.Options; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Cors; using Microsoft.OpenApi.Models; using NoFurion.SqlSugar; using SqlSugar; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Reflection; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; +using Volo.Abp.AspNetCore.Mvc.AntiForgery; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.Modularity; @@ -98,6 +95,11 @@ public class DolphinExamPictureCutHttpApiHostModule : AbpModule options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); options.Audience = "Dolphin"; }); + + Configure(options => + { + options.AutoValidate = false; + }); } private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) diff --git a/Dolphin.ExamPictureCut.HttpApi.Host/appsettings.json b/Dolphin.ExamPictureCut.HttpApi.Host/appsettings.json index 9738e38..7bf9529 100644 --- a/Dolphin.ExamPictureCut.HttpApi.Host/appsettings.json +++ b/Dolphin.ExamPictureCut.HttpApi.Host/appsettings.json @@ -4,7 +4,7 @@ }, "ConnectionStrings": { "marking_basic": "Server=192.168.2.9;Port=3306;Database=marking_basic;Uid=root;Pwd=qwe123!@#;AllowLoadLocalInfile=true;", - "penoffline": "host=192.168.2.7;port=8812;username=zhjs;password=zhjsniubi;database=qdb;ServerCompatibilityMode=NoTypeLoading;" + "penoffline": "host=47.108.209.28;port=8812;username=zhjs;password=zhjsniubi;database=qdb;ServerCompatibilityMode=NoTypeLoading;" }, "Redis": { "Configuration": "192.168.2.7:6379,password=qwe123!@#,defaultDatabase=14,idleTimeout=3000,poolsize=5,prefix=marking"