package cn.com.ty.lift.push.app;

import cn.com.ty.lift.common.model.PushMessage;
import lombok.AllArgsConstructor;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 推送消息生产者demo,在具体业务发生点send消息到队列中, message >>> queue
 *
 * @author wcz
 * @since 2020/4/26
 */
@RestController
@AllArgsConstructor
@RequestMapping("push")
public class PushProducer {

    private JmsMessagingTemplate jmsMessagingTemplate;

    //发送queue类型消息
    @GetMapping("/announcement")
    public Object announcement() {
        PushMessage pushMessage = PushMessage.announcementNotice("有一条公司公告，请注意查收");
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }

    @GetMapping("/maintain")
    public Object maintain(Integer num) {
        PushMessage pushMessage = PushMessage.maintainHasTaskDaily(num);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
    @GetMapping("/emergency")
    public Object emergency(String areaName, String projectName, String devicePosition, String registrationCode,int isTrapped, String callerFaultDescription, String workerName) {
        PushMessage pushMessage = PushMessage.emergencyAssign(areaName, projectName, devicePosition, registrationCode, LocalDateTime.now(), isTrapped, callerFaultDescription, workerName);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
    @GetMapping("/team")
    public Object team(String applyName, String teamName) {
        PushMessage pushMessage = PushMessage.teamJoin(applyName, teamName);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
    @GetMapping("/work")
    public Object work(String areaName, String projectName) {
        PushMessage pushMessage = PushMessage.workStartProject(areaName, projectName);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
    @GetMapping("/manager")
    public Object manager() {
        PushMessage pushMessage = PushMessage.managerMaintainDaily(10, 5);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
    @GetMapping("/inspection")
    public Object inspection(String projectName, String devicePosition, String registrationCode) {
        PushMessage pushMessage = PushMessage.inspectionAdvance45daysNotice(projectName, devicePosition, registrationCode);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
    @GetMapping("/news")
    public Object news(String title) {
        PushMessage pushMessage = PushMessage.newsNotice(title);
        pushMessage.sendAllOnPlatform(jmsMessagingTemplate);
        return pushMessage;
    }
}