2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
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
using iWareCc.Conveyor.EnumType;
using iWareCc.DecomposeTask.Entity;
using iWareCc.Properties;
using iWareCommon.Common.Entity;
using iWareCommon.Common.EnumType;
using iWareCommon.Utils;
using iWareDataCore.ORM;
using iWareDataCore.TASK.Entity;
using iWareDataCore.TASK.EnumType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.CreateOutMainTask.chain
{
    public class 生成出库主任务: IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private MainTaskContainer MainTaskContainer;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="resultContainer">结果容器</param>
        /// <param name="decompositionTaskContainer">WIP任务容器</param>
        public 生成出库主任务( MainTaskContainer mainTaskContainer)
        {
            this.MainTaskContainer = mainTaskContainer;
        }
 
 
        public void Handle()
        {
 
            using (var dbModel = new DbModelCore())
            {
                try
                {
 
            
                    var inoutlistdetail = dbModel.BASEInOutListDetailViews.FirstOrDefault(x =>x.isfinish== 0&&x.typename=="出库");
                    if (inoutlistdetail == null)
                    {
 
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成出库主任务流程", "在出库批次中未找到要出库的任务");
                        return;
                    }
                    string materialcode = inoutlistdetail.materialcode;
                    var placematerial = dbModel.BASEPlaceMaterialViews.FirstOrDefault(x => x.materialcode == materialcode);
                    if (placematerial == null)
                     {
                         inoutlistdetail.isfinish = 1;
                         dbModel.SaveChanges();
                                     // alarm.SendGateAlarmTask((int)ESendCode.已在立库中不能入库);
                         LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成出库主任务流程", "物料号:{0}", materialcode + "不在立库中");
                        return;
                     }
                    var tasknew = dbModel.TASKPartTasks.FirstOrDefault(x => x.type == (int)EPartTaskType.输送机任务 && x.isreleased == (int)EYesOrNo.否 && x.isfinished == (int)EYesOrNo.否 && x.materialcode == materialcode && x.maintasktype == (int)EMainTaskType.出库任务);
                    if (tasknew != null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成出库主任务流程", "物料号:{0}", materialcode + "已在要执行的任务序列中");
                          return;
                    }
                    var task = dbModel.TASKMainTasks.FirstOrDefault(x => x.materialcode == materialcode && x.tasktype == (int)EMainTaskType.出库任务&&x.status == 0);
                    if (task != null)
                    {
                       LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成出库主任务流程", "物料号:{0}", "该任务已存在");
                       return;
                    }
                    TASKMainTask matask = new TASKMainTask()
                    {
                        taskno = DateTime.Now.ToFileTime().ToString(),
                        tasktype = (int)EMainTaskType.出库任务,
                        materialcode = materialcode,
                        syscode = "1",
                        sendtime = DateTime.Now,
                        sourceplace = "100101",
                        toplace = inoutlistdetail.placecode,
                        packageno = "",
                        processcardnumber = "",
                        quantity = 1,
                        status = 0,
                        decompositiontime = DateTime.Now,
                        wipstatus = 0,
                        decompositiontimes = 0,
                        islots = 0,
                        priority = 0,
                    };
                    MainTaskContainer.MainTask = new MainTaskEntity(matask);
       
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
 
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}