package lingtao.net.service;

import lingtao.net.bean.Msg;
import lingtao.net.bean.StandardMemo;
import lingtao.net.bean.SysUser;
import lingtao.net.bean.TipContent;
import lingtao.net.dao.StandardMemoMapper;
import lingtao.net.dao.TipContentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class TipContentService {

    @Autowired
    private TipContentMapper tipContentMapper;

    public List<TipContent> getTipContents(TipContent tipContent) {
        return tipContentMapper.getTipContents(tipContent);
    }

    public Msg addTipContent(TipContent tipContent, HttpSession session) {
        SysUser user = (SysUser) session.getAttribute("USER_SESSION");
        tipContent.setCreateBy(user.getRealname());
        try {
            tipContentMapper.addTipContent(tipContent);
            return Msg.success();
        } catch (Exception e) {
            return Msg.fail();
        }
    }

    public Msg updateTipContentById(TipContent tipContent, HttpSession session) {
        SysUser user = (SysUser) session.getAttribute("USER_SESSION");
        tipContent.setUpdateBy(user.getRealname());
        try {
            tipContentMapper.updateTipContentById(tipContent);
            return Msg.success();
        } catch (Exception e) {
            return Msg.fail();
        }

    }

    public Msg deleteTipContentById(Integer id) {
        try {
            tipContentMapper.deleteTipContentById(id);
            return Msg.success();
        } catch (Exception e) {
            return Msg.fail();
        }

    }

}
