package cn.superdesk.uniorder.controller._thirdpart.szhtxx.electronicInvoice;

import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.common.pagination.PageQueryGenericParam;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxx;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxParam;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxXmxxDubboConsumerService;
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: 2022-01-24 11:50:43
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022-01-24 11:50:43
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "第三方-深圳航天信息有限公司-电子发票-发票主体-项目信息", tags = {"第三方-深圳航天信息有限公司-电子发票-发票主体-项目信息"})
@Slf4j
@RestController
@RequestMapping("/thirdpart/szhtxx/electronicInvoiceFptxxXmxx")
public class SzhtxxElectronicInvoiceFptxxXmxxController extends BaseController {

	@Autowired
	private SzhtxxElectronicInvoiceFptxxXmxxDubboConsumerService szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService;

//	@ApiOperation(value = "分页查询 - 默认不用")
//	@RequestMapping(value = "listByObscure", method = RequestMethod.POST)
//	@ResponseBody
//	public R<List<SzhtxxElectronicInvoiceFptxxXmxx>> pageQuerySzhtxxElectronicInvoiceFptxxXmxx(@RequestBody PageQueryParam param) {
//
//		log.info("pageQuerySzhtxxElectronicInvoiceFptxxXmxx:\n{}", JSONUtil.toJsonStr(param));
//
//		R<List<SzhtxxElectronicInvoiceFptxxXmxx>> result = new R<>();
//
//		// TODO 参数合法性判定
//
//		result = szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService.pageQuery(param.getConditions(), param.getPageNo(), param.getPageSize());
//
//		return result;
//	}

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

		log.info("pageQuerySzhtxxElectronicInvoiceFptxxXmxx:\n{}", JSONUtil.toJsonStr(param));

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

		// TODO 参数合法性判定

		SzhtxxElectronicInvoiceFptxxXmxx entity = szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService.findSzhtxxElectronicInvoiceFptxxXmxxById(id);

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

		result.setData(data);

		return result;
	}

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

		log.info("addSzhtxxElectronicInvoiceFptxxXmxx:\n{}", JSONUtil.toJsonStr(param));


		// TODO 参数合法性判定

		szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService.addSzhtxxElectronicInvoiceFptxxXmxx(param);

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

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

		log.info("updateSzhtxxElectronicInvoiceFptxxXmxx:\n{}", JSONUtil.toJsonStr(param));

		szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService.updateSzhtxxElectronicInvoiceFptxxXmxx(param);

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

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

		// TODO 参数合法性判定

		szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService.deleteSzhtxxElectronicInvoiceFptxxXmxx(id);

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

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

		log.info(JSONUtil.toJsonStr(ids));

		for (long id : ids) {
			szhtxxElectronicInvoiceFptxxXmxxDubboConsumerService.deleteSzhtxxElectronicInvoiceFptxxXmxx(id);
		}

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

	}


}
