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

	@Autowired
	private InvoiceInvoicedDubboConsumerService             invoiceInvoicedDubboConsumerService;
	@Autowired
	private InvoiceInvoicedFieldDeletedDubboConsumerService invoiceInvoicedFieldDeletedDubboConsumerService;

	@ApiOperation(value = "InvoiceInvoiced-Deleted-操作 初始化或恢复 状态改变为 正常_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);
			invoiceInvoicedFieldDeletedDubboConsumerService.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-Deleted-操作 软删除 状态改变为 删除_1")
	@RequestMapping(value = "/opDelete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<?> opDelete(@PathVariable("id") Long id) {

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

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


}
