You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.AsbitemDetails;
using Shentun.Peis.Models;
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;
namespace Shentun.Peis.Suggestions
{
/// <summary>
/// 诊断建议
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class SuggestionAppService : ApplicationService
{
private readonly IRepository<Suggestion, Guid> _suggestionRepository;
private readonly SuggestionManager _manager;
public SuggestionAppService(
IRepository<Suggestion, Guid> suggestionRepository,
SuggestionManager manager
)
{
this._suggestionRepository = suggestionRepository;
this._manager = manager;
}
/// <summary>
/// 批量创建 先删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/suggestion/createsuggestionmany")]
public async Task CreateSuggestionManyAsync(CreateSuggestionManyDto input)
{
//先按诊断ID删除所有建议
await _manager.CheckAndDeleteInDiagnosisIdAsync(input.DiagnosisId, input.SuggestionType);
if (input.Details.Any())
{
List<Suggestion> suggestions = new List<Suggestion>();
foreach (var item in input.Details)
{
var entity = new Suggestion
{
DiagnosisId = input.DiagnosisId,
DisplayOrder = input.Details.IndexOf(item) + 1,
SuggestionContent = item.SuggestionContent,
SuggestionType = input.SuggestionType
};
suggestions.Add(_manager.CreateAsync(entity));
}
if (suggestions.Count > 0)
{
await _suggestionRepository.InsertManyAsync(suggestions);
}
}
}
}
}