package cn.superdesk.uniorder.controller.invoice.supplier.state;

import cn.superdesk.uniorder.common.constants.ResponseMsgConstants;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.invoice.supplier.InvoiceApplySupplier;
import cn.superdesk.uniorder.dubbo.consumer.invoice.supplier.InvoiceApplySupplierDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.invoice.supplier.InvoiceApplySupplierFieldMailTickStatusDubboConsumerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 10/12/20 4:28 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 10/12/20 4:28 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "InvoiceApplySupplier - MailTickStatus", tags = {"InvoiceApplySupplier - MailTickStatus"})
@Slf4j
@RestController
@RequestMapping("/invoice/apply/supplier/score/state/mailTickStatus")
public class InvoiceApplySupplierScoreFieldMailTickStatusController extends BaseController {

	@Autowired
	private InvoiceApplySupplierDubboConsumerService                    invoiceApplySupplierDubboConsumerService;
	@Autowired
	private InvoiceApplySupplierFieldMailTickStatusDubboConsumerService invoiceApplySupplierFieldMailTickStatusDubboConsumerService;

	@ApiOperation(value = "InvoiceApplySupplier - MailTickStatus - 操作 供应商|商户 开票后 未寄出 状态改变为 未邮寄_0")
	@RequestMapping(value = "/opInit/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opInit(@PathVariable("id") Long id) {

		R<?> result = new R<>();

		try {
			InvoiceApplySupplier entity = invoiceApplySupplierDubboConsumerService.findById(id);
			invoiceApplySupplierFieldMailTickStatusDubboConsumerService.opInit(getToken(), entity);
			result.setSuccess(true);

		} catch (Exception e) {

			result.setSuccess(false);
			result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}
		return result;
	}

	@ApiOperation(value = "InvoiceApplySupplier - MailTickStatus - 操作 供应商|商户 op寄票登记 开票后 寄出发票 状态改变为 已邮寄_1")
	@RequestMapping(value = "/opComplete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opComplete(@PathVariable("id") Long id) {

		R<?> result = new R<>();

		try {
			InvoiceApplySupplier entity = invoiceApplySupplierDubboConsumerService.findById(id);
			invoiceApplySupplierFieldMailTickStatusDubboConsumerService.opComplete(getToken(), entity);
			result.setSuccess(true);

		} catch (Exception e) {

			result.setSuccess(false);
			result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}
		return result;
	}


}
