package com.ekexiu.portal.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.jfw.apt.annotation.Autowrie;
import org.jfw.apt.web.annotation.Path;
import org.jfw.apt.web.annotation.operate.Delete;
import org.jfw.apt.web.annotation.operate.Get;
import org.jfw.apt.web.annotation.operate.Post;
import org.jfw.apt.web.annotation.param.JdbcConn;
import org.jfw.apt.web.annotation.param.PathVar;
import org.jfw.util.StringUtil;

import com.ekexiu.portal.dao.MessagesDao;
import com.ekexiu.portal.po.Messages;

@Path("/messages")
public class MessageService {
	@Autowrie
	private MessagesDao messagesDao;

	public MessagesDao getMessagesDao() {
		return messagesDao;
	}

	public void setMessagesDao(MessagesDao messagesDao) {
		this.messagesDao = messagesDao;
	}
	
	@Post
	@Path
	public String insert(@JdbcConn(true) Connection con, Messages messages) throws SQLException {
		messages.setMessageId(StringUtil.buildUUID());
		this.messagesDao.insert(con, messages);
		return messages.getMessageId();
	}
	
	@Get
	@Path("/{messageId}")
	public Messages query(@JdbcConn Connection con, @PathVar String messageId) throws SQLException {
		return this.messagesDao.query(con, messageId);
	}
	
	@Get
	@Path("/qaoper")
	public List<Messages> queryOper(@JdbcConn Connection con, String operationId) throws SQLException {
		return this.messagesDao.queryOper(con, operationId);
	}
	
	@Get
	@Path("/qapro")
	public List<Messages> queryPro(@JdbcConn Connection con, String operationId, String professorId) throws SQLException {
		return this.messagesDao.quetyPro(con, operationId, professorId);
	}
	
	@Delete
	@Path("/{messageId}")
	public void delete(@JdbcConn(true) Connection con, @PathVar String messageId) throws SQLException {
		this.messagesDao.delete(con, messageId);
	}
	
}
