package lingtao.net.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lingtao.net.bean.Information;
import lingtao.net.bean.Msg;
import lingtao.net.bean.StandardMemo;
import lingtao.net.service.InformationService;
import lingtao.net.service.StandardMemoService;
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 StandardMemoController {

    @Autowired
    private StandardMemoService standardMemoService;

    /**
     * 产品知识列表
     *
     * @return
     */
    @RequestMapping("/getStandard")
    public Msg getStandard(@RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "limit", defaultValue = "10") Integer limit, StandardMemo standardMemo) {
        PageHelper.startPage(page, limit);
        List<StandardMemo> standardMemoList = standardMemoService.getStandardMemos(standardMemo);
        PageInfo<StandardMemo> pageInfo = new PageInfo<>(standardMemoList);
        return Msg.success().add("list", pageInfo);
    }

    /**
     * 添加产品知识
     */
    @RequestMapping("/addStandard")
    public Msg addStandard(StandardMemo standardMemo, HttpSession session) {
        standardMemoService.addStandardMemo(standardMemo, session);
        return Msg.success();
    }

    /**
     * 修改产品知识
     */
    @RequestMapping("/updateStandard")
    public Msg updateStandard(StandardMemo standardMemo, HttpSession session) {
        standardMemoService.updateStandardMemoById(standardMemo, session);
        return Msg.success();
    }

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