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

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.common.InvoiceTypeModeConfigSzhtxxElectronicInvoice;
import cn.superdesk.uniorder.dto.param.invoice.common.InvoiceTypeModeConfigSzhtxxElectronicInvoiceParam;
import cn.superdesk.uniorder.dto.param.invoice.common.InvoiceTypeModeConfigSzhtxxElectronicInvoiceQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.invoice.common.InvoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService;
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.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: 2022-02-10 17:46:12
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022-02-10 17:46:12
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "系统设置-发票种类-所属开票方式-深圳航信电子发票", tags = {"系统设置-发票种类-所属开票方式-深圳航信电子发票"})
@Slf4j
@RestController
@RequestMapping("/invoiceTypeModeConfigSzhtxxElectronicInvoice")
public class InvoiceTypeModeConfigSzhtxxElectronicInvoiceController extends BaseController {

	@Autowired
	private InvoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService invoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService;

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

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

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

		// TODO 参数合法性判定

		InvoiceTypeModeConfigSzhtxxElectronicInvoice entity = invoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService.findInvoiceTypeModeConfigSzhtxxElectronicInvoiceById(id);

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

		result.setData(data);

		return result;
	}

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

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


		// TODO 参数合法性判定

		invoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService.addInvoiceTypeModeConfigSzhtxxElectronicInvoice(param, getToken());

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

	@ApiOperation(value = "编辑-成功会自动更新对映-模块X发票种类X发票方式[深圳航信电子发票]-开通")
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public R<String> updateInvoiceTypeModeConfigSzhtxxElectronicInvoice(@RequestBody InvoiceTypeModeConfigSzhtxxElectronicInvoiceParam param) {

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

		invoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService.updateInvoiceTypeModeConfigSzhtxxElectronicInvoice(param, getToken());

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

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

		// TODO 参数合法性判定

		invoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService.deleteInvoiceTypeModeConfigSzhtxxElectronicInvoice(id, getToken());

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

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

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

		for (long id : ids) {
			invoiceTypeModeConfigSzhtxxElectronicInvoiceDubboConsumerService.deleteInvoiceTypeModeConfigSzhtxxElectronicInvoice(id, getToken());
		}

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

	}


}
