package com.sv.oms.controller;
import com.sv.service.oms.MemberCardService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.entity.enums.StatusEnum;
import com.ydd.oms.controller.OmsController;
import com.sv.entity.MemberCard;

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

import javax.annotation.Resource;

/**
 * Controller - 用户会员卡
 *
 * @author yechanglin
 * @since 2018-08-02
 */
@RestController
public class MemberCardController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(MemberCardController.class);
	
	@Resource
	private MemberCardService memberCardService;

	/**
	 * 分页查询用户会员卡
	 */
	@RequestMapping(value = "/member/cards", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination, Integer memberId, Byte status, Byte veneuType,
								@RequestParam(name = "venueName",required = false)String venueName) {
		return ResponseDTO.ok()
				.setPagination(memberCardService.findPage(pagination, memberId, status, veneuType,venueName));
	}

	/**
	 * 查询用户会员卡信息
	 */
	@RequestMapping(value = "/member/card/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberCard", memberCardService.findById(id));
	}

	/**
	 * 保存用户会员卡
	 */
	@RequestMapping(value = "/member/card", method = RequestMethod.POST)
	public ResponseDTO save(MemberCard memberCard) {
		memberCardService.save(memberCard);
		return ResponseDTO.ok("保存成功");
	}

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

}
