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
package kr.wisestone.owl.service.impl;
 
import com.google.common.collect.Lists;
import kr.wisestone.owl.common.ExcelConditionCheck;
import kr.wisestone.owl.constant.Constants;
import kr.wisestone.owl.constant.MsgConstants;
import kr.wisestone.owl.domain.CompanyField;
import kr.wisestone.owl.domain.IspField;
import kr.wisestone.owl.domain.Priority;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.mapper.IspFieldMapper;
import kr.wisestone.owl.repository.IspFieldRepository;
import kr.wisestone.owl.service.CompanyFieldService;
import kr.wisestone.owl.service.IspFieldService;
import kr.wisestone.owl.service.WorkspaceService;
import kr.wisestone.owl.util.CommonUtil;
import kr.wisestone.owl.util.ConvertUtil;
import kr.wisestone.owl.vo.*;
import kr.wisestone.owl.web.condition.IspFieldCondition;
import kr.wisestone.owl.web.form.CompanyFieldForm;
import kr.wisestone.owl.web.form.IspFieldForm;
import kr.wisestone.owl.web.view.ExcelView;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
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.util.*;
import java.util.regex.Pattern;
 
@Service
public class IspFieldServiceImpl extends AbstractServiceImpl<IspField, Long, JpaRepository<IspField, Long>> implements IspFieldService {
 
    @Autowired
    private IspFieldRepository ispFieldRepository;
 
    @Autowired
    private IspFieldMapper ispFieldMapper;
 
    @Autowired
    private WorkspaceService workspaceService;
 
    @Autowired
    private CompanyFieldService companyFieldService;
 
    @Autowired
    private ExcelView excelView;
 
    @Autowired
    private ExcelConditionCheck excelConditionCheck;
 
    @Override
    protected JpaRepository<IspField, Long> getRepository() {
        return this.ispFieldRepository;
    }
 
    private static final int EXCEL_IMPORT_MAX_ROWS = 10000; //  excel import 제한
 
    // Isp 추가
    @Override
    public IspField add(IspFieldForm IspFieldForm) {
        //  ISP명 중복 체크
        //this.verifyTitle(IspFieldForm.getName(), null);
        
        if (IspFieldForm.getTelList() != null && IspFieldForm.getTelList().size() > 0) {
            String tels = IspFieldForm.getTelList().toString();
            if (tels.contains("[")) {
                tels = tels.substring(1, tels.indexOf("]"));
            }
            IspFieldForm.setTel(tels.trim());
        }
        if (IspFieldForm.getEmailList() != null && IspFieldForm.getEmailList().size() > 0) {
            String emails = IspFieldForm.getEmailList().toString();
            if (emails.contains("[")) {
                emails = emails.substring(1, emails.indexOf("]"));
            }
            IspFieldForm.setEmail(emails.trim());
        }
 
        IspField ispField = ConvertUtil.copyProperties(IspFieldForm, IspField.class);
 
        if (ispField.getCode() != null && !ispField.getCode().equals("")) {
            try {
                ispFieldRepository.saveAndFlush(ispField);
            } catch (Exception e) {
                throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISP_CODE_USED_EXIST_VALUE));
            }
        } else {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISP_CODE_NOT_ENTER));
        }
 
        return ispField;
    }
 
    // Isp 목록을 가져온다.
    @Override
    public List<IspFieldVo> find(Map<String, Object> resJsonData,
                                 IspFieldCondition condition, Pageable pageable) {
        condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
        condition.setPageSize(pageable.getPageSize());
 
        List<Map<String, Object>> results = this.ispFieldMapper.find(condition);
        Long totalIspCount = this.ispFieldMapper.count(condition);
 
        return this.convertIspVoToMap(results, totalIspCount, pageable, resJsonData);
    }
 
    public Map<String, Object> find(Long id) {
        return this.ispFieldMapper.findById(id);
    }
 
    // Isp 상세 조회한다.
    @Override
    public void detail(Map<String, Object> resJsonData, IspFieldCondition ispFieldCondition) {
        IspFieldVo IspFieldVo = new IspFieldVo();
 
        Long IspId = ispFieldCondition.getId();
        if (IspId != null) {
            IspField IspField = this.getIsp(IspId);
            IspFieldVo = ConvertUtil.copyProperties(IspField, IspFieldVo.class);
        }
        resJsonData.put(Constants.REQ_KEY_CONTENT, IspFieldVo);
    }
 
    // Isp 정로를 수정한다.
    @Override
    public void modify(IspFieldForm IspFieldForm) {
        //  ISP명 유효성 체크
        //this.verifyTitle(IspFieldForm.getName(), IspFieldForm.getId());
 
        if (IspFieldForm.getTelList() != null && IspFieldForm.getTelList().size() > 0) {
            String tels = IspFieldForm.getTelList().toString();
            if (tels.contains("[")) {
                tels = tels.substring(1, tels.indexOf("]"));
            }
            IspFieldForm.setTel(tels.trim());
        }
        if (IspFieldForm.getEmailList() != null && IspFieldForm.getEmailList().size() > 0) {
            String emails = IspFieldForm.getEmailList().toString();
            if (emails.contains("[")) {
                emails = emails.substring(1, emails.indexOf("]"));
            }
            IspFieldForm.setEmail(emails.trim());
        }
 
        IspField ispField = ConvertUtil.copyProperties(IspFieldForm, IspField.class);
 
        if (ispField.getCode() != null && !ispField.getCode().equals("")) {
            try {
                ispFieldRepository.saveAndFlush(ispField);
            } catch (Exception e) {
                throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISP_CODE_USED_EXIST_VALUE));
            }
        } else {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISP_CODE_NOT_ENTER));
        }
 
    }
 
 
    // Isp를 삭제한다.
    @Override
    public void remove(IspFieldForm IspFieldForm) {
        if (IspFieldForm.getRemoveIds().size() < 1) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISP_REMOVE_NOT_SELECT));
        }
        for (Long id : IspFieldForm.getRemoveIds()) {
            List<CompanyField> companyField = this.companyFieldService.findByIsp(id);
            if (companyField != null && companyField.size() > 0) {
                throw new OwlRuntimeException(
                        this.messageAccessor.getMessage(MsgConstants.ISP_EXIST_COMPANY));
            } else {
                this.ispFieldRepository.deleteById(id);
            }
        }
        this.ispFieldRepository.flush();
    }
 
    @Override
    @Transactional(readOnly = true)
    public List<IspField> findAll() {
        return this.ispFieldRepository.findAll();
    }
 
    // Isp 목록을 엑셀로 다운로드 한다.
    @Override
    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;
        }
 
        IspFieldCondition ispFieldCondition = IspFieldCondition.make(conditions);
 
 
        List<Map<String, Object>> results = this.ispFieldMapper.find(ispFieldCondition);
        List<IspFieldVo> ispFieldVos = ConvertUtil.convertListToListClass(results, IspFieldVo.class);
        // code_ko_KR 에 code명 설정
        ExportExcelVo excelInfo = new ExportExcelVo();
        excelInfo.setFileName(this.messageAccessor.message("Isp 목록"));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("name", this.messageAccessor.message("isp.ispName"), 6, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("code", this.messageAccessor.message("isp.ispCode"), 6, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("manager", this.messageAccessor.message("isp.ispManager"), 10, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("tel", this.messageAccessor.message("isp.ispTel"), 10, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("email", this.messageAccessor.message("isp.ispEmail"), 10, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("url", this.messageAccessor.message("isp.ispUrl"), 10, ExportExcelAttrVo.ALIGN_CENTER));
        excelInfo.addAttrInfos(new ExportExcelAttrVo("memo", this.messageAccessor.message("isp.ispMemo"), 10, ExportExcelAttrVo.ALIGN_CENTER));
 
        excelInfo.setDatas(ispFieldVos);
 
        model.addAttribute(Constants.EXCEL, excelInfo);
        return new ModelAndView(this.excelView);
    }
 
    //  ISP Import 용 엑셀 템플릿 다운로드
    @Override
    @Transactional
    public ModelAndView downloadExcelTemplate(HttpServletRequest request, Model model) {
 
        ExportExcelVo excelInfo = new ExportExcelVo();
        excelInfo.setHideCount(true);
        excelInfo.setFileName(this.messageAccessor.message("common.registerExcelIspField")); // 엑셀로 ISP 등록하기
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispName"), 20, ExportExcelAttrVo.ALIGN_CENTER)); // ISP명
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispCode"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 코드
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispManager"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 담당자
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispTel"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 연락처
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispEmail"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // 이메일
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispUrl"), 10, ExportExcelAttrVo.ALIGN_CENTER)); // url
        excelInfo.addAttrInfos(new ExportExcelAttrVo("id", this.messageAccessor.message("isp.ispMemo"), 40, ExportExcelAttrVo.ALIGN_CENTER)); // 비고
 
        //  엑셀에 넣을 데이터 - IspFieldVo 데이터를 엑셀에서 표시할 수 있는 데이터로 변경한다.
        excelInfo.setDatas(Lists.newArrayList(new IspFieldVo()));
 
        model.addAttribute(Constants.EXCEL, excelInfo);
        return new ModelAndView(this.excelView);
    }
 
    //  업로드 파일 확장자 체크
    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));
        }
    }
 
    //  엑셀 import 로 ISP를 등록한다.
    @Override
    @Transactional
    public void importExcel(MultipartFile multipartFile) throws Exception {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
 
        if (multipartFile != null) {
            //  업로드 파일 확장자 체크
            this.verifyMultipartFileExtension(multipartFile);
 
            List<IspFieldForm> ispFieldForms = Lists.newArrayList();
            List<String> headers = Lists.newArrayList();
 
            Workbook workbook;
 
            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) {
                    //  ISP로 등록하기 위해 ispFieldForm 에 데이터를 셋팅한다.
                    IspFieldForm newIspFieldForm = this.setIspFieldFormToExcelField(row, (rowIndex + 1), headers);
 
                    ispFieldForms.add(newIspFieldForm);
                }
            }
 
            if (ispFieldForms.size() < 1) {
                return;
            }
 
            for (IspFieldForm saveIspFieldForm : ispFieldForms) {
                IspField ispField = new IspField();
                ConvertUtil.copyProperties(saveIspFieldForm, ispField);
 
                if (ispField.getCode() != null && !ispField.getCode().equals("")) {
                    try {
                        ispField = ispFieldRepository.saveAndFlush(ispField);
                    } catch (Exception e) {
                        throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISP_CODE_USED_EXIST_VALUE));
                    }
                } else {
                    throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.ISP_CODE_NOT_ENTER));
                }
 
                saveIspFieldForm.setId(ispField.getId());
            }
        }
    }
 
    /**
     * 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 체크 함수
     * @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;
    }
 
    /**
     * 전화번호 CellType 체크 함수
     * @param cell Cell
     * @param rowIndex int
     */
    private void telTypeCheck (Cell cell, int rowIndex) {
        if (cell != null && cell.getCellType() != cell.CELL_TYPE_STRING) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_TEL_NOT_STRING_TYPE, rowIndex));
        }
    }
 
    //  엑셀 필드에 있는 정보를 ISP form 으로 옮긴다.
    private IspFieldForm setIspFieldFormToExcelField(Row row, int rowIndex, List<String> headers) {
        IspFieldForm ispFieldForm = new IspFieldForm();
        ispFieldForm.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:
                    //  ISP명
                    if (isNull) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_ISP_NAME_IS_NULL, rowIndex));
                    }
                    this.setIspFormName(cellStr, ispFieldForm);
                    break;
 
                case 1:
                    //  코드
                    if (isNull) {
                        throw new OwlRuntimeException(
                                this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_ISP_CODE_IS_NULL, rowIndex));
                    }
                    this.setIspFormCode(cellStr, ispFieldForm);
                    break;
 
                case 2:
                    // 담당자
                    this.setIspFormManager(cellStr, ispFieldForm, isNull);
                    break;
 
                case 3:
                    // 연락처
                    telTypeCheck(cell, rowIndex);
                    this.setIspFormTel(cellStr, ispFieldForm, rowIndex, isNull);
                    break;
 
                case 4:
                    // 이메일
                    this.setIspFormEmail(cellStr, ispFieldForm, isNull);
                    break;
 
                case 5:
                    // url
                    this.setIspFormUrl(cellStr, ispFieldForm, isNull);
                    break;
 
                case 6:
                    // 비고
                    this.setIspFormMemo(cellStr, ispFieldForm, isNull);
            }
        }
 
        return ispFieldForm;
    }
 
    private void setIspFormMemo(String memo, IspFieldForm ispFieldForm, boolean isNull) {
        if (!isNull) {
            ispFieldForm.setMemo(memo);
        }
    }
 
    private void setIspFormUrl(String url, IspFieldForm ispFieldForm, boolean isNull) {
        if (!isNull) {
            if (url.contains(" ")) {
                url = url.replace(" ", "");
            }
            ispFieldForm.setUrl(url);
        }
    }
 
    private void setIspFormEmail(String email, IspFieldForm ispFieldForm, boolean isNull) {
        if (!isNull) {
            //  이메일 유효성 검사
            email = this.verifyEmail(email);
            ispFieldForm.setEmail(email);
        }
    }
 
    /**
     * 이메일 유효성 검사
     * @param email String
     * @return String
     */
    private String verifyEmail(String email) {
        if (!Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", email)) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EMAIL_NOT_INVALID));
        }
 
        if (email.contains(" ")) {
            email = email.replace(" ", "");
        }
 
        return email;
    }
 
    private void setIspFormTel(String tel, IspFieldForm ispFieldForm, int rowIndex, boolean isNull) {
        if (!isNull) {
            //  연락처 유효성 검사
            tel = this.verifyTel(tel);
            ispFieldForm.setTel(tel);
        }
    }
 
    /**
     * 연락처 유효성 검사
     * @param tel String
     * @return String
     */
    private String verifyTel(String tel) {
        if (!Pattern.matches("^[0-9-]{2,20}$", tel)) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.TEL_NOT_INVALID));
        }
 
        if (tel.contains("-")) {
            tel = tel.replace("-", "");
        }
        if (tel.contains(" ")) {
            tel = tel.replace(" ", "");
        }
 
        return tel;
    }
 
    private void setIspFormManager(String manager, IspFieldForm ispFieldForm, boolean isNull) {
        if (!isNull) {
            ispFieldForm.setManager(manager);
        }
    }
 
    private void setIspFormCode(String code, IspFieldForm ispFieldForm) {
        //코드 유효성 체크
        this.verifyCode(code);
        ispFieldForm.setCode(code);
    }
 
    /**
     * 코드 유효성 검사
     * @param code String
     */
    private void verifyCode(String code) {
        if (!Pattern.matches("^[a-zA-Z0-9가-힣ㄱ-ㅎㅏ-ㅣ\\u318D\\u119E\\u11A2\\u2022\\u2025a\\u00B7\\uFE55]+$", code)) {
            throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.CODE_NOT_INVALID));
        }
    }
 
    private void setIspFormName(String title, IspFieldForm ispFieldForm) {
        //  ISP명 유효성 체크
        //this.verifyTitle(title, null);
        ispFieldForm.setName(title);
    }
 
    //  ISP명 유효성 체크
    private void verifyTitle(String title, Long id) {
        List<IspField> ispFields = new ArrayList<>();
 
        //  ISP명 중복 체크
 
        if (id != null) { //수정 일 경우
            ispFields = this.ispFieldRepository.findByNameAndIdNot(title, id);
        } else { // 추가 일 경우
            ispFields = this.ispFieldRepository.findByName(title);
        }
        if (ispFields != null && ispFields.size() > 0) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISP_NAME_ALREADY_IN_USE));
        }
 
        //  ISP명 빈값 체크
        if (StringUtils.isEmpty(title)) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISP_NO_TITLE));
        }
 
        //  ISP명 길이 체크
        if (title.length() > 300) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISP_NAME_MAX_LENGTH_OUT));
        }
    }
 
    //  검색 결과를 IspVo 로 변환한다.
    private List<IspFieldVo> convertIspVoToMap(List<Map<String, Object>> results, Long totalIspCount, Pageable pageable, Map<String, Object> resJsonData) {
        List<IspFieldVo> ispFieldVos = Lists.newArrayList();
 
        for (Map<String, Object> result : results) {
            IspFieldVo IspFieldVo = ConvertUtil.convertMapToClass(result, IspFieldVo.class);
            ispFieldVos.add(IspFieldVo);
        }
 
        int totalPage = (int) Math.ceil((totalIspCount - 1) / pageable.getPageSize()) + 1;
 
        resJsonData.put(Constants.RES_KEY_CONTENTS, ispFieldVos);
        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
                totalPage, totalIspCount));
 
        return ispFieldVos;
    }
 
    // Isp ID 로 조회한다
    @Override
    public IspField getIsp(Long id) {
        if (id == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISP_NOT_EXIST));
        }
 
        IspField IspField = this.findOne(id);
 
        if (IspField == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISP_NOT_EXIST));
        }
        return IspField;
    }
 
 
}