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());
|
}
|
}
|
|
}
|