package cn.superdesk.uniorder.dubbo.provider.invoice.customer.invoiced;

import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dto.vo.invoice.customer.invoiced.InvoiceInvoicedExcelExportVo;
import cn.superdesk.uniorder.dubbo.facade.invoice.customer.invoiced.DubboInvoiceInvoicedFieldIsOverdueService;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsOverdueService;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @Description: 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 10/12/20 4:28 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 10/12/20 4:28 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service(version = "1.0.0", retries = -1, timeout = 10000)
public class DubboInvoiceInvoicedFieldIsOverdueServiceImpl implements DubboInvoiceInvoicedFieldIsOverdueService {

	@Autowired
	private InvoiceInvoicedFieldIsOverdueService invoiceInvoicedFieldIsOverdueService;

	/****************************************** 状态机 外部使用 类门面 start ******************************************/
	// 状态流转为 正常(0, "正常")
	@Override
	public void opInitOrReset(InvoiceInvoicedExcelExportVo form, LoginSysUser loginSysUser) {
		invoiceInvoicedFieldIsOverdueService.opInitOrReset(form, loginSysUser);
	}

	// 状态流转为 逾期(1, "逾期")
	@Override
	public void opOverdued(InvoiceInvoicedExcelExportVo form, LoginSysUser loginSysUser) {
		invoiceInvoicedFieldIsOverdueService.opOverdued(form, loginSysUser);
	}

	/****************************************** 状态机 外部使用 类门面   end ******************************************/

	@Override
	public void processInvoiceInvoicedsOverdueTask(InvoiceInvoicedExcelExportVo taskParams, LoginSysUser loginSysUser) {
		invoiceInvoicedFieldIsOverdueService.processInvoiceInvoicedsOverdueTask(taskParams, loginSysUser);
	}

	@Override
	public void kafkaInvoiceInvoicedsOverdueTaskReceive(String message, LoginSysUser loginSysUser) {

		log.info("##################### kafkaInvoiceInvoicedsOverdueTaskReceive start #####################\n原始:\n{}", message);

		try {

			InvoiceInvoicedExcelExportVo taskParams = AnJsonUtils.toObject(message, InvoiceInvoicedExcelExportVo.class);
			log.info("\n转换:\n{}", AnJsonUtils.toJson(taskParams));

			invoiceInvoicedFieldIsOverdueService.processInvoiceInvoicedsOverdueTask(taskParams, loginSysUser);

		} catch (Exception e) {

			log.error("kafkaInvoiceInvoicedsOverdueTaskReceive 任务处理 错误 \n " + ExceptionUtils.getMessage(e));

			e.printStackTrace();
		}
	}
}
