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.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.ConsultDao;
import com.ekexiu.portal.dao.TidingsDao;
import com.ekexiu.portal.po.Tidings;

@Path("/tidings")
public class TidingsService {
	@Autowrie
	private TidingsDao tidingsDao;
	@Autowrie
	private ConsultDao consultDao;
	
	public TidingsDao getTidingsDao() {
		return tidingsDao;
	}
	public void setTidingsDao(TidingsDao tidingsDao) {
		this.tidingsDao = tidingsDao;
	}
	public ConsultDao getConsultDao() {
		return consultDao;
	}
	public void setConsultDao(ConsultDao consultDao) {
		this.consultDao = consultDao;
	}
	
	@Post
	@Path
	public String insert(@JdbcConn(true) Connection con, Tidings tidings) throws SQLException {
		String tidingsId = StringUtil.buildUUID();
		tidings.setTidingsId(tidingsId);
		this.tidingsDao.insert(con, tidings);
		String consultId = tidings.getConsultId();
		this.consultDao.updateRevoveryTime(con, consultId);
		return tidingsId;
	}
	
	@Get
	@Path("/{tidingsId}")
	public Tidings query(@JdbcConn Connection con, @PathVar String tidingsId) throws SQLException {
		return this.tidingsDao.query(con, tidingsId);
	}
	
	@Get
	@Path("/qacon")
	public List<Tidings> queryCon(@JdbcConn Connection con, String consultId) throws SQLException {
		return this.tidingsDao.queryCon(con, consultId);
	}
}
