package com.chinacreator.videoalliance.order.dao; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.chinacreator.common.dao.ExecutorDao; import com.chinacreator.common.exception.BusinessException; import com.chinacreator.videoalliance.common.util.DataSource; import com.chinacreator.videoalliance.order.bean.OrderInfo; import com.chinacreator.videoalliance.order.bean.OrderLog; import com.chinacreator.videoalliance.order.bean.TdYoutuOrderRecBean; import com.frameworkset.common.poolman.SQLExecutor; /** * 优酷后向产品 * @author xu.zhou * @date 20190516 */ @Component public class YoutuDao extends ExecutorDao { private static Logger logger = Logger.getLogger("orderError"); public List findByUser(String userid) throws SQLException { return getExecutor().queryListWithDBName(OrderInfo.class, "net3g", "findByUser", new Object[] { userid }); } public void order(OrderInfo orderInfo) throws Exception { getExecutor().insertBean("net3g", "order", orderInfo); } public HashMap getCpSp(String cpid, String spid) throws SQLException{ return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "getCpSp", new Object[] { cpid, spid }); } public HashMap findByUserAndSpid(String userid, String cpid, String spid) throws SQLException { return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "findByUserAndSpid", new Object[] { userid, cpid, spid }); } public List findByUserAndCpid(String userid, String cpid) throws SQLException { return getExecutor().queryListWithDBName(OrderInfo.class, "net3g", "findByUserAndCpid", new Object[] { userid, cpid }); } public List findOrderRecByUserid(String userid) throws SQLException { return getExecutor().queryListWithDBName(TdYoutuOrderRecBean.class, "net3g", "findOrderRecByUserid", new Object[] { userid }); } /** * 根据订单ID查询订单信息 * @param orderid * @return * @throws SQLException */ public List findOrderRecByOrderid(String orderid) throws SQLException { return getExecutor().queryListWithDBName(TdYoutuOrderRecBean.class, "net3g", "findOrderRecByOrderid", new Object[] { orderid }); } /** * 保存订购日志 * @param orderLog * @throws BusinessException */ public void addOrderLog(OrderLog orderLog) { try { this.getExecutor().insertBean(DataSource.NET3G, "addOrderLog", orderLog); } catch (SQLException e) { e.printStackTrace(); logger.error(orderLog.getUserid()+"=>保存订购日志失败", e); } } /** * 添加订购记录 * @param orderInfo * @throws BusinessException */ public void addOrderRec(TdYoutuOrderRecBean bean) throws Exception { this.getExecutor().insertBean(DataSource.NET3G, "addOrderRec", bean); } /** * 订购成功更新CDN和CP同步状态 * @param orderInfo * @return */ /* public int orderSuccess(OrderInfo orderInfo) throws Exception{ int result = 0; result = (Integer)this.getExecutor().updateWithDBName(DataSource.NET3G, "orderSuccess", new Object[] { orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid()}); return result; } */ /** * 设置订单rollback * @param orderid * @return */ /* public int orderRecRollback(OrderInfo orderInfo) throws Exception { int result = 0; result = (Integer)this.getExecutor().updateWithDBName(DataSource.NET3G, "orderRecRollback", new Object[] { orderInfo.getOrderid()}); return result; } */ /** * 设置赠送会员成功 * @param orderid * @return */ /* public int orderRecVipstatus(OrderInfo orderInfo)throws Exception { int result = 0; result = (Integer)this.getExecutor().updateWithDBName(DataSource.NET3G, "orderRecVipstatus", new Object[] { orderInfo.getOrderid()}); return result; } */ /** * 订购失败,ENDTIME回滚 * @param orderInfo * @return * @throws BusinessException */ /* public int orderFail(OrderInfo orderInfo,String oldEndTime)throws Exception { int result = 0; result = (Integer)this.getExecutor().updateWithDBName(DataSource.NET3G, "orderFail", new Object[] { oldEndTime, orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid()}); return result; } */ /** * 删除新增订购关系 * @param orderInfo * @return * @throws BusinessException */ /* public int orderFailDel(OrderInfo orderInfo)throws Exception { int result = 0; result = (Integer)this.getExecutor().updateWithDBName(DataSource.NET3G, "orderFailDel", new Object[] {orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid()}); return result; } */ /** * 获取当前时间 * @return * @throws SQLException */ public String getCurrentTime() throws SQLException { String sql = "select to_char(sysdate, 'yyyymmddhh24miss') from dual"; return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql); } /** * 获取从当前天起31天的有效期 * @return * @throws SQLException */ public String curr31Day() throws SQLException{ return getExecutor().queryFieldWithDBName(DataSource.NET3G, "curr31Day", new Object[] {}); } /** * 获取从指定时间加31天有效期 * @param endtime * @return * @throws SQLException */ public String endtime31Day(String endtime) throws SQLException{ return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtime31Day", new Object[] {endtime}); } /** * 生成ID * @return * @throws SQLException */ public String generateID() throws SQLException { String sql = "SELECT TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.NEXTVAL FROM DUAL"; return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql); } /** * 获取活动配置表数据 * @param cpid * @param spid * @param province * @return * @throws SQLException */ public Map getActivityInfo(String cpid, String spid, String province) throws SQLException{ String sql = "select cpid,spid,to_char(begintime,'yyyymmddhh24miss') begintime,to_char(endtime,'yyyymmddhh24miss') endtime,to_char(endtime,'yyyymmddhh24miss') cancelendtime ,activetype,province from TB_ACTIVITY_CONFIG where cpid = ? and spid = ? and province in ('0',?) and status =0 "; return SQLExecutor.queryObjectWithDBName(HashMap.class, DataSource.NET3G, sql,new Object[] { cpid, spid, province}); } /** * 根据ORDERID查询会员赠送状态 * @param orderid * @return * @throws SQLException */ public String getVipstatus(String orderid) throws SQLException{ String sql = "SELECT VIPSTATUS FROM TD_YOUTU_ORDER_REC WHERE ORDERID = ? "; return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, new Object[] {orderid}); } public static void main(String[] args) { try { YoutuDao dao = new YoutuDao(); // System.out.println(dao.findByUserAndSpid("18673197465", "youtu", "1167")); //System.out.println(dao.findOrderRecByUserid("18673197465")); OrderInfo orderInfo = new OrderInfo(); orderInfo.setUserid("18673197465"); orderInfo.setProvince("湖南"); orderInfo.setArea("长沙"); orderInfo.setOrderid("123456789"); orderInfo.setType(0); //dao.addOrderRec(orderInfo); //System.out.println(dao.endtime31Day("20190620235959")); //System.out.println(dao.findByUserAndSpid("18673197465", "youtu", "1167")); //System.out.println(dao.getCpSp("youtu", "1167")); //System.out.println(dao.getActivityInfo("youtu", "1167", "湖南")); //System.out.println(dao.generateID()); String vipstatus = dao.getVipstatus("028b4f73-14bc-4450-afaa-81a323ef9d24"); System.out.println(vipstatus); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }