OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-02-22 6a916b069c73ad7def95ad72ae848125544bc309
src/main/java/kr/wisestone/owl/service/impl/UserServiceImpl.java
@@ -12,6 +12,7 @@
import kr.wisestone.owl.domain.enumType.SocialType;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.mapper.UserMapper;
import kr.wisestone.owl.repository.DepartmentRepository;
import kr.wisestone.owl.repository.UserRepository;
import kr.wisestone.owl.service.*;
import kr.wisestone.owl.util.*;
@@ -55,6 +56,15 @@
    private UserRepository userRepository;
    @Autowired
    private DepartmentRepository departmentRepository;
    @Autowired
    private UserLevelService userLevelService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private SystemRoleService systemRoleService;
    @Autowired
@@ -82,6 +92,9 @@
    private ProjectService projectService;
    @Autowired
    private IssueTypeService issueTypeService;
    @Autowired
    private UserSecurityService userSecurityService;
    @Autowired
@@ -92,6 +105,9 @@
    @Autowired
    private AttachedFileService attachedFileService;
    @Autowired
    private UserDepartmentService userDepartmentService;
    @Autowired
    private IssueService issueService;
@@ -156,6 +172,9 @@
    @Value("${total.statistics.email}")
    private String totalStatisticsEmail; //  프로젝트, 이슈, 사용자수 알림
    @Value("${email.joinEmail}")
    private boolean bJoinEmail;
    @Autowired
    private ExcelView excelView;
@@ -197,7 +216,8 @@
        user.setAccount(CommonUtil.encryptAES128(userForm.getAccount()));
        user.setPassword(this.passwordEncoder.encode(user.getPassword()));
        this.userRepository.saveAndFlush(user);
        //this.userLevelRepository.saveAndFlush(user);
        //userLevelRepository.saveAndFlush(user);
        //  프로필 파일이 유효한지 체크한다.
        this.verifyProfile(profile);
@@ -217,11 +237,28 @@
            this.userInviteService.includePrimaryWorkspace(user, primaryWorkspace);
            UserLevel userLevel = this.userLevelService.getBasicUserLevel();
            user.setUserLevel(userLevel);
            // edit by zenith for permission at 20200803
            user.setPermission(MngPermission.USER_PERMISSION_MNG_NONE);
            /*user.setPermission(MngPermission.USER_PERMISSION_MNG_NONE);*/
        } else if(validAdmin == 1) {    // 라이센스 입력 관리자
            /*DepartmentForm departmentForm = new DepartmentForm();
            departmentForm.setDepartmentName("부서 없음");
            Department department = this.departmentService.add(departmentForm);
            this.departmentRepository.saveAndFlush(department);*/
            Workspace primaryWorkspace = this.workspaceService.getPrimaryWorkspace();
            UserLevel userLevel = this.userLevelService.addSuperUserLevel();
            user.setUserLevel(userLevel);
            this.userLevelService.addNormalAdminUserLevel();
            this.userLevelService.addNormalUserLevel();
            if(primaryWorkspace == null || primaryWorkspace.getName() != userForm.getWorkspaceName()) {
                //  업무 공간를 생성한다. 가입한 사용자는 업무 공간의 주인이다.
@@ -229,23 +266,25 @@
                this.userWorkspaceService.addUserWorkspace(user, workspace, true, true);
                //  기본으로 제공되는 프로젝트를 생성한다.
//                this.projectService.addDefaultProject(user, workspace);
                this.projectService.addDefaultProject(user, workspace);
                // 기본으로 제공되는 프로젝트를 이슈 유형의 사용 프로젝트로 설정
                this.issueTypeService.addDefaultUsedProject(workspace);
                user.setLastWorkspaceId(workspace.getId());
                // edit by zenith for permission at 20200803
                user.setPermission(MngPermission.makeAllPermission());
                //user.setPermission(MngPermission.makeAllPermission());
            } else  {
                this.userInviteService.includePrimaryWorkspace(user, primaryWorkspace);
                user.setLastWorkspaceId(primaryWorkspace.getId());
                user.setPermission(MngPermission.makeSubAllPermission());
                /*user.setPermission(MngPermission.makeSubAllPermission());*/
            }
        }
        this.userRepository.saveAndFlush(user);
        //  이메일 알림 예정 시간이 공백이면 디폴트 이메일 알림 예정 시간으로 설정한다.
        user.setReservationNotifyTime(User.DEFAULT_RESERVATION_NOTIFY_TIME);
        this.userRepository.saveAndFlush(user);
        //  초대받은 메일이 있는 사용자가 가입했으면 초대했을 때 선택한 프로젝트에 참여 시킨다.
        this.userInviteService.checkInviteUser(user);
@@ -256,8 +295,9 @@
        userMap.put("registerDate", DateUtil.convertDateToYYYYMMDD(user.getRegisterDate()));
        //  회원 가입 알림 메일 전송
        this.systemEmailService.directEmail(new String[]{user.getAccount()}, EmailType.WORKSPACE_JOIN, userMap, null);
        if(bJoinEmail) {
            this.systemEmailService.directEmail(new String[]{user.getAccount()}, EmailType.WORKSPACE_JOIN, userMap, null);
        }
        return user;
    }
@@ -513,8 +553,12 @@
            User user = this.getUser(userCondition.getId());
            userVo = ConvertUtil.copyProperties(user, UserVo.class, "password");
            userVo.setAccount(CommonUtil.decryptAES128(userVo.getAccount()));
        }
            Map<String, Object> projectManagerYN = this.projectRoleUserService.findProjectManager((userCondition.getId()));
            if(projectManagerYN != null){
                userVo.setProjectManagerYN(true);
            }
        }
        resJsonData.put(Constants.RES_KEY_CONTENTS, userVo);
    }
@@ -921,6 +965,15 @@
        return this.convertUserVoToMap(results, totalUsersCount, pageable, resJsonData);
    }
    //  사용자 정보를 가져온다.
    @Override
    @Transactional(readOnly = true)
    public void findMyLevelAndDepartment(Map<String, Object> resJsonData) {
        Long loginId = this.webAppUtil.getLoginId();
        Map<String, Object> result = this.userMapper.findByMyLevelAndDepartment(loginId);
        resJsonData.put(Constants.RES_KEY_CONTENTS, result);
    }
    //  사용자 아이디로 사용자를 조회한다.
    @Override
    @Transactional(readOnly = true)
@@ -1005,7 +1058,13 @@
        this.userRepository.saveAndFlush(user);
    }
        //  마지막으로 선택한 프로젝트 정보를 저장한다.
    //  삭제 할 등급명을 유저가 사용하고 있는지 확인
    @Override
    public boolean useUserLevel(Long levelId) {
        return this.userMapper.findByLevelId(levelId) > 0;
    }
    //  마지막으로 선택한 프로젝트 정보를 저장한다.
    @Override
    @Transactional
    public void updateLastProject(Map<String, Object> resJsonData, UserForm userForm) {
@@ -1030,6 +1089,30 @@
        resJsonData.put(Constants.RES_KEY_CONTENTS, userVo);
    }
    //  마지막으로 선택한 이슈 타입 정보를 저장한다.
    @Override
    @Transactional
    public void updateLastIssueType(Map<String, Object> resJsonData, UserForm userForm) {
        User user = this.getUser(this.webAppUtil.getLoginId());
        if (userForm.getLastIssueTypeId() != null) {
            user.setLastIssueTypeId(userForm.getLastIssueTypeId());
        }
        this.userRepository.saveAndFlush(user);
        //  세션 업데이트
        SecurityUtils.setUserToSession(user);
        //  클라이언트의 사용자 정보 업데이트
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class, "password");
        if (user.getSocialType() != null) {
            userVo.setSocialType(user.getSocialType().toString());
        }
        userVo.setAccount(CommonUtil.decryptAES128(userVo.getAccount()));
        resJsonData.put(Constants.RES_KEY_CONTENTS, userVo);
    }
    //  특정 아이디에 해당하는 사용자 목록을 가져온다.
    @Override
    @Transactional(readOnly = true)
@@ -1041,7 +1124,7 @@
    @Override
    @Transactional(readOnly = true)
    public List<User> findAdmin() {
        return this.userRepository.findAdmin();
        return this.userRepository.findAdmin(MngPermission.makeAllPermission());
    }
    //  해당 사용자가 관리하는 업무 공간을 마지막으로 접근한 업무 공간 정보로 업데이트한다.
@@ -1150,6 +1233,7 @@
        }
    }
    //  업무 공간에서 제외되거나 업무 공간 삭제시 참여 사용자들의 마지막 접근 업무 공간 정보로 세션 업데이트하기 위해 사용
    @Override
    @Transactional(readOnly = true)
@@ -1165,7 +1249,18 @@
    public User getUserSession(Map<String, Object> resJsonData, HttpServletRequest httpServletRequest) {
        User user = this.getUser(this.webAppUtil.getLoginId());
        UserVo userVo = ConvertUtil.copyProperties(user, UserVo.class, "password");
        // user에서 Permission 값을 가져와서 userVo 에 setPermission 함
        userVo.setAccount(CommonUtil.decryptAES128(userVo.getAccount()));
        UserLevel userLevel = user.getUserLevel();
        if (userLevel != null) {
            userVo.setLevelName(userLevel.getLevelName());
        }
        List<Department> departments = this.userDepartmentService.findDepartment(user.getId());
        if (departments != null) {
            userVo.setDepartmentVos(ConvertUtil.convertObjectsToClasses(departments, DepartmentVo.class));
        }
        resJsonData.put(Constants.RES_KEY_CONTENTS, userVo);
        //  사용자 세션 정보를 분석해서 로그에 남긴다.
        log.info(ElasticSearchUtil.makeUserSessionHistoryMessage(httpServletRequest, userVo));
@@ -1191,6 +1286,22 @@
        conditions.put("endTime", DateUtil.convertDateToStr(endCal.getTime(), "HH:mm"));
        List<Map<String, Object>> users = this.userMapper.findByReservationNotifyTime(conditions);
        List<String> results = Lists.newArrayList();
        for (Map<String, Object> user : users) {
            results.add(MapUtil.getString(user, "account"));
        }
        return results;
    }
    //  이메일 알림 예정 시간을 실시간으로 설정한 사용자를 조회한다.
    @Override
    @Transactional(readOnly = true)
    public List<String> findByRealTimeNotifyTime() {
        Map<String, Object> conditions = new HashMap<>();
        List<Map<String, Object>> users = this.userMapper.findByRealTimeNotifyTime(conditions);
        List<String> results = Lists.newArrayList();
        for (Map<String, Object> user : users) {
@@ -1266,15 +1377,17 @@
        userMap.put("newUserCount", joinUsers.size());
        userMap.put("joinUsers", userVos);
        String[] sendEmails = this.userJoinStatisticsEmail.replaceAll("\\p{Z}", "").split(",");
        List<String> encryptSendEmail = Lists.newArrayList();
        if (this.userJoinStatisticsEmail != null && !this.userJoinStatisticsEmail.equals("")) {
            String[] sendEmails = this.userJoinStatisticsEmail.replaceAll("\\p{Z}", "").split(",");
            List<String> encryptSendEmail = Lists.newArrayList();
        for (String sendEmail : sendEmails) {
            encryptSendEmail.add(CommonUtil.encryptAES128(sendEmail));
            for (String sendEmail : sendEmails) {
                encryptSendEmail.add(CommonUtil.encryptAES128(sendEmail));
            }
            //  결제 성공 메일 발송
            this.systemEmailService.directEmail(encryptSendEmail.toArray(new String[encryptSendEmail.size()]), EmailType.USER_JOIN_STATISTICS, userMap, null);
        }
        //  결제 성공 메일 발송
        this.systemEmailService.directEmail(encryptSendEmail.toArray(new String[encryptSendEmail.size()]), EmailType.USER_JOIN_STATISTICS, userMap, null);
    }
    //  전체 사용자, 프로젝트 수, 이슈 수를 이메일로 보낸다.
@@ -1292,15 +1405,17 @@
        userMap.put("projectCount", CommonUtil.getDecimalFormat(projectCount));
        userMap.put("userCount", CommonUtil.getDecimalFormat(activeUsers.size()));
        String[] sendEmails = this.totalStatisticsEmail.replaceAll("\\p{Z}", "").split(",");
        List<String> encryptSendEmail = Lists.newArrayList();
        if (this.totalStatisticsEmail != null && !this.totalStatisticsEmail.equals("")) {
            String[] sendEmails = this.totalStatisticsEmail.replaceAll("\\p{Z}", "").split(",");
            List<String> encryptSendEmail = Lists.newArrayList();
        for (String sendEmail : sendEmails) {
            encryptSendEmail.add(CommonUtil.encryptAES128(sendEmail));
            for (String sendEmail : sendEmails) {
                encryptSendEmail.add(CommonUtil.encryptAES128(sendEmail));
            }
            //  결제 성공 메일 발송
            this.systemEmailService.directEmail(encryptSendEmail.toArray(new String[encryptSendEmail.size()]), EmailType.TOTAL_STATISTICS, userMap, null);
        }
        //  결제 성공 메일 발송
        this.systemEmailService.directEmail(encryptSendEmail.toArray(new String[encryptSendEmail.size()]), EmailType.TOTAL_STATISTICS, userMap, null);
    }