feat(REQ-3114) - 新增创建待办的 API
This commit is contained in:
parent
e0f1a1411f
commit
075d4c2b7c
@ -0,0 +1,73 @@
|
||||
package cn.axzo.riven.client.req;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 创建待办入参模型
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024-10-31 10:34
|
||||
*/
|
||||
@Data
|
||||
public class ThirdCreateTodoReq {
|
||||
|
||||
/**
|
||||
* 应用的 ClientId
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 待办的创建人
|
||||
*/
|
||||
private String operatorId;
|
||||
|
||||
/**
|
||||
* 待办的执行人
|
||||
*/
|
||||
@NotEmpty(message = "执行人不能为空")
|
||||
private List<String> executorIds;
|
||||
|
||||
/**
|
||||
* 待办的标题
|
||||
*/
|
||||
@NotBlank(message = "标题不能为空")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 待办的描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 待办的截止时间
|
||||
*/
|
||||
private Long dueDate;
|
||||
|
||||
/**
|
||||
* 优先级
|
||||
*/
|
||||
private Integer priority = 20;
|
||||
|
||||
public String toCommandStr() {
|
||||
String command = " createTodo ";
|
||||
if (StringUtils.hasText(title)) {
|
||||
command += " -t " + title;
|
||||
}
|
||||
if (StringUtils.hasText(description)) {
|
||||
command += " -d " + description;
|
||||
}
|
||||
if (Objects.nonNull(dueDate)) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
command += " -d " + sdf.format(dueDate);
|
||||
}
|
||||
command += " -p " + priority;
|
||||
return command;
|
||||
}
|
||||
}
|
||||
@ -36,6 +36,7 @@ import javax.annotation.Resource;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@ -116,13 +117,7 @@ public class CreateTodoKeywordProcessor extends AbstractKeywordProcessor {
|
||||
|
||||
Set<String> users = new HashSet<>();
|
||||
users.add(chatbotMessage.getSenderStaffId());
|
||||
if (chatbotMessage.getAtUsers().size() == 2) {
|
||||
// 为单人创建
|
||||
users.add(chatbotMessage.getAtUsers().get(1).getStaffId());
|
||||
} else {
|
||||
// 批量创建
|
||||
users.addAll(chatbotMessage.getAtUsers().stream().map(MentionUser::getStaffId).distinct().collect(Collectors.toList()));
|
||||
}
|
||||
users.addAll(chatbotMessage.getAtUsers().stream().map(MentionUser::getStaffId).filter(StringUtils::hasText).distinct().collect(Collectors.toList()));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info("使用 userId 查询三方用户信息: {}", JSON.toJSONString(users));
|
||||
}
|
||||
|
||||
@ -1,12 +1,18 @@
|
||||
package cn.axzo.riven.dingtalk.controller;
|
||||
|
||||
import cn.axzo.riven.client.req.ThirdApplicationReq;
|
||||
import cn.axzo.riven.client.req.ThirdCreateTodoReq;
|
||||
import cn.axzo.riven.dingtalk.callback.robot.RobotMsgCallbackConsumer;
|
||||
import cn.axzo.riven.dingtalk.callback.robot.model.ChatbotMessageWrapper;
|
||||
import cn.axzo.riven.dingtalk.repository.entity.ThirdApplication;
|
||||
import cn.axzo.riven.dingtalk.robot.connection.AutoConnector;
|
||||
import cn.axzo.riven.dingtalk.service.ThirdApplicationService;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.dingtalk.open.app.api.OpenDingTalkClient;
|
||||
import com.dingtalk.open.app.api.models.bot.MentionUser;
|
||||
import com.dingtalk.open.app.api.models.bot.MessageContent;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -15,10 +21,14 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import shade.com.alibaba.fastjson2.JSON;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.axzo.riven.dingtalk.robot.connection.AutoConnector.clientMap;
|
||||
|
||||
@ -37,6 +47,8 @@ public class DingtalkController {
|
||||
private ThirdApplicationService thirdApplicationService;
|
||||
@Resource
|
||||
private AutoConnector autoConnector;
|
||||
@Resource
|
||||
private RobotMsgCallbackConsumer robotMsgCallbackConsumer;
|
||||
|
||||
@PostMapping("/enabled")
|
||||
public CommonResponse<String> changeStream(@RequestParam(required = false) String appId, @RequestParam Boolean enable) {
|
||||
@ -75,4 +87,53 @@ public class DingtalkController {
|
||||
thirdApplicationService.insert(application);
|
||||
return CommonResponse.success("应用注册成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建待办
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("todo/create")
|
||||
public CommonResponse<Boolean> createTodo(@Validated @RequestBody ThirdCreateTodoReq req) {
|
||||
ChatbotMessageWrapper messageWrapper = new ChatbotMessageWrapper();
|
||||
messageWrapper.setConversationId("mock-"+ UUID.fastUUID());
|
||||
messageWrapper.setConversationTitle("mock-title");
|
||||
messageWrapper.setConversationType("2");
|
||||
messageWrapper.setMsgId("mock-msgid-"+ UUID.fastUUID());
|
||||
messageWrapper.setSenderNick("mock-name");
|
||||
messageWrapper.setSenderStaffId(req.getOperatorId());
|
||||
messageWrapper.setSenderId("mock-sender-id");
|
||||
messageWrapper.setSessionWebhook("");
|
||||
List<MentionUser> atUsers = new ArrayList<>();
|
||||
MentionUser robotUser = new MentionUser();
|
||||
robotUser.setDingtalkId("$:LWCP_v1:$BQYU6rJ24ZSqNq30n47vbAdAwuFkEDtq");
|
||||
atUsers.add(robotUser);
|
||||
|
||||
List<MentionUser> executors = req.getExecutorIds().stream().map(userId -> {
|
||||
MentionUser mentionUser = new MentionUser();
|
||||
mentionUser.setDingtalkId(userId);
|
||||
mentionUser.setStaffId(userId);
|
||||
return mentionUser;
|
||||
}).collect(Collectors.toList());
|
||||
atUsers.addAll(executors);
|
||||
messageWrapper.setAtUsers(atUsers);
|
||||
messageWrapper.setSessionWebhookExpiredTime(req.getDueDate());
|
||||
|
||||
messageWrapper.setMsgtype("text");
|
||||
MessageContent text = new MessageContent();
|
||||
text.setContent(req.toCommandStr());
|
||||
messageWrapper.setText(text);
|
||||
messageWrapper.setRobotCode("dingx9pejjkh8whnaqkw");
|
||||
robotMsgCallbackConsumer.execute(messageWrapper);
|
||||
return CommonResponse.success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/test/consumer")
|
||||
public CommonResponse test() {
|
||||
String json = "{\"conversationId\":\"cidJaQrl1/gNuYwUdwnxXv9rw==\",\"atUsers\":[{\"dingtalkId\":\"$:LWCP_v1:$V3m0NHKO2lgEZLHNkq3kCQ==\",\"staffId\":\"17189335664858211\"},{\"dingtalkId\":\"$:LWCP_v1:$BQYU6rJ24ZSqNq30n47vbAdAwuFkEDtq\"}],\"chatbotCorpId\":\"ding509fc72d6685d56d4ac5d6980864d335\",\"chatbotUserId\":\"$:LWCP_v1:$BQYU6rJ24ZSqNq30n47vbAdAwuFkEDtq\",\"msgId\":\"msgle3bAxyvcgljY51KWNg2jA==\",\"senderNick\":\"张勇杰\",\"senderStaffId\":\"16643308030554669\",\"sessionWebhookExpiredTime\":1730346122013,\"createAt\":1730340721715,\"senderCorpId\":\"ding509fc72d6685d56d4ac5d6980864d335\",\"conversationType\":\"2\",\"senderId\":\"$:LWCP_v1:$7CYT5pCj4s4mkQK7Y3n12A==\",\"conversationTitle\":\"通知\",\"sessionWebhook\":\"https://oapi.dingtalk.com/robot/sendBySession?session=225ea1735196265565ee379c85081a0b\",\"msgtype\":\"text\",\"text\":{\"content\":\" createTodo -t 请完成REQ-3115的状态 -d 需求已经提测 -D 2024-10-31 17:00:00 -p 30\"},\"senderPlatform\":\"Win\",\"robotCode\":\"dingx9pejjkh8whnaqkw\"}";
|
||||
ChatbotMessageWrapper messageWrapper = JSON.parseObject(json, ChatbotMessageWrapper.class);
|
||||
robotMsgCallbackConsumer.execute(messageWrapper);
|
||||
return CommonResponse.success(true);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user