VerticalFitup.cs
10.2 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using HHECS.Application.Enums;
using HHECS.BllModel;
using HHECS.Communication;
using HHECS.DAL.Repository;
using HHECS.Dal;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using HHECS.Application.Error;
using System.Linq;
using HHECS.Dal.Repository;
using HHECS.Communication.PLC;
namespace HHECS.Executor.EquipmentHandler.Machine
{
/// <summary>
/// 立式组队
/// </summary>
public class VerticalFitup : StationExecute
{
/// <summary>
///
/// </summary>
/// <param name="timeSpace"></param>
/// <param name="origin"></param>
/// <param name="referer"></param>
/// <param name="sendNoneGoodsPointsUrl"></param>
public VerticalFitup(EquipmentType equipmentType, string origin, string referer, string sendNoneGoodsPointsUrl) : base(equipmentType)
{
this.origin = origin;
this.referer = referer;
this.callMaterialUrl = sendNoneGoodsPointsUrl;
}
/// <summary>
/// 地址请求的处理
/// 注意:allEquipments引用所有设备,此为共享应用
/// </summary>
/// <param name="station"></param>
/// <param name="allEquipments"></param>
/// <param name="plc"></param>
/// <returns></returns>
public override BllResult ExcuteArrive(Equipment station, List<Equipment> allEquipments, PLCCore plc, User user)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,没有到达处理方法!");
}
public override BllResult ExcuteRequest(Equipment station, List<Equipment> allEquipments, PLCCore plc, User user)
{
try
{
//检查运输设备是否可用
var checkResult = CheckTransportEquipment(station, allEquipments);
if (!checkResult.Success) return checkResult;
//从当前设备获取工件类型
var requestProductType = station[StationProps.RequestProductType.ToString()];
var productTypeResult = int.TryParse(requestProductType.Value, out int wcsProductType);
if (!productTypeResult)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 地址请求失败,工件型号[{requestProductType.Value}]转化为整数失败!");
}
if (wcsProductType < 1)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 地址请求失败,工件型号[{requestProductType.Value}]不能小于1!");
}
//根据工件类型,获取产品信息
var productHeaderRepository = new BaseProductHeaderRepository();
var productHeader = productHeaderRepository.Where(t => t.WcsProductType == wcsProductType).First();
if (productHeader == null)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 地址请求失败,根据工件型号【{requestProductType.Value}】,找不到对应的产品,请核对产品数据!");
}
var workCenterStationRelRepository = new BaseWorkCenterStationRelRepository();
var workCenterCode = workCenterStationRelRepository.Where(t => t.WorkStationCode == station.WorkStationCode).First(t => t.WorkCenterCode);
if (workCenterCode == null)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 地址请求失败,根据工位编码【{station.WorkStationCode}】,找不到工作中心,请检查工作中心、工位关联表!");
}
var init = (int)EnumOrderBodyStatus.初始化;
var finished = (int)EnumOrderBodyStatus.已完成;
var workOrderDetailRepository = new BusWorkOrderDetailRepository();
//找到当前工序任务明细
var currentWorkOrderDetail = workOrderDetailRepository.Where(t => t.ProductHeaderCode == productHeader.ProductCode && t.WorkCenterCode == workCenterCode && t.State == init).First();
if (currentWorkOrderDetail == null)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 地址请求失败,根据工件型号【{requestProductType.Value}】,找不到【初始化或者在当前工位、且未完成】的工序任务明细!");
}
//找出下一个工序任务明细
var nextWorkOrderDetail = workOrderDetailRepository.Where(t => t.HeadKeys == currentWorkOrderDetail.HeadKeys &&
t.State < finished && t.SerialNumber > currentWorkOrderDetail.SerialNumber).First();
var workOrderDetails = new List<BusWorkOrderDetail>();
workOrderDetails.Add(currentWorkOrderDetail);
if (nextWorkOrderDetail != null)
{
workOrderDetails.Add(nextWorkOrderDetail);
}
var workOrderHeadRepository = new BusWorkOrderHeadRepository();
//获取对应的工序任务头
var workOrderHead = workOrderHeadRepository.Where(t => t.Keys == currentWorkOrderDetail.HeadKeys).First();
if (workOrderHead == null)
{
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】 地址请求失败,找不到工序任务头KEY[{currentWorkOrderDetail.HeadKeys}]的数据");
}
//获取所有能去的下一个工序的设备列表
var allowEntryEquipmentResult = GetNextAllowEntryEquipment(station, allEquipments, workOrderDetails.Last());
//根据料点关系表返会任务起点和终点点位
//var allowEntryEquipmentResult = GetNextAllowEntryEquipmentForLocationRel(station, allEquipments, workOrderDetails.Last());
if (!allowEntryEquipmentResult.Success) return allowEntryEquipmentResult;
//生成运输任务
var transportTaskResult = CreateTransportTask(station, allEquipments, allowEntryEquipmentResult.Data, wcsProductType, workOrderHead, user);
if (!transportTaskResult.Success) return transportTaskResult;
var transportTask = transportTaskResult.Data;
//设置工序任务实体
SetWorkOrder(station, workOrderHead, workOrderDetails, transportTask, user);
var requestNumber = station[StationProps.RequestNumber.ToString()];
using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
{
try
{
workOrderDetailRepository.UnitOfWork = uw;
workOrderHeadRepository.UnitOfWork = uw;
//如果生成了桁车任务,就写入桁车任务表
if (transportTask.BusTaskTruss != null)
{
var taskTrussEntityRepository = new BusTaskTrussRepository();
taskTrussEntityRepository.UnitOfWork = uw;
taskTrussEntityRepository.Insert(transportTask.BusTaskTruss);
}
//如果生成了AGV任务,就写入桁车任务表
if (transportTask.BusAGVTask != null)
{
var busAGVTaskRepository = new BusAGVTaskRepository();
busAGVTaskRepository.UnitOfWork = uw;
busAGVTaskRepository.Insert(transportTask.BusAGVTask);
}
//更新工序任务明细表
workOrderDetailRepository.Update(workOrderDetails);
//更新工序任务头表
workOrderHeadRepository.Update(workOrderHead);
//响应设备
var sendResult = SendAddressReplyToPlc(station, plc, StationMessageFlag.WCSAddressReply, StationLoadStatus.Default, requestNumber.Value,
workOrderHead.Id.ToString(), transportTask.ToEquipment.SelfAddress, "", "0", "0", "0", "0");
if (sendResult.Success)
{
uw.Commit();
return BllResultFactory.Success($"工位【{station.WorkStationCode}】的设备【{station.Name}】地址请求成功,工序任务ID【{workOrderHead.Id}】信息以及下个设备【{transportTask.ToEquipment.SelfAddress}】的地址写入PLC成功!");
}
else
{
uw?.Rollback();
return BllResultFactory.Error($"工位【{station.WorkStationCode}】的设备【{station.Name}】地址请求失败,工序任务ID【{workOrderHead.Id}】的信息写入PLC失败,原因:{sendResult.Msg}");
}
}
catch (Exception ex)
{
uw?.Rollback();
return BllResultFactory.Create(BllResultCode.Exception, ex, "$工位【{station.WorkStationCode}】的设备【{station.Name}】地址请求的时候,处理工序任务ID【{workOrderHead.Id}】发生异常,原因:{ex.Message}", ErrorCodeConst.Exe_E0001.ToString());
}
}
}
catch (Exception ex)
{
return BllResultFactory.Create(BllResultCode.Exception, ex, $"工位【{station.WorkStationCode}】的设备【{station.Name}】地址请求时候,发生异常:{ex.Message}", ErrorCodeConst.Exe_E0001.ToString());
}
}
}
}