Search in sources :

Example 1 with ActionCardMessage

use of com.jeecg.dingtalk.api.message.vo.ActionCardMessage in project jeecg-boot by jeecgboot.

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, THIRD_TYPE);
            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 2 with ActionCardMessage

use of com.jeecg.dingtalk.api.message.vo.ActionCardMessage 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 3 with ActionCardMessage

use of com.jeecg.dingtalk.api.message.vo.ActionCardMessage in project kykms 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)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 ActionCardMessage (com.jeecg.dingtalk.api.message.vo.ActionCardMessage)3 Message (com.jeecg.dingtalk.api.message.vo.Message)3 TextMessage (com.jeecg.dingtalk.api.message.vo.TextMessage)3