package com.sptg.estate.biz.receiver;

import com.sptg.common.core.constant.OperationConstant;
import com.sptg.common.core.entity.PublishTaskResult;
import com.sptg.estate.api.entity.NoticePushDeviceDetails;
import com.sptg.estate.biz.service.NoticePushDeviceDetailsServiceInterface;
import com.sptg.estate.biz.stream.NoticeTaskCallbackReceiverInterface;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

/**
 *
 *
 * description: 公告任务回调消费者
 */
@Component
@Slf4j
@RequiredArgsConstructor
@EnableBinding(value = { NoticeTaskCallbackReceiverInterface.class})
public class NoticeTaskCallbackReceiver {

    private final NoticePushDeviceDetailsServiceInterface noticePushDeviceDetailsServiceInterface;

    @StreamListener(value = NoticeTaskCallbackReceiverInterface.INPUT)
    public void input(PublishTaskResult taskResult){
        NoticePushDeviceDetails details = new NoticePushDeviceDetails();
        details.setTaskId(taskResult.getTaskId());
        details.setDeviceId(taskResult.getDeviceId());
        details.setDeviceName(taskResult.getDeviceName());
        details.setSerialNumber(taskResult.getSerialNumber());
        details.setInstallPath(taskResult.getInstallPath());
        details.setXqName(taskResult.getXqName());
        details.setDyName(taskResult.getDyName());
        details.setPushStatus(taskResult.getPushStatus());
        details.setRemark(taskResult.getRemark());
        details.setStatus(OperationConstant.ZERO);
        this.noticePushDeviceDetailsServiceInterface.insert(details);
    }

}
