Search in sources :

Example 86 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class ThirdLoginController method getThirdLoginUser.

@SuppressWarnings("unchecked")
@RequestMapping(value = "/getLoginUser/{token}/{thirdType}", method = RequestMethod.GET)
@ResponseBody
public Result<JSONObject> getThirdLoginUser(@PathVariable("token") String token, @PathVariable("thirdType") String thirdType) throws Exception {
    Result<JSONObject> result = new Result<JSONObject>();
    String username = JwtUtil.getUsername(token);
    // 1. 校验用户是否有效
    SysUser sysUser = sysUserService.getUserByName(username);
    result = sysUserService.checkUserIsEffective(sysUser);
    if (!result.isSuccess()) {
        return result;
    }
    // update-begin-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
    LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
    query.eq(SysThirdAccount::getSysUserId, sysUser.getId());
    query.eq(SysThirdAccount::getThirdType, thirdType);
    SysThirdAccount account = sysThirdAccountService.getOne(query);
    if (oConvertUtils.isEmpty(sysUser.getRealname())) {
        sysUser.setRealname(account.getRealname());
    }
    if (oConvertUtils.isEmpty(sysUser.getAvatar())) {
        sysUser.setAvatar(account.getAvatar());
    }
    // update-end-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
    JSONObject obj = new JSONObject();
    // 用户登录信息
    obj.put("userInfo", sysUser);
    // token 信息
    obj.put("token", token);
    result.setResult(obj);
    result.setSuccess(true);
    result.setCode(200);
    baseCommonService.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null);
    return result;
}
Also used : SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount) JSONObject(com.alibaba.fastjson.JSONObject) SysUser(org.jeecg.modules.system.entity.SysUser) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 87 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project kms by mahonelau.

the class ThirdLoginController method loginThird.

@RequestMapping("/{source}/callback")
public String loginThird(@PathVariable("source") String source, AuthCallback callback, ModelMap modelMap) {
    log.info("第三方登录进入callback:" + source + " params:" + JSONObject.toJSONString(callback));
    AuthRequest authRequest = factory.get(source);
    AuthResponse response = authRequest.login(callback);
    log.info(JSONObject.toJSONString(response));
    Result<JSONObject> result = new Result<JSONObject>();
    if (response.getCode() == 2000) {
        JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(response.getData()));
        String username = data.getString("username");
        String avatar = data.getString("avatar");
        String uuid = data.getString("uuid");
        // 构造第三方登录信息存储对象
        ThirdLoginModel tlm = new ThirdLoginModel(source, uuid, username, avatar);
        // 判断有没有这个人
        // update-begin-author:wangshuai date:20201118 for:修改成查询第三方账户表
        LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<SysThirdAccount>();
        query.eq(SysThirdAccount::getThirdUserUuid, uuid);
        query.eq(SysThirdAccount::getThirdType, source);
        List<SysThirdAccount> thridList = sysThirdAccountService.list(query);
        SysThirdAccount user = null;
        if (thridList == null || thridList.size() == 0) {
            // 否则直接创建新账号
            user = saveThirdUser(tlm);
        } else {
            // 已存在 只设置用户名 不设置头像
            user = thridList.get(0);
        }
        // update-begin-author:wangshuai date:20201118 for:从第三方登录查询是否存在用户id,不存在绑定手机号
        if (oConvertUtils.isNotEmpty(user.getSysUserId())) {
            String sysUserId = user.getSysUserId();
            SysUser sysUser = sysUserService.getById(sysUserId);
            String token = saveToken(sysUser);
            modelMap.addAttribute("token", token);
        } else {
            modelMap.addAttribute("token", "绑定手机号," + "" + uuid);
        }
    // update-end-author:wangshuai date:20201118 for:从第三方登录查询是否存在用户id,不存在绑定手机号
    // update-begin--Author:wangshuai  Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441--------------------
    } else {
        modelMap.addAttribute("token", "登录失败");
    }
    // update-end--Author:wangshuai  Date:20200729 for:接口在签名校验失败时返回失败的标识码 issues#1441--------------------
    result.setSuccess(false);
    result.setMessage("第三方登录异常,请联系管理员");
    return "thirdLogin";
}
Also used : AuthRequest(me.zhyd.oauth.request.AuthRequest) SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount) JSONObject(com.alibaba.fastjson.JSONObject) SysUser(org.jeecg.modules.system.entity.SysUser) ThirdLoginModel(org.jeecg.modules.system.model.ThirdLoginModel) AuthResponse(me.zhyd.oauth.model.AuthResponse) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 88 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project RuoYi-Vue-Plus by JavaLionLi.

the class SysDictTypeServiceImpl method deleteDictTypeByIds.

/**
 * 批量删除字典类型信息
 *
 * @param dictIds 需要删除的字典ID
 */
@Override
public void deleteDictTypeByIds(Long[] dictIds) {
    for (Long dictId : dictIds) {
        SysDictType dictType = selectDictTypeById(dictId);
        if (dictDataMapper.exists(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType.getDictType()))) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
        }
        RedisUtils.deleteObject(getCacheKey(dictType.getDictType()));
    }
    baseMapper.deleteBatchIds(Arrays.asList(dictIds));
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDictType(com.ruoyi.common.core.domain.entity.SysDictType) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 89 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class YxStoreCouponUserServiceImpl method queryAll.

@Override
public // @Cacheable
Map<String, Object> queryAll(YxStoreCouponUserQueryCriteria criteria, Pageable pageable) {
    getPage(pageable);
    PageInfo<YxStoreCouponUser> page = new PageInfo<>(queryAll(criteria));
    List<YxStoreCouponUserDto> storeOrderDTOS = generator.convert(page.getList(), YxStoreCouponUserDto.class);
    for (YxStoreCouponUserDto couponUserDTO : storeOrderDTOS) {
        YxUser yxUser = userService.getOne(new LambdaQueryWrapper<YxUser>().eq(YxUser::getUid, couponUserDTO.getUid()));
        if (yxUser == null) {
            couponUserDTO.setNickname("--");
            continue;
        }
        couponUserDTO.setNickname(yxUser.getNickname());
    }
    Map<String, Object> map = new LinkedHashMap<>(2);
    map.put("content", storeOrderDTOS);
    map.put("totalElements", page.getTotal());
    return map;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) YxStoreCouponUserDto(co.yixiang.modules.activity.service.dto.YxStoreCouponUserDto) YxUser(co.yixiang.modules.shop.domain.YxUser) YxStoreCouponUser(co.yixiang.modules.activity.domain.YxStoreCouponUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) LinkedHashMap(java.util.LinkedHashMap)

Example 90 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class QiNiuServiceImpl method upload.

@Override
// @CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
    FileUtil.checkSize(maxSize, file.getSize());
    if (qiniuConfig.getId() == null) {
        throw new BadRequestException("请先添加相应配置,再操作");
    }
    // 构造一个带指定Zone对象的配置类
    Configuration cfg = new Configuration(QiNiuUtil.getRegion(qiniuConfig.getZone()));
    UploadManager uploadManager = new UploadManager(cfg);
    Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
    String upToken = auth.uploadToken(qiniuConfig.getBucket());
    try {
        String key = file.getOriginalFilename();
        if (qiniuContentService.getOne(new LambdaQueryWrapper<QiniuContent>().eq(QiniuContent::getName, key)) != null) {
            key = QiNiuUtil.getKey(key);
        }
        Response response = uploadManager.put(file.getBytes(), key, upToken);
        // 解析上传成功的结果
        DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class);
        QiniuContent content = qiniuContentService.getOne(new LambdaQueryWrapper<QiniuContent>().eq(QiniuContent::getName, FileUtil.getFileNameNoEx(putRet.key)));
        if (content == null) {
            // 存入数据库
            QiniuContent qiniuContent = new QiniuContent();
            qiniuContent.setSuffix(FileUtil.getExtensionName(putRet.key));
            qiniuContent.setBucket(qiniuConfig.getBucket());
            qiniuContent.setType(qiniuConfig.getType());
            qiniuContent.setName(FileUtil.getFileNameNoEx(putRet.key));
            qiniuContent.setUrl(qiniuConfig.getHost() + "/" + putRet.key);
            qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(file.getSize() + "")));
            qiniuContentService.save(qiniuContent);
            return qiniuContent;
        }
        return content;
    } catch (Exception e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : Response(com.qiniu.http.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Configuration(com.qiniu.storage.Configuration) Auth(com.qiniu.util.Auth) BadRequestException(co.yixiang.exception.BadRequestException) DefaultPutRet(com.qiniu.storage.model.DefaultPutRet) QiniuContent(co.yixiang.modules.tools.domain.QiniuContent) UploadManager(com.qiniu.storage.UploadManager) BadRequestException(co.yixiang.exception.BadRequestException) QiniuException(com.qiniu.common.QiniuException) IOException(java.io.IOException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18