You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.3 KiB
107 lines
3.3 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using AutoMapper;
|
|
using AutoMapper.Configuration;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Uow;
|
|
using Win_in.Sfs.Scp.v1.Domain;
|
|
using Microsoft.Extensions.Configuration;
|
|
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
|
|
|
|
namespace Win_in.Sfs.Scp.WebApi
|
|
{
|
|
/// <summary>
|
|
/// 零件服务
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route(RouteConsts.Part)]
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
|
|
|
|
public class PartAppService :ReadOnlyAppService<Part,PartDTO,Guid, RequestDTO>, IPartAppService
|
|
{
|
|
private readonly IPartRepository _partRepository;
|
|
private readonly ITaPartRepository _taPartRepository;
|
|
private readonly string _validSites = Validator.VALID_SITES;
|
|
|
|
public PartAppService(
|
|
IPartRepository repository
|
|
,ITaPartRepository taPartRepository
|
|
,IConfiguration configuration
|
|
) : base(repository)
|
|
{
|
|
_partRepository = repository;
|
|
_taPartRepository = taPartRepository;
|
|
_validSites = configuration["ValidSites"];
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按ID获取零件 (Get part by ID)
|
|
/// </summary>
|
|
/// <param name="id">唯一ID(unique ID)</param>
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
[Route("{id}")]
|
|
public override async Task<PartDTO> GetAsync(Guid id)
|
|
{
|
|
return await base.GetAsync(id);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 按条件获取零件列表 (Get part list by request condition)
|
|
/// </summary>
|
|
/// <param name="requestDTO">请求条件DTO(Request condition DTO)</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("")]
|
|
public override async Task<PagedResultDto<PartDTO>> GetListAsync(RequestDTO requestDTO)
|
|
{
|
|
return await base.GetListAsync(requestDTO);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增零件(Create New part)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("")]
|
|
public virtual async Task<PartDTO> CreateAsync(PartCreateDto partCreateDTO)
|
|
{
|
|
|
|
var entity = ObjectMapper.Map<PartCreateDto, Part>(partCreateDTO);
|
|
|
|
try
|
|
{
|
|
Validator.CheckSite(_validSites,entity.Site);
|
|
await UpsertTaPartAsync(entity);
|
|
await CurrentUnitOfWork.SaveChangesAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var baseEx = ex.GetBaseException();
|
|
entity.ErrorCode = 1;
|
|
entity.ErrorMessage = baseEx.Message;
|
|
}
|
|
|
|
var ret = await _partRepository.InsertAsync(entity);
|
|
|
|
|
|
var dto = ObjectMapper.Map<Part, PartDTO>(ret);
|
|
return dto;
|
|
}
|
|
|
|
private async Task UpsertTaPartAsync(Part entity)
|
|
{
|
|
//使用AutoMapper执行类型转换
|
|
var taPart = ObjectMapper.Map<Part, TA_PART>(entity);
|
|
//根据传入数据新增或修改SCP数据
|
|
await _taPartRepository.UpsertAsync(taPart);
|
|
}
|
|
}
|
|
}
|