package cn.superdesk.uniorder.executor.scheduler.kafka._inner;

import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.executor.scheduler.kafka._inner._constants.InnerTopicChannelConstants;
import cn.superdesk.uniorder.executor.scheduler.kafka._inner._constants.enums.InvoiceApplyCustomerKafkaEventEnum;
import cn.superdesk.uniorder.executor.scheduler.kafka._inner.dto.invoice.customer.InvoiceApplyCustomerKafkaEventCheckAndUpdateAccountingOrderFieldInvoiceStatusEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/5/23 10:40 上午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/5/23 10:40 上午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class InvoiceApplyCustomerKafkaEventPublisher {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;


    private void tmpLog(String topic, String messageKey, String messageBody) {

        log.info("\n\n\n\n------------- QchjcStatementEventPublisher info start -------------" +
                        "\ntopic:        {}" +
                        "\nmessage_key:  {}" +
                        "\nmessage_body: {}",
                topic,
                messageKey,
                messageBody
        );
    }


    /**************************************** 基于发票单 联动 检查 对账的对账单 开票申请状态 且 更新 start ****************************************/


    public int checkAndUpdateAccountingOrderFieldInvoiceStatus(InvoiceApplyCustomerKafkaEventCheckAndUpdateAccountingOrderFieldInvoiceStatusEvent event) {

        String topic       = InnerTopicChannelConstants.TOPIC_EVENT_CHANNEL_INNER_INVOICE_APPLY_CUSTOMER_SERVICE;
        String messageKey  = InvoiceApplyCustomerKafkaEventEnum.基于发票单触发_检验与更新对账单字段开票申请状态.getKey();
        String messageBody = JSONUtil.toJsonStr(event);

        tmpLog(topic, messageKey, messageBody);

        kafkaTemplate.send(topic, messageKey, messageBody);

        return 1;

    }
}
