liujie
2 天以前 77ad4788416a7e7a15dc15d0d2a01d304519262b
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.ruoyi.system.listener;
 
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.listener.event.PublishTopicLiveInfoEvent;
import com.ruoyi.system.model.TCrmClinic;
import com.ruoyi.system.model.TCrmSalesperson;
import com.ruoyi.system.model.TSysAppUser;
import com.ruoyi.system.model.TSysLive;
import com.ruoyi.system.service.*;
import com.ruoyi.system.utils.util.TemplateMessageSendUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * @author xiaochen
 * @ClassName PublishTopicUpdateCollectEventListener
 * @Description
 * @date 2021-08-11 18:44
 */
@Slf4j
@Component
public class PublishTopicLiveInfoEventListener {
 
    @Autowired
    private TemplateMessageSendUtil templateMessageSendUtil;
    @Autowired
    private TCrmClinicService crmClinicService;
    @Autowired
    private TSysAppUserService sysAppUserService;
    @Autowired
    private TCrmSalespersonService crmSalespersonService;
    @Autowired
    private TSysLiveService sysLiveService;
    @Autowired
    private ISysUserService sysUserService;
 
    @Async
    @EventListener(PublishTopicLiveInfoEvent.class)
    public void PublishTopicLiveInfoEventListener(PublishTopicLiveInfoEvent event) {
        String pushTypeAndId = (String) event.getSource();
        String[] split = pushTypeAndId.split("_");
        String pushType = split[0];
        String liveId = split[1];
        try {
            // 查询直播信息
            TSysLive sysLive = sysLiveService.getById(liveId);
            if(Objects.isNull(sysLive)){
                log.error("模板消息发送--未查询到直播信息");
                return;
            }
            String liveTitle = sysLive.getLiveTitle();
            String liveStartTime = DateUtils.localDateTimeToString(sysLive.getStartTime());
            log.info("开始发送直播信息");
            if(pushType.contains("1")){
                // 诊所
                List<TCrmClinic> clinicList = crmClinicService.list();
                if(!CollectionUtils.isEmpty(clinicList)){
                    List<Long> userIds = clinicList.stream().map(TCrmClinic::getUserId).collect(Collectors.toList());
                    List<SysUser> sysUserList = sysUserService.selectUserListByIds(userIds);
                    for (SysUser user : sysUserList) {
                        templateMessageSendUtil.wxOfficeTemplateAppLiveRequest(user.getOpenId(),liveTitle,liveStartTime);
                    }
                }
            }
            if(pushType.contains("2")){
                // 用户
                List<TSysAppUser> sysAppUsers = sysAppUserService.list();
                for (TSysAppUser sysAppUser : sysAppUsers) {
                    templateMessageSendUtil.wxOfficeTemplateAppLiveRequest(sysAppUser.getOfficeOpenId(),liveTitle,liveStartTime);
                }
            }
            if(pushType.contains("3")){
                // 业务员
                List<TCrmSalesperson> crmSalespeopleList = crmSalespersonService.list();
                if(!CollectionUtils.isEmpty(crmSalespeopleList)){
                    List<Long> userIds = crmSalespeopleList.stream().map(TCrmSalesperson::getUserId).collect(Collectors.toList());
                    List<SysUser> sysUserList = sysUserService.selectUserListByIds(userIds);
                    for (SysUser user : sysUserList) {
                        templateMessageSendUtil.wxOfficeTemplateAppLiveRequest(user.getOpenId(),liveTitle,liveStartTime);
                    }
                }
            }
        } catch (Exception e) {
            log.error("发送直播信息失败:{}", e.getMessage());
        }
    }
 
}