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

import cn.superdesk.libs.common.json.JsonUtils;
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.InvoiceInvoicedOperationLog;
import cn.superdesk.uniorder.dto.param.invoice.customer.invoiced.InvoiceInvoicedOperationLogParam;
import cn.superdesk.uniorder.dto.param.invoice.customer.invoiced.InvoiceInvoicedOperationLogQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.invoiced.InvoiceInvoicedOperationLogDubboConsumerService;
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("/invoiceInvoicedOperationLog")
public class InvoiceInvoicedOperationLogController extends BaseController {

	@Autowired
	private InvoiceInvoicedOperationLogDubboConsumerService invoiceInvoicedOperationLogDubboConsumerService;

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

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

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

		// TODO 参数合法性判定

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

		return result;
	}

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

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

		// TODO 参数合法性判定

		InvoiceInvoicedOperationLog entity = invoiceInvoicedOperationLogDubboConsumerService.findInvoiceInvoicedOperationLogById(id);

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

		result.setData(data);

		return result;
	}

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

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


		// TODO 参数合法性判定

		invoiceInvoicedOperationLogDubboConsumerService.addInvoiceInvoicedOperationLog(param);

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

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

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

		invoiceInvoicedOperationLogDubboConsumerService.updateInvoiceInvoicedOperationLog(param);

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

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

		// TODO 参数合法性判定

		invoiceInvoicedOperationLogDubboConsumerService.deleteInvoiceInvoicedOperationLog(id);

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

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

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

		for (long id : ids) {
			invoiceInvoicedOperationLogDubboConsumerService.deleteInvoiceInvoicedOperationLog(id);
		}

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

	}


}
