MassageNoticeScheduleService.java 2.74 KB
package com.pipihelper.project.scheduled;

import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService;
import com.pipihelper.project.feishu.service.massage.MassageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: TODO
 * @author: charles
 * @date: 2022年10月15日 17:26
 */
@Slf4j
@Component
public class MassageNoticeScheduleService {


    @Autowired
    private PainService painService;

    @Autowired
    private MassageService massageService;

    @Autowired
    private FeiShuApiService feiShuApiService;
    /**
     * 每周四定时生成要按摩的人员名单,并发送大群和单人消息
     */
    @Async
    @Scheduled(cron = "0 0 10 * * ?")
    public void sendMsgCardToPipiChat(){

    }


    /**
     * 当天时间2:55,给第一波三个人更新卡片,并发送应用内提醒
     */
    @Async
    @Scheduled(cron = "0 0 10 * * ?")
    public void massageStart(){
        List<Pain> pains = painService.findListAsc(3);
        for(Pain pain:pains){
            String messageId = pain.getMessageId();
            massageService.updateSingleMassageMsgCardWhenBegin(messageId);
            //1代表正在按
            pain.setStatus(1);
            painService.update(pain);
            JSONObject noticeMsg = new JSONObject();
            noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
            //发送应用内提醒
            log.info("发送应用内容消息提醒");
            feiShuApiService.patchUrgentApp(messageId, noticeMsg);
        }

    }


//    /**
//     * 当天时间2:55,给第一波三个人更新卡片,并发送应用内提醒
//     */
//    @Async
//    @Scheduled(cron = "0 0 10 * * ?")
//    public void massageStart(){
//        List<Pain> pains = painService.findListAsc(3);
//        for(Pain pain:pains){
//            String messageId = pain.getMessageId();
//            massageService.updateSingleMassageMsgCardWhenBegin(messageId);
//            //1代表正在按
//            pain.setStatus(1);
//            painService.update(pain);
//            JSONObject noticeMsg = new JSONObject();
//            noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
//            //发送应用内提醒
//            log.info("发送应用内容消息提醒");
//            feiShuApiService.patchUrgentApp(messageId, noticeMsg);
//        }
//
//    }
}