package com.sv.api.controller;

import com.sv.entity.PayConfig;
import com.sv.service.api.PayConfigService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 支付参数配置表
 *
 * @author lihong
 * @since 2018-08-03
 */
@RestController
public class PayConfigController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(PayConfigController.class);
	
	@Resource
	private PayConfigService payConfigService;

	/**
	 * 分页查询支付参数配置表
	 */
	@RequestMapping(value = "/pay/configs", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(payConfigService.findPage(pagination));
	}

	/**
	 * 查询支付参数配置表信息
	 */
	@RequestMapping(value = "/pay/config/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("payConfig", payConfigService.findById(id));
	}

	/**
	 * 保存支付参数配置表
	 */
	@RequestMapping(value = "/pay/config", method = RequestMethod.POST)
	public ResponseDTO save(PayConfig payConfig) {
		payConfigService.save(payConfig);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除支付参数配置表
	 */
	@RequestMapping(value = "/pay/config/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		payConfigService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
