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.annotation.Nullable;
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.AssessDao;
import com.ekexiu.portal.po.Assess;

@Path("/assess")
public class AssessService {
	@Autowrie
	private AssessDao assessDao;

	public AssessDao getAssessDao() {
		return assessDao;
	}

	public void setAssessDao(AssessDao assessDao) {
		this.assessDao = assessDao;
	}
	
	@Post
	@Path
	public String insert(@JdbcConn(true) Connection con, Assess assess) throws SQLException {
		String assessId = StringUtil.buildUUID();
		assess.setAssessId(assessId);
		this.assessDao.insert(con, assess);
		return assessId;
	}
	
	@Get
	@Path("/{assessId}")
	public Assess query(@JdbcConn Connection con, @PathVar String assessId) throws SQLException {
		return this.assessDao.query(con, assessId);
	}
	
	@Get
	@Path("/qaoper")
	public List<Assess> queryOper(@JdbcConn Connection con, String operationId) throws SQLException {
		return this.assessDao.queryOper(con, operationId);
	}
	
	@Get
	@Path("/qares")
	public List<Assess> queryRes(@JdbcConn Connection con, String resourceId) throws SQLException {
		return this.assessDao.queryRes(con, resourceId);		
	}
	
	@Get
	@Path("/qapro")
	public List<Assess> queryPro(@JdbcConn Connection con, String professorId) throws SQLException {
		return this.assessDao.queryPro(con, professorId);
	}
	
	@Get
	@Path("/qa")
	public List<Assess> queryAll(@JdbcConn Connection con, @Nullable String operationId, @Nullable String resourceId, @Nullable String professorId) throws SQLException {
		if(operationId != null) {
			return this.queryOper(con, operationId);
		} else if(resourceId != null) {
			return this.queryRes(con, resourceId);
		} else if(professorId != null) {
			return this.queryPro(con, professorId);
		} else {
			return null;
		}
	}
	
	@Delete
	@Path("/{assessId}")
	public void delete(@JdbcConn(true) Connection con, String assessId) throws SQLException {
		this.assessDao.delete(con, assessId);
	}
	
	@Delete
	@Path("/deleteres")
	public void deleteRes(@JdbcConn(true) Connection con, String resourceId) throws SQLException {
		this.assessDao.deleteRes(con, resourceId);
	}
	
	@Delete
	@Path("/deletepro")
	public void deletePro(@JdbcConn(true) Connection con,String professorId) throws SQLException {
		this.assessDao.deletePro(con, professorId);
	}
	
}
