package com.sv.oms.controller;
import com.sv.service.oms.MemberCardOrderService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController;
import com.sv.entity.MemberCardOrder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 会员卡订单
 *
 * @author yechanglin
 * @since 2018-08-03
 */
@RestController
public class MemberCardOrderController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(MemberCardOrderController.class);
	
	@Resource
	private MemberCardOrderService memberCardOrderService;

	/**
	 * 分页查询会员卡订单
	 */
	@RequestMapping(value = "/member/card/orders", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination,
								@RequestParam(value = "payStatus",required = false) Integer payStatus,
								@RequestParam(value = "starTime",required = false) String starTime,
								@RequestParam(value = "endTime",required = false) String endTime,
								@RequestParam(value = "orderSn",required = false) String orderSn) {
		return ResponseDTO.ok()
				.setPagination(memberCardOrderService.findPage(pagination, payStatus, starTime, endTime, orderSn));
	}

	/**
	 * 查询会员卡订单信息
	 */
	@RequestMapping(value = "/member/card/order/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberCardOrder", memberCardOrderService.findById(id));
	}

	/**
	 * 保存会员卡订单
	 */
	@RequestMapping(value = "/member/card/order", method = RequestMethod.POST)
	public ResponseDTO save(MemberCardOrder memberCardOrder) {
		memberCardOrderService.save(memberCardOrder);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除会员卡订单
	 */
	@RequestMapping(value = "/member/card/order/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		memberCardOrderService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
