package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isOverdue.state.concrete;

import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.dto.vo.invoice.customer.invoiced.InvoiceInvoicedExcelExportVo;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isOverdue.context.InvoiceInvoicedFieldIsOverdueContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isOverdue.state.InvoiceInvoicedFieldIsOverdueState;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsOverdueService;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedService;
import cn.superdesk.uniorder.common.spring.SpringContextHolder;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 9/23/20 2:00 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 9/23/20 2:00 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@ToString
@AllArgsConstructor
public class InvoiceInvoicedFieldIsOverdueConcreteState_1_逾期 implements InvoiceInvoicedFieldIsOverdueState {

	private InvoiceInvoicedService               invoiceInvoicedService;
	private InvoiceInvoicedFieldIsOverdueService invoiceInvoicedFieldIsOverdueService;

	private InvoiceInvoicedFieldIsOverdueContext context;

	public InvoiceInvoicedFieldIsOverdueConcreteState_1_逾期(InvoiceInvoicedFieldIsOverdueContext context) {
		this.context = context;
		this.invoiceInvoicedService = (InvoiceInvoicedService) SpringContextHolder.getBean(InvoiceInvoicedService.class);
		this.invoiceInvoicedFieldIsOverdueService = (InvoiceInvoicedFieldIsOverdueService) SpringContextHolder.getBean(InvoiceInvoicedFieldIsOverdueService.class);
	}

	// 初始化或重置 -> 状态 -> 正常(0, "正常")
	public void opInitOrReset() {

		log.info("初始化或重置 -> 状态 -> {} -> 正常(0, \"正常\")", getClass().getName());

		InvoiceInvoiced              entity       = context.getEntity();
		InvoiceInvoicedExcelExportVo form         = context.getForm();
		LoginSysUser                 loginSysUser = context.getLoginSysUser();

		invoiceInvoicedFieldIsOverdueService.opInitOrResetByStateMachine(entity, form, loginSysUser);
	}

	// 计划任务检查-已逾期 -> 状态 -> 逾期(1, "逾期")
	public void opOverdued() {

		log.info("计划任务检查-已逾期 -> 状态 -> {} -> 逾期(1, \"逾期\")", getClass().getName());

		InvoiceInvoiced              entity       = context.getEntity();
		InvoiceInvoicedExcelExportVo form         = context.getForm();
		LoginSysUser                 loginSysUser = context.getLoginSysUser();

		invoiceInvoicedFieldIsOverdueService.opOverduedByStateMachine(entity, form, loginSysUser);
	}

}
