package lingtao.net.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lingtao.net.bean.Msg;
import lingtao.net.bean.StandardMemo;
import lingtao.net.bean.TipContent;
import lingtao.net.service.StandardMemoService;
import lingtao.net.service.TipContentService;
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.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class TipContentController {

    @Autowired
    private TipContentService tipContentService;

    /**
     * 产品知识列表
     *
     * @return
     */
    @RequestMapping("/getTipContent")
    public Msg getStandard(@RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "limit", defaultValue = "10") Integer limit, TipContent tipContent) {
        PageHelper.startPage(page, limit);
        List<TipContent> tipContentList = tipContentService.getTipContents(tipContent);
        PageInfo<TipContent> pageInfo = new PageInfo<>(tipContentList);
        return Msg.success().add("list", pageInfo);
    }

    /**
     * 添加产品知识
     */
    @RequestMapping("/addTipContent")
    public Msg addStandard(TipContent tipContent, HttpSession session) {
        tipContentService.addTipContent(tipContent, session);
        return Msg.success();
    }

    /**
     * 修改产品知识
     */
    @RequestMapping("/updateTipContent")
    public Msg updateStandard(TipContent tipContent, HttpSession session) {
        tipContentService.updateTipContentById(tipContent, session);
        return Msg.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/deleteTipContent")
    public Msg deleteStandard(@RequestParam("id") Integer id) {
        tipContentService.deleteTipContentById(id);
        return Msg.success();
    }
}
