package cn.superdesk.uniorder.controller.invoice.customer.invoiced;

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.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.invoiced.InvoiceInvoicedDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.invoiced.InvoiceInvoicedFieldIsInvalidDubboConsumerService;
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 = "InvoiceInvoiced-IsInvalid", tags = {"InvoiceInvoiced-IsInvalid"})
@Slf4j
@RestController
@RequestMapping("/invoiceInvoiced/state/isInvalid")
public class InvoiceInvoicedFieldIsInvalidController extends BaseController {

	@Autowired
	private InvoiceInvoicedDubboConsumerService               invoiceInvoicedDubboConsumerService;
	@Autowired
	private InvoiceInvoicedFieldIsInvalidDubboConsumerService invoiceInvoicedFieldIsInvalidDubboConsumerService;

	@ApiOperation(value = "InvoiceInvoiced-IsInvalid-操作 初始化或反作废 状态改变为 正常_0")
	@RequestMapping(value = "/opInitOrBeValid/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opInitOrBeValid(@PathVariable("id") Long id) {

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

		try {
			InvoiceInvoiced entity = invoiceInvoicedDubboConsumerService.findById(id);
			invoiceInvoicedFieldIsInvalidDubboConsumerService.opInitOrBeValid(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 = "InvoiceInvoiced-IsInvalid-操作 作废 状态改变为 作废_1")
	@RequestMapping(value = "/opBecomeInvalid/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opBecomeInvalid(@PathVariable("id") Long id) {

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

		try {
			InvoiceInvoiced entity = invoiceInvoicedDubboConsumerService.findById(id);
			invoiceInvoicedFieldIsInvalidDubboConsumerService.opBecomeInvalid(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;
	}


}
