PolishExcute.cs 29.4 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
using HHECS.Application.Enums;
using HHECS.Application.Service;
using HHECS.BLL.Services;
using HHECS.BllModel;
using HHECS.Communication;
using HHECS.Communication.PLC;
using HHECS.Dal;
using HHECS.Dal.Repository;
using HHECS.DAL;
using HHECS.DAL.Repository;
using HHECS.Executor.EquipmentHandler;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;

namespace HHECS.BLL.EquipmentExcute.Machine
{
    /// <summary>
    /// 自动打磨机
    /// </summary>
    public class PolishExcute : StationExecute
    {
        int toadd = 0;
        public PolishExcute(EquipmentType equipmentType) : base(equipmentType)
        {
        }




        /// <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)
        {
            try
            {
                var arriveBarcode = station[StationProps.ArriveBarcode.ToString()];
                var number = station[StationProps.ArriveRealAddress.ToString()];
                var baseMaterialRepository = new BaseMaterialRepository();
                var busWorkOrderHeadRepository = new BusWorkOrderHeadRepository();
                var busWorkOrderDetailRepository = new BusWorkOrderDetailRepository();
                var cutPlandDilt = new CutPlanDetailRepository();
                var workOrderDetail = new BusWorkOrderDetail();
                var workOrderHead = new BusWorkOrderHead();
                string beavl = "";
                if (string.IsNullOrEmpty(arriveBarcode.Value))
                {
                    workOrderDetail = busWorkOrderDetailRepository.Where(t => t.State == (int)EnumOrderBodyStatus.初始化 && t.EquipmentCode == station.Code).OrderBy(t => t.UpdateTime).First();
                    if (workOrderDetail == null)
                    {
                        return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,没有找到符合正在运输中并且设备等于{station.Code}工位条件的工单");
                    }
                    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,没有找到符合正在运输中并且设备等于{station.Code}工位条件的工单");
                }
                else
                {
                    var convertResult = int.TryParse(arriveBarcode.Value, out int BarCode);
                    if (!convertResult)
                    {
                        return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,工序任务ID【{arriveBarcode.Value}】转化为整数失败!");
                    }
                    if (BarCode < 1)
                    {
                        return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,工序任务ID【{arriveBarcode.Value}】不能小于1!");
                    }
                    var cutplandilt = cutPlandDilt.Where(t => t.Id == BarCode).First();
                    var details = busWorkOrderDetailRepository.Where(t => t.State == (int)EnumOrderBodyStatus.初始化 && t.BarCode == cutplandilt.BarCode&& t.OprSequenceCode == "Bevel").OrderByDescending(t=>t.CreateTime).ToList();
                    if (details.Count == 0) //无需坡口
                    {
                        using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
                        {
                            try
                            {
                                BllResult sendResult = SendAckToPlc(station, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.ArriveReply, "0", "0", details.Count.ToString(), 0, 0, 0, 0, 0);
                                if (sendResult.Success)
                                {
                                    uw.Commit();
                                    //WebApiService.SendIWPTechnologylineProcess(workOrderHead.WorkOrderCode, workOrderDetail.BarCode, (int)EnumCutHeadState.打磨进行);
                                    return BllResultFactory.Success($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达成功,管段条码【{arriveBarcode.Value}】信息写入设备成功,无需坡口");
                                }
                                else
                                {
                                    uw.Rollback();
                                    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达失败,库存id【{details[0].BarCode}】信息写入设备失败,原因:{sendResult.Msg}");
                                }

                            }
                            catch (Exception ex)
                            {
                                uw.Rollback();
                                return BllResultFactory.Exception(ex, $"处理工位【{station.WorkStationCode}】的设备【{station.Name}】位置到达的时候,处理库存id【{details[0].BarCode}】信息发生异常,原因:{ex.Message}");
                            }

                        }
                    }
                    else //需要坡口
                    {
                        workOrderHead = busWorkOrderHeadRepository.Where(t => t.Keys == details[0].HeadKeys).First();
                        if (workOrderHead == null)
                        {
                            return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,找不到工单数据");
                        }
                        var material = baseMaterialRepository.Where(t => t.MaterialCode == details[0].CutMaterCode).First();
                        if (material == null)
                        {
                            return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】位置到达失败,没有找到物料");
                        }
                        if (!string.IsNullOrEmpty(details[0].ExtendComp2))
                        {
                            beavl = details[0].ExtendComp2;
                        }
                        else if (!string.IsNullOrEmpty(details[0].ExtendComp3))
                        {
                            beavl = details[0].ExtendComp3;
                        }
                        foreach (var item in details)
                        {
                            item.State = (int)EnumOrderBodyStatus.已完成;
                            item.EquipmentCode = station.Code;
                            item.StationCode = station.WorkStationCode;
                            item.UpdateBy = user.UserCode;
                            item.ActualEndTime = DateTime.Now;

                        }
                        using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
                        {
                            try
                            {
                                cutPlandDilt.UnitOfWork = uw;
                                busWorkOrderDetailRepository.UnitOfWork = uw;
                                baseMaterialRepository.UnitOfWork = uw;
                                busWorkOrderHeadRepository.UnitOfWork = uw;
                                busWorkOrderDetailRepository.Update(details);
                                BllResult sendResult = SendAckToPlc(station, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.ArriveReply, "0", "0", details.Count.ToString(), Convert.ToInt32(beavl) * 10, 0, 0, 0, 0);
                                if (sendResult.Success)
                                {
                                    uw.Commit();
                                    //WebApiService.SendIWPTechnologylineProcess(workOrderHead.WorkOrderCode, workOrderDetail.BarCode, (int)EnumCutHeadState.打磨进行);
                                    return BllResultFactory.Success($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达成功,管段条码【{arriveBarcode.Value}】信息写入设备成功,坡口数量{details.Count.ToString()},坡口角度{Convert.ToUInt32(beavl)}");
                                }
                                else
                                {
                                    uw.Rollback();
                                    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达失败,库存id【{details[0].BarCode}】信息写入设备失败,原因:{sendResult.Msg}");
                                }

                            }
                            catch (Exception ex)
                            {
                                uw.Rollback();
                                return BllResultFactory.Exception(ex, $"处理工位【{station.WorkStationCode}】的设备【{station.Name}】位置到达的时候,处理库存id【{details[0].BarCode}】信息发生异常,原因:{ex.Message}");
                            }

                        }
                    }
               
                
               
            }
            }
            catch (Exception ex)
            {
                return BllResultFactory.Exception(ex, $"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达失败时候,异常原因:{ex.Message}");
            }
        }

        /// <summary>
        /// 执行地址请求,余料和废料不请求,切割机直接翻到切割下料台
        /// 注意:allEquipments引用所有设备,此为共享应用
        /// </summary>
        /// <param name="station"></param>
        /// <param name="allEquipments"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public override BllResult ExcuteRequest(Equipment station, List<Equipment> allEquipments, PLCCore plc, User user)
        {
            try
            {
                var arriveBarcode = station[StationProps.RequestBarcode.ToString()];

                var baseMaterialRepository = new BaseMaterialRepository();
                var busWorkOrderHeadRepository = new BusWorkOrderHeadRepository();
                var busWorkOrderDetailRepository = new BusWorkOrderDetailRepository();
                var cutPlandDilt = new CutPlanDetailRepository();
                var workOrderDetail = new BusWorkOrderDetail();
                var workOrderHead = new BusWorkOrderHead();
                string beavl = "";
                if (string.IsNullOrEmpty(arriveBarcode.Value))
                {
                    //workOrderDetail = busWorkOrderDetailRepository.Where(t => t.State == (int)EnumOrderBodyStatus.初始化 && t.EquipmentCode == station.Code).OrderBy(t => t.UpdateTime).First();
                    //if (workOrderDetail == null)
                    //{
                    //    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,没有找到符合正在运输中并且设备等于{station.Code}工位条件的工单");
                    //}
                    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,arriveBarcode为空");
                }
                else
                {
                    var convertResult = int.TryParse(arriveBarcode.Value, out int BarCode);
                    if (!convertResult)
                    {
                        return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,工序任务ID【{arriveBarcode.Value}】转化为整数失败!");
                    }
                    if (BarCode < 1)
                    {
                        return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,工序任务ID【{arriveBarcode.Value}】不能小于1!");
                    }
                    var cutplandilt = cutPlandDilt.Where(t => t.Id == BarCode).First();
                    var details = busWorkOrderDetailRepository.Where(t => t.State == (int)EnumOrderBodyStatus.初始化 && t.BarCode == cutplandilt.BarCode && t.OprSequenceCode == "Bevel").OrderByDescending(t => t.CreateTime).ToList();
                    if (details.Count == 0) //无需坡口
                    {
                        using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
                        {
                            try
                            {
                               // var cutplandilt = cutPlandDilt.Where(t => t.Id.ToString() == arriveBarcode.Value).OrderByDescending(t => t.CreateTime).ToList();
                                var busworkdi = busWorkOrderDetailRepository.Where(t => t.BarCode == cutplandilt.BarCode && t.OprSequenceCode == "Cut" && t.State == 0).OrderByDescending(t => t.CreateTime).ToList();
                                if (cutplandilt == null)
                                {
                                    return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,没有找到切割明细");
                                }
                                //cutplandilt[0].CutState = (int)CutPlanDetailState.切割完成;
                                var cutplanhead = busWorkOrderHeadRepository.Where(t => t.Keys == cutplandilt.HeadKeys).First();
                                if (cutplanhead == null)
                                {
                                    return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,没有找到切割主表明细");
                                }
                                var materl = baseMaterialRepository.Where(t => t.MaterialCode == cutplanhead.MaterielCode).First();
                                if (materl == null)
                                {
                                    return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,没有找到物料明细");
                                }


                                var sendResult = NewSendAddressReplyToPlc(station, plc, StationMessageFlag.WCSAddressReply, StationLoadStatus.Default, "0", "0", "0", "0", "0", "0", Convert.ToInt32(cutplandilt.Cuttinglength), Convert.ToInt32(materl.Diameter), Convert.ToInt32(materl.Thickness));
                               // BllResult sendResult = SendAckToPlc(station, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.ArriveReply, "0", "0", details.Count.ToString(), 0, 0, 0, 0, 0);
                                if (sendResult.Success)
                                {
                                    uw.Commit();
                                    //WebApiService.SendIWPTechnologylineProcess(workOrderHead.WorkOrderCode, workOrderDetail.BarCode, (int)EnumCutHeadState.打磨进行);
                                    return BllResultFactory.Success($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达成功,管段条码【{arriveBarcode.Value}】信息写入设备成功,无需坡口");
                                }
                                else
                                {
                                    uw.Rollback();
                                    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达失败,库存id【{details[0].BarCode}】信息写入设备失败,原因:{sendResult.Msg}");
                                }

                            }
                            catch (Exception ex)
                            {
                                uw.Rollback();
                                return BllResultFactory.Exception(ex, $"处理工位【{station.WorkStationCode}】的设备【{station.Name}】位置到达的时候,处理库存id【{details[0].BarCode}】信息发生异常,原因:{ex.Message}");
                            }

                        }
                    }
                    else //需要坡口
                    {
                        workOrderHead = busWorkOrderHeadRepository.Where(t => t.Keys == details[0].HeadKeys).First();
                        if (workOrderHead == null)
                        {
                            return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】 位置到达失败,找不到工单数据");
                        }
                        var material = baseMaterialRepository.Where(t => t.MaterialCode == details[0].CutMaterCode).First();
                        if (material == null)
                        {
                            return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】的设备【{station.Name}】位置到达失败,没有找到物料");
                        }
                        if (!string.IsNullOrEmpty(details[0].ExtendComp2))
                        {
                            beavl = details[0].ExtendComp2;
                        }
                        else if (!string.IsNullOrEmpty(details[0].ExtendComp3))
                        {
                            beavl = details[0].ExtendComp3;
                        }
                        foreach (var item in details)
                        {
                            item.State = (int)EnumOrderBodyStatus.已完成;
                            item.EquipmentCode = station.Code;
                            item.StationCode = station.WorkStationCode;
                            item.UpdateBy = user.UserCode;
                            item.ActualEndTime = DateTime.Now;

                        }
                        using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
                        {
                            try
                            {
                                cutPlandDilt.UnitOfWork = uw;
                                busWorkOrderDetailRepository.UnitOfWork = uw;
                                baseMaterialRepository.UnitOfWork = uw;
                                busWorkOrderHeadRepository.UnitOfWork = uw;
                                busWorkOrderDetailRepository.Update(details);
                                BllResult sendResult = SendAckToPlc(station, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.ArriveReply, "0", "0", details.Count.ToString(), Convert.ToInt32(beavl) * 10, 0, 0, 0, 0);
                                if (sendResult.Success)
                                {
                                    uw.Commit();
                                    //WebApiService.SendIWPTechnologylineProcess(workOrderHead.WorkOrderCode, workOrderDetail.BarCode, (int)EnumCutHeadState.打磨进行);
                                    return BllResultFactory.Success($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达成功,管段条码【{arriveBarcode.Value}】信息写入设备成功,坡口数量{details.Count.ToString()},坡口角度{Convert.ToUInt32(beavl)}");
                                }
                                else
                                {
                                    uw.Rollback();
                                    return BllResultFactory.Error($"处理工位【{station.WorkStationCode}】设备【{station.Name}】位置到达失败,库存id【{details[0].BarCode}】信息写入设备失败,原因:{sendResult.Msg}");
                                }

                            }
                            catch (Exception ex)
                            {
                                uw.Rollback();
                                return BllResultFactory.Exception(ex, $"处理工位【{station.WorkStationCode}】的设备【{station.Name}】位置到达的时候,处理库存id【{details[0].BarCode}】信息发生异常,原因:{ex.Message}");
                            }

                        }
                    }








                    //var number = station[StationProps.ArriveRealAddress.ToString()];
                    //var baseMaterialRepository = new BaseMaterialRepository();
                    //var cutPlanHeadRepository = new CutPlanHeadRepository();
                    //var cutPlandDilt = new CutPlanDetailRepository();
                    //var BusWorkOrderDetail = new BusWorkOrderDetailRepository();
                    //int gotoadd;
                    //int gotadd;
                    //if (string.IsNullOrEmpty(arriveBarcode.Value))
                    //{
                    //    return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】下料条码{arriveBarcode.Value}为空请求失败,切割方案");
                    //}
                    //else
                    //{
                    //    var cutplandilt = cutPlandDilt.Where(t => t.Id.ToString() == arriveBarcode.Value).OrderByDescending(t => t.CreateTime).ToList();
                    //    var busworkdi = BusWorkOrderDetail.Where(t => t.BarCode == cutplandilt[0].BarCode && t.OprSequenceCode == "Cut" && t.State == 0).OrderByDescending(t => t.CreateTime).ToList();
                    //    if (cutplandilt == null)
                    //    {
                    //        return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,没有找到切割明细");
                    //    }
                    //    //cutplandilt[0].CutState = (int)CutPlanDetailState.切割完成;
                    //    var cutplanhead = cutPlanHeadRepository.Where(t => t.Keys == cutplandilt[0].HeadKeys).First();
                    //    if (cutplanhead == null)
                    //    {
                    //        return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,没有找到切割主表明细");
                    //    }
                    //    var materl = baseMaterialRepository.Where(t => t.MaterialCode == cutplanhead.MaterialCode).First();
                    //    if (materl == null)
                    //    {
                    //        return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,没有找到物料明细");
                    //    }
                    //    using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
                    //    {
                    //        cutPlandDilt.UnitOfWork = uw;
                    //        BusWorkOrderDetail.UnitOfWork = uw;
                    //        //var planhead = cutPlanHeadRepository.Where(t => t.Keys == cutplandilt[0].HeadKeys).First();

                    //        //var busworkorderdetail = BusWorkOrderDetail.Where(t => t.BodyKeys == cutplandilt[0].WorkOrderDetailKeys && t.OprSequenceName == "弯管" && t.State!=100).First();//如果存在弯管的给目的地为弯管机
                    //        if (string.IsNullOrEmpty(cutplandilt[0].Extend2))
                    //        {
                    //            if (busworkdi.Count != 0)
                    //            {
                    //                busworkdi[0].State = 100;
                    //                busworkdi[0].UpdateTime = DateTime.Now;
                    //                BusWorkOrderDetail.Update(busworkdi);
                    //            }
                    //            //gotadd = Convert.ToInt32(cutplandilt[0].Extend2);
                    //            //cutplandilt[0].UpdateTime = DateTime.Now;
                    //            //cutplandilt[0].CutEndTime = DateTime.Now;
                    //            //cutPlandDilt.Update(cutplandilt);
                    //            var sendResult = NewSendAddressReplyToPlc(station, plc, StationMessageFlag.WCSAddressReply, StationLoadStatus.Default, "0", "0", "0", "0", "0", "0", Convert.ToInt32(cutplandilt[0].Cuttinglength), Convert.ToInt32(materl.Diameter), Convert.ToInt32(materl.Thickness));
                    //            if (sendResult.Success)
                    //            {
                    //                //WebApiService.Layingoff(cutplandilt[0].BarCode, gotadd.ToString());//告诉mes在哪下料
                    //                uw.Commit();
                    //                return BllResultFactory.Success($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求成功,工单id【{cutplandilt[0].Id}】信息写入设备成功,管段长度{cutplandilt[0].Cuttinglength},管径{materl.Diameter},壁厚{materl.Thickness}");
                    //            }
                    //            else
                    //            {
                    //                uw.Rollback();
                    //                return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,工单id【{cutplandilt[0].Id}】信息写入设备失败,原因:{sendResult.Msg}");
                    //            }
                    //        }
                    //        else
                    //        {
                    //            if (busworkdi.Count != 0)
                    //            {
                    //                busworkdi[0].State = 100;
                    //                busworkdi[0].UpdateTime = DateTime.Now;
                    //                busworkdi[0].StationCode = toadd.ToString();
                    //                BusWorkOrderDetail.Update(busworkdi);
                    //            }
                    //            //cutplandilt[0].Extend2 = toadd.ToString();
                    //            //cutplandilt[0].UpdateTime = DateTime.Now;
                    //            //cutplandilt[0].CutEndTime = DateTime.Now;
                    //            //cutPlandDilt.Update(cutplandilt);
                    //            var sendResult = NewSendAddressReplyToPlc(station, plc, StationMessageFlag.WCSAddressReply, StationLoadStatus.Default, "0", "0", "0", "0", "0", "0",Convert.ToInt32(cutplandilt[0].Cuttinglength), Convert.ToInt32(materl.Diameter), Convert.ToInt32(materl.Thickness));
                    //            if (sendResult.Success)
                    //            {
                    //                //WebApiService.Layingoff(cutplandilt[0].BarCode, toadd.ToString());//告诉mes在哪下料
                    //                uw.Commit();
                    //                return BllResultFactory.Success($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求成功,工单id【{cutplandilt[0].Id}】信息写入设备成功,管段长度{cutplandilt[0].Cuttinglength},管径{materl.Diameter},壁厚{materl.Thickness}");
                    //            }
                    //            else
                    //            {
                    //                uw.Rollback();
                    //                return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,工单id【{cutplandilt[0].Id}】信息写入设备失败,原因:{sendResult.Msg}");
                    //            }
                    //        }

                    //var pland = cutPlandDilt.Where(t => t.HeadKeys == cutplandilt[0].HeadKeys && t.CutState == (int)CutPlanDetailState.切割开始).ToList();
                    //if (pland.Count == 0)
                    //{
                    //    cutPlanHeadRepository.UnitOfWork = uw;
                    //    planhead.State = (int)CutPlanHeadState.切割完成;
                    //    planhead.UpdateTime = DateTime.Now;
                    //    cutPlanHeadRepository.Update(planhead);
                    //var sendResult = SendAddressReplyToPlc(station, plc, StationMessageFlag.WCSAddressReply, StationLoadStatus.Default, "0", "0", "0", cutplandilt[0].Cuttinglength.ToString(), "0", "0", toadd.ToString(), "0");
                    //if (sendResult.Success)
                    //{
                    //    WebApiService.SurpplusRecord(planhead.Id.ToString());
                    //    uw.Commit();
                    //    return BllResultFactory.Success($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求成功,工单id【{cutplandilt[0].Id}】信息写入设备成功,Mes请求余料信息{planhead.Keys},主表id{planhead.Id}");
                    //}
                    //else
                    //{
                    //    uw.Rollback();
                    //    return BllResultFactory.Error($"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,工单id【{cutplandilt[0].Id}】信息写入设备失败,原因:{sendResult.Msg}");
                    //}
                    //}

                }
           
            }
            catch (Exception ex)
            {
                return BllResultFactory.Exception(ex, $"处理切割工位【{station.WorkStationCode}】设备【{station.Name}】地址请求失败,异常原因:{ex.Message}");
            }

        }
    }
}