using AutoMapper.Internal.Mappers; using Microsoft.AspNetCore.Mvc; using Shentun.Peis.Diagnosises; using Shentun.Peis.AsbitemDetails; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using TencentCloud.Ame.V20190916.Models; using Microsoft.EntityFrameworkCore; using Shentun.Peis.Items; using Volo.Abp; using Shentun.Peis.Models; using Microsoft.AspNetCore.Authorization; namespace Shentun.Peis.AsbitemDetails { /// /// 组合项目包含的小项目 /// [ApiExplorerSettings(GroupName = "Work")] [Authorize] public class AsbitemDetailAppService : ApplicationService { private readonly IRepository _repository; private readonly IRepository _userRepository; private readonly AsbitemDetailManager _manager; public AsbitemDetailAppService(IRepository repository, IRepository userRepository, AsbitemDetailManager manager) { this._repository = repository; this._userRepository = userRepository; this._manager = manager; } /// /// 创建 /// /// /// [RemoteService(false)] public async Task CreateAsync(CreateAsbitemDetailDto input) { var createEntity = ObjectMapper.Map(input); var entity = await _repository.InsertAsync(createEntity); var dto = ObjectMapper.Map(entity); return dto; } /// /// 批量创建 先删除 /// /// /// [HttpPost("api/app/asbitemdetail/createasbitemdetailmany")] public async Task CreateAsbitemDetailManyAsync(CreateAsbitemDetailDto input) { await _manager.CheckAndDeleteAsync(input.AsbitemId); if (input.Details.Any()) { List asbitemDetails = new List(); foreach (var details in input.Details) { var entity = new AsbitemDetail { AsbitemId = input.AsbitemId, ItemId = details.ItemId }; asbitemDetails.Add(_manager.CreateAsbitemAsync(entity)); } if (asbitemDetails.Count > 0) { await _repository.InsertManyAsync(asbitemDetails); } } } /// /// 获取列表 组合项目包含的小项目 /// /// /// public async Task> GetAsbitemDetailInItemAsync(AsbitemDetailInItemDto input) { var entlist = _repository.GetDbSetAsync().Result.Include(c => c.Item) .Where(m => m.AsbitemId == input.AsbitemId).ToList(); var userList = await _userRepository.GetListAsync(); var entdto = entlist.Select(s => new ItemDto { CreationTime = s.Item.CreationTime, CreatorId = s.Item.CreatorId, DisplayName = s.Item.DisplayName, DisplayOrder = s.Item.DisplayOrder, Id = s.Item.Id, ItemTypeId = s.Item.ItemTypeId, LastModificationTime = s.Item.LastModificationTime, LastModifierId = s.Item.LastModifierId, SimpleCode = s.Item.SimpleCode, CalculationFunction = s.Item.CalculationFunction, DefaultResult = s.Item.DefaultResult, DiagnosisFunction = s.Item.DiagnosisFunction, EnglishShortName = s.Item.EnglishShortName, InputCheck = s.Item.InputCheck, IsActive = s.Item.IsActive, IsCalculationItem = s.Item.IsCalculationItem, IsContinueProcess = s.Item.IsContinueProcess, IsDiagnosisFunction = s.Item.IsDiagnosisFunction, IsNameIntoSummary = s.Item.IsNameIntoSummary, IsProduceSummary = s.Item.IsProduceSummary, Price = s.Item.Price, PriceItemId = s.Item.PriceItemId, ReferenceRangeTypeFlag = s.Item.ReferenceRangeTypeFlag, ResultTemplateTypeFlag = s.Item.ResultTemplateTypeFlag, UnitId = s.Item.UnitId, CreatorName = EntityHelper.GetUserNameNoSql(userList, s.Item.CreatorId), LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.Item.LastModifierId) }).ToList(); return entdto; } } }