This commit is contained in:
2025-05-04 10:51:27 +08:00
parent 6197f13e8e
commit ef978529ac
16 changed files with 157 additions and 41 deletions

View File

@@ -2,11 +2,14 @@ package com.ycwl.basic.task;
import cn.hutool.core.date.DateUtil;
import com.ycwl.basic.mapper.MemberMapper;
import com.ycwl.basic.mapper.ScenicMapper;
import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.member.resp.MemberRespVO;
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
import com.ycwl.basic.model.pc.scenic.entity.ScenicEntity;
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
import com.ycwl.basic.notify.NotifyFactory;
import com.ycwl.basic.notify.adapters.INotifyAdapter;
@@ -22,8 +25,11 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@@ -39,6 +45,8 @@ public class DownloadNotificationTasker {
private MemberMapper memberMapper;
@Autowired
private TemplateRepository templateRepository;
@Autowired
private ScenicMapper scenicMapper;
@Scheduled(cron = "0 0 21 * * *")
public void sendDownloadNotification() {
@@ -131,4 +139,69 @@ public class DownloadNotificationTasker {
adapter.sendTo(new NotifyContent(title, page, params), member.getOpenId());
});
}
@Scheduled(cron = "0 0 * * * *")
public void sendExtraDownloadNotification() {
log.info("开始执行定时任务");
List<ScenicRespVO> scenicList = scenicMapper.list(new ScenicReqQuery());
if (scenicList.isEmpty()) {
return;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
calendar.clear();
scenicList.parallelStream().forEach(scenic -> {
Long scenicId = scenic.getId();
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
if (scenicConfig == null) {
return;
}
if (StringUtils.isEmpty(scenicConfig.getExtraNotificationTime())) {
return;
}
List<String> timeList = Arrays.asList(StringUtils.split(scenicConfig.getExtraNotificationTime(), ","));
if (!timeList.contains(String.valueOf(currentHour))) {
return;
}
log.info("当前景区{},配置了{}", scenic.getName(), scenicConfig.getExtraNotificationTime());
videoMapper.listRelationByCreateTime(DateUtil.beginOfDay(new Date()), new Date())
.parallelStream()
.forEach(item -> {
if (item.getIsBuy() == 1) {
return;
}
MemberRespVO member = memberMapper.getById(item.getMemberId());
MpConfigEntity scenicMp = scenicRepository.getScenicMpConfig(member.getScenicId());
// 发送模板消息
String templateId = scenicRepository.getVideoDownloadTemplateId(item.getScenicId());
if (StringUtils.isBlank(templateId)) {
log.info("模板消息为空");
return;
}
log.info("发送模板消息");
String title = "您在【" + scenic.getName() + "】的专属影像";
String page = "pages/videoSynthesis/index?type=2&scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId();
/**
* 景区 {{thing1.DATA}}
* 备注 {{thing3.DATA}}
*/
Map<String, Object> params = new HashMap<>();
Map<String, Object> dataParam = new HashMap<>();
Map<String, String> videoMap = new HashMap<>();
videoMap.put("value", title);
dataParam.put("thing1", videoMap);
Map<String, String> remarkMap = new HashMap<>();
remarkMap.put("value", "请及时购买并下载好您的旅行视频");
dataParam.put("thing3", remarkMap);
params.put("data", dataParam);
params.put("page", page);
params.put("template_id", templateId);
log.info("视频下载通知模板参数:{},用户ID:{}", params, member.getOpenId());
INotifyAdapter adapter = NotifyFactory.get(NotifyType.WX_MP_SRV, scenicMp.toMap());
adapter.sendTo(new NotifyContent(title, page, params), member.getOpenId());
});
});
}
}

View File

@@ -126,8 +126,8 @@ public class VideoPieceGetter {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNamePrefix("VPG-" + task.faceId + "-t")
.build();
final ThreadPoolExecutor executor = new ThreadPoolExecutor(16, 512, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(512),
final ThreadPoolExecutor executor = new ThreadPoolExecutor(16, 128, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(128),
threadFactory
);
List<String> currentUnFinPlaceholder = new ArrayList<>();