TaskRunner.java
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package vion.cron;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.date.TimeUtil;
import org.dromara.hutool.core.lang.Opt;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vion.model.Task;
import vion.model.User;
import vion.service.ITaskService;
import vion.service.IUserService;
import vion.third.DingMod;
import vion.utils.JsonUtil;
import java.time.LocalDateTime;
import java.util.stream.Collectors;
/**
* @author vion
* @date 2023/11/13
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class TaskRunner {
private final IUserService userService;
private final ITaskService taskService;
private final DingMod dingMod;
@Scheduled(cron = "0 0 17 * * ?")
void pushUndoneTask() {
log.info("开始推送未完成工单");
var taskList = taskService.list(Wrappers.<Task>lambdaQuery().notIn(Task::getStatus, 3, 5));
Opt.ofEmptyAble(taskList)
.map(l -> l.stream().map(Task::getActiveUser).collect(Collectors.toSet()))
.ifPresent(userIds -> {
var userList = userService.list(Wrappers.<User>lambdaQuery().in(User::getId, userIds));
userList.forEach(user -> dingMod.workMsg(buildMsg(user)));
});
log.info("推送未完成工单完成");
}
String buildMsg(User user) {
var jsonObj = JsonUtil.createObj()
.put("agent_id", 2358374016L)
.put("userid_list", user.getUserid());
var content = JsonUtil.createObj()
.put("title", "请查看您未完成的工单~_~")
.put("markdown", """
### 未完成工单提醒
#### 请查看您未完成的工单
#### 发送时间:""" + TimeUtil.formatNormal(LocalDateTime.now()))
.put("btn_orientation", "1");
var jsonArray = JsonUtil.createArr()
.add(JsonUtil.createObj().put("title", "查看详情")
.put("action_url", "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid" +
"=dingkrzwks0jpi2di3uo&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=https%3A%2F%2Fyunwei.vionyun.com%3A8443%2Fyunwei%2Fapi%2Fding%2Fcallback%2Finside%3FuserId%3D" + user.getId()));
content.set("btn_json_list", jsonArray);
var msg = JsonUtil.createObj().put("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj.toString();
}
}