YD_SmartSports.Api/VOL.Business/Services/Norm/N_HealthStandardsService.cs
2025-06-06 16:00:39 +08:00

156 lines
5.6 KiB
C#

using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Business.IServices;
using VOL.Core.CacheManager;
using VOL.Core.Extensions.AutofacManager;
using VOL.Core.ManageUser;
using VOL.Entity.DomainModels;
using VOL.Entity.Enum;
using VOL.Model;
using VOL.System.IRepositories;
using VOL.System.Repositories;
namespace VOL.Business.Services.Norm
{
public class N_HealthStandardsService : IN_HealthStandardsService, IDependency
{
#region
private readonly IMapper _mapper;
private readonly IN_HealthStandardsRepository _healthStandardsRepository;
[ActivatorUtilitiesConstructor]
public N_HealthStandardsService(IMapper mapper,
IN_HealthStandardsRepository healthStandardsRepository)
{
_mapper = mapper;
_healthStandardsRepository = healthStandardsRepository;
}
#endregion
public async Task<PageDataDto<HealthStandardsPageListModel>> GetHealthStandardsPageList(HealthStandardsPageListParam paramDto)
{
var res = new PageDataDto<HealthStandardsPageListModel>();
var query = from s in _healthStandardsRepository.DbContext.Set<N_HealthStandards>()
join g in _healthStandardsRepository.DbContext.Set<S_Grade>() on s.GradeId equals g.Id
//where s.Creator == UserContext.Current.TenantId
select new HealthStandardsPageListModel()
{
Id = s.Id,
GradeId = g.Id,
GradeName = g.GradeName,
CategoryEnum = s.CategoryEnum,
CreateDate = s.CreateDate,
MaxValue = s.MaxValue,
MinValue = s.MinValue,
Rank = s.Rank,
Score = s.Score,
Sex = s.Sex == SexType.Male ? "男" : "女"
};
if (!string.IsNullOrWhiteSpace(paramDto.CategoryEnum))
{
query = query.Where(x => x.CategoryEnum.Equals(paramDto.CategoryEnum));
}
res.Total = await query.CountAsync();
var list = await query
.Skip((paramDto.PageIndex - 1) * paramDto.PageSize)
.Take(paramDto.PageSize)
.ToListAsync();
res.Datas = list;
return res;
}
public async Task<List<HealthStandardsPageListModel>> GetHealthStandardsList(HealthStandardsExportParam paramDto)
{
var query = from s in _healthStandardsRepository.DbContext.Set<N_HealthStandards>()
join g in _healthStandardsRepository.DbContext.Set<S_Grade>() on s.GradeId equals g.Id
//where s.Creator == UserContext.Current.TenantId
select new HealthStandardsPageListModel()
{
Id = s.Id,
GradeId = g.Id,
GradeName = g.GradeName,
CategoryEnum = s.CategoryEnum,
CreateDate = s.CreateDate,
MaxValue = s.MaxValue,
MinValue = s.MinValue,
Rank = s.Rank,
Score = s.Score,
Sex = s.Sex == SexType.Male ? "男" : "女"
};
if (!string.IsNullOrWhiteSpace(paramDto.CategoryEnum))
{
query = query.Where(x => x.CategoryEnum.Equals(paramDto.CategoryEnum));
}
var list = await query.ToListAsync();
return list;
}
public async Task AddHealthStandards(List<AddHealthStandardsParam> paramDto)
{
if (paramDto == null || paramDto.Count == 0)
throw new ArgumentNullException($"{nameof(paramDto)}参数为空");
var entitys = new List<N_HealthStandards>();
foreach (var item in paramDto)
{
var entity = _mapper.Map<N_HealthStandards>(item);
entity.Creator = UserContext.Current.UserId;
entity.CreateDate = DateTime.Now;
entitys.Add(entity);
}
if (entitys.Count > 0)
{
await _healthStandardsRepository.AddRangeAsync(entitys);
await _healthStandardsRepository.SaveChangesAsync();
}
}
public async Task ModifyHealthStandards(List<AddHealthStandardsParam> paramDto)
{
var updateEntitys = _mapper.Map<List<N_HealthStandards>>(paramDto);
updateEntitys.ForEach(x =>
{
x.Modifier = UserContext.Current.UserId;
x.ModifyDate = DateTime.Now;
});
_healthStandardsRepository.UpdateRange(updateEntitys);
await _healthStandardsRepository.SaveChangesAsync();
}
public async Task DeleteHealthStandards(List<int> Ids)
{
var model = await _healthStandardsRepository.FindAsync(x => Ids.Contains(x.Id));
if (model == null)
throw new ArgumentNullException($"未找到删除的数据");
_healthStandardsRepository.DbContext.RemoveRange(model);
await _healthStandardsRepository.SaveChangesAsync();
}
}
}