package lingtao.net.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lingtao.net.bean.Msg;
import lingtao.net.bean.SysDictSearchPro;
import lingtao.net.service.SysDictSearchProService;

@RestController
public class SysDictSearchProController {

	@Autowired
	private SysDictSearchProService searchProService;

	/**
	 * 查询关键字
	 * 
	 * @param searchPro
	 * @return
	 */
	@RequestMapping("/getKeyWordsList")
	public PageInfo<SysDictSearchPro> keyWordsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit, SysDictSearchPro searchPro) {
		PageHelper.startPage(page, limit);
		List<SysDictSearchPro> keyWordsList = searchProService.keyWordsList(searchPro);
		PageInfo<SysDictSearchPro> pageInfo = new PageInfo<SysDictSearchPro>(keyWordsList);
		return pageInfo;
	}

	/**
	 * 添加关键字
	 */
	@RequestMapping("/addSearchPro")
	public Msg addSearchPro(SysDictSearchPro searchPro, HttpSession session) {
		return searchProService.addSearchPro(searchPro, session);
	}

	/**
	 * 根据id修改关键字
	 * 
	 */
	@ResponseBody
	@RequestMapping("/updateKeyWord")
	public Msg updateKeyWordById(HttpSession session, @RequestParam(value = "id") int id,
			@RequestParam(value = "value") String value, @RequestParam(value = "field") String field) throws Exception {
		return searchProService.updateKeyWordById(session, id, value, field);
	}

	/**
	 * 改变用户状态
	 */
	@RequestMapping("/changeKeyWordsStatus")
	public Msg changeKeyWordStatus(@RequestParam(value = "id") Integer id) {
		return searchProService.changeKeyWordStatus(id);
	}
}
