Search in sources :

Example 21 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project blogSpringBoot by lurenha.

the class UserController method profileUpdate.

/**
 * 个人信息页修改
 */
@PostMapping("/profile/update")
public JsonResult profileUpdate(@Validated @RequestBody User user, ServletRequest request) {
    HttpServletRequest req = (HttpServletRequest) request;
    String token = req.getHeader("Peng-Token");
    Long userId = TokenUtil.getUserId(token);
    if (iUserService.count(new LambdaQueryWrapper<User>().ne(User::getUsId, userId).eq(User::getUsername, user.getUsername())) > 0) {
        return ResultUtil.faile(ResultCode.DATA_ALREADY_EXISTED_ROLE);
    }
    user.setUsId(userId);
    user.setPassword(null);
    user.setAvatar(null);
    Boolean bool = iUserService.updateById(user);
    if (bool) {
        return ResultUtil.successNoData(ResultCode.SUCCESS);
    } else {
        return ResultUtil.faile(ResultCode.DATA_IS_WRONG);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.peng.entity.User) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 22 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class ThirdAppDingtalkServiceImpl method oauth2Login.

/**
 * OAuth2登录,成功返回登录的SysUser,失败返回null
 */
public SysUser oauth2Login(String authCode) {
    ThirdAppTypeItemVo dtConfig = thirdAppConfig.getDingtalk();
    // 1. 根据免登授权码获取用户 AccessToken
    String userAccessToken = JdtOauth2API.getUserAccessToken(dtConfig.getClientId(), dtConfig.getClientSecret(), authCode);
    if (userAccessToken == null) {
        log.error("oauth2Login userAccessToken is null");
        return null;
    }
    // 2. 根据用户 AccessToken 获取当前用户的基本信息(不包括userId)
    ContactUser contactUser = JdtOauth2API.getContactUsers("me", userAccessToken);
    if (contactUser == null) {
        log.error("oauth2Login contactUser is null");
        return null;
    }
    String unionId = contactUser.getUnionId();
    // 3. 根据获取到的 unionId 换取用户 userId
    String accessToken = this.getAccessToken();
    if (accessToken == null) {
        log.error("oauth2Login accessToken is null");
        return null;
    }
    Response<String> getUserIdRes = JdtUserAPI.getUseridByUnionid(unionId, accessToken);
    if (!getUserIdRes.isSuccess()) {
        log.error("oauth2Login getUseridByUnionid failed: " + JSON.toJSONString(getUserIdRes));
        return null;
    }
    String appUserId = getUserIdRes.getResult();
    log.info("appUserId: " + appUserId);
    if (appUserId != null) {
        // 判断第三方用户表有没有这个人
        LambdaQueryWrapper<SysThirdAccount> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysThirdAccount::getThirdUserUuid, appUserId);
        queryWrapper.or().eq(SysThirdAccount::getThirdUserId, appUserId);
        queryWrapper.eq(SysThirdAccount::getThirdType, THIRD_TYPE);
        SysThirdAccount thirdAccount = sysThirdAccountService.getOne(queryWrapper);
        if (thirdAccount != null) {
            return this.getSysUserByThird(thirdAccount, null, appUserId, accessToken);
        } else {
            // 直接创建新账号
            User appUser = JdtUserAPI.getUserById(appUserId, accessToken).getResult();
            ThirdLoginModel tlm = new ThirdLoginModel(THIRD_TYPE, appUser.getUserid(), appUser.getName(), appUser.getAvatar());
            thirdAccount = sysThirdAccountService.saveThirdUser(tlm);
            return this.getSysUserByThird(thirdAccount, appUser, null, null);
        }
    }
    return null;
}
Also used : ContactUser(com.jeecg.dingtalk.api.oauth2.vo.ContactUser) ContactUser(com.jeecg.dingtalk.api.oauth2.vo.ContactUser) User(com.jeecg.dingtalk.api.user.vo.User) ThirdAppTypeItemVo(org.jeecg.config.thirdapp.ThirdAppTypeItemVo) ThirdLoginModel(org.jeecg.modules.system.model.ThirdLoginModel) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 23 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class ThirdAppDingtalkServiceImpl method syncDepartmentToLocalRecursion.

public void syncDepartmentToLocalRecursion(List<JdtDepartmentTreeVo> departmentTreeList, String sysParentId, String username, SyncInfoVo syncInfo, String accessToken) {
    if (departmentTreeList != null && departmentTreeList.size() != 0) {
        for (JdtDepartmentTreeVo departmentTree : departmentTreeList) {
            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
            // 根据 source_identifier 字段查询
            queryWrapper.eq(SysDepart::getId, departmentTree.getSource_identifier());
            SysDepart sysDepart = sysDepartService.getOne(queryWrapper);
            if (sysDepart != null) {
                // 执行更新操作
                SysDepart updateSysDepart = this.dtDepartmentToSysDepart(departmentTree, sysDepart);
                if (sysParentId != null) {
                    updateSysDepart.setParentId(sysParentId);
                }
                try {
                    sysDepartService.updateDepartDataById(updateSysDepart, username);
                    String str = String.format("部门 %s 更新成功!", updateSysDepart.getDepartName());
                    syncInfo.addSuccessInfo(str);
                } catch (Exception e) {
                    this.syncDepartCollectErrInfo(e, departmentTree, syncInfo);
                }
                if (departmentTree.hasChildren()) {
                    // 紧接着同步子级
                    this.syncDepartmentToLocalRecursion(departmentTree.getChildren(), updateSysDepart.getId(), username, syncInfo, accessToken);
                }
            } else {
                // 执行新增操作
                SysDepart newSysDepart = this.dtDepartmentToSysDepart(departmentTree, null);
                if (sysParentId != null) {
                    newSysDepart.setParentId(sysParentId);
                    // 2 = 组织机构
                    newSysDepart.setOrgCategory("2");
                } else {
                    // 1 = 公司
                    newSysDepart.setOrgCategory("1");
                }
                try {
                    sysDepartService.saveDepartData(newSysDepart, username);
                    // 更新钉钉 source_identifier
                    Department updateDtDepart = new Department();
                    updateDtDepart.setDept_id(departmentTree.getDept_id());
                    updateDtDepart.setSource_identifier(newSysDepart.getId());
                    Response response = JdtDepartmentAPI.update(updateDtDepart, accessToken);
                    if (!response.isSuccess()) {
                        throw new RuntimeException(response.getErrmsg());
                    }
                    String str = String.format("部门 %s 创建成功!", newSysDepart.getDepartName());
                    syncInfo.addSuccessInfo(str);
                } catch (Exception e) {
                    this.syncDepartCollectErrInfo(e, departmentTree, syncInfo);
                }
                // 紧接着同步子级
                if (departmentTree.hasChildren()) {
                    this.syncDepartmentToLocalRecursion(departmentTree.getChildren(), newSysDepart.getId(), username, syncInfo, accessToken);
                }
            }
        }
    }
}
Also used : Response(com.jeecg.dingtalk.api.core.response.Response) Department(com.jeecg.dingtalk.api.department.vo.Department) JdtDepartmentTreeVo(org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 24 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class ThirdAppWechatEnterpriseServiceImpl method deleteDepartRecursion.

// 递归删除部门以及子部门,由于企业微信不允许删除带有成员和子部门的部门,所以需要递归删除下子部门,然后把部门成员移动端根部门下
private void deleteDepartRecursion(List<JwDepartmentTreeVo> children, String accessToken, boolean ifLocal) {
    for (JwDepartmentTreeVo departmentTree : children) {
        String depId = departmentTree.getId();
        // 过滤根部门
        if (!"1".equals(depId)) {
            // 判断本地是否有该部门
            if (ifLocal) {
                LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(SysDepart::getQywxIdentifier, depId);
                SysDepart sysDepart = sysDepartService.getOne(queryWrapper);
                // 本地有该部门,不删除
                if (sysDepart != null) {
                    if (departmentTree.hasChildren()) {
                        this.deleteDepartRecursion(departmentTree.getChildren(), accessToken, true);
                    }
                    continue;
                }
            }
            // 判断是否有成员,有就移动到根部门
            List<User> departUserList = JwUserAPI.getUsersByDepartid(depId, "1", null, accessToken);
            if (departUserList != null && departUserList.size() > 0) {
                for (User user : departUserList) {
                    User updateUser = new User();
                    updateUser.setUserid(user.getUserid());
                    updateUser.setDepartment(new Integer[] { 1 });
                    JwUserAPI.updateUser(updateUser, accessToken);
                }
            }
            // 有子部门优先删除子部门
            if (departmentTree.hasChildren()) {
                this.deleteDepartRecursion(departmentTree.getChildren(), accessToken, false);
            }
            // 执行删除操作
            JwDepartmentAPI.deleteDepart(depId, accessToken);
        }
    }
}
Also used : User(com.jeecg.qywx.api.user.vo.User) JwDepartmentTreeVo(org.jeecg.modules.system.vo.thirdapp.JwDepartmentTreeVo) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 25 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project jeecg-boot by jeecgboot.

the class ThirdAppWechatEnterpriseServiceImpl method sendTextCardMessage.

/**
 * 发送文本卡片消息(SysAnnouncement定制)
 *
 * @param announcement
 * @param verifyConfig 是否验证配置(未启用的APP会拒绝发送)
 * @return
 */
public JSONObject sendTextCardMessage(SysAnnouncement announcement, boolean verifyConfig) {
    if (verifyConfig && !thirdAppConfig.isWechatEnterpriseEnabled()) {
        return null;
    }
    String accessToken = this.getAppAccessToken();
    if (accessToken == null) {
        return null;
    }
    TextCard textCard = new TextCard();
    textCard.setAgentid(thirdAppConfig.getWechatEnterprise().getAgentIdInt());
    boolean isToAll = CommonConstant.MSG_TYPE_ALL.equals(announcement.getMsgType());
    String usernameString = "";
    if (!isToAll) {
        // 将userId转为username
        String userId = announcement.getUserIds();
        String[] userIds = null;
        if (oConvertUtils.isNotEmpty(userId)) {
            userIds = userId.substring(0, (userId.length() - 1)).split(",");
        } else {
            LambdaQueryWrapper<SysAnnouncementSend> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysAnnouncementSend::getAnntId, announcement.getId());
            SysAnnouncementSend sysAnnouncementSend = sysAnnouncementSendMapper.selectOne(queryWrapper);
            userIds = new String[] { sysAnnouncementSend.getUserId() };
        }
        List<String> usernameList = sysUserService.userIdToUsername(Arrays.asList(userIds));
        usernameString = String.join(",", usernameList);
    }
    textCard.setTouser(this.getTouser(usernameString, isToAll));
    TextCardEntity entity = new TextCardEntity();
    entity.setTitle(announcement.getTitile());
    entity.setDescription(oConvertUtils.getString(announcement.getMsgAbstract(), "空"));
    entity.setUrl(RestUtil.getBaseUrl() + "/sys/annountCement/show/" + announcement.getId());
    textCard.setTextcard(entity);
    return JwMessageAPI.sendTextCardMessage(textCard, accessToken);
}
Also used : TextCardEntity(com.jeecg.qywx.api.message.vo.TextCardEntity) TextCard(com.jeecg.qywx.api.message.vo.TextCard) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

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