2025-07-08 14:57:45 +08:00
|
|
|
|
using AutoMapper;
|
2025-08-06 14:06:29 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2025-07-08 14:57:45 +08:00
|
|
|
|
using YD_WeChatApplet.Api.Services.Interface;
|
|
|
|
|
using YD_WeChatApplet.Api.SmartSportsEntitys;
|
|
|
|
|
using YD_WeChatApplet.Api.Utilities;
|
|
|
|
|
using YD_WeChatApplet.Context;
|
|
|
|
|
|
|
|
|
|
namespace YD_WeChatApplet.Api.Services.Impl
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 公共接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FrameworkService : IFrameworkService
|
|
|
|
|
{
|
|
|
|
|
public SmartSportsContext _sportsContext;
|
|
|
|
|
public FrameworkService(SmartSportsContext sportsContext)
|
|
|
|
|
{
|
|
|
|
|
_sportsContext = sportsContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-08 17:11:05 +08:00
|
|
|
|
/// Ai一体机扫描登录
|
2025-07-08 14:57:45 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="code"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<bool> ScanCodeLogin(string code)
|
|
|
|
|
{
|
2025-08-06 14:06:29 +08:00
|
|
|
|
var schoolCode = UserLoginContext.Current.SchoolCode;
|
|
|
|
|
var teacherId = UserLoginContext.Current.UserId;
|
|
|
|
|
|
|
|
|
|
// 先检查是否已存在相同的记录
|
|
|
|
|
var exist = await _sportsContext.Ai_ScanCodeLogin
|
2025-08-06 14:24:08 +08:00
|
|
|
|
.AnyAsync(x => x.Code == code && x.SchoolCode == schoolCode);
|
2025-08-06 14:06:29 +08:00
|
|
|
|
|
|
|
|
|
if (exist)
|
|
|
|
|
return true; // 已存在,认为成功
|
|
|
|
|
|
|
|
|
|
// 不存在则添加
|
|
|
|
|
var entity = new Ai_ScanCodeLogin
|
2025-07-08 14:57:45 +08:00
|
|
|
|
{
|
|
|
|
|
Code = code,
|
2025-08-06 14:06:29 +08:00
|
|
|
|
SchoolCode = schoolCode,
|
|
|
|
|
TeacherId = teacherId,
|
2025-07-08 14:57:45 +08:00
|
|
|
|
TeacherPhoneNo = UserLoginContext.Current.PhoneNo,
|
|
|
|
|
CreateDate = DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _sportsContext.AddAsync(entity);
|
|
|
|
|
return await _sportsContext.SaveChangesAsync() > 0;
|
|
|
|
|
}
|
2025-08-06 14:06:29 +08:00
|
|
|
|
|
2025-07-08 14:57:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|