package cn.superdesk.uniorder.controller.invoice.common;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.sys.SysInv;
import cn.superdesk.uniorder.dubbo.consumer.sys.SysInvDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Description: 弃用 发票信息
 * @Author: linjinyu
 * @CreateDate: 7/9/20 6:09 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 7/9/20 6:09 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/inv")
public class SysInvController extends BaseController {

	@Autowired
	SysInvDubboConsumerService sysInvDubboConsumerService;

	/**
	 * 返回收款方发票信息
	 *
	 * @return
	 */
	@PostMapping("/findById")
	@ResponseBody
	public R<SysInv> findById() {

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

		try {

			SysInv inv = sysInvDubboConsumerService.findById(1L);

			result.setData(inv);
			result.setSuccess(true);

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage(e.getMessage());

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();

			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 新增修改
	 *
	 * @param model
	 * @return
	 */
	@PostMapping("/saveOrUpdate")
	@ResponseBody
	public R<?> saveOrUpdate(SysInv model) {

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

		try {

			if (model.getId() == null) {
				// 新增
				sysInvDubboConsumerService.add(model);
				result.setSuccess(true);

			} else {
				// 修改
				sysInvDubboConsumerService.update(model);
				result.setSuccess(true);
			}

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage(e.getMessage());

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();

		}

		return result;
	}
}
