package com.sv.oms.controller;

import com.sv.entity.Protocol;
import com.sv.service.oms.ProtocolService;
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-16
 */
@RestController
public class ProtocolController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(ProtocolController.class);
	
	@Resource
	private ProtocolService protocolService;

	/**
	 * 分页查询协议
	 */
	@RequestMapping(value = "/protocols", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(protocolService.findPage(pagination));
	}

	/**
	 * 查询协议信息
	 */
	@RequestMapping(value = "/protocol/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("protocol", protocolService.findById(id));
	}

	/**
	 * 保存协议
	 */
	@RequestMapping(value = "/protocol", method = RequestMethod.POST)
	public ResponseDTO save(Protocol protocol) {
		protocolService.save(protocol);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除协议
	 */
	@RequestMapping(value = "/protocol/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		protocolService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
