1
dengjunjie
2025-05-08 092971a8ba7848f024427694c642959d0fbc8599
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Magicodes.IE.Core;
using MailKit.Search;
using System;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.WCSInfo;
using WIDESEA_Model.Models;
using WIDESEAWCS_DTO.WCSInfo;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
 
        /// <summary>
        /// 产线申请
        /// </summary>
        /// <param name="productionlineDTO"></param>
        /// <returns></returns>
        public WebResponseContent ProductionlineRequest(ProductionlineDTO productionlineDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(productionlineDTO.Barcode);
                if (stockInfo != null) throw new Exception($"托盘【{productionlineDTO.Barcode}】已存在库存信息");
                stockInfo = new Dt_StockInfo();
                stockInfo.Details = new List<Dt_StockInfoDetail>();
                #region MyRegion
                string OrderNo = productionlineDTO.batchNo.Substring(0, 8);// DateTime.Now.ToString("yyMMdd");
                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(OrderNo);
                if (inboundOrder == null) throw new Exception($"未找到批号为【{OrderNo}】的入库单");
                //var BatchNo = string.Join("", productionlineDTO.batchNo.Except(OrderNo));
                var BatchNo = productionlineDTO.batchNo.Substring(8);
                Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.Where(x => x.BatchNo == BatchNo).FirstOrDefault();
                if (inboundOrderDetail == null) throw new Exception($"批号【{OrderNo}】的入库单未找到柜号【{BatchNo}】");
                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1) throw new Exception($"批号【{OrderNo}】的柜号【{BatchNo}】可组盘数量不足");
 
                Dt_Task dt_Task = new Dt_Task()
                {
                    CurrentAddress = productionlineDTO.stationCode,
                    NextAddress = "SC01",
                    SourceAddress = productionlineDTO.stationCode,
                    TargetAddress = "SC01",
                    Creater = "System",
                    PalletCode = productionlineDTO.Barcode,
                    Roadway = "SC01",
                    OrderNo = productionlineDTO.batchNo,// inboundOrder.OrderNo,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    CreateDate = DateTime.Now,
                    Dispatchertime = DateTime.Now,
                };
 
                productionlineDTO.batchNo = BatchNo;
                content = _stockService.StockInfoService.AddStockInfo(ref stockInfo, ref inboundOrder, productionlineDTO);
                if (!content.Status) throw new Exception(content.Message);
                Db.Ado.BeginTran();
                _inboundService.InbounOrderService.UpdateDataWithDetail(inboundOrder);
                _stockService.StockInfoService.AddMaterielGroup(stockInfo);
                AddData(dt_Task);
                content.OK(data: dt_Task);
                Db.Ado.CommitTran();
                #endregion
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// 产线申请
        /// </summary>
        /// <param name="lineDTO"></param>
        /// <returns></returns>
        public WebResponseContent ProductionlineRequest(ConveyorLineDTO lineDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode);
                if (task != null && task.TaskType == TaskTypeEnum.Inbound.ObjToInt())
                    return content.OK(data: task);
                if (task != null) throw new Exception($"托盘号[{lineDTO.Barcode}]已存在任务");
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode);
                (bool, string) result = CheckRequestInbound(lineDTO.stationCode, lineDTO.Barcode, true, stockInfo);
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                var StockInfoDetails = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).ToList();
                #region 生成入库任务
                Dt_Task dt_Task = new Dt_Task()
                {
                    CurrentAddress = lineDTO.stationCode,
                    NextAddress = "SC01",
                    SourceAddress = lineDTO.stationCode,
                    TargetAddress = "SC01",
                    CreateDate = DateTime.Now,
                    Creater = "System",
                    PalletCode = lineDTO.Barcode,
                    OrderNo = StockInfoDetails.Count() == 1 ? StockInfoDetails.First().OrderNo : null,
                    Roadway = "SC01",
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                };
                dt_Task.Dispatchertime = dt_Task.CreateDate;
                Db.Ado.BeginTran();
                BaseDal.AddData(dt_Task);
                task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt());
                //content.Data = dt_Task;
                Db.Ado.CommitTran();
                if (task != null) return content.OK(data: task);
                #endregion
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
    }
}