yaozc2021
2025-04-16 1739b4d76263f97023b0a14b4b8eae217e5000c4
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
package me.zhengjie.modules.quartz.task;
 
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.modules.system.repository.*;
import org.springframework.stereotype.Service;
 
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 客户资源管理提醒(延时)
 * @author 魏传栋
 * @date 2023-01-10
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ResourceReminderMethod {
 
    private final UserRepository userRepository;
    private final OpaiDingTalkService opaiDingTalkService;
    private final CustomerResourcesRepository customerResourcesRepository;
    private final CustomerResourcesUserRepository customerResourcesUserRepository;
 
    /**
     * 客户资源管理提醒
     * @throws Exception
     */
    public void resourceReminder() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 当前时间
        String nowTime = sdf.format(new Date());
        // 查询客户资源管理表
        List<CustomerResources> customerResourcesList = customerResourcesRepository.findAll();
        for(CustomerResources customerResources : customerResourcesList){
            // 表中的提醒时间与当前的时间一致,发送钉钉消息
            if(customerResources.getOpeningTime() != null && customerResources.getOpeningTime().compareTo(Timestamp.valueOf(nowTime)) == 0){
                // 钉钉List
                List<String> dingDingList = new ArrayList<>();
                // 查询中间表
                List<CustomerResourcesUser> customerResourcesUserList = customerResourcesUserRepository.findByCustomerResourcesId(customerResources.getId());
                for(int i = 0; i < customerResourcesUserList.size(); i++){
                    // 查询用户
                    User user = userRepository.findById(customerResourcesUserList.get(i).getUserId()).orElseGet(User::new);
                    dingDingList.add(user.getDingding());
                }
                // 发送信息至被提醒人钉钉
                opaiDingTalkService.sendNotice(dingDingList, "客户资源管理提示", "### 客户资源管理提示  \n  >" +
                        "  \n  标题:"   + customerResources.getTitle() +
                        "  \n  分类: " + customerResources.getClassification() +
                        "  \n  新增客户资源,请登录PMS系统查看。", "card");
            }
        }
    }
}