diff --git a/src/Shentun.Peis.Application.Contracts/Poisons/PoisonWithTypeDto.cs b/src/Shentun.Peis.Application.Contracts/Poisons/PoisonWithTypeDto.cs new file mode 100644 index 0000000..cec28c3 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/Poisons/PoisonWithTypeDto.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.Poisons +{ + public class PoisonWithTypeDto + { + public string PoisonTypeName { get; set; } + + public List poisonDtos { get; set; } + } + + public class PoisonWithTypeSimpePoison + { + + public Guid Id { get; set; } + + /// + /// 毒害因素名称 + /// + public string DisplayName { get; set; } + + + /// + /// 自定义简码 + /// + public string SimpleCode { get; set; } + + } +} diff --git a/src/Shentun.Peis.Application/Poisons/PoisonAppService.cs b/src/Shentun.Peis.Application/Poisons/PoisonAppService.cs index 9f4f0b0..3ad834e 100644 --- a/src/Shentun.Peis.Application/Poisons/PoisonAppService.cs +++ b/src/Shentun.Peis.Application/Poisons/PoisonAppService.cs @@ -13,7 +13,7 @@ using Volo.Abp.Domain.Repositories; namespace Shentun.Peis.Poisons { - + /// /// 毒害因素 @@ -23,17 +23,20 @@ namespace Shentun.Peis.Poisons public class PoisonAppService : ApplicationService { private readonly IRepository _poisonRepository; + private readonly IRepository _poisonTypeRepository; private readonly PoisonManager _poisonManager; private readonly CacheService _cacheService; public PoisonAppService( IRepository poisonRepository, PoisonManager poisonManager, - CacheService cacheService) + CacheService cacheService, + IRepository poisonTypeRepository) { _poisonRepository = poisonRepository; _poisonManager = poisonManager; _cacheService = cacheService; + _poisonTypeRepository = poisonTypeRepository; } /// @@ -80,6 +83,38 @@ namespace Shentun.Peis.Poisons } + + /// + /// 获取毒害因素,附加毒害类别 + /// + /// + [HttpPost("api/app/Poison/GetPoisonWithTypeList")] + public async Task> GetPoisonWithTypeListAsync() + { + var poisonList = (from poison in await _poisonRepository.GetQueryableAsync() + join poisonType in await _poisonTypeRepository.GetQueryableAsync() on poison.PoisonTypeId equals poisonType.Id into poisonTypeTemp + from poisonTypeHaveEmpty in poisonTypeTemp.DefaultIfEmpty() + select new + { + PoisonTypeName = poisonTypeHaveEmpty != null ? poisonTypeHaveEmpty.DisplayName : "", + poison + }).ToList(); + + var entDto = poisonList.GroupBy(g => g.poison.PoisonTypeId).Select(s => new PoisonWithTypeDto + { + PoisonTypeName = s.FirstOrDefault().PoisonTypeName, + poisonDtos = s.Select(ss => new PoisonWithTypeSimpePoison + { + DisplayName = ss.poison.DisplayName, + Id = ss.poison.Id, + SimpleCode = ss.poison.SimpleCode + }).ToList() + }).ToList(); + + return entDto; + + } + /// /// 创建 ///