# Conflicts: # src/SJZY.Track.Application/Services/TrackStatus/TrackStatusService.cs # src/SJZY.Track.Domain/Aggregates/TrackStatusAggregate/ITrackStatusRepository.cs # src/SJZY.Track.Domain/SJZY.Track.Domain.csproj # src/SJZY.Track.Repository/TrackStatusRepository.cs
100 lines
3.5 KiB
C#
100 lines
3.5 KiB
C#
using SJZY.Track.Application.Dtos.TrackStatus;
|
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackStatus;
|
|
|
|
/// <summary>
|
|
/// 轨迹状态
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹状态")]
|
|
[Route("/Track/Status")]
|
|
public class TrackStatusService : ApplicationService, ITransientDependency
|
|
{
|
|
private readonly ITrackStatusRepository _trackStatusRepository;
|
|
|
|
public TrackStatusService(
|
|
ITrackStatusRepository trackStatusRepository
|
|
)
|
|
{
|
|
this._trackStatusRepository = trackStatusRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹状态编辑
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("Edit")]
|
|
public async Task<UnifyResultDto> EditAsync(EditTrackStatusInput input)
|
|
{
|
|
return input.Options switch
|
|
{
|
|
OptionType.新增 => await AddAsync(input),
|
|
OptionType.修改 => await UpdateAsync(input),
|
|
OptionType.删除 => await DeleteAsync(input),
|
|
_ => throw new BusinessException(message: "当前操作动作不合法")
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据状态id获取轨迹状态
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetDetail")]
|
|
public async Task<UnifyResultDto<GetTrackStatusDetailDto>> GetDetailAsync(int id)
|
|
{
|
|
var detailInfo = await _trackStatusRepository.GetDetailAsync(id);
|
|
if (detailInfo == null)
|
|
{
|
|
return new UnifyResultDto<GetTrackStatusDetailDto>(false, null, "未查询到轨迹状态");
|
|
}
|
|
|
|
var dto = ObjectMapper.Map<GetTrackStatusDetailVO, GetTrackStatusDetailDto>(detailInfo);
|
|
return new UnifyResultDto<GetTrackStatusDetailDto>("200", "", dto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分页轨迹状态
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetList")]
|
|
public async Task<UnifyPageResultDto<GetTrackStatusListDto>> GetPageTrackStatus(GetPageTrackStatusInput input)
|
|
{
|
|
var vo = ObjectMapper.Map<GetPageTrackStatusInput, GetPageTrackStatusVO>(input);
|
|
var resultDto = await _trackStatusRepository.GetPageTrackStatus(vo);
|
|
var pageResultDto =
|
|
ObjectMapper.Map<UnifyPageResultDto<GetTrackStatusListVO>, UnifyPageResultDto<GetTrackStatusListDto>>(
|
|
resultDto);
|
|
|
|
return pageResultDto;
|
|
}
|
|
|
|
#region 私有方法
|
|
private async Task<UnifyResultDto> AddAsync(EditTrackStatusInput input)
|
|
{
|
|
var entity = ObjectMapper.Map<EditTrackStatusInput, TrackStatusEntity>(input);
|
|
var isTrue = await _trackStatusRepository.InsertAsync(entity);
|
|
|
|
return new UnifyResultDto("200", "新增成功", isTrue);
|
|
}
|
|
|
|
private async Task<UnifyResultDto> UpdateAsync(EditTrackStatusInput input)
|
|
{
|
|
var templateEntity = await _trackStatusRepository.GetFirstAsync(a => a.Id == input.Id);
|
|
ObjectMapper.Map(input, templateEntity);
|
|
var isTrue = await _trackStatusRepository.UpdateAsync(templateEntity);
|
|
|
|
return new UnifyResultDto("200", "修改成功", isTrue);
|
|
}
|
|
|
|
private async Task<UnifyResultDto> DeleteAsync(EditTrackStatusInput input)
|
|
{
|
|
var isTrue = await _trackStatusRepository.SoftDeleteAsync(x => x.Id == input.Id);
|
|
|
|
return new UnifyResultDto("200", "删除成功", isTrue);
|
|
}
|
|
|
|
#endregion
|
|
} |