145 lines
5.6 KiB
C#
145 lines
5.6 KiB
C#
using Microsoft.Extensions.Localization;
|
|
using SJZY.Track.Application.Contract.Dtos.TrackStatus;
|
|
using SJZY.Track.Application.Localization;
|
|
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
|
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;
|
|
private readonly ITrackContentRepository _trackContentRepository;
|
|
|
|
public TrackStatusService(
|
|
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
|
|
ITrackStatusRepository trackStatusRepository,
|
|
ITrackContentRepository trackContentRepository
|
|
)
|
|
{
|
|
this._stringLocalizer = stringLocalizer;
|
|
this._trackStatusRepository = trackStatusRepository;
|
|
this._trackContentRepository=trackContentRepository;
|
|
}
|
|
|
|
/// <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 trackStatusEntitys = await _trackStatusRepository.GetListAsync(a => a.SubSystemId == input.SubSystemId &&
|
|
(a.Code == input.Code ||
|
|
a.Status == input.TrackStatus || a.EnStatus == input.EntrackStatus));
|
|
if (trackStatusEntitys.Any())
|
|
{
|
|
//throw new BusinessException(message: _stringLocalizer["TrackStatusExist"]);
|
|
throw new BusinessException(message: "当前子系统下,轨迹状态代码或轨迹状态或轨迹状态英文存在");
|
|
}
|
|
|
|
#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 trackStatusEntitys = await _trackStatusRepository.GetListAsync(a => a.Id != input.Id &&
|
|
a.SubSystemId == input.SubSystemId && (a.Code == input.Code ||
|
|
a.Status == input.TrackStatus || a.EnStatus == input.EntrackStatus));
|
|
if (trackStatusEntitys.Any())
|
|
{
|
|
//throw new BusinessException(message: _stringLocalizer["TrackStatusExist"]);
|
|
throw new BusinessException(message: "当前子系统下,轨迹状态代码或轨迹状态或轨迹状态英文存在");
|
|
}
|
|
|
|
#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)
|
|
{
|
|
#region 业务校验
|
|
var isExistStatus = await _trackContentRepository.GetFirstAsync(a => a.TrackStatusId==input.Id);
|
|
if (isExistStatus!=null)
|
|
{
|
|
//throw new BusinessException(message: _stringLocalizer["IsExistTrackStatus"]);
|
|
throw new BusinessException(message: "轨迹内容已经绑定了该轨迹状态,请先删除轨迹内容后再删除该轨迹状态");
|
|
}
|
|
#endregion
|
|
var isTrue = await _trackStatusRepository.SoftDeleteAsync(x => x.Id == input.Id);
|
|
|
|
return new UnifyResultDto("200", "删除成功", isTrue);
|
|
}
|
|
|
|
#endregion
|
|
} |