Search in sources :

Example 1 with UserRoleVO

use of com.netsteadfast.greenstep.vo.UserRoleVO in project bamboobsc by billchen198318.

the class RoleLogicServiceImpl method updateUserRole.

/**
	 * 更新帳戶的role
	 * 
	 * @param accountOid
	 * @param roles
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> updateUserRole(String accountOid, List<String> roles) throws ServiceException, Exception {
    if (super.isBlank(accountOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    AccountVO account = new AccountVO();
    account.setOid(accountOid);
    DefaultResult<AccountVO> aResult = this.accountService.findObjectByOid(account);
    if (aResult.getValue() == null) {
        throw new ServiceException(aResult.getSystemMessage().getValue());
    }
    account = aResult.getValue();
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    result.setValue(false);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
    this.deleteUserRoleByAccount(account);
    for (int i = 0; roles != null && i < roles.size(); i++) {
        String roleOid = roles.get(i).trim();
        if (super.isBlank(roleOid)) {
            continue;
        }
        RoleVO role = new RoleVO();
        role.setOid(roleOid);
        DefaultResult<RoleVO> rResult = this.roleService.findObjectByOid(role);
        if (rResult.getValue() == null) {
            throw new ServiceException(rResult.getSystemMessage().getValue());
        }
        role = rResult.getValue();
        UserRoleVO userRole = new UserRoleVO();
        userRole.setAccount(account.getAccount());
        userRole.setRole(role.getRole());
        userRole.setDescription("");
        DefaultResult<UserRoleVO> urResult = this.userRoleService.saveObject(userRole);
        if (urResult.getValue() == null) {
            throw new ServiceException(urResult.getSystemMessage().getValue());
        }
    }
    result.setValue(true);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) AccountVO(com.netsteadfast.greenstep.vo.AccountVO) UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) SysMenuRoleVO(com.netsteadfast.greenstep.vo.SysMenuRoleVO) RoleVO(com.netsteadfast.greenstep.vo.RoleVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserRoleVO

use of com.netsteadfast.greenstep.vo.UserRoleVO in project bamboobsc by billchen198318.

the class EmployeeLogicServiceImpl method create.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<EmployeeVO> create(EmployeeVO employee, List<String> organizationOid) throws ServiceException, Exception {
    if (employee == null || super.isBlank(employee.getEmpId())) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("empId", employee.getEmpId());
    if (this.getEmployeeService().countByParams(params) > 0) {
        throw new ServiceException("Please change another Id!");
    }
    AccountVO account = this.tranAccount(employee);
    if (this.isAdministrator(account.getAccount())) {
        throw new ServiceException("Please change another Account!");
    }
    DefaultResult<AccountVO> mResult = this.getAccountService().saveObject(account);
    if (mResult.getValue() == null) {
        throw new ServiceException(mResult.getSystemMessage().getValue());
    }
    DefaultResult<EmployeeVO> result = this.getEmployeeService().saveObject(employee);
    employee = result.getValue();
    this.createEmployeeOrganization(employee, organizationOid);
    // create default role
    UserRoleVO userRole = new UserRoleVO();
    userRole.setAccount(employee.getAccount());
    userRole.setRole(this.roleLogicService.getDefaultUserRole());
    userRole.setDescription(employee.getAccount() + " `s role!");
    this.getUserRoleService().saveObject(userRole);
    this.createHierarchy(employee, BscConstants.EMPLOYEE_HIER_ZERO_OID);
    return result;
}
Also used : EmployeeVO(com.netsteadfast.greenstep.vo.EmployeeVO) UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AccountVO(com.netsteadfast.greenstep.vo.AccountVO) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)2 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)2 UserRoleVO (com.netsteadfast.greenstep.vo.UserRoleVO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)1 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)1 EmployeeVO (com.netsteadfast.greenstep.vo.EmployeeVO)1 RoleVO (com.netsteadfast.greenstep.vo.RoleVO)1 SysMenuRoleVO (com.netsteadfast.greenstep.vo.SysMenuRoleVO)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1