wangxinhui
2025-09-26 9ae0890dd74771ba9edd44d4830e0de37f8d9938
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
97
98
99
100
101
102
103
104
105
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.MaterielEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.MES;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_OutboundService
{
    public class OutMESOrderService : ServiceBase<Dt_OutMESOrder, IOutMESOrderRepository>, IOutMESOrderService
    {
        public IOutMESOrderRepository Repository => BaseDal;
        private IBasicRepository _basicRepository;
        private IStockService _stockService;
        private IOutStockLockInfoService _outStockLockInfoService;
        private IBasicService _basicService;
        private ILocationStatusChangeRecordService _locationStatusChangeRecordService;
        private readonly IMapper _mapper;
 
        public OutMESOrderService(IOutMESOrderRepository BaseDal,IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, ILocationStatusChangeRecordService locationStatusChangeRecordService,IMapper mapper) : base(BaseDal)
        {
            _basicRepository = basicRepository;
            _stockService = stockService;
            _outStockLockInfoService = outStockLockInfoService;
            _basicService = basicService;
            _locationStatusChangeRecordService = locationStatusChangeRecordService;
            _mapper = mapper;
        }
        List<string> GradeCodes = new List<string>
        {
            "001"
        };
        /// <summary>
        /// 接收MES领料计划
        /// </summary>
        /// <returns></returns>
        public WebResponseContent ReceiveOutBound(List<OutMESOrderDTO> outMESOrderDTOs)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (outMESOrderDTOs==null || outMESOrderDTOs.Count <= 0)
                {
                    return content.Error("领料计划传入信息为空");
                }
                outMESOrderDTOs.Select(x => x.OutDetailId);
                List<Dt_Warehouse> warehouses = _basicRepository.WarehouseRepository.QueryData();
                OutMESOrderDTO? CheckWarehouseCode = outMESOrderDTOs.FirstOrDefault(x => !warehouses.Select(x => x.WarehouseCode).Contains(x.WarehouseCode));
                if (CheckWarehouseCode!=null)
                {
                    return content.Error($"领料计划库区{nameof(OutMESOrderDTO.WarehouseCode)}:{CheckWarehouseCode.WarehouseCode}不存在");
                }
                OutMESOrderDTO? CheckGradeCode = outMESOrderDTOs.FirstOrDefault(x => !GradeCodes.Contains(x.GradeCode));
                if (CheckGradeCode != null)
                {
                    return content.Error($"领料计划库区{nameof(OutMESOrderDTO.GradeCode)}:{CheckGradeCode.GradeCode}不存在");
                }
                OutMESOrderDTO? CheckOutDetailId = outMESOrderDTOs.FirstOrDefault(x => x.OutDetailId <= 0);
                if (CheckOutDetailId != null)
                {
                    return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{CheckOutDetailId.ProductOrderNo}需要大于0");
                }
                OutMESOrderDTO? CheckReqQuantity = outMESOrderDTOs.FirstOrDefault(x => x.ReqQuantity <= 0);
                if (CheckReqQuantity != null)
                {
                    return content.Error($"领料计划{nameof(OutMESOrderDTO.ReqQuantity)}:{CheckReqQuantity.ProductOrderNo}需要大于0");
                }
                //获取所有物料信息
                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x=>x.MaterielInvOrgId==MaterielInvOrgEnum.新厂.ObjToInt());
                //获取所有领料计划
                List<Dt_OutMESOrder> outMESOrders = BaseDal.QueryData();
                OutMESOrderDTO? CheckMaterialCode = outMESOrderDTOs.FirstOrDefault(x=> !materielInfos.Select(x=>x.MaterielCode).Contains(x.MaterialCode));
                if (CheckMaterialCode != null)
                {
                    return content.Error($"物料编码{nameof(OutMESOrderDTO.MaterialCode)}:{CheckMaterialCode.MaterialCode}信息不存在");
                }
                Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x=> outMESOrderDTOs.Select(x=>x.OutDetailId).Contains(x.OutDetailId));
                if (OldoutMESOrder!=null)
                {
                    return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{OldoutMESOrder.OutDetailId}信息已存在");
                }
                List<Dt_OutMESOrder> outMESOrder = outMESOrderDTOs.Select(x=> _mapper.Map<Dt_OutMESOrder>(x)).ToList();
                BaseDal.AddData(outMESOrder);
                return content.OK("接收成功");
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}