wangxinhui
2025-10-17 ce40df5daffae0d17b4e9fa7cb6d677afaa4d66f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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;
        }
    }
}