update:飞书发消息,同步审批实例记录结果
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.jero.modules.docking.feishu.common;
|
||||||
|
|
||||||
|
public interface Constant {
|
||||||
|
|
||||||
|
Integer OA = 1;
|
||||||
|
|
||||||
|
Integer FEISHU_PENDING = 2;
|
||||||
|
|
||||||
|
Integer FEISHU_MESSAGE = 3;
|
||||||
|
|
||||||
|
}
|
||||||
+40
-10
@@ -12,6 +12,7 @@ import com.jero.common.system.util.JwtUtil;
|
|||||||
import com.jero.common.system.vo.SysDictItemCore;
|
import com.jero.common.system.vo.SysDictItemCore;
|
||||||
import com.jero.common.util.RedisUtil;
|
import com.jero.common.util.RedisUtil;
|
||||||
import com.jero.common.util.oConvertUtils;
|
import com.jero.common.util.oConvertUtils;
|
||||||
|
import com.jero.modules.docking.feishu.common.Constant;
|
||||||
import com.jero.modules.docking.feishu.dto.BotMessageDto;
|
import com.jero.modules.docking.feishu.dto.BotMessageDto;
|
||||||
import com.jero.modules.docking.feishu.dto.InstanceDto;
|
import com.jero.modules.docking.feishu.dto.InstanceDto;
|
||||||
import com.jero.modules.docking.feishu.service.IFeiShuDockingService;
|
import com.jero.modules.docking.feishu.service.IFeiShuDockingService;
|
||||||
@@ -20,11 +21,14 @@ import com.jero.modules.docking.feishu.vo.definition.*;
|
|||||||
import com.jero.modules.docking.feishu.vo.instance.ApprovalsInstanceVo;
|
import com.jero.modules.docking.feishu.vo.instance.ApprovalsInstanceVo;
|
||||||
import com.jero.modules.docking.feishu.vo.instance.InstanceLink;
|
import com.jero.modules.docking.feishu.vo.instance.InstanceLink;
|
||||||
import com.jero.modules.docking.feishu.vo.instance.InstanceTask;
|
import com.jero.modules.docking.feishu.vo.instance.InstanceTask;
|
||||||
|
import com.jero.modules.docking.hiwork.entity.LawsUnifiedTodoLog;
|
||||||
|
import com.jero.modules.docking.hiwork.service.LawsUnifiedTodoLogService;
|
||||||
import com.jero.modules.system.entity.*;
|
import com.jero.modules.system.entity.*;
|
||||||
import com.jero.modules.system.service.*;
|
import com.jero.modules.system.service.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
@@ -35,7 +39,6 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
@@ -65,6 +68,7 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ISysRoleService sysRoleService;
|
private ISysRoleService sysRoleService;
|
||||||
@Resource
|
@Resource
|
||||||
|
private LawsUnifiedTodoLogService lawsUnifiedTodoLogService;
|
||||||
private CommonAPI commonAPI;
|
private CommonAPI commonAPI;
|
||||||
@Value("${feishu.app_id}")
|
@Value("${feishu.app_id}")
|
||||||
private String appId;
|
private String appId;
|
||||||
@@ -148,7 +152,6 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
List<DefinitionTexts> texts = new ArrayList<>();
|
List<DefinitionTexts> texts = new ArrayList<>();
|
||||||
texts.add(new DefinitionTexts("@i18n@1",approvalName));
|
texts.add(new DefinitionTexts("@i18n@1",approvalName));
|
||||||
texts.add(new DefinitionTexts("@i18n@2",approvalName));
|
texts.add(new DefinitionTexts("@i18n@2",approvalName));
|
||||||
texts.add(new DefinitionTexts("@i18n@3","飞书"));
|
|
||||||
// 构建国际化文案对象
|
// 构建国际化文案对象
|
||||||
DefinitionI18nResources definitionI18nResources = new DefinitionI18nResources();
|
DefinitionI18nResources definitionI18nResources = new DefinitionI18nResources();
|
||||||
definitionI18nResources.setLocale("zh-CN");
|
definitionI18nResources.setLocale("zh-CN");
|
||||||
@@ -224,8 +227,8 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
throw new JeroBootException("根据手机号获取user_id失败");
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,8 +249,11 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
HttpHeaders headers = createHeaders(accessToken);
|
HttpHeaders headers = createHeaders(accessToken);
|
||||||
// 创建 HttpEntity
|
// 创建 HttpEntity
|
||||||
HttpEntity<ApprovalsInstanceVo> entity = new HttpEntity<>(approvalsInstanceVo, headers);
|
HttpEntity<ApprovalsInstanceVo> entity = new HttpEntity<>(approvalsInstanceVo, headers);
|
||||||
restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
|
||||||
|
JSONObject jsonResponse = JSON.parseObject(response.getBody());
|
||||||
|
logMessage(JSON.toJSONString(instanceDto), jsonResponse, "/feishu/synchronizeApprovalInstance", Constant.FEISHU_PENDING);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
logError(JSON.toJSONString(instanceDto), e.getMessage(), "/feishu/synchronizeApprovalInstance", Constant.FEISHU_PENDING);
|
||||||
log.error("同步三方审批实例异常" + e.getMessage());
|
log.error("同步三方审批实例异常" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,6 +410,7 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
// 获取token
|
// 获取token
|
||||||
String accessToken = getAccessToken();
|
String accessToken = getAccessToken();
|
||||||
// 构建参数
|
// 构建参数
|
||||||
|
// TODO 这里使用到了飞书的user_id,后续对接了IAM后,需验证下获取飞书id发送消息是否正常
|
||||||
List<String> newPushRange = new ArrayList<>();
|
List<String> newPushRange = new ArrayList<>();
|
||||||
if (StringUtils.isNotBlank(botMessageDto.getReceiveIds())) {
|
if (StringUtils.isNotBlank(botMessageDto.getReceiveIds())) {
|
||||||
List<String> pushRangeList = Arrays.asList(botMessageDto.getReceiveIds().split(","));
|
List<String> pushRangeList = Arrays.asList(botMessageDto.getReceiveIds().split(","));
|
||||||
@@ -411,13 +418,14 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
SysUser reviewUser = sysUserService.getById(id);
|
SysUser reviewUser = sysUserService.getById(id);
|
||||||
if (!Objects.isNull(reviewUser) && StringUtils.isNotBlank(reviewUser.getFeishuId())) {
|
if (!Objects.isNull(reviewUser) && StringUtils.isNotBlank(reviewUser.getFeishuId())) {
|
||||||
newPushRange.add(reviewUser.getFeishuId());
|
newPushRange.add(reviewUser.getFeishuId());
|
||||||
|
} else {
|
||||||
|
BotMessageDto botMessageDto1 = new BotMessageDto();
|
||||||
|
BeanUtils.copyProperties(botMessageDto,botMessageDto1);
|
||||||
|
botMessageDto1.setReceiveIds(id);
|
||||||
|
logError(JSON.toJSONString(botMessageDto1), "用户id:" + id +"对应的飞书账用户不存在", "/feishu/sendHrefMessageByBot", Constant.FEISHU_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newPushRange.isEmpty()) {
|
|
||||||
log.error("接收消息的飞书用户均不存在,消息发送终止");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 将url替换为单点登录的地址
|
// 将url替换为单点登录的地址
|
||||||
// 使用 URL 编码来处理特殊字符,将url替换为单点登录的地址
|
// 使用 URL 编码来处理特殊字符,将url替换为单点登录的地址
|
||||||
String hrefUrl = URLEncoder.encode(botMessageDto.getHrefUrl(), "UTF-8");
|
String hrefUrl = URLEncoder.encode(botMessageDto.getHrefUrl(), "UTF-8");
|
||||||
@@ -471,13 +479,35 @@ public class FeiShuDockingServiceImpl implements IFeiShuDockingService {
|
|||||||
botMessageVo.setReceive_id(pushId);
|
botMessageVo.setReceive_id(pushId);
|
||||||
botMessageVo.setUuid(uuid);
|
botMessageVo.setUuid(uuid);
|
||||||
HttpEntity<BotMessageVo> entity = new HttpEntity<>(botMessageVo, headers);
|
HttpEntity<BotMessageVo> entity = new HttpEntity<>(botMessageVo, headers);
|
||||||
restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
|
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
|
||||||
|
JSONObject jsonResponse = JSON.parseObject(response.getBody());
|
||||||
|
logMessage(JSON.toJSONString(botMessageDto), jsonResponse, "/feishu/sendHrefMessageByBot", Constant.FEISHU_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("飞书发送消息异常" + e.getMessage());
|
logError(JSON.toJSONString(botMessageDto), e.getMessage(), "/feishu/sendHrefMessageByBot", Constant.FEISHU_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logMessage(String dto, JSONObject jsonResponse, String url, Integer messageType) {
|
||||||
|
LawsUnifiedTodoLog logEntry = new LawsUnifiedTodoLog();
|
||||||
|
logEntry.setJsonStr(dto);
|
||||||
|
logEntry.setResponseBody("success");
|
||||||
|
logEntry.setState("0".equals(jsonResponse.getString("code")) ? 1 : 2);
|
||||||
|
logEntry.setMessageType(messageType);
|
||||||
|
logEntry.setUrl(url);
|
||||||
|
lawsUnifiedTodoLogService.add(logEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logError(String dto, String errorMessage, String url, Integer messageType) {
|
||||||
|
LawsUnifiedTodoLog logEntry = new LawsUnifiedTodoLog();
|
||||||
|
logEntry.setJsonStr(dto);
|
||||||
|
logEntry.setResponseBody(errorMessage);
|
||||||
|
logEntry.setState(2);
|
||||||
|
logEntry.setMessageType(messageType);
|
||||||
|
logEntry.setUrl(url);
|
||||||
|
lawsUnifiedTodoLogService.add(logEntry);
|
||||||
|
log.error("飞书发送消息异常: " + errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据预授权码获取用户信息
|
* 根据预授权码获取用户信息
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ import java.util.Date;
|
|||||||
@ApiModel(description="统一代办推送日志表")
|
@ApiModel(description="统一代办推送日志表")
|
||||||
@TableName(value = "laws_unified_todo_log")
|
@TableName(value = "laws_unified_todo_log")
|
||||||
public class LawsUnifiedTodoLog {
|
public class LawsUnifiedTodoLog {
|
||||||
@TableId(value = "id", type = IdType.INPUT)
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
@ApiModelProperty(value="")
|
@ApiModelProperty(value="")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user