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.InvoiceInvoicedFieldisRedWriteOffDubboConsumerService;
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-isRedWriteOff", tags = {"InvoiceInvoiced-isRedWriteOff"})
@Slf4j
@RestController
@RequestMapping("/invoiceInvoiced/state/isRedWriteOff")
public class InvoiceInvoicedFieldisRedWriteOffController extends BaseController {

	@Autowired
	private InvoiceInvoicedDubboConsumerService                   invoiceInvoicedDubboConsumerService;
	@Autowired
	private InvoiceInvoicedFieldisRedWriteOffDubboConsumerService invoiceInvoicedFieldisRedWriteOffDubboConsumerService;

	@ApiOperation(value = "InvoiceInvoiced-isRedWriteOff-操作 初始化 状态改变为 否_0")
	@RequestMapping(value = "/opInit/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opInit(@PathVariable("id") Long id) {

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

		try {
			InvoiceInvoiced entity = invoiceInvoicedDubboConsumerService.findById(id);
			invoiceInvoicedFieldisRedWriteOffDubboConsumerService.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 = "InvoiceInvoiced-isRedWriteOff-操作 红冲发票 状态改变为 是_1")
	@RequestMapping(value = "/opRedWriteOff/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opRedWriteOff(@PathVariable("id") Long id) {

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

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


}
