package cn.superdesk.uniorder.controller.organisation;

import cn.superdesk.libs.common.json.JsonUtils;
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.organisation.SysCliqueXInvoice;
import cn.superdesk.uniorder.dto.param.organisation.SysCliqueXInvoiceParam;
import cn.superdesk.uniorder.dubbo.consumer.organisation.SysCliqueXInvoiceDubboConsumerService;
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.*;

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


/**
 * @Description:
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2021-05-13 19:10:28
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-05-13 19:10:28
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "集团分公司X发票抬头信息-集团分公司(数据来源-服务之窗)", tags = {"集团分公司X发票抬头信息-集团分公司(数据来源-服务之窗)"})
@Slf4j
@RestController
@RequestMapping("/sysCliqueXInvoice")
public class SysCliqueXInvoiceController extends BaseController {

	@Autowired
	private SysCliqueXInvoiceDubboConsumerService sysCliqueXInvoiceDubboConsumerService;

	@ApiOperation(value = "分页查询")
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	public R<List<SysCliqueXInvoice>> pageQuerySysCliqueXInvoices(@RequestBody PageQueryParam param) {

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

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

		// TODO 参数合法性判定

		SysCliqueXInvoice entity = sysCliqueXInvoiceDubboConsumerService.findSysCliqueXInvoiceById(id);

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

		result.setData(data);

		return result;
	}

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

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


		// TODO 参数合法性判定

		sysCliqueXInvoiceDubboConsumerService.addSysCliqueXInvoice(param);

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

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

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

		sysCliqueXInvoiceDubboConsumerService.updateSysCliqueXInvoice(param);

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

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

		// TODO 参数合法性判定

		sysCliqueXInvoiceDubboConsumerService.deleteSysCliqueXInvoice(id);

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

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

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

		for (long id : ids) {
			sysCliqueXInvoiceDubboConsumerService.deleteSysCliqueXInvoice(id);
		}

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

	}


}
