You've already forked FrameTour-BE
feat(task): 添加资源通知定时任务功能
- 实现了每日19点执行的资源通知定时任务 - 查询当日新增人脸数据并获取相关会员信息 - 整合景区、视频和照片资源统计数据 - 集成微信订阅消息推送服务 - 构建资源通知模板变量并触发消息发送 - 添加异常处理和日志记录机制
This commit is contained in:
@@ -0,0 +1,86 @@
|
|||||||
|
package com.ycwl.basic.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||||
|
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2DTO;
|
||||||
|
import com.ycwl.basic.mapper.FaceMapper;
|
||||||
|
import com.ycwl.basic.mapper.MemberMapper;
|
||||||
|
import com.ycwl.basic.model.pc.face.req.FaceReqQuery;
|
||||||
|
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
|
||||||
|
import com.ycwl.basic.model.pc.member.resp.MemberRespVO;
|
||||||
|
import com.ycwl.basic.model.pc.notify.req.WechatSubscribeNotifyTriggerRequest;
|
||||||
|
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
|
||||||
|
import com.ycwl.basic.repository.MemberRelationRepository;
|
||||||
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
|
import com.ycwl.basic.service.notify.WechatSubscribeNotifyTriggerService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class SourceNotificationTasker {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FaceMapper faceMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberMapper memberMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WechatSubscribeNotifyTriggerService notifyTriggerService;
|
||||||
|
@Autowired
|
||||||
|
private ScenicRepository scenicRepository;
|
||||||
|
@Autowired
|
||||||
|
private MemberRelationRepository memberRelationRepository;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 19 * * ?")
|
||||||
|
public void sendSourceNotification() {
|
||||||
|
log.info("开始执行SOURCE_NOTICE定时任务");
|
||||||
|
Date now = new Date();
|
||||||
|
FaceReqQuery query = new FaceReqQuery();
|
||||||
|
query.setStartTime(DateUtil.beginOfDay(now));
|
||||||
|
query.setEndTime(DateUtil.endOfDay(now));
|
||||||
|
|
||||||
|
List<FaceRespVO> faces = faceMapper.list(query);
|
||||||
|
log.info("查询到今日新增人脸数: {}", faces.size());
|
||||||
|
|
||||||
|
for (FaceRespVO item : faces) {
|
||||||
|
try {
|
||||||
|
MemberRespVO member = memberMapper.getById(item.getMemberId());
|
||||||
|
if (member == null || member.getOpenId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, Object> variables = new HashMap<>();
|
||||||
|
ScenicV2DTO scenic = scenicRepository.getScenicBasic(item.getScenicId());
|
||||||
|
variables.put("scenicName", scenic.getName());
|
||||||
|
variables.put("scenicId", scenic.getId());
|
||||||
|
variables.put("faceId", item.getId());
|
||||||
|
List<MemberSourceEntity> sourceVideoList = memberRelationRepository.listSourceByFaceRelation(item.getId(), 1);
|
||||||
|
variables.put("sourceVideoCount", sourceVideoList.size());
|
||||||
|
variables.put("sourceVideoCreateTime", DateUtil.format(item.getCreateAt(), "yyyy-MM-dd"));
|
||||||
|
List<MemberSourceEntity> sourcePhotoList = memberRelationRepository.listSourceByFaceRelation(item.getId(), 2);
|
||||||
|
variables.put("sourcePhotoCount", sourcePhotoList.size());
|
||||||
|
variables.put("sourcePhotoCreateTime", DateUtil.format(item.getCreateAt(), "yyyy-MM-dd"));
|
||||||
|
|
||||||
|
WechatSubscribeNotifyTriggerRequest request = WechatSubscribeNotifyTriggerRequest.builder()
|
||||||
|
.scenicId(item.getScenicId())
|
||||||
|
.memberId(item.getMemberId())
|
||||||
|
.openId(member.getOpenId())
|
||||||
|
.bizId(String.valueOf(item.getId()))
|
||||||
|
.variables(variables)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
notifyTriggerService.trigger("SOURCE_NOTICE", request);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送SOURCE_NOTICE失败, faceId: {}", item.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user