OWL ITS + 탐지시스템(인터넷 진흥원)
박지현
2022-03-07 398a4927e195755bd6a46be99337efd8dacc3dc2
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
/**
 * Created by wisestone on 2018-05-08.
 */
'use strict';
 
define([
        'app',
        'angular'
    ],
    function (app, angular) {
        app.controller('companyFieldModifyController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', 'CompanyField', 'parameter', 'SweetAlert', '$filter', '$q', '$injector','$controller',
            function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, CompanyField, parameter, SweetAlert, $filter, $q, $injector, $controller) {
 
                $scope.fn = {
                    detail : detail,  //  상세 조회
                    cancel : cancel,    //  팝업 창 닫기
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,  //  폼 체크
                    getIssueIspFieldListCallBack : getIssueIspFieldListCallBack,
                    getIssueHostingFieldListCallBack : getIssueHostingFieldListCallBack,
                    getCompanyTypeListCallBack : getCompanyTypeListCallBack,
                    getParentSectorListCallBack : getParentSectorListCallBack,
                    getChildSectorListCallBack : getChildSectorListCallBack,
                    getRegionListCallBack : getRegionListCallBack,
                    getStatusListCallBack : getStatusListCallBack,
                    addTel : addTel,
                    addMail : addMail,
                    removeTelInput : removeTelInput,
                    removeMailInput : removeMailInput
                };
 
                $scope.vm = {
                    id : parameter.id,
                    form : {
                        name : "",  //업체명
                        ispId : "",
                        ispName : "",
                        hostingName : "",
                        hostingId : "",
                        manager : "",   //담당자
                        tel : "",  //전화번호
                        email : "",  //이메일
                        url : "", // url
                        ipStart : "", //ip시작주소
                        ipEnd : "", //ip종료주소
                        memo : "",  //메모(비고)
                        companyTypeId : "",
                        companyType : "", //기업구분
                        parentSectorId : "",
                        parentSector : "", //업종(대분류)
                        childSectorId : "",
                        childSector : "", //업종(중분류)
                        regionId : "",
                        region : "", //지역
                        statusId : "",
                        status : "", //상태
                        inputTels : [0],
                        tels : {},
                        inputMails : [0],
                        emails : {}
                    },
                    typeCategory : {
                        companyType : "COMPANYTYPE",
                        parentSector : "PARENTSECTOR",
                        childSector : "CHILDSECTOR",
                        region : "REGION",
                        status : "STATUS"
                    },
                    autoCompletePage : {
                        ispField : {
                            page : 0,
                            totalPage : 0
                        },
                        hostingField : {
                            page : 0,
                            totalPage : 0
                        },
                        companyType : {
                            page : 0,
                            totalPage : 0
                        },
                        parentSector : {
                            page : 0,
                            totalPage : 0
                        },
                        childSector : {
                            page : 0,
                            totalPage : 0
                        },
                        region : {
                            page : 0,
                            totalPage : 0
                        },
                        status : {
                            page : 0,
                            totalPage : 0
                        }
                    }
                };
 
                angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector}));
 
 
                // ISP정보 autocomplete page 업데이트
                function getIssueIspFieldListCallBack(result) {
                    $scope.vm.autoCompletePage.ispField.totalPage = result.data.page.totalPage;
                }
 
                // 호스팅정보 autocomplete page 업데이트
                function getIssueHostingFieldListCallBack(result) {
                    $scope.vm.autoCompletePage.hostingField.totalPage = result.data.page.totalPage;
                }
 
                // 업체 카테고리 autocomplete page 업데이트
                function getCompanyTypeListCallBack(result) {
                    $scope.vm.autoCompletePage.companyType.totalPage = result.data.page.totalPage;
                }
 
                // 업체 카테고리 autocomplete page 업데이트
                function getParentSectorListCallBack(result, value) {
                    if (value === "") {
                        $scope.vm.form.parentSectorId = "";
                        if ($rootScope.isDefined($scope.vm.form.parentSectors) && $rootScope.isDefined($scope.vm.form.parentSectors[0])) {
                            $scope.vm.form.parentSectors[0].id = "";
                        }
                        $scope.vm.form.childSectorId = "";
                        $scope.vm.form.childSector = "";
                        $scope.vm.form.childSectors = [];
                    }
                    $scope.vm.autoCompletePage.parentSector.totalPage = result.data.page.totalPage;
                }
 
                // 업체 카테고리 autocomplete page 업데이트
                function getChildSectorListCallBack(result) {
                    $scope.vm.autoCompletePage.childSector.totalPage = result.data.page.totalPage;
                }
 
                // 업체 카테고리 autocomplete page 업데이트
                function getRegionListCallBack(result) {
                    $scope.vm.autoCompletePage.region.totalPage = result.data.page.totalPage;
                }
 
                // 업체 카테고리 autocomplete page 업데이트
                function getStatusListCallBack(result) {
                    $scope.vm.autoCompletePage.status.totalPage = result.data.page.totalPage;
                }
 
                // 폼 체크
                function formCheck(formInvalid) {
                    if (formInvalid) {
                        return true;
                    }
 
                    return false;
                }
 
                $scope.$on("ispFieldEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.ispId = result[0].id;
                    }
                });
 
                $scope.$on("hostingFieldEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.hostingId = result[0].id;
                    }
                });
 
                $scope.$on("companyTypeEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.companyTypeId = result[0].id;
                    }
                });
                $scope.$on("parentSectorEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.parentSectorId = result[0].id;
                    }  else {
                        $scope.vm.form.parentSectorId = "";
                        if ($rootScope.isDefined($scope.vm.form.parentSectors) && $rootScope.isDefined($scope.vm.form.parentSectors[0])) {
                            $scope.vm.form.parentSectors[0].id = "";
                        }
                    }
                    $scope.vm.form.childSectorId = "";
                    $scope.vm.form.childSector = "";
                    $scope.vm.form.childSectors = [];
                });
                $scope.$on("childSectorEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.childSectorId = result[0].id;
                    }
                });
                $scope.$on("regionEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.regionId = result[0].id;
                    }
                });
                $scope.$on("statusEvent", function (event, result) {
                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
                        $scope.vm.form.statusId = result[0].id;
                    }
                });
 
                //  폼 전송
                function formSubmit() {
                    $rootScope.spinner = true;
                    $scope.vm.form.tel = $scope.vm.form.tel.replace(/\-/g,'');  // 전화번호를 보낼땐 하이픈을 제거해서 DB에 저장
 
                    var content = {
                        id : parameter.id,
                        name : $rootScope.preventXss($scope.vm.form.name),
                        ispId : (function () {  // ISP 아이디
                            var ispId = null;
                            if ($scope.vm.form.ispName !== "" && $scope.vm.form.ispId !== null && $scope.vm.form.ispId !== -1) {
                                ispId = $scope.vm.form.ispId;
                            }else if ($scope.vm.form.issueIspFields != null && $scope.vm.form.issueIspFields.length > 0) {
                                ispId = $scope.vm.form.issueIspFields[0].id;
                            }
                            return ispId;
                        })(),
                        hostingId : (function () {  // Hosting 아이디
                            var hostingId = null;
                            if ($scope.vm.form.hostingName !== "" && $scope.vm.form.hostingId !== null && $scope.vm.form.hostingId !== -1) {
                                hostingId = $scope.vm.form.hostingId;
                            }else if ($scope.vm.form.issueHostingFields != null && $scope.vm.form.issueHostingFields.length > 0) {
                                hostingId = $scope.vm.form.issueHostingFields[0].id;
                            }
                            return hostingId;
                        })(),
                        manager : $rootScope.preventXss($scope.vm.form.manager),
                        tels : (function () {
                            var telList = [];
                            if ($scope.vm.form.tels != null) {
                                angular.forEach($scope.vm.form.tels, function (tel) {
                                    telList.push(tel);
                                });
                                telList  = telList.filter(function(item) { //쓰레기 데이터 필터링
                                    return item !== null && item !== undefined && item !== '';
                                });
                                telList  = telList.filter(function(item, idx){
                                    return telList.findIndex(function(item2, idx2){
                                        return item === item2
                                    }) == idx;
                                });
                            }
                            return telList;
                        })(),
                        emails : (function () {
                            var emailList = [];
                            if ($scope.vm.form.emails != null) {
                                angular.forEach($scope.vm.form.emails, function (email) {
                                    emailList.push(email);
                                });
                                emailList  = emailList.filter(function(item) { //쓰레기 데이터 필터링
                                    return item !== null && item !== undefined && item !== '';
                                });
                                emailList  = emailList.filter(function(item, idx){
                                    return emailList.findIndex(function(item2, idx2){
                                        return item === item2
                                    }) == idx;
                                });
                            }
                            return emailList;
                        })(),
                        url : (function () {
                            //  모든 공백 제거
                            var regex = / /gi;
                            let url = $scope.vm.form.url;
                            if ($rootScope.isDefined(url) && url.indexOf(" ") !== -1) {
                                url = url.replace(regex, "");
                            }
                            return url;
                        })(),
                        ipStart : $scope.vm.form.ipStart, // ip시작주소
                        ipEnd : $scope.vm.form.ipEnd, // ip종료주소
                        memo : $scope.vm.form.memo,
                        companyTypeId : (function () {
                            var companyTypeId = null;
                            if ($scope.vm.form.companyTypes != null && $scope.vm.form.companyTypes.length > 0) {
                                companyTypeId = $scope.vm.form.companyTypes[0].id;
                            } else {
                                companyTypeId = $scope.vm.form.companyTypeId;
                            }
                            return companyTypeId;
                        })(),
                        parentSectorId : (function () {
                            var parentSectorId = null;
                            if ($scope.vm.form.parentSectors != null && $scope.vm.form.parentSectors.length > 0) {
                                parentSectorId = $scope.vm.form.parentSectors[0].id;
                            } else {
                                parentSectorId = $scope.vm.form.parentSectorId;
                            }
                            return parentSectorId;
                        })(),
                        childSectorId : (function () {
                            var childSectorId = null;
                            if ($scope.vm.form.childSectors != null && $scope.vm.form.childSectors.length > 0) {
                                childSectorId = $scope.vm.form.childSectors[0].id;
                            } else {
                                childSectorId = $scope.vm.form.childSectorId;
                            }
                            return childSectorId;
                        })(),
                        regionId : (function () {
                            var regionId = null;
                            if ($scope.vm.form.regions != null && $scope.vm.form.regions.length > 0) {
                                regionId = $scope.vm.form.regions[0].id;
                            } else {
                                regionId = $scope.vm.form.regionId;
                            }
                            return regionId;
                        })(),
                        statusId : (function () {
                            var statusId = null;
                            if ($scope.vm.form.statuses != null && $scope.vm.form.statuses.length > 0) {
                                statusId = $scope.vm.form.statuses[0].id;
                            } else {
                                statusId = $scope.vm.form.statusId;
                            }
                            return statusId;
                        })(),
                        statusName : $scope.vm.form.status
                    };
 
                    CompanyField.modify($resourceProvider.getContent(
                        content,
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            $scope.fn.cancel();
                            //  목록 화면 갱신
                            $rootScope.$broadcast("getPageList", {});
                        }
                        else {
                            SweetAlert.error($filter("translate")("companyField.failedCompanyFieldRegistration"), result.data.message.message); //업체 등록 실패
                        }
 
                        $rootScope.spinner = false;
                    });
 
                }
 
                // 메일 주소 input 창 추가 버튼
                function addTel() {
                    var arrayFull = true;      // 배열이 가득 차 있는지 여부
                    var index = 0;
                    $scope.vm.form.inputTels.forEach(function (tel) {
                        if (!$rootScope.isDefined($scope.vm.form.tels[index])) {
                            arrayFull = false;
                        }
                        index++;
                    });
 
                    if (arrayFull) {
                        $scope.vm.form.inputTels.push(index);
                        $scope.vm.form.tels[index] = "";
                    } else {
                        SweetAlert.warning($filter("translate")("companyField.writeCompanyTel"), $filter("translate")("companyField.writeTel")); // 추가버튼 경고
                    }
                }
 
                // 메일 주소 input 창 추가 버튼
                function addMail() {
                    var arrayFull = true;      // 배열이 가득 차 있는지 여부
                    var index = 0;
                    $scope.vm.form.inputMails.forEach(function (email) {
                        if (!$rootScope.isDefined($scope.vm.form.emails[index])) {
                            arrayFull = false;
                        }
                        index++;
                    });
 
                    if (arrayFull) {
                        $scope.vm.form.inputMails.push(index);
                        $scope.vm.form.emails[index] = ""
                    } else {
                        SweetAlert.warning($filter("translate")("issue.writeIssueMail"), $filter("translate")("issue.writeMail")); // 추가버튼 경고
                    }
                }
 
                // 연락처 input 삭제
                function removeTelInput(index) {
                    $scope.vm.form.inputTels.splice(index, 1);
                }
 
                // 이메일 주소 input 삭제
                function removeMailInput(index) {
                    $scope.vm.form.inputMails.splice(index, 1);
                }
 
                //  팝업 창 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
                    $uibModalInstance.dismiss('cancel');
                    $(document).unbind("keydown");  //  단축키 이벤트 제거
                }
 
                //  상세 정보
                function detail() {
                    var deferred = $q.defer();
 
                    var conditions = {
                        id : parameter.id
                    }
 
                    CompanyField.detail($resourceProvider.getContent(
                        conditions,
                        $resourceProvider.getPageContent(0, 1))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            if (result.data.content != null) {
                                $scope.vm.form.name = result.data.content.name;
                                $scope.vm.form.manager = result.data.content.manager;
 
                                if (result.data.content.tel != null) {
                                    var inputTels = $scope.vm.form.inputTels;
                                    var tels = result.data.content.tel;
                                    if (result.data.content.tel.indexOf("[") !== -1){
                                        tels = result.data.content.tel.substr(1, result.data.content.tel.indexOf("]")-1);
                                    }
                                    var telArr = tels.split(",");
                                    angular.forEach(telArr, function (tel) {
                                        var tell = tel.trim();
                                        inputTels.push(tell);
                                    });
                                    inputTels  = inputTels.filter(function(item) {
                                        return item !== null && item !== undefined && item !== '';
                                    });
                                    if (inputTels[0] === 0 || inputTels[0] === "") {
                                        inputTels.shift();
                                    }
                                    inputTels.push("");
                                    $scope.vm.form.tels = angular.copy(inputTels);
                                }
 
                                if (result.data.content.email != null) {
                                    var inputMails = $scope.vm.form.inputMails;
                                    var emails = result.data.content.email
                                    if (result.data.content.email.indexOf("[") !== -1){
                                        emails = result.data.content.email.substr(1, result.data.content.email.indexOf("]")-1);
                                    }
                                    var emailArr = emails.split(",");
                                    angular.forEach(emailArr, function (email) {
                                        var mail = email.trim();
                                        inputMails.push(mail);
                                    });
                                    inputMails  = inputMails.filter(function(item) {
                                        return item !== null && item !== undefined && item !== '';
                                    });
                                    if(inputMails[0] === 0 || inputMails[0] === "") { // 첫번째 배열은 공백으로
                                        inputMails.shift();
                                    }
                                    inputMails.push("");
                                    $scope.vm.form.emails = angular.copy(inputMails);
                                }
 
                                $scope.vm.form.url = result.data.content.url;
                                $scope.vm.form.ipStart = result.data.content.ipStart;
                                $scope.vm.form.ipEnd = result.data.content.ipEnd;
                                $scope.vm.form.memo = result.data.content.memo;
                                $scope.vm.form.companyTypeId = result.data.content.companyTypeId;
                                $scope.vm.form.companyType = result.data.content.companyTypeName;
                                $scope.vm.form.parentSectorId = result.data.content.parentSectorId;
                                $scope.vm.form.parentSector = result.data.content.parentSectorName;
                                $scope.vm.form.childSectorId = result.data.content.childSectorId;
                                $scope.vm.form.childSector = result.data.content.childSectorName;
                                $scope.vm.form.regionId = result.data.content.regionId;
                                $scope.vm.form.region = result.data.content.regionName;
                                $scope.vm.form.statusId = result.data.content.statusId;
                                $scope.vm.form.status = result.data.content.statusName;
 
                                if (result.data.content.ispFieldVo != null) {
                                    $scope.vm.form.ispId = result.data.content.ispFieldVo.id;
                                    $scope.vm.form.ispName = result.data.content.ispFieldVo.name;
                                }
                                if (result.data.content.hostingFieldVo != null) {
                                    $scope.vm.form.hostingId = result.data.content.hostingFieldVo.id;
                                    $scope.vm.form.hostingName = result.data.content.hostingFieldVo.name;
                                }
                            }
                        }
                        else {
                            SweetAlert.swal($filter("translate")("customField.failedToDetailCompanyFieldModify"), result.data.message.message, "error"); // "업체 상세 정보 조회 실패"
                        }
                        deferred.resolve(result.data.data);
                    });
                    return deferred.promise;
                }
 
                $scope.fn.detail();
 
            }]);
    });