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.SzhtxxElectronicInvoiceFptxxResult;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxResultParam;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxResultQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.thirdpart.szhtxx.electronicInvoice.SzhtxxElectronicInvoiceFptxxResultDubboConsumerService;
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/electronicInvoiceFptxxResult")
public class SzhtxxElectronicInvoiceFptxxResultController extends BaseController {

	@Autowired
	private SzhtxxElectronicInvoiceFptxxResultDubboConsumerService szhtxxElectronicInvoiceFptxxResultDubboConsumerService;

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

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

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

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

		// TODO 参数合法性判定

		SzhtxxElectronicInvoiceFptxxResult entity = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.findSzhtxxElectronicInvoiceFptxxResultById(id);

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

		result.setData(data);

		return result;
	}

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

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


		// TODO 参数合法性判定

		szhtxxElectronicInvoiceFptxxResultDubboConsumerService.addSzhtxxElectronicInvoiceFptxxResult(param);

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

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

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

		szhtxxElectronicInvoiceFptxxResultDubboConsumerService.updateSzhtxxElectronicInvoiceFptxxResult(param);

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

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

		// TODO 参数合法性判定

		szhtxxElectronicInvoiceFptxxResultDubboConsumerService.deleteSzhtxxElectronicInvoiceFptxxResult(id);

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

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

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

		for (long id : ids) {
			szhtxxElectronicInvoiceFptxxResultDubboConsumerService.deleteSzhtxxElectronicInvoiceFptxxResult(id);
		}

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

	}

	//	@ApiModelProperty("引用ref.szhtxx_fptxx.fpqqlsh发票请求唯一流水号^_^每张发票的发票请求唯一流水号无重复,由企业定义.限制固定20位.流水号包含公司简称(如:华为终端:HWZD************)")
//	private String fpqqlsh;

	/**
	 * @param fpqqlsh
	 * @return
	 * @url http://192.168.6.223:8089/web/thirdpart/szhtxx/electronicInvoiceFptxxResult/savedPdfUrl/{fpqqlsh}
	 * @url http://192.168.6.223:8089/web/thirdpart/szhtxx/electronicInvoiceFptxxResult/savedPdfUrl/CIA2022030851533312
	 */
	@ApiOperation(value = "op转存-通过发票请求唯一流水号转存发票Pdf")
	@RequestMapping(value = "savedPdfUrl/{fpqqlsh}", method = RequestMethod.POST)
	@ResponseBody
	public R<String> savedPdfUrl(@PathVariable("fpqqlsh") String fpqqlsh) {

		int ret = szhtxxElectronicInvoiceFptxxResultDubboConsumerService.savedPdfUrl(fpqqlsh, getToken());

		return new R<>("200", fpqqlsh, true);
	}


}
