using AutoMapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_BasicRepository;
|
using WIDESEA_Common.MaterielEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.Basic;
|
using WIDESEA_DTO.ERP;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IBasicService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_BasicService
|
{
|
public class CustomerInfoService : ServiceBase<Dt_CustomerInfo, ICustomerInfoRepository>, ICustomerInfoService
|
{
|
public ICustomerInfoRepository Repository => BaseDal;
|
private readonly IMapper _mapper;
|
private readonly IUnitOfWorkManage _unitOfWorkManage;
|
public CustomerInfoService(ICustomerInfoRepository BaseDal,IMapper mapper,IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
|
{
|
_mapper = mapper;
|
_unitOfWorkManage = unitOfWorkManage;
|
}
|
/// <summary>
|
/// 接收二期客户信息
|
/// </summary>
|
/// <param name="eRPCustomerDTO"></param>
|
/// <returns></returns>
|
public WebResponseContent ReceiveCustomer(ERPCustomerDTO eRPCustomerDTO)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (eRPCustomerDTO == null)
|
{
|
return content.Error("客户信息不能传入为空");
|
}
|
List<Dt_CustomerInfo> OldcustomerInfos = BaseDal.QueryData();
|
|
if (eRPCustomerDTO.OperateType == 1)
|
{
|
//判断重复插入
|
Dt_CustomerInfo? customerInfoOld = OldcustomerInfos.FirstOrDefault(x => x.CustomerCode == eRPCustomerDTO.CustomerCode);
|
if (customerInfoOld != null)
|
{
|
return content.Error($"客户{customerInfoOld.CustomerCode}已存在");
|
}
|
Dt_CustomerInfo customerInfo = _mapper.Map<Dt_CustomerInfo>(eRPCustomerDTO);
|
//新增
|
BaseDal.AddData(customerInfo);
|
}
|
else if (eRPCustomerDTO.OperateType == 2)
|
{
|
//判断是否存在
|
Dt_CustomerInfo? customerInfoOld = OldcustomerInfos.FirstOrDefault(x => x.CustomerCode == eRPCustomerDTO.CustomerCode);
|
if (customerInfoOld == null)
|
{
|
return content.Error($"更新客户{eRPCustomerDTO.CustomerCode}不存在");
|
}
|
Dt_CustomerInfo customerInfo = _mapper.Map<Dt_CustomerInfo>(eRPCustomerDTO);
|
customerInfo.Id = customerInfoOld.Id;
|
//更新
|
BaseDal.UpdateData(customerInfoOld);
|
}
|
else if (eRPCustomerDTO.OperateType == 3)
|
{
|
// 判断是否存在
|
Dt_CustomerInfo? customerInfoOld = OldcustomerInfos.FirstOrDefault(x => x.CustomerCode == eRPCustomerDTO.CustomerCode);
|
if (customerInfoOld == null)
|
{
|
return content.Error($"更新客户{eRPCustomerDTO.CustomerCode}不存在");
|
}
|
BaseDal.DeleteData(customerInfoOld);
|
}
|
else
|
{
|
return content.Error("未找到操作类型");
|
}
|
//更新数据
|
return content.OK("接收成功");
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
}
|
}
|