178 lines
6.5 KiB
C#
178 lines
6.5 KiB
C#
using SJZY.Track.Application.Contract.Dtos.TrackStatus;
|
|
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
|
using SJZY.Track.Domain.Dtos.TrackStatus;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackStatus;
|
|
|
|
/// <summary>
|
|
/// 轨迹状态
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "轨迹状态")]
|
|
[Route("/Track/Status")]
|
|
public class TrackStatusService : ApplicationService
|
|
{
|
|
private readonly ITrackContentRepository _trackContentRepository;
|
|
private readonly ITrackStatusRepository _trackStatusRepository;
|
|
|
|
public TrackStatusService(
|
|
ITrackStatusRepository trackStatusRepository,
|
|
ITrackContentRepository trackContentRepository
|
|
)
|
|
{
|
|
_trackStatusRepository = trackStatusRepository;
|
|
_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>(GlobalConst.SuccessCode, "", dto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分页轨迹状态
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("GetList")]
|
|
public async Task<UnifyPageResultDto<GetTrackStatusListDto>> GetPagedTrackStatus(GetPagedTrackStatusInput input)
|
|
{
|
|
var vo = ObjectMapper.Map<GetPagedTrackStatusInput, GetPagedTrackStatusVO>(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())
|
|
{
|
|
var trackStatusCode = trackStatusEntitys.FirstOrDefault(t => t.Code == input.Code);
|
|
if (trackStatusCode != null)
|
|
{
|
|
throw new BusinessException(message: "该子系统下轨迹状态代码已存在");
|
|
}
|
|
|
|
var trackStatusName = trackStatusEntitys.FirstOrDefault(t => t.Status == input.TrackStatus);
|
|
if (trackStatusName != null)
|
|
{
|
|
throw new BusinessException(message: "该子系统下轨迹状态已存在");
|
|
}
|
|
|
|
var trackStatusEnName = trackStatusEntitys.FirstOrDefault(t => t.EnStatus == input.EnTrackStatus);
|
|
if (trackStatusEnName != null)
|
|
{
|
|
throw new BusinessException(message: "该子系统下轨迹状态英文已存在");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
var entity = ObjectMapper.Map<EditTrackStatusInput, TrackStatusEntity>(input);
|
|
var isTrue = await _trackStatusRepository.InsertAsync(entity);
|
|
|
|
return new UnifyResultDto(GlobalConst.SuccessCode, "新增成功", 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())
|
|
{
|
|
var trackStatusCode = trackStatusEntitys.FirstOrDefault(t => t.Code == input.Code);
|
|
if (trackStatusCode != null)
|
|
{
|
|
throw new BusinessException(message: "该子系统下轨迹状态代码已存在");
|
|
}
|
|
|
|
var trackStatusName = trackStatusEntitys.FirstOrDefault(t => t.Status == input.TrackStatus);
|
|
if (trackStatusName != null)
|
|
{
|
|
throw new BusinessException(message: "该子系统下轨迹状态已存在");
|
|
}
|
|
|
|
var trackStatusEnName = trackStatusEntitys.FirstOrDefault(t => t.EnStatus == input.EnTrackStatus);
|
|
if (trackStatusEnName != null)
|
|
{
|
|
throw new BusinessException(message: "该子系统下轨迹状态英文已存在");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
var trackStatus = await _trackStatusRepository.GetFirstAsync(a => a.Id == input.Id);
|
|
if (trackStatus == null)
|
|
{
|
|
throw new BusinessException(message: "轨迹状态不存在");
|
|
}
|
|
|
|
ObjectMapper.Map(input, trackStatus);
|
|
var isTrue = await _trackStatusRepository.UpdateAsync(trackStatus);
|
|
|
|
return new UnifyResultDto(GlobalConst.SuccessCode, "修改成功", 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(GlobalConst.SuccessCode, "删除成功", isTrue);
|
|
}
|
|
|
|
#endregion
|
|
}
|