TaskRunner.java
2.65 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
70
package vion.cron;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
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 java.util.stream.Collectors;
/**
* @author HlQ
* @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("推送未完成工单完成");
}
JSONObject buildMsg(User user) {
var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L)
.set("userid_list", user.getUserid());
var msg = JSONUtil.ofObj();
var content = JSONUtil.ofObj()
.set("title", "请查看您未完成的工单~_~")
.set("markdown", """
### 未完成工单提醒
#### 请查看您未完成的工单
#### 发送时间:""" + DateUtil.now())
.set("btn_orientation", "1");
JSONArray jsonArray = JSONUtil.ofArray()
.put(JSONUtil.ofObj().set("title", "查看详情")
.set("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);
msg.set("msgtype", "action_card").set("action_card", content);
jsonObj.set("msg", msg);
return jsonObj;
}
}