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

import cn.superdesk.libs.common.json.JsonUtils;
import cn.superdesk.uniorder.common.pagination.PageQueryGenericParam;
import cn.superdesk.uniorder.common.pagination.PageQueryParam;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.invoice.supplier.InvoiceApplySupplierXGoods;
import cn.superdesk.uniorder.dto.param.invoice.supplier.InvoiceApplySupplierXGoodsParam;
import cn.superdesk.uniorder.dto.param.invoice.supplier.InvoiceApplySupplierXGoodsQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.invoice.supplier.InvoiceApplySupplierXGoodsDubboConsumerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description:
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2021-12-09 17:35:01
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-12-09 17:35:01
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/invoiceApplySupplierXGoods")
public class InvoiceApplySupplierXGoodsController extends BaseController {

	@Autowired
	private InvoiceApplySupplierXGoodsDubboConsumerService invoiceApplySupplierXGoodsDubboConsumerService;

	@ApiOperation(value = "分页查询 - 默认不用")
	@RequestMapping(value = "listByObscure", method = RequestMethod.POST)
	@ResponseBody
	public R<List<InvoiceApplySupplierXGoods>> pageQueryInvoiceApplySupplierXGoods(@RequestBody PageQueryParam param) {

		log.info("pageQueryInvoiceApplySupplierXGoods:\n{}", JsonUtils.toJson(param));

		R<List<InvoiceApplySupplierXGoods>> result = new R<>();

		// TODO 参数合法性判定

		result = invoiceApplySupplierXGoodsDubboConsumerService.pageQuery(param.getConditions(), param.getPageNo(), param.getPageSize());

		return result;
	}

	@ApiOperation(value = "分页查询")
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	public R<List<InvoiceApplySupplierXGoods>> pageQueryGenericParamInvoiceApplySupplierXGoods(@RequestBody PageQueryGenericParam<InvoiceApplySupplierXGoodsQueryCriteria> param) {

		log.info("pageQueryInvoiceApplySupplierXGoods:\n{}", JsonUtils.toJson(param));

		R<List<InvoiceApplySupplierXGoods>> result = new R<>();

		// TODO 参数合法性判定

		result = invoiceApplySupplierXGoodsDubboConsumerService.pageQueryGenericParam(param.getConditions());

		return result;
	}

	@ApiOperation(value = "按id查询")
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	@ResponseBody
	public R<List<InvoiceApplySupplierXGoods>> getById(@PathVariable("id") long id) {

		R<List<InvoiceApplySupplierXGoods>> result = new R<>();

		// TODO 参数合法性判定

		InvoiceApplySupplierXGoods entity = invoiceApplySupplierXGoodsDubboConsumerService.findInvoiceApplySupplierXGoodsById(id);

		List<InvoiceApplySupplierXGoods> data = new ArrayList<>();
		data.add(entity);

		result.setData(data);

		return result;
	}

	@ApiOperation(value = "新增")
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public R<String> addInvoiceApplySupplierXGoods(@RequestBody InvoiceApplySupplierXGoodsParam param) {

		log.info("addInvoiceApplySupplierXGoods:\n{}", JsonUtils.toJson(param));


		// TODO 参数合法性判定

		invoiceApplySupplierXGoodsDubboConsumerService.addInvoiceApplySupplierXGoods(param);

		return new R<>("200", "操作成功", true);
	}

	@ApiOperation(value = "更新")
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public R<String> updateInvoiceApplySupplierXGoods(@RequestBody InvoiceApplySupplierXGoodsParam param) {

		log.info("updateInvoiceApplySupplierXGoods:\n{}", JsonUtils.toJson(param));

		invoiceApplySupplierXGoodsDubboConsumerService.updateInvoiceApplySupplierXGoods(param);

		return new R<>("200", "操作成功", true);
	}

	@ApiOperation(value = "删除")
	@RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<String> deleteInvoiceApplySupplierXGoods(@PathVariable("id") long id) {

		// TODO 参数合法性判定

		invoiceApplySupplierXGoodsDubboConsumerService.deleteInvoiceApplySupplierXGoods(id);

		return new R<>("200", "操作成功", true);
	}

	@ApiOperation(value = "批量删除")
	@RequestMapping(value = "delete_ids", method = RequestMethod.POST)
	@ResponseBody
	public R<String> deleteIdsInvoiceApplySupplierXGoods(@RequestParam(value = "ids") long[] ids) {

		log.info(JsonUtils.toJson(ids));

		for (long id : ids) {
			invoiceApplySupplierXGoodsDubboConsumerService.deleteInvoiceApplySupplierXGoods(id);
		}

		return new R<>("200", "操作成功", true);

	}


}
