OWL ITS + 탐지시스템(인터넷 진흥원)
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
package kr.wisestone.owl.service.impl;
 
import com.google.common.collect.Lists;
import kr.wisestone.owl.common.ExcelConditionCheck;
import kr.wisestone.owl.common.IssueCustomFieldValueFormComparator;
import kr.wisestone.owl.config.CommonConfiguration;
import kr.wisestone.owl.constant.*;
import kr.wisestone.owl.data.CheckIssueData;
import kr.wisestone.owl.domain.*;
import kr.wisestone.owl.domain.enumType.CustomFieldType;
import kr.wisestone.owl.domain.enumType.EmailType;
import kr.wisestone.owl.domain.enumType.IssueHistoryType;
import kr.wisestone.owl.domain.enumType.IssueStatusType;
import kr.wisestone.owl.exception.ApiAuthException;
import kr.wisestone.owl.exception.ApiParameterException;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.mapper.DepartmentMapper;
import kr.wisestone.owl.mapper.IssueMapper;
import kr.wisestone.owl.mapper.IssueRelationMapper;
import kr.wisestone.owl.mapper.ProjectMapper;
import kr.wisestone.owl.repository.*;
import kr.wisestone.owl.service.*;
import kr.wisestone.owl.util.*;
import kr.wisestone.owl.util.DateUtil;
import kr.wisestone.owl.vo.*;
import kr.wisestone.owl.web.condition.*;
import kr.wisestone.owl.web.form.*;
import kr.wisestone.owl.web.view.ExcelView;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.poi.ss.usermodel.*;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;
 
import static kr.wisestone.owl.domain.enumType.CustomFieldType.*;
 
@Service
public class IssueServiceImpl extends AbstractServiceImpl<Issue, Long, JpaRepository<Issue, Long>> implements IssueService {
 
    private static final Logger log = LoggerFactory.getLogger(IssueServiceImpl.class);
 
    @Autowired
    private IssueRepository issueRepository;
 
    @Autowired
    private ProjectService projectService;
 
    @Autowired
    private IssueTableConfigService issueTableConfigService;
 
    @Autowired
    private IssueStatusService issueStatusService;
 
    @Autowired
    private IssueTypeService issueTypeService;
 
    @Autowired
    private PriorityService priorityService;
 
    @Autowired
    private SeverityService severityService;
 
    @Autowired
    private CustomFieldApiOverlapService customFieldApiOverlapService;
 
    @Autowired
    private IssueApiDefaultService issueApiDefaultService;
 
    @Autowired
    private ApiTokenService apiTokenService;
 
    @Autowired
    private CompanyFieldService companyFieldService;
 
    @Autowired
    private CompanyFieldCategoryService companyFieldCategoryService;
 
    @Autowired
    private IspFieldService ispFieldService;
 
    @Autowired
    private HostingFieldService hostingFieldService;
 
    @Autowired
    private CommonConfiguration configuration;
 
    @Autowired
    private IssueNumberGeneratorService issueNumberGeneratorService;
 
    @Autowired
    private AttachedFileService attachedFileService;
 
    @Autowired
    private IssueCustomFieldValueService issueCustomFieldValueService;
 
    @Autowired
    private IssueCompanyService issueCompanyService;
 
    @Autowired
    private IssueIspService issueIspService;
 
    @Autowired
    private IssueHostingService issueHostingService;
 
    @Autowired
    private IssueUserService issueUserService;
 
    @Autowired
    private IssueDepartmentService issueDepartmentService;
 
    @Autowired
    private CustomFieldService customFieldService;
 
    @Autowired
    private IssueTypeCustomFieldService issueTypeCustomFieldService;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private DepartmentService departmentService;
 
    @Autowired
    private IssueCommentService issueCommentService;
 
    @Autowired
    private IssueHistoryService issueHistoryService;
 
    @Autowired
    private ProjectRoleUserService projectRoleUserService;
 
    @Autowired
    private ProjectRoleDepartmentService projectRoleDepartmentService;
 
    @Autowired
    private IssueRiskService issueRiskService;
 
    @Autowired
    private WorkspaceService workspaceService;
 
    @Autowired
    private SystemEmailService systemEmailService;
 
    @Autowired
    private IssueVersionService issueVersionService;
 
    @Autowired
    private IssueReservationService issueReservationService;
 
    @Autowired
    private UserWorkspaceService userWorkspaceService;
 
    @Autowired
    private UserLevelService userLevelService;
 
    @Autowired
    private WorkflowDepartmentService workflowDepartmentService;
 
    @Autowired
    private IssueRelationService issueRelationService;
 
    @Autowired
    private IssueRelationRepository issueRelationRepository;
 
    @Autowired
    private ExcelView excelView;
 
    @Autowired
    private IssueMapper issueMapper;
 
    @Autowired
    private IssueCompanyRepository issueCompanyRepository;
 
    @Autowired
    private IssueIspRepository issueIspRepository;
 
    @Autowired
    private IssueHostingRepository issueHostingRepository;
 
    @Autowired
    private ExcelConditionCheck excelConditionCheck;
 
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;
 
    @Autowired
    private UserDepartmentService userDepartmentService;
 
    @Autowired
    private UserDepartmentRepository userDepartmentRepository;
 
    @Autowired
    private DepartmentMapper departmentMapper;
 
    @Autowired
    private WorkflowDepartmentRepository workflowDepartmentRepository;
 
    @Autowired
    private IssueRelationMapper issueRelationMapper;
 
    @Autowired
    private WorkflowTransitionService workflowTransitionService;
 
    @Override
    protected JpaRepository<Issue, Long> getRepository() {
        return this.issueRepository;
    }
 
    private static final int EXCEL_DOWNLOAD_MAX_ROWS = 10000;   //  excel download 제한
    private static final int EXCEL_IMPORT_MAX_ROWS = 10000; //  excel import 제한
 
    @Override
    @Transactional
    public void addIssueVersion(Long id) {
        Issue issue = this.getIssue(id);
        //  이슈 버전 생성
        this.issueVersionService.addIssueVersion(issue);
    }
 
    @Override
    @Transactional
    public void addIssueVersion(Long id, Long userId) {
        Issue issue = this.getIssue(id);
        User user = this.userService.getUser(userId);
        //  이슈 버전 생성
        this.issueVersionService.addIssueVersion(issue, user);
    }
 
 
    private IssueForm convertToIssueForm(IssueApiForm issueApiForm, User user) {
        if (issueApiForm.getIssueTypeId() == null) {
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ISSUE_TYPE_ERROR));
        }
 
        IssueForm issueForm = ConvertUtil.copyProperties(issueApiForm, IssueForm.class);
//        issueForm.setFiles(issueApiForm.getFiles());
        IssueType issueType = this.issueTypeService.getIssueType(issueApiForm.getIssueTypeId());
        if (issueType == null){
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_ISSUE_TYPE_ERROR));
        }
 
        Workflow workflow = issueType.getWorkflow();
 
        if (issueApiForm.getApiType().equals(IssueApiForm.ApiType.add)) {
            // 이슈 상태가 지정되어 있지 않을 경우 워크플로우 대기 상태 값으로 지정
            List<Long> departmentIds = this.workflowDepartmentService.findFirstDepartmentIds(workflow);
            if (departmentIds != null && departmentIds.size() > 0) {
                for (Long departmentId : departmentIds) {
                    issueForm.addDepartmentId(departmentId);
                }
            }
        } else if (issueApiForm.getIssueStatusId() == null){
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_ISSUE_STATUS_NOT_EXIST));
        } else if (!this.workflowTransitionService.contains(issueApiForm.getIssueStatusId(), workflow.getId())) {
            //이슈 상태 유효성 확인
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_ISSUE_STATUS_NOT_EXIST_IN_WORKFLOW));
        }
 
        // 프로젝트 입력
        Project project = issueType.getProject();
        if (project == null){
            throw new ApiParameterException(this.messageAccessor.getMessage(MsgConstants.API_PARAMETER_PROJECT_ERROR));
        }
        issueForm.setProjectId(project.getId());
 
        if (user != null) {
            // 기본값 입력하기
            IssueApiDefaultForm issueApiDefaultForm = new IssueApiDefaultForm();
            issueApiDefaultForm.setUserId(user.getId());
            issueApiDefaultForm.setIssueTypeId(issueForm.getIssueTypeId());
            IssueApiDefault issueApiDefault = this.issueApiDefaultService.find(issueApiDefaultForm);
            if (issueApiDefault != null) {
                ConvertUtil.copyProperties(issueApiDefault, issueForm);
                issueForm.setId(null);
                issueForm.setPriorityId(issueApiDefault.getPriority().getId());
                issueForm.setSeverityId(issueApiDefault.getSeverity().getId());
            }
 
            // 중복 값 상위 이슈의 하위 이슈로 처리하기
            CustomFieldApiOverlapForm customFieldApiOverlapForm = new CustomFieldApiOverlapForm();
            customFieldApiOverlapForm.setUserId(user.getId());
            customFieldApiOverlapForm.setIssueTypeId(issueForm.getIssueTypeId());
 
            // 상위일감에 사용할 중복값 설정
            List<CustomFieldApiOverlap> customFieldApiOverlaps = this.customFieldApiOverlapService.find(user.getId(), issueApiForm.getIssueTypeId());
//            if (customFieldApiOverlaps == null || customFieldApiOverlaps.size() == 0){
//                throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_OVERLAP_SETTING_NOT_EXIST));
//            }
            if (customFieldApiOverlaps != null && customFieldApiOverlaps.size() > 0) {
                for (int i = 0; i < customFieldApiOverlaps.size(); i++) {
                    CustomFieldApiOverlap customFieldApiOverlap = customFieldApiOverlaps.get(i);
                    issueApiForm.addUseIssueCustomFieldId(customFieldApiOverlap.getCustomField().getId());
                }
 
                // 중복된 상위 이슈검색
                List<Issue> issues = this.findIssue(issueApiForm, issueForm, customFieldApiOverlaps, user.getId());
                int size = issues.size();
                if (size > 0) {
                    Issue targetIssue = issues.get(0);
                    if (targetIssue.getParentIssue() != null) {
                        issueForm.setParentIssueId(targetIssue.getParentIssue().getId());
                    } else {
                        issueForm.setParentIssueId(targetIssue.getId());
                    }
                }
            }
 
            issueForm.setIsApi(Issue.IS_API_YES);
 
            // 사용자 정의 필드 설정
            issueForm.setIssueCustomFields(issueApiForm.getCustomFieldValues());
            //  같은 도메인 업체 찾기
 
            // api 입력값 적용
            ConvertUtil.copyProperties(issueApiForm, issueForm);
 
            return issueForm;
 
        } else {
            throw new ApiAuthException(this.messageAccessor.getMessage(MsgConstants.API_USER_ERROR));
        }
    }
 
    /**
     * 도메인이 동일한 업체 찾기
     * @param issueForm IssueForm
     * @return IssueForm
     */
    private IssueForm findCompanyField(IssueForm issueForm) {
        if(issueForm.getIssueCustomFields() != null && issueForm.getIssueCustomFields().size() > 0) {
            CompanyFieldCondition condition = new CompanyFieldCondition();
            List<Map<String, Object>> companyFields = Lists.newArrayList();
            List<Map<String, Object>> issueCompanyFields = Lists.newArrayList();
            List<Map<String, Object>> issueIspFields = Lists.newArrayList();
            List<Map<String, Object>> issueHostingFields = Lists.newArrayList();
 
            for (Map<String, Object> issueCustomField : issueForm.getIssueCustomFields()) {
                Long customFieldId = MapUtil.getLong(issueCustomField, "customFieldId");
                CustomField customField = this.customFieldService.getCustomField(customFieldId);
                if(customField != null && customField.getCustomFieldType().equals(SITE) && customField.getName().equals("도메인")) {
                    String useValue = issueCustomField.get("useValue").toString();
                    String[] urlArr = null;
                    List<String> urls = Lists.newArrayList();
                    if (useValue.contains(",")) {
                        urlArr = useValue.split(",");
                        urls.addAll(Arrays.asList(urlArr));
                    } else {
                        urls.add(useValue);
                    }
                    condition.setUrl(urls);
                    companyFields = this.companyFieldService.find(condition);
 
                    if(companyFields != null && companyFields.size() > 0) {
                        for (Map<String, Object> companyField : companyFields) {
                            CompanyFieldVo companyFieldVo = ConvertUtil.convertMapToClass(companyField, CompanyFieldVo.class);
                            companyField.put("companyId", companyField.get("id"));
                            issueCompanyFields.add(companyField);
                            if(companyFieldVo.getIspId() != null && companyFieldVo.getIspId() != -1) {
                                Map<String, Object> ispField = this.ispFieldService.find(companyFieldVo.getIspId());
                                if (ispField != null) {
                                    ispField.put("ispId", ispField.get("id"));
                                    issueIspFields.add(ispField);
                                }
                            }
                            if(companyFieldVo.getHostingId() != null && companyFieldVo.getHostingId() != -1) {
                                Map<String, Object> hostingField = this.hostingFieldService.find(companyFieldVo.getHostingId());
                                if (hostingField != null) {
                                    hostingField.put("hostingId", hostingField.get("id"));
                                    issueHostingFields.add(hostingField);
                                }
                            }
                        }
                    }
                }
                issueForm.setIssueCompanyFields(issueCompanyFields);
                issueForm.setIssueIspFields(issueIspFields);
                issueForm.setIssueHostingFields(issueHostingFields);
            }
        }
 
        return issueForm;
    }
 
    /**
     * 조건에 맞는 파트너 정보 찾기
     * @param condition CompanyFieldCondition
     * @param issueCompanyFields List<Map<String, Object>>
     * @param issueIspFields List<Map<String, Object>>
     * @param issueHostingFields List<Map<String, Object>>
     */
    private void findPartner(CompanyFieldCondition condition, List<Map<String, Object>> issueCompanyFields
            , List<Map<String, Object>> issueIspFields, List<Map<String, Object>> issueHostingFields) {
 
        List<Map<String, Object>> companyFields = this.companyFieldService.find(condition);
 
        if(companyFields != null && companyFields.size() > 0) {
            for (Map<String, Object> companyField : companyFields) {
                CompanyFieldVo companyFieldVo = ConvertUtil.convertMapToClass(companyField, CompanyFieldVo.class);
                companyField.put("companyId", companyField.get("id"));
                issueCompanyFields.add(companyField);
                if(companyFieldVo.getIspId() != null && companyFieldVo.getIspId() != -1) {
                    Map<String, Object> ispField = this.ispFieldService.find(companyFieldVo.getIspId());
                    if (ispField != null) {
                        ispField.put("ispId", ispField.get("id"));
                        issueIspFields.add(ispField);
                    }
                }
                if(companyFieldVo.getHostingId() != null && companyFieldVo.getHostingId() != -1) {
                    Map<String, Object> hostingField = this.hostingFieldService.find(companyFieldVo.getHostingId());
                    if (hostingField != null) {
                        hostingField.put("hostingId", hostingField.get("id"));
                        issueHostingFields.add(hostingField);
                    }
                }
            }
        }
    }
 
    private User convertToUser(String token) {
        // 토큰으로 유저 정보 가져오기
        UserVo userVo = this.apiTokenService.certification(token);
 
        // 해당 유저 정보가 현재 db에 있는지 확인
        return this.userService.getUser(userVo.getId());
    }
 
 
    //  API 를 통해 이슈 추가.
    @Override
    @Transactional
    public List<Issue> addApiIssue(IssueApiForm issueApiForm) throws CloneNotSupportedException {
        User user = convertToUser(issueApiForm.getToken());
        IssueForm issueForm = this.convertToIssueForm(issueApiForm, user);
 
        List<Issue> issues = Lists.newArrayList();
        if (issueForm.getParentIssueId() != null    // 기존 추가된 상위 일감이 없거나 설정된 중복 이슈 id가 없을때
                || issueApiForm.getUseIssueCustomFieldIds().size() == 0) {
            issues.add(addIssue(user, issueForm, issueApiForm.getMultipartFiles()));
        } else {
            // 가상 상위 이슈 추가
            IssueForm parentIssueForm = issueForm.clone();
            // 가상 상위 이슈 추가
            parentIssueForm.setUseIssueCustomFields(issueApiForm.getUseIssueCustomFieldIds());
            //  같은 도메인 업체 찾기
            if (parentIssueForm.getIssueCompanyFields() == null) {
                IssueForm partners = this.findCompanyField(parentIssueForm);
                parentIssueForm.setIssueCompanyFields(partners.getIssueCompanyFields());
                parentIssueForm.setIssueIspFields(partners.getIssueIspFields());
                parentIssueForm.setIssueHostingFields(partners.getIssueHostingFields());
            }
 
            Issue issue = addIssue(user, parentIssueForm, null);
            issues.add(issue);
            // 하위 이슈 추가
            issueForm.setParentIssueId(issue.getId());
            issues.add(addIssue(user, issueForm, issueApiForm.getMultipartFiles()));
        }
 
        return issues;
    }
 
    // 상위 이슈 가져오기
    private IssueVo getParentIssueVo(Long parentIssueId) {
        if (parentIssueId != null) {
            Issue parentIssue = this.getIssue(parentIssueId);
            return ConvertUtil.copyProperties(parentIssue, IssueVo.class);
        }
        return null;
    }
 
    // 중복된 상위 이슈 검색
    private List<Issue> findIssue(IssueApiForm issueApiform, IssueForm issueForm, List<CustomFieldApiOverlap> customFieldApiOverlaps, Long userId) {
        List<IssueCustomFieldValueForm> issueCustomFieldValueForms = issueApiform.getIssueCustomFieldValues();
        List<Issue> resultIssueVos = Lists.newArrayList();
        String comma = ",";
 
        if (issueCustomFieldValueForms.size() > 0) {
            String concatUseValue = "";
            String customFieldType = "";
            int useIdx = 0;
            int cntIp = 0;
            int cntSite = 0;
 
            IssueCustomFieldValueFormComparator comp = new IssueCustomFieldValueFormComparator();
            Collections.sort(issueCustomFieldValueForms, comp);
 
            List<String> userValues = Lists.newArrayList();
            CompanyFieldCondition condition = new CompanyFieldCondition();
            List<Map<String, Object>> issueCompanyFields = Lists.newArrayList();
            List<Map<String, Object>> issueIspFields = Lists.newArrayList();
            List<Map<String, Object>> issueHostingFields = Lists.newArrayList();
 
            for (IssueCustomFieldValueForm issueCustomFieldValueForm : issueCustomFieldValueForms) {
                userValues.add(issueCustomFieldValueForm.getUseValue());
 
                for(CustomFieldApiOverlap customFieldApiOverlap : customFieldApiOverlaps) {
                    if (customFieldApiOverlap.getCustomField().getId().equals(issueCustomFieldValueForm.getCustomFieldId())) {
 
                        String useValue = issueCustomFieldValueForm.getUseValue();
                        if (useValue.contains(" ")) {
                            useValue = useValue.replace(" ","");
                        }
 
                        if (customFieldApiOverlap.getCustomField().getCustomFieldType().equals(IP_ADDRESS)) {
                            long ip = ConvertUtil.ipToLong(useValue);
                            customFieldType = IP_ADDRESS.toString();
                            if (cntIp == 0){
                                condition.setIp(ip);
                            }
                            cntIp ++;
                        }
 
                        if(customFieldApiOverlap.getCustomField().getCustomFieldType().equals(SITE)) {
                            String[] urlArr = null;
                            List<String> urls = Lists.newArrayList();
                            if (useValue.contains(",")) {
                                urlArr = useValue.split(",");
                                urls.addAll(Arrays.asList(urlArr));
                            } else {
                                urls.add(useValue);
                            }
                            if (cntSite == 0) {
                                condition.setUrl(urls);
                            }
                            cntSite ++;
                        }
 
                        if (useIdx > 0) {
                            concatUseValue = concatUseValue.concat(comma);
                        }
                        concatUseValue = concatUseValue.concat(issueCustomFieldValueForm.getUseValue());
                        useIdx++;
                    }
                }
            }
 
            // 추가 할 url or ip에 포함되어있는 파트너 찾기
            this.findPartner(condition, issueCompanyFields, issueIspFields, issueHostingFields);
 
            issueForm.setIssueCompanyFields(issueCompanyFields);
            issueForm.setIssueIspFields(issueIspFields);
            issueForm.setIssueHostingFields(issueHostingFields);
 
            IssueCustomFieldValueCondition issueCustomFieldValueCondition = new IssueCustomFieldValueCondition();
            issueCustomFieldValueCondition.setUseValue(concatUseValue);
            issueCustomFieldValueCondition.setUseValues(userValues);
            issueCustomFieldValueCondition.setIssueTypeId(issueApiform.getIssueTypeId());
            issueCustomFieldValueCondition.setCustomFieldType(customFieldType);
//            issueCustomFieldValueCondition.setIssueStatusType("CLOSE");
            List<Map<String, Object>> results = Lists.newArrayList();
            if (customFieldType.equals(IP_ADDRESS.toString()) && issueForm.getIssueCompanyFields() != null && issueForm.getIssueCompanyFields().size() > 0) {
                long ipValue = 0;
                if (concatUseValue.contains(",")) {
                    String[] arr = concatUseValue.split(",");
                    for (String str : arr) {
                        ipValue = ConvertUtil.ipToLong(str);
                    }
                } else {
                    ipValue = ConvertUtil.ipToLong(concatUseValue);
                }
                issueCustomFieldValueCondition.setUseValue(String.valueOf(ipValue));
                //  하위이슈조건의 타입이 IP일 경우 같은 업체정보인 이슈 찾기
                results = this.issueMapper.findByCustomFieldValueOfIp(issueCustomFieldValueCondition);
            } else {
                results = this.issueMapper.findByCustomFieldValue(issueCustomFieldValueCondition);
            }
 
            if (results != null && results.size() > 0) {
                for (Map<String, Object> result : results) {
                    resultIssueVos.add(this.getIssue(MapUtil.getLong(result, "id")));
                }
            }
        }
        return resultIssueVos;
    }
 
    //  이슈를 생성한다.
    @Override
    @Transactional
    public Issue addIssue(IssueForm issueForm, List<MultipartFile> multipartFiles) {
        User user = this.webAppUtil.getLoginUserObject();
        return addIssue(user, issueForm, multipartFiles);
    }
 
    //  이슈를 생성한다.
    @Override
    @Transactional
    public Issue addIssue(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
        StringBuilder detectIssueChange = new StringBuilder();
 
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        Workspace workspace = this.workspaceService.checkUseWorkspace(user, user.getLastWorkspaceId());
        //  프로젝트 유효성 체크
        Project project = this.projectService.getProject(issueForm.getProjectId());
        //  이슈 유형 유효성 체크
        IssueType issueType = this.issueTypeService.getIssueType(issueForm.getIssueTypeId());
        //  우선순위 유효성 체크
        Priority priority = this.priorityService.getPriority(issueForm.getPriorityId());
        //  중요도 유효성 체크
        Severity severity = this.severityService.getSeverity(issueForm.getSeverityId());
 
        //  제목 유효성 체크
        this.verifyTitle(issueForm.getTitle());
        //  날짜 유효성 체크
        this.checkStartCompleteDate(issueForm.getStartDate(), issueForm.getCompleteDate());
        //  담당 부서 유효성 체크
        //this.verifyIssueDepartment(project, issueForm);
 
        //  이슈 상태 유형이 '대기' 인 이슈 상태 가져오기
        IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
 
        Issue issue = ConvertUtil.copyProperties(issueForm, Issue.class);
        issue.setProject(project);
        issue.setIssueStatus(issueStatus);
        issue.setIssueType(issueType);
        issue.setPriority(priority);
        issue.setSeverity(severity);
        if (issueForm.getParentIssueId() != null){
            Issue parentIssue = this.getIssue(issueForm.getParentIssueId());
            issue.setParentIssue(parentIssue);
 
            // 상위 이슈가 종료일경우 대기로 변경
            IssueStatus parentIssueStatus = parentIssue.getIssueStatus();
            if (parentIssueStatus.getIssueStatusType().equals(IssueStatusType.CLOSE)) {
                parentIssue.setIssueStatus(issueStatus);
            }
        }
 
        issue.setIssueNumber(this.issueNumberGeneratorService.generateIssueNumber(project));    //  각 프로젝트의 고유 이슈 번호 생성
 
        issue = this.issueRepository.saveAndFlush(issue);
 
        issue.setReverseIndex(issue.getId() * -1);  //  쿼리 속도 개선을 위해 리버스 인덱스 생성
 
        if (issueForm.getParentIssueId() != null){
            Issue parentIssue = this.getIssue(issueForm.getParentIssueId());
            if (issueForm.getIsApi().equals(Issue.IS_API_YES)
                    || (issueForm.getInheritYn() != null && issueForm.getInheritYn())) {
                //  하위이슈에 상위이슈의 파트너 정보 적용
                this.inheritPartners(issue, parentIssue);
            }
        }
 
        //  담당자 지정
        //this.issueUserService.modifyIssueUser(issue, project.getWorkspace(), issueForm.getUserIds());
        //  담당부서 지정
        this.issueDepartmentService.modifyIssueDepartment(issue, user, project.getWorkspace(), issueForm.getDepartmentIds());
        //  업체 정보 저장
        this.issueCompanyService.modifyIssueCompanyField(issue, issueForm, detectIssueChange);
        //  ISP 정보 저장
        this.issueIspService.modifyIssueIspField(issue, issueForm, detectIssueChange);
        //  HOSTING 정보 저장
        this.issueHostingService.modifyIssueHostingField(issue, issueForm, detectIssueChange);
 
        //  첨부 파일 저장
        //  multipartFile 을 file Map List 객체로 변경한다.
        List<Map<String, Object>> convertFileMaps = this.convertMultipartFileToFile(multipartFiles);
        this.attachedFileService.addAttachedFile(convertFileMaps, issue, user.getAccount());
 
        //  텍스트 에디터에 첨부한 파일을 이슈와 연결
        this.checkNotHaveIssueIdAttachedFile(issue, issueForm);
        //  사용자 정의 필드 저장
        this.issueCustomFieldValueService.modifyIssueCustomFieldValue(issue, issueForm.getIssueCustomFields());
        //  이슈 이력 생성
        this.issueHistoryService.addIssueHistory(issue, user, IssueHistoryType.ADD, null);
        //  이슈 위험 관리 생성
        this.issueRiskService.addIssueRisk(issue, project.getWorkspace());
        //  영속성 컨텍스트 비우기
        this.clear();
        //  이슈 생성, 삭제시 예약 이메일에 등록해놓는다.
        this.reservationIssueEmail(issue, EmailType.ISSUE_ADD);
        //  사용자 시스템 기능 사용 정보 수집
 
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_ADD));
 
        return issue;
    }
 
    //  연관이슈를 생성한다.
    @Override
    @Transactional
    public Issue addRelIssue(IssueForm issueForm, List<MultipartFile> multipartFiles) {
        User user = this.webAppUtil.getLoginUserObject();
        return addRelIssue(user, issueForm, multipartFiles);
    }
 
    //  하위이슈를 생성한다.
    @Override
    @Transactional
    public Issue addDownIssue(Map<String, Object> resJsonData, IssueForm issueForm, List<MultipartFile> multipartFiles) {
        User user = this.webAppUtil.getLoginUserObject();
        return addDownIssue(resJsonData, user, issueForm, multipartFiles);
    }
 
    //  하위이슈를 생성한다.
    @Override
    @Transactional
    public Issue addDownIssue(Map<String, Object> resJsonData, User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
        StringBuilder detectIssueChange = new StringBuilder();
 
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        Workspace workspace = this.workspaceService.checkUseWorkspace(user, user.getLastWorkspaceId());
        //  프로젝트 유효성 체크
        Project project = this.projectService.getProject(issueForm.getProjectId());
        //  이슈 유형 유효성 체크
        IssueType issueType = this.issueTypeService.getIssueType(issueForm.getIssueTypeId());
        //  우선순위 유효성 체크
        Priority priority = this.priorityService.getPriority(issueForm.getPriorityId());
        //  중요도 유효성 체크
        Severity severity = this.severityService.getSeverity(issueForm.getSeverityId());
 
        //  제목 유효성 체크
        this.verifyTitle(issueForm.getTitle());
        //  날짜 유효성 체크
        this.checkStartCompleteDate(issueForm.getStartDate(), issueForm.getCompleteDate());
        //  담당 부서 유효성 체크
        //this.verifyIssueDepartment(project, issueForm);
 
        //  이슈 상태 유형이 '대기' 인 이슈 상태 가져오기
        IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
 
        Issue issue = ConvertUtil.copyProperties(issueForm, Issue.class);
        issue.setProject(project);
        issue.setIssueStatus(issueStatus);
        issue.setIssueType(issueType);
        issue.setPriority(priority);
        issue.setSeverity(severity);
        if (issueForm.getParentIssueId() != null){
            Issue parentIssue = this.getIssue(issueForm.getParentIssueId());
            issue.setParentIssue(parentIssue);
        }
 
        issue.setIssueNumber(this.issueNumberGeneratorService.generateIssueNumber(project));    //  각 프로젝트의 고유 이슈 번호 생성
 
        issue = this.issueRepository.saveAndFlush(issue);
 
        issue.setReverseIndex(issue.getId() * -1);  //  쿼리 속도 개선을 위해 리버스 인덱스 생성
        //  담당자 지정
        //this.issueUserService.modifyIssueUser(issue, project.getWorkspace(), issueForm.getUserIds());
        //  담당부서 지정
        this.issueDepartmentService.modifyIssueDepartment(issue, user, project.getWorkspace(), issueForm.getDepartmentIds());
        //  업체 정보 저장
        this.issueCompanyService.modifyIssueCompanyField(issue, issueForm, detectIssueChange);
        //  ISP 정보 저장
        this.issueIspService.modifyIssueIspField(issue, issueForm, detectIssueChange);
        //  HOSTING 정보 저장
        this.issueHostingService.modifyIssueHostingField(issue, issueForm, detectIssueChange);
 
        //  첨부 파일 저장
        //  multipartFile 을 file Map List 객체로 변경한다.
        List<Map<String, Object>> convertFileMaps = this.convertMultipartFileToFile(multipartFiles);
        this.attachedFileService.addAttachedFile(convertFileMaps, issue, user.getAccount());
 
        //  텍스트 에디터에 첨부한 파일을 이슈와 연결
        this.checkNotHaveIssueIdAttachedFile(issue, issueForm);
        //  사용자 정의 필드 저장
        this.issueCustomFieldValueService.modifyIssueCustomFieldValue(issue, issueForm.getIssueCustomFields());
        //  이슈 이력 생성
        this.issueHistoryService.addIssueHistory(issue, user, IssueHistoryType.ADD, null);
        //  이슈 위험 관리 생성
        this.issueRiskService.addIssueRisk(issue, project.getWorkspace());
 
        //  영속성 컨텍스트 비우기
        this.clear();
        //  이슈 생성, 삭제시 예약 이메일에 등록해놓는다.
        this.reservationIssueEmail(issue, EmailType.ISSUE_ADD);
        //  사용자 시스템 기능 사용 정보 수집
 
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_ADD));
 
        IssueVo issueVo = this.convertToIssueVo(issue);
        resJsonData.put(Constants.RES_KEY_CONTENTS, issueVo);
 
        return issue;
    }
 
    /**
     * Issue를 IssueVo로 변환(하위이슈의 파트너 정보 상속 시 필요)
     * @param issue Issue
     * @return IssueVo
     */
    private IssueVo convertToIssueVo(Issue issue) {
        IssueVo issueVo = ConvertUtil.copyProperties(issue, IssueVo.class);
        issueVo.setInheritPartners(issue.getIssueType().getInheritPartners());
        issueVo.setUsePartner(issue.getIssueType().getUsePartner());
        return issueVo;
    }
 
    //  연관이슈를 생성한다.
    @Override
    @Transactional
    public Issue addRelIssue(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
        StringBuilder detectIssueChange = new StringBuilder();
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        Workspace workspace = this.workspaceService.checkUseWorkspace(user, user.getLastWorkspaceId());
        //  프로젝트 유효성 체크
        Project project = this.projectService.getProject(issueForm.getProjectId());
        //  이슈 유형 유효성 체크
        IssueType issueType = this.issueTypeService.getIssueType(issueForm.getIssueTypeId());
        //  우선순위 유효성 체크
        Priority priority = this.priorityService.getPriority(issueForm.getPriorityId());
        //  중요도 유효성 체크
        Severity severity = this.severityService.getSeverity(issueForm.getSeverityId());
 
        //  제목 유효성 체크
        this.verifyTitle(issueForm.getTitle());
        //  날짜 유효성 체크
        this.checkStartCompleteDate(issueForm.getStartDate(), issueForm.getCompleteDate());
        //  담당 부서 유효성 체크
        //this.verifyIssueDepartment(project, issueForm);
 
        //  이슈 상태 유형이 '대기' 인 이슈 상태 가져오기
        IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
 
        Issue issue = ConvertUtil.copyProperties(issueForm, Issue.class);
        issue.setProject(project);
        issue.setIssueStatus(issueStatus);
        issue.setIssueType(issueType);
        issue.setPriority(priority);
        issue.setSeverity(severity);
        if (issueForm.getParentIssueId() != null){
            Issue parentIssue = this.getIssue(issueForm.getParentIssueId());
            issue.setParentIssue(parentIssue);
        }
 
        issue.setIssueNumber(this.issueNumberGeneratorService.generateIssueNumber(project));    //  각 프로젝트의 고유 이슈 번호 생성
 
        issue = this.issueRepository.saveAndFlush(issue);
 
        issue.setReverseIndex(issue.getId() * -1);  //  쿼리 속도 개선을 위해 리버스 인덱스 생성
        //  담당자 지정
        //this.issueUserService.modifyIssueUser(issue, project.getWorkspace(), issueForm.getUserIds());
        //  담당부서 지정
        this.issueDepartmentService.modifyIssueDepartment(issue, user, project.getWorkspace(), issueForm.getDepartmentIds());
        //  업체 정보 저장
        this.issueCompanyService.modifyIssueCompanyField(issue, issueForm, detectIssueChange);
        //  ISP 정보 저장
        this.issueIspService.modifyIssueIspField(issue, issueForm, detectIssueChange);
        //  HOSTING 정보 저장
        this.issueHostingService.modifyIssueHostingField(issue, issueForm, detectIssueChange);
 
        //  첨부 파일 저장
        //  multipartFile 을 file Map List 객체로 변경한다.
        List<Map<String, Object>> convertFileMaps = this.convertMultipartFileToFile(multipartFiles);
        this.attachedFileService.addAttachedFile(convertFileMaps, issue, user.getAccount());
 
        //  텍스트 에디터에 첨부한 파일을 이슈와 연결
        this.checkNotHaveIssueIdAttachedFile(issue, issueForm);
        //  사용자 정의 필드 저장
        this.issueCustomFieldValueService.modifyIssueCustomFieldValue(issue, issueForm.getIssueCustomFields());
        //  이슈 이력 생성
        this.issueHistoryService.addIssueHistory(issue, user, IssueHistoryType.ADD, null);
        //  이슈 위험 관리 생성
        this.issueRiskService.addIssueRisk(issue, project.getWorkspace());
        //  영속성 컨텍스트 비우기
        this.clear();
        //  이슈 생성, 삭제시 예약 이메일에 등록해놓는다.
        this.reservationIssueEmail(issue, EmailType.ISSUE_ADD);
        //  사용자 시스템 기능 사용 정보 수집
 
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_ADD));
 
        return issue;
    }
 
    //  이슈 생성, 삭제시 예약 이메일에 등록해놓는다.
    private void reservationIssueEmail(Issue issue, EmailType emailType) {
        Map<String, Object> issueMap = new HashMap<>();
        //  이슈 정보를 이메일 전송에 사용하기 위해 Map 형태로 변환한다.
        this.makeIssueMapToIssue(issue, issueMap);
 
        Map<String, Object> projectRoleUserMap = new HashMap<>();
        projectRoleUserMap.put("id", issue.getProject().getId());
        projectRoleUserMap.put("statuses", Lists.newArrayList("02"));   //  관리자 조회
        //  관리자 정보 셋팅
        List<Map<String, Object>> projectRoleUsers = this.projectRoleUserService.findProjectRoleUser(projectRoleUserMap);
        if (projectRoleUsers != null && !projectRoleUsers.isEmpty()) {
            for (Map<String, Object> projectRoleUser : projectRoleUsers) {
                UserVo userVo = ConvertUtil.convertMapToClass(projectRoleUser, UserVo.class);
                //  이슈 생성 알림 메일 전송
                this.systemEmailService.reservationEmail(new String[]{userVo.getAccount()}, emailType, issueMap);
            }
        }
    }
 
    //  이슈 정보를 이메일 전송에 사용하기 위해 Map 형태로 변환한다.
    public void makeIssueMapToIssue(Issue issue, Map<String, Object> issueMap) {
        issueMap.put("title", issue.getTitle());
        issueMap.put("issueNumber", issue.getIssueNumber());
        issueMap.put("issueTypeName", issue.getIssueType().getName());
        issueMap.put("issueStatusName", issue.getIssueStatus().getName());
 
        //  담당자
        StringBuilder assigneeBuilder = new StringBuilder();
        for (IssueUser issueUser : issue.getIssueUsers()) {
            assigneeBuilder.append(issueUser.getUser().getName());
            assigneeBuilder.append("(");
            assigneeBuilder.append(CommonUtil.decryptAES128(issueUser.getUser().getAccount()));
            assigneeBuilder.append(")");
            assigneeBuilder.append("\n");
        }
        issueMap.put("assignees", assigneeBuilder.toString());
 
        //  담당부서
        StringBuilder departsBuilder = new StringBuilder();
        for (IssueDepartment issueDepartment : issue.getIssueDepartments()) {
            departsBuilder.append(issueDepartment.getDepartment().getDepartmentName());
            departsBuilder.append("\n");
        }
        issueMap.put("departments", departsBuilder.toString());
 
        //  기간
        if (!StringUtils.isEmpty(issue.getStartDate())) {
            issueMap.put("period", issue.getStartDate() + " ~ " + issue.getCompleteDate());
        }
 
        issueMap.put("severityName", issue.getSeverity().getName());
        issueMap.put("priorityName", issue.getPriority().getName());
        issueMap.put("projectName", issue.getProject().getName());
        issueMap.put("projectKey", issue.getProject().getProjectKey());
 
        User user = this.userService.getUser(issue.getRegisterId());
        StringBuilder registerBuilder = new StringBuilder();
        registerBuilder.append(user.getName());
        registerBuilder.append("(");
        registerBuilder.append(CommonUtil.decryptAES128(user.getAccount()));
        registerBuilder.append(")");
        issueMap.put("register", registerBuilder.toString());
 
        Map<String, Object> customField = new HashMap<>();
 
        List<IssueCustomFieldValueVo> issueCustomFieldValueVos = this.issueCustomFieldValueService.findByIssueId(issue.getId());
 
        for (IssueCustomFieldValueVo issueCustomFieldValueVo : issueCustomFieldValueVos) {
            //  이미 데이터가 존재
            if (customField.get(issueCustomFieldValueVo.getCustomFieldVo().getName()) != null) {
                List<String> useValues = (List<String>) customField.get(issueCustomFieldValueVo.getCustomFieldVo().getName());
                useValues.add(issueCustomFieldValueVo.getUseValue());
                customField.put(issueCustomFieldValueVo.getCustomFieldVo().getName(), useValues);
            } else {
                if (issueCustomFieldValueVo.getCustomFieldVo().getCustomFieldType().equals(INPUT.toString())) {
                    customField.put(issueCustomFieldValueVo.getCustomFieldVo().getName(), issueCustomFieldValueVo.getUseValue());
                } else {
                    customField.put(issueCustomFieldValueVo.getCustomFieldVo().getName(), Lists.newArrayList(issueCustomFieldValueVo.getUseValue()));
                }
            }
        }
 
        List<Map<String, Object>> customFields = Lists.newArrayList();
 
        Iterator<String> iterator = customField.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Map<String, Object> result = new HashMap<>();
            result.put("name", key);
            result.put("useValue", customField.get(key));
            customFields.add(result);
        }
 
        issueMap.put("customFields", customFields);
        issueMap.put("description", issue.getDescription());
 
        //업체,ISP,HOSTING 추가
 
 
        StringBuilder attachedFileBuilder = new StringBuilder();
 
        List<AttachedFile> attachedFiles = this.attachedFileService.findByIssueId(issue.getId());
 
        for (AttachedFile attachedFile : attachedFiles) {
            attachedFileBuilder.append("<a href='");
            attachedFileBuilder.append(attachedFile.getPath());
            attachedFileBuilder.append("'>");
            attachedFileBuilder.append(attachedFile.getName());
            attachedFileBuilder.append("</a>");
            attachedFileBuilder.append("\n");
        }
 
        issueMap.put("attachedFiles", attachedFileBuilder.toString());
    }
 
    //  제목 유효성 체크
    private void verifyTitle(String title) {
        if (StringUtils.isEmpty(title)) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NO_TITLE));
        }
 
        if (title.length() > 300) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_TITLE_MAX_LENGTH_OUT));
        }
    }
 
    /**
     * 날짜 유효성 체크
     * @param startDate 시작 일자(문자)
     * @param completeDate 종료 일자(문자)
     */
    private void checkStartCompleteDate(String startDate, String completeDate) {
        if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(completeDate)) {
            Date start = DateUtil.convertStrToDate(startDate, "yy-MM-dd");
            Date end = DateUtil.convertStrToDate(completeDate, "yy-MM-dd");
            checkStartCompleteDate(start, end);
        }
    }
 
    /**
     * 날짜 유효성 체크
     * @param start 시작 일자
     * @param end 종료 일자
     */
    private void checkStartCompleteDate(Date start, Date end) {
        if (start.getTime() > end.getTime()) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.DATE_PICKER_NOT_AVAILABLE));
        }
    }
 
    //  텍스트 에디터에 첨부한 파일을 이슈와 연결
    private void checkNotHaveIssueIdAttachedFile(Issue issue, IssueForm issueForm) {
        if (!issueForm.getAttachedFileIds().isEmpty()) {
            this.attachedFileService.connectIssueIdAttachedFile(issue, issueForm);
        }
    }
 
    void SetMyDepartmentId(IssueCondition issueCondition){
        Long loginId = issueCondition.getLoginUserId();
        List<Long> myDepartmentIds = Lists.newArrayList();
        List<UserDepartment> myDepartments = this.userDepartmentRepository.findByUserId(loginId);
 
        if(myDepartments != null && myDepartments.size() > 0){
            for(UserDepartment myDepartment : myDepartments){
                myDepartmentIds.add(myDepartment.getDepartmentId());
            }
        } else {
            myDepartmentIds.add(-1L);
        }
        issueCondition.setMyDepartmentIds(myDepartmentIds);
    }
 
    void SetAllDepartmentId(IssueCondition issueCondition){
        List<Long> departmentIds = Lists.newArrayList();
        List<Map<String, Object>> departmentList = this.departmentMapper.find(null);
 
        if(departmentList != null && departmentList.size() > 0){
            for(Map<String, Object> department : departmentList){
                departmentIds.add((Long) department.get("id"));
            }
        }
        issueCondition.setMyDepartmentIds(departmentIds);
    }
 
    void SetWorkflowDepartment(List<IssueVo> issueVos){
        for(IssueVo issueVo : issueVos){
            Long issueTypeId = issueVo.getIssueTypeId();
            IssueType issueType = this.issueTypeService.getIssueType(issueTypeId);
            Long workflowId = issueType.getWorkflow().getId();
            List<WorkflowDepartment> workflowDepartmentList = this.workflowDepartmentRepository.findByWorkflowId(workflowId);
            List<Long> workflowDepartmentIds = Lists.newArrayList();
            if(workflowDepartmentList != null && workflowDepartmentList.size()>0){
                for(WorkflowDepartment workflowDepartment : workflowDepartmentList){
                    workflowDepartmentIds.add(workflowDepartment.getDepartment().getId());
                }
            }
            if(issueVo.getIssueTypeId().equals(issueTypeId)){
                issueVo.setWorkflowDepartmentIds(workflowDepartmentIds);
            }
        }
    }
 
    //  이슈 목록을 조회한다.
    @Override
    @Transactional(readOnly = true)
    public List<IssueVo> findIssue(Map<String, Object> resJsonData, IssueCondition issueCondition, Pageable pageable) {
        //  검색 조건을 만든다
        if (!this.makeIssueSearchCondition(issueCondition, Lists.newArrayList("01", "02", "03"), pageable)) {
            //  이슈 목록을 찾지 못할 경우 기본 정보로 리턴한다.
            this.notFoundIssueList(resJsonData, pageable);
            return Lists.newArrayList();
        }
 
        Set<String> issueIds = new HashSet<>(); //  사용자 정의 필드 검색시 나오는 이슈 아이디 저장 컬렉션
 
        //  사용자 정의 필드를 사용한 이슈를 찾는다. 만약 이슈가 없다면 여기서 이슈 조회가 끝난다.
        if (!this.searchUseCustomFields(issueCondition, issueIds, resJsonData, pageable)) {
            //  이슈 목록을 찾지 못할 경우 기본 정보로 리턴한다.
            this.notFoundIssueList(resJsonData, pageable);
            return Lists.newArrayList();
        }
 
        List<IssueVo> issueVos = Lists.newArrayList();  //  이슈 목록 데이터 저장 컬렉션
        //  사용자 정의 필드로 검색한 이슈 아이디 값
        List<String> issueKeys = Lists.newArrayList(issueIds);
        issueCondition.setIssueIds(issueKeys);
        User user = this.webAppUtil.getLoginUserObject();
 
        issueCondition.setLoginUserId(user.getId());
        issueCondition.setWorkspaceId(user.getLastWorkspaceId());
 
 
        List<Map<String, Object>> results = Lists.newArrayList();
        Long totalCount = 0L;
//        UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
 
//        if (!this.userWorkspaceService.checkWorkspaceManager(user)
//                && !MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE)) { //최고관리자 & 프로젝트,이슈 관리자 일 경우 모든 이슈 보기
//            this.SetMyDepartmentId(issueCondition);
        //this.SetAllDepartmentId(issueCondition);
//        } /*else{
//            results = this.issueMapper.findByDepartment(issueCondition);
//            totalCount = this.issueMapper.countByDepartment(issueCondition);
//        }*/
//        StopWatch serviceStart = new StopWatch();
//        serviceStart.start();
        results = this.issueMapper.find(issueCondition);
//         serviceStart.stop();
//        log.error("result : " + serviceStart.toString());
 
//        serviceStart = new StopWatch();
//        serviceStart.start();
        totalCount = this.issueMapper.count(issueCondition);
 
//        serviceStart.stop();
//        log.error("totalCount : " + serviceStart.toString());
 
        int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
        //  이슈 아이디 초기화
 
        issueCondition.setIsApi(issueCondition.getIsApi());
 
        issueCondition.setIssueIds(Lists.newArrayList());
        //  Map 에 있는 데이터를 IssueVo 데이터로 변환한다.
        this.setMapToIssueVo(results, issueVos, issueCondition, user);
 
        if (issueCondition.getTree()) {
            this.setParentIssue(issueVos);
            this.setDownIssues(user, issueVos);
            this.setRelationIssues(issueVos);
        }
 
        this.setCountDownIssues(issueVos);
        this.SetWorkflowDepartment(issueVos); //워크플로우에 설정한 담당부서 가져오기
 
        resJsonData.put(Constants.RES_KEY_CONTENTS, issueVos);
        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
                totalPage, totalCount));
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_FIND));
        return issueVos;
    }
 
 
    // 하위 이슈 세팅(재귀)
    private void setDownIssues(User user, List<IssueVo> issueVos) {
        for(IssueVo issueVo : issueVos) {
            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueVo.getId());
            List<IssueVo> downIssueVos = Lists.newArrayList();
            IssueCondition issueCondition = new IssueCondition();
            issueCondition.addIssueIds(String.valueOf(issueVo.getId()));
 
            for(Issue downIssue : downIssues){
                IssueVo addIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
                addIssueVo.setIssueTypeId(downIssue.getIssueType().getId());
                downIssueVos.add(addIssueVo);
            }
            issueVo.setIssueDownVos(downIssueVos);
 
            if (downIssueVos.size() > 0) {
                this.setDownIssues(user, downIssueVos);
            }
 
            //  이슈 사용자 정보 추가
            //this.setIssueUserList(issueVos, issueCondition);
            this.setIssueDepartmentList(issueVos, issueCondition, user);
            //  등록자 정보 추가
            this.setRegister(issueVos);  //  담당자 정보 셋팅
            //  사용자 정의 필드 정보 추가
            this.setIssueCustomFieldValue(issueVos, issueCondition);
            //워크플로우에 설정한 담당부서 가져오기
            this.SetWorkflowDepartment(issueVos);
        }
    }
 
    // 연관 이슈 세팅
    private void setRelationIssues(List<IssueVo> issueVos) {
        for(IssueVo issueVo : issueVos) {
            List<IssueVo> relationIssues = this.issueRelationService.findRelationIssue(issueVo.getId());
            for(IssueVo relationIssue : relationIssues){
                issueVo.addRelationIssueVo(ConvertUtil.copyProperties(relationIssue, IssueVo.class));
            }
        }
    }
 
    // 상위 이슈 체크
    private void setParentIssue(List<IssueVo> issueVos) {
        for(IssueVo issueVo : issueVos) {
            if(issueVo.getParentIssueId() != null) {
                Issue parentIssue = this.getIssue(issueVo.getParentIssueId());
                //issueVo.setParentIssueVo(ConvertUtil.copyProperties(parentIssue, IssueVo.class));
                if(parentIssue.getIssueCustomFieldValues() == null || parentIssue.getIssueCustomFieldValues().size() == 0){
                    issueVo.setIssueCustomFieldValueVos(null);
                }
                ConvertUtil.copyProperties(parentIssue, issueVo);
            }
        }
    }
 
    @Override
    @Transactional(readOnly = true)
    public void setCountDownIssues(List<IssueVo> issueVos) {
        for (IssueVo issueVo : issueVos){
            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueVo.getId()); //하위이슈 가져오기
            if(downIssues != null && downIssues.size() > 0){ //상위이슈 가지고 있는 애들이 있으면
                int downIssueAllCount = 0;// 하위이슈 전체 카운트
                int downIssueCount = 0;// 하위이슈 미완료 카운트
                for(Issue downIssue : downIssues){
                    downIssueAllCount ++;
                    Long parentIssueId = downIssue.getParentIssue().getId();
                    Issue parentIssue = this.getIssue(parentIssueId);
                    IssueVo parentIssueVo = ConvertUtil.copyProperties(parentIssue, IssueVo.class);
                    parentIssueVo.setDownIssueAllCount(downIssueAllCount);
 
                    IssueStatus downIssueStatus = this.issueStatusService.getIssueStatus(downIssue.getIssueStatus().getId());
                    IssueVo downIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
                    downIssueVo.setIssueStatusType(downIssueStatus.getIssueStatusType().toString());
 
                    if(!downIssueVo.getIssueStatusType().equals("CLOSE")){ //미완료 하위이슈 체크
                        downIssueCount ++;
                    }
 
                    issueVo.setDownIssueCount(downIssueCount);
                    issueVo.setDownIssueAllCount(parentIssueVo.getDownIssueAllCount());
                }
            }
        }
    }
 
 
    //  이슈 목록을 조회한다(차트용 - 연관일감포함)
    @Override
    @Transactional(readOnly = true)
    public void findApiIssue(ApiMonitorCondition apiMonitorCondition, Map<String, Object> resJsonData) {
 
        IssueTypeCondition issueTypeCondition = new IssueTypeCondition();
        issueTypeCondition.setIsApi(Issue.IS_API_YES);
        List<IssueTypeVo> issueTypes = this.issueTypeService.findIssueType(issueTypeCondition);
 
        //  검색 일자를 구한다.
        List<Date> searchDates = Lists.newArrayList();
        if (apiMonitorCondition.getSearchPeriod().equals(DateUtil.CUSTOM_INPUT)) {
            Date startDate = DateUtil.convertStrToDate(apiMonitorCondition.getSearchStartDate(), "yyyy-MM-dd");
            Date endDate = DateUtil.addDays(DateUtil.convertStrToDate(apiMonitorCondition.getSearchEndDate(), "yyyy-MM-dd"), 1);
 
            searchDates = CommonUtil.findSearchPeriod(startDate, endDate);
        } else {
            searchDates = CommonUtil.findSearchPeriod(apiMonitorCondition.getSearchPeriod());
        }
 
        //  날짜가 검색되지 않았으면 오류
        if (searchDates.size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.WIDGET_SEARCH_DATE_NOT_FOUND));
        }
 
        Long index = 1L;
        List<ApiMonitorVo> apiMonitorVos = Lists.newArrayList();
        for (Date date : searchDates) {
 
            String onlyDate = DateUtil.convertDateToYYYYMMDD(date);
            issueTypeCondition.setStartDate(onlyDate + " 00:00:00");
            issueTypeCondition.setEndDate(onlyDate + " 23:59:59");
 
            ApiMonitorVo apiMonitorVo = new ApiMonitorVo();
            apiMonitorVo.setId(index);
            for (IssueTypeVo issueTypeVo : issueTypes) {
                issueTypeCondition.setId(issueTypeVo.getId());
                apiMonitorVo.addIssueTypeCount(this.issueMapper.countByIssueTypeIdAndDate(issueTypeCondition));
                apiMonitorVo.setIsApi(Issue.IS_API_YES);
 
                apiMonitorVos.add(apiMonitorVo);
            }
            index++;
        }
        Map<String, Object> data = new HashMap<>();
        data.put("issueTypeVos", issueTypes);
        data.put("apiMonitorVos", apiMonitorVos);
        resJsonData.put(Constants.RES_KEY_CONTENTS, data);
    }
 
 
    //  이슈 목록을 조회한다(차트용 - 연관일감포함)
    @Override
    @Transactional(readOnly = true)
    public List<IssueVo> findChartIssue(Map<String, Object> resJsonData,
                                        IssueCondition issueCondition, Pageable pageable) {
 
        //  검색 조건을 만든다
        if (!this.makeIssueSearchCondition(issueCondition,Lists.newArrayList("01", "02", "03"), pageable)) {
            //  이슈 목록을 찾지 못할 경우 기본 정보로 리턴한다.
            this.notFoundIssueList(resJsonData, pageable);
            return Lists.newArrayList();
        }
 
        Set<String> issueIds = new HashSet<>(); //  사용자 정의 필드 검색시 나오는 이슈 아이디 저장 컬렉션
 
        //  사용자 정의 필드를 사용한 이슈를 찾는다. 만약 이슈가 없다면 여기서 이슈 조회가 끝난다.
        if (!this.searchUseCustomFields(issueCondition, issueIds, resJsonData, pageable)) {
            //  이슈 목록을 찾지 못할 경우 기본 정보로 리턴한다.
            this.notFoundIssueList(resJsonData, pageable);
            return Lists.newArrayList();
        }
 
        //  튜닝 전 - 1.3 / 1.2 / 1.1
        //  튜닝 후 (단일/다중 검색 조건 3개 기준) - 0.49 / 0.41 / 0.47 / 0.41
        List<IssueVo> issueVos = Lists.newArrayList();  //  이슈 목록 데이터 저장 컬렉션
        //  사용자 정의 필드로 검색한 이슈 아이디 값
        List<String> issueKeys = Lists.newArrayList(issueIds);
        issueCondition.setIssueIds(issueKeys);
 
        List<Map<String, Object>> results = this.issueMapper.find(issueCondition);
        int totalCount = results.size();
        int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
 
        //  이슈 아이디 초기화
        issueCondition.setIssueIds(Lists.newArrayList());
        //  Map 에 있는 데이터를 IssueVo 데이터로 변환한다.
        this.setMapToIssueVoForChart(results, issueVos, issueCondition);
 
        resJsonData.put(Constants.RES_KEY_CONTENTS, issueVos);
        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
                totalPage, totalCount));
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_FIND));
        return issueVos;
    }
 
    //  이슈 목록을 조회한다(차트용 - 연관일감)
    @Override
    @Transactional(readOnly = true)
    public List<IssueVo> findChartIssue(Map<String, Object> resJsonData,
                                        ProjectCondition projectCondition, Pageable pageable) {
 
        IssueCondition issueCondition = new IssueCondition();
        //  검색 조건을 만든다
 
        User user = this.webAppUtil.getLoginUserObject();
        if (!this.makeIssueSearchCondition(user, issueCondition, projectCondition, pageable)) {
            //  이슈 목록을 찾지 못할 경우 기본 정보로 리턴한다.
            this.notFoundIssueList(resJsonData, pageable);
            return Lists.newArrayList();
        }
 
        Set<String> issueIds = new HashSet<>(); //  사용자 정의 필드 검색시 나오는 이슈 아이디 저장 컬렉션
        List<IssueVo> issueVos = Lists.newArrayList();  //  이슈 목록 데이터 저장 컬렉션
        //  사용자 정의 필드로 검색한 이슈 아이디 값
        List<String> issueKeys = Lists.newArrayList(issueIds);
        issueCondition.setIssueIds(issueKeys);
 
        List<Map<String, Object>> results = this.issueMapper.find(issueCondition);
        int totalCount = results.size();
        int totalPage = (int) Math.ceil((totalCount - 1) / pageable.getPageSize()) + 1;
 
        //  이슈 아이디 초기화
        issueCondition.setIssueIds(Lists.newArrayList());
        //  Map 에 있는 데이터를 IssueVo 데이터로 변환한다.
        this.setMapToIssueVoForChart(results, issueVos, issueCondition);
 
        resJsonData.put(Constants.RES_KEY_CONTENTS, issueVos);
        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
                totalPage, totalCount));
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_FIND));
        return issueVos;
    }
 
    // Map 에 있는 데이터를 IssueVo 데이터로 변환한다. 차트용
    private void setMapToIssueVoForChart(List<Map<String, Object>> results, List<IssueVo> issueVos, IssueCondition issueCondition) {
        for (Map<String, Object> result : results) {
            IssueVo issueVo = ConvertUtil.convertMapToClass(result, IssueVo.class);
            issueVos.add(issueVo);
            issueCondition.addIssueIds(String.valueOf(issueVo.getId()));
        }
 
        for (IssueVo issueVo : issueVos) {
            this.setRelationIssue(issueVo, issueVo.getId());
        }
    }
 
    //  Map 에 있는 데이터를 IssueVo 데이터로 변환한다.
    private void setMapToIssueVo(List<Map<String, Object>> results, List<IssueVo> issueVos, IssueCondition issueCondition, User user) {
        for (Map<String, Object> result : results) {
            IssueVo issueVo = ConvertUtil.convertMapToClass(result, IssueVo.class);
            if (MapUtil.getString(result, "inheritPartners") != null && MapUtil.getString(result, "inheritPartners").equals("1")) {
                issueVo.setInheritPartners(true);
            }
            issueVos.add(issueVo);
            issueCondition.addIssueIds(String.valueOf(issueVo.getId()));
        }
 
        //  이슈 사용자 정보 추가
        //this.setIssueUserList(issueVos, issueCondition);
        this.setIssueDepartmentList(issueVos, issueCondition, user);
        //  등록자 정보 추가
        this.setRegister(issueVos);  //  담당자 정보 셋팅
 
        //  사용자 정의 필드 정보 추가
        this.setIssueCustomFieldValue(issueVos, issueCondition);
    }
 
    //  검색 조건을 만든다
    private boolean makeIssueSearchCondition(IssueCondition condition, List<String> projectStatues, Pageable pageable) {
        if (pageable != null) {
            condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
            condition.setPageSize(pageable.getPageSize());
        }
 
        condition.setLoginUserId(this.webAppUtil.getLoginId());
        condition.setWorkspaceId(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());
 
        User user = this.webAppUtil.getLoginUserObject();
        UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
 
        //  프로젝트 키가 존재할 경우 프로젝트 키에 해당하는 프로젝트를 조회하고 검색 조건에 셋팅한다.
        if (!this.getProjectByProjectKey(condition.getProjectKey(), condition)) {
            return false;
        }
 
        //  프로젝트를 선택하지 않았으면 해당 업무 공간에서 참여하고 있는 프로젝트를 찾는다.
        if (condition.getProjectIds().size() < 1) {
            List<Map<String, Object>> projects = Lists.newArrayList();
            if (this.userWorkspaceService.checkWorkspaceManager(user) || MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_PROJECT)){
                return true;
            }/*else if (MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE)){
                projects = this.projectService.findByWorkspaceIdAndIncludeProjectAll(projectStatues, condition.getProjectType());
            }*/
            else {
                projects = this.projectService.findByWorkspaceIdAndIncludeProject(projectStatues, condition.getProjectType());
            }
 
            List<Long> projectIds = Lists.newArrayList();
            for (Map<String, Object> result : projects) {
                Long projectId = MapUtil.getLong(result, "id");
 
                if (projectId != null) {
                    projectIds.add(projectId);
                }
            }
 
            condition.setProjectIds(projectIds);
 
            if (projectIds.size() < 1) {
                return false;
            }
        }
 
        return true;
    }
 
    //  검색 조건을 만든다
    private boolean makeIssueSearchCondition(User user, IssueCondition condition, ProjectCondition projectCondition, Pageable pageable) {
        if (pageable != null) {
            condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
            condition.setPageSize(pageable.getPageSize());
        }
 
        condition.setLoginUserId(this.webAppUtil.getLoginId());
        condition.setWorkspaceId(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());
        projectCondition.setWorkspaceId(condition.getWorkspaceId());
 
        //  프로젝트 키가 존재할 경우 프로젝트 키에 해당하는 프로젝트를 조회하고 검색 조건에 셋팅한다.
        if (!this.getProjectByProjectKey(condition.getProjectKey(), condition)) {
            return false;
        }
 
        //  프로젝트를 선택하지 않았으면 해당 업무 공간에서 참여하고 있는 프로젝트를 찾는다.
        if (condition.getProjectIds().size() < 1) {
            List<Map<String, Object>> projects = null;
            UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
            if (this.userWorkspaceService.checkWorkspaceManager(user)
                    || (MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_PROJECT) &&
                    MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE))) {
                projects = this.projectMapper.findByWorkspaceManagerAll(projectCondition);
            } else  {
                projects = this.projectService.findByWorkspaceIdAndIncludeProjectAll(projectCondition);
            }
            List<Long> projectIds = Lists.newArrayList();
 
            for (Map<String, Object> result : projects) {
                Long projectId = MapUtil.getLong(result, "id");
 
                if (projectId != null) {
                    projectIds.add(projectId);
                }
            }
 
            condition.setProjectIds(projectIds);
 
            if (projectIds.size() < 1) {
                return false;
            }
        }
 
        return true;
    }
 
    //  프로젝트 키가 존재할 경우 프로젝트 키에 해당하는 프로젝트를 조회하고 검색 조건에 셋팅한다.
    private boolean getProjectByProjectKey(String projectKey, IssueCondition condition) {
        if (!StringUtils.isEmpty(projectKey)) {
            Project project = this.projectService.findByProjectKey(projectKey);
 
            if (project != null) {
                //  이미 프로젝트를 선택했을 경우에 프로젝트키로 검색한 프로젝트가 포함되어 있지 않으면 false
                if (condition.getProjectIds().size() > 0) {
                    if (condition.getProjectIds().contains(project.getId())) {
                        condition.setProjectIds(Lists.newArrayList());
                    } else {
                        return false;
                    }
                }
 
                condition.addProjectIds(project.getId());
            } else {
                return false;
            }
        }
 
        return true;
    }
 
    //  이슈 목록을 찾지 못할 경우 기본 정보로 리턴한다.
    private void notFoundIssueList(Map<String, Object> resJsonData, Pageable pageable) {
        resJsonData.put(Constants.RES_KEY_CONTENTS, Lists.newArrayList());
        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
                0, 0));
    }
 
    //  사용자 정의 필드를 사용한 이슈를 찾는다. 만약 이슈가 없다면 여기서 이슈 조회가 끝난다.
    private boolean searchUseCustomFields(IssueCondition condition, Set<String> issueIds, Map<String, Object> resJsonData, Pageable pageable) {
        //  사용자 정의 필드 값이 검색 옵션으로 있었을 때 조회된 이슈가 없으면 조회를 더 이상 할 필요가 없다.
        //  사용자 정의 필드를 사용한 이슈를 찾는다.
        boolean customFieldSearch = this.issueCustomFieldValueService.find(condition, issueIds);
 
        //  사용자 정의 필드 값이 존재하여 검색을 했을 때 검색된 이슈가 없으면 여기서 종료한다.
        if (customFieldSearch && issueIds.size() < 1) {
            resJsonData.put(Constants.RES_KEY_CONTENTS, Lists.newArrayList());
 
            if (pageable != null) {
                resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
                        0, 0));
            }
 
            return false;
        }
 
        return true;
    }
 
    //  이슈 담당자 정보를 셋팅한다.
    private void setIssueUserList(List<IssueVo> issueVos, IssueCondition issueCondition, User user) {
        if (issueVos.size() < 1) {
            return;
        }
 
        List<Map<String, Object>> issueUsers = this.issueMapper.findIssueUser(issueCondition);
        Map<String, Object> issueConverterUsers = new HashMap<>();
 
        //  이슈에 해당하는 이슈 담당자 정보 셋팅
        for (Map<String, Object> issueUser : issueUsers) {
            String issueId = MapUtil.getString(issueUser, "issueId");
 
            if (MapUtil.getObject(issueConverterUsers, issueId) != null) {
                List<UserVo> users = (List) MapUtil.getObject(issueConverterUsers, issueId);
                users.add(new UserVo(MapUtil.getLong(issueUser, "id"), MapUtil.getString(issueUser, "name"), CommonUtil.decryptAES128(MapUtil.getString(issueUser, "account")), MapUtil.getString(issueUser, "profile")));
            } else {
                List<UserVo> users = Lists.newArrayList(new UserVo(MapUtil.getLong(issueUser, "id"), MapUtil.getString(issueUser, "name"), CommonUtil.decryptAES128(MapUtil.getString(issueUser, "account")),
                        MapUtil.getString(issueUser, "profile")));
                issueConverterUsers.put(issueId, users);
            }
        }
 
        //  이슈Vo에 담당자 정보를 셋팅
        for (IssueVo issueVo : issueVos) {
            if (MapUtil.getObject(issueConverterUsers, String.valueOf(issueVo.getId())) != null) {
                List<UserVo> userVos = (List) MapUtil.getObject(issueConverterUsers, String.valueOf(issueVo.getId()));
 
                issueVo.setUserVos(userVos);
            }
 
            //  이슈 수정 권한을 갖고 있는지 확인
            if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, null)) {
                issueVo.setModifyPermissionCheck(Boolean.TRUE);
            }
        }
    }
 
    //  이슈 담당부서 정보를 셋팅한다.
    private void setIssueDepartmentList(List<IssueVo> issueVos, IssueCondition issueCondition, User user) {
        if (issueVos.size() < 1) {
            return;
        }
 
        List<Map<String, Object>> issueDepartments = this.issueMapper.findIssueDepartment(issueCondition);
        Map<String, Object> issueConverterDepartments = new HashMap<>();
 
        //  이슈에 해당하는 이슈 담당부서 정보 셋팅
        for (Map<String, Object> issueDepartment : issueDepartments) {
            String issueId = MapUtil.getString(issueDepartment, "issueId");
 
            if (MapUtil.getObject(issueConverterDepartments, issueId) != null) {
                List<DepartmentVo> departments = (List) MapUtil.getObject(issueConverterDepartments, issueId);
                departments.add(new DepartmentVo(MapUtil.getLong(issueDepartment, "id"), MapUtil.getString(issueDepartment, "departmentName"), MapUtil.getString(issueDepartment, "departmentDescription")));
            } else {
                List<DepartmentVo> departments = Lists.newArrayList(new DepartmentVo(MapUtil.getLong(issueDepartment, "id"), MapUtil.getString(issueDepartment, "departmentName"), MapUtil.getString(issueDepartment, "departmentDescription")));
                issueConverterDepartments.put(issueId, departments);
            }
        }
 
        //  이슈Vo에 담당부서 정보를 셋팅
        for (IssueVo issueVo : issueVos) {
            if (MapUtil.getObject(issueConverterDepartments, String.valueOf(issueVo.getId())) != null) {
                List<DepartmentVo> departmentVos = (List) MapUtil.getObject(issueConverterDepartments, String.valueOf(issueVo.getId()));
 
                issueVo.setDepartmentVos(departmentVos);
            }
 
            //  이슈 수정 권한을 갖고 있는지 확인
            if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, issueVo.getDepartmentVos())) {
                issueVo.setModifyPermissionCheck(Boolean.TRUE);
            }
        }
    }
 
    //  이슈 상세 정보를 조회한다.
    @Override
    @Transactional(readOnly = true)
    public void detailIssue(Map<String, Object> resJsonData, IssueCondition issueCondition) {
        IssueVo issueVo = new IssueVo();
        Pageable relPageable = issueCondition.getRelPageable();
        Pageable downPageable = issueCondition.getDownPageable();
 
        if (issueCondition.getId() != null) {
            Issue issue = this.getIssue(issueCondition.getId());
            issueVo = ConvertUtil.copyProperties(issue, IssueVo.class);
            User user = this.webAppUtil.getLoginUserObject();
 
            if (relPageable != null) {
                issueVo.setRelPageNumber(relPageable.getPageNumber());
                issueVo.setRelPageSize(relPageable.getPageSize());
                issueVo.setRelPage(relPageable.getPageNumber() * relPageable.getPageSize());
            }
            if (downPageable != null) {
                issueVo.setDownPageNumber(downPageable.getPageNumber());
                issueVo.setDownPage(downPageable.getPageNumber() * downPageable.getPageSize());
                issueVo.setDownPageSize(downPageable.getPageSize());
            }
 
            switch (issueCondition.getDeep()) {
                case "01": //  프로젝트, 이슈 유형, 이슈 상태,  우선순위, 중요도, 담당부서, 첨부파일, 사용자 정의 필드 정보를 셋팅한다.
                    issueVo.setProjectVo(ConvertUtil.copyProperties(issue.getProject(), ProjectVo.class));
                    issueVo.setIssueTypeVo(ConvertUtil.copyProperties(issue.getIssueType(), IssueTypeVo.class));
                    issueVo.setIssueStatusVo(ConvertUtil.copyProperties(issue.getIssueStatus(), IssueStatusVo.class));
                    issueVo.setPriorityVo(ConvertUtil.copyProperties(issue.getPriority(), PriorityVo.class));
                    issueVo.setSeverityVo(ConvertUtil.copyProperties(issue.getSeverity(), SeverityVo.class));
 
                    this.setRegister(issue, issueVo);   //  등록자 정보 셋팅
                    //this.setIssueUser(issue, issueVo);  //  담당자 정보 셋팅
                    this.setIssueDepartment(issue, issueVo);  //  담당부서 정보 셋팅
                    this.setAttachedFiles(issue, issueVo);  //  첨부 파일 정보 셋팅
                    this.setIssueCustomFields(issue, issueVo);  //  사용자 정의 필드 값 정보 셋팅
                    this.setRelationIssue(issue, issueVo);        //연관 일감 셋팅
                    this.setDownIssues(issue, issueVo); //하위 이슈 세팅
                    break;
 
                case "02": //  프로젝트, 이슈 유형, 이슈 상태,  우선순위, 중요도, 담당자, 첨부파일, 사용자 정의 필드 정보, 댓글, 기록을 셋팅한다.
                    this.setIssueDetail(issueVo, issue, user);    //  이슈 상세 정보를 셋팅한다.
                    this.setIssueTableConfigs(issue, issueVo, issueCondition);
                    issueVo.setProjectVo(ConvertUtil.copyProperties(issue.getProject(), ProjectVo.class));
                    break;
            }
        }
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_DETAIL));
 
        resJsonData.put(Constants.RES_KEY_CONTENTS, issueVo);
    }
 
    // 테이블 설정 셋팅
    private void setIssueTableConfigs(Issue issue, IssueVo issueVo, IssueCondition issueCondition) {
        //Long IssueTypeId = issue.getIssueType().getId();
        Long IssueTypeId = issueCondition.getIssueTypeId();
 
        for (int tableConfigType : IssueTableConfig.IssueTableTypes) {
            if (tableConfigType != IssueTableConfig.ISSUE_TABLE_TYPE_MAIN) {
                issueVo.addIssueTableConfigVo(createIssueTableConfigVo(IssueTypeId, tableConfigType));
            }
        }
    }
 
    private IssueTableConfigVo createIssueTableConfigVo(Long issueTypeId, int tableConfigType) {
        IssueTableConfig issueTableConfig = this.issueTableConfigService.findByUserIdAndWorkspaceIdAndIssueTypeIdAndIssueTableType(issueTypeId, tableConfigType);
        if (issueTableConfig != null) {
            return ConvertUtil.copyProperties(issueTableConfig, IssueTableConfigVo.class);
        }
        return new IssueTableConfigVo();
    }
 
 
    // 하위 이슈 정보를 셋팅한다
    private void setDownIssues(Issue issue, IssueVo issueVo) {
        Page<Issue> downIssues = null;
 
        List<Issue> downIssueList = this.issueRepository.findByParentIssueId(issue.getId());
        if(downIssueList != null && downIssueList.size() > 0) {
            int startPage = 0;
            if (issueVo.getDownPage() != 0) {
                startPage = (int) Math.floor(issueVo.getDownPage()/issueVo.getDownPageSize());
            }
            Pageable pageable = PageRequest.of(startPage, issueVo.getDownPageSize());
            downIssues = this.issueRepository.findByParentIssueId(issue.getId(), pageable);
        }
        if(downIssues != null){
            issueVo.setDownTotalPage(downIssues.getTotalPages());
            issueVo.setDownTotalCount(downIssues.getTotalElements());
 
            List<IssueVo> resultList = new ArrayList<>();
            for(Issue downIssue : downIssues){
                IssueVo downIssueVo = ConvertUtil.copyProperties(downIssue, IssueVo.class);
                downIssueVo.setIssueTypeVo(ConvertUtil.copyProperties(downIssue.getIssueType(), IssueTypeVo.class));
                downIssueVo.setPriorityVo(ConvertUtil.copyProperties(downIssue.getPriority(), PriorityVo.class));
                downIssueVo.setSeverityVo(ConvertUtil.copyProperties(downIssue.getSeverity(), SeverityVo.class));
                //이슈 상태 추가
                IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(downIssue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
                issueStatusVo.setIssueStatusType(downIssue.getIssueStatus().getIssueStatusType().toString());
                downIssueVo.setIssueStatusVo(issueStatusVo);
 
                this.setRegister(downIssue, downIssueVo); // 등록자
                this.setIssueDepartment(downIssue, downIssueVo);  //  담당부서 정보 셋팅
                this.setIssueCustomFields(downIssue, downIssueVo);   // 사용자정의필드 정보 세팅
                this.setIssueHistory(downIssue, downIssueVo);   //  이슈 기록 정보 셋팅
                this.setIssueComments(downIssue, downIssueVo);  //  댓글 정보 셋팅
                this.setIssueCompanyField(downIssue, downIssueVo);  //업체 정보 세팅
                this.setIssueIspField(downIssue, downIssueVo);  //ISP 정보 세팅
                this.setIssueHostingField(downIssue, downIssueVo);  //HOSTING 정보 세팅
 
                downIssueVo.setModifyPermissionCheck(issueVo.getModifyPermissionCheck());
 
                resultList.add(downIssueVo);
            }
            issueVo.setIssueDownVos(resultList);
        }
    }
 
    //  이슈 상세 정보를 셋팅한다.
    @Override
    @Transactional(readOnly = true)
    public void setIssueDetail(IssueVo issueVo, Issue issue, User user) {
        //  이슈 수정 권한을 갖고 있는지 확인
        if (this.checkHasPermission(issueVo, issueVo.getUserVos(), user, issueVo.getDepartmentVos())) {
            issueVo.setModifyPermissionCheck(Boolean.TRUE);
        }
 
        issueVo.setProjectVo(ConvertUtil.copyProperties(issue.getProject(), ProjectVo.class));
        issueVo.setIssueTypeVo(ConvertUtil.copyProperties(issue.getIssueType(), IssueTypeVo.class));
        IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(issue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
        issueStatusVo.setIssueStatusType(issue.getIssueStatus().getIssueStatusType().toString());
        issueVo.setIssueStatusVo(issueStatusVo);
        issueVo.setPriorityVo(ConvertUtil.copyProperties(issue.getPriority(), PriorityVo.class));
        issueVo.setSeverityVo(ConvertUtil.copyProperties(issue.getSeverity(), SeverityVo.class));
        this.setRegister(issue, issueVo);   //  등록자 정보 셋팅
        //this.setIssueUser(issue, issueVo);  //  담당자 정보 셋팅
        this.setIssueDepartment(issue, issueVo);  //  담당부서 정보 셋팅
        this.setAttachedFiles(issue, issueVo);  //  첨부 파일 정보 셋팅
        this.setIssueCustomFields(issue, issueVo);  //  사용자 정의 필드 값 정보 셋팅
        this.setRelationIssue(issue, issueVo);        //연관 일감 셋팅
        this.setDownIssues(issue, issueVo); //하위 일감 세팅
        this.setIssueComments(issue, issueVo);  //  댓글 정보 셋팅
        this.setIssueHistory(issue, issueVo);   //  이슈 기록 정보 셋팅
 
        IssueType issueType = this.issueTypeService.getIssueType(issueVo.getIssueTypeVo().getId()); // 이슈의 이슈유형 객체
        Integer using = issueType.getUsePartner() != null ? issueType.getUsePartner().intValue() : 0; // 이슈유형별로 사용중인 업체/ISP/호스팅 값
 
        List<UsePartnerVo> usePartnerVos = Lists.newArrayList();
        for (Integer usePartner : UsePartner.partners) { //1(업체), 2(ISP), 4(호스팅)
            UsePartnerVo usePartnerVo = UsePartner.checkUsePartner(using, usePartner);
 
            if (usePartnerVo != null) {
                usePartnerVos.add(usePartnerVo);
                //useCompanyVo.setValues();
            }
            issueVo.setUsePartnerVos(usePartnerVos);
        }
 
        this.setIssueCompanyField(issue, issueVo);  //업체 정보 세팅
        this.setIssueIspField(issue, issueVo);  //ISP 정보 세팅
        this.setIssueHostingField(issue, issueVo);  //HOSTING 정보 세팅
        this.setParentIssue(issue,issueVo); //상위 이슈 정보 세팅
    }
 
    //  상위일감 정보 추가
    private void setParentIssue(Issue issue, IssueVo issueVo) {
        if(issue.getParentIssue() != null){
            issueVo.setParentIssueVo(ConvertUtil.copyProperties(issue.getParentIssue(), IssueVo.class));
        }
    }
 
    //  등록자 정보 추가
    private void setRegister(List<IssueVo> issueVos) {
        for (IssueVo issueVo : issueVos) {
            //  사용자 패스워드를 삭제하고 사용자 계정을 복호화한다.
            issueVo.setRegisterVo(this.userService.removeSensitiveUser(issueVo.getRegisterId()));
        }
    }
 
    //  이슈 등록자 정보를 셋팅한다.
    private void setRegister(Issue issue, IssueVo issueVo) {
        UserVo userVo = this.userService.removeSensitiveUser(issue.getRegisterId());
        issueVo.setRegisterVo(userVo);
 
        //  등록자는 항상 수정 가능.
        if (userVo.getId().equals(this.webAppUtil.getLoginId())) {
            issueVo.setModifyPermissionCheck(Boolean.TRUE);
        }
    }
 
    // 연관 이슈 정보를 셋팅한다
    private void setRelationIssue(Issue issue, IssueVo issueVo) {
        //Set<IssueRelation> issueRelations = issue.getIssueRelations();
 
        List<Map<String, Object>> results = this.issueRelationMapper.findByIssueId(issueVo);
        Long totalCount = this.issueRelationMapper.count(issueVo);
 
        if (issue != null && issueVo != null && results.size() > 0) {
            int totalPage = (int) Math.ceil((totalCount - 1) / issueVo.getRelPageSize()) + 1;
            issueVo.setRelTotalPage(totalPage);
            issueVo.setRelTotalCount(totalCount);
            for (Map<String, Object> result : results) {
                IssueRelationVo issueRelationVo = ConvertUtil.convertMapToClass(result, IssueRelationVo.class);
                Issue relationIssue = this.findOne(MapUtil.getLong(result, "relationIssueId"));
                IssueVo relIssueVo = ConvertUtil.copyProperties(relationIssue, IssueVo.class);
                Project project = this.projectService.getProject(relationIssue.getProject().getId());
                relIssueVo.setProjectId(project.getId());
                relIssueVo.setProjectKey(project.getProjectKey());
                relIssueVo.setIssueNumber(relationIssue.getIssueNumber());
 
                issueRelationVo.setIssueRelation(relIssueVo);
                issueRelationVo.setTitle(relationIssue.getTitle());
                issueRelationVo.setIssueTypeVo(ConvertUtil.copyProperties(relationIssue.getIssueType(), IssueTypeVo.class));
                issueRelationVo.setPriorityVo(ConvertUtil.copyProperties(relationIssue.getPriority(), PriorityVo.class));
                issueRelationVo.setSeverityVo(ConvertUtil.copyProperties(relationIssue.getSeverity(), SeverityVo.class));
                //이슈 상태 추가
                IssueStatusVo issueStatusVo = ConvertUtil.copyProperties(relationIssue.getIssueStatus(), IssueStatusVo.class, "issueStatusType");
                issueStatusVo.setIssueStatusType(relationIssue.getIssueStatus().getIssueStatusType().toString());
                issueRelationVo.setIssueStatusVo(issueStatusVo);
 
                issueRelationVo.setModifyPermissionCheck(issueVo.getModifyPermissionCheck());
 
                this.setRegister(relationIssue, relIssueVo); // 등록자
                this.setIssueDepartment(relationIssue, relIssueVo);  //  담당부서 정보 셋팅
                this.setIssueCustomFields(relationIssue, relIssueVo);   // 사용자정의필드 정보 세팅
 
                Set<IssueCompany> issueCompanies = relationIssue.getIssueCompanies();
                Iterator<IssueCompany> itrCompany = issueCompanies.iterator();
                while (itrCompany.hasNext()) {
                    issueRelationVo.addIssueCompanyVo(ConvertUtil.copyProperties(itrCompany.next(), IssueCompanyVo.class));
                }
 
                Set<IssueIsp> issueIsps = relationIssue.getIssueIspFields();
                Iterator<IssueIsp> itrIsp = issueIsps.iterator();
                while (itrIsp.hasNext()) {
                    issueRelationVo.addIssueIspVo(ConvertUtil.copyProperties(itrIsp.next(), IssueIspVo.class));
                }
 
                Set<IssueHosting> issueHostings = relationIssue.getIssueHostingFields();
                Iterator<IssueHosting> itrHosting = issueHostings.iterator();
                while (itrHosting.hasNext()) {
                    issueRelationVo.addIssueHostingVo(ConvertUtil.copyProperties(itrHosting.next(), IssueHostingVo.class));
                }
 
                issueVo.addIssueRelationVo(issueRelationVo);
            }
        } else {
            issue.clearIssueRelations();
        }
    }
 
    //  이슈 담당자 정보를 셋팅한다.
    /*private void setIssueUser(Issue issue, IssueVo issueVo) {
        List<UserVo> userVos = Lists.newArrayList();
 
        for (IssueUser issueUser : issue.getIssueUsers()) {
            UserVo userVo = ConvertUtil.copyProperties(issueUser.getUser(), UserVo.class, "password");
            userVo.setByName(userVo.getName() + "(" + CommonUtil.decryptAES128(userVo.getAccount()) + ")");
            userVo.setAccount(CommonUtil.decryptAES128(userVo.getAccount()));
            userVos.add(userVo);
            //  담당자가 있을 경우 담당자만 수정 가능.
            if (userVo.getId().equals(this.webAppUtil.getLoginId())) {
                issueVo.setModifyPermissionCheck(Boolean.TRUE);
            }
        }
 
        //  스케쥴러에서 실행될 경우 오류 발생하므로 권한 체크하지 않는다.
        if (this.webAppUtil.getLoginId() != null) {
            //  업무 공간 관리자일 경우 수정 권한을 갖는다.
            if (this.userWorkspaceService.checkWorkspaceManager()) {
                issueVo.setModifyPermissionCheck(Boolean.TRUE);
            }
 
            //  프로젝트 관리자일 경우 해당 프로젝트에 등록된 이슈는 수정 권한을 갖는다.
            if (this.projectRoleUserService.checkProjectManager(issue.getProject())) {
                issueVo.setModifyPermissionCheck(Boolean.TRUE);
            }
        }
 
        //  담당자가 없으면 모든 사용자가 수정 가능.
        if (issue.getIssueUsers().size() < 1) {
            issueVo.setModifyPermissionCheck(Boolean.TRUE);
        }
 
        issueVo.setUserVos(userVos);
    }*/
 
    //  이슈 담당부서 정보를 셋팅한다.
    private void setIssueDepartment(Issue issue, IssueVo issueVo) {
        List<DepartmentVo> departmentVos = Lists.newArrayList();
 
        for (IssueDepartment issueDepartment : issue.getIssueDepartments()) {
            DepartmentVo departmentVo = ConvertUtil.copyProperties(issueDepartment.getDepartment(), DepartmentVo.class);
            departmentVo.setByName(departmentVo.getDepartmentName());
            departmentVos.add(departmentVo);
 
            List<UserDepartment> userDepartments = this.userDepartmentRepository.findByDepartmentId(departmentVo.getId());
            if (userDepartments != null && userDepartments.size() > 0) {
                for (UserDepartment userDepartment : userDepartments) {
                    if (userDepartment.getUserId().equals(this.webAppUtil.getLoginId())){
                        issueVo.setModifyPermissionCheck(Boolean.TRUE);
                    }
                }
            }
        }
        issueVo.setDepartmentVos(departmentVos);
    }
 
    //  이슈 첨부파일 정보를 셋팅한다.
    private void setAttachedFiles(Issue issue, IssueVo issueVo) {
        List<AttachedFileVo> attachedFileVos = Lists.newArrayList();
 
        for (AttachedFile attachedFile : issue.getAttachedFiles()) {
            AttachedFileVo attachedFileVo = ConvertUtil.copyProperties(attachedFile, AttachedFileVo.class, "fileType");
            attachedFileVo.setFileType(attachedFile.getFileType().toString());
            attachedFileVos.add(attachedFileVo);
        }
 
        issueVo.setAttachedFileVos(attachedFileVos);
    }
 
    //  이슈(이슈 유형)에 연결된 사용자 정의 필드 정보를 셋팅한다.
    private IssueVo setIssueCustomFields(Issue issue, IssueVo issueVo) {
 
        //  해당 프로젝트의 이슈 유형에 연결된 사용자 정의 필드 정보를 가져온다.
        IssueTypeCustomFieldCondition issueTypeCustomFieldCondition = new IssueTypeCustomFieldCondition();
        issueTypeCustomFieldCondition.setProjectId(issue.getProject().getId());
        issueTypeCustomFieldCondition.setIssueTypeId(issue.getIssueType().getId());
        List<IssueTypeCustomFieldVo> issueTypeCustomFieldVos = this.issueTypeCustomFieldService.findIssueTypeCustomField(new HashMap<>(), issueTypeCustomFieldCondition);
        issueVo.setIssueTypeCustomFieldVos(issueTypeCustomFieldVos);
 
        //  이슈에서 사용된 사용자 정의 필드 값을 가져온다.
        List<IssueCustomFieldValueVo> issueCustomFieldValueVos = this.issueCustomFieldValueService.findByIssueId(issue.getId());
        issueVo.setIssueCustomFieldValueVos(issueCustomFieldValueVos);
 
        return issueVo;
    }
 
    //  이슈에 등록된 댓글 정보를 셋팅한다.
    private void setIssueComments(Issue issue, IssueVo issueVo) {
        issueVo.setIssueCommentVos(this.issueCommentService.findIssueComment(issue.getId()));
    }
 
    //  이슈 기록 정보를 셋팅한다.
    private void setIssueHistory(Issue issue, IssueVo issueVo) {
        issueVo.setIssueHistoryVos(this.issueHistoryService.findIssueHistory(issue));
    }
 
    // 사용자 정의 필드 값이 같은 이슈 찾기
    @Override
    @Transactional
    public List<Issue> findIssue(IssueApiForm issueApiform) {
 
        List<IssueCustomFieldValueForm> issueCustomFieldValueForms = issueApiform.getIssueCustomFieldValues();
        List<Issue> resultIssueVos = Lists.newArrayList();
        String comma = ",";
 
        List<String> userValues = Lists.newArrayList();
        if (issueCustomFieldValueForms.size() > 0) {
            IssueCustomFieldValueFormComparator comp = new IssueCustomFieldValueFormComparator();
            Collections.sort(issueCustomFieldValueForms, comp);
 
            String concatUseValue = "";
            for (int i = 0; i < issueCustomFieldValueForms.size(); i++) {
                IssueCustomFieldValueForm issueCustomFieldValueForm = issueCustomFieldValueForms.get(i);
                userValues.add(issueCustomFieldValueForm.getUseValue());
                if (i > 0) {
                    concatUseValue = concatUseValue.concat(comma);
                }
                concatUseValue = concatUseValue.concat(issueCustomFieldValueForm.getUseValue());
            }
 
            IssueCustomFieldValueCondition issueCustomFieldValueCondition = new IssueCustomFieldValueCondition();
            issueCustomFieldValueCondition.setUseValue(concatUseValue);
            issueCustomFieldValueCondition.setUseValues(userValues);
            issueCustomFieldValueCondition.setIssueTypeId(issueApiform.getIssueTypeId());
            issueCustomFieldValueCondition.setIssueStatusType("CLOSE");
            List<Map<String, Object>> results = this.issueMapper.findByCustomFieldValue(issueCustomFieldValueCondition);
            if (results != null && results.size() > 0) {
                for (Map<String, Object> result : results) {
                    resultIssueVos.add(this.getIssue(MapUtil.getLong(result, "id")));
                }
            }
        }
 
        return resultIssueVos;
    }
 
    // 리스트에서 해당 아이디를 가지고 있는 이슈 검색
    private IssueVo findIssueVo(List<IssueVo> list, Long id) {
        for (IssueVo issueVo : list) {
            if (id.equals(issueVo.getId())) {
                return issueVo;
            }
        }
        return null;
    }
 
 
    // 이슈를 수정한다(api용)
    @Override
    @Transactional
    public List<Issue> modifyIssue(IssueApiForm issueApiForm, List<MultipartFile> files) {
        User user = this.convertToUser(issueApiForm.getToken());
        IssueForm issueForm = this.convertToIssueForm(issueApiForm, user);
 
        List<Issue> issue = this.findIssue(issueApiForm);
        if (issue != null && issue.size() > 0) {
            List<Issue> issues = Lists.newArrayList();
            for (Issue issueVo : issue) {
                issueForm.setId(issueVo.getId());
                issueForm.setTitle(issueVo.getTitle());
 
                // 자동 종료 상태 설정이 되어 있지 않으면 오류발생
                Issue modifyIssue = this.modifyIssueForApi(user, issueForm, files);
                Issue parentIssue = modifyIssue.getParentIssue();
                IssueType issueType = modifyIssue.getIssueType();
 
                Set<IssueTypeApiEndStatus> issueTypeApiEndStatuses = issueType.getIssueTypeApiEndStatuses();
                IssueTypeApiEndStatus issueStatus = null;
                if (issueTypeApiEndStatuses != null && issueTypeApiEndStatuses.size() > 0) {
                    issueStatus = issueTypeApiEndStatuses.iterator().next();
                } else {
                    throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.API_COMPLETE_ISSUE_STATUS_NOT_EXIST));
                }
 
                if (parentIssue != null) {
 
                    IssueCondition issueCondition = new IssueCondition(issueVo.getId(), parentIssue.getId());
                    List<Map<String, Object>> results = this.issueMapper.findNotCompleteByParentIssueId(issueCondition);
                    // 하위 일감이 모두 종료 상태일때 상위 일감도 종료 처리
                    if (results == null || results.size() == 0) {
                        parentIssue.setIssueStatus(issueStatus.getIssueStatus());
                        this.issueRepository.saveAndFlush(parentIssue);
                    }
                }
 
                issues.add(modifyIssue);
            }
            return issues;
        } else {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.API_ISSUE_NOT_EXIST));
        }
    }
 
    //  이슈를 수정한다.
    @Override
    @Transactional
    public Issue modifyIssue(IssueForm issueForm, List<MultipartFile> multipartFiles) {
        User user = this.webAppUtil.getLoginUserObject();
        return modifyIssue(user, issueForm, multipartFiles);
    }
 
    // 수정 데이터가 유효한지 확인
    private CheckIssueData checkIssue(User user, IssueForm issueForm) {
 
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace(user, user.getLastWorkspaceId());
 
        Issue issue = this.getIssue(issueForm.getId());
        IssueStatus oldIssueStatus = issue.getIssueStatus();
        //  이슈 수정 권한 체크
        this.verifyIssueModifyPermission(issue, user);
        //  프로젝트 유효성 체크
        Project project = this.projectService.getProject(issueForm.getProjectId());
        //  이슈 상태 유효성 체크
        IssueStatus issueStatus = this.issueStatusService.getIssueStatus(issueForm.getIssueStatusId());
        //  이슈 유형 유효성 체크
        IssueType issueType = this.issueTypeService.getIssueType(issueForm.getIssueTypeId());
        //  우선순위 유효성 체크
        Priority priority = this.priorityService.getPriority(issueForm.getPriorityId());
        //  중요도 유효성 체크
        Severity severity = this.severityService.getSeverity(issueForm.getSeverityId());
        //  제목 유효성 체크
        this.verifyTitle(issueForm.getTitle());
        //  날짜 유효성 체크
        this.checkStartCompleteDate(issueForm.getStartDate(), issueForm.getCompleteDate());
 
        //  담당자 유효성 체크
        //this.verifyIssueAssignee(project, issueForm);
        //  담당부서 유효성 체크
        //this.verifyIssueDepartment(project, issueForm);
 
        CheckIssueData checkIssueData = new CheckIssueData();
        checkIssueData.setIssue(issue);
        checkIssueData.setProject(project);
        checkIssueData.setOldIssueStatus(oldIssueStatus);
        checkIssueData.setNewIssueStatus(issueStatus);
        checkIssueData.setIssueType(issueType);
        checkIssueData.setPriority(priority);
        checkIssueData.setSeverity(severity);
 
        return  checkIssueData;
    }
 
    // 이슈 수정(API용)
    private Issue modifyIssueForApi(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
        CheckIssueData checkIssueData = this.checkIssue(user, issueForm);
 
        if (issueForm.getComment() != null && !issueForm.getComment().equals("")) { //댓글 추가
            IssueCommentForm issueCommentForm = new IssueCommentForm();
            issueCommentForm.setDescription(issueForm.getComment());
            issueCommentForm.setIssueId(issueForm.getId());
            this.issueCommentService.addIssueComment(issueCommentForm, user);
        }
 
        // 이슈 이력 남기기
        this.addIssueHistoryModify(user, issueForm, checkIssueData, multipartFiles);
 
        // db에 저장
        return this.saveIssue(issueForm, checkIssueData);
    }
 
    private void addIssueHistoryModify(User user, IssueForm issueForm, CheckIssueData checkIssueData, List<MultipartFile> multipartFiles) {
        //  변경 이력 정보 추출
        StringBuilder detectIssueChange = this.issueHistoryService.detectIssueChange(issueForm, checkIssueData, multipartFiles);
 
        //  프로젝트가 변경되면 이슈 넘버를 새로 따야 한다.
        this.checkChangeProject(checkIssueData.getProject(), checkIssueData.getIssue());
 
        //  이슈 유형이 변경되었는지 확인하고 변경되었다면 이슈 상태 속성이 '대기' 인 이슈 상태로 교체한다.
        if (this.checkChangeIssueType(checkIssueData.getIssueType(), checkIssueData.getNewIssueStatus(), checkIssueData.getIssue())) {
            checkIssueData.setNewIssueStatus(this.issueStatusService.findByIssueStatusTypeIsReady(checkIssueData.getIssueType().getWorkflow()));
            //  이슈 상태 변경 이력 남기기 - 이력을 남기기 위해 issueForm 에 issueStatus Id 값을 저장.
            issueForm.setIssueStatusId(checkIssueData.getNewIssueStatus().getId());
            this.issueHistoryService.detectIssueStatus(checkIssueData.getIssue(), issueForm, detectIssueChange, checkIssueData.getOldIssueStatus(), checkIssueData.getNewIssueStatus());
        }
 
        // db에 저장
//        checkIssueData.setIssue(this.saveIssue(issueForm, checkIssueData));
 
        //  이슈 이력 등록
        if (!StringUtils.isEmpty(detectIssueChange.toString())) {
            this.issueHistoryService.addIssueHistory(checkIssueData.getIssue(), user, IssueHistoryType.MODIFY, detectIssueChange.toString());
        }
        //  사용자 시스템 기능 사용 정보 수집
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_MODIFY));
    }
 
 
 
    private Issue saveIssue(IssueForm issueForm, CheckIssueData checkIssueData) {
        Issue issue = checkIssueData.getIssue();
        ConvertUtil.copyProperties(issueForm, issue, "id");
        issue.setProject(checkIssueData.getProject());
        issue.setIssueStatus(checkIssueData.getNewIssueStatus());
        issue.setIssueType(checkIssueData.getIssueType());
        issue.setPriority(checkIssueData.getPriority());
        issue.setSeverity(checkIssueData.getSeverity());
        issue.setStartDate(issueForm.getStartDate());
        issue.setCompleteDate(issueForm.getCompleteDate());
 
        return this.issueRepository.saveAndFlush(issue);
    }
 
    //  이슈를 수정한다.
    @Override
    @Transactional
    public Issue modifyIssue(User user, IssueForm issueForm, List<MultipartFile> multipartFiles) {
        CheckIssueData checkIssueData = this.checkIssue(user, issueForm);
 
        Issue issue = checkIssueData.getIssue();
        IssueStatus oldIssueStatus = checkIssueData.getOldIssueStatus();
        Project project = checkIssueData.getProject();
        IssueStatus issueStatus = checkIssueData.getNewIssueStatus();
        IssueType issueType = checkIssueData.getIssueType();
 
        //  변경 이력 정보 추출
        StringBuilder detectIssueChange = this.issueHistoryService.detectIssueChange(issueForm, checkIssueData, multipartFiles);
 
        //  프로젝트가 변경되면 이슈 넘버를 새로 따야 한다.
        this.checkChangeProject(project, issue);
 
        //  이슈 유형이 변경되었는지 확인하고 변경되었다면 이슈 상태 속성이 '대기' 인 이슈 상태로 교체한다.
        if (this.checkChangeIssueType(issueType, issueStatus, issue)) {
            issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
            //  이슈 상태 변경 이력 남기기 - 이력을 남기기 위해 issueForm 에 issueStatus Id 값을 저장.
            issueForm.setIssueStatusId(issueStatus.getId());
            this.issueHistoryService.detectIssueStatus(issue, issueForm, detectIssueChange, oldIssueStatus, issueStatus);
        }
 
        issue = this.saveIssue(issueForm, checkIssueData);
        //this.issueUserService.modifyIssueUser(issue, project.getWorkspace(), issueForm.getUserIds());
        //  담당부서 지정
        if(issueForm.getDepartmentIds().size()>0){
            this.issueDepartmentService.modifyIssueDepartment(issue, user, project.getWorkspace(), issueForm.getDepartmentIds());
        }
 
        //  multipartFile 을 file Map List 객체로 변경한다.
        List<Map<String, Object>> convertFileMaps = this.convertMultipartFileToFile(multipartFiles);
 
        //  첨부 파일 저장 - 비동기로 작동
        this.attachedFileService.addAttachedFile(convertFileMaps, issue, user.getAccount());
        //  삭제된 첨부파일 처리
        this.attachedFileService.removeAttachedFiles(issueForm.getRemoveFiles());
        //  텍스트 에디터에 첨부한 파일을 이슈와 연결
        this.checkNotHaveIssueIdAttachedFile(issue, issueForm);
        //  사용자 정의 필드 저장
        this.issueCustomFieldValueService.modifyIssueCustomFieldValue(issue, issueForm.getIssueCustomFields());
        //  사용자 시스템 기능 사용 정보 수집
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class);
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(userVo, ElasticSearchConstants.ISSUE_MODIFY));
 
        //  업체 정보 저장
        this.issueCompanyService.modifyIssueCompanyField(issue, issueForm, detectIssueChange);
        //  ISP 정보 저장
        this.issueIspService.modifyIssueIspField(issue, issueForm, detectIssueChange);
        //  HOSTING 정보 저장
        this.issueHostingService.modifyIssueHostingField(issue, issueForm, detectIssueChange);
 
        //  파트너정보 하위이슈 상속
        List<Issue> downIssues = this.issueRepository.findByParentIssueId(issue.getId());
        if (issueForm.getInheritYn() != null && issueForm.getInheritYn()
                && downIssues != null && downIssues.size() > 0) {
            for (Issue downIssue : downIssues) {
                this.inheritPartners(downIssue, issue);
            }
        }
 
        //  이슈 이력 등록
        if (!StringUtils.isEmpty(detectIssueChange.toString())) {
            this.issueHistoryService.addIssueHistory(issue, user, IssueHistoryType.MODIFY, detectIssueChange.toString());
        }
 
        return issue;
    }
 
    //  multipartFile 을 file Map 객체로 변경한다.
    private List<Map<String, Object>> convertMultipartFileToFile(List<MultipartFile> multipartFiles) {
        List<Map<String, Object>> convertFileMaps = Lists.newArrayList();
 
        if (multipartFiles != null && multipartFiles.size() > 0) {
            for (MultipartFile multipartFile : multipartFiles) {
                try {
                    Map<String, Object> fileMap = CommonUtil.makeFileMap(multipartFile);
                    convertFileMaps.add(fileMap);
                } catch (Exception e) {
                    log.debug("multipartFile -> file 변환 오류" + e.getMessage());
                }
            }
        }
 
        return convertFileMaps;
    }
 
    //  프로젝트가 변경되었는지 확인한다.
    private void checkChangeProject(Project newProject, Issue issue) {
        if (!issue.getProject().getId().equals(newProject.getId())) {
            //  각 프로젝트의 고유 이슈 번호 생성
            issue.setIssueNumber(this.issueNumberGeneratorService.generateIssueNumber(newProject));
        }
    }
 
    //  이슈 유형이 변경되었는지 확인하고 변경되었으면 이슈 상태를 대기 속성인 이슈 상태로 셋팅한다.
    private Boolean checkChangeIssueType(IssueType newIssueType, IssueStatus issueStatus, Issue issue) {
        if (!issue.getIssueType().getId().equals(newIssueType.getId())) {
            //  이슈 상태를 선택하지 않았을 때
            if (issueStatus == null) {
                return true;
            }
 
            //  이슈 상태의 속성이 '대기' 가 아닌 경우
            if (!issueStatus.getIssueStatusType().equals(IssueStatusType.READY)) {
                return true;
            } else {
                //  변경하는 이슈 유형의 워크플로우에 존재하는 상태 속성 '대기'와 동일한 상태인지 확인
                IssueStatus newReadyIssueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(newIssueType.getWorkflow());
 
                if (!newReadyIssueStatus.getId().equals(issueStatus.getId())) {
                    return true;
                }
 
            }
        }
 
        return false;
    }
 
    //  이슈 담당부서로 지정될 부서가 해당 프로젝트에 참여 하고 있는 부서인지 확인
    private void verifyIssueDepartment(Project project, IssueForm issueForm) {
        if (issueForm.getDepartmentIds().size() > 0) {
            List<Long> trustDepartmentIds = Lists.newArrayList(); //  참여 확인된 부서
 
            for (Long departmentId : issueForm.getDepartmentIds()) {
                boolean includeProject = false;
 
                for (ProjectRole projectRole : project.getProjectRoles()) {
                    ProjectRoleDepartment projectRoleDepartment = this.projectRoleDepartmentService.findByProjectRoleIdAndDepartmentId(projectRole.getId(), departmentId);
 
                    if (projectRoleDepartment != null) {
                        includeProject = true;
                        trustDepartmentIds.add(departmentId);
                        break;
                    }
                }
 
                //  데이터 보정 작업 - 프로젝트에서 제외된 사용자는 담당자에서 제외 될 수 있도록 처리
                if (!includeProject) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.PROJECT_NOT_INCLUDE_DEPARTMENT));
                }
            }
            //  참여 확인된 부서로 담당부서 변경
            issueForm.setDepartmentIds(trustDepartmentIds);
        }
    }
 
    //  이슈 담당자로 지정될 사용자가 해당 프로젝트에 참여 하고 있는 사용자 인지 확인
    private void verifyIssueAssignee(Project project, IssueForm issueForm) {
        if (issueForm.getUserIds().size() > 0) {
            List<Long> trustUserIds = Lists.newArrayList(); //  참여 확인된 사용자
 
            for (Long userId : issueForm.getUserIds()) {
                boolean includeProject = false;
 
                for (ProjectRole projectRole : project.getProjectRoles()) {
                    ProjectRoleUser projectRoleUser = this.projectRoleUserService.findByProjectRoleIdAndUserId(projectRole.getId(), userId);
 
                    if (projectRoleUser != null) {
                        includeProject = true;
                        trustUserIds.add(userId);
                        break;
                    }
                }
 
                //  데이터 보정 작업 - 프로젝트에서 제외된 사용자는 담당자에서 제외 될 수 있도록 처리
                if (!includeProject) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.PROJECT_NOT_INCLUDE_USER));
                }
            }
            //  참여 확인된 사용자로 담당자 변경
            issueForm.setUserIds(trustUserIds);
        }
    }
 
    //  이슈 수정 권한 체크
    private void verifyIssueModifyPermission(Issue issue, User user) {
        //  이슈 수정 권한을 갖고 있는지 확인
        if (!this.checkHasPermission(ConvertUtil.copyProperties(issue, IssueVo.class), this.getIssueUserVos(issue), user, this.getIssueDepartmentVos(issue))) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_MODIFY_PERMISSION));
        }
    }
 
    //  이슈에서 담당자 정보를 추출한다.
    private List<UserVo> getIssueUserVos(Issue issue) {
        List<UserVo> userVos = Lists.newArrayList();
 
        Set<IssueUser> issueUsers = issue.getIssueUsers();
 
        try {
            for (IssueUser issueUser : issueUsers) {
                User user = issueUser.getUser();
                UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class, "password");
                userVos.add(userVo);
            }
        } catch (Exception ex) {
 
        }
 
        return userVos;
    }
 
    //  이슈에서 담당자 정보를 추출한다.
    private List<DepartmentVo> getIssueDepartmentVos(Issue issue) {
        List<DepartmentVo> departmentVos = Lists.newArrayList();
 
        Set<IssueDepartment> issueDepartments = issue.getIssueDepartments();
 
        try {
            for (IssueDepartment issueDepartment : issueDepartments) {
                Department department = issueDepartment.getDepartment();
                DepartmentVo departmentVo = ConvertUtil.copyProperties(department, DepartmentVo.class);
                departmentVos.add(departmentVo);
            }
        } catch (Exception ex) {
 
        }
 
        return departmentVos;
    }
 
    //  이슈 수정 권한을 갖고 있는지 확인
    private boolean checkHasPermission(IssueVo issueVo, List<UserVo> issueUserVos, User user, List<DepartmentVo> departmentVos) {
        boolean hasPermission = false;
 
        //  업무 공간 관리자일 경우 수정 권한을 갖는다.
        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.WORKSPACE_MANAGER, issueVo, null, null, user);
        //  프로젝트 관리자일 경우 해당 프로젝트에 등록된 이슈는 수정 권한을 갖는다.
        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.PROJECT_MANAGER, issueVo, null, null, user);
        //  이슈 관리자일 경우 수정 권한을 갖는다.
        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ISSUE_MANAGER, issueVo, null, null, user);
        //   이슈 등록자일 경우 수정 권한을 갖는다.
        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.REGISTER, issueVo, null, null, user);
        //  이슈 담당자일 경우 수정 권한을 갖는다.
        //hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ASSIGNEE, issueVo, issueUserVos);
        //  이슈 담당부서일 경우 수정 권한을 갖는다.
        hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.DEPARTMENT, issueVo, null, departmentVos, user);
        //  담당자가 없으면 모든 사용자가 수정 권한을 갖는다.
 
        //hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ALL_ISSUE_MANAGER, issueVo, null, null, user);
        //hasPermission = this.checkIssueModifyPermission(hasPermission, Issue.ALL_PROJECT_MANAGER, issueVo, null, null, user);
 
        return hasPermission;
    }
 
    //  이슈 수정 권한을 확인한다.
    private boolean checkIssueModifyPermission(Boolean hasPermission, String checkType, IssueVo issueVo, List<UserVo> issueUserVos, List<DepartmentVo> departmentVos, User user) {
        if (!hasPermission) {
            switch (checkType) {
                case Issue.WORKSPACE_MANAGER:  //  업무 공간 관리자
                    //  업무 공간 관리자일 경우 수정 권한을 갖는다.
                    hasPermission = this.userWorkspaceService.checkWorkspaceManager(user);
                    break;
 
                case Issue.PROJECT_MANAGER:    //  프로젝트 관리자
                    Issue issue = this.getIssue(issueVo.getId());
                    //  프로젝트 관리자일 경우 해당 프로젝트에 등록된 이슈는 수정 권한을 갖는다.
                    hasPermission = this.projectRoleUserService.checkProjectManager(issue.getProject(), user);
                    break;
 
                case Issue.ISSUE_MANAGER:    //  이슈 관리자
                    UserLevel userLevel = this.userLevelService.getUserLevel(user.getUserLevel().getId());
                    hasPermission = MngPermission.checkMngPermission(userLevel.getPermission(), MngPermission.USER_PERMISSION_MNG_ISSUE);
                    break;
 
                case Issue.REGISTER:   //  이슈 등록자
                    hasPermission = issueVo.getRegisterId().equals(user.getId());
                    break;
 
                case Issue.ASSIGNEE:
                    //  담당자가 없으면 모든 사용자가 수정 권한을 갖는다.
                    if (issueUserVos.size() < 1) {
                        hasPermission = true;
                        break;
                    }
                    //   이슈 담당자 여부 확인
                    for (UserVo issueUserVo : issueUserVos) {
                        if (issueUserVo.getId().equals(user.getId())) {
                            hasPermission = true;
                            break;
                        }
                    }
                    break;
 
                case Issue.DEPARTMENT:
                    //  담당부서가 없으면 모든 사용자가 수정 권한을 갖는다.
                    /*if (userDepartmentVos.size() < 1) {
                        hasPermission = true;
                        break;
                    }*/
                    //   이슈 담당부서 여부 확인
                    for (DepartmentVo departmentVo : departmentVos) {
                        List<UserDepartment> userDepartments = this.userDepartmentService.findByDepartmentId(departmentVo.getId());
                        if(userDepartments != null && userDepartments.size() > 0) {
                            for (UserDepartment userDepartment : userDepartments) {
                                if (userDepartment.getUserId().equals(user.getId())){
                                    hasPermission = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
            }
        }
 
        return hasPermission;
    }
 
    //  이슈 상태 변경
    @Override
    @Transactional
    public void modifyIssueStatus(IssueForm issueForm, User user) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
        //  변경 이력 정보 추출
        StringBuilder detectIssueChange = new StringBuilder();
        //  이슈 수정 권한 체크
        Issue issue = this.getIssue(issueForm.getId());
        IssueStatus oldIssueStatus = issue.getIssueStatus();
 
        this.verifyIssueModifyPermission(issue, user);
 
        IssueStatus issueStatus = this.issueStatusService.getIssueStatus(issueForm.getIssueStatusId());
 
        if (issueStatus.getIssueStatusType().toString().equals("CLOSE")) {
            List<String> downIssuesStatus = issueForm.getDownIssuesStatus();
            if (downIssuesStatus != null && downIssuesStatus.size() > 0) {
                for (String downIssueStatus : downIssuesStatus) {
                    if (!downIssueStatus.equals("CLOSE")) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_MODIFY_STATUS));
                    }
                }
            }
        }
 
        //  이슈 상태를 변경할 때 선택한 이슈 상태로 변경할 수 있는지 확인한다.
        this.issueStatusService.checkNextIssueStatus(issue, issueStatus);
        //  변경 이력 정보 추출
        this.issueHistoryService.detectIssueStatus(issue, issueForm, detectIssueChange, oldIssueStatus, issueStatus);
 
        issue.setIssueStatus(issueStatus);
        this.issueRepository.saveAndFlush(issue);
 
        //  코멘트 등록
        if (!StringUtils.isEmpty(issueForm.getComment())) {
            IssueCommentForm issueCommentForm = new IssueCommentForm();
            issueCommentForm.setIssueId(issue.getId());
            issueCommentForm.setDescription(issueForm.getComment());
            this.issueCommentService.addIssueComment(issueCommentForm);
        }
 
        //  이슈 이력 등록
        if (!StringUtils.isEmpty(detectIssueChange.toString())) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("<ul class=\"activity-list\">");
            stringBuilder.append(detectIssueChange.toString());
            stringBuilder.append("</ul>");
 
            this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, stringBuilder.toString());
        }
 
        //  이슈 버전 생성
        this.issueVersionService.addIssueVersion(issue);
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_STATUS_CHANGE));
    }
 
    //  이슈 담당자 변경
    @Override
    @Transactional
    public void modifyIssueUser(IssueForm issueForm) {
        User user = this.webAppUtil.getLoginUserObject();
 
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
        //  변경 이력 정보 추출
        StringBuilder detectIssueChange = new StringBuilder();
        //  이슈 수정 권한 체크
        Issue issue = this.getIssue(issueForm.getId());
        this.verifyIssueModifyPermission(issue, user);
        issue.setProject(this.projectService.getProject(issueForm.getProjectId()));
 
        //  변경 이력 정보 추출
        this.issueHistoryService.detectIssueManager(issue, issueForm, detectIssueChange);
 
        this.issueUserService.modifyIssueUser(issue, issue.getProject().getWorkspace(), issueForm.getDepartmentIds()); //getUserIds -> getDepartmentIds
        this.issueRepository.saveAndFlush(issue);
 
        //  이슈 이력 등록
        if (!StringUtils.isEmpty(detectIssueChange.toString())) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("<ul class=\"activity-list\">");
            stringBuilder.append(detectIssueChange.toString());
            stringBuilder.append("</ul>");
 
            this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, stringBuilder.toString());
        }
 
        //  이슈 버전 생성
        this.issueVersionService.addIssueVersion(issue);
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_USER_CHANGE));
    }
 
    @Override
    @Transactional
    public void modifyIssueDepartment(IssueForm issueForm) {
        User user = this.webAppUtil.getLoginUserObject();
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
        //  변경 이력 정보 추출
        StringBuilder detectIssueChange = new StringBuilder();
        //  이슈 수정 권한 체크
        Issue issue = this.getIssue(issueForm.getId());
        this.verifyIssueModifyPermission(issue, user);
        issue.setProject(this.projectService.getProject(issueForm.getProjectId()));
 
        //  변경 이력 정보 추출
        this.issueHistoryService.detectIssueDepartment(issue, issueForm, detectIssueChange);
 
        //this.issueUserService.modifyIssueUser(issue, issue.getProject().getWorkspace(), issueForm.getUserIds());
        this.issueDepartmentService.modifyIssueDepartment(issue, issue.getProject().getWorkspace(), issueForm.getDepartmentIds());
        this.issueRepository.saveAndFlush(issue);
 
        //  이슈 이력 등록
        if (!StringUtils.isEmpty(detectIssueChange.toString())) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("<ul class=\"activity-list\">");
            stringBuilder.append(detectIssueChange.toString());
            stringBuilder.append("</ul>");
 
            this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, stringBuilder.toString());
        }
 
        //  이슈 버전 생성
        this.issueVersionService.addIssueVersion(issue);
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_USER_CHANGE));
    }
 
    //  이슈를 삭제한다.
    @Override
    @Transactional
    public void removeIssues(IssueForm issueForm) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        User user = this.webAppUtil.getLoginUserObject();
        this.workspaceService.checkUseWorkspace();
 
        if (issueForm.getRemoveIds().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_REMOVE_NOT_SELECT));
        }
 
        List<Issue> removeIssues = Lists.newArrayList();
 
        for (Long issueId : issueForm.getRemoveIds()) {
            //하위이슈 체크
            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueId);
            if(downIssues != null && downIssues.size() > 0){
                for(Issue downIssue : downIssues){
                    if(downIssue.getParentIssue() != null){
                        downIssue.setParentIssue(null);
                    }
                }
            }
 
            Issue issue = this.issueRemoves(issueId, user);
            removeIssues.add(issue);
        }
 
        /*if (removeIssues.size() > 0) {
            this.issueRepository.deleteAll(removeIssues);
        }*/
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_REMOVE));
    }
 
    //  이슈를 삭제한다.
    @Override
    @Transactional
    public void removeAllIssues(IssueForm issueForm) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        User user = this.webAppUtil.getLoginUserObject();
        this.workspaceService.checkUseWorkspace();
 
        if (issueForm.getRemoveIds().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_REMOVE_NOT_SELECT));
        }
 
        Set<Long> removeIds = new HashSet<>();
 
        for (Long issueId : issueForm.getRemoveIds()) {
            removeIds.add(issueId);
            //하위이슈 체크
            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueId);
            if(downIssues != null && downIssues.size() > 0){
                for(Issue downIssue : downIssues){
                    Long downIssueId = downIssue.getId();
                    removeIds.add(downIssueId);
                }
            }
        }
 
        for (Long removeId : removeIds) {
            this.issueRemoves(removeId, user);
        }
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_REMOVE));
    }
 
    //  하위이슈를 삭제한다.
    @Override
    @Transactional
    public void removeDownIssues(IssueForm issueForm) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        User user = this.webAppUtil.getLoginUserObject();
        this.workspaceService.checkUseWorkspace();
 
        if (issueForm.getRemoveIds().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_REMOVE_NOT_SELECT));
        }
 
        List<Issue> removeIssues = Lists.newArrayList();
        Long downIssueId = 0L;
        for (Long issueId : issueForm.getRemoveIds()) {
            //삭제 할 이슈의 하위이슈 체크
            List<Issue> downIssues = this.issueRepository.findByParentIssueId(issueId);
            if(downIssues != null && downIssues.size() > 0){
                for(Issue downIssue : downIssues){
                    downIssueId = downIssue.getId();
                }
            }
            Issue issue = this.issueRemoves(downIssueId, user);
            removeIssues.add(issue);
        }
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_REMOVE));
    }
 
    private Issue issueRemoves(Long issueId, User user) {
        Issue issue = null;
        if(issueId != null){
            issue = this.getIssue(issueId);
        }
        //  이슈 수정 권한을 갖고 있는지 확인
        this.verifyIssueModifyPermission(issue, user);
 
        //  이슈 첨부 파일을 삭제한다.
        if (issue.getAttachedFiles().size() > 0) {
            List<Long> attachedFileIds = Lists.newArrayList();
 
            for (AttachedFile attachedFile : issue.getAttachedFiles()) {
                attachedFileIds.add(attachedFile.getId());
            }
            //  첨부파일 삭제
            this.attachedFileService.removeAttachedFiles(attachedFileIds);
        }
 
        // 지울 이슈가 연관이슈인지 체크 후 연관이슈 테이블에서도 삭제한다.
        List<IssueRelation> issueRelationList = this.issueRelationRepository.findByRelationIssueId(issueId);
        if (issueRelationList != null && issueRelationList.size() > 0) {
            for(IssueRelation issueRelation : issueRelationList){
                StringBuilder sb = new StringBuilder();
                issueHistoryService.detectRelationIssue(IssueHistoryType.DELETE, issueRelation, sb);
                issueHistoryService.addIssueHistory(issueRelation.getIssue(), IssueHistoryType.MODIFY, sb.toString());
                this.issueRelationRepository.delete(issueRelation);
            }
        }
 
        //  이슈 생성, 삭제시 예약 이메일에 등록해놓는다.
        this.reservationIssueEmail(issue, EmailType.ISSUE_REMOVE);
        //  이슈 삭제
        this.issueRepository.delete(issue);
 
        return issue;
    }
 
    @Override
    @Transactional(readOnly = true)
    public Issue getIssue(Long id) {
        if (id == null) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_EXIST));
        }
 
        Issue issue = this.findOne(id);
 
        if (issue == null) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_EXIST));
        }
 
        return issue;
    }
 
    //  이슈 유형을 사용하는 이슈 갯수를 조회한다.
    @Override
    @Transactional(readOnly = true)
    public long countByIssueTypeId(Long issueTypeId) {
        return this.issueMapper.countByIssueTypeId(issueTypeId);
    }
 
    //  이슈 상태를 사용하는 이슈 갯수를 조회한다.
    @Override
    @Transactional(readOnly = true)
    public long countByIssueStatus(Long issueStatusId) {
        return this.issueMapper.countByIssueStatusId(issueStatusId);
    }
 
    //  이슈 유형에서 워크플로우가 변경되었을 때 해당 워크플로우에 현재 이슈 상태가 존재하지 않으면 대기(생성) 로 변경한다.
    @Override
    @Transactional
    public void changeWorkflows(Workflow workflow, IssueType issueType) {
        List<Map<String, Object>> issueMaps = this.issueMapper.findByIssueTypeId(issueType.getId());
        List<IssueStatusVo> issueStatusVos = this.issueStatusService.findByWorkflowId(workflow.getId());
        IssueStatus readyIssueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(workflow);
        List<Issue> updateIssues = Lists.newArrayList();
 
        for (Map<String, Object> issueMap : issueMaps) {
            boolean exist = false;
 
            for (IssueStatusVo issueStatusVo : issueStatusVos) {
                Long issueStatusId = MapUtil.getLong(issueMap, "issueStatusId");
                if (issueStatusId == null) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.ISSUE_STATUS_NOT_EXIST));
                }
 
                if (issueStatusId.equals(issueStatusVo.getId())) {
                    exist = true;
                    break;
                }
            }
            //  존재하지 않는 대상은
            if (!exist) {
                StringBuilder stringBuilder = new StringBuilder();
                String issueStatusName = MapUtil.getString(issueMap, "issueStatusName");
                if (issueStatusName == null) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.ISSUE_STATUS_NOT_EXIST));
                }
 
                Issue issue = this.getIssue(MapUtil.getLong(issueMap, "issueId"));
 
                //  워크플로우에서 이슈 상태가 삭제되어 상태가 변경된 정보를 기록한다.
                this.issueHistoryService.recordRemoveWorkflowToIssueStatus(issueStatusName, readyIssueStatus.getName(), stringBuilder);
                this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, stringBuilder.toString());
 
                issue.setIssueStatus(readyIssueStatus);
                updateIssues.add(issue);
            }
        }
 
        if (updateIssues.size() > 0) {
            this.issueRepository.saveAll(updateIssues);
 
            for (Issue issue : updateIssues) {
                //  이슈 버전 생성
                this.issueVersionService.addIssueVersion(issue);
            }
        }
    }
 
    //  이슈 목록을 엑셀로 다운로드 한다.
    @Override
    @Transactional
    public ModelAndView downloadExcel(HttpServletRequest request, Model model) {
 
        //  사용 공간에서 로그인한 사용자가 비활성인지 확인하고 비활성일 경우 엑셀 다운로드를 금지한다.
        ModelAndView modelAndView = this.workspaceService.checkUseExcelDownload(model);
        if (modelAndView != null) {
            return modelAndView;
        }
 
        Map<String, Object> conditions = new HashMap<>();
        //  엑셀 다운로드에 필요한 검색 조건 정보를 추출하고 검색 조건 추출에 오류가 발생하면 경고를 표시해준다.
        modelAndView = this.excelConditionCheck.checkCondition(conditions, request, model);
        if (modelAndView != null) {
            return modelAndView;
        }
 
        IssueCondition issueCondition = IssueCondition.make(conditions);
        //  검색 조건을 만든다
        this.makeIssueSearchCondition(issueCondition, Lists.newArrayList("01", "02", "03"), null);
 
        Set<String> issueIds = new HashSet<>(); //  사용자 정의 필드 검색시 나오는 이슈 아이디 저장 컬렉션
        Map<String, Object> resJsonData = new HashMap<>();
 
        ExportExcelVo excelInfo = new ExportExcelVo();
        excelInfo.setFileName(this.messageAccessor.message("common.issueList")); // 이슈 목록
        excelInfo.addAttrInfos(new ExportExcelAttrVo("issueStatusName", this.messageAccessor.message("common.status"), 6, ExportExcelAttrVo.ALIGN_CENTER)); // 상태
        excelInfo.addAttrInfos(new ExportExcelAttrVo("issueKey", this.messageAccessor.message("common.issueKey"), 6, ExportExcelAttrVo.ALIGN_CENTER)); // 이슈 번호
        excelInfo.addAttrInfos(new ExportExcelAttrVo("title", this.messageAccessor.message("common.issueTitle"), 40, ExportExcelAttrVo.ALIGN_LEFT)); // 이슈 제목
        excelInfo.addAttrInfos(new ExportExcelAttrVo("description", this.messageAccessor.message("common.content"), 60, ExportExcelAttrVo.ALIGN_LEFT)); // 내용
        excelInfo.addAttrInfos(new ExportExcelAttrVo("issueTypeName", this.messageAccessor.message("common.issueType"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 이슈 타입
        excelInfo.addAttrInfos(new ExportExcelAttrVo("departments", this.messageAccessor.message("common.department"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 담당부서
        excelInfo.addAttrInfos(new ExportExcelAttrVo("priorityName", this.messageAccessor.message("common.priority"), 6, ExportExcelAttrVo.ALIGN_CENTER)); // 우선순위
        excelInfo.addAttrInfos(new ExportExcelAttrVo("severityName", this.messageAccessor.message("common.importance"), 6, ExportExcelAttrVo.ALIGN_CENTER)); // 중요도
        excelInfo.addAttrInfos(new ExportExcelAttrVo("register", this.messageAccessor.message("common.register"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 등록자
        excelInfo.addAttrInfos(new ExportExcelAttrVo("period", this.messageAccessor.message("common.period"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 기간
        excelInfo.addAttrInfos(new ExportExcelAttrVo("modifyDate", this.messageAccessor.message("common.modifyDate"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 최종 변경일
        excelInfo.addAttrInfos(new ExportExcelAttrVo("companyName", this.messageAccessor.message("common.company"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 업체
        excelInfo.addAttrInfos(new ExportExcelAttrVo("ispName", this.messageAccessor.message("common.isp"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // ISP
        excelInfo.addAttrInfos(new ExportExcelAttrVo("hostingName", this.messageAccessor.message("common.hosting"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 호스팅
 
 
        //  사용자 정의 필드를 사용한 이슈를 찾는다. 만약 이슈가 없다면 여기서 이슈 조회가 끝난다.
        if (!this.searchUseCustomFields(issueCondition, issueIds, resJsonData, null)) {
            model.addAttribute(Constants.EXCEL, excelInfo);
            return new ModelAndView(this.excelView);
        }
 
        List<IssueVo> issueVos = Lists.newArrayList();  //  이슈 목록 데이터 저장 컬렉션
        //  사용자 정의 필드로 검색한 이슈 아이디 값
        List<String> issueKeys = Lists.newArrayList(issueIds);
        issueCondition.setIssueIds(issueKeys);
 
        List<Map<String, Object>> results = this.issueMapper.find(issueCondition);
        //  엑셀 다운로드를 진행할 때 전체 사용자 정의 필드를 표시한다.
        this.makeIssueExcelDownloadCustomFields(excelInfo);
 
        //  이슈 아이디 초기화
        issueCondition.setIssueIds(Lists.newArrayList());
 
        //  Map 에 있는 데이터를 IssueVo 데이터로 변환한다.
        User user = this.webAppUtil.getLoginUserObject();
        this.setMapToIssueVo(results, issueVos, issueCondition, user);
 
        //  IssueVos 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
        List<Map<String, String>> convertExcelViewToIssueMaps = this.convertExcelViewToIssueVos(issueVos);
 
        if (results.size() > EXCEL_DOWNLOAD_MAX_ROWS) {
            //  엑셀 1만건 초과 알림
            this.simpMessagingTemplate.convertAndSendToUser(this.webAppUtil.getLoginUser().getAccount(), "/notification/system-alert", this.messageAccessor.getMessage(MsgConstants.EXCEL_DOWNLOAD_MAX_ROWS_OVER));
 
            //  1만 건만 출력해준다.
            excelInfo.setDatas(convertExcelViewToIssueMaps.subList(0, EXCEL_DOWNLOAD_MAX_ROWS));
            model.addAttribute(Constants.EXCEL, excelInfo);
            return new ModelAndView(this.excelView);
        }
 
        //  엑셀에 넣을 데이터 - IssueVos 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
        excelInfo.setDatas(convertExcelViewToIssueMaps);
 
        model.addAttribute(Constants.EXCEL, excelInfo);
        return new ModelAndView(this.excelView);
    }
 
    //  엑셀 다운로드를 진행할 때 전체 사용자 정의 필드를 표시한다.
    private void makeIssueExcelDownloadCustomFields(ExportExcelVo excelInfo) {
        List<CustomField> customFields = this.customFieldService.findByWorkspaceId();
 
        for (CustomField customField : customFields) {
            excelInfo.addAttrInfos(new ExportExcelAttrVo("customField_" + customField.getId(), customField.getName(), 10, ExportExcelAttrVo.ALIGN_CENTER));
        }
    }
 
    //  사용자 정의 필드 정보 추가
    private void setIssueCustomFieldValue(List<IssueVo> issueVos, IssueCondition issueCondition) {
        //  이슈에서 저장한 사용자 정의 필드 값을 조회한다.
        List<Map<String, Object>> issueCustomFieldValues = this.issueCustomFieldValueService.findInIssueIds(issueCondition);
 
        for (IssueVo issueVo : issueVos) {
            for (Map<String, Object> issueCustomFieldValue : issueCustomFieldValues) {
                int count = 0;
                Map<String, Object> useValues = new HashMap<>();
 
                if (issueVo.getId().equals(MapUtil.getLong(issueCustomFieldValue, "issueId"))) {
                    IssueCustomFieldValueVo issueCustomFieldValueVo = new IssueCustomFieldValueVo();
 
                    useValues.put("useValue"+count, MapUtil.getString(issueCustomFieldValue, "useValue"));
                    useValues.put("customFieldId", MapUtil.getLong(issueCustomFieldValue, "customFieldId"));
                    issueCustomFieldValueVo.setUseValues(useValues);
 
                    issueCustomFieldValueVo.setUseValue(MapUtil.getString(issueCustomFieldValue, "useValue"));
 
                    CustomFieldVo customFieldVo = new CustomFieldVo();
                    customFieldVo.setId(MapUtil.getLong(issueCustomFieldValue, "customFieldId"));
                    issueCustomFieldValueVo.setCustomFieldVo(customFieldVo);
                    issueVo.addIssueCustomFieldValueVo(issueCustomFieldValueVo);
                }
            }
        }
    }
 
    //  업체 정보 추가
    private void setIssueCompanyField(Issue issue, IssueVo issueVo) {
        List<IssueCompanyVo> issueCompanyVos = Lists.newArrayList();
 
        for(IssueCompany issueCompany : issue.getIssueCompanies()){
            IssueCompanyVo issueCompanyVo = ConvertUtil.copyProperties(issueCompany, IssueCompanyVo.class);
            issueCompanyVo.setId(issueCompany.getId());
            CompanyField companyField = issueCompany.getCompanyField();
            if (companyField != null) {
                issueCompanyVo.setCompanyId(issueCompany.getCompanyField().getId());
                if (issueCompany.getCompanyTypeId() != null && issueCompany.getCompanyTypeId() != -1) {
                    CompanyFieldCategory companyType = this.companyFieldCategoryService.find(issueCompany.getCompanyTypeId());
                    issueCompanyVo.setCompanyTypeName(companyType.getUseValue());
                }
                if (issueCompany.getParentSectorId() != null && issueCompany.getParentSectorId() != -1) {
                    CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(issueCompany.getParentSectorId());
                    issueCompanyVo.setParentSectorName(parentSector.getUseValue());
                }
                if (issueCompany.getChildSectorId() != null && issueCompany.getChildSectorId() != -1) {
                    CompanyFieldCategory childSector = this.companyFieldCategoryService.find(issueCompany.getChildSectorId());
                    issueCompanyVo.setChildSectorName(childSector.getUseValue());
                }
                if (issueCompany.getRegionId() != null && issueCompany.getRegionId() != -1) {
                    CompanyFieldCategory region = this.companyFieldCategoryService.find(issueCompany.getRegionId());
                    issueCompanyVo.setRegionName(region.getUseValue());
                }
                if (issueCompany.getStatusId() != null && issueCompany.getStatusId() != -1) {
                    if (issueCompany.getStatusName() != null && !issueCompany.getStatusName().equals("")) {
                        issueCompanyVo.setStatusName(issueCompany.getStatusName());
                    } else {
                        CompanyFieldCategory status = this.companyFieldCategoryService.find(issueCompany.getStatusId());
                        issueCompanyVo.setStatusName(status.getUseValue());
                    }
                }
            }
            issueCompanyVos.add(issueCompanyVo);
        }
        issueVo.setIssueCompanyVos(issueCompanyVos);
    }
 
    //  Isp 정보 추가
    private void setIssueIspField(Issue issue, IssueVo issueVo) {
        List<IssueIspVo> issueIspVos = Lists.newArrayList();
 
        for(IssueIsp issueIsp : issue.getIssueIspFields()){
            IssueIspVo issueIspVo = ConvertUtil.copyProperties(issueIsp, IssueIspVo.class);
            issueIspVo.setId(issueIsp.getId());
            IspField ispField = issueIsp.getIspField();
            if (ispField != null) {
                issueIspVo.setIspId(ispField.getId());
            }
            issueIspVos.add(issueIspVo);
        }
        issueVo.setIssueIspVos(issueIspVos);
    }
 
    // Hosting 정보 추가
    private void setIssueHostingField(Issue issue, IssueVo issueVo) {
        List<IssueHostingVo> issueHostingVos = Lists.newArrayList();
 
        for(IssueHosting issueHosting : issue.getIssueHostingFields()){
            IssueHostingVo issueHostingVo = ConvertUtil.copyProperties(issueHosting, IssueHostingVo.class);
            issueHostingVo.setId(issueHosting.getId());
            HostingField hostingField = issueHosting.getHostingField();
            if (hostingField != null) {
                issueHostingVo.setHostingId(hostingField.getId());
            }
 
            issueHostingVos.add(issueHostingVo);
        }
        issueVo.setIssueHostingVos(issueHostingVos);
    }
 
    //  연관일감 정보 추가
    private void setRelationIssue(IssueVo issueVo, Long issueId) {
        List<IssueVo> relationIssues = this.issueRelationService.findRelationIssue(issueId);
        issueVo.setIssueRelationIssueVos(relationIssues);
    }
 
    //  IssueVos 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
    private List<Map<String, String>> convertExcelViewToIssueVos(List<IssueVo> issueVos) {
        List<Map<String, String>> results = Lists.newArrayList();
 
        for (IssueVo issueVo : issueVos) {
            try {
                Map<String, String> result = new HashMap<>();
                result.put("issueStatusName", issueVo.getIssueStatusName());
                result.put("issueKey", issueVo.getProjectKey() + "-" + issueVo.getIssueNumber());
                result.put("title", issueVo.getTitle());
 
                String description = "";
 
                if (issueVo.getDescription() != null) {
                    description = Jsoup.parse(issueVo.getDescription()).text();   //  HTML 태그 제거
                    description = description.replaceAll("\\<.*?>", "");    //  공백 제거
                }
 
                result.put("description", description);
                result.put("issueTypeName", issueVo.getIssueTypeName());
                result.put("assignees", CommonUtil.convertUserVosToString(issueVo.getUserVos()));
                result.put("departments", CommonUtil.convertDepartmentVosToString(issueVo.getDepartmentVos()));
                result.put("priorityName", issueVo.getPriorityName());
                result.put("severityName", issueVo.getSeverityName());
                result.put("companyName", issueVo.getCompanyName());
                result.put("ispName", issueVo.getIspName());
                result.put("hostingName", issueVo.getHostingName());
 
                UserVo register = this.userService.removeSensitiveUser(issueVo.getRegisterId());
                //  등록자
                result.put("register", register.getByName());
                //  최종 변경일
                result.put("modifyDate", issueVo.getModifyDate());
 
                if (StringUtils.isEmpty(issueVo.getStartDate())) {
                    result.put("period", "");
                } else {
                    result.put("period", issueVo.getStartDate() + " ~ " + issueVo.getCompleteDate());
                }
 
                for (IssueCustomFieldValueVo issueCustomFieldValueVo : issueVo.getIssueCustomFieldValueVos()) {
                    //  사용자 정의 필드 값 저장이 아직 안되어 있는 경우
                    if (result.get("customField_" + issueCustomFieldValueVo.getCustomFieldVo().getId()) == null) {
                        result.put("customField_" + issueCustomFieldValueVo.getCustomFieldVo().getId().toString(), issueCustomFieldValueVo.getUseValue());
                    } else {
                        //  이미 저장되어 있으면 다중 선택 사용자 정의 필드 값이다.
                        String useValue = result.get("customField_" + issueCustomFieldValueVo.getCustomFieldVo().getId());
                        result.put("customField_" + issueCustomFieldValueVo.getCustomFieldVo().getId().toString(), useValue + ", " + issueCustomFieldValueVo.getUseValue());
                    }
                }
                results.add(result);
            } catch (Exception e) {
                log.error("엑셀 다운로드 오류 발생");
            }
        }
        return results;
    }
 
    //  이슈 다중 상태 변경
    @Override
    @Transactional
    public void modifyMultiIssueStatus(IssueForm issueForm) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
 
        User user = this.webAppUtil.getLoginUserObject();
 
        for (Long issueId : issueForm.getIds()) {
            issueForm.setId(issueId);
            //  이슈 상태 변경
            this.modifyIssueStatus(issueForm, user);
        }
 
        // 담당 부서 수정
        if (issueForm.getDepartmentIds().size() > 0) {
            Issue issue = this.getIssue(issueForm.getId());
            Project project = this.projectService.getProject(issueForm.getProjectId());
 
            this.issueDepartmentService.modifyIssueDepartment(issue, project.getWorkspace(), issueForm.getDepartmentIds());
        }
    }
 
    //  이슈 Import 용 엑셀 템플릿 다운로드
    @Override
    @Transactional
    public ModelAndView downloadExcelTemplate(HttpServletRequest request, Model model) {
        Map<String, Object> conditions;
 
        try {
            //  엑셀 다운로드에 필요한 검색 조건 정보를 추출한다.
            conditions = CommonUtil.getSearchConditions(request);
        } catch (IOException e) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EXCEL_CONDITIONS_NOT_EXIST));
        }
 
        ExportExcelVo excelInfo = new ExportExcelVo();
        excelInfo.setHideCount(true);
        excelInfo.setFileName(this.messageAccessor.message("common.registerExcelIssue")); // 엑셀로 이슈 등록하기
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.title"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // 제목
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.content"), 40, ExportExcelAttrVo.ALIGN_CENTER)); // 내용
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.priority"), 5, ExportExcelAttrVo.ALIGN_CENTER)); // 우선순위
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.importance"), 5, ExportExcelAttrVo.ALIGN_CENTER)); // 중요도
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.startDate"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 시작일
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.endDate"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 종료일
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.company"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 업체
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.isp"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // ISP
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("common.hosting"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 호스팅
        //  프로젝트에 연결된 사용자 정의 필드 정보를 추출하여 엑셀 download 템플릿을 만든다.
        this.makeIssueExcelTemplateCustomFields(excelInfo, conditions);
        //  엑셀에 넣을 데이터 - IssueVos 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
        excelInfo.setDatas(Lists.newArrayList(new IssueVo()));
 
        model.addAttribute(Constants.EXCEL, excelInfo);
        return new ModelAndView(this.excelView);
    }
 
    //  프로젝트에 연결된 사용자 정의 필드 정보를 추출하여 엑셀 download 템플릿을 만든다.
    private void makeIssueExcelTemplateCustomFields(ExportExcelVo excelInfo, Map<String, Object> conditions) {
        List<IssueTypeCustomField> issueTypeCustomFields = this.issueTypeCustomFieldService.findByProjectIdAndIssueTypeId(MapUtil.getLong(conditions, "projectId"), MapUtil.getLong(conditions, "issueTypeId"));
 
        for (IssueTypeCustomField issueTypeCustomField : issueTypeCustomFields) {
            excelInfo.addAttrInfos(new ExportExcelAttrVo("id", issueTypeCustomField.getCustomField().getName(), 10, ExportExcelAttrVo.ALIGN_CENTER));
        }
    }
 
    //  엑셀 import 로 이슈를 등록한다.
    @Override
    @Transactional
    public void importExcel(IssueForm issueForm, MultipartFile multipartFile) throws Exception {
        /*StopWatch serviceStart = new StopWatch();
        serviceStart.start();*/
 
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
 
        if (multipartFile != null) {
            //  업로드 파일 확장자 체크
            this.verifyMultipartFileExtension(multipartFile);
 
            Map<String, Priority> priorityMaps = new HashMap<>();   //  우선 순위 모음
            Map<String, Severity> severityMaps = new HashMap<>();   //  중요도 모음
            Map<String, DepartmentVo> departmentMaps = new HashMap<>(); //  부서 모음
            Map<String, CustomField> customFieldMaps = new HashMap<>();
            Map<Long, Long> issueNumberMaps = new HashMap<>();  //  이슈 번호 모음
            Map<String, Long> issueTypeCustomFieldMaps = new HashMap<>(); //  이슈 타입 + 사용자 정의 필드 연결 정보
 
            Map<String, CompanyField> companyFieldMaps = new HashMap<>();   //업체 모음
            Map<String, IspField> ispFieldMaps = new HashMap<>();   //isp 모음
            Map<String, HostingField> hostingFieldMaps = new HashMap<>();   //호스팅 모음
 
            Workspace workspace = this.workspaceService.getWorkspace(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId());  //  이슈를 넣으려는 업무 공간
            //  이슈의 주요 속성을 map 에 저장하여 엑셀 import 에서 지정한 대상(이슈 속성)을 빠르게 찾을 수 있게 한다.
            this.IssueAttributeMapToList(issueForm, priorityMaps, severityMaps, departmentMaps, customFieldMaps,
                    issueTypeCustomFieldMaps, companyFieldMaps, ispFieldMaps, hostingFieldMaps);
            //  0.237 - 0.230
 
            List<IssueForm> issueForms = Lists.newArrayList();
            List<String> headers = Lists.newArrayList();
 
            Workbook workbook;
 
            IssueType issueType = new IssueType();
            Workflow workflow = new Workflow();
 
            workbook = WorkbookFactory.create(multipartFile.getInputStream());
            Sheet sheet = workbook.getSheetAt(0);
            int lastRowNum = sheet.getLastRowNum() + 1;
 
            //  2건 - 제목, 헤더 - 성능을 위해 최대 1만건으로 제한
            if (lastRowNum > (EXCEL_IMPORT_MAX_ROWS + 2)) {
                throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_MAX_ROWS_OVER));
            }
 
            for (int rowIndex = 0; rowIndex < lastRowNum; rowIndex++) {
                //  0번은 헤더는 무시한다.
                Row row = sheet.getRow(rowIndex);
                //  헤더 정보를 추출한다 - 사용자 정의 필드 정보를 가져오기 위해
                if (rowIndex == 1) {
                    for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
                        Cell cell = row.getCell(cellIndex);
 
                        if (cell == null) {
                            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EXCEL_EMPTY_CELL));
                        }
 
                        //  엑셀 import 데이터에서 cell 값을 문자열로 변환한다.
                        String cellValue = CommonUtil.convertExcelStringToCell(cell);
 
                        if (StringUtils.isEmpty(cellValue)) {
                            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EXCEL_HEADER_EMPTY_CELL));
                        }
 
                        headers.add(cellValue);
                    }
                }
 
                //  1번 헤더부터 데이터 영역
                if (rowIndex > 1) {
                    //  이슈로 등록하기 위해 IssueForm 에 데이터를 셋팅한다.
                    IssueForm newIssueForm = this.setIssueFormToExcelField(row, (rowIndex + 1), priorityMaps, severityMaps, customFieldMaps,
                            companyFieldMaps, ispFieldMaps, hostingFieldMaps, headers);
                    ConvertUtil.copyProperties(issueForm, newIssueForm);
 
                    Project project = this.projectService.getProject(newIssueForm.getProjectId());
                    Long issueNumber = this.issueNumberGeneratorService.generateIssueNumber(project);
                    newIssueForm.setIssueNumber(issueNumber);
 
                    issueType = this.issueTypeService.getIssueType(newIssueForm.getIssueTypeId());
                    workflow = issueType.getWorkflow();
                    IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(workflow);
 
                    newIssueForm.setIssueStatusId(issueStatus.getId());
                    issueForms.add(newIssueForm);
                }
            }
 
            if (issueForms.size() < 1) {
                return;
            }
            //  1.176
 
            //  이슈 등록
            this.issueMapper.insertBatch(issueForms);
 
            for (IssueForm saveIssueForm : issueForms) {
                Issue issue = new Issue();
                ConvertUtil.copyProperties(saveIssueForm, issue);
 
                if (issueForm.getInheritYn() != null && issueForm.getInheritYn() && issueForm.getParentIssueId() != null) {
                    Issue parentIssue = this.getIssue(issueForm.getParentIssueId());
                    //  상위이슈의 파트너 정보 상속
                    this.inheritPartners(issue, parentIssue);
                }
 
                saveIssueForm.setId(issue.getId());
 
                //  워크플로우 대기 상태의 부서 추가
                List<Long> departmentsIds = this.workflowDepartmentService.findFirstDepartmentIds(workflow);
                if (departmentsIds != null && departmentsIds.size() > 0) {
                    this.issueDepartmentService.add(departmentsIds, workspace, issue);
                }
                this.setIssuePartners(saveIssueForm, issue);
            }
 
            //  0.416 - 0.439
 
            //  1.373 ~ 1.394
 
            //  TODO - 이슈 이력 벌크 등록을 할 경우 프로필 이력 조회에서 부하가 심해서 넣을지 고민해야함.
            //  this.bulkInsertIssueHistory(issueForms);
 
            //  이슈 담당자 벌크 등록
            this.bulkInsertIssueAssignee(issueForms, workspace);
            //  0.361 - 0.705
 
            //  1.816
            /*StopWatch serviceStart = new StopWatch();
            serviceStart.start();*/
            //  이슈 사용자 정의 값 필드 벌크 등록
            this.bulkInsertIssueCustomFieldValue(issueForms, issueTypeCustomFieldMaps);
            //  3.628 - 3.445
 
            /*serviceStart.stop();
            log.debug("2차 저장 시간 : " + serviceStart.getTime());*/
 
            //  이슈 리스크 벌크 등록
            this.bulkInsertIssueRisk(issueForms, workspace);
 
            //  reverse index 업데이트
            this.issueMapper.updateBatch(issueForms);
            //  증가된 이슈 번호를 업데이트 한다.
//            issueNumberMaps.put(issueForm.getProjectId(), issueForm.getProjectId());
//            this.issueNumberGeneratorService.updateIssueNumber(issueNumberMaps);
        }
    }
 
    /**
     * 엑셀로 입력한 파트너 정보 저장
     * @param issueForm IssueForm
     */
    private void setIssuePartners(IssueForm issueForm, Issue issue) {
        //issueCompany 등록
        if (issueForm.getIssueCompanyFields() != null && issueForm.getIssueCompanyFields().size() > 0) {
            for (Map<String, Object> issueCompanyMap : issueForm.getIssueCompanyFields()) {
                CompanyField companyField =  ConvertUtil.convertMapToClass(issueCompanyMap, CompanyField.class);
                IssueCompany issueCompany = ConvertUtil.convertMapToClass(issueCompanyMap, IssueCompany.class, "id", "registerDate", "modifyDate");
                issueCompany.setCompanyField(companyField);
                issueCompany.setIssue(issue);
                this.issueCompanyRepository.saveAndFlush(issueCompany);
 
                //  사용자가 ISP를 직접 입력하지 않았을 경우 업체에 등록되어있는 ISP 설정
                if (issueForm.getIssueIspFields() == null || issueForm.getIssueIspFields().size() < 1) {
                    //  업체의 ISP가 있는 경우 issueISP 등록
                    if (companyField.getIspId() != null && companyField.getIspId() != -1) {
                        IspField ispField = this.ispFieldService.getIsp(companyField.getIspId());
                        IssueIsp issueIsp = ConvertUtil.copyProperties(ispField, IssueIsp.class, "id", "registerDate", "modifyDate");
                        issueIsp.setIspField(ispField);
                        issueIsp.setIssue(issue);
                        this.issueIspRepository.saveAndFlush(issueIsp);
                    }
                }
                //  사용자가 호스팅을 직접 입력하지 않았을 경우 업체에 등록되어있는 호스팅 설정
                if (issueForm.getIssueHostingFields() == null || issueForm.getIssueHostingFields().size() < 1) {
                    //  업체의 호스팅이 있는 경우 issueHosting 등록
                    if (companyField.getHostingId() != null && companyField.getHostingId() != -1) {
                        HostingField hostingField = this.hostingFieldService.getHosting(companyField.getHostingId());
                        IssueHosting issueHosting = ConvertUtil.copyProperties(hostingField, IssueHosting.class, "id", "registerDate", "modifyDate");
                        issueHosting.setHostingField(hostingField);
                        issueHosting.setIssue(issue);
                        this.issueHostingRepository.saveAndFlush(issueHosting);
                    }
                }
            }
        }
        //issueIsp 등록
        if (issueForm.getIssueIspFields() != null && issueForm.getIssueIspFields().size() > 0) {
            for (Map<String, Object> issueIspMap : issueForm.getIssueIspFields()) {
                IssueIsp issueIsp = ConvertUtil.convertMapToClass(issueIspMap, IssueIsp.class, "id", "registerDate", "modifyDate");
                IspField ispField = ConvertUtil.convertMapToClass(issueIspMap, IspField.class);
                issueIsp.setIspField(ispField);
                issueIsp.setIssue(issue);
                this.issueIspRepository.saveAndFlush(issueIsp);
            }
        }
        //issueHosting 등록
        if (issueForm.getIssueHostingFields() != null && issueForm.getIssueHostingFields().size() > 0) {
            for (Map<String, Object> issueHostingMap : issueForm.getIssueHostingFields()) {
                IssueHosting issueHosting = ConvertUtil.convertMapToClass(issueHostingMap, IssueHosting.class, "id", "registerDate", "modifyDate");
                HostingField hostingField = ConvertUtil.convertMapToClass(issueHostingMap, HostingField.class);
                issueHosting.setHostingField(hostingField);
                issueHosting.setIssue(issue);
                this.issueHostingRepository.saveAndFlush(issueHosting);
            }
        }
    }
 
    //  업로드 파일 확장자 체크
    private void verifyMultipartFileExtension(MultipartFile multipartFile) {
        multipartFile.getOriginalFilename();
 
        int pos = multipartFile.getOriginalFilename().lastIndexOf(".");
        String ext = multipartFile.getOriginalFilename().substring(pos + 1);
 
        if (!ext.equals("xlsx")) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EXCEL_NOT_EXTENSION));
        }
    }
 
    //  이슈 이력 벌크 등록
    private void bulkInsertIssueHistory(List<IssueForm> issueForms) {
        List<Map<String, Object>> issueHistoryMaps = Lists.newArrayList();
 
        for (IssueForm issueForm : issueForms) {
            Map<String, Object> issueHistoryMap = new HashMap<>();
            issueHistoryMap.put("issueId", issueForm.getId());
            issueHistoryMap.put("projectId", issueForm.getProjectId());
            issueHistoryMap.put("registerId", this.webAppUtil.getLoginId());
            issueHistoryMap.put("issueHistoryType", IssueHistoryType.ADD.toString());
 
            StringBuilder description = new StringBuilder();
            //  이력 테스트 추출
            this.issueHistoryService.makeDescription(description, IssueHistoryType.ADD, null);
            issueHistoryMap.put("description", description.toString());
 
            issueHistoryMaps.add(issueHistoryMap);
        }
 
        //  이슈 이력 벌크 등록
        this.issueMapper.insertHistoryBatch(issueHistoryMaps);
    }
 
    //  이슈 담당자 벌크 등록
    private void bulkInsertIssueAssignee(List<IssueForm> issueForms, Workspace workspace) {
        List<Map<String, Long>> issueAssigneeMaps = Lists.newArrayList();
 
        for (IssueForm issueForm : issueForms) {
            for (Long departmentId : issueForm.getDepartmentIds()) {
                Map<String, Long> issueAssigneeMap = new HashMap<>();
                issueAssigneeMap.put("issueId", issueForm.getId());
                //issueAssigneeMap.put("userId", userId);
                issueAssigneeMap.put("departmentId", departmentId);
                issueAssigneeMap.put("workspaceId", workspace.getId());
                issueAssigneeMap.put("registerId", this.webAppUtil.getLoginId());
                issueAssigneeMaps.add(issueAssigneeMap);
            }
        }
 
        if (issueAssigneeMaps.size() > 0) {
            //  이슈 담당자 벌크 등록
            //this.issueUserService.insertIssueUser(issueAssigneeMaps);
            this.issueDepartmentService.insertIssueDepartment(issueAssigneeMaps);
        }
    }
 
    //  이슈 리스크 벌크 등록
    private void bulkInsertIssueRisk(List<IssueForm> issueForms, Workspace workspace) {
        List<Map<String, Long>> issueRiskMaps = Lists.newArrayList();
        for (IssueForm issueForm : issueForms) {
            Map<String, Long> issueRiskMap = new HashMap<>();
            issueRiskMap.put("issueId", issueForm.getId());
            issueRiskMap.put("changeAssigneeCount", 0L);
            issueRiskMap.put("changeDepartmentCount", 0L);
            issueRiskMap.put("changeIssueStatusCount", 0L);
            issueRiskMap.put("workspaceId", workspace.getId());
            issueRiskMap.put("issueStatusIds", issueForm.getIssueStatusId());
            issueRiskMap.put("registerId", this.webAppUtil.getLoginId());
            issueRiskMaps.add(issueRiskMap);
        }
 
        if (issueRiskMaps.size() > 0) {
            //  이슈 리스크 벌크 등록
            this.issueMapper.insertIssueRiskBatch(issueRiskMaps);
        }
    }
 
    //  이슈 사용자 정의 필드 선택 값 벌크 등록
    private void bulkInsertIssueCustomFieldValue(List<IssueForm> issueForms, Map<String, Long> issueTypeCustomFieldMaps) {
        List<Map<String, Object>> issueCustomFieldValueMaps = Lists.newArrayList();
 
        for (IssueForm issueForm : issueForms) {
            for (Map<String, Object> issueCustomField : issueForm.getIssueCustomFields()) {
                String findKey = issueForm.getIssueTypeId().toString() + MapUtil.getString(issueCustomField, "customFieldId");
 
                //  이슈 타입 + 사용자 정의 필드 연결정보가 없다면 저장하지 않는다.
                if (issueTypeCustomFieldMaps.get(findKey) == null) {
                    continue;
                }
 
                issueCustomField.put("issueTypeCustomFieldId", issueTypeCustomFieldMaps.get(findKey));
                issueCustomField.put("issueId", issueForm.getId());
                issueCustomField.put("registerId", this.webAppUtil.getLoginId());
                issueCustomFieldValueMaps.add(issueCustomField);
            }
 
            //  엑셀에 업체명을 입력하지 않았을 경우 같은 도메인 업체 찾기
            this.findPartnerByDomain(issueForm);
        }
 
        if (issueCustomFieldValueMaps.size() > 0) {
            this.issueMapper.insertIssueCustomFieldValueBatch(issueCustomFieldValueMaps);
        }
    }
 
    /**
     * 엑셀에 업체명을 입력하지 않았을 경우 같은 도메인 업체 찾기
     * @param issueForm IssueForm
     */
    private void findPartnerByDomain(IssueForm issueForm) {
        if (issueForm.getIssueCompanyFields() == null || issueForm.getIssueCompanyFields().size() < 1) {
            // 같은 도메인 업체 찾기
            IssueForm partners = this.findCompanyField(issueForm);
            Issue issue = this.findOne(issueForm.getId());
            if (partners.getIssueCompanyFields() != null && partners.getIssueCompanyFields().size() > 0) {
                for (Map<String, Object> company : partners.getIssueCompanyFields()) {
                    IssueCompany issueCompany = ConvertUtil.convertMapToClass(company, IssueCompany.class);
                    CompanyField companyField = ConvertUtil.convertMapToClass(company, CompanyField.class);
                    issueCompany.setCompanyField(companyField);
                    issueCompany.setIssue(issue);
 
                    this.issueCompanyRepository.saveAndFlush(issueCompany);
                }
            }
            if (partners.getIssueIspFields() != null && partners.getIssueIspFields().size() > 0) {
                for (Map<String, Object> isp : partners.getIssueIspFields()) {
                    IssueIsp issueIsp = ConvertUtil.convertMapToClass(isp, IssueIsp.class);
                    IspField ispField = ConvertUtil.convertMapToClass(isp, IspField.class);
                    issueIsp.setIspField(ispField);
                    issueIsp.setIssue(issue);
                    this.issueIspRepository.saveAndFlush(issueIsp);
                }
            }
            if (partners.getIssueHostingFields() != null && partners.getIssueHostingFields().size() > 0) {
                for (Map<String, Object> hosting : partners.getIssueHostingFields()) {
                    IssueHosting issueHosting = ConvertUtil.convertMapToClass(hosting, IssueHosting.class);
                    HostingField hostingField = ConvertUtil.convertMapToClass(hosting, HostingField.class);
                    issueHosting.setHostingField(hostingField);
                    issueHosting.setIssue(issue);
                    this.issueHostingRepository.saveAndFlush(issueHosting);
                }
            }
        }
    }
 
    //  이슈의 주요 속성을 map 에 저장하여 엑셀 import 에서 지정한 대상(이슈 속성)을 빠르게 찾을 수 있게 한다.
    private void IssueAttributeMapToList(IssueForm issueForm, Map<String, Priority> priorityMaps, Map<String, Severity> severityMaps,
                                         Map<String, DepartmentVo> departmentMaps, Map<String, CustomField> customFieldMaps,Map<String, Long> issueTypeCustomFieldMaps,
                                         Map<String, CompanyField> companyFieldMaps, Map<String, IspField> ispFieldMaps, Map<String, HostingField> hostingFieldMaps) {
 
        Project project = this.projectService.getProject(issueForm.getProjectId());
 
        for (IssueTypeCustomField issueTypeCustomField : project.getIssueTypeCustomFields()) {
            //  빠르게 찾기 위해 이슈 타입 아이디 + 사용자 정의 필드 아이디를 키로 한다.
            String makeKey = issueTypeCustomField.getIssueType().getId().toString() + issueTypeCustomField.getCustomField().getId().toString();
            issueTypeCustomFieldMaps.put(makeKey, issueTypeCustomField.getId());
        }
 
        //  우선순위를 바로 찾을 수 있게 준비
        List<Priority> priorities = this.priorityService.findByWorkspaceId();
        for (Priority priority : priorities) {
            priorityMaps.put(priority.getName(), priority);
        }
 
        //  중요도를 바로 찾을 수 있게 준비
        List<Severity> severities = this.severityService.findByWorkspaceId();
        for (Severity severity : severities) {
            severityMaps.put(severity.getName(), severity);
        }
 
        //  사용자 정의 필드를 바로 찾을 수 있게 준비
        List<CustomField> customFields = this.customFieldService.findByWorkspaceId();
        for (CustomField customField : customFields) {
            customFieldMaps.put(customField.getName(), customField);
        }
 
        //  업체 정보를 바로 찾을 수 있게 준비
        List<CompanyField> companyFields = this.companyFieldService.findAll();
        for (CompanyField companyField : companyFields) {
            companyFieldMaps.put(companyField.getName(), companyField);
        }
        //  ISP 정보를 바로 찾을 수 있게 준비
        List<IspField> ispFields = this.ispFieldService.findAll();
        for (IspField ispField : ispFields) {
            ispFieldMaps.put(ispField.getName(), ispField);
        }
        //  호스팅 정보를 바로 찾을 수 있게 준비
        List<HostingField> hostingFields = this.hostingFieldService.findAll();
        for (HostingField hostingField : hostingFields) {
            hostingFieldMaps.put(hostingField.getName(), hostingField);
        }
    }
 
    /**
     * cell String으로 변환 함수
     * @param cell Cell
     * @param isNull boolean
     * @return String
     */
    private String stringToCell (Cell cell, boolean isNull) {
        String cellStr = "";
        if (!isNull) {
            cellStr = CommonUtil.convertExcelStringToCell(cell);
            //  공백 제거
            cell.setCellValue(cellStr.trim());
        } else {
            cell.setCellValue(cellStr);
        }
        return cellStr;
    }
 
    /**
     * cell NULL 체크 함수
     * 빈 값이 아닌 cell 체크
     * @param cell Cell
     * @return boolean
     */
    private Boolean cellNullCheck (Cell cell) {
        int cellType = cell.getCellType();
        if (cellType < Cell.CELL_TYPE_BLANK) {
            if (cellType == Cell.CELL_TYPE_STRING) {
                if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }
 
    //  엑셀 필드에 있는 정보를 이슈 form 으로 옮긴다.
    private IssueForm setIssueFormToExcelField(Row row, int rowIndex, Map<String, Priority> priorityMaps,
                                               Map<String, Severity> severityMaps, Map<String, CustomField> customFieldMaps,
                                               Map<String, CompanyField> companyFieldMaps, Map<String, IspField> ispFieldMaps, Map<String, HostingField> hostingFieldMaps,
                                               List<String> headers) throws ParseException {
        IssueForm issueForm = new IssueForm();
        issueForm.setRegisterId(this.webAppUtil.getLoginId());
 
        //  제목, 내용, 프로젝트 키, 이슈 타입, 우선순위, 중요도, 담당자, 시작일, 종료일, 사용자 정의 필드
        for (int cellIndex = 0; cellIndex < headers.size(); cellIndex++) {
            Cell cell = row.getCell(cellIndex);
 
            String cellStr = "";
            boolean isNull = true;
 
            if (cell != null) {
                isNull = cellNullCheck(cell);
                cellStr = stringToCell(cell, isNull); //cell을 String으로 변환
            }
 
            switch (cellIndex) {
                case 0:
                    //  이슈 제목을 IssueForm 에 저장한다.
                    if (isNull) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_ISSUE_TITLE_IS_NULL, rowIndex));
                    }
                    this.setIssueFormTitle(cellStr, issueForm, rowIndex);
                    break;
 
                case 1:    //  내용
                    issueForm.setDescription(cellStr);
                    break;
 
                case 2:
                    //  우선순위를 IssueForm 에 저장한다.
                    if (isNull) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PRIORITY_IS_NULL, rowIndex));
                    }
                    this.setIssueFormPriority(cellStr, priorityMaps, issueForm, rowIndex);
                    break;
 
                case 3:
                    //  중요도를 IssueForm 에 저장한다.
                    if (isNull) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_SEVERITY_IS_NULL, rowIndex));
                    }
                    this.setIssueFormSeverity(cellStr, severityMaps, issueForm, rowIndex);
                    break;
                /*case 6:
                    //  담당자를 IssueForm 에 저장한다.
                    this.setIssueFormAssignee(cell, userMaps, issueForm, project);
                    break;*/
                case 4:
                    //  시작일을 IssueForm 에 저장한다.
                    this.setIssueFormPeriod(cellStr, issueForm, true, rowIndex, isNull);
                    break;
                case 5:
                    //  종료일을 IssueForm 에 저장한다.
                    this.setIssueFormPeriod(cellStr, issueForm, false, rowIndex, isNull);
                    break;
                case 6:
                    //  업체를 IssueForm 에 저장한다.
                    this.setIssueFormCompanyField(cellStr, companyFieldMaps, issueForm, rowIndex);
                    break;
                case 7:
                    //  ISP를 IssueForm 에 저장한다.
                    this.setIssueFormIspField(cellStr, ispFieldMaps, issueForm, rowIndex);
                    break;
                case 8:
                    //  호스팅을 IssueForm 에 저장한다.
                    this.setIssueFormHostingField(cellStr, hostingFieldMaps, issueForm, rowIndex);
                    break;
                default:
                    //  9번 부터는 사용자 정의 필드. 사용자 정의 필드 정보를 IssueForm 에 저장한다.
                    this.setIssueFormCustomFieldValue(cellStr, customFieldMaps, issueForm, headers.get(cellIndex), rowIndex);
            }
        }
 
        return issueForm;
    }
 
    private void setIssueFormHostingField(String cell, Map<String, HostingField> hostingFieldMaps, IssueForm issueForm, int rowIndex) {
        if (cell.length() > 0) {
            Map<String, Object> issueHostingFields = new HashMap<>();
            HostingField hostingFieldMap = hostingFieldMaps.get(cell);
            if (hostingFieldMap == null) {
                throw new OwlRuntimeException(
                        this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_HOSTING_NOT_EXIST, rowIndex));
            }
            ConvertUtil.copyProperties(hostingFieldMap, issueHostingFields);
            issueForm.addIssueHostingField(issueHostingFields);
        }
    }
 
    private void setIssueFormIspField(String cell, Map<String, IspField> ispFieldMaps, IssueForm issueForm, int rowIndex) {
        if (cell.length() > 0) {
            Map<String, Object> issueIspFields = new HashMap<>();
            IspField ispFieldMap = ispFieldMaps.get(cell);
            if (ispFieldMap == null) {
                throw new OwlRuntimeException(
                        this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_ISP_NOT_EXIST, rowIndex));
            }
            ConvertUtil.copyProperties(ispFieldMap, issueIspFields);
            issueForm.addIssueIspField(issueIspFields);
        }
    }
 
    private void setIssueFormCompanyField(String cell, Map<String, CompanyField> companyFieldMaps, IssueForm issueForm, int rowIndex) {
        if (cell.length() > 0) {
            Map<String, Object> issueCompanyFields = new HashMap<>();
            CompanyField companyFieldMap = companyFieldMaps.get(cell);
            if (companyFieldMap == null) {
                throw new OwlRuntimeException(
                        this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_COMPANY_NOT_EXIST, rowIndex));
            }
            ConvertUtil.copyProperties(companyFieldMap, issueCompanyFields);
            issueForm.addissueCompanyField(issueCompanyFields);
        }
    }
 
    //  이슈 제목을 IssueForm 에 저장한다.
    private void setIssueFormTitle(String title, IssueForm issueForm, int rowIndex) {
        //  제목 유효성 체크
        this.verifyTitle(title);
        issueForm.setTitle(title);
    }
 
    //  프로젝트 아이디를 IssueForm 에 저장한다.
    private Project setIssueFormProject(Cell cell, Map<String, Project> projectMaps, IssueForm issueForm, int rowIndex) {
        if (cell == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PROJECT_KEY_IS_NULL, rowIndex));
        }
 
        Project project = projectMaps.get(CommonUtil.convertExcelStringToCell(cell).toUpperCase());
 
        if (project == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PROJECT_NOT_EXIST, rowIndex));
        }
 
        issueForm.setProjectId(project.getId());
 
        return project;
    }
 
    //  이슈 고유 번호를 IssueForm 에 저장한다.
    private void setIssueFormIssueNumber(IssueForm issueForm, Map<Long, Long> issueNumberMaps, Project project, int rowIndex) {
        //  이슈 고유 번호
        Long issueNumber = issueNumberMaps.get(project.getId());
 
        if (issueNumber == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NUMBER_NOT_EXIST, rowIndex));
        }
 
        issueForm.setIssueNumber(issueNumber);
        issueNumberMaps.put(project.getId(), ++issueNumber);  //  이슈 번호를 1씩 증가 시킨다.
    }
 
 
    //  우선순위를 IssueForm 에 저장한다.
    private void setIssueFormPriority(String priorityStr, Map<String, Priority> priorityMaps, IssueForm issueForm, int rowIndex) {
        Priority priority = priorityMaps.get(priorityStr);
 
        if (priority == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PRIORITY_NOT_EXIST, rowIndex));
        }
 
        issueForm.setPriorityId(priority.getId());
    }
 
    //  중요도를 IssueForm 에 저장한다.
    private void setIssueFormSeverity(String strSeverity, Map<String, Severity> severityMaps, IssueForm issueForm, int rowIndex) {
        Severity severity = severityMaps.get(strSeverity);
 
        if (severity == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_SEVERITY_NOT_EXIST, rowIndex));
        }
 
        issueForm.setSeverityId(severity.getId());
    }
 
    private void setIssueFormAssignee(Cell cell, Map<String, Object> userMaps, IssueForm issueForm, Project project) {
        if (cell != null) {
            String[] splitAssignee = CommonUtil.convertExcelStringToCell(cell).split("#");
            Map<String, Object> userMap = (Map<String, Object>) MapUtil.getObject(userMaps, project.getProjectKey());
 
            List<Long> userIds = Lists.newArrayList();
 
            for (String account : splitAssignee) {
                if (MapUtil.getLong(userMap, account) != null) {
                    userIds.add(MapUtil.getLong(userMap, account));
                }
            }
            issueForm.setUserIds(userIds);
        }
    }
    //  시작일, 종료일을 IssueForm 에 저장한다.
    private void setIssueFormPeriod(String periodDate, IssueForm issueForm, Boolean checkStartDate, int rowIndex, boolean isNull) throws ParseException {
        if (!isNull) {
 
            Date startDate = DateUtil.convertStrToDateOnly(periodDate);
            if (startDate == null) {
                throw new OwlRuntimeException(
                        this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PERIOD_NOT_VALIDITY_EMPTY, rowIndex));
            }
 
            if (checkStartDate) {
                issueForm.setStartDate(DateUtil.convertDateToStr(startDate, "yyyy-MM-dd"));
            } else {
                issueForm.setCompleteDate(DateUtil.convertDateToStr(startDate, "yyyy-MM-dd"));
 
                //  종료일만 입력 했을 경우
                if (issueForm.getCompleteDate() != null && issueForm.getStartDate() == null) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PERIOD_NOT_VALIDITY_EMPTY_START, rowIndex));
                }
 
                try {
                    //  날짜 유효성 체크
                    this.checkStartCompleteDate(issueForm.getStartDate(), issueForm.getCompleteDate());
                } catch (OwlRuntimeException e) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PERIOD_NOT_VALID, rowIndex));
                }
            }
        }
    }
 
    //  사용자 정의 필드 정보를 IssueForm 에 저장한다.-
    private void setIssueFormCustomFieldValue(String cellValue, Map<String, CustomField> customFieldMaps, IssueForm issueForm, String customFieldName, int rowIndex) {
        Map<String, Object> issueCustomFieldMap = new HashMap<>();
        CustomField customField = customFieldMaps.get(customFieldName);
 
        if (customField == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_HEADER_CUSTOM_FIELD_NOT_EXIST, rowIndex));
        }
        //  사용자 정의 필드 값이 공백이면 중지
        if (StringUtils.isEmpty(cellValue)) {
            return;
        }
 
        boolean validity = false;
 
        switch (customField.getCustomFieldType()) {
            case INPUT:
            case NUMBER:
            case DATETIME:
            case IP_ADDRESS:
            case EMAIL:
            case SITE:
            case TEL:
                if (customField.getCustomFieldType() != INPUT && cellValue.length() > 100) { //INPUT 타입은 100자 제한 없음
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.CUSTOM_FIELD_TEXT_TYPE_MAX_LENGTH_OUT));
                }
 
                //DATETIME일 경우 format 변경
                if (customField.getCustomFieldType() == DATETIME) {
                    Date date = DateUtil.convertStrToDate(cellValue);
                    if (date == null) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_DATETIME_NOT_DASH, rowIndex));
                    }
                }
 
                //IP_ADDRESS일 경우 정규표현식 체크
                if (customField.getCustomFieldType() == IP_ADDRESS) {
                    String regExp = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
                            + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
                            + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
                            + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
 
                    if (!cellValue.matches(regExp)) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_IP_ADDRESS_NOT_VALIDITY, rowIndex));
                    }
                }
 
                issueCustomFieldMap.put("customFieldId", customField.getId());
                issueCustomFieldMap.put("useValue", cellValue);
                issueForm.addIssueCustomFields(issueCustomFieldMap);
                break;
            case SINGLE_SELECT:
                //  값 유효성 체크
                for (CustomFieldValue customFieldValue : customField.getCustomFieldValues()) {
                    if (customFieldValue.getValue().equals(cellValue)) {
                        validity = true;
                        break;
                    }
                }
 
                if (!validity) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.EXCEL_CUSTOM_FIELD_VALUE_NOT_VALIDITY, rowIndex));
                }
 
                issueCustomFieldMap.put("customFieldId", customField.getId());
                issueCustomFieldMap.put("useValue", cellValue);
                issueForm.addIssueCustomFields(issueCustomFieldMap);
 
                break;
            case MULTI_SELECT:
                //  값 유효성 체크
                String[] useValues = cellValue.split("#");
                //  해, 달
                for (String useValue : useValues) {
                    for (CustomFieldValue customFieldValue : customField.getCustomFieldValues()) {
 
                        if (customFieldValue.getValue().equals(useValue)) {
                            validity = true;
                            Map<String, Object> multiValueMap = new HashMap<>();
                            multiValueMap.put("customFieldId", customField.getId());
                            multiValueMap.put("useValue", useValue);
                            issueForm.addIssueCustomFields(multiValueMap);
                        }
 
                    }
                }
 
                if (!validity) {
                    throw new OwlRuntimeException(
                            this.messageAccessor.getMessage(MsgConstants.EXCEL_CUSTOM_FIELD_VALUE_NOT_VALIDITY, rowIndex));
                }
 
                break;
        }
    }
 
    //  프로젝트에 있는 모든 이슈 정보를 조회한다.
    @Override
    @Transactional(readOnly = true)
    public List<Long> findByProjectId(Long projectId) {
        List<Map<String, Object>> issueMaps = this.issueMapper.findByProjectId(projectId);
        List<Long> issueIds = Lists.newArrayList();
 
        for (Map<String, Object> issueMap : issueMaps) {
            Long issueId = MapUtil.getLong(issueMap, "id");
            if (issueId != null) {
                issueIds.add(issueId);
            }
        }
 
        return issueIds;
    }
 
    //  이슈를 대상자들에게 메일로 발송한다.
    @Override
    @Transactional(readOnly = true)
    public void sendIssueEmail(IssueForm issueForm) {
        if (issueForm.getSendEmails().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SEND_USER));
        }else if (issueForm.getTemplate() != null){
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SELECT_TEMPLATE));
        }
 
        Issue issue = this.getIssue(issueForm.getId());
 
        Map<String, Object> issueMap = new HashMap<>();
        //  이슈 정보를 이메일 전송에 사용하기 위해 Map 형태로 변환한다.
        this.makeIssueMapToIssue(issue, issueMap);
        //  발신자 표시
        UserVo toUser = this.webAppUtil.getLoginUser();
        issueMap.put("toUser", toUser.getName() + "(" + CommonUtil.decryptAES128(toUser.getAccount()) + ")");
 
        // 이슈 링크
        String projectKey = issue.getProject().getProjectKey();
        Long IssueNumber = issue.getIssueNumber();
        String link = this.configuration.getEmailSendUrl() + "/#/issues/issueList?projectKey=" + projectKey + "&issueNumber=" + IssueNumber.toString();
 
        issueMap.put("issueLink", link);
        issueMap.put("projectLink", link);
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_ANOTHER_USER_SEND_EMAIL));
        this.systemEmailService.directEmail(issueForm.getSendEmails().toArray(new String[issueForm.getSendEmails().size()]), EmailType.ISSUE_SEND, issueMap, null);
    }
 
    //  이슈를 템플릿에 따라 파트너 담당자에게 메일로 발송한다.
    @Override
    @Transactional(readOnly = true)
    public void sendIssueEmailPartners(EmailTemplateForm emailTemplateForm, List<MultipartFile> multipartFiles) {
        if (emailTemplateForm.getSendEmails().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SEND_USER));
        }else if (emailTemplateForm.getTemplate() == null){
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SELECT_TEMPLATE));
        } else if (emailTemplateForm.getIssueId() == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_EXIST));
        }
 
        Issue issue = this.getIssue(emailTemplateForm.getIssueId());
 
        //  발신자 표시
        User user = this.webAppUtil.getLoginUserObject();
        UserVo toUser = this.webAppUtil.getLoginUser();
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_ANOTHER_USER_SEND_EMAIL));
        StringBuilder sb = new StringBuilder();
 
        Locale locale = CommonUtil.getUserLanguage(user.getLanguage());
        String[] sendMails = ConvertUtil.ToArray(emailTemplateForm.getSendEmails());
        for(int i=0; i < sendMails.length; i++) {
            sendMails[i] = CommonUtil.decryptAES128(sendMails[i]);
        }
        this.systemEmailService.sendEmail(emailTemplateForm.getTitle(), emailTemplateForm.getTemplate(), sendMails, null, multipartFiles);
 
        this.issueHistoryService.detectSendIssueMail(IssueHistoryType.SEND, emailTemplateForm.getSendEmails(), sb);
        this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.SEND, sb.toString());
    }
 
    @Override
    public void sendCommonEmail(EmailCommonForm emailCommonForm, List<MultipartFile> multipartFiles) {
        if (emailCommonForm.getSendEmails().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_NOT_SEND_USER));
        }
 
        Issue issue = null;
        if(emailCommonForm.getIssueId() != null) {
            issue = this.getIssue(emailCommonForm.getIssueId());
        }
 
        //  발신자 표시
        User user = this.webAppUtil.getLoginUserObject();
        UserVo toUser = this.webAppUtil.getLoginUser();
 
        //  사용자 시스템 기능 사용 정보 수집
        log.info(ElasticSearchUtil.makeUserActiveHistoryMessage(this.webAppUtil.getLoginUser(), ElasticSearchConstants.ISSUE_ANOTHER_USER_SEND_EMAIL));
        StringBuilder sb = new StringBuilder();
 
        Locale locale = CommonUtil.getUserLanguage(user.getLanguage());
        String[] sendMails = ConvertUtil.ToArray(emailCommonForm.getSendEmails());
        for(int i=0; i < sendMails.length; i++) {
            sendMails[i] = CommonUtil.decryptAES128(sendMails[i]);
        }
        this.systemEmailService.sendEmail(emailCommonForm.getTitle(), emailCommonForm.getDescription(), sendMails, null, multipartFiles);
 
        if (issue != null) {
            this.issueHistoryService.detectSendIssueMail(IssueHistoryType.SEND, emailCommonForm.getSendEmails(), sb);
            this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.SEND, sb.toString());
        }
    }
 
    //  예약 발생 이슈를 실행한다
    @Override
    @Transactional
    public void reservationIssue() {
        List<IssueReservation> issueReservations = this.issueReservationService.findByIssueReservationTypeNotNull();
 
        Calendar calendar = Calendar.getInstance();
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        int month = calendar.get(Calendar.MONTH) + 1;
        int date = calendar.get(Calendar.DATE);
 
        for (IssueReservation issueReservation : issueReservations) {
            switch (issueReservation.getIssueReservationType()) {
                case DAY:
                    //  이슈를 다시 생성 상태로 변경시킨다.
                    this.occurReservationIssue(issueReservation.getIssue());
                    break;
                case WEEK:
                    if (dayOfWeek == Integer.parseInt(issueReservation.getReservation())) {
                        //  이슈를 다시 생성 상태로 변경시킨다.
                        this.occurReservationIssue(issueReservation.getIssue());
                    }
 
                    break;
                case MONTH:
                    if (date == Integer.parseInt(issueReservation.getReservation())) {
                        //  이슈를 다시 생성 상태로 변경시킨다.
                        this.occurReservationIssue(issueReservation.getIssue());
                    }
 
                    break;
                case YEAR:
                    String[] reservations = issueReservation.getReservation().split("-");
 
                    if (reservations.length > 1) {
                        if ((Integer.parseInt(reservations[0]) == month) && Integer.parseInt(reservations[1]) == date) {
                            //  이슈를 다시 생성 상태로 변경시킨다.
                            this.occurReservationIssue(issueReservation.getIssue());
                        }
                    }
 
                    break;
            }
        }
    }
 
    //  이슈를 다시 생성 상태로 변경시킨다.
    private void occurReservationIssue(Issue issue) {
        if (!issue.getIssueStatus().getIssueStatusType().equals(IssueStatusType.READY)) {
            //  이슈를 생성 상태로 변경시킨다.
            IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issue.getIssueType().getWorkflow());
 
            if (issueStatus != null) {
                StringBuilder detectIssueChange = new StringBuilder();
                //  예약 발생으로 이슈 상태 변경된 정보를 기록한다.
                this.issueHistoryService.detectReservationIssueStatus(issue, detectIssueChange, issueStatus);
                issue.setIssueStatus(issueStatus);
                this.issueRepository.saveAndFlush(issue);
                //  이슈 상태 변경 정보를 이력으로 남긴다.
                this.issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, detectIssueChange.toString());
                //  이슈 버전 생성
                this.issueVersionService.addIssueVersion(issue);
            }
        }
    }
 
    @Autowired
    private ProjectMapper projectMapper;
 
    @Override
    @Transactional(readOnly = true)
    public Map<String, Object> findTask(IssueCondition taskCondition) {
 
        StopWatch serviceStart = new StopWatch();
        serviceStart.start();
        ProjectCondition projectCondition = new ProjectCondition(this.webAppUtil.getLoginUser().getLastProjectId(), this.webAppUtil.getLoginId());
        List<Map<String, Object>> checkProjectRole = this.projectMapper.checkIncludeProject(projectCondition);
 
        if (checkProjectRole.size() < 1) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.PROJECT_NOT_INCLUDE_USER));
        }
 
        //  이중으로 역할 체크를 해서 참여하지 않은 사용자가 해당 프로젝트에 접근 못하도록 한다.
        taskCondition.setLoginUserId(this.webAppUtil.getLoginId());
//        List<Map<String, Object>> results = this.taskMapper.find(taskCondition);
        List<Map<String, Object>> results = this.issueMapper.find(taskCondition);
 
        serviceStart.stop();
        long executeTime = serviceStart.getTime();
 
        Map<String, Object> tasks = new HashMap<>();
        //  워크플로우 상태 id 를 키로 만든다.
        for (Long workflowStatusId : taskCondition.getStatusIds()) {
            tasks.put(workflowStatusId.toString(), Lists.newArrayList());
        }
 
        Map<String, Object> taskUserSave = new HashMap<>();
        //  전체 task_id를 모은다.
        for (Map<String, Object> result : results) {
            Long taskId = MapUtil.getLong(result, "id");
            taskCondition.addIssueIds(taskId.toString());
            //  각 task_id 별로 사용자 정보를 저장할 공간을 미리 확보한다.
            taskUserSave.put(taskId.toString(), Lists.newArrayList());
        }
 
        List<Map<String, Object>> taskDepartments = Lists.newArrayList();
        //  task 가 하나도 없을 경우에는 조회를 하지 않는다.
        if (!taskCondition.getIssueIds().isEmpty()) {
            //taskUsers = this.issueMapper.getAllTaskUser(taskCondition);
            taskDepartments = this.issueMapper.getAllTaskUser(taskCondition);
        }
 
        //  task_id 에 매칭되는 담당자 정보를 준비한다.
        /*for (Map<String, Object> taskUser : taskUsers) {
            Long taskId = MapUtil.getLong(taskUser, "taskId");
            List<UserVo> userVos = (List<UserVo>)taskUserSave.get(taskId.toString());
            userVos.add(ConvertUtil.convertMapToClass(taskUser, UserVo.class));
        }*/
 
        for (Map<String, Object> taskDepartment : taskDepartments) {
            Long taskId = MapUtil.getLong(taskDepartment, "taskId");
            List<DepartmentVo> departmentVos = (List<DepartmentVo>)taskUserSave.get(taskId.toString());
            departmentVos.add(ConvertUtil.convertMapToClass(taskDepartment, DepartmentVo.class));
        }
 
        for (Map<String, Object> result : results) {
            IssueVo taskVo = ConvertUtil.convertMapToClass(result, IssueVo.class);
 
            //  중요도 셋팅
            if (MapUtil.getLong(result, "priorityId") != null) {
                PriorityVo priorityVo = new PriorityVo();
                priorityVo.setId(MapUtil.getLong(result, "priorityId"));
                priorityVo.setName(MapUtil.getString(result, "priorityName"));
                priorityVo.setColor(MapUtil.getString(result, "priorityColor"));
                taskVo.setPriorityVo(priorityVo);
            }
 
            //  워크플로우 상태 셋팅
            if (MapUtil.getLong(result, "workflowStatusId") != null) {
                WorkflowStatusVo workflowStatusVo = new WorkflowStatusVo();
                workflowStatusVo.setId(MapUtil.getLong(result, "workflowStatusId"));
                workflowStatusVo.setName(MapUtil.getString(result, "workflowStatusName"));
                workflowStatusVo.setColor(MapUtil.getString(result, "workflowStatusColor"));
                taskVo.setWorkflowStatusVo(workflowStatusVo);
            }
 
            //  담당자 셋팅
            //List<UserVo> userVos =  (List<UserVo>)taskUserSave.get(taskVo.getId().toString());
            //taskVo.setUserVos(userVos);
 
            //  담당부서 세팅
            List<DepartmentVo> departmentVos = (List<DepartmentVo>)taskUserSave.get(taskVo.getId().toString());
            taskVo.setDepartmentVos(departmentVos);
 
            List<IssueVo> taskVos = (List<IssueVo>)tasks.get(MapUtil.getString(result, "workflowStatusId"));
            taskVos.add(taskVo);
            tasks.put(MapUtil.getString(result, "workflowStatusId"), taskVos);
        }
 
        /*serviceStart.stop();
        long executeTime = serviceStart.getTime();*/
 
        return tasks;
    }
 
    @Transactional
    @Override
    public void modifyParentIssue(IssueForm issueDownForm) {
        //Issue issue = this.getIssue(issueDownForm.getId()); //하위 이슈
        Long newParentIssueId = issueDownForm.getParentIssueId(); //변경할 하위이슈의 상위이슈
        StringBuilder sb = new StringBuilder();
 
        for (Long downId : issueDownForm.getIds()) {
            Issue issue = this.getIssue(downId);
 
            Issue parentIssue = issue.getParentIssue(); //변경 전 하위이슈의 상위이슈
            if(parentIssue != null && parentIssue.getId().equals(newParentIssueId)){ //변경 전 하위이슈의 상위이슈가 존재 할 경우
                this.issueHistoryService.detectDownIssues(IssueHistoryType.DELETE, issue, sb);
                this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString());
            }
 
            if (newParentIssueId != null) { // 추가 할 경우
                parentIssue = this.getIssue(newParentIssueId); //상위이슈(myIssue)
                issue.setParentIssue(parentIssue); //myIssue를 하위이슈의 상위이슈로 set
                this.issueHistoryService.detectDownIssues(IssueHistoryType.ADD, issue, sb); //issue = 하위이슈
            } else{
                // 삭제 할 경우
                this.issueHistoryService.detectDownIssues(IssueHistoryType.DELETE, issue, sb);
                issue.setParentIssue(null);
            }
 
            if (issueDownForm.getInheritYn() != null && issueDownForm.getInheritYn() && issue.getParentIssue() != null) {
                //  상위이슈의 파트너 정보 상속받기
                issue = this.inheritPartners(issue, parentIssue);
            }
 
            this.issueHistoryService.addIssueHistory(parentIssue, IssueHistoryType.MODIFY, sb.toString()); //parentIssue = myIssue(기록은 현재 상세페이지에 해야하니까)
            this.issueRepository.saveAndFlush(issue);
        }
    }
 
    /**
     * 상위이슈의 파트너 정보 상속받기
     * @param issue Issue
     * @param parentIssue Issue
     * @return Issue
     */
    private Issue inheritPartners(Issue issue, Issue parentIssue) {
        if (parentIssue != null) {
            if (parentIssue.getIssueType().getInheritPartners()) {
                IssueCompany issueCompany = new IssueCompany();
                IssueIsp issueIsp = new IssueIsp();
                IssueHosting issueHosting = new IssueHosting();
 
                if (parentIssue.getIssueCompanies() != null && parentIssue.getIssueCompanies().size() > 0) {
                    issue.getIssueCompanies().clear();
                    issue.getIssueCompanies().addAll(parentIssue.getIssueCompanies());
                    Iterator<IssueCompany> itrCompany = issue.getIssueCompanies().iterator();
                    ConvertUtil.copyProperties(itrCompany.next(), issueCompany, "id");
                    issueCompany.setIssue(issue);
                    issueCompany.setCompanyField(parentIssue.getIssueCompanies().iterator().next().getCompanyField());
                    this.issueCompanyRepository.saveAndFlush(issueCompany);
                } else {
                    this.issueCompanyRepository.deleteByIssueId(issue.getId());
                    this.issueCompanyRepository.flush();
                }
                if (parentIssue.getIssueIspFields() != null && parentIssue.getIssueIspFields().size() > 0) {
                    issue.getIssueIspFields().clear();
                    issue.getIssueIspFields().addAll(parentIssue.getIssueIspFields());
                    Iterator<IssueIsp> itrIsp = issue.getIssueIspFields().iterator();
                    ConvertUtil.copyProperties(itrIsp.next(), issueIsp, "id");
                    issueIsp.setIssue(issue);
                    issueIsp.setIspField(parentIssue.getIssueIspFields().iterator().next().getIspField());
                    this.issueIspRepository.saveAndFlush(issueIsp);
                } else {
                    this.issueIspRepository.deleteByIssueId(issue.getId());
                    this.issueIspRepository.flush();
                }
                if (parentIssue.getIssueHostingFields() != null && parentIssue.getIssueHostingFields().size() > 0) {
                    issue.getIssueHostingFields().clear();
                    issue.getIssueHostingFields().addAll(parentIssue.getIssueHostingFields());
                    Iterator<IssueHosting> itrHosting = issue.getIssueHostingFields().iterator();
                    ConvertUtil.copyProperties(itrHosting.next(), issueHosting, "id");
                    issueHosting.setIssue(issue);
                    issueHosting.setHostingField(parentIssue.getIssueHostingFields().iterator().next().getHostingField());
                    this.issueHostingRepository.saveAndFlush(issueHosting);
                } else {
                    this.issueHostingRepository.deleteByIssueId(issue.getId());
                    this.issueHostingRepository.flush();
                }
            }
        }
        return issue;
    }
 
    @Override
    public void findPartner(Map<String, Object> resJsonData, Map<String, Object> params) {
        Long issueTypeId = MapUtil.getLong(params, "issueTypeId");
        List<UsePartnerVo> usePartnerVos = Lists.newArrayList();
        Integer using = 0;
 
        if (issueTypeId != null) {
            IssueType issueType = this.issueTypeService.getIssueType(issueTypeId); // 이슈의 이슈유형 객체
            using = issueType.getUsePartner() != null ? issueType.getUsePartner().intValue() : 0; // 이슈유형별로 사용중인 업체/ISP/호스팅 값
        } else {
            for (int partner : UsePartner.partners) {
                using += partner;
            }
        }
 
        for (Integer usePartner : UsePartner.partners) { //1(업체), 2(ISP), 4(호스팅)
            UsePartnerVo usePartnerVo = UsePartner.checkUsePartner(using, usePartner);
            if (usePartnerVo != null) {
                usePartnerVos.add(usePartnerVo);
            }
        }
 
        resJsonData.put(Constants.RES_KEY_CONTENTS, usePartnerVos);
    }
 
    @Override
    public void findReadyDepartments(Map<String, Object> resJsonData, DepartmentCondition condition, Pageable pageable) {
        IssueType issueType = this.issueTypeService.getIssueType(condition.getIssueTypeId());
        if (issueType != null) {
            //  이슈 상태 유형이 '대기' 인 이슈 상태 가져오기
            IssueStatus issueStatus = this.issueStatusService.findByIssueStatusTypeIsReady(issueType.getWorkflow());
            condition.setIssueStatusId(issueStatus.getId());
            condition.setWorkflowId(issueType.getWorkflow().getId());
        }
        List<Map<String, Object>> departmentVos = this.departmentMapper.findByIssueStatusId(condition);
        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos);
    }
}