wangxinhui
2025-08-30 cd78554c3da306ed8c866d971bee94457665f80c
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
using AutoMapper;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_DTO.Basic;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_BasicService
{
    public partial class MaterielInfoService : ServiceBase<Dt_MaterielInfo, IMaterielInfoRepository>, IMaterielInfoService
    {
        private readonly IBasicRepository _basicRepository;
 
        public IMaterielInfoRepository Repository => BaseDal;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IMapper _mapper;
 
        public MaterielInfoService(IMaterielInfoRepository BaseDal, IBasicRepository basicRepository,IUnitOfWorkManage unitOfWorkManage,IMapper mapper) : base(BaseDal)
        {
            _basicRepository = basicRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _mapper = mapper;
        }
        /// <summary>
        /// 添加老厂物料信息
        /// </summary>
        /// <returns></returns>
        public WebResponseContent AddMaterial(List<BSTMaterialDTO> bSTMaterialDTOs)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_MaterielInfo> OldMaterielInfos = BaseDal.QueryData(x => x.WarehouseId == WarehouseEnum.LLDYL.ObjToInt());
                //判断重复插入
                Dt_MaterielInfo? ExistMaterial = OldMaterielInfos.FirstOrDefault(x => bSTMaterialDTOs.Where(x => x.Way == 1).Select(x => x.MaterialId).Contains(x.MaterialSourceId));
                if (ExistMaterial != null)
                {
                    return content.Error($"物料Id{nameof(BSTMaterialDTO.MaterialId)}:{ExistMaterial.MaterialSourceId}已存在");
                }
                List<Dt_MaterielInfo> materielInfos = new List<Dt_MaterielInfo>();
                foreach (var item in bSTMaterialDTOs)
                {
                    Dt_MaterielInfo materielInfo = _mapper.Map<Dt_MaterielInfo>(item);
                    materielInfos.Add(materielInfo);
                }
                BaseDal.AddData(materielInfos);
                return content.OK("接收成功");
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
 
    }
}