package com.dbnt.faisp.kwms.service; import com.dbnt.faisp.kwms.model.VEmployee; import com.dbnt.faisp.kwms.repository.VEmployeeRepository; import com.dbnt.faisp.main.codeMgt.service.CodeMgtService; import com.dbnt.faisp.main.userInfo.model.UserInfo; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @Service @RequiredArgsConstructor public class KwmsService { private final VEmployeeRepository vEmployeeRepository; private final CodeMgtService codeMgtService; public UserInfo selectEmpInfo(String dicCode){ VEmployee empInfo = vEmployeeRepository.findByDicCode(dicCode).orElse(null); if(empInfo==null){ return null; }else{ return convertVEmployeeToUserInfo(empInfo); } } private UserInfo convertVEmployeeToUserInfo(VEmployee empInfo){ UserInfo userInfo = new UserInfo(); userInfo.setDicCode(empInfo.getDicCode()); userInfo.setUserNm(empInfo.getEmpNm()); userInfo.setSex(empInfo.getSex()); String[] positionAry = empInfo.getCallBuseoNm().split(" "); userInfo.setOgCd(codeMgtService.searchCode("OG", positionAry[0])); if (positionAry.length>1){ userInfo.setOfcCd(codeMgtService.searchCode("OFC", positionAry[1])); } userInfo.setTitleCd(codeMgtService.searchCode("JT", empInfo.getJikgeup())); userInfo.setOutturnCd(codeMgtService.searchCode("OTC", empInfo.getGyunggwa())); userInfo.setSeriesCd(codeMgtService.searchCode("SRC", empInfo.getJikbyul())); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); empInfo.setBirthDate( (Integer.parseInt(empInfo.getBirthDate().substring(0,2))>60?"19":"20")+empInfo.getBirthDate()); userInfo.setBirthDate(LocalDate.parse(empInfo.getBirthDate(), formatter)); userInfo.setPoliceInDate(LocalDate.parse(empInfo.getPoliceBmngIl(), formatter)); userInfo.setTitleInDate(LocalDate.parse(empInfo.getHnJikgeupImyngil(), formatter)); return userInfo; } }