package com.sv.oms.controller;

import com.sv.entity.Recharge;
import com.sv.service.oms.RechargeService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 快速充值配置信息
 *
 * @author lihong
 * @since 2018-08-15
 */
@RestController
public class RechargeController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(RechargeController.class);
	
	@Resource
	private RechargeService rechargeService;

	/**
	 * 分页查询快速充值配置信息
	 */
	@RequestMapping(value = "/recharges", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(rechargeService.findPage(pagination));
	}

	/**
	 * 查询快速充值配置信息信息
	 */
	@RequestMapping(value = "/recharge/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("recharge", rechargeService.findById(id));
	}

	/**
	 * 保存快速充值配置信息
	 */
	@RequestMapping(value = "/recharge", method = RequestMethod.POST)
	public ResponseDTO save(Recharge recharge) {
		recharge.setPlatformId(1);
		rechargeService.save(recharge);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除快速充值配置信息
	 */
	@RequestMapping(value = "/recharge/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		rechargeService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
