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.TdPreOrderRecBean; import com.chinacreator.videoalliance.order.bean.TdPreOrderidRecBean; import com.chinacreator.videoalliance.order.bean.TdYoutuOrderRecBean; import com.frameworkset.common.poolman.SQLExecutor; /** * 优酷后向产品 * @author xu.zhou * @date 20190516 */ @Component public class TcPreDao extends ExecutorDao { private static Logger logger = Logger.getLogger("orderError"); /** * 订购 * @param orderInfo * @throws BusinessException */ public void order(OrderInfo orderInfo) throws SQLException { getExecutor().insertBean("net3g", "order", orderInfo); } /** * 退订 * @param orderInfo * @throws BusinessException */ public void cancelOrder(OrderInfo orderInfo) throws SQLException { getExecutor().insertBean("net3g", "cancelOrder", orderInfo); } public HashMap getCpSp(String cpid, String spid) throws SQLException{ return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "getCpSp", new Object[] { cpid, spid }); } /** * 查询本地订购关系表数据 * @param userid * @param cpid * @param spid * @return * @throws SQLException */ public HashMap findOrderRela(String userid, String cpid, String spid) throws SQLException { return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "findOrderRela", new Object[] { userid, cpid, spid }); } /** * 查询预订购表数据 * @param userid * @param cpid * @param spid * @return * @throws SQLException */ public HashMap findPreOrderRela(String userid, String cpid,String spid) throws SQLException { return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "findPreOrderRela", new Object[] { userid, cpid,spid }); } /** * 根据手机号码获得所有本地订购关系表数据 * @param userid * @return * @throws SQLException */ public List findOrderRelaAll(String userid) throws SQLException { return getExecutor().queryListWithDBName(HashMap.class, "net3g", "findOrderRelaAll", new Object[] { userid }); } /** * 根据手机号码获得所有预订购表数据 * @param userid * @return * @throws SQLException */ public List findPreOrderRelaAll(String userid) throws SQLException { return getExecutor().queryListWithDBName(HashMap.class, "net3g", "findPreOrderRelaAll", new Object[] { userid }); } /** * 查询是否有相同订单 * @param orderid * @return * @throws SQLException */ public List findOrderId(String orderid) throws SQLException { return getExecutor().queryListWithDBName(HashMap.class, "net3g", "findOrderId", new Object[] { orderid }); } /** * 添加订单ID记录 * @param bean * @throws SQLException */ public void addOrderRec(TdPreOrderidRecBean bean) throws SQLException { this.getExecutor().insertBean(DataSource.NET3G, "addOrderRec", bean); } /** * 保存订购日志 * @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); } } /** * 获取当月最后一天 * @return * @throws SQLException */ public String getEndDayOfCurrentMonth() throws SQLException { String sql = "select to_char(trunc(last_day(sysdate))+1-1/86400, 'yyyymmddhh24miss') from dual"; return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql); } /** * 获取当前时间 * @return * @throws SQLException */ public String getCurrTime() throws SQLException { return getExecutor().queryFieldWithDBName(DataSource.NET3G, "getCurrTime", new Object[] {}); } /** * 获取预订购ID * @return * @throws SQLException */ public String getPreOrderId() throws SQLException{ return getExecutor().queryFieldWithDBName(DataSource.NET3G, "getPreOrderId", new Object[] {}); } /** * 预订购 * @param bean * @throws SQLException */ public void orderPre(OrderInfo orderInfo) throws SQLException{ this.getExecutor().insertBean(DataSource.NET3G, "orderPre", orderInfo); } /** * 预退订 * @param bean * @throws SQLException */ public void cancelOrderPre(OrderInfo orderInfo) throws SQLException{ this.getExecutor().insertBean(DataSource.NET3G, "cancelOrderPre", orderInfo); } /** * 生成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 * @return * @throws SQLException */ public String endtimeMonthLastDay(String month)throws SQLException{ return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtimeMonthLastDay", new Object[] {month}); } /** * 查询是否有配置业务 * @param orderInfo * @return * @throws SQLException */ public boolean valiBusi(OrderInfo orderInfo) throws SQLException { String sql = "SELECT COUNT(1) CNT FROM TB_TCPRE_CONF WHERE STATUS = '0' AND SPID = ? "+ " AND (PROVINCE IS NULL OR PROVINCE = '0' OR PROVINCE = ?) "+ " AND (CHANNEL IS NULL OR CHANNEL = '0' OR CHANNEL = ?) "; if(1 == orderInfo.getType()){//退订,只要有配置的都查出来,业务下线不影响退订 sql = "SELECT COUNT(1) CNT FROM TB_TCPRE_CONF WHERE SPID = ? "+ " AND (PROVINCE IS NULL OR PROVINCE = '0' OR PROVINCE = ?) "+ " AND (CHANNEL IS NULL OR CHANNEL = '0' OR CHANNEL = ?) "; } String count = (String)SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, new Object[] {orderInfo.getSpid(),orderInfo.getProvince(),orderInfo.getChannel()}); return Integer.parseInt(count) > 0 ? true : false; } /** * 更新上海2元权益报文表 * @param orderno * @param logid * @throws SQLException */ public void updShInPaInfo(TdPreOrderidRecBean bean)throws SQLException { this.getExecutor().updateWithDBName(DataSource.NET3G, "updShInPaInfo", new Object[] {bean.getId(),bean.getLogid()}); } /** * 订购次月生效的产品 * @param orderInfo * @throws BusinessException */ public void nmaOrder(OrderInfo orderInfo) throws SQLException { getExecutor().insertBean(DataSource.NET3G, "nmaOrder", orderInfo); } /** * 订购次月生效的产品 * @param orderInfo * @throws BusinessException */ public void nmaCancel(OrderInfo orderInfo) throws SQLException { getExecutor().insertBean(DataSource.NET3G, "nmaCancel", orderInfo); } /** * 获取配置数据 * @param spid * @return * @throws SQLException */ public List qryAopConf(OrderInfo orderInfo) throws SQLException { return getExecutor().queryListWithDBName(HashMap.class, DataSource.NET3G, "qryAopConf", orderInfo.getSpid()); } /** * 获取已有订购关系 * @param orderInfo * @return * @throws SQLException */ public List qryNmaOrder(OrderInfo orderInfo) throws SQLException { return getExecutor().queryListWithDBName(HashMap.class, DataSource.NET3G, "qryNmaOrder", orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); } /** * 获取生效时间,下月第一天0时0分0秒 * @return * @throws SQLException */ public String getEffecttime() throws SQLException { String sql = "SELECT TO_CHAR(LAST_DAY(SYSDATE)+1,'YYYYMMDD')||'000000' EFFECTTIME FROM DUAL"; return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql); } /** * 添加订购日志 * @param orderLog * @throws SQLException */ public void addNmaOrderLog(OrderLog orderLog) throws SQLException { try { this.getExecutor().insertBean(DataSource.NET3G, "addNmaOrderLog", orderLog); } catch (SQLException e) { e.printStackTrace(); logger.error(orderLog.getUserid()+"=>保存订购日志失败", e); } } public static void main(String[] args) { try { TcPreDao dao = new TcPreDao(); // System.out.println(dao.findByUserAndSpid("18673197465", "youtu", "1167")); //System.out.println(dao.findOrderRecByUserid("18673197465")); OrderInfo orderInfo = new OrderInfo(); orderInfo.setOrdertime(dao.getCurrTime()); orderInfo.setCanceltime(dao.getCurrTime()); orderInfo.setEffecttime(dao.getEffecttime()); orderInfo.setOrderchannel("test"); orderInfo.setCancelchannel("test2"); orderInfo.setSubchannel("aaaaaaa"); orderInfo.setUserid("18673197465"); orderInfo.setProvince("湖南"); orderInfo.setArea("长沙"); orderInfo.setOrderid("123456789"); orderInfo.setType(1); orderInfo.setCpid("changshi"); orderInfo.setSpid("1261"); System.out.println(dao.qryNmaOrder(orderInfo)); //System.out.println(dao.valiBusi(orderInfo)); //dao.nmaCancel(orderInfo); //System.out.println(dao.findOrderRela(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid())); //dao.addOrderRec(orderInfo); //System.out.println(dao.findOrderId("20190524103510000001")); //System.out.println(dao.findPreOrderRela("18673197465", "youtu", "1167")); //System.out.println(dao.findPreOrderRelaAll("18673197465")); //System.out.println(dao.findOrderId("123456")); //System.out.println(dao.getCpSp("youtu", "1167")); //System.out.println(dao.getActivityInfo("youtu", "1167", "湖南")); // TdPreOrderidRecBean torBean = new TdPreOrderidRecBean(); // torBean.setArea("长沙"); // torBean.setOrderpreid("1111111111111111"); // torBean.setOrdertime("20190524104125"); // torBean.setOrderid("20190524103510000001"); // torBean.setProvince("湖南"); // torBean.setResultcode("0"); // torBean.setResultinfo("成功"); // torBean.setBusitype("0"); // torBean.setUserid("18673197465"); //dao.addOrderRec(torBean); //System.out.println(dao.getCurrTime()); // TdPreOrderRecBean bean = new TdPreOrderRecBean(); // bean.setArea("长沙"); // bean.setProvince("湖南"); // bean.setCpid("youtu"); // bean.setSpid("1167"); // bean.setStatus("0"); // bean.setUserid("18673197465"); // // bean.setOrderida("2019052410351"); // bean.setOrdertime("20190524104125"); // bean.setOrderchannel("ttest"); // // bean.setCancelchannel("test"); // bean.setCanceltime("20190524111321"); // bean.setOrderidb("refesddfsfd"); // bean.setStatus("1"); //dao.orderPre(bean); //dao.cancelOrderPre(bean); // bean.setOrderida("2019052"); // bean.setOrdertime("20190524104129"); // bean.setOrderchannel("t"); //dao.orderPre(bean); //dao.updShInPaInfo("kkkkkkk","a9b60c753eb341f09c988d70759e8768"); } catch (Exception e) { e.printStackTrace(); } } }