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.Msg;
import lingtao.net.bean.SysUser;
import lingtao.net.bean.UpdateLog;
import lingtao.net.dao.UpdateLogMapper;

@Service
public class UpdateLogService {

	@Autowired
	private UpdateLogMapper updateLogMapper;

	public List<UpdateLog> getUpdateLogs(UpdateLog updateLog) {

		return updateLogMapper.getUpdateLogs(updateLog);
	}

	public Msg addLog(UpdateLog updateLog, HttpSession session) {
		SysUser user = (SysUser) session.getAttribute("USER_SESSION");
		updateLog.setCreateBy(user.getRealname());
		try {
			updateLogMapper.addLog(updateLog);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

	public Msg updateLogById(UpdateLog updateLog, HttpSession session) {
		try {
			updateLogMapper.updateLogById(updateLog);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

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

	public Msg changeReadLogStatus() {
		try {
			updateLogMapper.changeReadLogStatus();
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

}
