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> GetHealthStandardsPageList(HealthStandardsPageListParam paramDto) { var res = new PageDataDto(); var query = from s in _healthStandardsRepository.DbContext.Set() join g in _healthStandardsRepository.DbContext.Set() 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> GetHealthStandardsList(HealthStandardsExportParam paramDto) { var query = from s in _healthStandardsRepository.DbContext.Set() join g in _healthStandardsRepository.DbContext.Set() 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 paramDto) { if (paramDto == null || paramDto.Count == 0) throw new ArgumentNullException($"{nameof(paramDto)}参数为空"); var entitys = new List(); foreach (var item in paramDto) { var entity = _mapper.Map(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 paramDto) { var updateEntitys = _mapper.Map>(paramDto); updateEntitys.ForEach(x => { x.Modifier = UserContext.Current.UserId; x.ModifyDate = DateTime.Now; }); _healthStandardsRepository.UpdateRange(updateEntitys); await _healthStandardsRepository.SaveChangesAsync(); } public async Task DeleteHealthStandards(List Ids) { var model = await _healthStandardsRepository.FindAsync(x => Ids.Contains(x.Id)); if (model == null) throw new ArgumentNullException($"未找到删除的数据"); _healthStandardsRepository.DbContext.RemoveRange(model); await _healthStandardsRepository.SaveChangesAsync(); } } }