109 lines
4.0 KiB
C#
109 lines
4.0 KiB
C#
using SJZY.Track.Application.Dtos.TrackContents;
|
|
using SJZY.Track.Application.Dtos.TrackStatus;
|
|
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
|
using SJZY.Track.Domain.Dtos.TrackContents;
|
|
using SJZY.Track.Domain.Dtos.TrackStatus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackContents
|
|
{
|
|
/// <summary>
|
|
/// 轨迹内容服务
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹内容")]
|
|
[Route("/Track/Content")]
|
|
public class TrackContentService : ApplicationService, ITransientDependency
|
|
{
|
|
private readonly ITrackContentRepository _trackContentRepository;
|
|
|
|
public TrackContentService(
|
|
ITrackContentRepository trackContentRepository
|
|
)
|
|
{
|
|
this._trackContentRepository=trackContentRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 轨迹内容编辑
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("Edit")]
|
|
public async Task<UnifyResultDto> EditAsync(EditTrackContentInput 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<GetTrackContentDetailDto>> GetDetailAsync(int id)
|
|
{
|
|
var detailInfo = await _trackContentRepository.GetDetailAsync(id);
|
|
if (detailInfo == null)
|
|
{
|
|
return new UnifyResultDto<GetTrackContentDetailDto>(false, null, "未查询到轨迹状态");
|
|
}
|
|
|
|
var dto = ObjectMapper.Map<GetTrackContentDetailVO, GetTrackContentDetailDto>(detailInfo);
|
|
return new UnifyResultDto<GetTrackContentDetailDto>("200", "", dto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分页轨迹内容
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetList")]
|
|
public async Task<UnifyPageResultDto<GetTrackContentListDto>> GetPageTrackContent(GetPageTrackContentInput input)
|
|
{
|
|
var vo = ObjectMapper.Map<GetPageTrackContentInput, GetPageTrackContentVO>(input);
|
|
var resultDto = await _trackContentRepository.GetPageTrackContent(vo);
|
|
var pageResultDto =
|
|
ObjectMapper.Map<UnifyPageResultDto<GetTrackContentListVO>, UnifyPageResultDto<GetTrackContentListDto>>(
|
|
resultDto);
|
|
|
|
return pageResultDto;
|
|
}
|
|
|
|
#region 私有方法
|
|
private async Task<UnifyResultDto> AddAsync(EditTrackContentInput input)
|
|
{
|
|
var entity = ObjectMapper.Map<EditTrackContentInput, TrackContentEntity>(input);
|
|
var isTrue = await _trackContentRepository.InsertAsync(entity);
|
|
|
|
return new UnifyResultDto("200", "新增成功", isTrue);
|
|
}
|
|
|
|
private async Task<UnifyResultDto> UpdateAsync(EditTrackContentInput input)
|
|
{
|
|
var templateEntity = await _trackContentRepository.GetFirstAsync(a => a.Id == input.Id);
|
|
ObjectMapper.Map(input, templateEntity);
|
|
var isTrue = await _trackContentRepository.UpdateAsync(templateEntity);
|
|
|
|
return new UnifyResultDto("200", "修改成功", isTrue);
|
|
}
|
|
|
|
private async Task<UnifyResultDto> DeleteAsync(EditTrackContentInput input)
|
|
{
|
|
var isTrue = await _trackContentRepository.SoftDeleteAsync(x => x.Id == input.Id);
|
|
|
|
return new UnifyResultDto("200", "删除成功", isTrue);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|