Init.cs 51.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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
using RCS.Dal;
using RCS.Model.Comm;
using RCS.Model.Entity;
using RCS.Model.PLC;
using RCS.WinClient.PLC;
using RCS.WinClient.Service;
using SqlSugar;
using System.Collections.ObjectModel;
using System.Data;
using System.Drawing;


namespace RCS.WinClient.Common
{
    public class Init
    {
        private static BaseDal<Base_Point> _pointDb = new BaseDal<Base_Point>();
        private static BaseDal<Base_Point> _demoPointDb = new BaseDal<Base_Point>();
        private static BaseDal<Base_Task> _taskDb = new BaseDal<Base_Task>();
        private static BaseDal<Base_SubTask> _sonTaskDb = new BaseDal<Base_SubTask>();
        private static BaseDal<Base_PathPoint> _pathPointDb = new BaseDal<Base_PathPoint>();
        private static BaseDal<Base_Agv> _agvDb = new BaseDal<Base_Agv>();
        private static BaseDal<Base_Station> _stationDb = new BaseDal<Base_Station>();
        private static BaseDal<Config_TaskSplit> _taskSplitDb = new BaseDal<Config_TaskSplit>();
        private static BaseDal<Config_ErrMsg> _errMsgDb = new BaseDal<Config_ErrMsg>();
        private static BaseDal<Config_KeyValue> _keyValueDb = new BaseDal<Config_KeyValue>();
        private static BaseDal<Config_TaskAgvGroup> _taskAgvGroupDb = new BaseDal<Config_TaskAgvGroup>();
        private static BaseDal<Config_Point> _cgPointDb = new BaseDal<Config_Point>();
        private static BaseDal<Base_Loction> _loctionDb = new BaseDal<Base_Loction>();
        private static BaseDal<Base_Equipment> _equipmentDb = new BaseDal<Base_Equipment>();
        private static BaseDal<Base_EquipmentProp> _equipmentPropDb = new BaseDal<Base_EquipmentProp>();
        private static BaseDal<Log_AgvErrMsg> _logErrMsgDb = new BaseDal<Log_AgvErrMsg>();
        private static BaseDal<ProtocolDetail> _protocolDetail = new();
        private static BaseDal<Protocol> _protocol = new();
        public static BllResult InitData()
        {
            var pointresult = DownPoint();
            if (!pointresult.IsSuccess)
            {
                return BllResult.Error($"初始化点位信息异常;{pointresult.Message}");
            }
            var tasksplitresult = DownTaskSplit();
            if (!tasksplitresult.IsSuccess)
            {
                return BllResult.Error($"初始化任务分解信息异常{tasksplitresult.Message}");
            }

            var taskresult = DownTask();
            if (!taskresult.IsSuccess)
            {
                return BllResult.Error($"初始化任务信息异常;{taskresult.Message}");
            }

            var stationresult = DownStation();
            if (!stationresult.IsSuccess)
            {
                return BllResult.Error($"初始化站台信息异常{stationresult.Message}");
            }

            var sontaskresult = DownSonTask();
            if (!sontaskresult.IsSuccess)
            {
                return BllResult.Error($"初始化子任务信息异常{sontaskresult.Message}");
            }

            var agvresult = DownAgv();
            if (!agvresult.IsSuccess)
            {
                return BllResult.Error($"初始化AGV信息异常{agvresult.Message}");
            }

            var pathresult = DownPath();
            if (!pathresult.IsSuccess)
            {
                return BllResult.Error($"初始化路径信息异常{pathresult.Message}");
            }


            var errmsgresult = DownErrMsg();
            if (!errmsgresult.IsSuccess)
            {
                return BllResult.Error($"初始化异常信息异常{errmsgresult.Message}");
            }

            var taskagvgroup = DownTaskAgvGroup();
            if (!taskagvgroup.IsSuccess)
            {
                return BllResult.Error($"初始化小车绑定任务群组信息异常{taskagvgroup.Message}");
            }

            var keyvalueresult = DownKeyValue();
            if (!keyvalueresult.IsSuccess)
            {
                return BllResult.Error($"初始化电量配置信息异常{keyvalueresult.Message}");
            }

            var cgpointresult = DownConfigPoint();
            if (!cgpointresult.IsSuccess)
            {
                return BllResult.Error($"初始化特殊点配置信息异常{cgpointresult.Message}");
            }

            var loctionresult = DownLoction();
            if (!loctionresult.IsSuccess)
            {
                return BllResult.Error($"初始化料点配置信息异常{loctionresult.Message}");
            }

            var equipmentResult = InitEquipment();
            if (!equipmentResult.IsSuccess)
            {
                return BllResult.Error($"初始化设备信息异常{equipmentResult.Message}");
            }

            var errorRes = DownErrorInfo();
            if (!errorRes.IsSuccess)
            {
                return BllResult.Error($"初始化异常信息异常:{errorRes.Message}");
            }
            var protocolRes = DownProtocolInfo();
            if (!protocolRes.IsSuccess)
            {
                return BllResult.Error($"初始化异常信息异常:{protocolRes.Message}");
            }
            return BllResult.Success();
        }

        /// <summary>
        /// 下载点位信息(t_base_point表)
        /// </summary>
        /// <param name="errMsg"></param>
        public static BllResult DownPoint()
        {
            var pointResult = _pointDb.Query(x => x.AreaType == App.AppConfig.MapName);

            if (!pointResult.IsSuccess)
            {
                if (pointResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化点位信息异常;{pointResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }
            foreach (var _point in pointResult.Data)
            {
                _point.TmpDirectionList = new List<TmpDirection>();
                App.PointList.Add(_point);
            }

            #region 临时注释

            //string sql = string.Format("SELECT * FROM T_Base_Point");
            //DataSet ds = DbHelperSQL.Query(sql);
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Point point = new Point();
            //    point.strBarcode = dr["strBarcode"].ToString();
            //    point.AreaType = dr["pointAreaType"].ToString();
            //    point.pointType = (EnumMsg.PointType) int.Parse(dr["pointType"].ToString());
            //    point.intX = int.Parse(dr["intX"].ToString());
            //    point.intY = 1000 - int.Parse(dr["intY"].ToString());
            //    point.isXPos = dr["isXPos"].ToString() == "0" ? false : true;
            //    point.isXNeg = dr["isXNeg"].ToString() == "0" ? false : true;
            //    point.isYPos = dr["isYNeg"].ToString() == "0" ? false : true;
            //    point.isYNeg = dr["isYPos"].ToString() == "0" ? false : true;
            //    point.intXLength = int.Parse(dr["intXLength"].ToString());
            //    point.intYLength = int.Parse(dr["intYLength"].ToString());
            //    point.oriAgv = (EnumMsg.OriType) int.Parse(dr["OriAgv"].ToString());
            //    point.oriDial = (EnumMsg.OriDial) int.Parse(dr["OriDial"].ToString());
            //    point.isEnable = dr["isEnable"].ToString() == "0" ? false : true;
            //    point.isOccupy = dr["isOccupy"].ToString() == "0" ? false : true;
            //    point.strOccupyAgvNo = dr["strOccupyAgvNo"].ToString();
            //    point.strRegionName = dr["strRegionName"].ToString();
            //    point.stopTime = int.Parse(dr["stopTime"].ToString());
            //    point.strPreBarcode = dr["strPreBarcode"].ToString();
            //    point.intStopLevel = int.Parse(dr["intStopLevel"].ToString());
            //    point.isStop = dr["isStop"].ToString() == "0" ? false : true;
            //    point.tmpDirectionList = new List<TmpDirection>();
            //    point.lockedAgv = null;
            //    App.PointList.Add(point);
            //}

            #endregion 临时注释

            #region 赋值每个点位的四周点

            foreach (Base_Point point in App.PointList)
            {
                int xPos = 1;
                int xNeg = 1;
                int yPos = 1;
                int yNeg = 1;

                #region 搜索X正方向临近点

                for (int i = point.IntX;
                    i < App.PointList.FindAll(a => a.AreaType == point.AreaType).Max(a => a.IntX);
                    i++)
                {
                    point.XPosPoint = App.PointList.Find(a =>
                        a.IntX == point.IntX + xPos && a.IntY == point.IntY && a.AreaType == point.AreaType);
                    if (point.XPosPoint == null)
                    {
                        xPos++;
                        continue;
                    }

                    //if (point.xPosPoint != null && point.isXPos) point.intXLength = point.XPosLength;
                    break;
                }

                #endregion 搜索X正方向临近点

                #region 搜索X负方向临近点

                for (int i = point.IntX;
                    i > App.PointList.FindAll(a => a.AreaType == point.AreaType).Min(a => a.IntX);
                    i--)
                {
                    point.XNegPoint = App.PointList.FirstOrDefault(a =>
                        a.IntX == point.IntX - xNeg && a.IntY == point.IntY && a.AreaType == point.AreaType);
                    if (point.XNegPoint == null)
                    {
                        xNeg++;
                        continue;
                    }
                    break;
                }

                #endregion 搜索X负方向临近点

                #region 搜索Y正反向临近点

                for (int i = point.IntY;
                    i < App.PointList.FindAll(a => a.AreaType == point.AreaType).Max(a => a.IntY);
                    i++)
                {
                    point.YPosPoint = App.PointList.FirstOrDefault(a =>
                        a.IntX == point.IntX && a.IntY == point.IntY + yPos && a.AreaType == point.AreaType);
                    if (point.YPosPoint == null)
                    {
                        yPos++;
                        continue;
                    }
                }

                #endregion 搜索Y正反向临近点

                #region 搜索Y负方向临近点

                for (int i = point.IntY;
                    i > App.PointList.FindAll(a => a.AreaType == point.AreaType).Min(a => a.IntY);
                    i--)
                {
                    point.YNegPoint = App.PointList.FirstOrDefault(a =>
                        a.IntX == point.IntX && a.IntY == point.IntY - yNeg && a.AreaType == point.AreaType);
                    if (point.YNegPoint == null)
                    {
                        yNeg++;
                        continue;
                    }
                }

                #endregion 搜索Y负方向临近点
            }

            #endregion 赋值每个点位的四周点

            return BllResult.Success();
        }

        /// <summary>
        /// 下载Demo点位信息
        /// </summary>
        /// <param name="errMsg"></param>
        public static BllResult DownDemoPoint()
        {
            var demoPointResult = _demoPointDb.Query();

            if (!demoPointResult.IsSuccess)
            {
                if (demoPointResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化Demo点信息异常;{demoPointResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }

            foreach (var _DemoPoint in demoPointResult.Data)
            {
                _DemoPoint.TmpDirectionList = new List<TmpDirection>();
                _DemoPoint.LockedAgv = null;
                App.PointList.Add(_DemoPoint);
            }

            #region sql临时注释

            //string sql = string.Format("SELECT * FROM T_Base_DemoPoint");
            //DataSet ds = DbHelperSQL.Query(sql);
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Base_Point point = new Base_Point();
            //    point.Barcode = dr["strBarcode"].ToString();
            //    point.AreaType = dr["pointAreaType"].ToString();
            //    point.PointType = (EnumMsg.PointType)int.Parse(dr["pointType"].ToString());
            //    point.IntX = int.Parse(dr["intX"].ToString());
            //    point.IntY = 1000 - int.Parse(dr["intY"].ToString());
            //    point.IsXPos = dr["isXPos"].ToString() == "0" ? false : true;
            //    point.IsXNeg = dr["isXNeg"].ToString() == "0" ? false : true;
            //    point.IsYPos = dr["isYNeg"].ToString() == "0" ? false : true;
            //    point.IsYNeg = dr["isYPos"].ToString() == "0" ? false : true;
            //    point.AgvOri = (EnumMsg.AgvOri)int.Parse(dr["OriAgv"].ToString());
            //    point.DialOri = (EnumMsg.DialOri)int.Parse(dr["OriDial"].ToString());
            //    point.IsEnable = dr["isEnable"].ToString() == "0" ? false : true;
            //    point.IsOccupy = dr["isOccupy"].ToString() == "0" ? false : true;
            //    point.OccupyAgvNo = dr["strOccupyAgvNo"].ToString();
            //    point.RegionName = dr["strRegionName"].ToString();
            //    point.TmpDirectionList = new List<TmpDirection>();
            //    point.LockedAgv = null;
            //    App.DemoPointList.Add(point);
            //}

            #endregion sql临时注释

            #region 赋值四周点

            foreach (Base_Point point in App.DemoPointList)
            {
                int xPos = 1;
                int xNeg = 1;
                int yPos = 1;
                int yNeg = 1;

                #region 搜索X正方向临近点

                for (int i = point.IntX; i < App.DemoPointList.FindAll(a => a.AreaType == point.AreaType).Max(a => a.IntX); i++)
                {
                    point.XPosPoint = App.DemoPointList.Find(a => a.IntX == point.IntX + xPos && a.IntY == point.IntY && a.AreaType == point.AreaType);
                    if (point.XPosPoint == null)
                    {
                        xPos++;
                        continue;
                    }
                    break;
                }

                #endregion 搜索X正方向临近点

                #region 搜索X负方向临近点

                for (int i = point.IntX; i > App.DemoPointList.FindAll(a => a.AreaType == point.AreaType).Min(a => a.IntX); i--)
                {
                    point.XNegPoint = App.DemoPointList.FirstOrDefault(a => a.IntX == point.IntX - xNeg && a.IntY == point.IntY && a.AreaType == point.AreaType);
                    if (point.XNegPoint == null)
                    {
                        xNeg++;
                        continue;
                    }
                    break;
                }

                #endregion 搜索X负方向临近点

                #region 搜索Y正反向临近点

                for (int i = point.IntY; i < App.DemoPointList.FindAll(a => a.AreaType == point.AreaType).Max(a => a.IntY); i++)
                {
                    point.YPosPoint = App.DemoPointList.FirstOrDefault(a => a.IntX == point.IntX && a.IntY == point.IntY + yPos && a.AreaType == point.AreaType);
                    if (point.YPosPoint == null)
                    {
                        yPos++;
                        continue;
                    }
                    break;
                }

                #endregion 搜索Y正反向临近点

                #region 搜索Y负方向临近点

                for (int i = point.IntY; i > App.DemoPointList.FindAll(a => a.AreaType == point.AreaType).Min(a => a.IntY); i--)
                {
                    point.YNegPoint = App.DemoPointList.FirstOrDefault(a => a.IntX == point.IntX && a.IntY == point.IntY - yNeg && a.AreaType == point.AreaType);
                    if (point.YNegPoint == null)
                    {
                        yNeg++;
                        continue;
                    }
                    break;
                }

                #endregion 搜索Y负方向临近点
            }

            #endregion 赋值四周点

            return BllResult.Success();
        }

        /// <summary>
        /// 下载主任务信息(t_base_task表)
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownTask()
        {
            var taskResult = _taskDb.Query();

            if (!taskResult.IsSuccess)
            {
                if (taskResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化主任务信息异常;{taskResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }
            //根据点位条码找到起点,并且给任务的点位赋值
            foreach (var _task in taskResult.Data)
            {
                var startPoint = App.PointList.Find(a => a.Barcode == _task.StartBarcode);
                var endPoint = App.PointList.Find(a => a.Barcode == _task.EndBarcode);
                if (startPoint == null)
                {
                    return BllResult.Error($"初始化主任务起点信息异常;");
                }
                if (_task.TaskType != EnumMsg.TaskType.出库区任务.ToString())
                {
                    if (endPoint == null)
                    {
                        return BllResult.Error($"初始化主任务终点信息异常;");
                    }
                }
                _task.SubTaskList = new ObservableCollection<Base_SubTask>();
                _task.StartPoint = startPoint;
                _task.EndPoint = endPoint;
                App.TaskList.Add(_task);
            }

            #region sql临时注释

            //string sql = string.Format("SELECT * FROM  T_Task");
            //DataSet ds = DbHelperSQL.Query(sql);
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Base_FTask task = new Base_FTask();
            //    task.TaskNo = dr["strTaskNo"].ToString();
            //    task.TaskID = dr["strTaskID"].ToString();
            //    task.TaskGroup = dr["strTaskGroup"].ToString();
            //    task.TaskLevel = int.Parse(dr["intTaskLevel"].ToString());
            //    task.TaskPallet = dr["strTaskBarcode"].ToString();
            //    task.Initial = dr["strInitial"].ToString();
            //    task.Target = dr["strTarget"].ToString();
            //    task.StartPoint = App.PointList.Find(a => a.Barcode == dr["startPoint"].ToString());
            //    task.EndPoint = App.PointList.Find(a => a.Barcode == dr["endPoint"].ToString());
            //    task.AcceptTime = dr["strAcceptTime"].GetDateTime();
            //    task.IsSubmit = dr["isTaskSubmit"].ToString() == "0" ? false : true;
            //    task.TaskAgvNo = dr["strTaskAgv"].ToString();
            //    task.SubTaskList = new ObservableCollection<Base_SonTask>();
            //    task.BeginTime = dr["strBeginTime"].GetDateTime();
            //    task.EndTime = dr["strEndTime"].GetDateTime();
            //    task.TaskErrMsg = dr["taskErrMsg"].ToString();
            //    task.Direction = (EnumMsg.DialOri)int.Parse(dr["direction"].ToString());
            //    App.TaskList.Add(task);
            //}

            #endregion sql临时注释

            return BllResult.Success();
        }

        /// <summary>
        /// 下载子任务信息(t_base_subtask表)
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownSonTask()
        {
            var sonTaskResult = _sonTaskDb.Query("", "TaskNo,SubTaskNo");
            if (!sonTaskResult.IsSuccess)
            {
                return BllResult.Error(sonTaskResult.Message);
            }
            foreach (var sonTask in sonTaskResult.Data)
            {
                //如果子任务没有对应主任务,就删除子任务
                var task = App.TaskList.FirstOrDefault(a => a.TaskNo == sonTask.TaskNo);
                if (task == null)
                {
                    App.ExFile.MessageError("SonTaskInit", $"{sonTask.SubTaskNo}");
                    var deleteresult = _sonTaskDb.Delete(sonTask);
                    if (!deleteresult.IsSuccess)
                    {
                        return BllResult.Error($"该子任务删除失败,删除RCS子任务表信息{sonTask.SubTaskNo}失败");
                    }

                    #region sql语句

                    //string sqlDelete = string.Format("DELETE FROM T_SonTask  WHERE intSonTaskNo = '{0}';", _sonTask.SubTaskNo);
                    //int sqlResult = DbHelperSQL.ExecuteSql(sqlDelete);

                    #endregion sql语句

                    continue;
                }
                sonTask.ConfigTaskSplit = App.Config_TaskSplitList.Find(x => x.ID == sonTask.ConfigTaskSplitID);
                sonTask.PathPointList = new List<Base_PathPoint>();
                var startPoint = App.PointList.Find(a => a.Barcode == sonTask.StartBarcode);
                var endPoint = App.PointList.Find(a => a.Barcode == sonTask.EndBarcode);
                if (startPoint == null)
                {
                    return BllResult.Error($"初始化主任务起点信息异常;");
                }
                if (endPoint == null)
                {
                    return BllResult.Error($"初始化主任务终点信息异常;");
                }
                //起点和终点不在同一区域,就找到新的点位
                var listPoints = ComnMethod.GetAreaPoint(startPoint, endPoint);
                startPoint = listPoints.First();
                endPoint = listPoints.Last();
                sonTask.StartPoint = startPoint;
                sonTask.EndPoint = endPoint;
                task.SubTaskList.Add(sonTask);
            }

            return BllResult.Success();

            #region sql语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM  T_SonTask ORDER BY strTaskNo,intSonTaskNo");
            //    DataSet ds = DbHelperSQL.Query(sql);

            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Base_SonTask sonTask = new Base_SonTask();
            //        sonTask.SerialNo = int.Parse(dr["intSerialNo"].ToString());
            //        sonTask.SubTaskNo = int.Parse(dr["intSonTaskNo"].ToString());
            //        sonTask.TaskNo = dr["strTaskNo"].ToString();
            //        sonTask.SubTaskType = (EnumMsg.AgvTaskType)int.Parse(dr["sonTaskType"].ToString());
            //        sonTask.StartPoint = App.PointList.Find(a => a.Barcode == dr["startPoint"].ToString());
            //        sonTask.EndPoint = App.PointList.Find(a => a.Barcode == dr["endPoint"].ToString());
            //        //起点终点不再同一区域,判断
            //        List<Base_Point> listPoints = ComnMethod.GetAreaPoint(sonTask.StartPoint, sonTask.EndPoint);
            //        sonTask.StartPoint = listPoints.First();
            //        sonTask.EndPoint = listPoints.LastOrDefault();
            //        sonTask.WaitTime = int.Parse(dr["waitTime"].ToString());
            //        sonTask.IsCarry = dr["isCarry"].ToString() == "0" ? false : true;
            //        sonTask.TaskRequestType = (EnumMsg.TaskRequestType)int.Parse(dr["taskRequestType"].ToString());
            //        sonTask.DialOri = (EnumMsg.DialOri)int.Parse(dr["dialDirection"].ToString());
            //        sonTask.AgvOri = (EnumMsg.AgvOri)int.Parse(dr["agvDirection"].ToString());
            //        sonTask.PathPointList = new List<Base_PathPoint>();
            //        sonTask.SubTaskState = (EnumMsg.SubTaskState)int.Parse(dr["sonTaskState"].ToString());
            //        sonTask.BeginTime = dr["strBeginTime"].GetDateTime();
            //        sonTask.EndTime = dr["strEndTime"].GetDateTime();
            //        sonTask.ChargeLength = int.Parse(dr["chargeLength"].ToString());
            //        Base_FTask task = App.TaskList.FirstOrDefault(a => a.TaskNo == sonTask.TaskNo);
            //        if (task == null)
            //        {
            //            App.ExFile.MessageError("SonTaskInit", sonTask.SubTaskNo + "==" + sonTask.SubTaskType + "==" + sonTask.SubTaskState);
            //            string sqlDelete = string.Format("DELETE FROM  T_SonTask  WHERE intSonTaskNo = '{0}';", sonTask.SubTaskNo);
            //            int sqlResult = DbHelperSQL.ExecuteSql(sqlDelete);
            //            continue;
            //        }
            //        task.SubTaskList.Add(sonTask);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "子任务初始化失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion sql语句
        }

        /// <summary>
        /// 下载AGV信息
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownAgv()
        {
            var agvResult = _agvDb.Query(x => x.CurrMap == App.AppConfig.MapName);

            if (!agvResult.IsSuccess)
            {
                return BllResult.Error($"初始化AGV信息异常;{agvResult.Message}");
            }

            foreach (var _agv in agvResult.Data)
            {
                App.AgvList.Add(_agv);
                _agv.AgvTask = App.TaskList.FirstOrDefault(a => a.TaskAgvNo == _agv.AgvNo && a.IsSubmit);
                _agv.HeightState = EnumMsg.HeightState.初始化;
                //_agv.InStock = EnumMsg.InStock.初始化;
                _agv.RollerState = EnumMsg.RollerState.初始化;
                //if (_agv.IsEnable && _agv.AgvTask != null && _agv.AgvTask.TaskType == "回家")
                //{
                //    _agv.AgvTask.EndPoint.IsOccupy = true;
                //    _agv.AgvTask.EndPoint.OccupyAgvNo = _agv.AgvNo;
                //}
                _agv.LockStation = App.StationList.Find(x => x.Name == _agv.ChargeStation);
                var point = App.PointList.Find(a => a.Barcode == _agv.Barcode);
                if (point == null) continue;
                point.LockedAgv = _agv;
                _agv.FreeTime = DateTime.Now;
                _agv.ChargeTime = DateTime.Now;
            }
            return BllResult.Success();

            #region SQL语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM  T_Base_Agv");
            //    DataSet ds = DbHelperSQL.Query(sql);
            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Agv agv = new Agv();
            //        agv.strAgvNo = dr["strAgvNo"].ToString();
            //        agv.agvType = (EnumMsg.AgvType)int.Parse(dr["agvAreaType"].ToString());
            //        agv.agvGroup = dr["agvGroup"].ToString();
            //        agv.strBarcode = dr["strBarcode"].ToString();
            //        agv.agvState = 0;
            //        agv.heightState = 0;
            //        agv.currentCharge = float.Parse(dr["currentCharge"].ToString());
            //        agv.strChooseStation = dr["strChooseStation"].ToString() == null ? "" : dr["strChooseStation"].ToString();
            //        agv.isEnable = dr["isEnable"].ToString() == "0" ? false : true;
            //        agv.isOnline = false;
            //        agv.agvTask = App.TaskList.FirstOrDefault(a => a.strTaskAgv == agv.strAgvNo);
            //        agv.strStopReason = "";
            //        agv.strAgvError = dr["strAgvError"].ToString() == null ? "" : dr["strAgvError"].ToString();
            //        agv.agvMilage = int.Parse(dr["agvMilage"].ToString());
            //        agv.agvMap = dr["agvmap"].ToString();
            //        agv.startCharges = float.Parse(dr["startCharges"].ToString());
            //        agv.IP = dr["Ip"].ToString();
            //        App.AgvList.Add(agv);
            //        #region 20181003小车任务为回家任务将回家点设为Occupy
            //        if (agv.isEnable && agv.agvTask != null && agv.agvTask.strTaskID == "回家")
            //        {
            //            agv.agvTask.endPoint.isOccupy = true;
            //            agv.agvTask.endPoint.strOccupyAgvNo = agv.agvTask.strTaskNo;
            //        }
            //        #endregion
            //        Point point = App.PointList.Find(a => a.strBarcode == agv.strBarcode);
            //        if (point == null) continue;
            //        point.lockedAgv = agv;
            //    }

            //}
            //catch (Exception ex)
            //{
            //    errMsg = "小车初始化失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 下载路径信息(t_base_pathpoint表)
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownPath()
        {
            var pathResult = _pathPointDb.Query();

            if (!pathResult.IsSuccess)
            {
                return BllResult.Error($"初始化路径点异常;{pathResult.Message}");
            }

            var listPathPoint = new List<Base_PathPoint>();
            //找出所有的子任务
            var result0 = App.TaskList.Where(a => a.SubTaskList.Count != 0).SelectMany(b => b.SubTaskList).ToList();

            foreach (var _pathPoint in pathResult.Data)
            {
                //如果路径对应的子任务不存在,就删除路径
                var result1 = result0.Exists(a => a.SubTaskNo == _pathPoint.SubTaskNo);
                if (!result1)
                {
                    var deleteresult = _pathPointDb.Delete(it => it.Barcode == _pathPoint.Barcode);
                    if (!deleteresult.IsSuccess)
                    {
                        return BllResult.Error($"删除无用路径点异常;");
                    }
                    continue;
                }
                //如果路径对应的子任务存在,给路径的点位赋值
                var point = App.PointList.FirstOrDefault(a => a.Barcode == _pathPoint.Barcode && a.AreaType == _pathPoint.AreaType) ?? throw new Exception($"路径点{_pathPoint.Barcode}对应点位空");

                _pathPoint.Point = point;
                listPathPoint.Add(_pathPoint);
            }

            foreach (var agv in App.AgvList)
            {
                if (agv.AgvTask == null || agv.AgvTask.SubTaskList.Count == 0)
                {
                    continue;
                }
                agv.AgvTask.SubTaskList.ToList().Sort();
                var sonTask = agv.AgvTask.SubTaskList.First();
                if (sonTask.SubTaskState < EnumMsg.SubTaskState.已建立路径)
                {
                    continue;
                }

                //把路径赋值给子任务的路径
                if (listPathPoint.Exists(a => a.SubTaskNo == sonTask.SubTaskNo))
                {
                    sonTask.PathPointList = listPathPoint.FindAll(a => a.SubTaskNo == sonTask.SubTaskNo);
                    sonTask.PathPointList.Sort();
                    for (var i = 0; i < sonTask.PathPointList.Count - 1; i++)
                    {
                        sonTask.PathPointList[i + 1].PreviousPathDirection = sonTask.PathPointList[i].PathDirection;
                    }
                    agv.PathPointList = [.. sonTask.PathPointList];
                    try
                    {
                        //添加方向锁
                        GetPath.OriLock(sonTask.PathPointList, agv);
                    }
                    catch (Exception ex)
                    {

                        App.ExFile.MessageError("DownPath", ex.Message + ex.StackTrace);
                    }
                }
            }

            return BllResult.Success();

            #region SQL语句

            //try
            //{
            //    string sql = "SELECT * FROM  T_Base_PathPoint ORDER BY intSonTaskNo,intSerialNo";
            //    DataSet ds = DbHelperSQL.Query(sql);
            //    List<Base_PathPoint> listPathPoint = new List<Base_PathPoint>();
            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Base_PathPoint pathPoint = new Base_PathPoint();
            //        pathPoint.AreaType = dr["areaType"].ToString();
            //        pathPoint.SubTaskNo = int.Parse(dr["intSonTaskNo"].ToString());
            //        pathPoint.SerialNo = int.Parse(dr["intSerialNo"].ToString());
            //        pathPoint.Point = App.PointList.Find(a => a.Barcode == dr["strBarcode"].ToString() && a.AreaType == pathPoint.AreaType);
            //        pathPoint.PathDirection = (EnumMsg.AgvOri)int.Parse(dr["pathDirection"].ToString());
            //        pathPoint.IsCorner = dr["isCorner"].ToString() == "0" ? false : true;
            //        pathPoint.PathPointType = (EnumMsg.PointType)int.Parse(dr["pathPointType"].ToString());
            //        pathPoint.PathTim = int.Parse(dr["pathTim"].ToString());
            //        listPathPoint.Add(pathPoint);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "路径初始化失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 下载任务分解配置信息
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownTaskSplit()
        {
            var taskSplitResult = _taskSplitDb.Query();
            if (!taskSplitResult.IsSuccess)
            {
                return BllResult.Error($"初始化任务分解异常;{taskSplitResult.Message}");
            }
            foreach (var _taskSplit in taskSplitResult.Data)
            {
                App.Config_TaskSplitList.Add(_taskSplit);
            }
            return BllResult.Success();

            #region SQL语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM T_Config_TaskSplit");
            //    DataSet ds = DbHelperSQL.Query(sql);
            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Config_TaskSplit config_TaskSplit = new Config_TaskSplit();
            //        config_TaskSplit.TaskID = dr["taskID"].ToString();
            //        config_TaskSplit.SerialNo = int.Parse(dr["intSerialNo"].ToString());
            //        config_TaskSplit.AgvTaskType = (EnumMsg.AgvTaskType)int.Parse(dr["agvTaskType"].ToString());
            //        config_TaskSplit.FromPoint = (EnumMsg.ConfigToFromPoint)int.Parse(dr["fromPoint"].ToString());
            //        config_TaskSplit.ToPoint = (EnumMsg.ConfigToFromPoint)int.Parse(dr["toPoint"].ToString());
            //        config_TaskSplit.WaitTime = int.Parse(dr["waitTime"].ToString());
            //        config_TaskSplit.IsCarry = dr["isCarry"].ToString() == "0" ? false : true;
            //        config_TaskSplit.TaskRequestType = (EnumMsg.TaskRequestType)int.Parse(dr["taskRequestType"].ToString());
            //        App.Config_TaskSplitList.Add(config_TaskSplit);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "分解任务初始化失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 下载站台信息(t_base_station表)
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownStation()
        {
            var stationResult = _stationDb.Query(x => x.Area == App.AppConfig.MapName);
            if (!stationResult.IsSuccess)
            {
                if (stationResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化站台信息异常;{stationResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }
            // 首先校验站台的点位,然后根据站台的附属点位,给点位的附属点位赋值
            foreach (var _station in stationResult.Data)
            {
                App.StationList.Add(_station);
                var point = App.PointList.Find(a => a.Barcode == _station.Barcode);
                if (point == null)
                {
                    return BllResult.Error($"未找到{_station.Name}对应的码值!");
                }
                _station.Point = point;
                var prePoint = App.PointList.Find(a => a.Barcode == _station.PreBarcode);
                if (prePoint != null)
                {
                    point.PreBarcode = prePoint.Barcode;
                    if (prePoint.PointType != EnumMsg.PointType.站台点)
                    {
                        prePoint.PointType = EnumMsg.PointType.站台附属点;
                    }
                }
                else if (!string.IsNullOrEmpty(_station.PreBarcode))
                {
                    return BllResult.Error($"未找到{_station.Name}对应的站台附属点码值{_station.PreBarcode}!");
                }
            }
            return BllResult.Success();
        }

        /// <summary>
        /// 异常信息表(t_log_agverrmsg表)
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownErrMsg()
        {
            App.Config_ErrMsgList = new string[64];
            var errMsgResult = _errMsgDb.Query();
            if (!errMsgResult.IsSuccess)
            {
                return BllResult.Error($"初始化异常信息异常;{errMsgResult.Message}");
            }
            foreach (var _errMsg in errMsgResult.Data)
            {
                App.Config_ErrMsgList[_errMsg.ErrorNo - 1] = _errMsg.ErrorMsg;
            }
            return BllResult.Success();

            #region SQL语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM  T_Config_ErrMsg");
            //    DataSet ds = DbHelperSQL.Query(sql);

            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Config_ErrMsg Err = new Config_ErrMsg();
            //        Err.ErrorNo = int.Parse(dr["intErrorNo"].ToString());
            //        Err.ErrorMsg = dr["strErrorMsg"].ToString();
            //        App.Config_ErrMsgList.Add(Err);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "异常信息初始化失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 参数配置(t_config_keyvalue表)
        /// </summary>
        /// <param name="errMsg"></param>
        public static BllResult DownKeyValue()
        {
            var keyValueResult = _keyValueDb.Query();
            if (!keyValueResult.IsSuccess)
            {
                return BllResult.Error($"初始化电量信息异常:{keyValueResult.Message}");
            }
            App.Config_KeyValueDic.Clear();
            foreach (var _keyValue in keyValueResult.Data)
            {
                if (!double.TryParse(_keyValue.Value, out double doubleValue))
                {
                    return BllResult.Error($"初始化电量信息异常:参数变量【{_keyValue.KeyVariable}】的值【{_keyValue.Value}】不能转化为double类型");
                }
                _keyValue.DoubleValue = doubleValue;
                App.Config_KeyValueDic.Add(_keyValue.KeyVariable, _keyValue);
            }
            return BllResult.Success();

            //foreach (var _keyValue in keyValueResult.Data)
            //{
            //    switch (_keyValue.KeyVariable)
            //    {
            //        case "Cfull":
            //            App.FullCharge = float.Parse(_keyValue.Value);
            //            break;

            //        case "Savety":
            //            App.SafeCharge = float.Parse(_keyValue.Value);
            //            break;

            //        case "Danger":
            //            App.DangerCharge = float.Parse(_keyValue.Value);
            //            break;

            //        case "MinCharges":
            //            App.MinCharges = float.Parse(_keyValue.Value);
            //            break;

            //        case "MinTime":
            //            App.MinTime = float.Parse(_keyValue.Value);
            //            break;

            //        default:
            //            break;
            //    }
            //}

            #region SQL语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM  T_Config_KeyValue");
            //    DataSet ds = DbHelperSQL.Query(sql);

            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        switch (dr["KeyVariable"].ToString())
            //        {
            //            case "Cfull":
            //                App.FullCharge = float.Parse(dr["Value"].ToString());
            //                break;

            //            case "Savety":
            //                App.SafeCharge = float.Parse(dr["Value"].ToString());
            //                break;

            //            case "Danger":
            //                App.DangerCharge = float.Parse(dr["Value"].ToString());
            //                break;

            //            case "MinCharges":
            //                App.MinCharges = float.Parse(dr["Value"].ToString());
            //                break;

            //            default:
            //                break;
            //        }
            //    }
            //}
            //catch (Exception Ex)
            //{
            //    errMsg = "电量控制初始化失败:" + Ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 任务AGV群组绑定(t_config_taskagvgroup表)
        /// </summary>
        /// <param name="errMsg"></param>
        private static BllResult DownTaskAgvGroup()
        {
            var taskAgvGroupResult = _taskAgvGroupDb.Query();
            if (!taskAgvGroupResult.IsSuccess)
            {
                if (taskAgvGroupResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化AGV和任务群组异常;{taskAgvGroupResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }

            foreach (var _taskAgvGroup in taskAgvGroupResult.Data)
            {
                App.TaskAgvGroupList.Add(_taskAgvGroup);
            }

            return BllResult.Success();

            #region SQL语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM  T_Config_TaskAgvGroup");
            //    DataSet ds = DbHelperSQL.Query(sql);

            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        TaskAgvGroup taskAgvGroup = new TaskAgvGroup();
            //        taskAgvGroup.TaskGroup = dr["taskGroup"].ToString();
            //        taskAgvGroup.AgvGroup = dr["agvGroup"].ToString();
            //        App.TaskAgvGroupList.Add(taskAgvGroup);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "异常信息初始化失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 下载关键点信息(t_config_point表)
        /// </summary>
        /// <param name="errMsg"></param>
        public static BllResult DownConfigPoint()
        {
            var configPointResult = _cgPointDb.Query();
            if (!configPointResult.IsSuccess)
            {
                if (configPointResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化点配置信息异常;{configPointResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }
            foreach (var _configPoint in configPointResult.Data)
            {
                App.Config_PointList.Add(_configPoint);
            }
            return BllResult.Success();

            #region SQL语句

            //try
            //{
            //    string sql = string.Format("SELECT * FROM  T_Config_Point");
            //    DataSet ds = DbHelperSQL.Query(sql);
            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Config_Point config_Point = new Config_Point();
            //        config_Point.No = int.Parse(dr["No"].ToString());
            //        config_Point.Barcode = dr["strBarcode"].ToString();
            //        config_Point.AreaType = dr["AreaType"].ToString();
            //        config_Point.RegionName = dr["strRegionName"].ToString();
            //        App.Config_PointList.Add(config_Point);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "旋转区域点配置失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}

            #endregion SQL语句
        }

        /// <summary>
        /// 下载关键点信息(t_base_loction表)
        /// </summary>
        /// <param name="errMsg"></param>
        public static BllResult DownLoction()
        {
            var loctionResult = _loctionDb.Query();
            if (!loctionResult.IsSuccess)
            {
                if (loctionResult.Message != "未查询到数据")
                {
                    return BllResult.Error($"初始化料点配置信息异常;{loctionResult.Message}");
                }
                else
                {
                    return BllResult.Success();
                }
            }
            foreach (var _loction in loctionResult.Data)
            {
                _loction.LoctionPoint = App.PointList.FirstOrDefault(x => x.Barcode == _loction.LoctionBarcode);
                App.LoctionList.Add(_loction);
            }
            return BllResult.Success();
        }

        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <returns></returns>
        public static BllResult<List<Base_Equipment>> InitEquipment()
        {
            var equipmentResult = _equipmentDb.Query(t => t.IsEnable == true);
            if (!equipmentResult.IsSuccess)
            {
                return BllResult<List<Base_Equipment>>.Error("初始化失败,查询设备失败!");
            }
            //if (equipmentResult.Data.Count > 0)
            //{
            //    return BllResult<List<Base_Equipment>>.Sucess();
            //}
            var equipmentCodeList = equipmentResult.Data.Select(t => t.Code).ToList();
            var equipmentPropResult = _equipmentPropDb.Query(t => equipmentCodeList.Contains(t.EquipmentCode));
            if (!equipmentPropResult.IsSuccess)
            {
                return BllResult<List<Base_Equipment>>.Error("初始化失败,查询设备属性失败!");
            }
            var result = EquipmentExecutor.Instance.Init(equipmentResult.Data, equipmentPropResult.Data);
            if (!result.IsSuccess)
            {
                return BllResult<List<Base_Equipment>>.Error($"初始化失败,{result.Message}");
            }
            App.EquipmentList = result.Data;
            //初始化华恒站台监控
            var equipments = App.EquipmentList.Where(t => t.Type == EnumPLC.EquipmentType.HuaHengStation.ToString()).ToList();
            foreach (var equipment in equipments)
            {
                HuahengStaion huahengStaion = new HuahengStaion
                {
                    EquipmentName = equipment.Name,
                    EquipmentCode = equipment.Code,
                    CADCode = equipment.CADCode
                };
                App.HuahengStaionList.Add(huahengStaion);
            }
            ////初始化剪床监控
            //equipments = App.EquipmentList.Where(t => t.Type == EnumPLC.EquipmentType.ShearsIn.ToString() ||
            //                                          t.Type == EnumPLC.EquipmentType.ShearsOut.ToString()).ToList();
            //foreach (var equipment in equipments)
            //{
            //    var shears = new Shears
            //    {
            //        EquipmentName = equipment.Name,
            //        EquipmentCode = equipment.Code,
            //        CADCode = equipment.CADCode
            //    };
            //    App.ShearsList.Add(shears);
            //}
            ////初始化快卷门监控
            //equipments = App.EquipmentList.Where(t => t.Type == EnumPLC.EquipmentType.Door.ToString()).ToList();
            //foreach (var equipment in equipments)
            //{
            //    var door = new Door
            //    {
            //        EquipmentName = equipment.Name,
            //        EquipmentCode = equipment.Code,
            //        CADCode = equipment.CADCode
            //    };
            //    App.DoorList.Add(door);
            //}

            return result;
        }

        /// <summary>
        /// 下载外部设备信息
        /// </summary>
        /// <param name="errMsg"></param>
        public static void DownEquipment(ref string errMsg)
        {
            //try
            //{
            //    string sql = string.Format("SELECT * FROM t_base_equipment");
            //    DataSet ds = DbHelperSQL.Query(sql);
            //    foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        Config_Equipment equipment = new Config_Equipment();
            //    }
            //}
            //catch (Exception ex)
            //{
            //    errMsg = "下载提升机信息失败:" + ex.Message.Replace(Environment.NewLine, "");
            //}
        }

        /// <summary>
        /// 加载agv原有的异常信息
        /// </summary>
        public static BllResult DownErrorInfo()
        {
            var res = _logErrMsgDb.Query(x => x.EndErrTime == null);
            if (!res.IsSuccess)
            {
                return BllResult.Error("查询数据失败!");
            }
            //var list = res.Data.FindAll(x => x.StartErrTime > DateTime.Now.AddDays(-1));
            var list = res.Data;


            foreach (var item in list)
            {
                item.IsInsert = true;
                App.AgvErrMsgs.Add(item);
            }
            return BllResult.Success();
        }

        /// <summary>
        /// 加载协议信息
        /// </summary>
        /// <returns></returns>
        public static BllResult DownProtocolInfo()
        {
            var protocolDetailRes = _protocolDetail.Query();
            var protocolRes = _protocol.Query();
            if (!protocolRes.IsSuccess || !protocolDetailRes.IsSuccess)
            {
                return BllResult.Error($"协议数据查询失败!:{protocolRes.Message}-{protocolDetailRes.Message}");
            }

            foreach (var protocol in protocolRes.Data)
            {
                protocol.Details = protocolDetailRes.Data.Where(x => x.ProtocolCode == protocol.Code).OrderBy(x => x.SerialNo).ToList();
                App.Protocols[protocol.Length] = protocol;
            }



            return BllResult.Success();
        }

    }
}