package com.chinacreator.process.dao;

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

import javax.annotation.PostConstruct;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.chinacreator.common.dao.CacheableDao;
import com.chinacreator.common.support.cache.annotation.CacheName;
import com.chinacreator.process.bean.OrderConfigBean;
import com.chinacreator.process.util.DataSource;
import com.frameworkset.common.poolman.PreparedDBUtil;

@Component
@CacheName("OrderConfigBean")
public class OrderConfigDao extends CacheableDao{

		@SuppressWarnings("unchecked")
		@PostConstruct
		public void loadCache() throws SQLException {
			PreparedDBUtil pdb = new PreparedDBUtil();
			String sql = "select * from TB_CHANNELORDER_CONFIG where status = 0 ";
			List<OrderConfigBean> orderConfigBeans = pdb.executeSelectForList(DataSource.SDK, sql, OrderConfigBean.class);
			for(OrderConfigBean orderConfigBean : orderConfigBeans) {
				addCache("OrderConfigBean", orderConfigBean.getVacproductid(), orderConfigBean);
			}
		}
		
		@Cacheable(value="OrderConfigBean", key="#vacproductid")
		public OrderConfigBean findByProductid(String vacproductid){
			PreparedDBUtil pdb = new PreparedDBUtil();
			String sql = "select * from TB_CHANNELORDER_CONFIG where vacproductid = ? and status = 0";
			try {
				pdb.preparedSelect(DataSource.SDK, sql);
				pdb.setString(1, vacproductid);
				return (OrderConfigBean) pdb.executePreparedForObject(OrderConfigBean.class);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return null;
		}
}
