1
dengjunjie
2025-03-11 c455612b03e6ecac994884dde5b5f4bc4909c181
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core;
using WIDESEA_Model.Models;
using WIDESEAWCS_DTO.WCSInfo;
using WIDESEA_DTO.WCSInfo;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        /// <summary>
        /// 输送线申请入库
        /// </summary>
        /// <param name="lineDTO"></param>
        /// <returns></returns>
        public WebResponseContent ConveyorLineRequestInbound(ConveyorLineDTO lineDTO)
        {
            WebResponseContent content = new WebResponseContent().OK();
            try
            {
                string ConveyorLineID = AppSettings.Configuration[nameof(ConveyorLineID)];
                if (!ConveyorLineID.Split(",").Contains(lineDTO.stationCode)) throw new Exception($"未找到输送线编号[{lineDTO.stationCode}]的信息");
                content = TransmissionlineRequest(lineDTO);
            }
            catch (Exception ex)
            {
                content.Code = 404;
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// 验证数据
        /// </summary>
        /// <param name="stationCode">起始地址</param>
        /// <param name="palletCode">托盘编号</param>
        /// <param name="isCheckStock">是否检查组盘信息--区分物料入库和空托入库</param>
        /// <param name="stockInfo">组盘信息--可空</param>
        /// <returns>返回处理结果</returns>
        private (bool, string) CheckRequestInbound(string stationCode, string palletCode, bool isCheckStock = true, Dt_StockInfo? stockInfo = null)
        {
            //if (BaseDal.QueryFirst(x => x.PalletCode == palletCode) != null)
            //{
            //    return (false, "该托盘号已有任务");
            //}
            //if (BaseDal.QueryFirst(x => (x.SourceAddress == stationCode || x.CurrentAddress == stationCode) && x.TaskStatus == InTaskStatusEnum.AGV_InFinish.ObjToInt()) != null)
            //{
            //    return (false, "当前入库站台已有一条任务");
            //}
            if (isCheckStock)
            {
                if (stockInfo == null)
                {
                    return (false, "未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
                {
                    return (false, "该组盘状态不可入库");
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return (false, "该托盘已绑定货位");
                }
                if (stockInfo.Details == null || stockInfo.Details.Count == 0)
                {
                    return (false, "没有库存明细信息");
                }
            }
            else
            {
                if (_stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == palletCode) != null)
                {
                    return (false, "该托盘已存在库内");
                }
            }
 
            return (true, "成功");
        }
 
        /// <summary>
        /// 输送线申请
        /// </summary>
        /// <param name="lineDTO"></param>
        /// <returns></returns>
        public WebResponseContent TransmissionlineRequest(ConveyorLineDTO lineDTO)
        {
            WebResponseContent content = new WebResponseContent().OK();
            try
            {
                //if (BaseDal.QueryFirst(x => (x.SourceAddress == lineDTO.stationCode || x.CurrentAddress == lineDTO.stationCode) && x.TaskStatus == InTaskStatusEnum.AGV_InFinish.ObjToInt()) != null)
                //{
                //    throw new Exception($"当前入库站台[{lineDTO.stationCode}]已有一条任务");
                //}
                var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode);
                if (task == null) throw new Exception($"未找到托盘号[{lineDTO.Barcode}]的入库任务");
                if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) return content;
                if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt()) throw new Exception($"未找到托盘号[{lineDTO.Barcode}]的入库任务");
 
                //if (task.TaskState != (int)InTaskStatusEnum.AGV_InFinish) 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);
 
                Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault();
 
                if (/*lineDTO.Spec != 1 ||*/ lineDTO.Weight > 1500)//检测条件需更改!!!!!!!!!!
                {
                    //task.NextAddress = "101";
                    task.TaskState = (int)InTaskStatusEnum.InException;
                    task.Remark = $"托盘[{lineDTO.Barcode}]超重";
                    //task.Remark = $"托盘[{lineDTO.Barcode}]信息不合格";
                    //stockInfo.StockStatus = StockStatusEmun.入库撤销.ObjToInt();
                }
                else
                {
                    task.NextAddress = "1004";
                    task.CurrentAddress = lineDTO.stationCode;
                    task.Remark = string.Empty;
                    task.TaskState = (int)InTaskStatusEnum.Line_InExecuting;
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                    stockInfoDetail.Status = StockStatusEmun.入库确认.ObjToInt();
                }
 
                #region 事务
                Db.Ado.BeginTran();
                BaseDal.UpdateData(task);
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                //Db.Updateable(stockInfo).ExecuteCommand();
                Db.Ado.CommitTran();
                #endregion
                if (!string.IsNullOrEmpty(task.Remark)) throw new Exception(task.Remark);
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
    }
}