package com.sv.oms.controller;
import com.sv.dto.oms.VenueLessonOmsDTO;
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.VenueLesson;
import com.sv.service.oms.VenueLessonService;

import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * Controller - 场馆课程
 *
 * @author zhaoziyu
 * @since 2018-08-06
 */
@RestController
public class VenueLessonController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(VenueLessonController.class);
	
	@Resource
	private VenueLessonService venueLessonService;

	/**
	 * 分页查询场馆课程
	 */
	@RequestMapping(value = "/venue/lessons", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination, String leftTime, String rightTime) {
		return ResponseDTO.ok()
				.setPagination(venueLessonService.findPage(pagination, leftTime, rightTime));
	}

	/**
	 * 查询场馆课程信息
	 */
	@RequestMapping(value = "/venue/lesson/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("venueLesson", venueLessonService.findByIdForOms(id));
	}

	/**
	 * 保存场馆课程
	 */
	@RequestMapping(value = "/venue/lesson", method = RequestMethod.POST)
	public ResponseDTO save(VenueLessonOmsDTO venueLesson) throws ParseException {
		venueLessonService.save(venueLesson);
		return ResponseDTO.ok("保存成功");
	}

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

}
