schangxiang@126.com
2025-08-20 b7bb4bf8ee6d007e0e7c3cacfc4fab77049beb58
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
using iWareCc.Cache.Entity;
using iWareCc.DecomposeTask.Entity;
using iWareCc.Properties;
using iWareCommon.Common.Entity;
using iWareCommon.Utils;
using iWareDataCore.ORM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using iWareDataCore.BASE.EnumType;
 
 
namespace iWareCc.DecomposeTask.Strategy.出库任务.Chain
{
   public class 寻找满足库存条件的库位 : IHandler
    {
       private MainTaskContainer LogisticalTaskContainer;
        private PlaceContainer PlaceContainer;
        private ResultContainer ResultContainer;
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        public 寻找满足库存条件的库位(ResultContainer resultContainer, MainTaskContainer logisticalTaskContainer, PlaceContainer placeContainer)
        {
            this.ResultContainer = resultContainer;
            this.LogisticalTaskContainer = logisticalTaskContainer;
            this.PlaceContainer = placeContainer;
        }
 
        public void Handle()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    if (LogisticalTaskContainer.MainTask == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找满足库存条件的库位:{0}", "未找到待分解任务");
                        ResultContainer.Msg = "未找到待分解任务";
                        return;
                    }
 
                    var task = LogisticalTaskContainer.MainTask;
                    ///为被锁定的物料库位
                    var placeMaterial = dbModel.BASEPlaceMaterialViews.FirstOrDefault(x => x.materialcode == task.MaterialCode && x.placetypename == EPlaceType.普通库位.ToString());
 
                    if (placeMaterial == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找指定数量的物料的库位:{0}", "没有找到合适的库位");
                        ResultContainer.Msg = "没有找到合适的库位";
                        return;
                    }
                    PlaceContainer.Place = CacheEntity.Places.FirstOrDefault(x => x.Id == placeMaterial.placeid);
 
                    LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找指定数量的物料的库位:{0}", PlaceContainer.Place.Code);
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
                catch (Exception ex)
                {
                    ResultContainer.Msg = ex.Message;
                    LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "寻找指定数量的物料的库位:{0}", ex.Message);
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}