123 lines
4.5 KiB
C#
123 lines
4.5 KiB
C#
using Microsoft.Extensions.Localization;
|
|
using SJZY.Track.Application.Dtos.TrackStatus;
|
|
using SJZY.Track.Application.Localization;
|
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
|
using SJZY.Track.Domain.Dtos.TrackStatus;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackStatus;
|
|
|
|
/// <summary>
|
|
/// 轨迹状态
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹状态")]
|
|
[Route("/Track/Status")]
|
|
public class TrackStatusService : ApplicationService, ITransientDependency
|
|
{
|
|
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
|
|
private readonly ITrackStatusRepository _trackStatusRepository;
|
|
|
|
public TrackStatusService(
|
|
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
|
|
ITrackStatusRepository trackStatusRepository
|
|
)
|
|
{
|
|
this._stringLocalizer=stringLocalizer;
|
|
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)
|
|
{
|
|
#region 业务校验
|
|
var trackStatusEntity = await _trackStatusRepository.GetFirstAsync(a => a.SubSystemId==input.SubSystemId&& (a.Code==input.Code ||
|
|
a.Status==input.TrackStatus || a.EnStatus==input.EntrackStatus));
|
|
if (trackStatusEntity!=null)
|
|
{
|
|
throw new BusinessException(message: _stringLocalizer["TrackStatusExist"]);
|
|
}
|
|
#endregion
|
|
|
|
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)
|
|
{
|
|
#region 业务校验
|
|
var trackStatusEntity = await _trackStatusRepository.GetFirstAsync(a => a.Id !=input.Id && a.SubSystemId==input.SubSystemId&& (a.Code==input.Code ||
|
|
a.Status==input.TrackStatus || a.EnStatus==input.EntrackStatus));
|
|
if (trackStatusEntity!=null)
|
|
{
|
|
throw new BusinessException(message: _stringLocalizer["TrackStatusExist"]);
|
|
}
|
|
#endregion
|
|
|
|
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
|
|
} |