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.
146 lines
5.1 KiB
146 lines
5.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NUglify.Helpers;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Domain.Entities;
|
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
|
using Win_in.Sfs.Basedata.Domain;
|
|
using Win_in.Sfs.Basedata.Domain.Shared;
|
|
using Win_in.Sfs.Basedata.Kittings.Inputs;
|
|
using Win_in.Sfs.Shared;
|
|
|
|
|
|
namespace Win_in.Sfs.Basedata.Application;
|
|
|
|
[Authorize]
|
|
[Route($"{BasedataConsts.RootPath}kitting")]
|
|
|
|
public class KittingAppService : SfsBaseDataWithCodeAppServiceBase<Kitting, KittingDTO, SfsBaseDataRequestInputBase, KittingEditInput, KittingImportInput>, IKittingAppService
|
|
{
|
|
private new readonly IKittingRepository _repository;
|
|
|
|
|
|
private readonly IKittingManager _manager;
|
|
|
|
public KittingAppService(IKittingRepository repository, IDistributedCache<KittingDTO> cache, IKittingManager manager) : base(repository,cache)
|
|
{
|
|
_repository = repository;
|
|
_manager = manager;
|
|
//base.CreatePolicyName = KittingPermissions.Create;
|
|
//base.UpdatePolicyName = KittingPermissions.Update;
|
|
//base.DeletePolicyName = KittingPermissions.Delete;
|
|
}
|
|
[HttpPost]
|
|
[Route("")]
|
|
public override async Task<KittingDTO> CreateAsync(KittingEditInput input)
|
|
{
|
|
|
|
var detailquery=await _repository.WithDetailsAsync().ConfigureAwait(false);
|
|
var first = detailquery.FirstOrDefault(p => p.Code == input.Code);
|
|
var codes = input.Details.Select(p => p.PartCode);
|
|
if (first != null)
|
|
{
|
|
|
|
throw new UserFriendlyException($"已存在编码:{input.Code}的Kitting箱");
|
|
|
|
|
|
//var query = from itm in input.Details
|
|
// join itm1 in first.Details on itm.PartCode equals itm1.PartCode
|
|
// into temp1
|
|
// from tm1 in temp1.DefaultIfEmpty()
|
|
// where tm1 == null
|
|
// select itm;
|
|
//var details = ObjectMapper.Map<List<KittingDetailInput>, List<KittingDetail>>(query.ToList());
|
|
//foreach (var itm in details)
|
|
//{
|
|
// itm.SetId(GuidGenerator.Create());
|
|
// itm.MasterId = first.Id;
|
|
// first.AddDetails(itm);
|
|
//}
|
|
//var entity= await _repository.UpdateAsync(first).ConfigureAwait(false);
|
|
|
|
//return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
|
}
|
|
else
|
|
{
|
|
var entity = ObjectMapper.Map<KittingEditInput, Kitting>(input);
|
|
entity.SetId(Guid.NewGuid());
|
|
entity.Details.ForEach(item =>
|
|
{
|
|
item.MasterId = entity.Id;
|
|
});
|
|
entity = await _repository.InsertAsync(entity).ConfigureAwait(false);
|
|
return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
|
|
|
}
|
|
|
|
//first.Details.Where(p => codes.Contains(p.PartCode));
|
|
//var entity = ObjectMapper.Map<KittingEditInput, Kitting>(input);
|
|
//entity.SetId(Guid.NewGuid());
|
|
//entity.Details.ForEach(item =>
|
|
//{
|
|
// item.MasterId = entity.Id;
|
|
//});
|
|
//entity = await _repository.InsertAsync(entity).ConfigureAwait(false);
|
|
//return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
|
}
|
|
|
|
[HttpPut]
|
|
[Route("{id}")]
|
|
public override Task<KittingDTO> UpdateAsync(Guid id, KittingEditInput input)
|
|
{
|
|
var detailquery = _repository.WithDetails();
|
|
var first = detailquery.FirstOrDefault(p => p.Id == id);
|
|
if (first.Code == input.Code)
|
|
{
|
|
throw new UserFriendlyException($"已存在编码:{input.Code}的Kitting箱");
|
|
}
|
|
|
|
var query = from itm in input.Details
|
|
join itm1 in first.Details on itm.PartCode equals itm1.PartCode
|
|
select itm;
|
|
List<string> errors = new List<string>();
|
|
foreach (var itm in query.ToList())
|
|
{
|
|
errors.Add(itm.PartCode);
|
|
}
|
|
if(errors.Count > 0)
|
|
{
|
|
throw new UserFriendlyException($"零件号${string.Join(",", errors)}已存在");
|
|
|
|
}
|
|
|
|
|
|
return base.UpdateAsync(id, input);
|
|
}
|
|
|
|
[HttpPost("update")]
|
|
public virtual async Task UpdateAsync(KittingEditInput input)
|
|
{
|
|
var entity = ObjectMapper.Map<KittingEditInput, Kitting>(input);
|
|
//var dic=await _repository.GetAsync(r => r.Code == entity.Code);
|
|
// if (dic != null)
|
|
// {
|
|
// await _repository.DeleteAsync(dic);
|
|
// }
|
|
// await _repository.InsertAsync(entity);
|
|
await _repository.UpdateAsync(entity).ConfigureAwait(false);
|
|
}
|
|
|
|
protected override async Task<KittingDTO> GetFromRepositoryAsync(string code)
|
|
{
|
|
var displayName = typeof(KittingDTO).GetNameOfDisplay();
|
|
|
|
var query = await _repository.WithDetailsAsync().ConfigureAwait(false);
|
|
|
|
var entity = await query.Where(p => p.Code == code).FirstOrDefaultAsync().ConfigureAwait(false);
|
|
|
|
return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
|
}
|
|
}
|
|
|