游畅
2023-04-29 cc266a1e4080bb3ecc47ea4a202dd549545111e1
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
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
global class SelectAssetEstimateURFController {
    //test
    private String targetHospitalId = null;                // 今後系列病院用
    private String targetMaintenanceContractId = null;
    public String typeresult {get; set;}
    
    public String targetEstimateId { get; private set; }
    public Boolean changedAfterPrint {get; set;}           // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにて実施
    public Decimal lastFriYearsPriceSum {get; set;}
    public Decimal lastSecYearsPriceSum {get; set;}
    Public String alertString {get; set;}
    Public String alertString2 {get; set;}
    Public String alertString3 {get; set;}
    public Boolean printAsset { get; private set; }
    public Boolean printContract { get; private set; }
    public Boolean printTripartite { get; private set; }
    public Boolean printAgent { get; private set; }
    public boolean inDicideFlag {get; set;}         //作为补充,对应报价决定之后,却未能讲合同起止日期传递给合同的问题
    public String isPaymentSet {get; set;}
    //public String PaymentSet {get;set;}
    // 引数のサービス契約の情報を格納する。
    public Maintenance_Contract__c contract { get; private set; }
    public Maintenance_Contract_Estimate__c estimate { get; set; }
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
    public Asset ass { get; set; }
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
    // 病院配下の納入機器の情報を格納する。
    private List<Asset> assetRecords;                           // TODO 系列病院の場合、Qこの配列は固定できないです。
    public List<AssetInfo> checkedAssets { get; set; }
    private List<AssetInfo> unCheckedAssets = new List<AssetInfo>();
    
    //public List<List<AssetInfo>> checkedAssetsView { get; set; }
    public List<List<AssetInfo> > unCheckedAssetsView { get; set; }
    
    // 分页用
    public Integer currPage { get; set; }         // 当前页
    public Integer totalPage { get; set; }         // 总页数
    public Integer selctRecordNum { get { return Integer.valueOf(selRecordOption); } }         // 选择的每页记录数
    public Integer totalRecords { get; set; }         // 总记录数
    public String selRecordOption { get; set; }
    public static List<SelectOption> recordNum { get; private set; }         // 选择每页记录数List
    
    //2021-11-30 fy add LJPH-C8W8FV 置顶 start
    public List<String> TopProductModel =new List<String>();
    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    
    //HWAG-B399Q8 2018/08/20  检验是否显示'请提交待审批' start
    public Boolean IS_Clone_After_Decide { get; set; }
    //HWAG-B399Q8 2018/08/20  检验是否显示'请提交待审批' end
    static {
        recordNum = new List<SelectOption>();
        recordNum.add(new SelectOption('10', '10'));
        recordNum.add(new SelectOption('20', '20'));
        recordNum.add(new SelectOption('50', '50'));
        recordNum.add(new SelectOption('100', '100'));
        recordNum.add(new SelectOption('200', '200'));
    }
    private List<String> checkIdList = new List<String> ();         // 合同对象设备的设备ID
    
    //-------HWAG-B4R3SS----------------update----------------------------
    public Boolean activeOn { get; set; }
    public String sortKey { get; set; }
    public Boolean sortOrderAsc { get; private set; }
    private String[] columus = new String[] {'Asset_situation__c', 'Name', 'SerialNumber', 'CurrentContract__r.Management_Code__c', 'Department_Name__c', 'Status', 'Installation_Site__c', 'Room_Number__c', 'InstallDate', 'Asset_Owner__c', 'Accumulation_Repair_Amount__c', 'AssetMark__c'};
    private Boolean isSoft;
    // 显示数据条数限制
    private static Integer SELECT_LIMIT = 200;
    public List<AssetInfo> unCheckedInfoList { get; set; }
    private String text1ForSort = null;
    private String cond1ForSort = null;
    private String val1ForSort = null;
    /*****************select option******************/
    public static List<SelectOption> textOpts { get; private set; }
    public Decimal countorder { get; set; }
    public List<String> assetSerialNumberList = new List<String>();
    // 新规 或者 copy
    private Boolean newIns = false;
    //URF限次合同2期 LY 20220811 start
    public String checkDealerId{get;set;}
    //URF限次合同2期 LY 20220811 end
    
    
    static {
        textOpts = new List<SelectOption>();
        //LJPH-BSS6E2  ---20200911 ---update by rentongxiao start
        // textOpts.add(new SelectOption('','-无-'));
        //LJPH-BSS6E2  ---20200911 ---update by rentongxiao end
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        /* 在查询语句中 新增了 AssetMark__c 的字段 */
        // textOpts.add(new SelectOption('S:Asset_situation__c'  , Schema.SObjectType.Asset.fields.Asset_situation__c.label));
        // 添加新条件 -- 耗材/主机
        textOpts.add(new SelectOption('S:AssetMark__c', '主机/耗材'));
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        textOpts.add(new SelectOption('S:Name', Schema.SObjectType.Asset.fields.Name.label));
        textOpts.add(new SelectOption('S:SerialNumber', Schema.SObjectType.Asset.fields.SerialNumber.label));
        textOpts.add(new SelectOption('S:CurrentContract__r.Management_Code__c', Schema.SObjectType.Asset.fields.CurrentContract__c.label));
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        // textOpts.add(new SelectOption('S:Status'              , Schema.SObjectType.Asset.fields.Status.label));
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        textOpts.add(new SelectOption('S:Installation_Site__c', Schema.SObjectType.Asset.fields.Installation_Site__c.label));
        textOpts.add(new SelectOption('S:Department_Name__c', Schema.SObjectType.Asset.fields.Department_Name__c.label));
    }
    public static List<SelectOption> equalOpts { get; private set; }
    static {
        equalOpts = new List<SelectOption>();
        equalOpts.add(new SelectOption('equals', '等于'));
        equalOpts.add(new SelectOption('contains', '包含'));
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        //新加匹配符 不等于
        equalOpts.add(new SelectOption('notequals', '不等于'));
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
    }
    public String text1 { get; set; }         // 对象
    public String cond1 { get; set; }         // 条件
    public String val1 { get; set; }         // 值
    //LJPH-BSS6E2  ---20200911 ---add by rentongxiao start
    public String contr {get; set; }         //判断是否init
    //LJPH-BSS6E2  ---20200911 ---add by rentongxiao end
 
    // 检索按钮
    public PageReference searchBtn() {
        countorder = 1;
        //验证
        assetSerialNumberList.clear();
        getAssetSerialNumber();
        totalRecords = 0;
        List<Asset> assetconfimList = getAssetconfim(text1, cond1, val1);
        for (Asset ast : assetconfimList) {
            totalRecords++;
        }
    
    
        // 获取assets
        List<Asset> assetList = getAsset(text1, cond1, val1);
    
        // 作成明细行
        getSortedUnCheckedInfoList(assetList);
        // 排序用检索条件退避
        text1ForSort = text1;
        cond1ForSort = cond1;
        val1ForSort = val1;
        currPage = 1;
    
    
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        return null;
    }
    
    // 取已选择资产的机身编码
    public void getAssetSerialNumber() {
        //LJPH-BSS6E2  ---20200911 ---add by rentongxiao start
        contr = '2';
        //LJPH-BSS6E2  ---20200911 ---add by rentongxiao end
        assetSerialNumberList = new List<String>();
        assetSerialNumberList.clear();
        for (AssetInfo ai : this.checkedAssets) {
            system.debug('checkedAssets1111111' + this.checkedAssets);
            //system.debug('ai.ah.SerialNumber__c' + ai.ah.SerialNumber__c);
            if (String.isNotEmpty(ai.rec.SerialNumber)) {
                assetSerialNumberList.add(ai.rec.SerialNumber);
            }
        }
    }
    
    //
    private void getSortedUnCheckedInfoList(List<Asset> assetList) {
        Boolean overLimit = false;
        Map<Id, AssetInfo> markUpUnCheckMap = new Map<Id, AssetInfo>();
        for (AssetInfo unCheckinfo : unCheckedAssets) {
    
            // 打勾,视为优先显示明细
            if (unCheckinfo.rec_checkBox_c == true) {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , 'unCheckinfo.rec_checkBox_c' + unCheckinfo.rec_checkBox_c));
                markUpUnCheckMap.put(unCheckinfo.rec.Id, unCheckinfo);
            }
        }
        unCheckedAssets.clear();
        // 优先显示明细放在最前面
        unCheckedInfoList = new List<AssetInfo>();
        for (AssetInfo asInfo : markUpUnCheckMap.values()) {
            unCheckedAssets.add(asInfo);
        }
        SELECT_LIMIT = selctRecordNum;
        Integer selectCnt = unCheckedAssets.size();
        for (Asset asset : assetList) {
            // 201を超えた場合前200のみを出す
            if (unCheckedAssets.size() >= SELECT_LIMIT) { overLimit = true; break; }
            if (markUpUnCheckMap.containsKey(asset.Id) == false) {
                //unCheckedInfoList.add(unCheckMap.get(asset.Id));
                unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), asset));
            }
        }
    }
    
    //检索验证
    private List<Asset> getAssetconfim(String txt, String con, String val) {
        String soql = this.makeSoqlconfim();
        soql += makeTextSql(txt, con, val);
        system.debug('makeTextSql_soql' + soql);
        if (isSoft) {
            soql += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last ');
        } else {
            soql += ' order by SerialNumber, Name, Department_Name__c, InstallDate';
        }
        system.debug('====getAssetconfim:' + soql);
        return Database.query(soql);
    }
    
    private List<Asset> getAsset(String txt, String con, String val) {
        String soql = this.makeSoqlconfim();
        soql += makeTextSql(txt, con, val);
    
        if (isSoft) {
            soql += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last ');
        } else {
            soql += ' order by SerialNumber, Name, Department_Name__c, InstallDate';
        }
        soql += ' limit ' + System.Label.Asset_Maxcount;
        soql += ' OFFSET ' + (countorder - 1) * Integer.valueOf(System.Label.Asset_Maxcount);
        return Database.query(soql);
    }
    
    public Integer soqlNos() {
        List<Asset> assetconfimList = getAssetconfim(text1, cond1, val1);
        totalRecords = assetconfimList.size();
        //totalPage = (totalRecords/selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        return totalRecords;
    }
    
    private String makeSoqlconfim() {
        String sqlTail = '(\'';
        system.debug('assetSerialNumberList.size()' + assetSerialNumberList.size());
        for (Integer i = 0; i < assetSerialNumberList.size(); i++) {
            if (i < assetSerialNumberList.size() - 1) {
                sqlTail += assetSerialNumberList[i] + '\',\'';
            } else {
                sqlTail += assetSerialNumberList[i] + '\')';
            }
        }
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c
                //tcm 删除第4行 Maintenance_Contract_No_F__c 替换 Management_Code__c  20211201
        String soql = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, '
                      + 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                      + 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, '
                          + 'CurrentContract_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                      + 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c, '
                      + 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,'
                      + 'CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,CurrentContract_F__r.Contract_Range__c,'
                      + 'Product2.ProductURF__c,Product2.ProductURF__r.URFLimitSerial__c,Product2.ProductURF__r.UFR_MaxRepairCount__c,Product2.ProductURF__r.UFR_Maintenance_Price_Month__c,'
                      //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                      + 'Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c, Product2.ProductURF__r.Maintenance_Price_Year_URF__c,'  
                      //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                      //URF限次合同2期 LY 20220811 start
                      + 'Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c, Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c, Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c,'
                      + 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,'
                      //URF限次合同2期 LY 20220811 end
                      + 'CurrentContract_End_Date__c, Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c,AssetMark__c FROM Asset WHERE Product2.ProductURF__c != null AND Hospital__c = \'' + this.targetHospitalId + '\' ';
        //HWAG-BDJ43R ---XHL---20190729---
        //soql +=  ' AND AssetMark__c != \'耗材\' AND Product2.Family != \'ET\' ';
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        // soql +=  ' AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' ) ';
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        //HWAG-BDJ43R ---XHL---20190729---
        if (assetSerialNumberList.size() > 0) {
            soql += ' AND SerialNumber not in ' + sqlTail;
        }
        return soql;
    }
    
    // 拼接检索条件sql文
    private String makeTextSql(String txt1, String con, String val) {
        String soql = '';
        if (String.isBlank(con)) {
            con = 'equals';
        }
        // containsの場合、日報画面の病院検索を真似し、spaceで分けて、and検索
        // equalsの場合、SF標準の検索を真似し、「,」で分けて、or検索
        if (!String.isBlank(txt1)) {
            if ((con == 'contains' || con == 'notcontains') && val.contains(' ')) {
                String[] vals = val.split(' ');
    
                String cSql = '';
                if (vals.size() > 0) {
                    String txt = txt1.substring(2);
                    soql += ' and ( ';
                    for (String v : vals) {
                        if (String.isNotBlank(v)) {
                            if (con == 'contains') {
                                soql += txt + ' like \'%' + v + '%\' or ';
                            } else {
                                soql += txt + ' not like \'%' + v + '%\' and ';
                            }
                        }
    
    
                    }
                    soql = soql.substring(0, soql.length() - 4);
                    soql += ')';
                }
                system.debug('containssoql:     ' + soql);
            } else if ((con == 'equals' || con == 'notequals') && val.contains(',')) {
                String[] vals = val.split(',');
                if (vals.size() > 0) {
                    String txt = txt1.substring(2);         // S:Name 、最初の2文字がタイプです
                    soql += ' and ( ';
                    for (String v : vals) {
                        if (con == 'equals') {
                            soql += txt + ' = \'' + v + '\' or ';
                        } else {
                            // notequals
                            soql += txt + ' <> \'' + v + '\' and ';
                        }
                    }
                    soql = soql.substring(0, soql.length() - 4);
                    soql += ')';
                }
            } else {
                String cSql = this.makeTextSqlStr(txt1, con, val);
                if (con != 'notcontains') {
                    soql += this.makeTextSqlStr(txt1, con, val);
                } else {
                    // notcontains
                    if (!String.isBlank(cSql)) {
                        cSql = cSql.substring(5);         // ' and ' の5文字を外す
                        soql += ' and (NOT ' + cSql + ') ';
                    }
                }
            }
        }
        // //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        // else{
        //     soql += 'And AssetMark__c = \'主机\'';
        // }
        // //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        return soql;
    }
    
    private String makeTextSqlStr(String txt1, String con, String val) {
        String soql = '';
        if (!String.isBlank(txt1)) {
            String txt = txt1.substring(2);
            String colType = txt1.substring(0, 2);
            String tmpVal = val.trim();
            // 空白の場合''にする
            if (String.isBlank(tmpVal)) {
                if (con == 'equals') {
                    //soql += ' and ' + txt + ' = ' + tmpVal;
                    soql += ' and ' + txt + ' = null';
                } else if (con == 'notequals') {
                    soql += ' and ' + txt + ' <> null';
                } else {
                    // 空白の場合、contains, notcontains と starts withは無視
                }
            } else {
                soql += ' and ' + txt;
                if (con == 'equals') {
                    if (colType == 'S:') {
                        soql += ' = \'' + tmpVal + '\'';
                    } else {
                        soql += ' = ' + tmpVal + ' ';
                    }
                } else if (con == 'notequals') {
                    if (colType == 'S:') {
                        soql += ' <> \'' + tmpVal + '\'';
                    } else {
                        soql += ' <> ' + tmpVal + ' ';
                    }
                } else if (con == 'contains' || con == 'notcontains') {
                    soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
                } else if (con == 'starts with') {
                    soql += ' like \'' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
                } else {
                    if (colType == 'S:') {
                        soql += ' ' + con + '\'' + tmpVal + '\'';
                    } else {
                        soql += ' ' + con + ' ' + tmpVal + ' ';
                    }
                }
            }
        }
        return soql;
    }
    
    //----------HWAG-B4R3SS------------------------------------------------------------
    
    
    
    
    
    
    public Boolean getEnablePrintContract() {
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            return this.estimate.Estimation_Decision__c;
        } else {
            return false;
        }
    }
    
    public Boolean getUnDecideBtnDisabled() {
        // 見積もりdecide取消しできない条件の判断
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            if (this.estimate.Estimation_Decision__c) {
                return false;
            }
        }
        // TODO 本当は特別資格があれば 決定可能にする
        return true;
    }
    public Boolean getDecideBtnDisabled() {
        // 見積もりdecideできない条件の判断
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            if (this.estimate.Estimation_Decision__c) {
                return true;
            }
            // TODO 特別資格があれば 決定可能にする
            return true;
        }
        if (this.estimate.Process_Status__c != '批准') {
            return true;
        } else {
            if (String.isBlank(this.estimate.Change_Dealer_Approval__c) == false
                && this.estimate.Change_Dealer_Approval__c != '批准'
                && this.estimate.Change_Dealer_Approval__c != '未批准') {
                return true;
            }
        }
        return false;
    }
    public Boolean getApprovalBtnDisabled() {
    
        // 見積もり申請できない条件の判断
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            // TODO 特別資格があれば 申請可能にする
            return true;
        }
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            //&& this.estimate.Process_Status__c != '不批准'
            ) {
            return true;
        }
        return false;
    }
    // 20200307 不用
    // public Boolean getcontactBtnDisabled() {
    //     if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
    //         // TODO 特別資格があれば 申請可能にする
    //         return true;
    //     }
    //     if (String.isBlank(this.estimate.Process_Status__c) == false
    //             && this.estimate.Process_Status__c != '草案中'
    //             && this.estimate.Process_Status__c != '申请中'
    //     ) {
    //         return true;
    //     }
    //     return false;
    // }
    public Boolean getSaveBtnDisabled() {
        // 見積もりsaveできない条件の判断
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            return true;
        }
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            //&& this.estimate.Process_Status__c != '不批准'
            ) {
            return true;
        }
        return false;
    }
    public Boolean getPrintBtnDisabled() {
        // 印刷できない条件の判断
        if (this.estimate.Process_Status__c != '批准' || !this.contract.Status__c.equals('引合中') ) {
            return true;
        } else {
            if (String.isBlank(this.estimate.Change_Dealer_Approval__c) == false
                && this.estimate.Change_Dealer_Approval__c != '批准'
                && this.estimate.Change_Dealer_Approval__c != '未批准') {
                return true;
            }
        }
        return false;
    }
    // 页面项目非活性设定
    public Boolean getPageDisabled() {
        if (String.isBlank(this.contract.Decided_Estimation__c) == false) {
            return true;
        }
        if (String.isBlank(this.estimate.Process_Status__c) == false
            && this.estimate.Process_Status__c != '草案中'
            ) {
            return true;
        }
        return false;
    }
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk star
    // public Boolean getPageDisabled1() {
    
    //     if (
    //         String.isBlank(this.ass.Name)
    //     ) {
    //         return true;
    //     }
    //     return false;
    // }
    // 2021、8、26 合同报价页面的优化,无保有设备点检对象选择框变黑 fxk end
    public Integer productCount {
        get {
            return checkedAssets == null ? 0 : checkedAssets.size();
        }
    }
    public Integer productCount2 {
        get {
            return unCheckedAssets == null ? 0 : unCheckedAssets.size();
        }
    }
    public Integer productCount3 {
        get {
            Integer cnt = 0;
            for (AssetInfo input : this.checkedAssets) {
                if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                    cnt += 1;
                }
            }
            return cnt;
        }
    }
    // TODO カスタムラベルから取得
    public static Decimal oxygenPriceAdj { get { return 0.1; } }              // TODO katsu 酸化水を使用しないように変更
    public static Decimal isNewPriceAdj { get { return 1; } }
    
    //public String productName { get; set; }
    public Integer productIdx { get; set; }
    
    public Integer isNewAddMonth { get { return Integer.valueOf(System.Label.MC_New_AddMonth); } }
    
    public Integer keepPriceMonth { get { return Integer.valueOf(System.Label.MC_KeepPrice_Month); } }
    
    public Boolean isPageAction = false;
    
    private Integer PosttoInstall { get { return Integer.valueOf(System.Label.Post_to_Install); }}
    
    public Boolean changedSubmitPrice {get; set;}
    
    public Boolean isSaveOrApproval {get; set;}
    public String OldContractStartDate {get; set;}
    public String OldMaintenancePrice { get; set; }
    
    /**
     * コンストラクタ
     */
    public SelectAssetEstimateURFController() {
        currPage = 1;
        selRecordOption = '20';
        totalRecords = 0;
        //URF限次合同2期 LY 20220920 start
        checkDealerId = '';
        //URF限次合同2期 LY 20220920 end
        Integer i = 0;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
    }
    /**
     * Visaulforceから呼ばれるコンストラクタ
     */
    public SelectAssetEstimateURFController(ApexPages.StandardController controller) {
        //HWAG-B4R3SS  START 20181026
        currPage = 1;
        selRecordOption = '20';
        //this.targetEstimateId = (String)(ApexPages.currentPage().getParameters().get('id'));
        totalRecords = 0;
        //HWAG-B4R3SS  END 20181026
    }
 
    private void setThisEstimate() {
        //HWAG-B399Q8 2018/08/20  添加一额外字段 IS_Clone_After_Decide__c start
        this.estimate = [SELECT Id, Name, Maintenance_Contract__c, Estimation_Decision__c, CreatedDate, Service_Contract_Staff__c,
                         JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c, Finally_Approved_Staff__c,
                         Contract_Esti_Start_Date__c, Contract_Esti_End_Date__c, Contract_Range__c, Contract_Start_Date__c, Contract_End_Date__c,
                         Maintenance_Contract_Status__c, Discount_reason__c, Improve_ConsumptionRate_Idea__c, Process_Status__c,
                         Estimate_Trial_Money__c, Maintenance_Price__c, Department__c, PrintDate__c, Quote_Date__c, Submit_quotation_day__c,
                         Examination_Price__c, Service_contract_target_number__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_First__c, Maintenance_Contract__r.Payment_Plan_Date_First__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Second__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Third__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Forth__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Fifth__c,
                         Maintenance_Contract__r.Payment_Plan_Sum_Sixth__c,
                         Discount_Price__c, Discount_Percentage__c, IsSyncing__c,
                         NotUse_Oxygenated_Water__c, Estimate_Target__c, Dealer__c,
                         Append_Condition_Price__c, Asset_Sum_Price__c, Asset_Repair_Sum_Price__c,
                         Print_Contract__c, Print_RepairPrice__c, Print_DiscountPercentage__c, Print_Agent__c, Change_Dealer_Approval__c,
                         Print_DiscountPrice__c, Print_ListPrice__c, Print_MaintePrice__c, Print_SumPrice__c, Print_Tripartite__c, TKZongjianApprovalManager__c
                         //打印报价(简化版) 2019/12/18 start
                         , IS_Clone_After_Decide__c, New_contract_offer__c, NewEstimation_Amount__c, EndUserType__c, Print_Simplify__c
                         //打印报价(简化版) 2019/12/18 end
                         //最低价格 最高价格 申请背景相关字段 20200108 start
                         , GuidePrice_Up__c, GuidePrice_Down__c, finalPriceDecideWay__c, mainTalksTime__c, talksStartDate__c
                         , Combined_rate__c, New_Contract_Type_TxT__c, Estimate_Price_range__c
                         //最低价格 最高价格计算 20200108 end
                         , Sales_incidental__c, Consumption_rate_Forecast__c, AgencyHos_Price__c
                         // 申请报价金额 和 相对标准价格范围的折扣率
                         , Request_quotation_Amount__c, Service_discount_Rate__c, ContractPriceType__c
                         , LastMContract1__c, LastMContract2__c, LastMContract3__c, LastMContract4__c, LastMContract5__c
                         , LastMContract1_ConCount__c, LastMContract2_ConCount__c, LastMContract3_ConCount__c, LastMContract4_ConCount__c, LastMContract5_ConCount__c,
                         LastMContract1_NO__c, LastMContract2_NO__c, LastMContract3_NO__c, LastMContract4_NO__c, LastMContract5_NO__c
                        // URF限次合同2期 LY 20220811 start
                        ,Is_RecognitionModel__c
                        ,URF_P_MaxRepairCount__c,URF_V_MaxRepairCount__c
                        ,URFMContract1__c,URFMContract1_startDate__c,URFMContract1_endDate__c
                        //,URFMContract2__c,URFMContract3__c,URFMContract4__c,URFMContract5__c
                        ,URF_LastMContract1_NO__c,URF_LastMContract2_NO__c,URF_LastMContract3_NO__c,URF_LastMContract4_NO__c,URF_LastMContract5_NO__c
                        ,URF_LastMContract1_ConCount__c,URF_LastMContract2_ConCount__c,URF_LastMContract3_ConCount__c,URF_LastMContract4_ConCount__c,URF_LastMContract5_ConCount__c
                        // URF限次合同2期 LY 20220811 end
                        //贸易合规 you start
                        ,Maintenance_Contract__r.AccDealerBlacklist__c 
                        ,Maintenance_Contract__r.Hospital__r.Name
                        ,Maintenance_Contract__r.Dealer__r.Name
                        ,CreatedById
                        //贸易合规 you end
                         FROM Maintenance_Contract_Estimate__c WHERE Id = :this.targetEstimateId];
        //HWAG-B399Q8 2018/08/20  添加一额外字段 IS_Clone_After_Decide__c end
        decimal PriceSum =  (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Second__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Second__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Third__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Third__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Forth__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Forth__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Fifth__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Fifth__c) +
                           (this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Sixth__c == null ? 0 : this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_Sixth__c);
        if ( this.estimate.Maintenance_Contract__r.Payment_Plan_Sum_First__c == null
             //102018/10/26 HWAG-B5C88S 不再根据是否填写第一次付款日期判断
             ) {
            isPaymentSet = 'false';
        } else if (this.estimate.Maintenance_Price__c != PriceSum) {
            isPaymentSet = 'Denied';
        } else {
            isPaymentSet = 'true';
        }
    }
    
    public void init() {
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        TopProductModel.add('CF-LV1I');
        TopProductModel.add('CF-LV1L');
        TopProductModel.add('CV-V1');
        TopProductModel.add('GIF-LV1');
        TopProductModel.add('OER-AW');
        TopProductModel.add('OER-A');
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        typeresult = null;
        changedAfterPrint = false;
        changedSubmitPrice = false;
        isSaveOrApproval = false;
        OldContractStartDate = null;
        OldMaintenancePrice = null;
    
        inDicideFlag = false;
    
        isSoft = false;
        activeOn = true;
        //LJPH-BSS6E2  ---20200911 ---update by rentongxiao start
        contr = '1';
        val1 = '主机';
        //LJPH-BSS6E2  ---20200911 ---update by rentongxiao end
    
        Date systemToday = System.today();
        if (isPageAction == false) {
            //HWAG-B399Q8 2018/08/20  添加状态5,为按save 按键后状态 start
            if (String.isBlank(ApexPages.currentPage().getParameters().get('completion')) == false) {
                if (ApexPages.currentPage().getParameters().get('completion') == '1') {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, System.Label.Message_002));
                } else if (ApexPages.currentPage().getParameters().get('completion') == '2') {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '审批提交成功。'));
                } else if (ApexPages.currentPage().getParameters().get('completion') == '3') {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Decided。'));
                } else if (ApexPages.currentPage().getParameters().get('completion') == '4') {
    
                } else if (ApexPages.currentPage().getParameters().get('completion') == '5') {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, System.Label.Message_002));
                }
            }
            //HWAG-B399Q8 2018/08/20  添加状态5,为按save 按键后状态 end
        }
        this.printAsset = false;
        this.printContract = false;
        this.printTripartite = false;
        this.printAgent = false;
        
        String copyid = '';
        if (isPageAction == false) {
            this.targetEstimateId = ApexPages.currentPage().getParameters().get('copyid');
            copyid = ApexPages.currentPage().getParameters().get('copyid');
            if (this.targetEstimateId == null) {
                String paramId = ApexPages.currentPage().getParameters().get('id');
                if (String.isBlank(paramId) == false && paramId.startsWith('a0z')) {
                    Maintenance_Contract_Asset_Estimate__c mcaeParam = [Select Maintenance_Contract_Estimate__c from Maintenance_Contract_Asset_Estimate__c where Id = :paramId];
                    this.targetEstimateId = mcaeParam.Maintenance_Contract_Estimate__c;
                } else {
                    this.targetEstimateId = paramId;
                }
            } else {
                this.newIns = true;
            }
            this.targetMaintenanceContractId = ApexPages.currentPage().getParameters().get('mcid');
        }
        // 編集から
        if (String.isBlank(this.targetEstimateId) == false) {
            setThisEstimate();
            this.targetMaintenanceContractId = this.estimate.Maintenance_Contract__c;
            this.setContractInfo(this.targetMaintenanceContractId);
        }
        // 新規から
        else if (!String.isBlank(this.targetMaintenanceContractId)) {
            this.estimate = new Maintenance_Contract_Estimate__c();
            this.estimate.Maintenance_Contract__c = this.targetMaintenanceContractId;
            this.estimate.Contract_Esti_Start_Date__c = systemToday;
            this.estimate.Contract_Start_Date__c = systemToday;
            this.setContractInfo(this.targetMaintenanceContractId);
            this.newIns = true;
        }
        // 何もなければ、念のため
        else {
            throw new ControllerUtil.myException('无法显示维修合同报价');
            //return;
        }
        //HWAG-B399Q8 2018/08/20  检验是否显示'请提交待审批' start
        IS_Clone_After_Decide = false;
        if (String.isBlank(ApexPages.currentPage().getParameters().get('completion')) == false &&
            ApexPages.currentPage().getParameters().get('completion') == '5' &&
            this.estimate != null && this.estimate.IS_Clone_After_Decide__c) {
            IS_Clone_After_Decide = true;
    
        }
        //HWAG-B399Q8 2018/08/20  检验是否显示'请提交待审批' end
        // 納入機器の情報を取得
        //tcm 删除第4行 Maintenance_Contract_No_F__c 替换 Management_Code__c  20211201 start
        if (!String.isBlank(this.targetHospitalId) && (this.targetHospitalId.length() == 15 || this.targetHospitalId.length() == 18)) {
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c
            assetRecords = [SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c, Management_Code__c, IF_Warranty__c, Reson_Can_not_Warranty__c,
                            InstallDate, isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, CurrentContract_End_Date__c, EquipmentGuaranteeFlg__c,
                                CurrentContract_F__c, CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.Maintenance_Contract_No_F__c, CurrentContract_F__r.RecordType_DeveloperName__c, CurrentContract_F__r.Estimate_Num__c, CurrentContract_F__r.Contract_End_Date__c, CurrentContract_F__r.Estimate_Contract_endDate__c,
                            CurrentContract_F_asset__c, CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c, CurrentContract_F_asset__r.endDateGurantee_Text__c, CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                            CurrentContract_F__r.First_Estimate_Date__c,
                            CurrentContract_F__r.Contract_Consumption_rate__c, CurrentContract_F__r.First_contract_usage_Rate__c,
                            CurrentContract_F__r.Contract_Range__c, AssetMark__c
                            // 限次合同信息 add by gzw start
                            , Product2.ProductURF__c, Product2.ProductURF__r.URFLimitSerial__c, Product2.ProductURF__r.UFR_MaxRepairCount__c, Product2.ProductURF__r.UFR_Maintenance_Price_Month__c
                            // 限次合同信息 add by gzw end
                            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                            , Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c
                            , Product2.ProductURF__r.Maintenance_Price_Year_URF__c
                            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                            //URF限次合同2期 LY 20220811 start
                            , Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c
                            , Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c
                            , Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c
                            , URF_Maintenance_Contract__c
                            , URF_Maintenance_Contract__r.Management_Code__c
                            , URF_Maintenance_Contract__r.Contract_End_Date__c
                            //URF限次合同2期 LY 20220811 end
                            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND ( AssetMark__c != '耗材' OR Product2.Family != 'ET' ) ORDER BY ID, IF_Warranty__c asc];
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
            // assetRecords = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
            //                      InstallDate,isNewDate_use__c, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,EquipmentGuaranteeFlg__c,
            //                      CurrentContract_F__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,
            //                      CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c,
            //                      CurrentContract_F__r.First_Estimate_Date__c,
            //                     CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,
            //                     CurrentContract_F__r.Contract_Range__c ,AssetMark__c
            //                      FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c = '主机' ORDER BY ID,IF_Warranty__c asc];
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        } else {
            assetRecords = new List<Asset>();
        }
        //sqlStr += ' AND AssetMark__c != \'耗材\' AND Product2.Family != \'ET\' ';
        this.checkedAssets = new List<AssetInfo>();
        this.unCheckedAssets = new List<AssetInfo>();
    
        // 選択済みの納入機器情報を取得
        Map<Id, Integer> selectedAssetIds = new Map<Id, Integer>();
        List<Maintenance_Contract_Asset_Estimate__c> selectedMcaes = new List<Maintenance_Contract_Asset_Estimate__c>();
        List<Maintenance_Contract_Asset_Estimate__c> newMcaes = new List<Maintenance_Contract_Asset_Estimate__c>();
        // 新規、且つ1つ目見積もりの場合、コピー元の保有設備を持つ
        if (String.isBlank(this.targetEstimateId) && this.contract.Estimate_Num__c == 0) {
            // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '00000000000000000000000000'));
            List<Maintenance_Contract_Asset__c> oldVals = [
                select Id, Name, Asset__c, Asset__r.InstallDate, Asset__r.isNewDate_use__c,
                Asset__r.Posting_Date__c, Asset__r.Maintenance_Price_Month__c,
                Asset__r.EquipmentGuaranteeFlg__c,
                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
                Asset__r.CurrentContract_F__r.First_Estimate_Date__c,
                Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c,
                Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c,
                Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c,
                Asset__r.CurrentContract_F__r.Contract_Range__c,
                Asset__r.CurrentContract_F__r.Contract_End_Date__c,
                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c
                // 20210315 gzw 追加限次产品信息 start
                , Asset__r.Product2.ProductURF__c
                , Asset__r.Product2.ProductURF__r.URFLimitSerial__c,
                Asset__r.Product2.ProductURF__r.UFR_MaxRepairCount__c,
                Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c
                // 20210315 gzw 追加限次产品信息 start
                //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                , Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c, Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF__c
                //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                //URF限次合同2期 LY 20220811 start
                , Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c
                , Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c
                , Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c
                , Asset__r.URF_Maintenance_Contract__c
                , Asset__r.URF_Maintenance_Contract__r.Management_Code__c
                , Asset__r.URF_Maintenance_Contract__r.Contract_End_Date__c
                //URF限次合同2期 LY 20220811 end
                from Maintenance_Contract_Asset__c
                where Maintenance_Contract__c = :this.targetMaintenanceContractId AND Asset__r.Product2.ProductURF__c != null
            ];
            Date mon1stDate = Date.newInstance(Date.today().year(), Date.today().month(), 1);
            for (Maintenance_Contract_Asset__c mca : oldVals) {
                // oldより更新したい項目
                Boolean isNew = false;
                // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
                boolean isCheck = true;
                // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk End
                // 20210315 gzw 追加限次产品信息 start
                // Decimal listPrice = mca.Asset__r.Maintenance_Price_Month__c;
                //URF限次合同2期 LY 20220811 start
                //Decimal listPrice = mca.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
                Decimal listPrice = mca.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
                //URF限次合同2期 LY 20220811 end
                // 20210315 gzw 追加限次产品信息 end
                Decimal asset_Consumption_rate = null;
                // 取上一期合同消费率
                if (mca.Asset__r.CurrentContract_F__r.First_Estimate_Date__c != null && mca.Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c > mon1stDate) {
                    asset_Consumption_rate = mca.Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c;
                } else {
                    asset_Consumption_rate = mca.Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c;
                }
                // InstallDate と 今日を比較
                // 1.安装日或者发货日和今天比较 实时变化
                // 2.提交后不再变化
                //Date createdDate = (estimate.CreatedDate == null || !String.isBlank(copyid)) ? systemToday : estimate.CreatedDate.date();
                Date createdDate = systemToday;
                if (createdDate.addMonths(isNewAddMonth) < mca.Asset__r.isNewDate_use__c) {
                    isNew = true;
                    // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
                    isCheck = true;
                    // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk End
                    // 20210315 gzw 追加限次产品信息 start
                    // listPrice = mca.Asset__r.Maintenance_Price_Month__c * isNewPriceAdj;
                    // listPrice = mca.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c  * isNewPriceAdj;
                    listPrice = mca.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c  * isNewPriceAdj;
 
                    
                    // 20210315 gzw 追加限次产品信息 end
    
                }
                selectedAssetIds.put(mca.Asset__c, selectedMcaes.size());
                selectedMcaes.add(new Maintenance_Contract_Asset_Estimate__c(
                              Asset__c = mca.Asset__c,
                              isNew__c = isNew,
                              // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
                              Check_Object__c = isCheck,
                              // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk End
                              Estimate_List_Price__c = listPrice,
                              // 取上一期合同价格
                              LastMContract_Price__c = mca.Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
    
                              Asset_Consumption_rate__c = asset_Consumption_rate,
                              EquipmentGuaranteeFlgTxt__c = mca.Asset__r.EquipmentGuaranteeFlg__c
                              ));
            }
        } else {
            List<Maintenance_Contract_Asset_Estimate__c> selectlist = [SELECT Id FROM
                                                                       Maintenance_Contract_Asset_Estimate__c
                                                                       WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId ];
    
            // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '111111111111111111111111' + selectlist.size()));
            for (Maintenance_Contract_Asset_Estimate__c mcae : [SELECT Id,
                                                                Name,
                                                                Maintenance_Contract_Estimate__c,
                                                                Asset__c,
                                                                Asset__r.Maintenance_Price_Month__c,
                                                                Asset__r.InstallDate,
                                                                Asset__r.isNewDate_use__c,
                                                                Asset__r.EquipmentGuaranteeFlg__c,
                                                                //2021-11-30 fy add LJPH-C8W8FV 置顶 start
                                                                Asset__r.OwnershipMachine_No__c,
                                                                //2021-11-30 fy add LJPH-C8W8FV 置顶 end
                                                                Asset_Consumption_rate__c,
                                                                Asset__r.CurrentContract_F__c,
                                                                Asset__r.CurrentContract_F__r.First_Estimate_Date__c,
                                                                Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c,
                                                                Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c,
                                                                Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c,
                                                                Asset__r.CurrentContract_F__r.Contract_Range__c,
                                                                Asset__r.CurrentContract_F__r.Contract_End_Date__c,
                                                                Asset__r.CurrentContract_F__r.Gurantee_Estimate_startDate__c,
                                                                LastMContract_Price__c,
                                                                Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,
                                                                Asset__r.CurrentContract_F_asset__r.endDateGurantee_Text__c,
                                                                Product_Manual__c,
                                                                Product_Manual__r.EquipmentGuaranteeFlg__c,
                                                                Product_Manual__r.Maintenance_Price_Month__c,
                                                                Product_Manual__r.Name,
                                                                // 20210315 gzw 追加限次产品信息 start
                                                                Product_Manual__r.ProductURF__c,
                                                                Product_Manual__r.ProductURF__r.URFLimitSerial__c,
                                                                Product_Manual__r.ProductURF__r.UFR_MaxRepairCount__c,
                                                                Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month__c,
                                                                //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                                                                Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_Max__c,
                                                                Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF__c,
                                                                //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                                                                //URF限次合同2期 LY 20220811 start
                                                                Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_3__c,
                                                                Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c,
                                                                Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month_3__c,
                                                                //URF限次合同2期 LY 20220811 end
                                                                //2021-11-30 fy add LJPH-C8W8FV 置顶 start
                                                                Product_Manual__r.Asset_Model_No__c,
                                                                //2021-11-30 fy add LJPH-C8W8FV 置顶 end
                                                                Asset__r.Product2.ProductURF__c,
                                                                Asset__r.Product2.ProductURF__r.URFLimitSerial__c,
                                                                Asset__r.Product2.ProductURF__r.UFR_MaxRepairCount__c,
                                                                Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c,
                                                                //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                                                                Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c,
                                                                Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF__c,
                                                                //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                                                                //URF限次合同2期 LY 20220811 start
                                                                Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c,
                                                                Asset__r.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c,
                                                                Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c,
                                                                Asset__r.URF_Maintenance_Contract__c,
                                                                Asset__r.URF_Maintenance_Contract__r.Management_Code__c,
                                                                Asset__r.URF_Maintenance_Contract__r.Contract_End_Date__c,
                                                                //URF限次合同2期 LY 20220811 end
                                                                URF_Series__c,
                                                                Series_RepairCount__c,
                                                                Series_MaxRepairCount__c,
                                                                Asset_RepairCount__c,
                                                                Asset_MaxRepairCount__c,
                                                                // 20210315 gzw 追加限次产品信息 start
                                                                IsNew__c,
                                                                //add 2021.6.4 fxk  Start
                                                                Check_Object__c,
                                                                //add 2021.6.4 fxk  end
                                                                Estimate_List_Price__c,
                                                                //Maintenance_Price_YearTXT__c,
                                                                Estimate_Cost__c,
                                                                Adjustment_ratio_Upper__c,
                                                                Adjustment_ratio_Lower__c,
                                                                Adjustment_Lower_price__c,
                                                                Adjustment_Upper_price__c,
                                                                Last_inspection_day__c,
                                                                Check_Result__c,
                                                                Repair_Price__c,
                                                                Comment__c,
                                                                Asset__r.Posting_Date__c,
                                                                EquipmentGuaranteeFlgTxt__c,
                                                                EquipmentGuaranteeFlg__c,
                                                                ifHaveleftInPrevious__c,
                                                                // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 start
                                                                Last_MContract__c
                                                                // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 eng
                                                                // LJPH-C9GD34 gzw fix start
                                                                ,Estimate_List_Price_Page__c
                                                                // LJPH-C9GD34 gzw fix end
                                                                FROM Maintenance_Contract_Asset_Estimate__c
                                                                WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId
                                                                                                         ORDER BY
                                                                                                         Id,
                                                                Asset__c,
                                                                Product_Manual__c,
                                                                Asset__r.SerialNumber,
                                                                Asset__r.Name,
                                                                Asset__r.Department_Name__c,
                                                                Asset__r.InstallDate
                 ]) {
                if (!getPageDisabled() || (getPageDisabled() && String.isBlank(copyid) == false)) {
                    //if (String.isBlank(copyid) == false) {
                    if (mcae.Asset__c <> null) {
                        mcae.EquipmentGuaranteeFlgTxt__c = mcae.Asset__r.EquipmentGuaranteeFlg__c;
                        if (systemToday.addMonths(isNewAddMonth) < mcae.Asset__r.isNewDate_use__c) {
                            mcae.IsNew__c = true;
                            if (String.isNotBlank(mcae.Asset__r.Product2.ProductURF__c)) {
                                //mcae.Estimate_List_Price__c = mcae.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c * isNewPriceAdj;
                                // mcae.Estimate_List_Price__c = mcae.Asset__r.Maintenance_Price_Month__c * isNewPriceAdj;
                                //URF限次合同2期 LY 20220811 start
                                // if (Integer.valueOf(this.estimate.URF_V_MaxRepairCount__c)==2){
                                //     mcae.Estimate_List_Price__c = mcae.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c * isNewPriceAdj;
                                // }else{
                                    mcae.Estimate_List_Price__c = mcae.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c * isNewPriceAdj;
                                // }
 
                                
                                //URF限次合同2期 LY 20220811 end
                            }
                        } else {
                            mcae.IsNew__c = false;
                            if (String.isNotBlank(mcae.Asset__r.Product2.ProductURF__c)) {
                                //mcae.Estimate_List_Price__c = mcae.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
                                // mcae.Estimate_List_Price__c = mcae.Asset__r.Maintenance_Price_Month__c;
                                //URF限次合同2期 LY 20220811 start
                                // if (Integer.valueOf(this.estimate.URF_V_MaxRepairCount__c)==2){
                                //     mcae.Estimate_List_Price__c = mcae.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
                                // }else{
                                    mcae.Estimate_List_Price__c = mcae.Asset__r.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
                                // }
                                
                                //URF限次合同2期 LY 20220811 end
                            }
    
                        }
                    } else if (mcae.Product_Manual__c <> null) {
                        mcae.IsNew__c = true;
                        if (String.isNotBlank(mcae.Product_Manual__r.ProductURF__c)) {
                            //URF限次合同2期 LY 20220811 start
                            //mcae.Estimate_List_Price__c = mcae.Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month__c * isNewPriceAdj;
                            // if (Integer.valueOf(this.estimate.URF_V_MaxRepairCount__c)==2){
                            //     mcae.Estimate_List_Price__c = mcae.Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month__c * isNewPriceAdj;
                            // }else{
                                mcae.Estimate_List_Price__c = mcae.Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month_3__c * isNewPriceAdj;
                            // }
                            
                            //URF限次合同2期 LY 20220811 end
                        }
                    }
                }
                if (mcae.Asset__c <> null) {
                    // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '22222222222222' +));
                    // 1 copy URF   追加
                    // 2 非copy 提交   追加
                    // 3 非copy 未提交 URF   追加
                    if ((String.isNotBlank(mcae.Asset__r.Product2.ProductURF__c) && String.isNotBlank(copyid) ) ||
                        ((getSaveBtnDisabled() && String.isBlank(copyid)) ||
                         (String.isBlank(copyid) && !getSaveBtnDisabled() && String.isNotBlank(mcae.Asset__r.Product2.ProductURF__c)))) {
                        // if ((getSaveBtnDisabled() && String.isBlank(copyid) )|| (((!getSaveBtnDisabled() && String.isBlank(copyid)) && String.isNotBlank(copyid)) && String.isNotBlank(mcae.Asset__r.Product2.ProductURF__c))){
                        // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '1 +  ' + selectedMcaes.size()));
                        selectedAssetIds.put(mcae.Asset__c, selectedMcaes.size());
                        selectedMcaes.add(mcae);
                    }
                    // else if (String.isNotBlank(mcae.Asset__r.Product2.ProductURF__c)) {
                    //     // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '2 +  ' + selectedMcaes.size()));
                    //     selectedAssetIds.put(mcae.Asset__c, selectedMcaes.size());
                    //     selectedMcaes.add(mcae);
                    // }
                } else {
                    if ((String.isNotBlank(mcae.Product_Manual__r.ProductURF__c) && String.isNotBlank(copyid) ) ||
                        ((getSaveBtnDisabled() && String.isBlank(copyid)) ||
                         (String.isBlank(copyid) && !getSaveBtnDisabled() && String.isNotBlank(mcae.Product_Manual__r.ProductURF__c)))) {
                        // if (getSaveBtnDisabled() || (!getSaveBtnDisabled() && String.isNotBlank(mcae.Product_Manual__r.ProductURF__c))){
                        newMcaes.add(mcae);
                    }
                }
            }
        }
        // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '+++++++++++++' + selectedMcaes.size()));
    
        // 選択済みのものにチェックを付ける
        // TODO xudan 一覧に出る明細件数が足りないケースがある
        // ①AssetA―明細Aで明細登録
        // ②Assetの検索条件変更により、AssetAは永遠に取得できない
        // ③Assetを元にデータをマッピングする時、明細マップからAssetAを取得できない?一覧に明細Aが出ない
        // 次回、Assetの検索条件が大きく変更する時、対応必要
        // 限次合同不需要上下限 20210315 gzw start
        // List<Data> datatemp = new List<Data>();
        // datatemp = getChartData();
        // 限次合同不需要上下限 20210315 gzw end
        for (Asset ast : this.assetRecords) {
            Boolean isNew = false;
            // Decimal listPrice = ast.Maintenance_Price_Month__c;
            //Decimal listPrice = ast.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
            //URF限次合同2期 LY 20220811 start
            // Decimal listPrice =0;
            // if (Integer.valueOf(this.estimate.URF_V_MaxRepairCount__c)==2){
            //     listPrice = ast.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
            // }else{
                Decimal listPrice = ast.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
            // }
 
            //URF限次合同2期 LY 20220811 end
            if (selectedAssetIds.containsKey(ast.Id)) {
                Maintenance_Contract_Asset_Estimate__c selectedLocal = selectedMcaes.get(selectedAssetIds.get(ast.Id));
                isNew = selectedLocal.isNew__c;
                listPrice = selectedLocal.Estimate_List_Price__c;
                // xudan 20160110 新品判断ここ要らない、contractStartDateChangeがやる
    //                if (systemToday.addMonths(-6) < ast.InstallDate) {
    //                if (estimate.Contract_Esti_Start_Date__c.addMonths(isNewAddMonth) < ast.InstallDate) {
    //                Date createdDate = (estimate.CreatedDate == null || !String.isBlank(copyid)) ? systemToday : estimate.CreatedDate.date();
    //System.debug(createdDate + '.addMonths(' + isNewAddMonth + ')' + createdDate.addMonths(isNewAddMonth) + ' < ast.InstallDate:' + ast.InstallDate);
    //                if (createdDate.addMonths(isNewAddMonth) < ast.InstallDate) {
    //                    isNew = true;
    //                    listPrice = ast.Maintenance_Price_Month__c * isNewPriceAdj;
    //                }
    //              // 计算上下线调整比例
    //              没有提交 或者在报价时从新计算
                // 限次合同不需要上下限 20210315 gzw start
                if (!getPageDisabled() || (getPageDisabled() && String.isBlank(copyid) == false)) {
                    Date mon1stDate = Date.newInstance(Date.today().year(), Date.today().month(), 1);
                    selectedLocal.LastMContract_Price__c = selectedLocal.Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c == null ?   selectedLocal.LastMContract_Price__c : selectedLocal.Asset__r.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c;
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , 'LastMContract_Price__c--' + selectedLocal.LastMContract_Price__c));
                    if (selectedLocal.Asset__r.CurrentContract_F__r.First_Estimate_Date__c != null && selectedLocal.Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c > mon1stDate) {
                        selectedLocal.Asset_Consumption_rate__c = selectedLocal.Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c == null ? selectedLocal.Asset_Consumption_rate__c : selectedLocal.Asset__r.CurrentContract_F__r.First_contract_usage_Rate__c;
                    } else {
                        selectedLocal.Asset_Consumption_rate__c = selectedLocal.Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c == null ? selectedLocal.Asset_Consumption_rate__c : selectedLocal.Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c;
                    }
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , selectedLocal.Asset__r.CurrentContract_F__r.First_Estimate_Date__c + 'Asset_Consumption--- ' + selectedLocal.Asset__r.CurrentContract_F__r.Estimate_Contract_endDate__c));
    
                    // if(String.isNotBlank(String.valueOf(selectedLocal.Asset_Consumption_rate__c))){
                    //     //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , 'Contract_Consumption_rate__c ' + selectedLocal.Asset__r.CurrentContract_F__r.Contract_Consumption_rate__c));
                    //     for (Data da : datatemp) {
                    //         if (String.isBlank(String.valueOf(da.rate_Lower)) &&  selectedLocal.Asset_Consumption_rate__c < da.rate_Upper) {
                    //             selectedLocal.Adjustment_ratio_Lower__c = da.price_Lower;
                    //             selectedLocal.Adjustment_ratio_Upper__c = da.price_Upper;
                    //             continue;
                    //         }else if (selectedLocal.Asset_Consumption_rate__c >= da.rate_Lower && String.isBlank(String.valueOf(da.rate_Upper))) {
                    //             selectedLocal.Adjustment_ratio_Lower__c = da.price_Lower;
                    //             selectedLocal.Adjustment_ratio_Upper__c = da.price_Upper;
                    //             continue;
                    //         }else if (selectedLocal.Asset_Consumption_rate__c >= da.rate_Lower
                    //                 && selectedLocal.Asset_Consumption_rate__c < da.rate_Upper) {
                    //             selectedLocal.Adjustment_ratio_Lower__c = da.price_Lower;
                    //             selectedLocal.Adjustment_ratio_Upper__c = da.price_Upper;
                    //             continue;
    
                    //         }
                    //         //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , '下限+上限--- ' + selectedLocal.Adjustment_ratio_Lower__c + '  ' + selectedLocal.Adjustment_ratio_Upper__c));
                    //     }
                    //    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , '下限+上限+++ ' + selectedLocal.Adjustment_ratio_Lower__c + '  ' + selectedLocal.Adjustment_ratio_Upper__c));
                    // }
                }
                // 限次合同不需要上下限 20210315 gzw end
    
    //
    //
    //
                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice, selectedLocal));
            } else {
                if (String.isBlank(ast.Product2.ProductURF__c)) continue;
                //update by rentongxiao 2020-09-23 start
                if (ast.AssetMark__c == '主机') {
                    totalRecords++;
                    if (unCheckedAssets.size() < selctRecordNum) {
                        unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast));
                    }
                }
                //update by rentongxiao 2020-09-23 end
    
            }
            // listCut(unCheckedAssets);
            /*
               if (ast.CheckBox__c) {
                checkedAssets.add(new AssetInfo(checkedAssets.size(), ast, isNew, listPrice));
               } else {
                unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast));
               }
             */
        }
        listCut(unCheckedAssets);
    
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
    
        system.debug('顺序检测' + checkedAssets);
        // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '----------------' + newMcaes.size()));
        for (Maintenance_Contract_Asset_Estimate__c mcae : newMcaes) {
            checkedAssets.add(new AssetInfo(checkedAssets.size(), mcae));
        }
    
        // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '2222222222222222' + checkedAssets.size()));
    
        // 最後10行追加
        if (Schema.getGlobalDescribe().get('Maintenance_Contract_Asset_Estimate__c').getDescribe().isCreateable()) {
            this.addNewRows();
        }
    
        if (!String.isBlank(copyid)) {
            this.targetEstimateId = null;
            this.estimate = new Maintenance_Contract_Estimate__c();
            this.estimate.Maintenance_Contract__c = this.targetMaintenanceContractId;
        }
        // 2021-02-07  gzw add  LJPH-BWY5QB start
        setEndUserType(this.targetMaintenanceContractId);
        // 2021-02-07  gzw add  LJPH-BWY5QB start
        assetRecords.clear();
        // 根据合同开始日重新计算维修合同价格
        //contractStartDateChange();
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        List<AssetInfo> topAsset =new List<AssetInfo>();
        List<AssetInfo> otherAsset =new List<AssetInfo>();
        
        for(AssetInfo ched : checkedAssets){
            system.debug('置顶检测2' + ched.ProductModelNoc);
            system.debug('置顶检测3' + ched.AssetModelNoc);
            system.debug('置顶检测5' + ched.rec.OwnershipMachine_No__c);
            // system.debug('置顶检测8' + ched.rec.MDM_Model_No__c);
            // system.debug('置顶检测9' + ched.rec.MDM_Model_No__c);
            if(TopProductModel.contains(ched.ProductModelNoc)||TopProductModel.contains(ched.AssetModelNoc)||TopProductModel.contains(ched.rec.OwnershipMachine_No__c)){
                ched.CheckRows = true;
                ched.mcae.Check_Object__c = false;
                topAsset.add(ched);
            }else{
                otherAsset.add(ched);
            }
        }
        topAsset.addAll(otherAsset);
        List<AssetInfo> NumberSort =new List<AssetInfo>();
        Integer i=0;
        for (AssetInfo ched2 : topAsset) {
            ched2.lineNo=i;
            i++;
            NumberSort.add(ched2);
        }
        checkedAssets=NumberSort;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    }
    
    //
    
    // 取得分页数据
    private void setPageRecord() {
        checkIdList = new List<String> ();
        for (AssetInfo ass : this.checkedAssets) {
            if (!ass.isManual) {
                checkIdList.add(ass.rec.Id);
            }
        }
    
        if ((currPage * selctRecordNum) <= 2000) {
            String notInId = '(\'';
            if (checkIdList.size() > 0) {
                for (String str : checkIdList) {
                    notInId += str + '\', \'';
                }
            }
            notInId += '\')';
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c
            //tcm 删除第4行 Maintenance_Contract_No_F__c 替换 Management_Code__c  20211201 start
            String sqlStr = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, '
                            + 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c, InstallDate,isNewDate_use__c, '
                            + 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c, '
                            + 'CurrentContract_End_Date__c, Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c, '
                                + 'CurrentContract_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,'
                            + 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c, '
                            + 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,'
                            + 'CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,'
                            + 'Product2.ProductURF__c,Product2.ProductURF__r.URFLimitSerial__c,Product2.ProductURF__r.UFR_MaxRepairCount__c,Product2.ProductURF__r.UFR_Maintenance_Price_Month__c,'
                            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                            + 'Product2.ProductURF__r.Maintenance_Price_Year_URF__c, Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c,' 
                            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                            //URF限次合同2期 LY 20220811 start
                            + 'Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c, Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c, Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c,'
                            + 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,'
                            //URF限次合同2期 LY 20220811 end
                            + 'CurrentContract_F__r.Contract_Range__c,AssetMark__c FROM Asset WHERE Product2.ProductURF__c != null AND Hospital__c = \'' + this.targetHospitalId + '\' '
                            + 'AND Id NOT IN ' + notInId;
            //HWAG-B4R3SS  START 20181026
            if (String.isNotBlank(text1) && String.isNotBlank(cond1) && String.isNotBlank(val1)) {
                sqlStr += makeTextSql(text1, cond1, val1);
            }
    
            //JZHG-BSDUT4 ---20200904---update By rentongxiao---Start
            // else{
            //     sqlStr += 'AND AssetMark__c = \'主机\'';
            // }
    
            //JZHG-BSDUT4 ---20200904---update By rentongxiao---end
            //HWAG-B4R3SS  END 20181026
            //HWAG-BDJ43R---XHL---20190729---
            sqlStr += ' AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' )';
            //HWAG-BDJ43R---XHL---20190729---
            sqlStr += ' ORDER BY ID,IF_Warranty__c asc ';
            if (currPage == 1) {
                sqlStr += 'limit ' + selRecordOption;
            } else {
                sqlStr += 'limit ' + selRecordOption + ' offset ' + String.valueOf((currPage - 1) * selctRecordNum);
            }
            //system.debug();
            //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,
            //               '222222222222_____'+sqlStr));
            //return;
            assetRecords = Database.query(sqlStr);
        } else {
            assetRecords.clear();
            Integer sqlLimit = currPage * selctRecordNum;
            List<Asset> temAsset = new List<Asset> ();
            //HWAG-BDJ43R ---XHL---20190729---
            String sqlStr = '';
            //2021-11-30 fy add LJPH-C8W8FV 置顶 start OwnershipMachine_No__c
            //tcm 删除第4行 Maintenance_Contract_No_F__c 替换 Management_Code__c  20211201 start 
            sqlStr  = 'SELECT Id, Name,OwnershipMachine_No__c, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c,';
            sqlStr += 'Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,InstallDate,isNewDate_use__c,';
            sqlStr += 'Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,';
            sqlStr += 'CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c,EquipmentGuaranteeFlg__c,';
                sqlStr += 'CurrentContract_F__c,CurrentContract_F__r.Management_Code__c,CurrentContract_F__r.Maintenance_Contract_No_F__c,CurrentContract_F__r.RecordType_DeveloperName__c,CurrentContract_F__r.Estimate_Num__c,CurrentContract_F__r.Contract_End_Date__c,';
            sqlStr += 'CurrentContract_F_asset__c,CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c,CurrentContract_F_asset__r.endDateGurantee_Text__c,CurrentContract_F__r.Gurantee_Estimate_startDate__c,';
            sqlStr += 'CurrentContract_F__r.First_Estimate_Date__c,CurrentContract_F__r.Estimate_Contract_endDate__c,';
            sqlStr += 'CurrentContract_F__r.Contract_Consumption_rate__c,CurrentContract_F__r.First_contract_usage_Rate__c,';
            sqlStr += 'Product2.ProductURF__c,Product2.ProductURF__r.URFLimitSerial__c,Product2.ProductURF__r.UFR_MaxRepairCount__c,Product2.ProductURF__r.UFR_Maintenance_Price_Month__c,';
            //URF限次合同2期 LY 20220811 start
            sqlStr += 'Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c,';
            sqlStr += 'URF_Maintenance_Contract__c,URF_Maintenance_Contract__r.Management_Code__c,URF_Maintenance_Contract__r.Contract_End_Date__c,';
            //URF限次合同2期 LY 20220811 end
            sqlStr += ' CurrentContract_F__r.Contract_Range__c,AssetMark__c FROM Asset WHERE Product2.ProductURF__c != null AND Hospital__c = \'' + this.targetHospitalId + '\'';
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
            // sqlStr += '  AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' ) ';
            //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
            //HWAG-B4R3SS  START 20181026
            if (String.isNotBlank(text1) && String.isNotBlank(cond1) && String.isNotBlank(val1)) {
                sqlStr += makeTextSql(text1, cond1, val1);
            }
    
            //JZHG-BSDUT4 ---20200904---update By rentongxiao---Start
            // else{
            //     sqlStr += 'AND AssetMark__c = \'主机\'';
            // }
    
            //JZHG-BSDUT4 ---20200904---update By rentongxiao---end
            //HWAG-B4R3SS  END 20181026
            if (checkIdList.size() > 0) {
    
                sqlStr += '  AND Id NOT IN ' + checkIdList;
                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
                //            InstallDate, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c
                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND Id NOT IN : checkIdList AND AssetMark__c != '耗材' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty__c asc limit : sqlLimit];
            } else {
                //temAsset = [SELECT Id, Name, Asset_situation__c, SerialNumber, Department_Name__c, Installation_Site__c, Posting_Date__c,Management_Code__c,IF_Warranty__c,Reson_Can_not_Warranty__c,
                //            InstallDate, Asset_Owner__c, Accumulation_Repair_Amount__c, Maintenance_Price_Month__c, Final_Examination_Date__c,CurrentContract_End_Date__c,Extend_Gurantee_DateTo__c
                //            FROM Asset WHERE Hospital__c = :this.targetHospitalId AND AssetMark__c != '耗材' AND Product2.Family != 'ET' ORDER BY ID,IF_Warranty__c asc limit : sqlLimit];
            }
            sqlStr += ' ORDER BY ID,IF_Warranty__c asc limit ' + sqlLimit;
            temAsset = Database.query(sqlStr);
            //HWAG-BDJ43R ---XHL---20190729---
            if (temAsset.size() >= (currPage * selctRecordNum)) {
                for (Integer i = ((currPage - 1) * selctRecordNum); i < (currPage * selctRecordNum); i++) {
                    assetRecords.add(temAsset.get(i));
                }
            } else {
                for (Integer i = ((currPage - 1) * selctRecordNum); i < temAsset.size(); i++) {
                    assetRecords.add(temAsset.get(i));
                }
            }
        }
        this.unCheckedAssets = new List<AssetInfo>();
        for (Asset ast : assetRecords) {
            this.unCheckedAssets.add(new AssetInfo(unCheckedAssets.size(), ast));
        }
        listCut(unCheckedAssets);
        // 根据合同开始日重新计算维修合同价格
        //contractStartDateChange();
    }
    
    // 翻页到首页
    public void firstPage() {
        getAssetSerialNumber();
        currPage = 1;
        //HWAG-B4R3SS  END 20181026
        totalRecords = soqlNos();
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        //HWAG-B4R3SS  END 20181026
        this.setPageRecord();
    }
    
    // 向前翻页
    public void previousPage() {
        getAssetSerialNumber();
        currPage--;
        //HWAG-B4R3SS  START 20181026
        totalRecords = soqlNos();
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        //HWAG-B4R3SS  END 20181026
        this.setPageRecord();
    }
    
    // 向后翻页
    public void nextPage() {
        getAssetSerialNumber();
        //HWAG-B4R3SS  START 20181026
        totalRecords = soqlNos();
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , 'totalRecords——————' + totalRecords));
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        if (totalRecords == 0) {
            currPage  = 1;
            //this.unCheckedAssets.clear();
        } else {
            currPage++;
            this.setPageRecord();
        }
        //HWAG-B4R3SS  END 20181026
    
    }
    
    // 翻页到尾页
    public void endPage() {
        getAssetSerialNumber();
        //HWAG-B4R3SS  START 20181026
        totalRecords = soqlNos();
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        if (totalRecords == 0) {
            currPage  = 1;
            this.unCheckedAssets.clear();
        } else {
            currPage = totalPage;
            this.setPageRecord();
        }
        //HWAG-B4R3SS  END 20181026
    }
    
    // 每页显示记录数变更
    public void recordNumChange() {
        currPage = 1;
        //totalRecords = soqlNos();
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        this.setPageRecord();
    }
    
    //list分割 集合大小超过1000对应
    private void listCut(List<AssetInfo> records) {
        List<AssetInfo> recordsbreak = new List<AssetInfo>();
        List<AssetInfo> recordsbreakover = new List<AssetInfo>();
        unCheckedAssetsView = new List<List<AssetInfo> >();
        AssetInfo c = null;
        recordsbreak.clear();
        recordsbreakover.clear();
        unCheckedAssetsView.clear();
        unCheckedAssetsView.add(records);
    }
    /*
     *显示过去两年的维修实绩
     *计算该维修合同报价的所有保佑设备,过去两年的修理实绩
     */
    public static void ComputeLTYRepair(String targetHospitalId) {
        system.debug('ComputeLTYRepair=====Start');
        List<Maintenance_Contract_Asset_Estimate__c> McaeList = new List<Maintenance_Contract_Asset_Estimate__c>();
        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c
                    from Maintenance_Contract_Asset_Estimate__c
                    where Maintenance_Contract_Estimate__c = :targetHospitalId];
        List<id> AsList = new List<id>();
        Map<id, id> McaecToAsset = new Map<id, id>();
        for (Maintenance_Contract_Asset_Estimate__c Mcaes : McaeList) {
            AsList.add(Mcaes.asset__c);
            McaecToAsset.put(Mcaes.id, Mcaes.asset__c);
        }
        Maintenance_Contract_Estimate__c mcec = [select id, createdDate, Submit_quotation_day__c from Maintenance_Contract_Estimate__c where id = :targetHospitalId];
        //1年前维修实绩
        Date today = null;
        Date LastYearDate = null;
        Date LastSecondYearDate = null;
        Date LastThirdYearDate = null;
        Decimal LastYearPriceForMCAEC = 0;
    
        if (mcec.Submit_quotation_day__c != null && String.valueOf(mcec.Submit_quotation_day__c) != '') {
            today = mcec.Submit_quotation_day__c;
            LastYearDate = mcec.Submit_quotation_day__c;
            LastSecondYearDate = mcec.Submit_quotation_day__c;
            LastThirdYearDate = mcec.Submit_quotation_day__c;
        } else {
            today = Date.valueOf(mcec.createdDate);
            LastYearDate = Date.valueOf(mcec.createdDate);
            LastSecondYearDate = Date.valueOf(mcec.createdDate);
            LastThirdYearDate = Date.valueOf(mcec.createdDate);
        }
    
        system.debug('去年' + LastYearDate + '前年' + LastSecondYearDate + '大前年' + LastThirdYearDate);
    
        LastYearDate = LastYearDate.addYears(-1);
        // LastYearDate = LastYearDate.addDays(1);
    
        //LastSecondYearDate = LastSecondYearDate.addDays(1);
        LastSecondYearDate = LastSecondYearDate.addYears(-2);
    
        // LastThirdYearDate = LastThirdYearDate.addDays(1);
        LastThirdYearDate = LastThirdYearDate.addYears(-3);
        system.debug('去年' + LastYearDate + '前年' + LastSecondYearDate + '大前年' + LastThirdYearDate);
        // 20191210 Gzw 服务合同过去3年修理实绩合并
        List<AggregateResult> FriRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c > :LastYearDate
            and Agreed_Date__c <= :today
            group by Delivered_Product__c
        ];
        List<AggregateResult> SecRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastYearDate
            and Agreed_Date__c > :LastSecondYearDate
            group by Delivered_Product__c
        ];
        // 过去3年间修理实绩
        List<AggregateResult> ThiRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastSecondYearDate
            and Agreed_Date__c > :LastThirdYearDate
            group by Delivered_Product__c
        ];
        // 过去3年修理实绩
        List<AggregateResult> ThreeyearList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c <= :today
            and Agreed_Date__c > :LastThirdYearDate
            group by Delivered_Product__c
        ];
    
        // system.debug('++++++++'+FriRepairList+'++++++++'+SecRepairList+'+++++++'+ThiRepairList+'+++++');
        // 过去1年间
        Map<id, Decimal> LastFriYearPriceSumMap = new Map<id, Decimal>();
        // 过去2年间
        Map<id, Decimal> LastSecYearPriceSumMap = new Map<id, Decimal>();
        // 过去3年间
        Map<id, Decimal> LastThiYearPriceSumMap = new Map<id, Decimal>();
        // 过去3年
        Map<id, Decimal> ThreeYearPriceSumMap = new Map<id, Decimal>();
        Map<id, Decimal> ThiYearMonthMap = new Map<id, Decimal>();
        for (AggregateResult Rpc : FriRepairList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal Defir = sumPrice1(Rpc);
            LastFriYearPriceSumMap.put(idf, Defir);
        }
        for (AggregateResult Rpc : SecRepairList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal Defir = sumPrice1(Rpc);
            LastSecYearPriceSumMap.put(idf, Defir);
        }
        for (AggregateResult Rpc : ThiRepairList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal Defir = sumPrice1(Rpc);
            LastThiYearPriceSumMap.put(idf, Defir);
        }
        for (AggregateResult Rpc : ThreeyearList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal threeYearM = decimal.valueOf(Rpc.get('threeYearM') + '');
            Decimal Defir = sumPrice1(Rpc);
            ThreeYearPriceSumMap.put(idf, Defir);
            ThiYearMonthMap.put(idf, threeYearM);
        }
        for (Maintenance_Contract_Asset_Estimate__c Mca : McaeList) {
            Mca.Lastyear_Repair_Cost_Text__c = LastFriYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : LastFriYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.Last_Second_Years_Repair_Cost_Text__c = LastSecYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : LastSecYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.Last_Third_Years_Repair_Cost_Text__c = LastThiYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : LastThiYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.Three_Years_Repair_Cost_Text__c = ThreeYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : ThreeYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.The_Date_Of_Compute_The_RPCost__c = Date.today();
            Mca.Last_Third_Years_Repair_Month__c = ThiYearMonthMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : ThiYearMonthMap.get(McaecToAsset.get(Mca.id));
    
    
        }
        try {
            system.debug('McaeList:::::' + McaeList);
            update McaeList;
    
            //return '';
        } catch (Exception e) {
            //return 'McaeList Update Failed : '+e;
        }
    
    }
    
    
    
    public void ComputeLTYRepair() {
        system.debug('ComputeLTYRepair=====Start');
        List<Maintenance_Contract_Asset_Estimate__c> McaeList = new List<Maintenance_Contract_Asset_Estimate__c>();
        McaeList = [select id, asset__c, Lastyear_Repair_Cost_Text__c, Last_Second_Years_Repair_Cost_Text__c, Last_Third_Years_Repair_Cost_Text__c, Three_Years_Repair_Cost_Text__c
                    from Maintenance_Contract_Asset_Estimate__c
                    where Maintenance_Contract_Estimate__c = :targetEstimateId];
        List<id> AsList = new List<id>();
        Map<id, id> McaecToAsset = new Map<id, id>();
        for (Maintenance_Contract_Asset_Estimate__c Mcaes : McaeList) {
            AsList.add(Mcaes.asset__c);
            McaecToAsset.put(Mcaes.id, Mcaes.asset__c);
        }
        Maintenance_Contract_Estimate__c mcec = new Maintenance_Contract_Estimate__c();
        List<Maintenance_Contract_Estimate__c>  mcecList = new List<Maintenance_Contract_Estimate__c>();
        mcecList = [select id, createdDate, Submit_quotation_day__c from Maintenance_Contract_Estimate__c where id = :targetEstimateId];
        if (mcecList.size() == 0) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, '请先保存报价!'));
            return;
        } else {
            mcec = mcecList[0];
        }
        //1年前维修实绩
        Date today = null;
        Date LastYearDate = null;
        Date LastSecondYearDate = null;
        Date LastThirdYearDate = null;
        Decimal LastYearPriceForMCAEC = 0;
    
        if (mcec.Submit_quotation_day__c != null && String.valueOf(mcec.Submit_quotation_day__c) != '') {
            today = mcec.Submit_quotation_day__c;
            LastYearDate = mcec.Submit_quotation_day__c;
            LastSecondYearDate = mcec.Submit_quotation_day__c;
            LastThirdYearDate = mcec.Submit_quotation_day__c;
        } else {
            today = Date.valueOf(mcec.createdDate);
            LastYearDate = Date.valueOf(mcec.createdDate);
            LastSecondYearDate = Date.valueOf(mcec.createdDate);
            LastThirdYearDate = Date.valueOf(mcec.createdDate);
        }
    
        LastYearDate = LastYearDate.addYears(-1);
        // LastYearDate = LastYearDate.addDays(1);
    
        // LastSecondYearDate = LastSecondYearDate.addDays(1);
        LastSecondYearDate = LastSecondYearDate.addYears(-2);
    
        // LastThirdYearDate = LastThirdYearDate.addDays(1);
        LastThirdYearDate = LastThirdYearDate.addYears(-3);
        system.debug('去年' + LastYearDate + '前年' + LastSecondYearDate + '大前年' + LastThirdYearDate);
        // 20191210 Gzw 服务合同过去3年修理实绩合并
        List<AggregateResult> FriRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c > :LastYearDate
            and Agreed_Date__c <= :today
            group by Delivered_Product__c
        ];
        List<AggregateResult> SecRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastYearDate
            and Agreed_Date__c > :LastSecondYearDate
            group by Delivered_Product__c
        ];
        // 过去3年间修理实绩
        List<AggregateResult> ThiRepairList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c <= :LastSecondYearDate
            and Agreed_Date__c > :LastThirdYearDate
            group by Delivered_Product__c
        ];
        // 过去3年修理实绩
        List<AggregateResult> ThreeyearList = [
            select
            sum(Discount_Price_formula__c) SumPrice,
            //2019/1添加
            sum(Repair_Quotation_Id__r.sales_discount__c) sales_discount,
            sum(Repair_Quotation_Id__r.Contract_target__c) contract_target,
            sum(Repair_Quotation_Id__r.Loaner_repair__c) loaner_repair,
            sum(Repair_Quotation_Id__r.long_term_insurance__c) long_term_insurance,
            sum(Repair_Quotation_Id__r.Set_discount__c) set_discount,
            sum(Repair_Quotation_Id__r.Servince_contract_discount_amount__c) sercince,
            sum(Repair_Quotation_Id__r.long_term_insurance_MD__c) long_term_insuranceMD,
            sum(Repair_Quotation_Id__r.Delivery_compensation__c) delivery,
            sum(Repair_Quotation_Id__r.Other_discount__c) other,
            AVG(Delivered_Product__r.Last_Years_Repair_Month__c) threeYearM,
            Delivered_Product__c
            from
            Repair__c
            where
            Delivered_Product__c in:AsList
            and Agreed_Date__c != null
            and Agreed_Date__c <= :today
            and Agreed_Date__c > :LastThirdYearDate
            group by Delivered_Product__c
        ];
        // 过去1年间
        Map<id, Decimal> LastFriYearPriceSumMap = new Map<id, Decimal>();
        // 过去2年间
        Map<id, Decimal> LastSecYearPriceSumMap = new Map<id, Decimal>();
        // 过去3年间
        Map<id, Decimal> LastThiYearPriceSumMap = new Map<id, Decimal>();
        // 过去3年
        Map<id, Decimal> ThreeYearPriceSumMap = new Map<id, Decimal>();
        Map<id, Decimal> ThiYearMonthMap = new Map<id, Decimal>();
        // system.debug('1'+FriRepairList);
        // system.debug('2'+SecRepairList);
        system.debug('3' + ThiRepairList);
    
        for (AggregateResult Rpc : FriRepairList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal Defir = this.sumPrice(Rpc);
            LastFriYearPriceSumMap.put(idf, Defir);
        }
        for (AggregateResult Rpc : SecRepairList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal Defir = this.sumPrice(Rpc);
            LastSecYearPriceSumMap.put(idf, Defir);
        }
        for (AggregateResult Rpc : ThiRepairList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal Defir = sumPrice1(Rpc);
            LastThiYearPriceSumMap.put(idf, Defir);
        }
        for (AggregateResult Rpc : ThreeyearList) {
            id idf        = String.valueOf(Rpc.get('Delivered_Product__c'));
            //Decimal Defir = decimal.valueOf(Rpc.get('SumPrice')+'');
            Decimal threeYearM = decimal.valueOf(Rpc.get('threeYearM') + '');
            Decimal Defir = sumPrice1(Rpc);
            ThreeYearPriceSumMap.put(idf, Defir);
            ThiYearMonthMap.put(idf, threeYearM);
        }
        for (Maintenance_Contract_Asset_Estimate__c Mca : McaeList) {
            Mca.Lastyear_Repair_Cost_Text__c = LastFriYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : LastFriYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.Last_Second_Years_Repair_Cost_Text__c = LastSecYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : LastSecYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.Last_Third_Years_Repair_Cost_Text__c = LastThiYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : LastThiYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.Three_Years_Repair_Cost_Text__c = ThreeYearPriceSumMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : ThreeYearPriceSumMap.get(McaecToAsset.get(Mca.id));
            Mca.The_Date_Of_Compute_The_RPCost__c = Date.today();
            Mca.Last_Third_Years_Repair_Month__c = ThiYearMonthMap.get(McaecToAsset.get(Mca.id)) == null ? 0 : ThiYearMonthMap.get(McaecToAsset.get(Mca.id));
            system.debug('过去3年天数111 ' + Mca.id + '---' + Mca.Last_Third_Years_Repair_Cost_Text__c + ' +++ ' + Mca.Last_Third_Years_Repair_Month__c);
        }
        try {
            update McaeList;
            //return '';
        } catch (Exception e) {
            //return 'McaeList Update Failed : '+e;
        }
    
    }
    
    private Decimal sumPrice(AggregateResult rpc) {
        Decimal SumPrice = Decimal.valueOf(rpc.get('SumPrice') + '');
        system.debug(rpc.get('sales_discount') == null ? 0 : rpc.get('sales_discount'));
        Decimal sales_discount = Decimal.valueOf((rpc.get('sales_discount') == null ? 0 : rpc.get('sales_discount')) + '') * -1;
        Decimal contract_target = Decimal.valueOf((rpc.get('contract_target') == null ? 0 : rpc.get('contract_target')) + '') * -1;
        Decimal loaner_repair = Decimal.valueOf((rpc.get('loaner_repair') == null ? 0 : rpc.get('loaner_repair')) + '') * -1;
        Decimal long_term_insurance = Decimal.valueOf((rpc.get('long_term_insurance') == null ? 0 : rpc.get('long_term_insurance')) + '') * -1;
        Decimal set_discount = Decimal.valueOf((rpc.get('set_discount') == null ? 0 : rpc.get('set_discount')) + '') * -1;
        Decimal sercince = Decimal.valueOf((rpc.get('sercince') == null ? 0 : rpc.get('sercince')) + '') * -1;
        Decimal long_term_insuranceMD = Decimal.valueOf((rpc.get('long_term_insuranceMD') == null ? 0 : rpc.get('long_term_insuranceMD')) + '') * -1;
        Decimal delivery = Decimal.valueOf((rpc.get('delivery') == null ? 0 : rpc.get('delivery')) + '') * -1;
        Decimal other = Decimal.valueOf((rpc.get('other') == null ? 0 : rpc.get('other')) + '') * -1;
        system.debug(rpc.get('SumPrice') + '--' + rpc.get('sales_discount') + '--' + rpc.get('contract_target') + '--' +
                     rpc.get('loaner_repair') + '--' + rpc.get('long_term_insurance') + '--' + rpc.get('set_discount') + '--' + rpc.get('long_term_insuranceMD')
                     + '--' + rpc.get('delivery') + '--' + rpc.get('other') + '--');
        return SumPrice + sales_discount + contract_target + loaner_repair + long_term_insurance + sercince + set_discount + long_term_insuranceMD + delivery + other;
    }
    
    private static Decimal sumPrice1(AggregateResult rpc) {
        Decimal SumPrice = Decimal.valueOf(rpc.get('SumPrice') + '');
        Decimal sales_discount = Decimal.valueOf((rpc.get('sales_discount') == null ? 0 : rpc.get('sales_discount')) + '') * -1;
        Decimal contract_target = Decimal.valueOf((rpc.get('contract_target') == null ? 0 : rpc.get('contract_target')) + '') * -1;
        Decimal loaner_repair = Decimal.valueOf((rpc.get('loaner_repair') == null ? 0 : rpc.get('loaner_repair')) + '') * -1;
        Decimal long_term_insurance = Decimal.valueOf((rpc.get('long_term_insurance') == null ? 0 : rpc.get('long_term_insurance')) + '') * -1;
        Decimal set_discount = Decimal.valueOf((rpc.get('set_discount') == null ? 0 : rpc.get('set_discount')) + '') * -1;
        Decimal sercince = Decimal.valueOf((rpc.get('sercince') == null ? 0 : rpc.get('sercince')) + '') * -1;
        Decimal long_term_insuranceMD = Decimal.valueOf((rpc.get('long_term_insuranceMD') == null ? 0 : rpc.get('long_term_insuranceMD')) + '') * -1;
        Decimal delivery = Decimal.valueOf((rpc.get('delivery') == null ? 0 : rpc.get('delivery')) + '') * -1;
        Decimal other = Decimal.valueOf((rpc.get('other') == null ? 0 : rpc.get('other')) + '') * -1;
        system.debug(rpc.get('SumPrice') + '--' + rpc.get('sales_discount') + '--' + rpc.get('contract_target') + '--' +
                     rpc.get('loaner_repair') + '--' + rpc.get('long_term_insurance') + '--' + rpc.get('set_discount') + '--' + rpc.get('long_term_insuranceMD')
                     + '--' + rpc.get('delivery') + '--' + rpc.get('other') + '--');
        return SumPrice + sales_discount + contract_target + loaner_repair + long_term_insurance + sercince + set_discount + long_term_insuranceMD + delivery + other;
    }
    
    
    //废弃中=========20161024==============//
    public void ShowLTYRepair() {
        system.debug('ShowLTYRepair=====Start');
        lastFriYearsPriceSum = 0;
        lastSecYearsPriceSum = 0;
        //
        List<Maintenance_Contract_Estimate__c> McecList = new List<Maintenance_Contract_Estimate__c>();
        McecList = [select
                    Last_Year_Repair_Sum__c,
                    Year_Before_Last_Year_Re_Sum__c,
                    Last_Two_Year_Repair_sum__c,
                    Process_Status__c,        //报价状态
                    Repair_Sum_Compute_Date__c
                    from
                    Maintenance_Contract_Estimate__c
                    where
                    id = :targetEstimateId
        ];
        Maintenance_Contract_Estimate__c McecEle = new Maintenance_Contract_Estimate__c();
        if (McecList.size() > 0) {
            McecEle = McecList[0];
            Date ComputeD = McecEle.Repair_Sum_Compute_Date__c == null ? Date.today() : McecEle.Repair_Sum_Compute_Date__c;
            String DateString1 = ComputeD + '';
            String DateString2 = ComputeD.addYears(-2).addDays(1) + '';
            alertString = '集計対象期間:' + DateString1.substring(0, 10) + '~' + DateString2.substring(0, 10) + '';
            alertString2 = '去年修理実績合計:' + McecEle.Last_Year_Repair_Sum__c + ' RMB ';
            alertString3 = '前年修理実績合計:' + McecEle.Year_Before_Last_Year_Re_Sum__c + ' RMB';
        } else {
            alertString = '没有有效的维修合同报价';
        }
    }
    /**
     * 手動で商品選択後のリフレッシュ
     **/
    public void refreshProductData() {
        System.debug('1535.......................进入refreshProductData方法');
        System.debug('1536.......................进入refreshProductData方法');
        for (Integer i = 0; i < checkedAssets.size(); i++) {
            if (i == productIdx) {
                AssetInfo ai = checkedAssets[i];
                if (ai.mcae.Product_Manual__c == null) {
                    ai.mcae.Estimate_List_Price__c = null;
                    // add by fxk 2021/9/9 控制点检对象是否可选 Star
                    ai.CheckRows = true;
                    //2021-11-30 fy add LJPH-C8W8FV 置顶 start
                    ai.mcae.Check_Object__c = true;
                    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
                    // add by fxk 2021/9/9 控制点检对象是否可选 End
                    System.debug('1540--');
                } else {
                    //2021-11-30 fy add LJPH-C8W8FV 置顶 start Asset_Model_No__c
                    List<Product2> prd = [select Id,Asset_Model_No__c, Maintenance_Price_Month__c, EquipmentGuaranteeFlg__c, Name,
                                          ProductURF__c, ProductURF__r.URFLimitSerial__c, ProductURF__r.UFR_MaxRepairCount__c, ProductURF__r.UFR_Maintenance_Price_Month__c
                                          //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                                          , ProductURF__r.Maintenance_Price_Year_URF__c, ProductURF__r.Maintenance_Price_Year_URF_Max__c
                                          //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                                          //URF限次合同2期 LY 20220811 start
                                          , ProductURF__r.Maintenance_Price_Year_URF_3__c
                                          , ProductURF__r.Maintenance_Price_Year_URF_Max_3__c
                                          , ProductURF__r.UFR_Maintenance_Price_Month_3__c
                                          //URF限次合同2期 LY 20220811 end
                                          from Product2 where Id = :ai.mcae.Product_Manual__c];
                    ai.mcae.EquipmentGuaranteeFlgTxt__c = prd[0].EquipmentGuaranteeFlg__c;
                    ai.etGFlg = prd[0].EquipmentGuaranteeFlg__c;
                    //add by rentx 2020-11-12 LJPH-BV93RZ start
                    ai.proName = prd[0].Name;
                    //add by rentx 2020-11-12 LJPH-BV93RZ end
                    // add by fxk 2021/9/9 控制点检对象是否可选 Star
                    ai.CheckRows = false;
                    // add by fxk 2021/9/9 控制点检对象是否可选 End
                    // 限次信息 gzw 20210316 start
                    if (String.isBlank(prd[0].ProductURF__c)) {
                        ai.mcae.Product_Manual__c.addError(prd[0].Name + ' 不是限次产品,请重新选择!');
                        return;
                    }
                    //URF限次合同2期 LY 20220811 start
                    //ai.mcae.Estimate_List_Price__c = prd[0].ProductURF__r.UFR_Maintenance_Price_Month__c * isNewPriceAdj;
                    // if (Integer.valueOf(this.estimate.URF_V_MaxRepairCount__c)==2){
                    //     ai.mcae.Estimate_List_Price__c = prd[0].ProductURF__r.UFR_Maintenance_Price_Month__c * isNewPriceAdj;
                    // }else{
                        ai.mcae.Estimate_List_Price__c = prd[0].ProductURF__r.UFR_Maintenance_Price_Month_3__c * isNewPriceAdj;
                    // }
                    
                    //URF限次合同2期 LY 20220811 end
                    //ai.mcae.Maintenance_Price_YearTXT__c = ai.mcae.Estimate_List_Price__c * 12;
                    ai.orgPrice = prd[0].ProductURF__r.UFR_Maintenance_Price_Month__c;
                    ai.uFRPrice = prd[0].ProductURF__r.UFR_Maintenance_Price_Month__c;
                    ai.uFRSerial = prd[0].ProductURF__r.URFLimitSerial__c;
                    //ai.uFRRepairCount = prd[0].ProductURF__r.UFR_MaxRepairCount__c;
                    //URF限次合同2期 LY 20220811 start
                    ai.uFRRepairCount = 0;
                    //URF限次合同2期 LY 20220811 start
                    //2021-11-30 fy add LJPH-C8W8FV 置顶 start
                    ai.MDMModelNoc = prd[0].Asset_Model_No__c;
                    if(TopProductModel.contains(ai.MDMModelNoc)){
                        ai.CheckRows = true;
                        ai.mcae.Check_Object__c = false;
                    }else {
                        if(String.isNotBlank(prd[0].ProductURF__c)){
                            ai.mcae.Check_Object__c = false;
                        }else{
                            ai.mcae.Check_Object__c = true;
                        }
                        ai.CheckRows = false;
                        
                    }
                    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
                    // 限次信息 gzw 20210316 end
                    //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                    ai.uFRMaxPrice = prd[0].ProductURF__r.Maintenance_Price_Year_URF_Max__c;
                    ai.uFRMinPrice = prd[0].ProductURF__r.Maintenance_Price_Year_URF__c;
                    //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                    //URF限次合同2期 LY 20220811 start
                    ai.uFRMaxPrice3 = prd[0].ProductURF__r.Maintenance_Price_Year_URF_Max_3__c;
                    ai.uFRMinPrice3 = prd[0].ProductURF__r.Maintenance_Price_Year_URF_3__c;
                    //URF限次合同2期 LY 20220811 end
                }
            }
        }
        // HWAG-BA73ZP
        //contractStartDateChange();
    }
    
    /**
     * 選択済み/未選択製品の置き換え
     */
    public PageReference exchangeAsset() {
        System.debug('exchangeAsset start');
        Date systemToday = System.today();
        List<AssetInfo> tmpChecked = new List<AssetInfo>();
        List<AssetInfo> tmpNewRows = new List<AssetInfo>();
        List<AssetInfo> tmpUnChecked = new List<AssetInfo>();
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        List<AssetInfo> tmpnewChecked = new List<AssetInfo>();
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        // 限次合同不需要上下限 20210315 gzw start
        // List<Data> datatemp = new List<Data>();
        // datatemp = getChartData();
        // 限次合同不需要上下限 20210315 gzw end
        for (AssetInfo ass : this.checkedAssets) {
            if (ass.isManual) {
                tmpNewRows.add(ass);
            } else if (ass.rec_checkBox_c) {
                tmpChecked.add(ass);
            } else {
                ass.mcae = null;
                tmpUnChecked.add(ass);
                totalRecords++;
            }
        }
        for (AssetInfo ass : this.unCheckedAssets) {
            Boolean isNew = false;
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
            boolean isCheck = true;
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk End
            // Decimal listPrice = ass.rec.Maintenance_Price_Month__c;
            //URF限次合同2期 LY 20220811 start
            //Decimal listPrice = ass.rec.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
            // Decimal listPrice =0;
            // if (Integer.valueOf(this.estimate.URF_V_MaxRepairCount__c)==2){
            //     listPrice = ass.rec.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
            // }else{
                Decimal listPrice = ass.rec.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
            // }
            
            //URF限次合同2期 LY 20220811 end
            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220510 start
            // Decimal MaxPrice = ass.rec.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c;
            // Decimal MinPrice = ass.rec.Product2.ProductURF__r.Maintenance_Price_Year_URF__c;
            Decimal MaxPrice = ass.rec.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c;
            Decimal MinPrice = ass.rec.Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c;
            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220510 end
            if (ass.rec_checkBox_c) {
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , 'unCheckedAssets ' ));
                // xudan 20160110 新品判断ここ要らない、contractStartDateChangeがやる
    //                if (systemToday.addMonths(-6) < ass.rec.InstallDate) {
    //                if (estimate.Contract_Esti_Start_Date__c.addMonths(isNewAddMonth) < ass.rec.InstallDate) {
    //                Date createdDate = estimate.CreatedDate == null ? systemToday : estimate.CreatedDate.date();
    //                if (createdDate.addMonths(isNewAddMonth) < ass.rec.InstallDate) {
    //                    isNew = true;
    //                    listPrice = ass.rec.Maintenance_Price_Month__c * isNewPriceAdj;
    //                }
                Maintenance_Contract_Asset_Estimate__c mcae = new Maintenance_Contract_Asset_Estimate__c(
                    isNew__c = isNew,
                    // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
                    Check_Object__c = isCheck,
                    // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk end
                    Estimate_List_Price__c = listPrice,
                    //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                    Adjustment_Upper_price__c = MaxPrice,
                    Adjustment_Lower_price__c = MinPrice,
                    //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
                    EquipmentGuaranteeFlgTxt__c = ass.rec.EquipmentGuaranteeFlg__c
                    );
                ass.mcae = mcae;
                // 计算上下线调整比例
                // 限次合同不需要上下限 20210315 gzw start
                if (!getPageDisabled()) {
                    // 取当前月第一天
                    Date mon1stDate = Date.newInstance(Date.today().year(), Date.today().month(), 1);
                    mcae.LastMContract_Price__c = ass.rec.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c == null ? mcae.LastMContract_Price__c : ass.rec.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c;
                    if (ass.rec.CurrentContract_F__r.First_Estimate_Date__c != null && ass.rec.CurrentContract_F__r.Estimate_Contract_endDate__c > mon1stDate) {
                        mcae.Asset_Consumption_rate__c = ass.rec.CurrentContract_F__r.First_contract_usage_Rate__c == null ? mcae.Asset_Consumption_rate__c : ass.rec.CurrentContract_F__r.First_contract_usage_Rate__c;
                    } else {
                        mcae.Asset_Consumption_rate__c = ass.rec.CurrentContract_F__r.Contract_Consumption_rate__c == null ? mcae.Asset_Consumption_rate__c : ass.rec.CurrentContract_F__r.Contract_Consumption_rate__c;
                    }
                    // if(String.isNotBlank(String.valueOf(mcae.Asset_Consumption_rate__c))){
                    //     for (Data da : datatemp) {
                    //         if (String.isBlank(String.valueOf(da.rate_Lower)) &&  mcae.Asset_Consumption_rate__c < da.rate_Upper) {
                    //             mcae.Adjustment_ratio_Lower__c = da.price_Lower;
                    //             mcae.Adjustment_ratio_Upper__c = da.price_Upper;
                    //             continue;
                    //         }else if (mcae.Asset_Consumption_rate__c >= da.rate_Lower && String.isBlank(String.valueOf(da.rate_Upper))) {
                    //             mcae.Adjustment_ratio_Lower__c = da.price_Lower;
                    //             mcae.Adjustment_ratio_Upper__c = da.price_Upper;
                    //             continue;
                    //         }else if (mcae.Asset_Consumption_rate__c >= da.rate_Lower
                    //                 && mcae.Asset_Consumption_rate__c < da.rate_Upper) {
                    //             mcae.Adjustment_ratio_Lower__c = da.price_Lower;
                    //             mcae.Adjustment_ratio_Upper__c = da.price_Upper;
                    //             continue;
                    //         }
                    //     }
                    // }
                }
                // 限次合同不需要上下限 20210315 gzw end
    
    
    
                // tmpChecked.add(ass);
                //2021-11-30 fy add LJPH-C8W8FV 置顶 start
                tmpnewChecked.add(ass);
                //2021-11-30 fy add LJPH-C8W8FV 置顶 end
                totalRecords--;
            } else {
                ass.mcae = null;
                tmpUnChecked.add(ass);
            }
        }
    
        this.checkedAssets = new List<AssetInfo>();
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        for (AssetInfo ass : tmpnewChecked) {
            if(String.isNotBlank(ass.rec.Product2.ProductURF__c)){
                ass.mcae.Check_Object__c = false;
            }
            tmpChecked.add(ass);
        }
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        for (AssetInfo ass : tmpChecked) {
            ass.lineNo = this.checkedAssets.size();
            this.checkedAssets.add(ass);
        }
        for (AssetInfo ass : tmpNewRows) {
            ass.lineNo = this.checkedAssets.size();
            this.checkedAssets.add(ass);
        }
        this.unCheckedAssets = new List<AssetInfo>();
        this.unCheckedAssets.addAll(tmpUnChecked);
    
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        this.setPageRecord();
    
        //listCut(unCheckedAssets);
        // 根据合同开始日重新计算维修合同价格
        //contractStartDateChange();
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        List<AssetInfo> topAsset =new List<AssetInfo>();
        List<AssetInfo> otherAsset =new List<AssetInfo>();
        system.debug('aaa'+this.checkedAssets);
        for(AssetInfo ched : this.checkedAssets){
            system.debug('ched.AssetModelNoc======'+ched.AssetModelNoc);
            system.debug('ched.ProductModelNoc======'+ched.ProductModelNoc);
            system.debug('ched.rec.OwnershipMachine_No__c======'+ched.rec.OwnershipMachine_No__c);
            if(TopProductModel.contains(ched.ProductModelNoc)||TopProductModel.contains(ched.AssetModelNoc)||TopProductModel.contains(ched.rec.OwnershipMachine_No__c)){
                ched.CheckRows = true;
                ched.mcae.Check_Object__c = false;
                topAsset.add(ched);
            }else{
                otherAsset.add(ched);
            }
        }
        topAsset.addAll(otherAsset);
        List<AssetInfo> NumberSort =new List<AssetInfo>();
        Integer i=0;
        for (AssetInfo ched2 : topAsset) {
            ched2.lineNo=i;
            i++;
            NumberSort.add(ched2);
        }
        this.checkedAssets=NumberSort;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        return null;
    }
    
    // 合同开始日变更,重新计算新品
    // 合同开始日变更,不计算新品,设备上的新品只看报价时点的状态 注释 BY GZW 20200325
    // public PageReference contractStartDateChange() {
    //     Date systemToday = System.today();
    //     // 创建日
    //     //Date createdDate = estimate.CreatedDate == null ? systemToday : estimate.CreatedDate.date();
    //     Date createdDate = systemToday;
    //     // 创建日3个月
    //     Date threeMonthAfter = createdDate.addMonths(keepPriceMonth);
    //     // 创建日6个月
    //     Date isNewAfter = createdDate.addMonths(-isNewAddMonth);
    //     // 合同开始日
    //     Date contractDate = estimate.Contract_Start_Date__c == null ? systemToday : estimate.Contract_Start_Date__c;
    //     // 合同开始预定日
    //     Date contractEstiDate = estimate.Contract_Esti_Start_Date__c == null ? systemToday : estimate.Contract_Esti_Start_Date__c;
    
    //     /**********************HWAG-AYDCZX 2018/5/8 ADD START***************************/
    //     // 新规、再报价、草案中 维修合同价格显示
    //     System.debug('********changedAfterPrint:'+ (changedAfterPrint ? 'true' : 'false'));
    //     if (this.estimate.CreatedDate == null
    //         || String.isBlank(ApexPages.currentPage().getParameters().get('copyid')) == false
    //         || this.estimate.Process_Status__c == '草案中'
    //         || changedAfterPrint) {
    //         for (AssetInfo info : checkedAssets) {System.debug('********contractDate changed:'+String.valueOf(contractDate));
    
    //             // 合同开始日大于创建日6个月,都不算新品
    //             if (contractEstiDate >= isNewAfter) {
    //             //    if (!info.isManual) {
    //             //        info.mcae.isNew__c = false;
    //             //        info.mcae.Estimate_List_Price__c = info.orgPrice;
    //             //    } else if (info.isManual && !String.isBlank(info.mcae.Product_Manual__c)) {
    //             //        info.mcae.isNew__c = false;
    //             //        info.mcae.Estimate_List_Price__c = info.orgPrice;
    //             //    }
    //             }
    //             // 合同开始日大于创建日3个月,使用合同开始日计算新品
    //             // 使用创建日计算新品
    //             //
    //             //
    //             // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同 20200218 Gzw 服务合同对应
    //             else {
    //                 Date isNewDate = contractDate;
    //                 // Date isNewDate = null;
    //                 // if (contractDate >= threeMonthAfter) {
    //                 //     isNewDate = contractDate;
    //                 // } else {
    //                 //     isNewDate = createdDate;
    //                 // }
    //                 if (!info.isManual) {
    //                     info.mcae.isNew__c = false;
    //                     info.mcae.Estimate_List_Price__c = info.orgPrice;
    //                     // 110からの場合、Postあり、Installなし
    //                     if (info.rec.Posting_Date__c != null && info.rec.InstallDate == null) {
    //                         if (isNewDate.addMonths(isNewAddMonth) < info.rec.Posting_Date__c) {
    //                             info.mcae.isNew__c = true;
    //                             info.mcae.Estimate_List_Price__c = info.orgPrice * isNewPriceAdj;
    //                         }
    //                     }
    //                     // Installあり
    //                     else if (info.rec.Posting_Date__c != null && info.rec.InstallDate != null) {
    //                         // Postから6月経ってもInstallしてない
    //                         // if (info.rec.Posting_Date__c.addMonths(PosttoInstall) < info.rec.isNewDate_use__c) {
    //                         //     // 新品適用しない
    //                         // }
    //                         // else {
    //                             if (isNewDate.addMonths(isNewAddMonth) < info.rec.isNewDate_use__c) {
    //                                 info.mcae.isNew__c = true;
    //                                 info.mcae.Estimate_List_Price__c = info.orgPrice * isNewPriceAdj;
    //                             }
    //                         // }
    //                     }
    //                     // Postなし
    //                     else if (info.rec.Posting_Date__c == null && info.rec.InstallDate != null) {
    //                         if (isNewDate.addMonths(isNewAddMonth) < info.rec.isNewDate_use__c) {
    //                             info.mcae.isNew__c = true;
    //                             info.mcae.Estimate_List_Price__c = info.orgPrice * isNewPriceAdj;
    //                         }
    //                     }
    //                     else {
    //                         // 特殊処理なし
    //                     }
    //                 } else if (info.isManual && !String.isBlank(info.mcae.Product_Manual__c)) {
    //                     info.mcae.isNew__c = true;
    //                     info.mcae.Estimate_List_Price__c = info.orgPrice * isNewPriceAdj;
    //                 }
    //             }
    //         }
    //     }
    //     return null;
    // }
    
    /**
     * 保存メソッド
     */
    public PageReference save() {
        System.debug('save start');
        //add by rentx 2020-11-13 LJPH-BV93RZ start
        if (estimate.Contract_Range__c == null) {
            System.debug('save start00');
            this.estimate.Contract_Range__c.addError('必须输入合同月数!');
            return null;
        }
        //add by rentx 2020-11-13 LJPH-BV93RZ end
        System.debug('save start1');
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
        if (changedSubmitPrice) {
            priceChangeReset();
            return null;
        }
        System.debug('save start2');
        if (syncEstimate(false, false)) {
            ComputeLTYRepair();
            //return null;
            return new PageReference('/' + this.targetEstimateId + '/e?completion=5');
        }
        System.debug('save start3');
        return null;
    }
    
    /**
     * 印刷メソッド、decide前は保有設備、decide後は合同配置
     */
    public void print() {
        System.debug('print start');
        this.printAsset = false;
        this.printContract = false;
        this.printTripartite = false;
        this.printAgent = false;
        this.estimate.PrintDate__c = Date.today();
        //SelectAssetEstimateURFController.ComputeLTYRepair(targetEstimateId);
        if (this.estimate.Quote_Date__c == null) {
            this.estimate.Quote_Date__c = Date.today();
        }
    
    
    
        if (this.estimate.Print_Tripartite__c && this.estimate.Print_Agent__c) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '不能同时选中三方协议和代理商合同!'));
        } else
    
    
        // 保存ボタンできない場合、印刷ボタンはフラグのみ保存
        if (this.getSaveBtnDisabled()) {
            if (savePrintFlg()) {
                // 2018/10/26 HWAG-B5C88S 原来打印逻辑 start
                /*if (this.estimate.Print_Contract__c && !this.estimate.Print_Tripartite__c && !this.estimate.Print_Agent__c) {
                    // 打印医院合同配置
                    this.printContract = true;
                   } else if(this.estimate.Print_Tripartite__c && !this.estimate.Print_Agent__c){
                    //打印三方合同
                    this.printTripartite = true;
                   } else if(!this.estimate.Print_Tripartite__c && this.estimate.Print_Agent__c){
                    //打印经销商合同
                    this.printAgent = true;
                   }else{
                    // 打印保有設備
                    this.printAsset = true;
                   }*/
                // 2018/10/26 HWAG-B5C88S 原来打印逻辑 end
                // 2018/10/26 HWAG-B5C88S start 选择三方打印三方,否则decide前打印保有设备,decide后根据报价对象打印医院或经销商合同
                if (this.estimate.Print_Tripartite__c ) {
                    //打印三方合同
                    this.printTripartite = true;
                } else if (!this.estimate.Estimation_Decision__c) {
                    this.printAsset = true;
    
                } else if (this.estimate.Estimate_Target__c != null && this.estimate.Estimate_Target__c.equals('医院')) {
                    this.printContract = true;
    
                } else if (this.estimate.Estimate_Target__c != null && this.estimate.Estimate_Target__c.equals('经销商')) {
                    this.printAgent = true;
                }
                // 2018/10/26 HWAG-B5C88S end
            }
        }
        // 保存ボタンできる場合、印刷ボタンは全部保存
        else {
            if (syncEstimate(false, false)) {
                // 2018/10/26 HWAG-B5C88S 原来打印逻辑 start
                /*
                   if (this.estimate.Print_Contract__c && !this.estimate.Print_Tripartite__c && !this.estimate.Print_Agent__c) {
                    // 打印医院合同配置
                    this.printContract = true;
                   } else if(this.estimate.Print_Tripartite__c && !this.estimate.Print_Agent__c){
                    //打印三方合同
                    this.printTripartite = true;
                   } else if(!this.estimate.Print_Tripartite__c && this.estimate.Print_Agent__c){
                    //打印经销商合同
                    this.printAgent = true;
                   }else{
                    // 打印保有設備
                    this.printAsset = true;
                   }
                 */
                // 2018/10/26 HWAG-B5C88S 原来打印逻辑 end
                // 2018/10/26 HWAG-B5C88S start 选择三方打印三方,否则decide前打印保有设备,decide后根据报价对象打印医院或经销商合同
                if (this.estimate.Print_Tripartite__c ) {
                    //打印三方合同
                    this.printTripartite = true;
                } else if (!this.estimate.Estimation_Decision__c) {
                    this.printAsset = true;
    
                } else if (this.estimate.Estimate_Target__c != null && this.estimate.Estimate_Target__c.equals('医院')) {
                    this.printContract = true;
    
                } else if (this.estimate.Estimate_Target__c != null && this.estimate.Estimate_Target__c.equals('经销商')) {
                    this.printAgent = true;
                }
                // 2018/10/26 HWAG-B5C88S end
            }
        }
        //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '合同'+this.printContract +'三方'+this.printTripartite+'保有'+this.printAsset+'经销商合同'+this.printAgent));
    }
    
    /**
     * 申請メソッド、最後必ず承認プロセスに載せる
     */
    public PageReference approvalProcess() {
    
    
        Id vmMaintenance_Contract = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId();
        estimate.recordtypeid = vmMaintenance_Contract;
    
        // Date systemToday = System.today();
        // // 创建日/提交日
        // Date createdDate = systemToday;
        // // 创建日6个月
        // Date isNewAfter = createdDate.addMonths(-isNewAddMonth);
        // // 合同开始预定日
        // Date contractEstiDate = estimate.Contract_Esti_Start_Date__c == null ? systemToday : estimate.Contract_Esti_Start_Date__c;
        //  for (AssetInfo info : checkedAssets) {
        //       // 合同预定开始日 大于提交日6个月,都不算新品 20200218 Gzw 服务合同对应
        //       //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'contractEstiDate '+ contractEstiDate +'isNewAfter '+isNewAfter));
        //       if (contractEstiDate >= isNewAfter) {
        //           if (!info.isManual) {
        //               info.mcae.isNew__c = false;
        //               info.mcae.Estimate_List_Price__c = info.orgPrice;
        //            } else if (info.isManual && !String.isBlank(info.mcae.Product_Manual__c)) {
        //               info.mcae.isNew__c = false;
        //               info.mcae.Estimate_List_Price__c = info.orgPrice;
        //            }
        //        }
        // }
    
        if (changedSubmitPrice) {
            priceChangeReset();
            return null;
        }
    
    
        if (syncEstimate(true, false)) {
            Savepoint sp = Database.setSavepoint();
            // 承認プロセスに載せる
            try {
    
                // 已填写申请状态
                this.estimate.ApprovalProcess_Status__c = '已填写完并申请';
                ControllerUtil.updateMaintenance_Contract_Estimate(new Maintenance_Contract_Estimate__c[] {this.estimate});
                // 承認プロセス
                Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
                psr.setObjectId(this.estimate.id);
                Approval.ProcessResult submitResult = Approval.process(psr);
                ComputeLTYRepair();
                if (changedAfterPrint) {
                    return new PageReference('/' + this.targetEstimateId);
                    //return new PageReference('/' + this.targetEstimateId + '/e?completion=1');
                } else {
                    return new PageReference('/' + this.targetEstimateId);
                    //return new PageReference('/' + this.targetEstimateId + '/e?completion=2');
                }
            } catch (Exception ex) {
                System.debug('=====Exception:' + ex.getMessage());
                Database.rollback(sp);
                this.estimate.ApprovalProcess_Status__c = null;
                ApexPages.addMessages(ex);
            }
        }
        return null;
    }
    
    /**
     * 決定取消メソッド
     */
    public PageReference undecide() {
    
    
        System.debug('undecide start');
        this.estimate.Estimation_Decision__c = false;
        this.estimate.Print_Contract__c = false;
    
        //清空报价批准时间
        this.estimate.Quotation_Determines_Time__c = null;
    
        try {
            ControllerUtil.updateMaintenance_Contract_Estimate(new Maintenance_Contract_Estimate__c[] {this.estimate});
            return new PageReference('/' + this.targetEstimateId + '/e?completion=1');
        } catch (Exception ex) {
            ApexPages.addMessages(ex);
        }
        return null;
    }
    
    /**
     * 決定メソッド
     */
    public PageReference decide() {
        System.debug('decide start');
        inDicideFlag = true;
        // TODO check decide 资格
        Savepoint sp = Database.setSavepoint();
    
        if (syncEstimate(false, true)) {
            //提交 报价决定日期
            this.estimate.Quotation_Determines_Time__c = date.today();
    
            if (changedAfterPrint) {
                return new PageReference('/' + this.targetEstimateId + '/e?completion=1');
            } else {
                return new PageReference('/' + this.targetEstimateId + '/e?completion=3');
            }
        }
    
        return null;
    }
    
    public PageReference decideCancle() {
    
        return new PageReference('/' + this.targetEstimateId + '/e?completion=4');
    
    }
    //贸易合规 you start
    public PageReference interceptsend(){
        //String BuchangApprovalManager = this.estimate.BuchangApprovalManager__c;
        //String JingliApprovalManager = this.estimate.JingliApprovalManager__c;
        String fseid = this.estimate.CreatedById;
        String AccDealerBlacklist = this.estimate.Maintenance_Contract__r.AccDealerBlacklist__c;
        String accname = this.estimate.Maintenance_Contract__r.Hospital__r.Name;
        String deaname = this.estimate.Maintenance_Contract__r.Dealer__r.Name;
        //FSE领导
        String[] FSEStr = new String[] {};
        //if(String.isNotBlank(BuchangApprovalManager)){
        //    FSEStr.add(BuchangApprovalManager);
        //}
        //if(String.isNotBlank(JingliApprovalManager)){
        //    FSEStr.add(JingliApprovalManager);
        //}
        FSEStr.add(fseid);
        system.debug('==jinlaile====='+FSEStr);
        Boolean reflag = OpportunityWebService.accSendEmailFW(AccDealerBlacklist,accname,deaname,this.targetEstimateId,'decide_con',FSEStr);
        system.debug('==fawanle====='+FSEStr);
        return null;
    }
    //贸易合规 you end
    
    /**
     * Process用のユーザー情報をセット、新規見積もり時用
     */
    
    private void setApprovalManager() {
        User loginUser = [SELECT Id, Name, JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c, TongkuoZongjian__c FROM User WHERE Id = :UserInfo.getUserId()];
        // 要注意 SaveMaintenanceByCopyController と copyのurlにも、下記の項目もクリア
        this.estimate.JingliApprovalManager__c = loginUser.JingliApprovalManager__c == null ? loginUser.Id : loginUser.JingliApprovalManager__c;
        this.estimate.BuchangApprovalManager__c = loginUser.BuchangApprovalManager__c == null ? loginUser.Id : loginUser.BuchangApprovalManager__c;
        this.estimate.ZongjianApprovalManager__c = loginUser.ZongjianApprovalManager__c == null ? loginUser.Id : loginUser.ZongjianApprovalManager__c;
        this.estimate.Service_Contract_Staff__c = this.contract.Service_Contract_Staff__c;
        this.estimate.TKZongjianApprovalManager__c = loginUser.TongkuoZongjian__c == null ? loginUser.Id : loginUser.TongkuoZongjian__c;
    }
    
    /**
     * 印刷フラグのみを保存
     */
    @TestVisible
    private Boolean savePrintFlg() {
        try {
            Maintenance_Contract_Estimate__c mce = new Maintenance_Contract_Estimate__c();
            mce.Id = this.targetEstimateId;
            //打印报价(简化版) 2019/12/18 start
            mce.Print_Simplify__c = this.estimate.Print_Simplify__c;
            //打印报价(简化版) 2019/12/18 end
            mce.Print_ListPrice__c = this.estimate.Print_ListPrice__c;
            mce.Print_RepairPrice__c = this.estimate.Print_RepairPrice__c;
            mce.Print_SumPrice__c = this.estimate.Print_SumPrice__c;
            mce.Print_DiscountPercentage__c = this.estimate.Print_DiscountPercentage__c;
            mce.Print_DiscountPrice__c = this.estimate.Print_DiscountPrice__c;
            mce.Print_MaintePrice__c = this.estimate.Print_MaintePrice__c;
            mce.Print_Contract__c = this.estimate.Print_Contract__c;
    
            ControllerUtil.updateMaintenance_Contract_Estimate(new Maintenance_Contract_Estimate__c[] {mce});
            return true;
        } catch (Exception ex) {
            ApexPages.addMessages(ex);
        }
        return false;
    }
    
    /**
     * 画面で入力データcheck, save, 親と同期 のロジック
     */
    // TODO xudan チェック追加、clsにも合計金額を計算、clsの合計金額と画面からjsの合計金額を比較
    // 異なる場合、保存完了したらwarningを出す
    public Boolean syncEstimate(boolean isApproval, boolean isDecide) {
        System.debug('syncEstimate start');
        // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'syncEstimates--tart'));
        Boolean hasDatabaseError = false;
        Savepoint sp = Database.setSavepoint();
    
        //bug修复
        //提交 报价决定日期
        // this.estimate.Quotation_Determines_Time__c = date.today();
    
        try {
            System.debug('checkValidate start----------------');
            // 保存限次系列最大次数 20210309
            Map<String, Integer> limitSerialMap = new Map<String, Integer>();
            if (!checkValidate()) {
                return false;
            }
            System.debug('checkValidate end----------------');
            if (checkChangedAfterPrint()) {
                if (isDecide) {
                    // まず Approval
                    isApproval = true;
                    isDecide = false;
                }
            }
            // 验证 开始日期,最早允许制定日之前半年
            Date createdDate = this.estimate.CreatedDate == null ? System.today() : this.estimate.CreatedDate.date();
            createdDate = createdDate.addMonths(isNewAddMonth);
            // if (estimate.Contract_Start_Date__c < createdDate) {
            //     this.estimate.Contract_Start_Date__c.addError('合同开始日最早允许追溯制定日之前半年');
            //     return false;
            // }
            // 验证 用户类型,必填
            if (String.isBlank(estimate.EndUserType__c) ) {
                this.estimate.EndUserType__c.addError('请选择用户类型!');
                return false;
            }
            // 验证 申请报价金额,需要大于0
            if (estimate.Request_quotation_Amount__c <= 0 || estimate.Request_quotation_Amount__c == null) {
                this.estimate.Request_quotation_Amount__c.addError('申请报价金额必需大于0');
                return false;
            }
            // 验证 限次合同的话不能申请低于标准价格最低价的金额
            //URF限次合同2期 LY 20220811 start
            if (estimate.Request_quotation_Amount__c < estimate.GuidePrice_Down__c) {
                this.estimate.Request_quotation_Amount__c.addError('不能申请低于标准价格最低价的金额');
                return false;
            }
            //URF限次合同2期 LY 20220811 end
            // fxk 改报错位置 2021、9、9 Star
            if (estimate.Request_quotation_Amount__c > estimate.GuidePrice_Up__c || estimate.Request_quotation_Amount__c < estimate.GuidePrice_Down__c) {
                if (!(this.estimate.mainTalksTime__c > 0)) {
                    this.estimate.mainTalksTime__c.addError('主要谈判次数必填');
                    return false;
                }
    
                if (this.estimate.talksStartDate__c == null) {
                    this.estimate.talksStartDate__c.addError('谈判的开始时间必填');
                    return false;
                }
    
                if (String.isBlank(this.estimate.Discount_reason__c)) {
                    this.estimate.Discount_reason__c.addError('价格申请理由必填');
                    return false;
                }
                if (String.isBlank(this.estimate.Improve_ConsumptionRate_Idea__c)) {
                    this.estimate.Improve_ConsumptionRate_Idea__c.addError('消费率改善方案必填');
                    return false;
                }
            }
            // fxk 改报错位置 2021、9、9 End
            //>>>
            if (isApproval || isDecide) {
                Boolean hasError = false;
                if (this.estimate.Maintenance_Price__c <= 0) {
                    this.estimate.Maintenance_Price__c.addError('合同价格必需大于0');
                    hasError = true;
                }
    
                // for (AssetInfo input : this.checkedAssets) {
                //     if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                //         if (String.isBlank(input.mcae.Check_Result__c)) {
                //             input.mcae.Check_Result__c.addError('点检结果必填');
                //             hasError = true;
                //         }
                //     }
                // }
                // if (this.estimate.Discount_Price__c > 0 && String.isBlank(this.estimate.Discount_reason__c)) {
                //     this.estimate.Discount_reason__c.addError('减价申请理由必填');
                //     hasError = true;
                // }
                // if (this.estimate.Discount_Price__c > 0 && String.isBlank(this.estimate.Improve_ConsumptionRate_Idea__c)) {
                //     this.estimate.Improve_ConsumptionRate_Idea__c.addError('消费率改善方案必填');
                //     hasError = true;
                // }
                if (hasError) {
                    return false;
                }
            }
            System.debug('验证规则条件验证1: ' + '主要谈判次数 ' + estimate.mainTalksTime__c + '谈判的开始时间 ' + estimate.talksStartDate__c + '价格申请理由 ' + estimate.Discount_reason__c + '消费率改善方案 ' + estimate.Improve_ConsumptionRate_Idea__c);
            System.debug('验证规则条件验证2: ' + '申请报价金额 ' + estimate.Request_quotation_Amount__c);
            System.debug('验证规则条件验证3: ' + '最低价 ' + estimate.GuidePrice_Down__c + '最高价 ' + estimate.GuidePrice_Up__c);
            if (isDecide && getDecideBtnDisabled()) {
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '已经是Decide过的合同 或 不是批准的报价,不能Decide'));
                return false;
            }
    
    
            // 追加上期合同信息 start
            // List<lastMContract> lastMContractRes = getlastMContract(this.checkedAssets);
    
            // 2021-09-10 tcm 排序逻辑调整 start
            List<lastMContract> lastMContractRes;
            if (isDecide) {
                system.debug('执行了tcm isDecide');
                lastMContractRes = getlastMContract(this.checkedAssets,this.estimate.Contract_Start_Date__c);
            } else{
                system.debug('执行了tcm NODecide');
                lastMContractRes = getlastMContract(this.checkedAssets,this.estimate.Contract_Esti_Start_Date__c);
            }
            // 2021-09-10 tcm 排序逻辑调整 end
    
            // URF限次合同2期 LY 20220908 排序逻辑调整 start
            List<lastMContract> urfMContractRes;
            if (isDecide) {
                system.debug('执行了tcm isDecide');
                urfMContractRes = getURFMContract(this.checkedAssets,this.estimate.Contract_Start_Date__c);
            } else{
                system.debug('执行了tcm NODecide');
                urfMContractRes = getURFMContract(this.checkedAssets,this.estimate.Contract_Esti_Start_Date__c);
            }
            // URF限次合同2期 LY 20220908 排序逻辑调整 end
            
            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
            Integer Contract_year = 0;
            System.debug('this.estimate.Contract_Range__c1:' + this.estimate.Contract_Range__c);
            if(this.estimate.Contract_Range__c != null){
                if(this.estimate.Contract_Range__c <= 12){
                    Contract_year = 1;
                } else{
                    Decimal year = this.estimate.Contract_Range__c / 12;
                    Contract_year = (Integer)year.round(System.RoundingMode.CEILING);
                }               
            }
            System.debug('Contract_year1:' + Contract_year);
            // 限次汇总信息
            Map<String, Decimal> uFRSerialMap = getLimitSerialData(Contract_year);
            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
            // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'lastMContractRes +++++!' + lastMContractRes));
            // if (true) {
            //     return false;
            // }
            
            this.estimate.LastMContract1__c = lastMContractRes[0].contractId;
            this.estimate.LastMContract1_NO__c = lastMContractRes[0].contractNo;
            this.estimate.LastMContract1_ConCount__c = lastMContractRes[0].count;
    
            this.estimate.LastMContract2__c = lastMContractRes[1].contractId;
            this.estimate.LastMContract2_NO__c = lastMContractRes[1].contractNo;
            this.estimate.LastMContract2_ConCount__c = lastMContractRes[1].count;
    
            this.estimate.LastMContract3__c = lastMContractRes[2].contractId;
            this.estimate.LastMContract3_NO__c = lastMContractRes[2].contractNo;
            this.estimate.LastMContract3_ConCount__c = lastMContractRes[2].count;
    
            this.estimate.LastMContract4__c = lastMContractRes[3].contractId;
            this.estimate.LastMContract4_NO__c = lastMContractRes[3].contractNo;
            this.estimate.LastMContract4_ConCount__c = lastMContractRes[3].count;
    
            this.estimate.LastMContract5__c = lastMContractRes[4].contractId;
            this.estimate.LastMContract5_NO__c = lastMContractRes[4].contractNo;
            this.estimate.LastMContract5_ConCount__c = lastMContractRes[4].count;
    
            // 追加上期合同信息 end
    
            //URF限次合同2期 LY 20220908 start
            //追加限次合同信息
            this.estimate.URFMContract1__c = urfMContractRes[0].contractId;
            this.estimate.URF_LastMContract1_NO__c = urfMContractRes[0].contractNo;
            this.estimate.URF_LastMContract1_ConCount__c = urfMContractRes[0].count;
    
            //this.estimate.URFMContract2__c = urfMContractRes[1].contractId;
            this.estimate.URF_LastMContract2_NO__c = urfMContractRes[1].contractNo;
            this.estimate.URF_LastMContract2_ConCount__c = urfMContractRes[1].count;
    
            //this.estimate.URFMContract3__c = urfMContractRes[2].contractId;
            this.estimate.URF_LastMContract3_NO__c = urfMContractRes[2].contractNo;
            this.estimate.URF_LastMContract3_ConCount__c = urfMContractRes[2].count;
    
            //this.estimate.URFMContract4__c = urfMContractRes[3].contractId;
            this.estimate.URF_LastMContract4_NO__c = urfMContractRes[3].contractNo;
            this.estimate.URF_LastMContract4_ConCount__c = urfMContractRes[3].count;
    
            //this.estimate.URFMContract5__c = urfMContractRes[4].contractId;
            this.estimate.URF_LastMContract5_NO__c = urfMContractRes[4].contractNo;
            this.estimate.URF_LastMContract5_ConCount__c = urfMContractRes[4].count;
            //URF限次合同2期 LY 20220908 end
    
            // 同期処理
            // ①维修合同に既存の保有设备を削除
            // ②保存した维修合同报价の保有设备を维修合同にコピー(Asset__cが設定さているデータだけ)
            // ③他の维修合同报价の同期フラグを外す
            // ④维修合同の Estimate_Trial_Money__c、Contract_Amount__c, Service_contract_target_number__c を更新
            this.estimate.IsSyncing__c = true;
            if (isDecide) {
                // 20200923 Gzw bug 修改
                //清空报价批准时间
                this.estimate.Quotation_Determines_Time__c = Date.today();
                this.estimate.Estimation_Decision__c = true;
            }
            // TODO validate
    
            // TODO validate check新品チェック(納品日で判断)
    
            // save
            // ③ start
            for (List<Maintenance_Contract_Estimate__c> otherEstimates : [select Id from Maintenance_Contract_Estimate__c where Id <> :this.estimate.Id
                                                                          and Maintenance_Contract__c = :this.contract.Id
                                                                                                        and IsSyncing__c = true]) {
                for (Maintenance_Contract_Estimate__c other : otherEstimates) {
                    other.IsSyncing__c = false;
                    if (isDecide) {
                        other.Estimation_Decision__c = false;
                    }
                }
                ControllerUtil.updateMaintenance_Contract_Estimate(otherEstimates);
            }
    
            // 合同结束预定日を算出
            Date t = this.estimate.Contract_Esti_Start_Date__c.addMonths(Integer.valueOf(this.estimate.Contract_Range__c));
            // 20151217 xudan 维修合同报价SH-RS-JS0046560-01 期间显示问题
            // うるう年特殊対応
            if (this.estimate.Contract_Esti_Start_Date__c.month() == 2 && this.estimate.Contract_Esti_Start_Date__c.day() == 29
                && t.month() == 2) {
                t = t;
            } else {
                t = t.addDays(-1);
            }
            this.estimate.Contract_Esti_End_Date__c = t;
            // decide 时,跳过赋值 JZHG-BRH5MU 20200715 start
            if (!isDecide) {
                this.estimate.New_Contract_Type_TxT__c = typeresult;
            }
            // decide 时,跳过赋值 JZHG-BRH5MU 20200715 end
            // 合同开始日を结束日
            if (this.estimate.Contract_Start_Date__c == null) {
                this.estimate.Contract_Start_Date__c = this.estimate.Contract_Esti_Start_Date__c;
            }
            t = this.estimate.Contract_Start_Date__c.addMonths(Integer.valueOf(this.estimate.Contract_Range__c));
            t = t.addDays(-1);
            this.estimate.Contract_End_Date__c = t;
            // 位置调整 在1951 line
            // Date createdDate = this.estimate.CreatedDate == null ? System.today() : this.estimate.CreatedDate.date();
            // 3ヶ月超過している場合には、Decideできない
            //if (createdDate.addMonths(3) <= System.today()) {
            //    this.estimate.addError('已超过3个月,请先更新报价。');
            //    return false;
            //}
            // 维修合同报价
            // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'this.targetEstimateId ++++++ ' + this.targetEstimateId));
            // if (true) {
            //     return false;
            // }
            //URF限次合同2期 LY 20220920 start
            //提交之后decide之前,经销商变更的话,先款信息以变更后的经销商先款信息执行 thh 20220418 start
            if(String.isNotBlank(this.estimate.Dealer__c)){
                checkDealerId = this.estimate.Dealer__c;
                onChDealerUpdate();
            }else{
                this.estimate.Is_RecognitionModel__c = false;
            }
            //提交之后decide之前,经销商变更的话,先款信息以变更后的经销商先款信息执行 thh 20220418 end
            //URF限次合同2期 LY 20220920 end
            if (String.isBlank(this.targetEstimateId)) {
                newIns = true;
                this.estimate.Process_Status__c = '草案中';
                // nameに番号をセット
                List<Maintenance_Contract_Estimate__c> maxNameRecords = [select Name From Maintenance_Contract_Estimate__c Where Maintenance_Contract__c = :this.contract.Id order by Name desc limit 1];
                String oppNo;
                Integer l = 1;
                if (maxNameRecords.size() > 0) {
                    try {
                        oppNo = maxNameRecords[0].Name;
                        l = Integer.valueOf(oppNo.substring(oppNo.length() - 2)) + 1;
                    } catch (System.TypeException e) {
                        System.debug('maxNameRecords Error: Maintenance_Contract__c.id=' + maxNameRecords[0].id);
                    }
                } else {
                    System.debug('first Maintenance_Contract_Estimate__c');
                }
                oppNo = '00' + String.valueof(l);
                oppNo = oppNo.substring(oppNo.length() - 2);
                this.estimate.Name = this.contract.Management_Code__c + '-' + oppNo;
                setApprovalManager();
                System.debug('Process_Status__c=' + this.estimate.Process_Status__c);
                insert this.estimate;
                this.targetEstimateId = this.estimate.Id;
                setThisEstimate();
            } else {
                if (isApproval) {
                    setApprovalManager();
                }
                ControllerUtil.updateMaintenance_Contract_Estimate(new Maintenance_Contract_Estimate__c[] {this.estimate});
            }
            // 维修合同报价/保有设备
            // delete and insertする
            List<Maintenance_Contract_Asset_Estimate__c> insertTarget = new List<Maintenance_Contract_Asset_Estimate__c>();
            // 是否使用首次报价日更新
            // 需要注意对报价提交日+3个月与合同结束日进行比较
            // 1)报价提交日+3个月的日期,小于合同结束日时,以合同结束日作为报价有效期的结束日
            // 2)报价提交日+3个月的日期,大于合同结束日时,报价提交日+3个月的日期作为报价有效期的结束日
            //
            //
            //  因为月初计算消费率,所以结束日在上月或以前,可以取到完整消费率,否则保存首次报价日
            Date toDate = Date.today();
            Date mon1stDate = Date.newInstance(toDate.year(), toDate.month(), 1);
            // list 修改 map
            Map<id, Maintenance_Contract__c> mcList = new Map<id, Maintenance_Contract__c>();
            for (AssetInfo input : this.checkedAssets) {
                if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                    //Maintenance_Contract_Asset_Estimate__c mcae = new Maintenance_Contract_Asset_Estimate__c();
                    input.mcae.Id = null;                   // insertのため
                    // 同じの場合設定しない
                    if (input.mcae.Maintenance_Contract_Estimate__c != this.targetEstimateId) {
                        // 親変更できない可能性があるため、設定するときエラーになるが、エラーにならないように他のロジックを工夫してください。
                        input.mcae.Maintenance_Contract_Estimate__c = this.targetEstimateId;
                    }
                    input.mcae.Maintenance_Price_Month__c = input.rec.Maintenance_Price_Month__c;
                    // 病院に所属する保有設備
    
                    if (!input.isManual) {
                        input.mcae.Asset__c = input.rec.Id;
                        input.mcae.Product_Manual__c = null;
                        input.mcae.Estimate_Cost__c = input.mcae.Estimate_Cost__c;
                        input.mcae.LastMContract_Price__c = input.rec.CurrentContract_F_asset__r.Estimate_Cost_Month_formula__c;
                        //input.mcae.Asset_Consumption_rate__c = input.mcae.Asset_Consumption_rate__c;
                    }
                    // 提交时,更新 是否使用上一期维修合同首次报价日
                    if (isApproval) {
                        Maintenance_Contract__c mctemp = new Maintenance_Contract__c();
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , '+++++ ' + ass.rec.CurrentContract_F__r.Contract_End_Date__c + '   ' + mon1stDate));
                        // 因为月初计算消费率,所以结束日在上月或以前,可以取到完整消费率,否则保存首次报价日
                        if (input.rec.CurrentContract_F__r.Contract_End_Date__c >= mon1stDate) {
                            if (input.rec.CurrentContract_F__r.First_Estimate_Date__c == null) {
                                mctemp.Id = input.rec.CurrentContract_F__c;
                                mctemp.First_contract_usage_Rate__c = input.rec.CurrentContract_F__r.Contract_Consumption_rate__c;
                                mctemp.First_Estimate_Date__c = Date.today();
                                mcList.put(mctemp.Id, mctemp);
                                input.mcae.ifHaveleftInPrevious__c = true;
                            }
                        }
                    }
                    if (!isDecide) {
                        //URF限次合同2期 LY 20220811 start
                        // if (input.uFRSerial=='URF-V' && Integer.valueOf(estimate.URF_V_MaxRepairCount__c)!=0){
                        //     input.uFRRepairCount = Integer.valueOf(estimate.URF_V_MaxRepairCount__c);
                        // }else if (input.uFRSerial=='URF-P' && Integer.valueOf(estimate.URF_P_MaxRepairCount__c)!=0) {
                        //     input.uFRRepairCount = Integer.valueOf(estimate.URF_P_MaxRepairCount__c);
                        // }else{
                        //     input.uFRRepairCount= 0;
                        // }
                        if (input.uFRSerial=='URF-V') {
                            input.uFRRepairCount = Integer.valueOf(estimate.URF_V_MaxRepairCount__c);
                        }
                        if (input.uFRSerial=='URF-P') {
                            input.uFRRepairCount = Integer.valueOf(estimate.URF_P_MaxRepairCount__c);
                        }
                        //URF限次合同2期 LY 20220811 end
                        // 限次信息保存
                        input.mcae.URF_Series__c = input.uFRSerial;
                        input.mcae.Series_RepairCount__c = 0;
                        input.mcae.Series_MaxRepairCount__c = uFRSerialMap.get(input.uFRSerial);
                        input.mcae.Asset_RepairCount__c = 0;
                        //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
                        input.mcae.Asset_MaxRepairCount__c = input.uFRRepairCount * Contract_year;
                        //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
    
    
                        // 限次信息保存
                    }
    
    
    
    
                    // Manual商品
                    if (input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                        input.mcae.Asset__c = null;
                        //mcae.Product_Manual__c = input.mcae.Product_Manual__c;
                    }
                    //新规时,保存新合同备品保证提供 Decide 后
                    if (!isDecide) {
                        input.mcae.EquipmentGuaranteeFlgTxt__c = input.etGFlg;
                    }
                    // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 start
    
                    // 2020/10/30 songxiaoqi start
                    if (input.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
                        input.mcae.Last_MContract__c = input.rec.CurrentContract_F__c;
    
                    }
                    //songxiaoqi end
    
    
                    // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 end
                    //mcae.Estimate_List_Price__c = input.mcae.Estimate_List_Price__c;
                    //mcae.IsNew__c = input.mcae.isNew__c;
                    //mcae.Check_Result__c = input.mcae.Check_Result__c;
                    //mcae.Repair_Price__c = input.mcae.Repair_Price__c;
                    //mcae.Comment__c = input.mcae.Comment__c;
                    insertTarget.add(input.mcae);
                }
            }
            // 本当に保存した納入機器があれば削除
            List<Maintenance_Contract_Asset_Estimate__c> selectedAsset = [SELECT Id, Name, Maintenance_Contract_Estimate__c, Asset__c, IsNew__c FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__c = :this.targetEstimateId];
            if (selectedAsset.size() > 0) {
                ControllerUtil.deleteMaintenance_Contract_Asset_Estimate(selectedAsset);
            }
            if (insertTarget.size() > 0) {
                ControllerUtil.insertMaintenance_Contract_Asset_Estimate(insertTarget);
            }
    
            // ① start
            for (List<Maintenance_Contract_Asset__c> oldList : [select Id from Maintenance_Contract_Asset__c
                                                                where Maintenance_Contract__c = :this.estimate.Maintenance_Contract__c]) {
                delete oldList;
            }
            // ② start
            {
                List<Maintenance_Contract_Asset__c> newValue = new List<Maintenance_Contract_Asset__c>();
                for (Maintenance_Contract_Asset_Estimate__c target : [select Id, Asset__c, Estimate_List_Price__c, Estimate_Cost__c,  IsNew__c, EquipmentGuaranteeFlgTxt__c,
                                                                      //add 点检改善:合同保有设备下的点检对象与报价保有设备下的点检对象同步 2021.6.9 fxk start
                                                                      Check_Object__c,
                                                                      //add 点检改善:合同保有设备下的点检对象与报价保有设备下的点检对象同步 2021.6.9 fxk end
                                                                      // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 start
                                                                      Last_MContract__c
                                                                      // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 eng
                                                                      , Last_MContract__r.RecordType_DeveloperName__c
                                                                      // LJPH-C9GD34 gzw fix start
                                                                      ,Estimate_List_Price_Page__c
                                                                      // LJPH-C9GD34 gzw fix end
                                                                      from Maintenance_Contract_Asset_Estimate__c
                                                                      where Maintenance_Contract_Estimate__c = :this.estimate.Id and Asset__c <> null]) {
    
                    Maintenance_Contract_Asset__c newVal = new Maintenance_Contract_Asset__c(
                        Maintenance_Contract__c = this.estimate.Maintenance_Contract__c,
                        Asset__c = target.Asset__c,
                        Maintenance_Contract_Asset_Estimate__c = target.Id,
                        Estimate_List_Price__c = target.Estimate_List_Price__c,
                        //Maintenance_Price_YearTXT__c = target.Maintenance_Price_YearTXT__c,
                        ////add 点检改善:合同保有设备下的点检对象与报价保有设备下的点检对象同步 2021.6.9 fxk start
                        Check_Object__c = target.Check_Object__c,
                        //add 点检改善:合同保有设备下的点检对象与报价保有设备下的点检对象同步 2021.6.9 fxk end
                        Estimate_IsNew__c = target.IsNew__c,
                        //EquipmentGuaranteeFlgTxt__c = target.EquipmentGuaranteeFlgTxt__c,
                        // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 start
                        // LastMContract__c = target.Last_MContract__c
                        // Gzw 20200807 五个去年合同相关,所以报价产品,获取上期合同 end
                        //如果是多年保修合同,不更新上期维修合同信息 LJPH-BUU3E3 update by rentx  2020-11-03
                        LastMContract__c = target.Last_MContract__r.RecordType_DeveloperName__c == 'VM_Contract' ? null : target.Last_MContract__c
                        );
                    newValue.add(newVal);
                }
                if (newValue.size() > 0) insert newValue;
            }
            // ④ start
            this.contract.Estimation_Id__c = this.targetEstimateId;
            this.contract.Contract_Esti_Start_Date__c = this.estimate.Contract_Esti_Start_Date__c;
            this.contract.Contract_Range__c = this.estimate.Contract_Range__c;
            this.contract.Contract_Esti_End_Date__c = this.estimate.Contract_Esti_End_Date__c;
            this.contract.Estimate_Target__c = this.estimate.Estimate_Target__c;
            this.contract.Dealer__c = this.estimate.Dealer__c;
            //URF限次合同2期 LY 20220920 start
            this.contract.old_Is_RecognitionModel__c = this.estimate.Is_RecognitionModel__c;
            //URF限次合同2期 LY 20220920 end
            this.contract.NotUse_Oxygenated_Water__c = this.estimate.NotUse_Oxygenated_Water__c;
            this.contract.Estimate_Trial_Money__c = this.estimate.Estimate_Trial_Money__c;
            this.contract.Contract_Amount__c = this.estimate.Maintenance_Price__c;
            this.contract.Service_contract_target_number__c = this.estimate.Service_contract_target_number__c;
            this.contract.Contract_department_manual__c = this.estimate.Department__c;
            
    
            // 追加上期合同信息 start
            this.contract.LastMContract1__c = this.estimate.LastMContract1__c;
            this.contract.LastMContract1_NO__c = this.estimate.LastMContract1_NO__c;
            this.contract.LastMContract1_ConCount__c =  this.estimate.LastMContract1_ConCount__c;
    
            //add by rentx 2021-06-04 给合同1赋值的同时,给去年合同赋值 start
            this.contract.Last_year_service_contract__c = this.estimate.LastMContract1__c;
            //add by renrx 2021-06-04 给合同1赋值的同时, 给去年合同赋值 end
    
            this.contract.LastMContract2__c =  this.estimate.LastMContract2__c;
            this.contract.LastMContract2_NO__c = this.estimate.LastMContract2_NO__c;
            this.contract.LastMContract2_ConCount__c =  this.estimate.LastMContract2_ConCount__c;
    
            this.contract.LastMContract3__c =  this.estimate.LastMContract3__c;
            this.contract.LastMContract3_NO__c = this.estimate.LastMContract3_NO__c;
            this.contract.LastMContract3_ConCount__c =  this.estimate.LastMContract3_ConCount__c;
    
            this.contract.LastMContract4__c =  this.estimate.LastMContract4__c;
            this.contract.LastMContract4_NO__c = this.estimate.LastMContract4_NO__c;
            this.contract.LastMContract4_ConCount__c =  this.estimate.LastMContract4_ConCount__c;
    
            this.contract.LastMContract5__c =  this.estimate.LastMContract5__c;
            this.contract.LastMContract5_NO__c = this.estimate.LastMContract5_NO__c;
            this.contract.LastMContract5_ConCount__c =  this.estimate.LastMContract5_ConCount__c;
            // 追加上期合同信息 end
 
            //URF限次合同2期 LY 20220908 start
            //追加上期限次合同信息 start
            this.contract.URF_LastMContract1__c = this.estimate.URFMContract1__c;
            this.contract.URF_LastMContract1_startDate__c = this.estimate.URFMContract1_startDate__c;
            this.contract.URF_LastMContract1_endDate__c = this.estimate.URFMContract1_endDate__c;
            this.contract.URF_LastMContract1_NO__c = this.estimate.URF_LastMContract1_NO__c;
            this.contract.URF_LastMContract1_ConCount__c =  this.estimate.URF_LastMContract1_ConCount__c;
    
            //this.contract.URF_LastMContract2__c =  this.estimate.URFMContract2__c;
            this.contract.URF_LastMContract2_NO__c = this.estimate.URF_LastMContract2_NO__c;
            this.contract.URF_LastMContract2_ConCount__c =  this.estimate.URF_LastMContract2_ConCount__c;
    
            //this.contract.URF_LastMContract3__c =  this.estimate.URFMContract3__c;
            this.contract.URF_LastMContract3_NO__c = this.estimate.URF_LastMContract3_NO__c;
            this.contract.URF_LastMContract3_ConCount__c =  this.estimate.URF_LastMContract3_ConCount__c;
    
            //this.contract.URF_LastMContract4__c =  this.estimate.URFMContract4__c;
            this.contract.URF_LastMContract4_NO__c = this.estimate.URF_LastMContract4_NO__c;
            this.contract.URF_LastMContract4_ConCount__c =  this.estimate.URF_LastMContract4_ConCount__c;
    
            //this.contract.URF_LastMContract5__c =  this.estimate.URFMContract5__c;
            this.contract.URF_LastMContract5_NO__c = this.estimate.URF_LastMContract5_NO__c;
            this.contract.URF_LastMContract5_ConCount__c =  this.estimate.URF_LastMContract5_ConCount__c;
            // 追加上期限次合同信息 end
            //URF限次合同2期 LY 20220908 end
    
            system.debug('测算isDecide的结果_1::::::::' + isDecide);
            if (isDecide == true) {
                system.debug('测算isDecide的结果_2::::::::' + isDecide);
    //              this.contract.Contract_Start_Date__c = this.estimate.Contract_Esti_Start_Date__c;
                this.contract.Contract_Start_Date__c = this.estimate.Contract_Start_Date__c;
                this.contract.Contract_Range__c = this.estimate.Contract_Range__c;
    //              this.contract.Contract_End_Date__c = this.estimate.Contract_Esti_End_Date__c;
                this.contract.Contract_End_Date__c = this.estimate.Contract_End_Date__c;
                this.contract.JingliApprovalManager__c = this.estimate.JingliApprovalManager__c;
                this.contract.BuchangApprovalManager__c = this.estimate.BuchangApprovalManager__c;
                this.contract.ZongjianApprovalManager__c = this.estimate.ZongjianApprovalManager__c;
                this.contract.Finally_Approved_Staff__c = this.estimate.Finally_Approved_Staff__c;
                this.contract.TKZongjianApprovalManager__c = this.estimate.TKZongjianApprovalManager__c;
                // JZHG-BQV3P4 20200624 Gzw add
                this.contract.HospitalAmountText__c = this.estimate.AgencyHos_Price__c;
                // JZHG-BQV3P4 20200624 Gzw add
            }
            //添加的额外对应过程
            if (inDicideFlag == true && (this.contract.Contract_Start_Date__c == null || this.contract.Contract_End_Date__c == null)) {
                system.debug('测算inDicideFlag的结果_2::::::::' + isDecide);
    //              this.contract.Contract_Start_Date__c = this.estimate.Contract_Esti_Start_Date__c;
                this.contract.Contract_Start_Date__c = this.estimate.Contract_Start_Date__c;
                this.contract.Contract_Range__c = this.estimate.Contract_Range__c;
    //              this.contract.Contract_End_Date__c = this.estimate.Contract_Esti_End_Date__c;
                this.contract.Contract_End_Date__c = this.estimate.Contract_End_Date__c;
                this.contract.JingliApprovalManager__c = this.estimate.JingliApprovalManager__c;
                this.contract.BuchangApprovalManager__c = this.estimate.BuchangApprovalManager__c;
                this.contract.ZongjianApprovalManager__c = this.estimate.ZongjianApprovalManager__c;
                this.contract.Finally_Approved_Staff__c = this.estimate.Finally_Approved_Staff__c;
                this.contract.TKZongjianApprovalManager__c = this.estimate.TKZongjianApprovalManager__c;
                // JZHG-BQV3P4 20200624 Gzw add
                this.contract.HospitalAmountText__c = this.estimate.AgencyHos_Price__c;
                // JZHG-BQV3P4 20200624 Gzw add
            }
            String oldProcessStatus = this.estimate.Process_Status__c;
            try {
                if (mcList.size() > 0) {
                    ControllerUtil.updMcList(mcList.values());
                }
                ControllerUtil.updateMaintenance_Contract_Estimate(new Maintenance_Contract_Estimate__c[] {this.estimate});
                update this.contract;
            } catch (Exception e) {
                // TODO 今後複数件の場合どうする?
                this.estimate.addError(e);
                // 一部の値を戻す
                this.estimate.Process_Status__c = oldProcessStatus;
                hasDatabaseError = true;
                Database.rollback(sp);
                ApexPages.addMessages(e);
            }
            if (hasDatabaseError) {
                System.debug('syncEstimate hasDatabaseError');
                return false;
            }
            if (isApproval) {
                SelectAssetEstimateURFController.ComputeLTYRepair(targetEstimateId);
            }
            // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'syncEstimates--end'));
            return true;
        } catch (DMLException ex) {
            // TODO Insert失敗のIDを消す必要?
            Database.rollback(sp);
            ApexPages.addMessages(ex);
        } catch (Exception ex) {
            Database.rollback(sp);
            ApexPages.addMessages(ex);
        }
        return false;
    }
    
    /**
     * 印刷後変更がある場合、true
     */
    @TestVisible
    private Boolean checkChangedAfterPrint() {
        System.debug('checkChangedAfterPrint start');
        if (changedAfterPrint) {
            this.targetEstimateId = null;
            this.estimate = this.estimate.clone();
            this.estimate.IS_Clone_After_Decide__c = true;
            this.estimate.PrintDate__c = null;
            this.estimate.Quote_Date__c = null;
            this.estimate.Print_Contract__c = false;
            this.estimate.Print_RepairPrice__c = false;
            this.estimate.Print_DiscountPercentage__c = false;
            this.estimate.Print_DiscountPrice__c = false;
            this.estimate.Print_ListPrice__c = false;
            //打印报价(简化版) 2019/12/18 start
            this.estimate.Print_Simplify__c = false;
            //打印报价(简化版) 2019/12/18 end
            this.estimate.Print_MaintePrice__c = false;
            this.estimate.Print_SumPrice__c = false;
            this.estimate.NotUse_Oxygenated_Water__c = false;
            this.estimate.Contract_Esti_Start_Date__c = this.estimate.Contract_Start_Date__c;
            //this.estimate.Process_Status__c = '草案中';
        }
        return changedAfterPrint;
    }
    
    /**
     * 行追加(10行ずつ)、前提必ず最後
     */
    public PageReference addNewRows() {
        for (Integer i = 0; i < 10; i++) {
            checkedAssets.add(new AssetInfo(checkedAssets.size()));
        }
        return null;
    }
    
    /** 保存返回 **/
    public PageReference saveAndCancel () {
        //add by rentx 2020-11-13 LJPH-BV93RZ start
        if (estimate.Contract_Range__c == null) {
            this.estimate.Contract_Range__c.addError('必须输入合同月数!');
            return null;
        }
        //add by rentx 2020-11-13 LJPH-BV93RZ end
        
        //URF限次合同2期 LY 20220811 start
        if (!String.isNotBlank(estimate.URF_V_MaxRepairCount__c)) {
            this.estimate.URF_V_MaxRepairCount__c.addError('请选择URF-V最大大修次数!');
            return null;
        }
        if (!String.isNotBlank(estimate.URF_P_MaxRepairCount__c)) {
            this.estimate.URF_V_MaxRepairCount__c.addError('请选择URF-V最大大修次数!');
            return null;
        }
        //URF限次合同2期 LY 20220811 end
        if (syncEstimate(false, false)) {
            PageReference ret = null;
            if (this.targetMaintenanceContractId != null) {
                ret = new PageReference('/' + this.targetMaintenanceContractId);
            }
            return ret;
        }
        return null;
    }
    
    /**
     * キャンセルメソッド
     */
    public PageReference cancel() {
        PageReference ret = null;
        if (this.targetMaintenanceContractId != null) {
            ret = new PageReference('/' + this.targetMaintenanceContractId);
        }
        return ret;
    }
    //URF限次合同2期 LY 20220920 start
    //获取当前选中的经销商是否为先款标识
    public PageReference onChDealerUpdate(){
        //checkDealerId  此变量可能会存 经销商id或经销商中文名
        if(String.isNotBlank(checkDealerId)){
            try {
                List<Account> accListC = [select id,name,FirstParagraphEnd__c from Account where id = :checkDealerId OR name = :checkDealerId];
                if(accListC != null && accListC.size() == 1){
                    if(accListC[0].FirstParagraphEnd__c){
                        this.estimate.Is_RecognitionModel__c = true;
                    }else{
                        this.estimate.Is_RecognitionModel__c = false;
                    }
                }else{
                    this.estimate.Is_RecognitionModel__c = false;
                }
            } catch (Exception e) {
                //return 'McaeList Update Failed : '+e;
            }
        }else{
            this.estimate.Is_RecognitionModel__c = false;
        }
        System.debug('----------------23--'+this.estimate.Is_RecognitionModel__c);
        return null;
    }
    //URF限次合同2期 LY 20220920 end
    
    // 2021-02-07  gzw add  LJPH-BWY5QB start
    private void setEndUserType(String id) {
        //贸易合规 you 20230414 加查询AccDealerBlacklist__c
        this.contract = [SELECT Id, Name,AccDealerBlacklist__c, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
                         Estimate_Num__c, Management_Code__c, Hospital__c,
                         Hospital__r.MaintenanceContractUserType__c,
                         Contract_Start_Date__c, Contract_End_Date__c
                         FROM Maintenance_Contract__c WHERE Id = :id];
        if (this.estimate.Process_Status__c == '草案中' || String.IsBlank(this.estimate.Process_Status__c)) {
    
            this.estimate.EndUserType__c = this.contract.Hospital__r.MaintenanceContractUserType__c == false ? '新用户' : '既有用户';
        }
    }
    // 2021-02-07  gzw add  LJPH-BWY5QB end
    
    private void setContractInfo(String id) {
        //贸易合规 you 20230414 加查询AccDealerBlacklist__c
        this.contract = [SELECT Id, Name,AccDealerBlacklist__c, Status__c, Decided_Estimation__c, Service_Contract_Staff__c,
                         Estimate_Num__c, Management_Code__c, Hospital__c,
                         //2021-01-18  mzy add  LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
                         // Hospital__r.MaintenanceContractUserType__c,
                         //2021-01-18  mzy add  LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
                         Contract_Start_Date__c, Contract_End_Date__c
                         FROM Maintenance_Contract__c WHERE Id = :id];
        this.targetHospitalId = this.contract.Hospital__c;
        // 2021-01-18  mzy  add LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
        // if(this.estimate.Process_Status__c == '草案中' || String.IsBlank(this.estimate.Process_Status__c)){
    
        //    this.estimate.EndUserType__c = this.contract.Hospital__r.MaintenanceContractUserType__c == false ? '新用户' : '既有用户';
        // }
        // 2021-01-18  mzy  add LJPH-BWY5QB   客户上的 维修合同用户类型 为true /false,报价 用户类型为 既有用户 / 新用户
    }
    
    private Boolean checkValidate() {
        Boolean rtn = true;
        Date today = Date.today();
        if (getPageDisabled()) {
            today = estimate.Submit_quotation_day__c;
        }
        // 部品供給停止の製品はエラー
        for (AssetInfo input : this.checkedAssets) {
            //如果是手动产品
            // 20210121 gzw 服务合同也验证设备价格是否为空 start
            if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                // if (input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                // 20210121 gzw 服务合同也验证设备价格是否为空 end
                if (input.mcae.Estimate_List_Price__c == null || input.mcae.Estimate_List_Price__c == 0) {
                    //update by rentx 2020-11-12 LJPH-BV93RZ start
                    // input.mcae.Product_Manual__c.addError(System.Label.Error_Message47);
                    //add by rentx 2021-01-25 start
                    //如果保有设备不为空的话在保有设备上报错
    
                    if (input.rec != null) {
                        input.rec.Name.addError(input.rec.Name + ' (机身编码为:' + input.rec.SerialNumber + ') 无合同金额,不建议参保');
    
                    } else
                    //add by rentx 2021-01-25 end
                    if (String.isNotBlank(input.proName)) {
                        input.mcae.Product_Manual__c.addError(System.Label.Error_Message47 + '(' + input.proName + ')');
                    }
                    //update by rentx 2020-11-12 LJPH-BV93RZ end
                    rtn = false;
                }
            }
            if (!input.isManual) {
                //update by rentx 2020-11-13 start
                if (!Test.isRunningTest() && (input.mcae.Adjustment_Upper_price__c == null || input.mcae.Adjustment_Upper_price__c == 0) ) {
                    // input.mcae.Adjustment_Upper_price__c.addError(input.rec.Name + '('+ input.rec.SerialNumber + ') 签约价格为0,-- 建议先与服务商品部咨询后再提交报价。');
                    input.mcae.Adjustment_Upper_price__c.addError(input.proSerialName + '(' + input.proSerialNumber + ') 签约价格为0,-- 建议先与服务商品部咨询后再提交报价。');
                    rtn = false;
                }
                if (!Test.isRunningTest() && (input.mcae.Adjustment_Lower_price__c == null || input.mcae.Adjustment_Lower_price__c == 0) ) {
                    input.mcae.Adjustment_Lower_price__c.addError(input.proSerialName + '(' + input.proSerialNumber + ') 签约价格为0,-- 建议先与服务商品部咨询后再提交报价。');
                    // input.mcae.Adjustment_Lower_price__c.addError(input.rec.Name + '('+ input.rec.SerialNumber + ') 签约价格为0,-- 建议先与服务商品部咨询后再提交报价。');
                    rtn = false;
                }
                //update by rentx 2020-11-13 end
    
                //1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。)
                //2.一年以上的合同,在结束前6个月开始可以开放续签报价。
                //3.管理员跳过,
                if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
    
                    Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F__r.Contract_End_Date__c);
                    Decimal monthCon = (Decimal)noOfDays / 365 * 12;
                    // 可开始报价的月数限制
                    if (input.rec.CurrentContract_F__r.Contract_Range__c >= 12 && monthCon > 6) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 合同结束前6个月开始可以制作报价。');
                        rtn = false;
                    }
                    if (input.rec.CurrentContract_F__r.Contract_Range__c < 12 && monthCon > Math.floor(input.rec.CurrentContract_F__r.Contract_Range__c / 2)) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 经历月数过半方可制作报价');
                        rtn = false;
                    }
                }
                // 多年保判断
                if ( String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
                    //if (UserInfo.getProfileId() != System.Label.ProfileId_SystemAdmin && String.isNotBlank(input.rec.CurrentContract_F__c) && input.rec.CurrentContract_F__r.RecordType_DeveloperName__c == 'VM_Contract') {
    
                    //Integer noOfDays = today.daysBetween(input.rec.CurrentContract_F_asset__r.endDateGurantee_Text__c);
                    //Decimal monthCon = (Decimal)noOfDays/365*12;
                    // 可开始报价的月数限制
                    if (input.rec.CurrentContract_F__r.Gurantee_Estimate_startDate__c > Date.today()) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 合同结束前6个月开始可以制作报价。');
                        rtn = false;
                    }
                }
                //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '---' + input.rec.CurrentContract_F__r.Contract_End_Date__c));
                if (inDicideFlag && String.isNotBlank(input.rec.CurrentContract_F__c)) {
                    //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, '+++' + input.rec.CurrentContract_F__r.Contract_End_Date__c));
                    // 合同开始日大于上期合同结束日加一个月,且没有点检日期或者最近一次点检日期是3个月前  报错
                    if (estimate.Contract_Start_Date__c > input.rec.CurrentContract_F__r.Contract_End_Date__c.addMonths(1)
                        && (input.rec.Final_Examination_Date__c == null
                            || input.rec.Final_Examination_Date__c < estimate.Contract_Start_Date__c.addMonths(-3))) {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 没有最新的点检记录');
                        rtn = false;
                    }
                }
    
                if (isSaveOrApproval) {
                    if (input.rec.IF_Warranty__c == '否') {
                        input.rec.Name.addError(input.rec.Name + '(' + input.rec.SerialNumber + ') -- 不能选择不可参保设备');
                        rtn = false;
                    }
                }
                // 20200805 Gzw Bug修复
                // isSaveOrApproval = false;
            }
        }
        return rtn;
    }
    
    // 价格变更后克隆报价前重新计算价格
    @TestVisible
    private void priceChangeReset() {
        // 取得master中最新价格
        List<Id> assIds = new List<Id>();
        List<Id> pdIds = new List<Id>();
        for (AssetInfo input : this.checkedAssets) {
            if (!input.isManual) {
                assIds.add(input.rec.Id);
            }
            if (input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
                pdIds.add(input.mcae.Product_Manual__c);
            }
        }
        Map<Id, Asset> assMap = new Map<Id, Asset>();
        Map<Id, Product2> pdMap = new Map<Id, Product2>();
        if (assIds.size() > 0) {
            assMap = new Map<Id, Asset>([select id, Maintenance_Price_Month__c from Asset where Id In: assIds]);
        }
        if (pdIds.size() > 0) {
            pdMap = new Map<Id, Product2>([select id, Maintenance_Price_Month__c, EquipmentGuaranteeFlg__c from Product2 where Id In: pdIds]);
        }
        if (assMap.size() > 0 || pdMap.size() > 0) {
            for (AssetInfo info : this.checkedAssets) {
                if (!info.isManual) {
                    info.orgPrice = assMap.get(info.rec.Id).Maintenance_Price_Month__c;
                }
                if (info.isManual && !String.isBlank(info.mcae.Product_Manual__c)) {
                    info.orgPrice = pdMap.get(info.mcae.Product_Manual__c).Maintenance_Price_Month__c;
                }
            }
        }
        //contractStartDateChange();
    }
    
    public class AssetInfo {
    // 新合同备品确保提供 当前标记
    public Boolean etGFlg {get; set;}
    public Integer lineNo {get; private set;}
    public Boolean rec_checkBox_c {get; set;}
    public Asset rec { get; set; }
    public Maintenance_Contract_Asset_Estimate__c mcae { get; set; }
    public Boolean isManual { get; set; }
    public Decimal orgPrice {get; private set;}
    public Decimal orgPrice12 {get; private set;}
    
    //2021-11-30 fy add LJPH-C8W8FV 置顶 start
    public String ProductModelNoc;
    public String AssetModelNoc;
    public String MDMModelNoc;
    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    
    //add by rentx 2020-11-12 LJPH-BV93RZ start
    public String proName;
    public String proSerialNumber;
    public String proSerialName;
    //add by rentx 2020-11-12 LJPH-BV93RZ end
    // add by fxk 2021/9/9 控制点检对象是否可选 Star
    public Boolean CheckRows {get; private set;}
    // add by fxk 2021/9/9 控制点检对象是否可选 End
    // 限次价格 add by gzw start
    public Decimal uFRPrice {get; private set;}
    // 限次系列
    public String uFRSerial {get; private set;}
    // 最大大修次数
    public Decimal uFRRepairCount {get; private set;}
    
    // 限次价格 add by gzw end
 
    // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
    public Decimal uFRMaxPrice {get; set;}
    public Decimal uFRMinPrice {get; set;}
    // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
    //URF限次合同2期 LY 20220811 start
    public Decimal uFRMaxPrice3 {get; set;}
    public Decimal uFRMinPrice3 {get; set;}
    //URF限次合同2期 LY 20220811 end
    
    public Id getRecId() {
        Id rtn = null;
        if (rec != null) {
            rtn = rec.Id;
        }
        return rtn;
    }
    public void setRecId(Id value) {
        // なにもしない
    }
    
    // Manual専用
    public AssetInfo(Integer lineNo) {
        this.lineNo = lineNo;
        this.rec = null;
        this.mcae = new Maintenance_Contract_Asset_Estimate__c(
            isNew__c = true,
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
            Check_Object__c = true
                              // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk end
            );
        this.isManual = true;
        this.rec_checkBox_c = false;
        this.orgPrice = 0;
        this.orgPrice12 = 0;
        this.etGFlg = false;
        this.uFRPrice = 0;
        this.uFRRepairCount = 0;
        // add by fxk 2021/9/9 控制点检对象是否可选 Star
        this.CheckRows = true;
        // add by fxk 2021/9/9 控制点检对象是否可选 End
        // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
        this.uFRMaxPrice = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_Max__c;
        this.uFRMinPrice = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF__c;
        //URF限次合同2期 LY 20220811 start
        this.uFRMaxPrice3 = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c;
        this.uFRMinPrice3 = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_3__c;
        //URF限次合同2期 LY 20220811 end
        // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
    }
    // 選択された用(非Manual)
    public AssetInfo(Integer lineNo, Asset record, Boolean isNew, Decimal listPrice, Maintenance_Contract_Asset_Estimate__c mcae) {
        this.lineNo = lineNo;
        this.rec = record;
        this.mcae = new Maintenance_Contract_Asset_Estimate__c(
    //                id = mcae.Id,             // 本当にいらないの? セットしたら、新規権限がなくでも、更新できます。後藤さんに確認した、なくでもいいです。
            isNew__c = isNew,
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
            Check_Object__c = mcae.Check_Object__c,
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk end
            Estimate_List_Price__c = listPrice,
            //Maintenance_Price_YearTXT__c = mcae.Maintenance_Price_YearTXT__c,
            Check_Result__c = mcae.Check_Result__c,
            Repair_Price__c = mcae.Repair_Price__c,
            Comment__c = mcae.Comment__c,
            EquipmentGuaranteeFlgTxt__c = mcae.EquipmentGuaranteeFlgTxt__c,
            Estimate_Cost__c = mcae.Estimate_Cost__c,
            Adjustment_ratio_Upper__c = mcae.Adjustment_ratio_Upper__c,
            Adjustment_ratio_Lower__c = mcae.Adjustment_ratio_Lower__c,
            Adjustment_Upper_price__c = mcae.Adjustment_Upper_price__c,
            LastMContract_Price__c = mcae.LastMContract_Price__c,
            Adjustment_Lower_price__c = mcae.Adjustment_Lower_price__c,
            Asset_Consumption_rate__c = mcae.Asset_Consumption_rate__c
                                        // 追加限次信息
            , URF_Series__c = mcae.URF_Series__c,
            Series_RepairCount__c = mcae.Series_RepairCount__c,
            Series_MaxRepairCount__c = mcae.Series_MaxRepairCount__c,
            Asset_RepairCount__c = mcae.Asset_RepairCount__c,
            Asset_MaxRepairCount__c = mcae.Asset_MaxRepairCount__c
            // LJPH-C9GD34 gzw fix start
            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c
            // LJPH-C9GD34 gzw fix end
    
            );
        this.isManual = false;
        this.rec_checkBox_c = true;
        this.orgPrice = record.Maintenance_Price_Month__c;
        this.orgPrice12 = this.orgPrice * 12;
        this.etGFlg = record.EquipmentGuaranteeFlg__c;
        //add by rentx 2020-11-12 LJPH-BV93RZ start
        this.proName = '机身编码为:' + record.SerialNumber;
        this.proSerialNumber = record.SerialNumber;
        this.proSerialName = record.Name;
    
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        this.ProductModelNoc = mcae.Product_Manual__r.Asset_Model_No__c;
        this.AssetModelNoc = mcae.Asset__r.OwnershipMachine_No__c;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    
        //add by rentx 2020-11-12 LJPH-BV93RZ end
        //URF限次合同2期 LY 20220811 start
        //this.uFRPrice = record.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
        this.uFRPrice = record.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
        //URF限次合同2期 LY 20220811 end
        this.uFRSerial = record.Product2.ProductURF__r.URFLimitSerial__c;
        //this.uFRRepairCount = record.Product2.ProductURF__r.UFR_MaxRepairCount__c;
        //URF限次合同2期 LY 20220811 start
        this.uFRRepairCount = 0;
        // if (this.uFRSerial=='URF-V'){
        //     this.uFRRepairCount=2;
        // }else{
        //     this.uFRRepairCount=3;
        // }
        //URF限次合同2期 LY 20220811 start
        //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
        this.uFRMaxPrice = record.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c;
        this.uFRMinPrice = record.Product2.ProductURF__r.Maintenance_Price_Year_URF__c;
        //URF限次合同2期 LY 20220811 start
        this.uFRMaxPrice3 = record.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c;
        this.uFRMinPrice3 = record.Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c;
        //URF限次合同2期 LY 20220811 end
        // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
    }
    // 選択された用、未納品用(Manual)
    public AssetInfo(Integer lineNo, Maintenance_Contract_Asset_Estimate__c mcae) {
        this.lineNo = lineNo;
        this.rec = null;
        this.mcae = new Maintenance_Contract_Asset_Estimate__c(
    //                id = mcae.Id,             // 本当にいらないの? セットしたら、新規権限がなくでも、更新できます。後藤さんに確認した、なくでもいいです。
            isNew__c = mcae.IsNew__c,
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk Star
            Check_Object__c = mcae.Check_Object__c,
            // add点检改善:新增一个点检对象复选框字段,默认为true 2021.6.8 fxk end
            Product_Manual__c = mcae.Product_Manual__c,
            Estimate_List_Price__c = mcae.Estimate_List_Price__c,
            //Maintenance_Price_YearTXT__c = mcae.Maintenance_Price_YearTXT__c,
            Check_Result__c = mcae.Check_Result__c,
            Repair_Price__c = mcae.Repair_Price__c,
            Comment__c = mcae.Comment__c,
            EquipmentGuaranteeFlgTxt__c = mcae.EquipmentGuaranteeFlgTxt__c,
            Estimate_Cost__c = mcae.Estimate_Cost__c,
            Adjustment_ratio_Upper__c = mcae.Adjustment_ratio_Upper__c,
            Adjustment_ratio_Lower__c = mcae.Adjustment_ratio_Lower__c,
            Adjustment_Upper_price__c = mcae.Adjustment_Upper_price__c,
            LastMContract_Price__c = mcae.LastMContract_Price__c,
            Adjustment_Lower_price__c = mcae.Adjustment_Lower_price__c,
            Asset_Consumption_rate__c = mcae.Asset_Consumption_rate__c
                                        // 追加限次信息
            , URF_Series__c = mcae.URF_Series__c,
            Series_RepairCount__c = mcae.Series_RepairCount__c,
            Series_MaxRepairCount__c = mcae.Series_MaxRepairCount__c,
            Asset_RepairCount__c = mcae.Asset_RepairCount__c,
            Asset_MaxRepairCount__c = mcae.Asset_MaxRepairCount__c
            // LJPH-C9GD34 gzw fix start
            ,Estimate_List_Price_Page__c = mcae.Estimate_List_Price_Page__c
            // LJPH-C9GD34 gzw fix end
            );
        this.isManual = true;
        this.rec_checkBox_c = false;
        this.orgPrice = mcae.Product_Manual__r.Maintenance_Price_Month__c;
        this.orgPrice12 = this.orgPrice * 12;
        this.proName = mcae.Product_Manual__r.Name;
        this.etGFlg = mcae.Product_Manual__r.EquipmentGuaranteeFlg__c;
        //this.uFRPrice = mcae.Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month__c;
        this.uFRSerial = mcae.Product_Manual__r.ProductURF__r.URFLimitSerial__c;
        //this.uFRRepairCount = mcae.Product_Manual__r.ProductURF__r.UFR_MaxRepairCount__c;
        //URF限次合同2期 LY 20220811 start
        this.uFRRepairCount =0;
        this.uFRPrice = mcae.Product_Manual__r.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
        //URF限次合同2期 LY 20220811 end
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        this.ProductModelNoc = mcae.Product_Manual__r.Asset_Model_No__c;
        this.AssetModelNoc = mcae.Asset__r.OwnershipMachine_No__c;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
        this.uFRMaxPrice = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_Max__c;
        this.uFRMinPrice = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF__c;
        // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
        //URF限次合同2期 LY 20220811 start
        this.uFRMaxPrice3 = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c;
        this.uFRMinPrice3 = mcae.Product_Manual__r.ProductURF__r.Maintenance_Price_Year_URF_3__c;
        //URF限次合同2期 LY 20220811 end
    }
    // 選択されなかった用
    public AssetInfo(Integer lineNo, Asset record) {
        this.lineNo = lineNo;
        this.rec = record;
        this.isManual = false;
        this.rec_checkBox_c = false;
        this.orgPrice = record.Maintenance_Price_Month__c;
        this.orgPrice12 = this.orgPrice * 12;
        this.etGFlg = record.EquipmentGuaranteeFlg__c;
        this.proSerialName = record.Name;
        this.proSerialNumber = record.SerialNumber;
        //this.uFRPrice = record.Product2.ProductURF__r.UFR_Maintenance_Price_Month__c;
        this.uFRSerial = record.Product2.ProductURF__r.URFLimitSerial__c;
        //this.uFRRepairCount = record.Product2.ProductURF__r.UFR_MaxRepairCount__c;
        //URF限次合同2期 LY 20220811 start
        this.uFRRepairCount =0;
        this.uFRPrice = record.Product2.ProductURF__r.UFR_Maintenance_Price_Month_3__c;
        //URF限次合同2期 LY 20220811 start
        //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
        this.uFRMaxPrice = record.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max__c;
        this.uFRMinPrice = record.Product2.ProductURF__r.Maintenance_Price_Year_URF__c;
        // XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
        //URF限次合同2期 LY 20220811 start
        this.uFRMaxPrice3 = record.Product2.ProductURF__r.Maintenance_Price_Year_URF_Max_3__c;
        this.uFRMinPrice3 = record.Product2.ProductURF__r.Maintenance_Price_Year_URF_3__c;
        //URF限次合同2期 LY 20220811 end
    }
    }
    
    WebService static String pageDecide(String strId) {
        String rs = '';
        SelectAssetEstimateURFController saec = new SelectAssetEstimateURFController();
        saec.targetEstimateId = strId;
        saec.isPageAction = true;
        saec.init();
        if (saec.getDecideBtnDisabled()) {
            rs = '已经是Decide过的合同 或 不是批准的报价,不能Decide';
            return rs;
        }
        if (saec.syncEstimate(false, true)) {
            rs = '0';
        } else {
            rs = 'Decide失败';
        }
        return rs;
    }
    
    WebService static String pageUndecide(String strId) {
        String rs = '';
        SelectAssetEstimateURFController saec = new SelectAssetEstimateURFController();
        saec.targetEstimateId = strId;
        saec.isPageAction = true;
        saec.init();
        if (saec.getUnDecideBtnDisabled()) {
            rs = '不是Decide过的报价,不能Undecide';
            return rs;
        }
        if (saec.undecide() != null) {
            rs = '0';
        } else {
            rs = 'Undecide失败';
        }
        return rs;
    }
    
    // 2021-09-10 tcm 排序逻辑调整 start 传入 startDate ,添加 lastMContractMap1
    public static List<lastMContract> getlastMContract(List<AssetInfo> checkedAssets, Date startDate) {
        Map<String, lastMContract> lastMContractMap = new Map<String, lastMContract>();
        Map<String, lastMContract> lastMContractMap1 = new Map<String, lastMContract>();
        for (AssetInfo ai : checkedAssets) {
                lastMContract lM = new lastMContract(ai.rec.CurrentContract_F__c, ai.rec.CurrentContract_F__r.Management_Code__c, ai.rec.CurrentContract_F__r.Contract_End_Date__c, 1);
            // 计算空白期
            if (startDate != null && lM.endDate != null) {
                if (startDate.daysbetween(lM.endDate) > -366 && startDate.daysbetween(lM.endDate) < 366) {
                    lm.ayearcontract = true;
                } else {
                    lm.ayearcontract = false;
                }
            } else {
                lm.ayearcontract = false;
            }
            // 2021-09-10 tcm 排序逻辑调整 end
    
            // if (String.isNotBlank(ai.rec.CurrentContract_F__c) ) {
            //判断 如果上一期维修合同为 多年保修合同 的话 则不放入map进行更新 LJPH-BUU3E3 update by rentx 2020-11-03 start
            if (String.isNotBlank(ai.rec.CurrentContract_F__c) && ai.rec.CurrentContract_F__r.RecordType_DeveloperName__c != 'VM_Contract') {
    
                // 2021-09-10 tcm 排序逻辑调整 start
                if (lm.ayearcontract) {
                    // 2021-09-10 tcm 排序逻辑调整 end
    
                    //判断 如果上一期维修合同为 多年保修合同 的话 则不放入map进行更新 LJPH-BUU3E3 update by rentx 2020-11-03 end
                    // 空白期
                    if (lastMContractMap.containsKey(ai.rec.CurrentContract_F__c)) {
                        lastMContractMap.get(ai.rec.CurrentContract_F__c).count++;
                    } else {
                        lastMContractMap.put(ai.rec.CurrentContract_F__c, lM);
                    }
                    // 非空白期
                } else {
                    if (lastMContractMap1.containsKey(ai.rec.CurrentContract_F__c)) {
                        lastMContractMap1.get(ai.rec.CurrentContract_F__c).count++;
                    } else {
                        lastMContractMap1.put(ai.rec.CurrentContract_F__c, lM);
                    }
                }
            }
        }
        List<lastMContract> listResulttemp = new List<lastMContract>();
        List<lastMContract> listResult = new List<lastMContract>();
        // 2021-09-10 tcm 排序逻辑调整 start
        List<lastMContract> listResulttemp1 = new List<lastMContract>();
        List<lastMContract> listResult1 = new List<lastMContract>();
        // 2021-09-10 tcm 排序逻辑调整 end
        // 空白期
        for ( lastMContract ll : lastMContractMap.values()) {
            listResulttemp.add(ll);
        }
        // 2021-09-10 tcm 排序逻辑调整 start
        // 非空白期
        for ( lastMContract ll : lastMContractMap1.values()) {
            listResulttemp1.add(ll);
        }
        // 2021-09-10 tcm 排序逻辑调整 end
        //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'listResult +++++!' + listResult));
    
        // 空白期
        listResulttemp.sort();
        // 2021-09-10 tcm 排序逻辑调整 start  (修改了循环次数 原5)
        for (Integer i = 0; i < listResulttemp.size(); i++) {
            // 2021-09-10 tcm 排序逻辑调整 end
            if (listResulttemp.size() >= i + 1) {
                listResult.add(listResulttemp[i]);
            }
        }
    
        // 2021-09-10 tcm 排序逻辑调整 start
        // 非空白期
        listResulttemp1.sort();
        for (Integer i = 0; i < 5 - listResulttemp.size(); i++) {
            if (listResulttemp1.size() >= i + 1) {
                listResult1.add(listResulttemp1[i]);
            } else {
                listResult1.add(new lastMContract(null, null, null, null));
            }
        }
        // 合并
        listResult.addAll(listResult1);
        // 2021-09-10 tcm 排序逻辑调整 end
        //List<lastMContract> listResult = new List<lastMContract>();
        return listResult;
    }
    //URF限次合同2期 LY 20220908 start
    //对限次合同进行排序
    public static List<lastMContract> getURFMContract(List<AssetInfo> checkedAssets, Date startDate) {
        Map<String, lastMContract> urfMContractMap = new Map<String, lastMContract>();
        Map<String, lastMContract> lastMContractMap1 = new Map<String, lastMContract>();
        for (AssetInfo ai : checkedAssets) {
            lastMContract urfMC = new lastMContract(ai.rec.URF_Maintenance_Contract__c, ai.rec.URF_Maintenance_Contract__r.Management_Code__c, ai.rec.URF_Maintenance_Contract__r.Contract_End_Date__c, 1);
            if (String.isNotBlank(ai.rec.URF_Maintenance_Contract__c)) {
                if (urfMContractMap.containsKey(ai.rec.URF_Maintenance_Contract__c)) {
                    urfMContractMap.get(ai.rec.URF_Maintenance_Contract__c).count++;
                } else {
                    urfMContractMap.put(ai.rec.URF_Maintenance_Contract__c, urfMC);
                }
            }
        }
        List<lastMContract> listResulttemp = new List<lastMContract>();
        List<lastMContract> listResult = new List<lastMContract>();
        
        for ( lastMContract ll : urfMContractMap.values()) {
            listResulttemp.add(ll);
        }
        listResulttemp.sort();
        if (listResulttemp.size() >= 5){
            for (Integer i = 0; i < listResulttemp.size(); i++) {
            
                if (listResulttemp.size() >= i + 1) {
                    listResult.add(listResulttemp[i]);
                }
            }
        }else {
            for (Integer i = 0; i < listResulttemp.size(); i++) {
                if (listResulttemp.size() >= i + 1) {
                    listResult.add(listResulttemp[i]);
                }
            }
            for (Integer i = listResulttemp.size(); i < 5; i++) {
                listResult.add(new lastMContract(null, null, null, null));
            }
        }
        
        return listResult;
    }
    //URF限次合同2期 LY 20220908 end
    
    
    // public static List<Data> getChartData() {
    //     List<Data> data = new List<Data>();
    //     List<Achievement_linkage__c> achlist = [select id,Consumption_rate_Lower__c,Consumption_rate_Upper__c,
    //     PriceCount_Lower__c,PriceCount_Upper__c from Achievement_linkage__c];
    //     for (Achievement_linkage__c al: achlist ) {
    //         data.add(new Data(al.Consumption_rate_Lower__c, al.Consumption_rate_Upper__c, al.PriceCount_Lower__c, al.PriceCount_Upper__c));
    //     }
    //     return data;
    // }
    // 计算限次系列次数
    public Map<String, Decimal> getLimitSerialData(Integer Contract_year) {
        Map<String, Decimal> limitSerial = new Map<String, Decimal>();
    
        for (AssetInfo input : this.checkedAssets) {
            //URF限次合同2期 LY 20220811 start
            if (String.isNotBlank(input.uFRSerial) && input.uFRSerial=='URF-V'){
                input.uFRRepairCount = Integer.valueOf(estimate.URF_V_MaxRepairCount__c);
            }else if (String.isNotBlank(input.uFRSerial) && input.uFRSerial=='URF-P'){
                input.uFRRepairCount = Integer.valueOf(estimate.URF_P_MaxRepairCount__c);
            }else{
                input.uFRRepairCount = 0;
            }
            //URF限次合同2期 LY 20220811 end
 
            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 start
            if (String.isNotBlank(input.uFRSerial) && limitSerial.containsKey(input.uFRSerial)) {
                limitSerial.put(input.uFRSerial, limitSerial.get(input.uFRSerial) + input.uFRRepairCount * Contract_year);
            } else {
                limitSerial.put(input.uFRSerial, input.uFRRepairCount * Contract_year);
            }
            //XLIU-CE7AVC【委托】URF限次修理合同的最高价格修改 thh 20220509 end
            // if (!input.isManual || input.isManual && !String.isBlank(input.mcae.Product_Manual__c)) {
            //     if (String.isBlank(input.mcae.Check_Result__c)) {
            //         input.mcae.Check_Result__c.addError('点检结果必填');
            //     }
            // }
        }
        return limitSerial;
    }
    
    // // 价格体系 class
    // public class Data {
    //     public Decimal rate_Upper { get; set; }
    //     public Decimal rate_Lower { get; set; }
    //     public Decimal price_Upper { get; set; }
    //     public Decimal price_Lower { get; set; }
    //     public Data(Decimal rate_Lower, Decimal  rate_Upper, Decimal price_Lower, Decimal  price_Upper) {
    //         this.rate_Upper = rate_Upper;
    //         this.rate_Lower = rate_Lower;
    //         this.price_Upper = price_Upper;
    //         this.price_Lower = price_Lower;
    //     }
    // }
    
    // 续签合同信息 class
    public class lastMContract implements Comparable {
    public Date endDate { get; set; }
    public Integer count { get; set; }
    public String contractId { get; set; }
    public String contractNo { get; set; }
    // 2021-09-10 tcm 排序逻辑调整 start
    public Boolean ayearcontract { get; set; }
    // 2021-09-10 tcm 排序逻辑调整 end
    public lastMContract(String contractId, String contractNo, Date endDate, Integer count) {
        this.endDate = endDate;
        this.count = count;
        this.contractId = contractId;
        this.contractNo = contractNo;
    }
    
    // 排序
    public Integer compareTo(Object compareTo) {
        lastMContract compareToesd = (lastMContract)compareTo;
        Integer returnValue = 0;
    
        // 2021-09-10 tcm 排序逻辑调整 start
        // 判断在数量
        if (count  > compareToesd.count) {
            returnValue = -1;
        } else if (count  < compareToesd.count) {
            returnValue = 1;
        } else {
            if (endDate  > compareToesd.endDate ) {
                returnValue = 1;
            } else {
                returnValue = -1;
            }
        }
        return returnValue;
        // 2021-09-10 tcm 排序逻辑调整 end
    }
    }
    }