package cn.superdesk.uniorder.controller.invoice.customer.invoiced;


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.invoice.customer.invoiced.InvoiceInvoicedBackCollectionOperationLog;
import cn.superdesk.uniorder.dto.param.invoice.customer.invoiced.InvoiceInvoicedBackCollectionOperationLogParam;
import cn.superdesk.uniorder.dto.param.invoice.customer.invoiced.InvoiceInvoicedBackCollectionOperationLogQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.invoiced.InvoiceInvoicedBackCollectionOperationLogDubboConsumerService;
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-07-28 15:28:43
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-07-28 15:28:43
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "客户结算-应收账款-回款日志", tags = {"客户结算-应收账款-回款日志"})
@Slf4j
@RestController
@RequestMapping("/invoiceInvoicedBackCollectionOperationLog")
public class InvoiceInvoicedBackCollectionOperationLogController extends BaseController {

	@Autowired
	private InvoiceInvoicedBackCollectionOperationLogDubboConsumerService invoiceInvoicedBackCollectionOperationLogDubboConsumerService;

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

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

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

		// TODO 参数合法性判定

		InvoiceInvoicedBackCollectionOperationLog entity = invoiceInvoicedBackCollectionOperationLogDubboConsumerService.findInvoiceInvoicedBackCollectionOperationLogById(id);

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

		result.setData(data);

		return result;
	}

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

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


		// TODO 参数合法性判定

		invoiceInvoicedBackCollectionOperationLogDubboConsumerService.addInvoiceInvoicedBackCollectionOperationLog(param);

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

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

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

		invoiceInvoicedBackCollectionOperationLogDubboConsumerService.updateInvoiceInvoicedBackCollectionOperationLog(param);

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

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

		// TODO 参数合法性判定

		invoiceInvoicedBackCollectionOperationLogDubboConsumerService.deleteInvoiceInvoicedBackCollectionOperationLog(id);

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

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

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

		for (long id : ids) {
			invoiceInvoicedBackCollectionOperationLogDubboConsumerService.deleteInvoiceInvoicedBackCollectionOperationLog(id);
		}

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

	}


}
