From 4179f8889305687d7acd35373ab8e8e55353d248 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Wed, 6 Aug 2025 14:06:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Impl/FrameworkService.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/WeChatApplet/Services/Impl/FrameworkService.cs b/WeChatApplet/Services/Impl/FrameworkService.cs index 6a627b8..3b5ed9d 100644 --- a/WeChatApplet/Services/Impl/FrameworkService.cs +++ b/WeChatApplet/Services/Impl/FrameworkService.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Microsoft.EntityFrameworkCore; using YD_WeChatApplet.Api.Services.Interface; using YD_WeChatApplet.Api.SmartSportsEntitys; using YD_WeChatApplet.Api.Utilities; @@ -25,11 +26,22 @@ namespace YD_WeChatApplet.Api.Services.Impl /// public async Task ScanCodeLogin(string code) { - var entity = new Ai_ScanCodeLogin() + var schoolCode = UserLoginContext.Current.SchoolCode; + var teacherId = UserLoginContext.Current.UserId; + + // 先检查是否已存在相同的记录 + var exist = await _sportsContext.Ai_ScanCodeLogin + .AnyAsync(x => x.Code == code && x.SchoolCode == schoolCode && x.TeacherId == teacherId); + + if (exist) + return true; // 已存在,认为成功 + + // 不存在则添加 + var entity = new Ai_ScanCodeLogin { Code = code, - SchoolCode = UserLoginContext.Current.SchoolCode, - TeacherId = UserLoginContext.Current.UserId, + SchoolCode = schoolCode, + TeacherId = teacherId, TeacherPhoneNo = UserLoginContext.Current.PhoneNo, CreateDate = DateTime.Now }; @@ -37,5 +49,6 @@ namespace YD_WeChatApplet.Api.Services.Impl await _sportsContext.AddAsync(entity); return await _sportsContext.SaveChangesAsync() > 0; } + } }