PDAService.cs
105 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
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
using ApkInfo;
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Redis;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Request;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.POJO.WebEntity.api;
using Hh.Mes.Service.Repository;
using Hh.Mes.Service.SystemAuth;
using Microsoft.VisualBasic;
using MySqlX.XDevAPI.Common;
using NPOI.SS.Formula.Functions;
using NPOI.Util;
using Org.BouncyCastle.Crypto;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
namespace Hh.Mes.Service
{
public class PDAService : RepositorySqlSugar<sys_user>
{
AuthContextFactory authContextFactory;
public PDAService(AuthContextFactory authContextFactory)
{
this.authContextFactory = authContextFactory;
}
/// <summary>
/// PDA物料追溯查询
/// (扫码查询物料追溯码,查看物料的批次,物料名称,壁厚等物料信息)
/// </summary>
/// <param name="barCode"></param>
/// <returns></returns>
public dynamic GetMaterialInfoByBarCode(dynamic requestData)
{
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
var reqData = DynamicJson.Parse(requestData.ToString());
var response = new POJO.Response.Response();
if (reqData == null || !reqData.IsDefined("barCode"))
{
return response.ResponseError($"工件编码参数字段不正确,请核对!");
}
string barCode = reqData.barCode;
if (string.IsNullOrEmpty(barCode)) return response.ResponseError($"工件编码不能为空,请核对!");
//1:扫码工件编码 查询base_work_order_head表
var bwdInfo = Context.Queryable<base_work_order_head>().First(x => x.workPieceNo == barCode);
response.Result = bwdInfo;
return response;
});
}
#region 组对、焊接
/// <summary>
/// 获取匹配的组对信息
/// </summary>
/// <param name="station">工位码</param>
/// <param name="pipe">管段码</param>
/// <returns></returns>
public dynamic GetMatchTeamList(string station, string pipe)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
if (string.IsNullOrWhiteSpace(station))
{
response.ResponseErr($"工位码为空,请扫描工位码!");
return response;
}
//工位信息
var equipment = base.Context.Queryable<base_work_station>().Where(x => x.workStationCode == station).First();
if (equipment == null)
{
return response.ResponseError($"工位码【{station}】未找到工位信息,请配置!");
}
if (string.IsNullOrWhiteSpace(pipe))
{
response.ResponseErr($"管段码为空,请扫描管段码!");
return response;
}
//查询出管段码对应的多焊口列表
var detList = Context.Queryable<bus_workOrder_detail, base_material>((b, c) => new
JoinQueryInfos(JoinType.Left, b.weldMaterCode == c.materialCode))
.Where((b, c) => b.barCode == pipe
&& b.workCenterCode == EnumoprSequenceCode.组对
&& b.state == (int)EnumOrderBodyStatus.初始化
&& !string.IsNullOrEmpty(b.weldMaterCode)
&& c.isDelete == (int)EnumtIsValid.是)
.Select((b, c) => new workOrderDet
{
id = b.id,
headKeys = b.headKeys.ToString(),
bodyKeys = b.bodyKeys.ToString(),
extendComp1 = b.extendComp1,
materialName = c.materialName,
cutMaterCode = b.cutMaterCode,
weldMaterCode = b.weldMaterCode,
pipelength = b.cuttingLength.ToString()
}
).ToList();
var weldMaterCodeList = detList.Where(x => string.IsNullOrEmpty(x.materialName)).Select(x => x.weldMaterCode).ToList();
if (weldMaterCodeList.Count != 0)
{
response.ResponseErr($"物料数据缺少,物料码【{weldMaterCodeList.ToJson(",")}】!");
return response;
}
if (detList.Count == 0)
{
response.ResponseErr($"管段码【{pipe}】未查询到组对数据!");
return response;
}
workOrderHead wHead = new workOrderHead();
if (detList.Count > 0)
{
var material = Context.Queryable<base_material>()
.Where(x => x.materialCode == detList[0].cutMaterCode && x.isDelete == (int)EnumtIsValid.是).First();
if (material == null)
{
response.ResponseErr($"物料码【{detList[0].cutMaterCode}】未查询到物料数据!");
return response;
}
var result = Context.Queryable<bus_workOrder_head>().Where(x => x.keys.ToString() == detList[0].headKeys).First();
if (result == null)
{
response.ResponseErr($"未查询到工单主数据!");
return response;
}
if (material != null)
{
wHead.barCode = pipe;
wHead.materialName = material.materialName;
wHead.pipelength = detList[0].pipelength;
}
wHead.teamList = detList;
}
response.Result = wHead;
return response;
});
}
/// <summary>
/// 获取组对开始列表
/// </summary>
/// <returns></returns>
public dynamic GetTeamStartList(string station)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
if (string.IsNullOrWhiteSpace(station))
{
response.ResponseErr($"工位码为空,请扫描工位码!");
return response;
}
//工位信息
var equipment = base.Context.Queryable<base_work_station>().Where(x => x.workStationCode == station).First();
if (equipment == null)
{
return response.ResponseError($"工位码【{station}】未找到工位信息,请配置!");
}
//查询出组对生产中的工序任务
var detList = Context.Queryable<bus_workOrder_detail, base_material>((b, c) => new
JoinQueryInfos(JoinType.Left, b.weldMaterCode == c.materialCode))
.Where((b, c) => b.workCenterCode == EnumoprSequenceCode.组对
&& b.state == (int)EnumOrderBodyStatus.生产中
&& c.isDelete == (int)EnumtIsValid.是
&& b.stationCode == station)
.Select((b, c) => new workOrderDet
{
id = b.id,
headKeys = b.headKeys.ToString(),
bodyKeys = b.bodyKeys.ToString(),
extendComp1 = b.extendComp1,
materialName = c.materialName,
cutMaterCode = b.cutMaterCode,
stationCode = b.stationCode,
barCode = b.barCode,
pipelength = b.cuttingLength.ToString()
}
).ToList();
var headKeyList = detList.GroupBy(x => x.headKeys).ToList();
List<workOrderHead> wHeadList = new List<workOrderHead>();
foreach (var headKey in headKeyList)
{
workOrderHead workH = new workOrderHead();
workH.teamList = new List<workOrderDet>();
var item = Context.Queryable<bus_workOrder_head>().Where(x => x.keys.ToString() == headKey.Key).First();
foreach (var detail in detList)
{
if (detail.headKeys == headKey.Key)
{
workH.teamList.Add(detail);
workH.barCode = detail.barCode;
}
}
var material = Context.Queryable<base_material>()
.Where(x => x.materialCode == workH.teamList[0].cutMaterCode && x.isDelete == (int)EnumtIsValid.是).First();
if (material != null)
{
workH.materialName = material.materialName;
workH.pipelength = detList[0].pipelength;
}
wHeadList.Add(workH);
}
response.Result = wHeadList;
return response;
});
}
/// <summary>
/// 保存组对开始列表
/// </summary>
/// <returns></returns>
public dynamic SaveTeamStartList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.stationCode = item.stationCode;
resultItem.actualEndTime = DateTime.Now;
resultItem.batchNo = item.batchNo;
resultItem.state = (int)EnumOrderBodyStatus.生产中;
resultItem.updateBy = sysUserApi?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).AddQueue();
}
else
{
response.ResponseErr($"未查询到工序组对任务信息!");
return response;
}
}
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
/// <summary>
/// 保存组对结束列表
/// </summary>
/// <returns></returns>
public dynamic SaveTeamEndList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
CutWeldService cutWeldService = new CutWeldService();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.state = (int)EnumOrderBodyStatus.已完成;
resultItem.actualEndTime = DateTime.Now;
resultItem.updateBy = sysUserApi?.Account;
resultItem.updateTime = DateTime.Now;
resultItem.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
Context.Updateable(resultItem).AddQueue();
}
else
{
response.ResponseErr($"未查询到工序组对任务信息!");
return response;
}
//工序完工反馈
cutWeldService.SendIWPTechnologylineProcess(resultItem.barCode, (int)EnumCutHeadState.组对完成);
}
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
/// <summary>
/// 获取匹配的焊接信息
/// </summary>
/// <param name="station">工位码</param>
/// <param name="pipe">管段码</param>
/// <returns></returns>
public dynamic GetMatchWeldList(string station, string pipe)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
if (string.IsNullOrWhiteSpace(pipe))
{
response.ResponseErr($"管段码【{pipe}】是空,请扫描管段码!");
return response;
}
if (string.IsNullOrWhiteSpace(station))
{
response.ResponseErr($"工位码【{station}】是空,请扫描工位码!");
return response;
}
//工位信息
var equipment = base.Context.Queryable<base_work_station>().Where(x => x.workStationCode == station).First();
if (equipment == null)
{
return response.ResponseError($"工位码【{station}】没有找到对应的工位信息!");
}
//查询出管段码对应的多焊口列表
var detList = Context.Queryable<bus_workOrder_detail, base_material>((b, c) => new
JoinQueryInfos(JoinType.Left, b.weldMaterCode == c.materialCode))
.Where((b, c) => b.barCode == pipe
&& b.workCenterCode == EnumoprSequenceCode.焊接
&& b.state == (int)EnumOrderBodyStatus.初始化
&& !string.IsNullOrEmpty(b.weldMaterCode)
&& c.isDelete == (int)EnumtIsValid.是)
.Select((b, c) => new workOrderDet
{
id = b.id,
headKeys = b.headKeys.ToString(),
bodyKeys = b.bodyKeys.ToString(),
extendComp1 = b.extendComp1,
materialName = c.materialName,
weldMaterCode = b.weldMaterCode,
cutMaterCode = b.cutMaterCode,
pipelength = b.cuttingLength.ToString()
}
).ToList();
var weldMaterCodeList = detList.Where(x => string.IsNullOrEmpty(x.materialName)).Select(x => x.weldMaterCode).ToList();
if (weldMaterCodeList.Count != 0)
{
response.ResponseErr($"物料数据缺少,物料码【{weldMaterCodeList.ToJson(",")}】!");
return response;
}
if (detList.Count == 0)
{
response.ResponseErr($"管段码【{pipe}】未查询到焊接数据!");
return response;
}
workOrderHead wHead = new workOrderHead();
if (detList.Count > 0)
{
var material = Context.Queryable<base_material>()
.Where(x => x.materialCode == detList[0].cutMaterCode && x.isDelete == (int)EnumtIsValid.是).First();
if (material == null)
{
response.ResponseErr($"物料码【{detList[0].cutMaterCode}】未查询到物料数据!");
return response;
}
var result = Context.Queryable<bus_workOrder_head>().Where(x => x.keys.ToString() == detList[0].headKeys).First();
if (result == null)
{
response.ResponseErr($"未查询到工单主数据!");
return response;
}
if (material != null)
{
wHead.barCode = pipe;
wHead.materialName = material.materialName;
wHead.pipelength = detList[0].pipelength;
}
wHead.teamList = detList;
}
response.Result = wHead;
return response;
});
}
/// <summary>
/// 获取焊接开始列表
/// </summary>
/// <returns></returns>
public dynamic GetWeldStartList(string station)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
if (string.IsNullOrWhiteSpace(station))
{
response.ResponseErr($"工位码为空,请扫描工位码!");
return response;
}
//工位信息
var equipment = base.Context.Queryable<base_work_station>().Where(x => x.workStationCode == station).First();
if (equipment == null)
{
return response.ResponseError($"工位码【{station}】未找到工位信息,请配置!");
}
//查询出焊接生产中的工序任务
var detList = Context.Queryable<bus_workOrder_detail, base_material>((b, c) => new
JoinQueryInfos(JoinType.Left, b.weldMaterCode == c.materialCode))
.Where((b, c) => b.workCenterCode == EnumoprSequenceCode.焊接
&& b.state == (int)EnumOrderBodyStatus.生产中
&& c.isDelete == (int)EnumtIsValid.是)
.Select((b, c) => new workOrderDet
{
id = b.id,
headKeys = b.headKeys.ToString(),
bodyKeys = b.bodyKeys.ToString(),
extendComp1 = b.extendComp1,
materialName = c.materialName,
cutMaterCode = b.cutMaterCode,
stationCode = b.stationCode,
barCode = b.barCode,
pipelength = b.cuttingLength.ToString()
}
).ToList();
var headKeyList = detList.GroupBy(x => x.headKeys).ToList();
List<workOrderHead> wHeadList = new List<workOrderHead>();
foreach (var headKey in headKeyList)
{
workOrderHead workH = new workOrderHead();
workH.teamList = new List<workOrderDet>();
var item = Context.Queryable<bus_workOrder_head>().Where(x => x.keys.ToString() == headKey.Key).First();
foreach (var detail in detList)
{
if (detail.headKeys == headKey.Key)
{
workH.teamList.Add(detail);
workH.barCode = detail.barCode;
}
}
var material = Context.Queryable<base_material>()
.Where(x => x.materialCode == workH.teamList[0].cutMaterCode && x.isDelete == (int)EnumtIsValid.是).First();
if (material != null)
{
workH.materialName = material.materialName;
workH.pipelength = detList[0].pipelength;
}
wHeadList.Add(workH);
}
response.Result = wHeadList;
return response;
});
}
/// <summary>
/// 保存焊接开始列表
/// </summary>
/// <returns></returns>
public dynamic SaveWeldStartList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.stationCode = item.stationCode;
resultItem.actualStartTime = DateTime.Now;
resultItem.state = (int)EnumOrderBodyStatus.生产中;
resultItem.updateBy = sysUserApi?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).AddQueue();
}
else
{
response.ResponseErr($"未查询到工序焊接任务信息!");
return response;
}
}
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
/// <summary>
/// 保存焊接结束列表
/// </summary>
/// <returns></returns>
public dynamic SaveWeldEndList(List<bus_workOrder_detail> details)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
CutWeldService cutWeldService = new CutWeldService();
foreach (var item in details)
{
var resultItem = Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == item.bodyKeys).First();
if (resultItem != null)
{
resultItem.state = (int)EnumOrderBodyStatus.已完成;
resultItem.actualEndTime = DateTime.Now;
resultItem.updateBy = sysUserApi?.Account;
resultItem.updateTime = DateTime.Now;
resultItem.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
Context.Updateable(resultItem).AddQueue();
}
else
{
response.ResponseErr($"未查询到工序焊接任务信息!");
return response;
}
//工序完工反馈
cutWeldService.SendIWPTechnologylineProcess(resultItem.barCode, (int)EnumCutHeadState.焊接完成);
}
var resultCount = Context.SaveQueues();
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
/// <summary>
/// 焊接工艺下发保存
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <param name="barCode">管段码</param>
/// <returns></returns>
public dynamic SaveWeldTechnology(string equipmentCode, string barCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode) || string.IsNullOrWhiteSpace(barCode))
{
return response.ResponseError($"设备编码或管段码为空,请重新扫描!");
}
//设备信息
var equipment = base.Context.Queryable<base_work_station>().Where(x => x.workStationCode == equipmentCode).First();
if (equipment == null)
{
return response.ResponseError($"设备编码{equipmentCode}在设备表中没有找到!");
}
//工序任务明细
var resultItem = base.Context.Queryable<bus_workOrder_detail>().Where(x => x.barCode == barCode).First();
if (equipment == null)
{
return response.ResponseError($"barCode:【{barCode}】不存在工序任务明细表中,请核对!");
}
//物料信息
var material = base.Context.Queryable<base_material>().Where(x => x.materialCode == resultItem.cutMaterCode && x.isDelete == (int)EnumtIsValid.是).First();
if (equipment == null)
{
return response.ResponseError($"barCode:【{barCode}】对应物料没有信息,请核对!");
}
//焊接工艺参数
var Equipment = new base_weld_technology_equipment()
{
technologyHeadId = 0,
equipmentCode = equipmentCode,
createBy = sysUserApi?.Account,
createTime = DateTime.Now.ToString(),
sendStatus = 0,
minDiameter = material.diameter,
minThickness = material.thickness,
minWeldingSeam = "0",
material = material.types,
pipelength = resultItem.cuttingLength.ToString(),
taskNo = barCode
};
switch (Equipment.material)
{
case "碳钢": Equipment.material = "1"; break;
case "不锈钢": Equipment.material = "2"; break;
case "合金钢": Equipment.material = "3"; break;
case "多重钢": Equipment.material = "4"; break;
default: Equipment.material = "1"; break;
}
response.Status = Add(Equipment);
response.Message = $"设备({equipment.workStationName})参数下发成功!";
return response;
});
}
/// <summary>
/// 批次码获取物料信息
/// </summary>
/// <param name="lotNo">批次码</param>
/// <returns></returns>
public dynamic GetMaterialBylotNo(string lotNo)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(lotNo))
{
return response.ResponseError($"批次码为空,请重新扫描!");
}
//调用上游接口查询批次码对应的物料码
//物料信息
var material = base.Context.Queryable<base_material>().Where(x => x.materialCode == lotNo && x.isDelete == (int)EnumtIsValid.是).First();
if (material == null)
{
return response.ResponseError($"批次码{lotNo}在系统表中没有找到对应的物料信息!");
}
response.Result = material;
return response;
});
}
/// <summary>
/// 设备编码获取设备信息
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <returns></returns>
public dynamic GetEquipmentByCode(string equipmentCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode))
{
return response.ResponseError($"设备编码为空,请重新扫描!");
}
//设备信息
var equipment = base.Context.Queryable<base_equipment>().Where(x => x.code == equipmentCode).First();
if (equipment == null)
{
return response.ResponseError($"设备编码{equipmentCode}没有找到对应的设备信息!");
}
//获取焊接类型ID
var equipmentType = base.Context.Queryable<base_equipment_type>().Where(x => x.code == EnumoprSequenceCode.焊接).First();
if (equipmentType == null)
{
return response.ResponseError($"焊接类型在系统中未配置!");
}
//判断设备是否为焊机,只有焊机可以呼叫AGV
if (equipment.equipmentTypeId != equipmentType.id)
{
return response.ResponseError($"只有焊机工位可以呼叫AGV!");
}
//AGV呼叫记录
var agvCalllog = base.Context.Queryable<bus_agvCall_log>().Where(x => x.callState == (int)EnumAgvCallState.接料中).First();
if (agvCalllog != null)
{
equipment.callState = (int)EnumAgvCallState.接料中;
equipment.equipmentNmae = agvCalllog.equipmentNmae;
}
else
{
equipment.callState = (int)EnumAgvCallState.初始;
equipment.equipmentNmae = "无";
}
response.Result = equipment;
return response;
});
}
/// <summary>
/// Agv接料完成
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <returns></returns>
public dynamic AgvCollectingEnd(string equipmentCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode))
{
return response.ResponseError($"设备编码为空,请重新扫描!");
}
//设备信息
var equipment = base.Context.Queryable<base_equipment>().Where(x => x.code == equipmentCode).First();
if (equipment == null)
{
return response.ResponseError($"设备编码{equipmentCode}没有找到对应的设备信息!");
}
//获取焊接类型ID
var equipmentType = base.Context.Queryable<base_equipment_type>().Where(x => x.code == EnumoprSequenceCode.焊接).First();
if (equipmentType == null)
{
return response.ResponseError($"焊接类型在系统中未配置!");
}
//判断设备是否为焊机,只有焊机可以呼叫AGV
if (equipment.equipmentTypeId != equipmentType.id)
{
return response.ResponseError($"只有焊机工位可以呼叫AGV!");
}
//AGV呼叫记录
var agvCalllog = base.Context.Queryable<bus_agvCall_log>().Where(x => x.callState == (int)EnumAgvCallState.接料中).First();
if (agvCalllog == null)
{
return response.ResponseError($"AGV没有在接料,不能进行此操作!");
}
if (agvCalllog.equipmentCode != equipmentCode)
{
return response.ResponseError($"确保误操作与安全,请扫描正在接料的工位,再操作接料完成!");
}
agvCalllog.callState = (int)EnumAgvCallState.接料完成;
agvCalllog.updateTime = DateTime.Now;
base.Context.Updateable(agvCalllog).ExecuteCommand();
response.Result = "";
response.Message = "AGV接料完成操作成功!";
return response;
});
}
/// <summary>
/// 呼叫Agv接料
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <returns></returns>
public dynamic AgvCollectingStart(string equipmentCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode))
{
return response.ResponseError($"设备编码为空,请重新扫描!");
}
//设备信息
var equipment = base.Context.Queryable<base_equipment>().Where(x => x.code == equipmentCode).First();
if (equipment == null)
{
return response.ResponseError($"设备编码{equipmentCode}没有找到对应的设备信息!");
}
//获取焊接类型ID
var equipmentType = base.Context.Queryable<base_equipment_type>().Where(x => x.code == EnumoprSequenceCode.焊接).First();
if (equipmentType == null)
{
return response.ResponseError($"焊接类型在系统中未配置!");
}
//判断设备是否为焊机,只有焊机可以呼叫AGV
if (equipment.equipmentTypeId != equipmentType.id)
{
return response.ResponseError($"只有焊机工位可以呼叫AGV!");
}
//AGV呼叫记录
var agvCalllog = base.Context.Queryable<bus_agvCall_log>().Where(x => x.callState == (int)EnumAgvCallState.接料中).First();
if (agvCalllog != null)
{
return response.ResponseError($"AGV正在{agvCalllog.equipmentNmae}接料,不能呼叫!");
}
var requestData = new
{
stationCode = equipmentCode,
userCode = ""
};
//发送WMS-AGV接料 url = "http://172.16.29.881:9100/api/WMS/CallEmptyContainer";
var url = GetDictionaryDictValue("UrlWCSCallEmptyContainer", "GetUrl");
var WCSresponse = HttpManWCS(url, requestData, EnumLog.WCS接口调用.ToString(), method: "post");
if (WCSresponse.Code == 200)
{
var busAgvCalllog = new bus_agvCall_log();
busAgvCalllog.equipmentNmae = equipment.name;
busAgvCalllog.equipmentCode = equipment.code;
busAgvCalllog.callState = (int)EnumAgvCallState.接料中;
busAgvCalllog.createTime = DateTime.Now;
base.Context.Insertable(busAgvCalllog).ExecuteCommand();
response.Result = "";
response.Message = "呼叫AGV接料成功!";
return response;
}
else
{
//var WcsResult = DynamicJson.Parse(WCSresponse.Result);
return response.ResponseError($"呼叫AGV接料失败!{WCSresponse.Result}");
}
});
}
/// <summary>
/// 托盘入库
/// </summary>
/// <param name="containerCode">托盘码</param>
/// <returns></returns>
public dynamic ContainerTransfer(string containerCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(containerCode))
{
return response.ResponseError($"托盘码为空,请重新扫描!");
}
//AGV呼叫记录
var agvCalllog = base.Context.Queryable<bus_agvCall_log>().Where(x => x.callState == (int)EnumAgvCallState.接料中).First();
if (agvCalllog != null)
{
return response.ResponseError($"AGV正在{agvCalllog.equipmentNmae}接料,不能回库,需要先完成agv接料状态!");
}
var requestData = new
{
containerCode = containerCode,
inLocationCode = ""
};
//发送WMS-托盘入库 url = "http://10.193.244.156:8066/api/WMS/ContainerTransfer";
var url = GetDictionaryDictValue("UrlWCSContainerTransfer", "GetUrl");
var WCSresponse = HttpManWCS(url, requestData, EnumLog.WCS接口调用.ToString(), method: "post");
if (WCSresponse.Code == 200)
{
response.Result = "";
response.Message = "托盘入库成功!";
return response;
}
else
{
return response.ResponseError($"托盘入库失败!{WCSresponse.Result}");
}
});
}
/// <summary>
/// 设备任务下发
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <param name="taskNumber">管段码</param>
/// <returns></returns>
public dynamic EquipmentTaskDistribute(string equipmentCode, string taskNumber)
{
var response = new Response(true);
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode) || string.IsNullOrWhiteSpace(taskNumber))
return response.ResponseError($"设备编码或任务号为空,请重新扫描!");
if (equipmentCode == EquipmentCode.组焊平台)
return response.ResponseError($"3D组焊平台没有在线设备,不能下发任务,只能直接完成!");
//设备信息
var equipment = base.Context.Queryable<base_equipment>().Where(x => x.code == equipmentCode).First();
if (equipment == null)
return response.ResponseError($"设备编码{equipmentCode}在设备表中没有找到!");
var oprSequenceCode = "";
if (equipmentCode == EquipmentCode.锯床)
oprSequenceCode = EnumoprSequenceCode.切割;
if (equipmentCode == EquipmentCode.端面坡口机)
oprSequenceCode = EnumoprSequenceCode.坡口;
if (equipmentCode == EquipmentCode.机器人打磨)
oprSequenceCode = EnumoprSequenceCode.打磨;
if (equipmentCode == EquipmentCode.机器人XY焊接)
oprSequenceCode = EnumoprSequenceCode.焊接;
if (equipmentCode == EquipmentCode.组焊一体机)
oprSequenceCode = EnumoprSequenceCode.焊接;
if (equipmentCode == EquipmentCode.组焊平台)
oprSequenceCode = EnumoprSequenceCode.组对;
//工序任务明细
var resultItem = base.Context.Queryable<bus_workOrder_detail>().Where(x => x.barCode == taskNumber && x.oprSequenceCode == oprSequenceCode).First();
if (resultItem == null)
return response.ResponseError($"taskNumber:【{taskNumber}】不存在工序任务明细表中,请核对!");
if (resultItem.state >= (int)EnumOrderHeadStatus.生产中)
return response.ResponseError($"taskNumber:【{taskNumber}】任务已经下发,请勿重复操作!");
if (equipmentCode == EquipmentCode.机器人打磨)
{
//机器人打磨需要交互
if (!robotDeviceStatus())
{
return response.ResponseError($"机器人运行中或未开机!");
}
//参数下发
else
{
var pipe = PipeInfo(resultItem.cutMaterCode);
if (!string.IsNullOrEmpty(pipe) && pipe != "Success")
{
return response.ResponseError($"{pipe}");
}
}
}
//更新工单明细
resultItem.state = (int)EnumOrderHeadStatus.生产中;
resultItem.actualStartTime = DateTime.Now;
resultItem.updateBy = sysUserApi?.Account;
resultItem.updateTime = DateTime.Now;
Context.Updateable(resultItem).UpdateColumns(t => new { t.state, t.actualStartTime, t.updateBy, t.updateTime }).AddQueue();
//更新工单
Context.Updateable<bus_workOrder_head>()
.SetColumns(x => x.state == (int)EnumOrderHeadStatus.生产中)
.SetColumns(x => x.actualStartTime == DateTime.Now)
.Where(x => x.keys == resultItem.headKeys).AddQueue();
//设备任务表
var Equipment = new base_task_equipment()
{
equipmentCode = equipmentCode,
taskCode = taskNumber,
sendStatus = (int)EnumWeldTechnologyEquipmentStatus.初始,
createBy = sysUserApi?.Account,
createTime = DateTime.Now
};
Context.Insertable(Equipment).AddQueue();
var inContext = Context.SaveQueues();
if (inContext > 0)
response.Message = $"设备({equipment.name})任务下发成功!";
else
return response.ResponseError($"设备({equipment.name})任务下发失败!");
return response;
});
}
//机器人状态判断
public bool robotDeviceStatus()
{
var url = GetDictionaryDictValue("DeviceStatus", "robotURL");
var response = HttpManPipe(url);
if (response != "" && response == "False")
{
return true;
}
return false;
}
//机器人打磨参数下发
public string PipeInfo(string materialCode)
{
var item = base.Context.Queryable<base_material>().Where(x => x.materialCode == materialCode && x.isDelete == (int)EnumtIsValid.是).First();
if (string.IsNullOrEmpty(item.diameter) || item.diameter == "0" || string.IsNullOrEmpty(item.thickness) || item.thickness == "0")
{
return "管径与壁厚数据缺少,需要上游维护下发!";
}
//默认为管
var currentPipeType = "SMLS";
if (item.materialName.IndexOf("三通") > -1 || item.specifications.IndexOf("三通") > -1)
{
currentPipeType = "Tee";
}
else if (item.materialName.IndexOf("法兰") > -1 || item.specifications.IndexOf("法兰") > -1)
{
currentPipeType = "Flange";
}
else if (item.materialName.IndexOf("弯头") > -1 || item.specifications.IndexOf("弯头") > -1)
{
currentPipeType = "Elbow";
}
var url = GetDictionaryDictValue("PipeInfo", "robotURL");
url = $"{url}?currentPipeType={currentPipeType}¤tPipeThick={item.diameter}¤tPipeDiameter={item.thickness}";
var response = HttpManPipe(url);
return response;
}
/// <summary>
/// 设备任务列表查询
/// </summary>
/// <param name="equipmentCode">设备编码</param>
/// <param name="state">查询状态:0未完成,30进行中,100已经完成</param>
/// <returns></returns>
public dynamic GetEquipmentTaskList(string equipmentCode, int state)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(equipmentCode) || state < 0)
return response.ResponseError($"设备编码或查询状态为空!");
//设备信息
if (equipmentCode != EquipmentCode.组焊平台)
{
var equipment = base.Context.Queryable<base_equipment>().Where(x => x.code == equipmentCode).First();
if (equipment == null)
return response.ResponseError($"设备编码{equipmentCode}在设备表中没有找到!");
}
var oprSequenceCode = "";
var orderType = 0;
if (equipmentCode == EquipmentCode.锯床)
{
oprSequenceCode = EnumoprSequenceCode.切割;
orderType = (int)EnumOrderType.成品件生产订单;
}
if (equipmentCode == EquipmentCode.端面坡口机)
{
oprSequenceCode = EnumoprSequenceCode.坡口;
orderType = (int)EnumOrderType.成品件生产订单;
}
if (equipmentCode == EquipmentCode.机器人打磨)
{
oprSequenceCode = EnumoprSequenceCode.打磨;
orderType = (int)EnumOrderType.机器人打磨;
}
if (equipmentCode == EquipmentCode.机器人XY焊接)
{
oprSequenceCode = EnumoprSequenceCode.焊接;
orderType = (int)EnumOrderType.成品件生产订单;
}
if (equipmentCode == EquipmentCode.组焊一体机)
{
oprSequenceCode = EnumoprSequenceCode.焊接;
orderType = (int)EnumOrderType.成品件生产订单;
}
if (equipmentCode == EquipmentCode.组焊平台)
{
oprSequenceCode = EnumoprSequenceCode.组对;
orderType = (int)EnumOrderType.成品件生产订单;
}
if (oprSequenceCode == "")
return response.ResponseError($"设备编码错误!");
//获取列表
var taskList = Context.Queryable<bus_workOrder_head, bus_workOrder_detail, base_material>((a, b, c) => new JoinQueryInfos(
JoinType.Left, a.keys == b.headKeys, JoinType.Left, b.cutMaterCode == c.materialCode))
.Where((a, b, c) => a.orderType == orderType.ToString()
&& b.oprSequenceCode == oprSequenceCode
&& b.state == state
&& a.isScrap == false
&& SqlFunc.Between(DateTime.Now, a.planStartTime, a.planEndTime)
&& c.isDelete == (int)EnumtIsValid.是)
.Select((a, b, c) => new
{
a.orderType,
a.planStartTime,
a.planEndTime,
b.oprSequenceName,
b.oprSequenceCode,
b.state,
b.cutMaterCode,
b.cuttingLength,
b.designUrl,
b.weldNo,
b.barCode,
c.materialName
}).ToList();
response.Result = taskList;
return response;
});
}
#endregion
#region 工位任务
/// <summary>
/// 工位任务列表查询(自动线,组对与焊接)
/// </summary>
/// <param name="workCenterCode">工作中心</param>
/// <returns></returns>
public dynamic GetTaskList(string workCenterCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(workCenterCode))
{
return response.ResponseError($"工作中心编码不能为空!");
}
//获取列表
var taskList = Context.Queryable<bus_workOrder_detail, bus_workOrder_head, base_material>((a, b, c) => new JoinQueryInfos(
JoinType.Left, a.headKeys == b.keys, JoinType.Left, a.cutMaterCode == c.materialCode
)).Where((a, b, c) =>
a.oprSequenceCode == workCenterCode
&& a.state == (int)EnumOrderBodyStatus.运输中
&& b.orderType == ((int)EnumProOrderType.正常订单).ToString()
&& c.isDelete == (int)EnumtIsValid.是
).Select((a, b, c) => new
{
b.orderType,
b.planStartTime,
b.planEndTime,
a.oprSequenceName,
a.oprSequenceCode,
a.state,
a.cutMaterCode,
a.cuttingLength,
a.designUrl,
a.weldNo,
a.barCode,
c.materialName
}).ToList();
var barCodeList = taskList.Select(x => x.barCode).Distinct().ToList();
var workOrderDetailList = Context.Queryable<bus_workOrder_detail>()
.Where(x => x.oprSequenceCode == EnumoprSequenceCode.套料 && barCodeList.Contains(x.barCode))
.Select(x => new { x.barCode, x.cuttingLength }).ToList();
taskList = taskList.Join(workOrderDetailList, task => task.barCode, detail => detail.barCode,
(task, detail) => new
{
task.orderType,
task.planStartTime,
task.planEndTime,
task.oprSequenceName,
task.oprSequenceCode,
task.state,
task.cutMaterCode,
detail.cuttingLength,
task.designUrl,
task.weldNo,
task.barCode,
task.materialName
}).ToList();
response.Result = taskList;
return response;
});
}
/// <summary>
/// 新增扫码记录
/// </summary>
/// <param name="stationCode">工位码</param>
/// <param name="barCode">管段码</param>
public void scanRecord(string stationCode, string barCode)
{
var station = base.Context.Queryable<base_work_station>().Where(x => x.workStationCode == stationCode).First();
if (station == null)
{
return;
}
//先把当前工位的扫码记录改为过期,超过10分的扫码记录也设置为过期
Context.Updateable<base_scan_record>()
.SetColumns(x => x.state == 1)
.Where(x => x.stationCode == station.workCenterCode)
.AddQueue();
var scanRecord = new base_scan_record();
scanRecord.stationCode = station.workCenterCode;
scanRecord.barCode = barCode;
scanRecord.state = 0;
scanRecord.createTime = DateTime.Now;
scanRecord.createBy = sysUserApi?.Account;
Context.Insertable(scanRecord).AddQueue();
Context.SaveQueues();
}
/// <summary>
/// 获取扫码记录
/// </summary>
/// <param name="workCenterCode">工作中心</param>
/// <returns></returns>
public dynamic GetScanRecord(string workCenterCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
if (string.IsNullOrWhiteSpace(workCenterCode))
{
return response.ResponseError($"工位编码为空!");
}
//先把当前工位的扫码记录改为过期,超过10分的扫码记录也设置为过期
var time = DateTime.Now.AddMinutes(-10);
Context.Updateable<base_scan_record>()
.SetColumns(x => x.state == 1)
.Where(x => x.stationCode == workCenterCode && time > x.createTime)
.ExecuteCommand();
var scanRecord = base.Context.Queryable<base_scan_record>().Where(x => x.stationCode == workCenterCode && x.state == 0).First();
response.Result = scanRecord;
return response;
});
}
#endregion
/// <summary>
/// 工序问题记录
/// </summary>
/// <returns></returns>
public dynamic SetProblem(dynamic requestData)
{
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
var reqData = DynamicJson.Parse(requestData.ToString());
var response = new POJO.Response.Response();
if (reqData == null || !reqData.IsDefined("barCode"))
{
return response.ResponseError($"barCode:参数字段不正确,请核对!");
}
string barCode = reqData.barCode;
string problem = reqData.problem;
string oprSequenceCode = reqData.oprSequenceCode;
if (string.IsNullOrEmpty(barCode)) return response.ResponseError($"管段码不能为空,请核对!");
if (string.IsNullOrEmpty(problem)) return response.ResponseError($"问题原因不能为空,请核对!");
if (string.IsNullOrEmpty(oprSequenceCode)) return response.ResponseError($"工序不能为空,请核对!");
//1:扫码 BarCode 查询bus_workOrder_detail 表确认BarCode是否存在。
var bwdInfo = Context.Queryable<bus_workOrder_detail>().First(x => x.barCode == barCode && x.oprSequenceCode == oprSequenceCode);
if (bwdInfo == null || string.IsNullOrEmpty(bwdInfo.barCode))
{
return response.ResponseError($"barCode:【{barCode}】不存在工序任务明细表中,请核对!");
}
//2:根据BarCode 查询到当前行的 materialCode,在去物料表查询 返回物料表的基础信息。
var materialInfo = Context.Queryable<base_material>().First(x => x.materialCode == bwdInfo.cutMaterCode && x.isDelete == (int)EnumtIsValid.是);
var workOrderDetail = Context.Queryable<bus_workOrder_detail>()
.Where(x => x.oprSequenceCode == EnumoprSequenceCode.套料 && x.barCode == barCode).First();
var procedureProblem = new base_procedure_problem();
procedureProblem.barCode = barCode;
procedureProblem.problem = problem;
procedureProblem.oprSequenceCode = oprSequenceCode;
procedureProblem.createTime = DateTime.Now;
procedureProblem.createBy = sysUserApi?.Account;
procedureProblem.materialCode = bwdInfo.cutMaterCode;
procedureProblem.oprSequenceName = bwdInfo.oprSequenceName;
procedureProblem.cuttingLength = workOrderDetail.cuttingLength;
procedureProblem.materialName = materialInfo.materialName;
procedureProblem.types = materialInfo.types;
procedureProblem.thickness = materialInfo.thickness;
procedureProblem.diameter = materialInfo.diameter;
procedureProblem.specifications = materialInfo.specifications;
procedureProblem.designUrl = bwdInfo.designUrl;
Context.Insertable(procedureProblem).ExecuteCommand();
return response;
});
}
#region 物料到达
/// <summary>
/// PDA扫码物料到达
/// </summary>
/// <param name="workStationCode">工位码</param>
/// <param name="pipeSN">管材SN</param>
public dynamic MaterialReach(string workStationCode, string pipeSN)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(workStationCode)) { return response.ResponseError($"工位码不能为空,请核对!"); }
if (string.IsNullOrEmpty(pipeSN)) { return response.ResponseError($"管材SN不能为空,请核对!"); }
var station = Context.Queryable<base_work_station>().Where(x => x.workStationCode == workStationCode).First();
if (station == null) { return response.ResponseError($"【{workStationCode}】工位码不存在,请核对!"); }
var inventory = Context.Queryable<base_inventory>().Where(x => x.pipeSN == pipeSN).First();
if (inventory == null) { return response.ResponseError($"【{pipeSN}】查询不到库存,请核对!"); }
if (inventory.useState != (int)InventoryUseState.已套料) { return response.ResponseError($"【{pipeSN}】未套料,请核对!"); }
var cutplanHead = Context.Queryable<bus_cutplan_head>().Where(x =>
x.lotNo == pipeSN
&& x.state == (int)EnumCutPlanHeadStatus.初始
&& x.workCenterCode == station.workCenterCode).First();
if (cutplanHead == null) { return response.ResponseError($"【{pipeSN}】未查询到匹配的切割方案!"); }
inventory.useState = (int)InventoryUseState.使用完毕;
inventory.updateBy = sysUserApi?.Account;
inventory.updateTime = DateTime.Now;
Context.Updateable(inventory).AddQueue();
cutplanHead.state = (int)EnumCutPlanHeadStatus.下料开始;
cutplanHead.updateBy = sysUserApi?.Account;
cutplanHead.updateTime = DateTime.Now.ToString();
Context.Updateable(cutplanHead).AddQueue();
response.Status = Context.SaveQueues() > 0;
if (response.Status)
{
response.Code = 200;
response.Message = $"【{pipeSN}】物料到达操作成功,到达工位【{station.workStationName}】";
return response;
}
else
{
return response.ResponseError($"数据库操作失败!");
}
});
}
/// <summary>
/// 查询库存物料
/// </summary>
/// <param name="pipeSN">管材SN</param>
public dynamic GetInventoryByPipeSN(string pipeSN)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(pipeSN)) { return response.ResponseError($"管材SN不能为空,请核对!"); }
var inventory = Context.Queryable<base_inventory>().Where(x => x.pipeSN == pipeSN).First();
if (inventory == null) { return response.ResponseError($"【{pipeSN}】查询不到库存,请核对!"); }
var inventoryNew = Context.Queryable<base_inventory, base_material>((a, b) => new JoinQueryInfos(
JoinType.Left, a.materialCode == b.materialCode))
.Where((a, b) => a.pipeSN == pipeSN && b.isDelete == (int)EnumtIsValid.是)
.Select((a, b) => new
{
a.pipeSN,
a.materialCode,
a.pipeLength,
b.materialName,
b.diameter,
b.thickness
}).First();
response.Result = inventoryNew;
return response;
});
}
#endregion
#region 质检
/// <summary>
/// 质检任务查询
/// </summary>
/// <param name="workCenterCode">工序code</param>
/// <param name="barCode">管段码</param>
/// <returns></returns>
public dynamic GetqualityStencilList(string workCenterCode, string barCode)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(workCenterCode)) { return response.ResponseError($"工序Code不能为空,请核对!"); }
//获取列表
var list = Context.Queryable<base_qualityStencil_Execute, bus_workOrder_detail, base_qualityStencil_detail>((a, b, c) => new JoinQueryInfos(
JoinType.Left, a.workOrderDetailKey == b.bodyKeys, JoinType.Left, a.qualityDetailKey == c.keys))
.Where((a, b, c) =>
a.isExecute == (int)EnumQualityisExecute.是
&& a.state == (int)EnumQuality.启用
&& b.workCenterCode == workCenterCode
&& a.executeResult == (int)EnumQualityExecute.未执行
).Select((a, b, c) => new
{
a.keys,
b.oprSequenceName,
b.barCode,
c.describe
}
).ToList();
if (!string.IsNullOrEmpty(barCode))
{
list = list.Where(x => x.barCode == barCode).ToList();
}
response.Result = list;
return response;
});
}
/// <summary>
/// 质检执行
/// </summary>
/// <param name="keys">keys 多个用逗号隔开</param>
/// <param name="executeResult">执行结果 10合格,20不合格</param>
/// <param name="executeUser">执行人</param>
/// <returns></returns>
public dynamic QualityStencilExecute(QualityExecute qualityExecute)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(qualityExecute.keys)) { return response.ResponseError($"keys不能为空,请核对!"); }
var keysStr = qualityExecute.keys.Split(",");
//更新
var upCount = Context.Updateable<base_qualityStencil_Execute>()
.SetColumns(x => x.isExecute == (int)EnumQualityisExecute.否)
.SetColumns(x => x.executeResult == qualityExecute.executeResult)
.SetColumns(x => x.executeUser == qualityExecute.executeUser)
.SetColumns(x => x.executeTime == DateTime.Now)
.SetColumns(x => x.updateTime == DateTime.Now)
.Where(x => keysStr.Contains(x.keys.ToString())).ExecuteCommand();
if (upCount <= 0)
{
return response.ResponseError($"操作失败!");
}
return response;
});
}
#endregion
#region 上料
/// <summary>
/// 上料任务查询(只返回20条数据)
/// </summary>
/// <param name="equipmentCode">工位编码</param>
/// <returns></returns>
public dynamic GetLoaderTaskList(string equipmentCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"工位编码不能为空,请核对!");
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
//获取列表
var list = Context.Queryable<base_loader_task, base_material>((a, b) => new JoinQueryInfos(
JoinType.Left, a.materialCode == b.materialCode))
.Where((a, b) => a.equipmentCode == equipmentCode && a.loaderStatus != (int)EnumLoaderTask.过期 && b.isDelete == (int)EnumtIsValid.是)
.Select((a, b) => new
{
a.id,
a.equipmentCode,
a.taskCode,
a.materialCode,
a.loaderNum,
a.feedbackNum,
a.loaderStatus,
a.consumeNum,
b.materialName,
a.createTime
}).OrderBy((a) => a.createTime, OrderByType.Desc).Take(20).ToList();
response.Result = list;
response.Count = list.Count;
return response;
});
}
/// <summary>
/// 物料查询(只返回20条数据)
/// </summary>
/// <param name="Code">code</param>
/// <returns></returns>
public dynamic GetMaterialList(string Code)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
var loaderTask = Context.Queryable<base_material>()
.Where(x => x.isDelete == (int)EnumtIsValid.是)
.WhereIF(!string.IsNullOrEmpty(Code), x => x.materialCode.Contains(Code) || x.materialName.Contains(Code) || x.specifications.Contains(Code))
.Take(20).ToList();
response.Result = loaderTask;
response.Count = loaderTask.Count;
return response;
});
}
/// <summary>
/// 上料任务新增
/// </summary>
/// <param name="equipmentCode">工位编码</param>
/// <param name="materialCode">物料码</param>
/// <param name="Num">数量</param>
/// <returns></returns>
public dynamic InLoaderTask(string equipmentCode, string materialCode, int Num)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"工位编码不能为空,请核对!");
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
if (string.IsNullOrEmpty(materialCode))
{
return response.ResponseError($"物料编码不能为空,请核对!");
}
var material = Context.Queryable<base_material>().First(x => x.materialCode == materialCode && x.isDelete == (int)EnumtIsValid.是);
if (material == null)
{
return response.ResponseError($"物料编码未查询到物料数据,请核对!");
}
if (Num <= 0)
{
return response.ResponseError($"上料数量为0,请核对!");
}
var loaderTaskList = Context.Queryable<base_loader_task>()
.Where(x => x.equipmentCode == equipmentCode && x.loaderStatus < (int)EnumLoaderTask.成功 && x.extend1 == ((int)EnumLoaderTaskType.原料上架).ToString()).ToList();
if (loaderTaskList.Count > 0)
{
return response.ResponseError($"有上料任务未完成,请稍后新增任务!");
}
var cutList = Context.Queryable<bus_cutplan_detail>().First(x => x.extend4.ToUpper() == equipment.lineCode.ToUpper() && x.cutState < 30 && string.IsNullOrEmpty(x.measureEndTime));
if (cutList != null)
{
return response.ResponseError($"除锈喷码未完成,请稍后新增任务!");
}
DateTime now = DateTime.Now;
string taskCode = now.ToString("yyyyMMddHHmmss");
var loaderTask = new base_loader_task();
loaderTask.equipmentCode = equipmentCode;
loaderTask.taskCode = taskCode;
loaderTask.materialCode = materialCode;
loaderTask.loaderNum = Num;
loaderTask.feedbackNum = 0;
loaderTask.consumeNum = 0;
loaderTask.loaderStatus = 0;
loaderTask.extend1 = ((int)EnumLoaderTaskType.原料上架).ToString();
if (!string.IsNullOrEmpty(sysUserApi?.Account))
{
loaderTask.createBy = sysUserApi?.Account;
}
else
{
loaderTask.createBy = "system";
}
loaderTask.createTime = now;
loaderTask.updateTime = now;
var inSuccess = Context.Insertable(loaderTask).ExecuteCommand();
if (inSuccess > 0)
{
return response;
}
else
{
return response.ResponseError($"新增任务失败,请稍后新增任务!");
}
});
}
/// <summary>
/// 上料任务取消
/// </summary>
/// <param name="id">id</param>
/// <returns></returns>
public dynamic EscLoaderTask(int id)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (id <= 0)
{
return response.ResponseError($"任务号错误,请核对!");
}
var loaderTask = Context.Queryable<base_loader_task>().Where(x => x.id == id).First();
if (loaderTask.loaderStatus != 0)
{
return response.ResponseError($"上料任务不是初始状态不能取消!");
}
loaderTask.loaderStatus = (int)EnumLoaderTask.过期;
loaderTask.updateTime = DateTime.Now;
if (!string.IsNullOrEmpty(sysUserApi?.Account))
{
loaderTask.createBy = sysUserApi?.Account;
}
var upSuccess = Context.Updateable(loaderTask).ExecuteCommand();
if (upSuccess > 0)
{
return response;
}
else
{
return response.ResponseError($"上料任务取消失败,请稍后再试!");
}
});
}
/// <summary>
/// 余料上架任务新增
/// </summary>
/// <param name="equipmentCode">工位编码</param>
/// <param name="oddCode">余料码,多个余料用竖杆“|”隔开</param>
/// <returns></returns>
public dynamic InLoaderOddTask(string equipmentCode, string oddCodes)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"工位编码不能为空,请核对!");
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
if (string.IsNullOrEmpty(oddCodes))
{
return response.ResponseError($"余料编码不能为空,请核对!");
}
var loaderTaskList = Context.Queryable<base_loader_task>()
.Where(x => x.equipmentCode == equipmentCode && x.loaderStatus < (int)EnumLoaderTask.成功 && x.extend1 == ((int)EnumLoaderTaskType.余料上架).ToString()).ToList();
if (loaderTaskList.Count > 0)
{
return response.ResponseError($"有余料上料任务未完成,请稍后新增任务!");
}
var oddCodeList = oddCodes.Split("|");
foreach (var code in oddCodeList)
{
var cutplanHead = Context.Queryable<bus_cutplan_head>().First(x => x.oddmentsCode == code);
if (cutplanHead == null)
{
return response.ResponseError($"余料编码【{code}】未查询到数据,请核对!");
}
var material = Context.Queryable<base_material>().First(x => x.materialCode == cutplanHead.materialCode && x.isDelete == (int)EnumtIsValid.是);
if (material == null)
{
return response.ResponseError($"物料编码【{cutplanHead.materialCode}】未查询到物料数据,请核对!");
}
var loaderTask = new base_loader_task();
loaderTask.equipmentCode = equipmentCode;
loaderTask.taskCode = code;
loaderTask.materialCode = cutplanHead.materialCode;
loaderTask.loaderNum = 1;
loaderTask.feedbackNum = 0;
loaderTask.consumeNum = 0;
loaderTask.loaderStatus = 0;
loaderTask.extend1 = ((int)EnumLoaderTaskType.余料上架).ToString();
if (!string.IsNullOrEmpty(sysUserApi?.Account))
{
loaderTask.createBy = sysUserApi?.Account;
}
else
{
loaderTask.createBy = "system";
}
loaderTask.createTime = DateTime.Now;
loaderTask.updateTime = DateTime.Now;
Context.Insertable(loaderTask).AddQueue();
}
var inSuccess = Context.SaveQueues();
if (inSuccess > 0)
{
return response;
}
else
{
return response.ResponseError($"新增余料上架任务失败,请稍后新增任务!");
}
});
}
/// <summary>
/// 余料信息查询
/// </summary>
/// <param name="oddCode">余料码</param>
/// <returns></returns>
public dynamic GetOddDetails(string oddCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(oddCode))
{
return response.ResponseError($"余料编码不能为空,请核对!");
}
var cutplanHead = Context.Queryable<bus_cutplan_head>().First(x => x.oddmentsCode == oddCode);
if (cutplanHead == null)
{
return response.ResponseError($"余料编码【{oddCode}】未查询到数据,请核对!");
}
var material = Context.Queryable<base_material>().First(x => x.materialCode == cutplanHead.materialCode && x.isDelete == (int)EnumtIsValid.是);
if (material == null)
{
return response.ResponseError($"物料编码【{cutplanHead.materialCode}】未查询到物料数据,请核对!");
}
var oddDetails = new OddDetails();
oddDetails.oddCode = oddCode;
oddDetails.materialCode = material.materialCode;
oddDetails.materialName = material.materialName;
oddDetails.types = material.types;
oddDetails.diameter = material.diameter;
oddDetails.thickness = material.thickness;
response.Result = oddDetails;
return response;
});
}
#endregion
#region 气动打标任务
/// <summary>
/// 打标任务查询(只返回50条数据)-工位打标
/// </summary>
/// <param name="equipmentCode">工位编码</param>
/// <param name="Status">打标状态 初始 = 0,待下发=5,已下发=10</param>
/// <returns></returns>
public dynamic GetImprintTaskList(string equipmentCode, int Status)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"工位编码不能为空,请核对!");
}
if (Status < 0)
{
return response.ResponseError($"打标状态错误,请核对!");
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
var irwstate = "初始";
if (Status == 5)
{
irwstate = "待下发";
}
else if (Status == 10)
{
irwstate = "已下发";
}
//获取列表
var list = Context.Queryable<base_imprint_task, bus_workOrder_detail, base_material, base_material>((a, b, c, d) =>
new JoinQueryInfos(
JoinType.Left, a.procedureID == b.id,
JoinType.Left, b.weldMaterCode == c.materialCode,
JoinType.Left, b.cutMaterCode == d.materialCode
)).Where((a, b, c, d) => a.equipmentCode == equipmentCode && a.status == Status && c.isDelete == (int)EnumtIsValid.是 && d.isDelete == (int)EnumtIsValid.是)
.Select((a, b, c, d) => new
{
a.id,
a.equipmentCode,
a.barCode,
a.content,
a.status,
b.cuttingLength,
materialName1 = d.materialName,
c.materialName,
a.createTime,
rwstate = irwstate
}).OrderBy((a) => a.createTime, OrderByType.Asc).Take(50).ToList();
response.Result = list;
response.Count = list.Count;
return response;
});
}
/// <summary>
/// 打标任务下发-工位打标
/// </summary>
/// <param name="ID">任务ID</param>
/// <param name="equipmentCode">工位编码</param>
/// <param name="Status">操作状态:0新增,1取消</param>
/// <returns></returns>
public dynamic ImprintTaskIssued(int ID, string equipmentCode, int Status)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (ID < 0)
{
return response.ResponseError($"任务ID错误,请核对!");
}
if (Status < 0)
{
return response.ResponseError($"操作状态错误,请核对!");
}
var imprint = Context.Queryable<base_imprint_task>().First(x => x.id == ID);
if (imprint == null)
{
return response.ResponseError($"任务ID未查询到信息,请核对!");
}
if (string.IsNullOrEmpty(imprint.equipmentCode) && string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"请扫描设备码!");
}
if (!string.IsNullOrEmpty(equipmentCode))
{
imprint.equipmentCode = equipmentCode;
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == imprint.equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
//新增验证
if (Status == (int)EnumEscOrAdd.新增)
{
var imprintList = Context.Queryable<base_imprint_task>()
.Where(x => x.status == (int)EnumImprintTaskType.待下发 && x.equipmentCode == imprint.equipmentCode).ToList();
if (imprintList.Count > 0)
{
return response.ResponseError($"该设备存在待下发任务,不能重复下发!");
}
}
//判断该物料另一个口是否已经打码,如果打码提示去同一设备打码
var imprint1 = Context.Queryable<base_imprint_task>().First(x => x.barCode == imprint.barCode && x.id != imprint.id);
if (Status == (int)EnumEscOrAdd.新增 && imprint1 != null && !string.IsNullOrEmpty(imprint1.equipmentCode) && imprint1.equipmentCode != imprint.equipmentCode)
{
return response.ResponseError($"该管件另一焊口物料已经在【{imprint1.equipmentCode}】设备打码,请去该设备打码!");
}
imprint.status = (int)EnumImprintTaskType.待下发;
if (Status == (int)EnumEscOrAdd.取消)
{
imprint.status = (int)EnumImprintTaskType.初始;
//判断是否已经分配过去向,去向有可能是切割完分配的,就不能清空工位码与工位编号
var orderDetail = Context.Queryable<bus_workOrder_detail>()
.Where(x => x.barCode == imprint.barCode && x.oprSequenceCode == EnumoprSequenceCode.切割).First();
if (orderDetail != null && string.IsNullOrEmpty(orderDetail.stationCode))
{
imprint.equipmentCode = "";
imprint.equipmentNo = "";
}
}
imprint.updateTime = DateTime.Now;
imprint.createBy = sysUserApi?.Account;
Context.Updateable(imprint).ExecuteCommand();
return response;
});
}
/// <summary>
/// 产前打标任务查询(只返回50条数据)
/// </summary>
/// <param name="lineCode">产线</param>
/// <param name="equipmentCode">工位编码</param>
/// <param name="Status">打标状态 初始 = 0,待下发=5,已下发=10</param>
/// <param name="barCode">管段号(模糊搜索)</param>
/// <param name="flowOrientation">流向:L=长管,S=短管</param>
/// <returns></returns>
public dynamic GetPreproductionTaskList(string lineCode, string equipmentCode, int Status, string barCode, string flowOrientation)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
//兼容PDA没更新的情况
if (string.IsNullOrEmpty(flowOrientation))
{
flowOrientation = EnumFlowOrientation.长管装配;
}
if (string.IsNullOrEmpty(lineCode))
{
return response.ResponseError($"请选择产线!");
}
if (Status < 0)
{
return response.ResponseError($"打标状态错误,请核对!");
}
else if (Status > 0)
{
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"查询待下发与已下发的任务需要扫码工位码!");
}
}
if (!string.IsNullOrEmpty(equipmentCode))
{
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
}
var irwstate = "初始";
if (Status == (int)EnumImprintTaskType.待下发)
{
irwstate = "待下发";
}
else if (Status == (int)EnumImprintTaskType.已下发)
{
irwstate = "已下发";
}
//获取列表
var list = Context.Queryable<base_imprint_task, bus_workOrder_detail, base_work_order_head>((a, b, f) =>
new JoinQueryInfos(
JoinType.Left, a.procedureID == b.id,
JoinType.Left, b.headKeys == f.keys
)).Where((a, b, f) => a.lineCode.ToUpper() == lineCode.ToUpper() && a.status == Status && f.flowOrientation1 == flowOrientation)
.Select((a, b, f) => new RMaterial
{
id = a.id,
equipmentCode = a.equipmentCode,
barCode = a.barCode,
content = a.content,
status = a.status,
cuttingLength = b.cuttingLength,
createTime = a.createTime,
rwstate = irwstate,
weldMaterCode = b.weldMaterCode,
cutMaterCode = b.cutMaterCode
}).OrderBy((a) => a.createTime, OrderByType.Asc).ToList();
if (Status == (int)EnumImprintTaskType.初始)
{
list = list.Where(x => string.IsNullOrEmpty(x.equipmentCode)).ToList();
}
if (!string.IsNullOrEmpty(equipmentCode) && Status != (int)EnumImprintTaskType.初始)
{
list = list.Where(x => x.equipmentCode == equipmentCode).ToList();
}
if (!string.IsNullOrEmpty(barCode))
{
list = list.Where(x => x.barCode.Contains(barCode)).ToList();
}
var rList = list.Take(50).ToList();
rList.ForEach(x =>
{
var material1 = Context.Queryable<base_material>().Where(d => d.materialCode == x.weldMaterCode).First();
if (material1 != null)
{
x.materialName1 = material1.materialName;
}
var material2 = Context.Queryable<base_material>().Where(d => d.materialCode == x.cutMaterCode).First();
if (material2 != null)
{
x.materialName = material2.materialName;
}
});
response.Result = rList;
response.Count = list.Count;
return response;
});
}
#endregion
#region 坡口任务
/// <summary>
/// 管段坡口信息查询
/// </summary>
/// <param name="barCode">管段码</param>
/// <returns></returns>
public dynamic GetBevelDet(string barCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(barCode))
{
return response.ResponseError($"管段码不能为空,请核对!");
}
var orderDetailList = Context.Queryable<bus_workOrder_detail>()
.Where(x => x.barCode == barCode && x.oprSequenceCode == EnumoprSequenceCode.坡口).ToList();
if (orderDetailList.Count == 0)
{
return response.ResponseError($"管段码【{barCode}】未查询到坡口信息!");
}
var material = Context.Queryable<base_material>().First(x => x.materialCode == orderDetailList[0].cutMaterCode && x.isDelete == (int)EnumtIsValid.是);
if (material == null)
{
return response.ResponseError($"管段码【{barCode}】物料信息未配置,物料码【{orderDetailList[0].cutMaterCode}】!");
}
var bevelDet = new BevelDetModel();
bevelDet.length = orderDetailList[0].cuttingLength;
bevelDet.materialName = material.materialName;
bevelDet.bevels1 = orderDetailList[0].extendComp2;
bevelDet.bevels2 = orderDetailList[0].extendComp3;
bevelDet.content = "单端坡口";
if (orderDetailList.Count > 1)
{
bevelDet.content = "双端坡口";
}
response.Result = bevelDet;
return response;
});
}
/// <summary>
/// 管段坡口任务新增
/// </summary>
/// <param name="barCode">管段码</param>
/// <param name="equipmentCode">工位编码</param>
/// <returns></returns>
public dynamic InBevelTask(string barCode, string equipmentCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(barCode))
{
return response.ResponseError($"管段码不能为空,请核对!");
}
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"工位编码不能为空,请核对!");
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
var orderDetail = Context.Queryable<bus_workOrder_detail>()
.Where(x => x.barCode == barCode && x.oprSequenceCode == EnumoprSequenceCode.坡口).First();
if (orderDetail == null)
{
return response.ResponseError($"管段码【{barCode}】未查询到坡口信息!");
}
var material = Context.Queryable<base_material>().First(x => x.materialCode == orderDetail.cutMaterCode && x.isDelete == (int)EnumtIsValid.是);
if (material == null)
{
return response.ResponseError($"管段码【{barCode}】物料信息未配置,物料码【{orderDetail.cutMaterCode}】!");
}
//焊接工艺参数
var Equipment = new base_weld_technology_equipment()
{
technologyHeadId = 0,
equipmentCode = equipmentCode,
createBy = sysUserApi?.Account,
createTime = DateTime.Now.ToString(),
sendStatus = 0,
minDiameter = material.diameter,
minThickness = material.thickness,
minWeldingSeam = "0",
material = material.types,
pipelength = orderDetail.cuttingLength.ToString()
};
switch (Equipment.material)
{
case "碳钢": Equipment.material = "1"; break;
case "不锈钢": Equipment.material = "2"; break;
case "合金钢": Equipment.material = "3"; break;
case "多重钢": Equipment.material = "4"; break;
default: Equipment.material = "1"; break;
}
Context.Insertable(Equipment).ExecuteCommand();
return response;
});
}
#endregion
#region 弯管任务
/// <summary>
/// 弯管信息查询
/// </summary>
/// <param name="barCode">管段码</param>
/// <param name="selType">查询状态:0=未下发,10=已经下发</param>
/// <returns></returns>
public dynamic GetBentPipeDet(string barCode, int selType)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
//获取列表
var orderDetailList = Context.Queryable<bus_workOrder_detail, base_material>((a, b) =>
new JoinQueryInfos(JoinType.Left, a.cutMaterCode == b.materialCode))
.Where((a, b) => a.oprSequenceCode == EnumoprSequenceCode.弯管 && b.isDelete == (int)EnumtIsValid.是)
.WhereIF(!string.IsNullOrEmpty(barCode), (a, b) => a.barCode.Contains(barCode))
.WhereIF(selType == 0, (a, b) => a.state == (int)EnumOrderBodyStatus.初始化)
.WhereIF(selType > 0, (a, b) => a.state > (int)EnumOrderBodyStatus.初始化)
.Select((a, b) => new
{
a.id,
a.barCode,
a.cuttingLength,
b.materialName,
a.createTime
}).OrderBy((a) => a.createTime, OrderByType.Asc)
.Take(50).ToList();
if (orderDetailList.Count == 0)
{
return response.ResponseError($"未查询到弯管任务!");
}
response.Result = orderDetailList;
return response;
});
}
/// <summary>
/// 弯管任务新增
/// </summary>
/// <param name="barCode">管段码</param>
/// <param name="equipmentCode">工位编码</param>
/// <returns></returns>
public dynamic InBentPipeTask(string barCode, string equipmentCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(barCode))
{
return response.ResponseError($"管段码不能为空,请核对!");
}
var orderDetail = Context.Queryable<bus_workOrder_detail>()
.Where(x => x.barCode == barCode && x.oprSequenceCode == EnumoprSequenceCode.弯管).First();
if (orderDetail == null)
{
return response.ResponseError($"管段码【{barCode}】未查询到弯管工序信息!");
}
if (string.IsNullOrEmpty(equipmentCode))
{
return response.ResponseError($"工位编码不能为空,请核对!");
}
var equipment = Context.Queryable<base_work_station>().First(x => x.workStationCode == equipmentCode);
if (equipment == null)
{
return response.ResponseError($"工位编码未查询到设备,请配置!");
}
if (string.IsNullOrEmpty(equipment.monitorIP))
{
return response.ResponseError($"工位【{equipment.workStationName}】未配置IP,请配置!");
}
var orderBend = Context.Queryable<base_work_order_bends>().Where(x => x.workPieceNo == barCode).First();
if (orderBend == null)
{
return response.ResponseError($"管段没有弯管信息,请核对!");
}
BentPipeModel bentPipeModel = new BentPipeModel();
bentPipeModel.batchCode = orderBend.workPieceNo;
bentPipeModel.mCode = equipmentCode;
bentPipeModel.bendList = new List<Bend>();
Bend bend = new Bend();
bend.project = orderBend.shipNo;
bend.number = orderBend.pipePartsNo;
bend.pno = orderBend.workPieceNo;
bend.material = "碳钢";
bend.pipeDia = orderBend.externalDiameter;
bend.thickness = orderBend.thickness;
bend.beforeBendLength = orderBend.length;
bend.bendMoldRadius = orderBend.radius;
bend.head = orderBend.file1;
bend.bottom = orderBend.file2;
bend.flangeIncludedAngle = orderBend.mountingCorner;
bend.fistBendAngle = orderBend.cornerOne;
bend.yBCList = new List<YBC>();
if (string.IsNullOrEmpty(orderBend.straightSegment) ||
string.IsNullOrEmpty(orderBend.corner) ||
string.IsNullOrEmpty(orderBend.curve))
{
return response.ResponseError($"直段,转角,弯角数据为空,请核对!");
}
var YList = orderBend.straightSegment.Split("/");
var BList = orderBend.corner.Split("/");
var CList = orderBend.curve.Split("/");
if (YList.Length == BList.Length && YList.Length == CList.Length)
{
for (int i = 0; i < YList.Length; i++)
{
YBC yBC = new YBC();
yBC.bendDataY = YList[i];
yBC.bendDataB = BList[i];
yBC.bendDataC = CList[i];
bend.yBCList.Add(yBC);
}
}
else
{
return response.ResponseError($"直段,转角,弯角数据错误,请核对!");
}
bentPipeModel.bendList.Add(bend);
//发送弯管机数据 url = "/bendApi/PushBendData";
var url = GetDictionaryDictValue("UrlPushBendData", "GetUrl");
if (string.IsNullOrEmpty(url))
{
return response.ResponseError($"字典未配置请求地址,请配置!");
}
url = $"{equipment.monitorIP}{url}";
var WCSresponse = HttpManWCSByBends(url, bentPipeModel, EnumLog.弯管机接口.ToString(), method: "post");
if (WCSresponse.Code == 200)
{
orderDetail.actualStartTime = DateTime.Now;
orderDetail.updateTime = DateTime.Now;
orderDetail.state = (int)EnumOrderBodyStatus.生产中;
orderDetail.updateBy = sysUserApi?.Account;
orderDetail.equipmentCode = equipmentCode;
Context.Updateable(orderDetail).ExecuteCommand();
return response;
}
else
{
//{WCSresponse.Result}
return response.ResponseError($"发送数据失败,与弯管机通讯失败!");
}
});
}
#endregion
#region 火焰切割任务
/// <summary>
/// 火焰切割查询
/// </summary>
/// <param name="barCode">管段码</param>
/// <returns></returns>
public dynamic GetFlameCutDet(string barCode)
{
var response = new POJO.Response.Response();
return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
{
if (string.IsNullOrEmpty(barCode))
{
return response.ResponseError($"管段码不能为空,请核对!");
}
var work_order = Context.Queryable<base_work_order_head>().First(x => x.workPieceNo == barCode);
if (work_order == null)
{
return response.ResponseError("未获取到对应的工单数据");
}
var cuts = Context.Queryable<base_work_order_flameCut>().First(x => x.headKeys.Equals(work_order.keys));
if (cuts == null)
{
return response.ResponseError("未获取到对应的切割数据");
}
var material = Context.Queryable<base_material>().First(x => x.materialCode == work_order.materielCode && x.isDelete == (int)EnumtIsValid.是);
if (material == null)
{
return response.ResponseError($"管段码【{barCode}】物料信息未配置,物料码【{work_order.materielCode}】!");
}
var bevelDet = new BevelDetModel();
bevelDet.length = work_order.cutLength;
bevelDet.materialName = material.materialName;
response.Result = bevelDet;
return response;
});
}
#endregion
}
}