|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
using Volo.Abp.Domain.Entities.Events;
|
|
|
|
using Volo.Abp.EventBus;
|
|
|
|
using Volo.Abp.ObjectMapping;
|
|
|
|
using Win_in.Sfs.Scp.v1.Domain;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Scp.WebApi
|
|
|
|
{
|
|
|
|
public class PartEventHandler
|
|
|
|
: ILocalEventHandler<EntityCreatedEventData<Part>>,
|
|
|
|
ITransientDependency
|
|
|
|
{
|
|
|
|
private readonly ITaPartRepository _taPartRepository;
|
|
|
|
private readonly IObjectMapper _objectMapper;
|
|
|
|
|
|
|
|
public PartEventHandler(ITaPartRepository taPartRepository,
|
|
|
|
IObjectMapper objectMapper)
|
|
|
|
{
|
|
|
|
_taPartRepository = taPartRepository;
|
|
|
|
_objectMapper = objectMapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task HandleEventAsync(EntityCreatedEventData<Part> eventData)
|
|
|
|
{
|
|
|
|
var part = eventData.Entity;
|
|
|
|
Console.WriteLine("Local Event:" + part.Code);
|
|
|
|
|
|
|
|
//根据传入数据新增或修改TA_PART
|
|
|
|
|
|
|
|
var taPart = _objectMapper.Map<Part, TA_PART>(part);
|
|
|
|
var current = await _taPartRepository.GetAsync(p => p.PartCode == taPart.PartCode);
|
|
|
|
if (current == null)
|
|
|
|
{
|
|
|
|
await _taPartRepository.InsertAsync(taPart);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current = _objectMapper.Map<Part, TA_PART>(part);
|
|
|
|
|
|
|
|
// current.PartDesc1 = part.Desc1;
|
|
|
|
// current.PartDesc2 = part.Desc2;
|
|
|
|
//...
|
|
|
|
|
|
|
|
await _taPartRepository.UpdateAsync(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|