package com.sv.oms.controller;
import com.sv.service.oms.VenueLessonTicketService;
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.VenueLessonTicket;

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

import javax.annotation.Resource;

/**
 * Controller - 课程票据
 *
 * @author zhaoziyu
 * @since 2018-08-06
 */
@RestController
public class VenueLessonTicketController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(VenueLessonTicketController.class);
	
	@Resource
	private VenueLessonTicketService venueLessonTicketService;

	/**
	 * 分页查询课程票据
	 */
	@RequestMapping(value = "/venue/lesson/tickets", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(venueLessonTicketService.findPage(pagination));
	}

	/**
	 * 查询课程票据信息
	 */
	@RequestMapping(value = "/venue/lesson/ticket/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("venueLessonTicket", venueLessonTicketService.findById(id));
	}

	/**
	 * 保存课程票据
	 */
	@RequestMapping(value = "/venue/lesson/ticket", method = RequestMethod.POST)
	public ResponseDTO save(VenueLessonTicket venueLessonTicket) {
		venueLessonTicketService.save(venueLessonTicket);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除课程票据
	 */
	@RequestMapping(value = "/venue/lesson/ticket/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		venueLessonTicketService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

	/**
	 * 变更课程票据状态
	 */
	@RequestMapping(value = "/venue/lesson/ticket/status", method = RequestMethod.POST)
	public ResponseDTO updateStatus(@RequestParam("id[]") Integer[] ids, Byte status) {
		venueLessonTicketService.updateStatus(ids, status);
		String operationName = (StatusEnum.ENABLE.value.equals(status) ? "启用" : "禁用") + "成功";
		return ResponseDTO.ok(operationName);
	}

}
