package lingtao.net.service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lingtao.net.bean.Information;
import lingtao.net.bean.Msg;
import lingtao.net.bean.SysUser;
import lingtao.net.dao.InformationMapper;

@Service
public class InformationService {

	@Autowired
	private InformationMapper informationMapper;

	public List<Information> getInformations(Information information) {
		return informationMapper.getInformations(information);
	}

	public Msg addInformation(Information information, HttpSession session) {
		SysUser user = (SysUser) session.getAttribute("USER_SESSION");
		information.setCreateBy(user.getRealname());
		try {
			informationMapper.addInformation(information);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

	public Msg updateInformationById(Information information, HttpSession session) {
		SysUser user = (SysUser) session.getAttribute("USER_SESSION");
		information.setUpdateBy(user.getRealname());
		try {
			informationMapper.updateInformationById(information);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}

	}

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

	}

	public List<Information> getShortAnswers() {
		return informationMapper.getShortAnswers();
	}

}
