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

import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
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 com.pipihelper.project.utils.CacheUtil;
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);
//        String msg = "{\"text\":\"当前按摩进度:<at user_id=\\\"%s\\\">%s</at> <at user_id=\\\"%s\\\">%s</at> <at user_id=\\\"%s\\\">%s</at>\"}";
        StringBuilder userString = new StringBuilder();
        for(Pain pain:pains){
            String messageId = pain.getMessageId();
            massageService.updateSingleMassageMsgCardWhenBegin(messageId);
            userString.append(String.format("<at user_id=\\\"%s\\\">%s</at>", pain.getOpenId(), pain.getName()));
            //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);

        }
        //按摩群中同步发送按摩进度信息
        FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
        String msg = "当前按摩进度:" + userString;
        JSONObject content = new JSONObject();
        content.put("text", msg);
        feiShuMsgDTO.setMsgType("text");
        feiShuMsgDTO.setContent(content.toString());
        feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
        feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");

    }


//    /**
//     * 当天时间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);
//        }
//
//    }
}