Search in sources :

Example 26 with BusinessException

use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.

the class WxMpMemberAuthServiceImpl method applyToken.

@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(String code, String state) throws Exception {
    // 校验STATE
    if (V.notEmpty(STATE) && !STATE.equals(state)) {
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "非法来源");
    }
    if (V.isEmpty(code)) {
        log.error("请求参数有误: code = null");
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "请求参数有误: code is null");
    }
    WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
    // 获取用户信息
    IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamMember.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
    MobileCredential credential = new MobileCredential(accessToken.getOpenId());
    credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
    credential.setUserTypeClass(IamMember.class);
    // 账户存在,直接登陆
    if (V.notEmpty(account)) {
        return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
    }
    // 账户不存在,表示首次进入,那么需要存储信息
    WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);
    IamMember iamMember = mpInfo2IamMemberEntity(userInfo).setUserId(0L).setOrgId(0L).setUserType(IamMember.class.getSimpleName());
    iamMemberService.createEntity(iamMember);
    // 创建iam_account账号
    IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getId(), IamMember.class);
    iamAccountService.createEntity(iamAccount);
    return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
Also used : MobileCredential(com.diboot.mobile.dto.MobileCredential) BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) IamMember(com.diboot.mobile.entity.IamMember) WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) WxOAuth2UserInfo(me.chanjar.weixin.common.bean.WxOAuth2UserInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with BusinessException

use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.

the class WxMpUserAuthServiceImpl method applyToken.

@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(String code, String state) throws Exception {
    // 校验STATE
    if (V.notEmpty(STATE) && !STATE.equals(state)) {
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "非法来源");
    }
    if (V.isEmpty(code)) {
        log.error("请求参数有误: code = null");
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "请求参数有误: code is null");
    }
    WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
    // 获取用户信息
    IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamUser.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
    MobileCredential credential = new MobileCredential(accessToken.getOpenId());
    credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
    // 账户存在,直接登陆
    if (V.isEmpty(account)) {
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "请登陆后绑定再使用快捷登陆");
    }
    return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
Also used : MobileCredential(com.diboot.mobile.dto.MobileCredential) BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with BusinessException

use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.

the class IamOrgServiceImpl method sortList.

@Override
public void sortList(List<IamOrg> orgList) {
    if (V.isEmpty(orgList)) {
        throw new BusinessException(Status.FAIL_OPERATION, "排序列表不能为空");
    }
    List<Long> sortIdList = new ArrayList();
    // 先将所有序号重新设置为自身当前id
    for (IamOrg item : orgList) {
        item.setSortId(item.getId());
        sortIdList.add(item.getSortId());
    }
    // 将序号列表倒序排序
    sortIdList = sortIdList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    // 整理需要更新的列表
    List<IamOrg> updateList = new ArrayList<>();
    for (int i = 0; i < orgList.size(); i++) {
        IamOrg item = orgList.get(i);
        IamOrg updateItem = new IamOrg();
        updateItem.setId(item.getId());
        updateItem.setSortId(sortIdList.get(i));
        updateList.add(updateItem);
    }
    if (updateList.size() > 0) {
        super.updateBatchById(updateList);
    }
}
Also used : BusinessException(com.diboot.core.exception.BusinessException) IamOrg(com.diboot.iam.entity.IamOrg)

Example 29 with BusinessException

use of com.diboot.core.exception.BusinessException in project diboot by dibo-software.

the class ScheduleJobServiceImpl method executeOnceJob.

@Override
public boolean executeOnceJob(Long jobId) {
    // 如果已经存在job,那么直接恢复,否则添加job
    if (!quartzSchedulerService.existJob(jobId)) {
        ScheduleJob entity = this.getEntity(jobId);
        if (V.isEmpty(entity)) {
            throw new BusinessException(Status.FAIL_OPERATION, "当前任务无效!");
        }
        quartzSchedulerService.addJobExecuteOnce(entity);
    } else {
        quartzSchedulerService.runJob(jobId);
    }
    return true;
}
Also used : ScheduleJob(com.diboot.scheduler.entity.ScheduleJob) BusinessException(com.diboot.core.exception.BusinessException)

Aggregations

BusinessException (com.diboot.core.exception.BusinessException)29 Transactional (org.springframework.transaction.annotation.Transactional)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)5 IamAccount (com.diboot.iam.entity.IamAccount)5 InvalidUsageException (com.diboot.core.exception.InvalidUsageException)4 IamMember (com.diboot.mobile.entity.IamMember)4 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 Dictionary (com.diboot.core.entity.Dictionary)3 UploadFile (com.diboot.file.entity.UploadFile)3 IamResourcePermission (com.diboot.iam.entity.IamResourcePermission)3 BaseJwtAuthToken (com.diboot.iam.jwt.BaseJwtAuthToken)3 IamResourcePermissionListVO (com.diboot.iam.vo.IamResourcePermissionListVO)3 ScheduleJob (com.diboot.scheduler.entity.ScheduleJob)3 HashMap (java.util.HashMap)3 WxOAuth2AccessToken (me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken)3 AuthenticationException (org.apache.shiro.authc.AuthenticationException)3 Subject (org.apache.shiro.subject.Subject)3 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)2 BaseService (com.diboot.core.service.BaseService)2 DictionaryService (com.diboot.core.service.DictionaryService)2