package com.sv.oms.controller;

import com.sv.entity.AboutUs;
import com.sv.service.oms.AboutUsService;
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-15
 */
@RestController
public class AboutUsController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(AboutUsController.class);
	
	@Resource
	private AboutUsService aboutUsService;

	/**
	 * 分页查询关于我们
	 */
	@RequestMapping(value = "/about/uss", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(aboutUsService.findPage(pagination));
	}

	/**
	 * 查询关于我们信息
	 */
	@RequestMapping(value = "/about/us/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("aboutUs", aboutUsService.findById(id));
	}

	/**
	 * 保存关于我们
	 */
	@RequestMapping(value = "/about/us", method = RequestMethod.POST)
	public ResponseDTO save(AboutUs aboutUs) {
		aboutUsService.save(aboutUs);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除关于我们
	 */
	@RequestMapping(value = "/about/us/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		aboutUsService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
