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.operate.Put;
import org.jfw.apt.web.annotation.param.JdbcConn;
import org.jfw.apt.web.annotation.param.PathVar;
import org.jfw.apt.web.annotation.param.RequestBody;
import org.jfw.util.StringUtil;

import com.ekexiu.portal.dao.PatentDao;
import com.ekexiu.portal.po.Patent;

@Path("/patent")
public class PatentService {
	@Autowrie
	private PatentDao patentDao;
	
	public PatentDao getPatentDao() {
		return patentDao;
	}

	public void setPatentDao(PatentDao patentDao) {
		this.patentDao = patentDao;
	}

	@Get
	@Path("/{id}")
	public Patent query(@JdbcConn Connection con,@PathVar String id) throws SQLException
	{
		return this.patentDao.queryOne(con, id);
	}
	@Post
	@Path
	public void insert(@JdbcConn(true) Connection con, Patent honor) throws SQLException {
		String id = StringUtil.buildUUID();
		honor.setId(id);
		this.patentDao.insert(con, honor);
	}

	@Put
	@Path
	public void update(@JdbcConn(true) Connection con, @RequestBody Patent honor) throws SQLException {
		this.patentDao.update(con, honor);
	}

	@Get
	@Path("/professor")
	public List<Patent> queryByProfessor(@JdbcConn(false) Connection con, String professorId) throws SQLException {
		return this.patentDao.query(con, professorId);
	}

	@Delete
	@Path("/{id}")
	public void delete(@JdbcConn(true) Connection con, @PathVar String id) throws SQLException {
		this.patentDao.delete(con, id);
	}
}
