adminserviceimpl.java

来自「一个关于tlms的一个小程序 看看能否帮助到别人」· Java 代码 · 共 452 行 · 第 1/2 页

JAVA
452
字号
        employee.populateUpdateBean(userId);
        adminDao.saveEmployee(employee);

        // system log:
        Log log = new Log();
        log.setEmpId(employee.getEmpId());
        log.setActionCode(GlobalConstants.LOG_ACTION_TYPE_REST_PASSWORD);
        Employee actionEmp = getEmployee(userId);
        if (actionEmp != null) {
            log.setActionBy(actionEmp.getEmpId());
        }
        log.populateCreateBean(userId);
        logService.saveLog(log);

        // send mail:
        String subject = SysPropertiesUtil.getProperty("mail.msg.subject.admin.resetPassword");
        String template = SysPropertiesUtil.getProperty("mail.msg.template.admin.resetPassword");
        mailService.sendMail(employee.getEmail(), subject, template, new HashMap());
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#resetPasswordBySelf(java.util.Map)
     */
    public void resetPasswordBySelf(Map map) throws TlmsServiceException {
        Long id = (Long) map.get("userId");
        String oldPassword = (String) map.get("oldPassword");
        String newPassword1 = (String) map.get("newPassword1");
        String newPassword2 = (String) map.get("newPassword2");
        if (!newPassword1.equals(newPassword2)) {
            throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD004);
        }
        Employee employee = adminDao.getEmployee(id);
        if (employee != null) {
            if (!oldPassword.equals(employee.getPassword()))
                throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD005);
        }
        employee.setPassword(newPassword1);
        adminDao.saveEmployee(employee);
    }

    /**
     * This method is to validate if the employee with the specific employeeId has existed
     *
     * @param empId
     * @return boolean
     * @throws TlmsServiceException
     */
    private boolean validateConflictEmployeeId(String empId) throws TlmsServiceException {
        return getEmployee(empId) != null;
    }

    /**
     * This method is to generate random password
     *
     * @return String
     */
    private String newRandomPassword() {   //todo
        String[] str = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
                "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
                "U", "V", "W", "X", "Y", "Z",
                "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
                "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
                "u", "v", "w", "x", "y", "z",
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
        StringBuffer password = new StringBuffer();
        for (int i = 0; i < 6; i++) {
            password.append(str[(int) Math.floor(Math.random() * 62)]);
        }
        return password.toString();
    }

    // Role Managerment: ----------------------------------------

    /**
     * @throws TlmsServiceException
     * @see AdminService#getRoles(java.util.Map, com.szmx.framework.base.model.Pagination)
     */
    public Pagination getRoles(Map paraMap, Pagination pagination) throws TlmsServiceException {
        Role searchBean = (Role) paraMap.get("searchBean");
        Map pMap = new HashMap();
        pMap.put("roleName", searchBean.getName());
        return adminDao.searchRoles(pagination, pMap);
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#searchNotAssignedRoles(Long)
     */
    public List searchNotAssignedRoles(Long id) throws TlmsServiceException {
        return adminDao.searchNotAssignedRoles(id);
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#searchAssignedRoles(Long)
     */
    public List searchAssignedRoles(Long id) throws TlmsServiceException {
        return adminDao.searchAssignedRoles(id);
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#getRole(Long)
     */
    public Role getRole(Long id) throws TlmsServiceException {
        return adminDao.getRole(id);
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#removeRole(String[])
     */
    public void removeRole(String[] idArr) throws TlmsServiceException {
        for (int i = 0; i < idArr.length; i++) {
            if (adminDao.searchEmpRoleRelation(new Long(idArr[i])).size() > 0) {
                throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD007);
            }
            Role role = adminDao.getRole(new Long(idArr[i]));
            role.setStatus(GlobalConstants.EMP_STATUS_INACTIVE);
            adminDao.saveRole(role);
            adminDao.removeAllResFromRole(role.getId());
        }
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#addRoleWithResource(java.util.Map)
     */
    public void addRoleWithResource(Map role_res_map) throws TlmsServiceException {
        Role role = (Role) role_res_map.get("roleBean");
        List resList = (List) role_res_map.get("roleRes");
        if (adminDao.getRoleByName(role.getName()) != null) {
            throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD006);
        }
        role.setName(role.getName().toUpperCase());
        adminDao.saveRole(role);
        //get roleId after add role
        Long newRoleId = adminDao.getRoleByName(role.getName()).getId();
        if (newRoleId != null && !role.getStatus().equals(GlobalConstants.EMP_STATUS_INACTIVE)) {
            adminDao.addBasicResForRole(newRoleId);
            addResourceForRole(newRoleId, resList);
        }
    }

    /**
     * @throws TlmsServiceException
     * @see AdminService#updateRoleWithResource(java.util.Map)
     */
    public void updateRoleWithResource(Map role_res_map) throws TlmsServiceException {
        Role role = (Role) role_res_map.get("roleBean");
        List resList = (List) role_res_map.get("roleRes");
        if (role.getId() != null) {
            Role r = adminDao.getRole(role.getId());
            if (!r.getName().equalsIgnoreCase(role.getName())) {
                if (adminDao.getRoleByName(role.getName()) != null) {
                    throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_AD006);
                }
            }
            r.setName(role.getName());
            r.setRemarks(role.getRemarks());
            r.setStatus(role.getStatus());
            r.setUpdatedId(role.getUpdatedId());
            r.setUpdatedTs(role.getUpdatedTs());
            adminDao.saveRole(r);
            adminDao.removeAllResFromRole(role.getId());
            if (!role.getStatus().equals(GlobalConstants.EMP_STATUS_INACTIVE)) {
                adminDao.addBasicResForRole(role.getId());
                addResourceForRole(role.getId(), resList);
            }
        }
    }

    /**
     * @return List
     * @throws TlmsServiceException
     * @see AdminService#getRoleResource(Long)
     */
    public List getRoleResource(Long roleId) throws TlmsServiceException {
        return adminDao.getRoleResource(roleId);
    }

    /**
     * @param modId
     * @return Resource
     * @throws TlmsServiceException
     * @see AdminService#getResourceModByModId(Long)
     */
    public Resource getResourceModByModId(Long modId) throws TlmsServiceException {
        return adminDao.getResourceModByModId(modId);
    }

    /**
     * This method is to add resource for a role
     *
     * @param roleId  (role id)
     * @param roleRes (resource list)
     * @throws TlmsServiceException
     */
    private void addResourceForRole(Long roleId, List roleRes) throws TlmsServiceException {
        for (Iterator i = roleRes.iterator(); i.hasNext();) {
            RelRoleResource relRoleRes = new RelRoleResource(roleId, new Long((String) i.next()));
            adminDao.addResourceForRole(relRoleRes);
        }
    }

    // Department Managerment: ----------------------------------------

    /**
     * @throws TlmsServiceException
     * @see AdminService#searchDepartment(com.szmx.framework.base.model.Pagination, java.util.Map)
     */
    public Pagination searchDepartment(Pagination pagination, Map paraMap) throws TlmsServiceException {
        return adminDao.searchDepartment(pagination, paraMap);
    }

    /**
     * @throws TlmsServiceException
     * @see com.szmx.tlms.admin.service.AdminService#getDepartmentList()
     */
    public List getDepartmentList() throws TlmsServiceException {
        return adminDao.getDepartmentList();
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?