Search in sources :

Example 61 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project matecloud by matevip.

the class SysUserServiceImpl method export.

@Override
public List<SysUserPOI> export() {
    LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(SysUser::getIsDeleted, "0");
    List<SysUser> sysUsers = this.baseMapper.selectList(queryWrapper);
    return sysUsers.stream().map(sysUser -> {
        SysUserPOI sysUserPoi = new SysUserPOI();
        BeanUtils.copyProperties(sysUser, sysUserPoi);
        sysUserPoi.setDepartName(sysDepartService.getById(sysUser.getDepartId()).getName());
        sysUserPoi.setRoleName(sysRoleService.getById(sysUser.getRoleId()).getRoleName());
        sysUserPoi.setStatusName(dictService.getValue("status", sysUser.getStatus()).getData());
        return sysUserPoi;
    }).collect(Collectors.toList());
}
Also used : ISysUserService(vip.mate.system.service.ISysUserService) SysUser(vip.mate.system.entity.SysUser) BaseException(vip.mate.core.common.exception.BaseException) ISysDictService(vip.mate.system.service.ISysDictService) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysUserMapper(vip.mate.system.mapper.SysUserMapper) ISysDepartService(vip.mate.system.service.ISysDepartService) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) ISysRoleService(vip.mate.system.service.ISysRoleService) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) Search(vip.mate.core.database.entity.Search) SysUserPOI(vip.mate.system.poi.SysUserPOI) Collection(java.util.Collection) PageUtil(vip.mate.core.database.util.PageUtil) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) AllArgsConstructor(lombok.AllArgsConstructor) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SystemConstant(vip.mate.core.common.constant.SystemConstant) BeanUtils(org.springframework.beans.BeanUtils) OrderTypeEnum(vip.mate.core.database.enums.OrderTypeEnum) CollectionUtil(vip.mate.core.web.util.CollectionUtil) SysUserPOI(vip.mate.system.poi.SysUserPOI) SysUser(vip.mate.system.entity.SysUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 62 with LambdaQueryWrapper

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

the class KmDocController method convertAll.

@AutoLog(value = "km_doc-批量转换")
@ApiOperation(value = "km_doc-批量转换", notes = "km_doc-批量转换")
@PostMapping(value = "/convertAll")
public Result<?> convertAll(HttpServletRequest req) {
    LambdaQueryWrapper<KmDoc> wrapper = new LambdaQueryWrapper<>();
    wrapper.ne(KmDoc::getFileType, "pdf");
    List<KmDoc> kmDocList = kmDocService.list(wrapper);
    if (kmDocList.size() > 0) {
        for (KmDoc kmDoc : kmDocList) {
            if (kmDoc != null) {
                kmDocService.convertDocSync(kmDoc);
            }
        }
    }
    return Result.OK();
}
Also used : KmDoc(org.jeecg.modules.KM.entity.KmDoc) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) AutoLog(org.jeecg.common.aspect.annotation.AutoLog) ApiOperation(io.swagger.annotations.ApiOperation)

Example 63 with LambdaQueryWrapper

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

the class SysUserDepartServiceImpl method queryDepartIdsOfUser.

/**
 * 根据用户id查询部门信息
 */
@Override
public List<DepartIdModel> queryDepartIdsOfUser(String userId) {
    LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
    LambdaQueryWrapper<SysDepart> queryDep = new LambdaQueryWrapper<SysDepart>();
    try {
        queryUDep.eq(SysUserDepart::getUserId, userId);
        List<String> depIdList = new ArrayList<>();
        List<DepartIdModel> depIdModelList = new ArrayList<>();
        List<SysUserDepart> userDepList = this.list(queryUDep);
        if (userDepList != null && userDepList.size() > 0) {
            for (SysUserDepart userDepart : userDepList) {
                depIdList.add(userDepart.getDepId());
            }
            queryDep.in(SysDepart::getId, depIdList);
            List<SysDepart> depList = sysDepartService.list(queryDep);
            if (depList != null || depList.size() > 0) {
                for (SysDepart depart : depList) {
                    depIdModelList.add(new DepartIdModel().convertByUserDepart(depart));
                }
            }
            return depIdModelList;
        }
    } catch (Exception e) {
        e.fillInStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysUserDepart(org.jeecg.modules.system.entity.SysUserDepart) SysDepart(org.jeecg.modules.system.entity.SysDepart) DepartIdModel(org.jeecg.modules.system.model.DepartIdModel)

Example 64 with LambdaQueryWrapper

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

the class ThirdAppDingtalkServiceImpl method sendActionCardMessage.

/**
 * 发送卡片消息(SysAnnouncement定制)
 *
 * @param announcement
 * @param verifyConfig 是否验证配置(未启用的APP会拒绝发送)
 * @return
 */
public Response<String> sendActionCardMessage(SysAnnouncement announcement, boolean verifyConfig) {
    if (verifyConfig && !thirdAppConfig.isDingtalkEnabled()) {
        return null;
    }
    String accessToken = this.getAccessToken();
    if (accessToken == null) {
        return null;
    }
    int agentId = thirdAppConfig.getDingtalk().getAgentIdInt();
    String markdown = "### " + announcement.getTitile() + "\n" + oConvertUtils.getString(announcement.getMsgAbstract(), "空");
    ActionCardMessage actionCard = new ActionCardMessage(markdown);
    actionCard.setTitle(announcement.getTitile());
    actionCard.setSingle_title("详情");
    actionCard.setSingle_url(RestUtil.getBaseUrl() + "/sys/annountCement/show/" + announcement.getId());
    Message<ActionCardMessage> actionCardMessage = new Message<>(agentId, actionCard);
    if (CommonConstant.MSG_TYPE_ALL.equals(announcement.getMsgType())) {
        actionCardMessage.setTo_all_user(true);
        return JdtMessageAPI.sendActionCardMessage(actionCardMessage, accessToken);
    } else {
        // 将userId转为username
        String[] userIds = null;
        String userId = announcement.getUserIds();
        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() };
        }
        if (userIds != null) {
            String[] usernameList = sysUserService.userIdToUsername(Arrays.asList(userIds)).toArray(new String[] {});
            // 通过第三方账号表查询出第三方userId
            List<SysThirdAccount> thirdAccountList = sysThirdAccountService.listThirdUserIdByUsername(usernameList, ThirdAppConfig.DINGTALK.toLowerCase());
            List<String> dtUserIds = thirdAccountList.stream().map(SysThirdAccount::getThirdUserId).collect(Collectors.toList());
            actionCardMessage.setUserid_list(dtUserIds);
            return JdtMessageAPI.sendActionCardMessage(actionCardMessage, accessToken);
        }
    }
    return null;
}
Also used : ActionCardMessage(com.jeecg.dingtalk.api.message.vo.ActionCardMessage) Message(com.jeecg.dingtalk.api.message.vo.Message) TextMessage(com.jeecg.dingtalk.api.message.vo.TextMessage) ActionCardMessage(com.jeecg.dingtalk.api.message.vo.ActionCardMessage) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 65 with LambdaQueryWrapper

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

the class ThirdAppDingtalkServiceImpl method syncLocalUserToThirdApp.

@Override
public SyncInfoVo syncLocalUserToThirdApp(String ids) {
    SyncInfoVo syncInfo = new SyncInfoVo();
    String accessToken = this.getAccessToken();
    if (accessToken == null) {
        syncInfo.addFailInfo("accessToken获取失败!");
        return syncInfo;
    }
    List<SysUser> sysUsers;
    if (StringUtils.isNotBlank(ids)) {
        String[] idList = ids.split(",");
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysUser::getId, (Object[]) idList);
        // 获取本地指定用户
        sysUsers = sysUserService.list(queryWrapper);
    } else {
        // 获取本地所有用户
        sysUsers = sysUserService.list();
    }
    // 查询钉钉所有的部门,用于同步用户和部门的关系
    List<Department> allDepartment = JdtDepartmentAPI.listAll(accessToken);
    for (SysUser sysUser : sysUsers) {
        // 外部模拟登陆临时账号,不同步
        if ("_reserve_user_external".equals(sysUser.getUsername())) {
            continue;
        }
        // 钉钉用户信息,不为null代表已同步过
        Response<User> dtUserInfo;
        /*
             * 判断是否同步过的逻辑:
             * 1. 查询 sys_third_account(第三方账号表)是否有数据,如果有代表已同步
             * 2. 本地表里没有,就先用手机号判断,不通过再用username判断。
             */
        SysThirdAccount sysThirdAccount = sysThirdAccountService.getOneBySysUserId(sysUser.getId(), ThirdAppConfig.DINGTALK.toLowerCase());
        if (sysThirdAccount != null && oConvertUtils.isNotEmpty(sysThirdAccount.getThirdUserId())) {
            // sys_third_account 表匹配成功,通过第三方userId查询出第三方userInfo
            dtUserInfo = JdtUserAPI.getUserById(sysThirdAccount.getThirdUserId(), accessToken);
        } else {
            // 手机号匹配
            Response<String> thirdUserId = JdtUserAPI.getUseridByMobile(sysUser.getPhone(), accessToken);
            // 手机号匹配成功
            if (thirdUserId.isSuccess() && oConvertUtils.isNotEmpty(thirdUserId.getResult())) {
                // 通过查询到的userId查询用户详情
                dtUserInfo = JdtUserAPI.getUserById(thirdUserId.getResult(), accessToken);
            } else {
                // 手机号匹配失败,尝试使用username匹配
                dtUserInfo = JdtUserAPI.getUserById(sysUser.getUsername(), accessToken);
            }
        }
        String dtUserId;
        // api 接口是否执行成功
        boolean apiSuccess;
        // 已同步就更新,否则就创建
        if (dtUserInfo != null && dtUserInfo.isSuccess() && dtUserInfo.getResult() != null) {
            User dtUser = dtUserInfo.getResult();
            dtUserId = dtUser.getUserid();
            User updateQwUser = this.sysUserToDtUser(sysUser, dtUser, allDepartment);
            Response<JSONObject> updateRes = JdtUserAPI.update(updateQwUser, accessToken);
            // 收集成功/失败信息
            apiSuccess = this.syncUserCollectErrInfo(updateRes, sysUser, syncInfo);
        } else {
            User newQwUser = this.sysUserToDtUser(sysUser, allDepartment);
            Response<String> createRes = JdtUserAPI.create(newQwUser, accessToken);
            dtUserId = createRes.getResult();
            // 收集成功/失败信息
            apiSuccess = this.syncUserCollectErrInfo(createRes, sysUser, syncInfo);
        }
        // api 接口执行成功,并且 sys_third_account 表匹配失败,就向 sys_third_account 里插入一条数据
        if (apiSuccess && (sysThirdAccount == null || oConvertUtils.isEmpty(sysThirdAccount.getThirdUserId()))) {
            if (sysThirdAccount == null) {
                sysThirdAccount = new SysThirdAccount();
                sysThirdAccount.setSysUserId(sysUser.getId());
                sysThirdAccount.setStatus(1);
                sysThirdAccount.setDelFlag(0);
                sysThirdAccount.setThirdType(ThirdAppConfig.DINGTALK.toLowerCase());
            }
            // 设置第三方app用户ID
            sysThirdAccount.setThirdUserId(dtUserId);
            sysThirdAccountService.saveOrUpdate(sysThirdAccount);
        }
    }
    return syncInfo;
}
Also used : SyncInfoVo(org.jeecg.modules.system.vo.thirdapp.SyncInfoVo) User(com.jeecg.dingtalk.api.user.vo.User) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Department(com.jeecg.dingtalk.api.department.vo.Department) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject)

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