2025-01-14 16:04:33 +08:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Collections.Generic;
|
2025-01-21 16:01:50 +08:00
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using VOL.Entity.DomainModels.XinWei;
|
2025-01-14 16:04:33 +08:00
|
|
|
|
using YD_XinWei.Api.Context;
|
|
|
|
|
using YD_XinWei.Api.Services.Interface;
|
|
|
|
|
using YD_XinWei.Api.SmartSportsEntitys;
|
|
|
|
|
using YD_XinWei.Api.Utilities;
|
|
|
|
|
using YD_XinWei.Commons.Dto.Common;
|
|
|
|
|
using YD_XinWei.Commons.Dto.HomeWork;
|
2025-01-15 09:32:35 +08:00
|
|
|
|
using YD_XinWei.Commons.Dto.Open;
|
2025-01-14 16:04:33 +08:00
|
|
|
|
using YD_XinWei.Commons.Dto.School;
|
2025-01-21 16:01:50 +08:00
|
|
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
2025-01-14 16:04:33 +08:00
|
|
|
|
|
|
|
|
|
namespace YD_XinWei.Api.Services.Impl
|
|
|
|
|
{
|
2025-01-15 09:32:35 +08:00
|
|
|
|
/// <summary>
|
2025-01-21 16:01:50 +08:00
|
|
|
|
/// 服务实现
|
2025-01-15 09:32:35 +08:00
|
|
|
|
/// </summary>
|
2025-01-14 16:04:33 +08:00
|
|
|
|
public class XinWeiService : IXinWeiService
|
|
|
|
|
{
|
|
|
|
|
public SmartSportsContext _sportsContext;
|
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
2025-01-15 09:32:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sportsContext"></param>
|
|
|
|
|
/// <param name="mapper"></param>
|
2025-01-14 16:04:33 +08:00
|
|
|
|
public XinWeiService(SmartSportsContext sportsContext, IMapper mapper)
|
|
|
|
|
{
|
|
|
|
|
_sportsContext = sportsContext;
|
|
|
|
|
_mapper = mapper;
|
|
|
|
|
}
|
2025-01-15 09:32:35 +08:00
|
|
|
|
|
2025-01-21 16:01:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取设备信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="deviceSerial"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
public async Task<DeviceInfoDto> DeviceInfo(string deviceSerial)
|
|
|
|
|
{
|
2025-02-12 16:05:53 +08:00
|
|
|
|
var deviceInfo = await _sportsContext.XW_Device.FirstOrDefaultAsync(x => x.DeviceSerial == deviceSerial);
|
2025-01-21 16:01:50 +08:00
|
|
|
|
var res = _mapper.Map<DeviceInfoDto>(deviceInfo);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2025-01-15 09:32:35 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 项目模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2025-01-14 16:04:33 +08:00
|
|
|
|
public async Task<List<ProjectModeDto>> SportsModelTypeList()
|
|
|
|
|
{
|
|
|
|
|
var res = await _sportsContext.XW_ProjectMode.Select(x => new ProjectModeDto()
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
ProjectKind = x.ProjectKind,
|
|
|
|
|
Name = x.Name
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-15 09:32:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 体育项目
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="orgId">学校Id</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
2025-01-14 16:04:33 +08:00
|
|
|
|
public async Task<List<TestingProjectDto>> OrgSportsProjectList(int orgId)
|
|
|
|
|
{
|
|
|
|
|
var res = await _sportsContext.XW_TestingProject.Where(x => x.OrgId == orgId).Select(x => new TestingProjectDto()
|
|
|
|
|
{
|
|
|
|
|
ProjectId = x.ProjectId,
|
|
|
|
|
IsOpen = x.IsOpen,
|
|
|
|
|
IsShow = x.IsShow,
|
|
|
|
|
ProjectName = x.ProjectName
|
|
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2025-01-15 09:32:35 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取学生信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="orgId">学校Id</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<StudentInfoDto>> MinimumOfStudentInfoList(int orgId)
|
|
|
|
|
{
|
2025-01-15 10:10:13 +08:00
|
|
|
|
string schoolCode = await _sportsContext.School.Where(x => x.Id == orgId).Select(x => x.SchoolCode).FirstAsync();
|
2025-01-15 09:32:35 +08:00
|
|
|
|
|
2025-01-15 10:10:13 +08:00
|
|
|
|
var res = await (from s in _sportsContext.Student
|
|
|
|
|
join c in _sportsContext.Class on s.ClassId equals c.Id
|
|
|
|
|
join g in _sportsContext.Grade on c.GradeId equals g.Id
|
|
|
|
|
where s.SchoolCode == schoolCode
|
|
|
|
|
select new StudentInfoDto()
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
OrgId = orgId,
|
2025-02-20 18:57:10 +08:00
|
|
|
|
UserId = s.Id,
|
2025-01-15 10:10:13 +08:00
|
|
|
|
StudentNo = s.StudentNo,
|
|
|
|
|
Name = s.StudentName,
|
|
|
|
|
Sex = s.Sex == 1 ? "男" : "女",
|
|
|
|
|
ClassId = c.Id,
|
|
|
|
|
GradeId = g.Id,
|
|
|
|
|
RuleGradeId = g.Id,
|
|
|
|
|
ClassName = c.ClassName,
|
|
|
|
|
GradeName = g.GradeName,
|
2025-02-20 18:57:10 +08:00
|
|
|
|
CardNo = new List<string>()
|
2025-01-15 10:10:13 +08:00
|
|
|
|
}).ToListAsync();
|
2025-01-15 09:32:35 +08:00
|
|
|
|
|
2025-01-15 10:10:13 +08:00
|
|
|
|
return res;
|
|
|
|
|
}
|
2025-01-21 16:01:50 +08:00
|
|
|
|
|
2025-02-20 18:57:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取名单列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="orgId"></param>
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
public async Task<List<SportsRosterDto>> SportsRosterList(int orgId, int userId = 0)
|
|
|
|
|
{
|
|
|
|
|
string schoolCode = await _sportsContext.School.Where(x => x.Id == orgId).Select(x => x.SchoolCode).FirstAsync();
|
|
|
|
|
var studentList = await _sportsContext.Student.Where(x => x.SchoolCode == schoolCode).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var list = await (from c in _sportsContext.Class
|
|
|
|
|
join g in _sportsContext.Grade on c.GradeId equals g.Id
|
|
|
|
|
where c.SchoolCode == schoolCode
|
|
|
|
|
select new SportsRosterDto()
|
|
|
|
|
{
|
|
|
|
|
Id = c.Id,
|
|
|
|
|
OrgId = orgId,
|
|
|
|
|
Name = c.ClassName,
|
|
|
|
|
GradeId = g.Id,
|
|
|
|
|
RuleGradeId = g.Id,
|
|
|
|
|
GradeName = g.GradeName,
|
|
|
|
|
Status = 1,
|
|
|
|
|
Type = 1
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var stuList = studentList.Where(x => x.ClassId == item.Id).ToList();
|
|
|
|
|
List<SportsRosterStudentDto> sportList = new List<SportsRosterStudentDto>();
|
|
|
|
|
|
|
|
|
|
foreach (var sport in stuList)
|
|
|
|
|
{
|
|
|
|
|
sportList.Add(new SportsRosterStudentDto()
|
|
|
|
|
{
|
|
|
|
|
Id = sport.Id,
|
|
|
|
|
GroupName = item.Name,
|
|
|
|
|
ClassId = item.Id,
|
|
|
|
|
ClassName = item.Name,
|
|
|
|
|
GradeId = item.GradeId,
|
|
|
|
|
GradeName = item.GradeName,
|
|
|
|
|
OrgId = orgId,
|
|
|
|
|
Sex = sport.Sex,
|
|
|
|
|
UserName = sport.StudentName,
|
|
|
|
|
StudentNo = sport.StudentNo,
|
|
|
|
|
UserId = sport.Id,
|
|
|
|
|
GroupOrder = 1,
|
|
|
|
|
RosterId = 1,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.RosterGroupList.Add(new SportsRosterGroupDto()
|
|
|
|
|
{
|
|
|
|
|
GroupName = item.Name,
|
|
|
|
|
RosterStudentList = sportList
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-21 16:01:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取人脸信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<FaceListOfDevicePageDto> FaceListOfDevicePage(FaceListOfDeviceDto dto)
|
|
|
|
|
{
|
|
|
|
|
var total = await _sportsContext.Student.CountAsync();
|
|
|
|
|
|
|
|
|
|
string schoolCode = await _sportsContext.School.Where(x => x.Id == dto.OrgId).Select(x => x.SchoolCode).FirstAsync();
|
|
|
|
|
|
|
|
|
|
var list = await _sportsContext.Student
|
|
|
|
|
.Where(x => x.SchoolCode == schoolCode)
|
|
|
|
|
.Select(s => new DeviceUserFaceVo()
|
|
|
|
|
{
|
|
|
|
|
FaceId = s.StudentNo,
|
|
|
|
|
FaceType = 1,
|
|
|
|
|
FaceUrl = s.Photo,
|
2025-02-25 15:32:58 +08:00
|
|
|
|
PersonId = s.StudentNo,
|
2025-01-21 16:01:50 +08:00
|
|
|
|
UserId = s.Id
|
|
|
|
|
})
|
|
|
|
|
.Skip((dto.PageNo - 1) * dto.PageSize)
|
|
|
|
|
.Take(dto.PageSize)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return new FaceListOfDevicePageDto()
|
|
|
|
|
{
|
|
|
|
|
Total = total,
|
|
|
|
|
PageNum = dto.PageNo,
|
|
|
|
|
Pages = dto.PageSize,
|
|
|
|
|
List = list
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取训练评分规则
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="orgId">学校Id</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<ScoreRuleDto>> ScoreRules(int orgId)
|
|
|
|
|
{
|
2025-02-20 18:57:10 +08:00
|
|
|
|
var scoreRules = await _sportsContext.HealthStandards.Where(x => x.CategoryEnum == "Pull_Up").ToArrayAsync();
|
|
|
|
|
var groupedData = scoreRules.GroupBy(x => x.GradeId).ToList();
|
|
|
|
|
|
|
|
|
|
var result = groupedData.Select(group => new ScoreRuleDto
|
|
|
|
|
{
|
|
|
|
|
GradeId = group.Key,
|
|
|
|
|
ProjectKind = 6,
|
|
|
|
|
ProjectName = "引体向上",
|
|
|
|
|
MarkType = 1,
|
|
|
|
|
ModelType = 13,
|
|
|
|
|
OrgId = orgId,
|
|
|
|
|
ProjectRuleId = 6,
|
|
|
|
|
RuleType = 1,
|
|
|
|
|
ProjectId = 6,
|
|
|
|
|
Items = group.Select(item => new ScoreRuleItemDto
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
Sex = item.Sex,
|
|
|
|
|
Name = "1",
|
|
|
|
|
Score = item.Score,
|
|
|
|
|
Max = item.MaxValue,
|
|
|
|
|
Min = item.MinValue
|
|
|
|
|
}).ToList(),
|
|
|
|
|
Pluses = new List<ScoreRulePlusDto>
|
|
|
|
|
{
|
|
|
|
|
new ScoreRulePlusDto()
|
|
|
|
|
{
|
|
|
|
|
Id = group.FirstOrDefault()?.Id ?? 0,
|
|
|
|
|
Sex = 1,
|
|
|
|
|
Max = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.MaxValue),
|
|
|
|
|
Min = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.MinValue),
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.Score),
|
|
|
|
|
Score = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.Score)
|
|
|
|
|
},
|
|
|
|
|
new ScoreRulePlusDto()
|
|
|
|
|
{
|
|
|
|
|
Id = group.FirstOrDefault()?.Id ?? 0,
|
|
|
|
|
Sex = 2,
|
|
|
|
|
Max = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.MaxValue),
|
|
|
|
|
Min = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.MinValue),
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.Score),
|
|
|
|
|
Score = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.Score)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ScoreScopes = new List<ScoreScope>
|
|
|
|
|
{
|
|
|
|
|
new ScoreScope()
|
|
|
|
|
{
|
|
|
|
|
Gender = 1,
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.Score),
|
|
|
|
|
MaxCount = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.MaxValue)
|
|
|
|
|
},
|
|
|
|
|
new ScoreScope()
|
|
|
|
|
{
|
|
|
|
|
Gender = 2,
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.Score),
|
|
|
|
|
MaxCount = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x.MaxValue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
var scoreRules1 = await _sportsContext.HealthStandards.Where(x => x.CategoryEnum == "One_Minute_Sit_Up").ToArrayAsync();
|
|
|
|
|
var groupedData1 = scoreRules1.GroupBy(x => x.GradeId).ToList();
|
|
|
|
|
var result1 = groupedData1.Select(group => new ScoreRuleDto
|
|
|
|
|
{
|
|
|
|
|
GradeId = group.Key,
|
|
|
|
|
ProjectKind = 5,
|
|
|
|
|
ProjectName = "仰卧起坐",
|
|
|
|
|
MarkType = 1,
|
2025-02-23 20:44:53 +08:00
|
|
|
|
ModelType = 13,
|
2025-02-20 18:57:10 +08:00
|
|
|
|
OrgId = orgId,
|
|
|
|
|
ProjectRuleId = 5,
|
|
|
|
|
RuleType = 1,
|
|
|
|
|
ProjectId = 5,
|
|
|
|
|
Items = group.Select(item => new ScoreRuleItemDto
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
Sex = item.Sex,
|
|
|
|
|
Name = "1",
|
|
|
|
|
Score = item.Score,
|
|
|
|
|
Max = item.MaxValue,
|
|
|
|
|
Min = item.MinValue
|
|
|
|
|
}).ToList(),
|
|
|
|
|
Pluses = new List<ScoreRulePlusDto>
|
|
|
|
|
{
|
|
|
|
|
new ScoreRulePlusDto()
|
|
|
|
|
{
|
|
|
|
|
Id = group.FirstOrDefault()?.Id ?? 0,
|
|
|
|
|
Sex = 1,
|
|
|
|
|
Max = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.MaxValue),
|
|
|
|
|
Min = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.MinValue),
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.Score),
|
|
|
|
|
Score = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.Score)
|
|
|
|
|
},
|
|
|
|
|
new ScoreRulePlusDto()
|
|
|
|
|
{
|
|
|
|
|
Id = group.FirstOrDefault()?.Id ?? 0,
|
|
|
|
|
Sex = 2,
|
|
|
|
|
Max = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.MaxValue),
|
|
|
|
|
Min = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.MinValue),
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.Score),
|
|
|
|
|
Score = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.Score)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ScoreScopes = new List<ScoreScope>
|
|
|
|
|
{
|
|
|
|
|
new ScoreScope()
|
|
|
|
|
{
|
|
|
|
|
Gender = 1,
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.Score),
|
|
|
|
|
MaxCount = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.MaxValue)
|
|
|
|
|
},
|
|
|
|
|
new ScoreScope()
|
|
|
|
|
{
|
|
|
|
|
Gender = 2,
|
|
|
|
|
MaxScore = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.Score),
|
|
|
|
|
MaxCount = group.Where(x => x.Sex == 1).DefaultIfEmpty().Max(x => x?.MaxValue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).ToList();
|
|
|
|
|
return result.Concat(result1).ToList();
|
2025-02-07 22:22:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增训练
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task AddTrain(AddTrainDto dto)
|
|
|
|
|
{
|
|
|
|
|
var entity = _mapper.Map<XW_SportsTestData>(dto);
|
|
|
|
|
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
await _sportsContext.XW_SportsTestData.AddAsync(entity);
|
|
|
|
|
await _sportsContext.SaveChangesAsync();
|
|
|
|
|
}
|
2025-01-21 16:01:50 +08:00
|
|
|
|
}
|
2025-01-14 16:04:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|