wangxinhui
昨天 c6e8b600398de38b6684f5fa1eaaaade8562859b
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
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;
        }
        /// <summary>
        /// 接收MES领料计划
        /// </summary>
        /// <returns></returns>
        public WebResponseContent ReceiveOutBound(OutMESOrderDTO outMESOrderDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (outMESOrderDTO==null)
                {
                    return content.Error("领料计划传入信息为空");
                }
                if (outMESOrderDTO.OutDetailId <= 0)
                {
                    return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{outMESOrderDTO.OutDetailId}需要大于0");
                }
                if (outMESOrderDTO.ReqQuantity <= 0)
                {
                    return content.Error($"领料计划{nameof(OutMESOrderDTO.ReqQuantity)}:{outMESOrderDTO.ReqQuantity}需要大于0");
                }
                //获取所有物料信息
                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x=>x.MaterielInvOrgId==MaterielInvOrgEnum.新厂.ObjToInt());
                //获取所有临料计划
                List<Dt_OutMESOrder> outMESOrders = BaseDal.QueryData();
                Dt_MaterielInfo? ExistmaterielInfo = materielInfos.FirstOrDefault(x=>x.MaterielCode== outMESOrderDTO.MaterialCode);
                if (ExistmaterielInfo == null)
                {
                    return content.Error($"物料编码{nameof(OutMESOrderDTO.MaterialCode)}:{outMESOrderDTO.MaterialCode}信息不存在");
                }
                Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x=>x.OutDetailId==outMESOrderDTO.OutDetailId);
                if (OldoutMESOrder!=null)
                {
                    return content.Error($"领料计划{nameof(OutMESOrderDTO.OutDetailId)}:{outMESOrderDTO.OutDetailId}信息已存在");
                }
                return content.Error($"领料计划{nameof(OutMESOrderDTO.ProductOrderNo)}:{outMESOrderDTO.ProductOrderNo},物料{outMESOrderDTO.MaterialCode}无可分配库存");
 
                Dt_OutMESOrder outMESOrder = _mapper.Map<Dt_OutMESOrder>(outMESOrderDTO);
                BaseDal.AddData(outMESOrder);
                return content.OK("接收成功");
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}