386f9242f60109360693fe15b5437ec47e41c083.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. package com.chinacreator.videoalliance.order.dao;
  2. import com.chinacreator.common.dao.ExecutorDao;
  3. import com.chinacreator.common.exception.BusinessException;
  4. import com.chinacreator.videoalliance.common.util.DataSource;
  5. import com.chinacreator.videoalliance.order.bean.BackBusiOrderRec;
  6. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  7. import com.chinacreator.videoalliance.order.bean.OrderLog;
  8. import com.frameworkset.common.poolman.SQLExecutor;
  9. import org.apache.log4j.Logger;
  10. import org.springframework.stereotype.Component;
  11. import java.io.ByteArrayOutputStream;
  12. import java.io.PrintWriter;
  13. import java.sql.SQLException;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * 优酷后向产品
  19. * @author xu.zhou
  20. * @date 20190516
  21. */
  22. @Component
  23. public class BackBusiOrderDao extends ExecutorDao {
  24. private static Logger logger = Logger.getLogger("orderError");
  25. public List<OrderInfo> findByUser(String userid) throws SQLException {
  26. return getExecutor().queryListWithDBName(OrderInfo.class, "net3g", "findByUser", new Object[] { userid });
  27. }
  28. public void order(OrderInfo orderInfo) throws Exception {
  29. getExecutor().insertBean("net3g", "order", orderInfo);
  30. }
  31. public HashMap getCpSp(String cpid, String spid) throws SQLException{
  32. return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "getCpSp", new Object[] { cpid, spid });
  33. }
  34. public HashMap findByUserAndSpid(String userid, String cpid, String spid) throws SQLException {
  35. return (HashMap)getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "findByUserAndSpid", new Object[] { userid, cpid, spid });
  36. }
  37. public List<OrderInfo> findByUserAndCpid(String userid, String cpid) throws SQLException {
  38. return getExecutor().queryListWithDBName(OrderInfo.class, "net3g", "findByUserAndCpid", new Object[] { userid, cpid });
  39. }
  40. public List<BackBusiOrderRec> findOrderRecByUserid(String userid) throws SQLException {
  41. return getExecutor().queryListWithDBName(BackBusiOrderRec.class, "net3g", "findOrderRecByUserid", new Object[] { userid });
  42. }
  43. /**
  44. * 根据订单ID查询订单信息
  45. * @param orderid
  46. * @return
  47. * @throws SQLException
  48. */
  49. public List<BackBusiOrderRec> findOrderRecByOrderid(String orderid) throws SQLException {
  50. return getExecutor().queryListWithDBName(BackBusiOrderRec.class, "net3g", "findOrderRecByOrderid", new Object[] { orderid });
  51. }
  52. /**
  53. * 保存订购日志
  54. * @param orderLog
  55. * @throws SQLException
  56. * @throws BusinessException
  57. */
  58. public void addOrderLog(OrderLog orderLog) throws SQLException {
  59. this.getExecutor().insertBean(DataSource.NET3G, "addOrderLog", orderLog);
  60. }
  61. /**
  62. * 添加订购记录
  63. * @param orderInfo
  64. * @throws BusinessException
  65. */
  66. public void addOrderRec(BackBusiOrderRec bean) throws Exception {
  67. try{
  68. this.getExecutor().insertBean(DataSource.NET3G, "addOrderRec", bean);
  69. }catch(Exception e){
  70. ByteArrayOutputStream buf=new ByteArrayOutputStream();
  71. e.printStackTrace(new PrintWriter(buf,true));
  72. String expMessage=buf.toString();
  73. if(expMessage.indexOf("ORA-00001")!=-1){ //
  74. //System.out.println("=============+++++++++++++++====违反唯一约束");
  75. throw new BusinessException("9001", "重复订单,不处理");
  76. }else{
  77. throw e;
  78. }
  79. }
  80. }
  81. /**
  82. * 更新订购信息表
  83. * @param BackBusiOrderRec
  84. * @return
  85. * @throws SQLException
  86. */
  87. public void updOrderRecByVipRetry(BackBusiOrderRec orderBean) {
  88. try {
  89. String sql = " UPDATE TD_BACKBUSI_ORDER_REC SET VIPSTATUS = ?, RETRYTIME = SYSDATE, RETRYCHANNEL = ?, RETRYCOUNT = ?, RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  90. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, orderBean.getVipstatus(), orderBean.getRetrychannel(),
  91. orderBean.getRetrycount(),orderBean.getResultcode(),orderBean.getResultinfo(),orderBean.getId());
  92. } catch (SQLException e) {
  93. e.printStackTrace();
  94. logger.error("orderId: "+orderBean.getId()+", 更新订购信息表出现异常,"+e.getMessage());
  95. }
  96. }
  97. /**
  98. * 获取当前时间
  99. * @return
  100. * @throws SQLException
  101. */
  102. public String getCurrentTime() throws SQLException {
  103. String sql = "select to_char(sysdate, 'yyyymmddhh24miss') from dual";
  104. return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql);
  105. }
  106. /**
  107. * 获取从当前天起31天的有效期
  108. * @return
  109. * @throws SQLException
  110. */
  111. public String curr31Day() throws SQLException{
  112. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "curr31Day", new Object[] {});
  113. }
  114. /**
  115. * 获取从指定时间加31天有效期
  116. * @param endtime
  117. * @return
  118. * @throws SQLException
  119. */
  120. public String endtime31Day(String endtime) throws SQLException{
  121. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtime31Day", new Object[] {endtime});
  122. }
  123. /**
  124. * 获取从当前天起加多少天的有效期
  125. * @param days 加多少天
  126. * @return
  127. * @throws SQLException
  128. */
  129. public String currParamDay(String days) throws SQLException{
  130. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "currParamDay", new Object[] {days});
  131. }
  132. /**
  133. * 获取从指定时间加多少天有效期
  134. * @param days 加多少天
  135. * @param endtime 起始日期
  136. * @return
  137. * @throws SQLException
  138. */
  139. public String endtimeParamDay(String days,String endtime) throws SQLException{
  140. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtimeParamDay", new Object[] {days,endtime});
  141. }
  142. /**
  143. * 获取当月最后一秒的时间
  144. * @param
  145. * @return
  146. * @throws SQLException
  147. */
  148. public String endtimeTheMonthLastDay()throws SQLException{
  149. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtimeTheMonthLastDay", new Object[] {});
  150. }
  151. /**
  152. * 获取当月最后一秒的时间
  153. * @param
  154. * @return
  155. * @throws SQLException
  156. */
  157. public String endtimeNextMonthLastDay(String endtime)throws SQLException{
  158. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtimeNextMonthLastDay", new Object[] {endtime});
  159. }
  160. /**
  161. * 生成ID
  162. * @return
  163. * @throws SQLException
  164. */
  165. public String generateID() throws SQLException {
  166. String sql = "SELECT TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.NEXTVAL FROM DUAL";
  167. return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql);
  168. }
  169. /**
  170. * 获取活动配置表数据
  171. * @param cpid
  172. * @param spid
  173. * @param province
  174. * @return
  175. * @throws SQLException
  176. */
  177. public Map getActivityInfo(String cpid, String spid, String province) throws SQLException{
  178. 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 ";
  179. return SQLExecutor.queryObjectWithDBName(HashMap.class, DataSource.NET3G, sql,new Object[] { cpid, spid, province});
  180. }
  181. /**
  182. * 根据ORDERID查询会员赠送状态
  183. * @param orderid
  184. * @return
  185. * @throws SQLException
  186. */
  187. public String getVipstatus(String orderid) throws SQLException{
  188. String sql = "SELECT VIPSTATUS FROM TD_BACKBUSI_ORDER_REC WHERE ORDERID = ? ";
  189. return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, new Object[] {orderid});
  190. }
  191. /**
  192. * 获取后向产品配置信息
  193. * @param cpid
  194. * @param spid
  195. * @return
  196. * @throws SQLException
  197. */
  198. public List<HashMap> getBackBusiConf(String cpid, String spid) throws SQLException {
  199. return getExecutor().queryListWithDBName(HashMap.class, "net3g", "getBackBusiConf", new Object[] { cpid, spid });
  200. }
  201. /**
  202. *
  203. * @param vipStatus
  204. * @param resultCode
  205. * @param resultInfo
  206. * @param id
  207. * @return
  208. * @throws SQLException
  209. */
  210. public boolean updBusiStatus(String vipStatus, String resultCode, String resultInfo, String id) throws SQLException {
  211. //赠送会员状态,0成功,1未赠送,2赠送中,3失败,4不赠送
  212. String sql = " UPDATE TD_BACKBUSI_ORDER_REC SET VIPSTATUS = ? , RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  213. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, vipStatus, resultCode, resultInfo, id);
  214. return ((Integer)obj)>0 ? true : false;
  215. }
  216. /**
  217. * 更新订购记录表
  218. * @param vipstatus 赠送会员状态
  219. * @param resultCode 处理结果
  220. * @param resultInfo
  221. * @param orderId 订单ID
  222. * @param busitype 业务类型
  223. * @throws SQLException
  224. */
  225. // public void updOrderRec(String vipstatus, String resultCode, String resultInfo, String orderId, String busitype) throws SQLException {
  226. // String sql = " UPDATE TD_BACKBUSI_ORDER_REC SET VIPSTATUS = ?, RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  227. // Object[] obj = new Object[]{vipstatus, resultCode, resultInfo, orderId};
  228. // if("2".equals(busitype)){
  229. // sql = " UPDATE TD_BACKBUSI_ORDER_REC SET RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  230. // obj = new Object[]{resultCode, resultInfo, orderId};
  231. // }
  232. // //Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, vipstatus, resultCode, resultInfo, orderId);
  233. // SQLExecutor.updateWithDBName(DataSource.NET3G, sql, obj);
  234. // }
  235. /**
  236. * 获取两个时间相差分钟数
  237. * @param rectime
  238. * @return
  239. * @throws SQLException
  240. */
  241. public boolean getMinNum(String rectime, int minute) throws SQLException {
  242. String sql = "select FLOOR((SYSDATE - TO_DATE(?,'yyyymmddhh24miss'))*24*60) AS FZNUM FROM DUAL";
  243. int num = SQLExecutor.queryObjectWithDBName(Integer.class, DataSource.NET3G,sql, rectime);
  244. if(num < minute){
  245. return false;
  246. }else{
  247. return true;
  248. }
  249. }
  250. /**
  251. * 获取从指定时间减31天后的日期
  252. * @param endtime
  253. * @return
  254. * @throws SQLException
  255. */
  256. public String endtimeMinus31Day(String endtime) throws SQLException{
  257. return getExecutor().queryFieldWithDBName(DataSource.NET3G, "endtimeMinus31Day", new Object[] {endtime});
  258. }
  259. /**
  260. * 根据手机号码、CPID、SPID查找有效的订购关系
  261. * @param bean
  262. * @return
  263. * @throws SQLException
  264. */
  265. public Map findYoutuOrderRal(BackBusiOrderRec bean) throws SQLException{
  266. return getExecutor().queryObjectBeanWithDBName(HashMap.class, DataSource.NET3G, "findYoutuOrderRal", bean);
  267. }
  268. /**
  269. * 退订
  270. * @param orderInfo
  271. * @throws Exception
  272. */
  273. public void cancel(OrderInfo orderInfo) throws Exception {
  274. getExecutor().insertBean("net3g", "cancel", orderInfo);
  275. }
  276. /**
  277. * 获取开始时间
  278. * @param endtime
  279. * @param netdays //免流天数
  280. * @return
  281. * @throws SQLException
  282. */
  283. public String getStartTime(String endtime, String netdays)throws SQLException{
  284. String sql = " SELECT TO_CHAR(TO_DATE(?,'YYYYMMDDHH24MISS')-?+2/(24*60*60),'YYYYMMDDHH24MISS') FROM DUAL ";
  285. return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, new Object[] {endtime,netdays});
  286. }
  287. /**
  288. * 获取快手产品开始时间
  289. * @return
  290. * @throws SQLException
  291. */
  292. public String getKsStartTime()throws SQLException{
  293. String sql = " SELECT TO_CHAR(TRUNC(SYSDATE), 'YYYYMMDDHH24MISS') FROM DUAL ";
  294. return SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, new Object[] {});
  295. }
  296. /**
  297. * 更新领取会员最后时间
  298. * @param userid
  299. * @param endtime
  300. * @return
  301. * @throws SQLException
  302. */
  303. public boolean updVipEndtime(String userid, String endtime)throws SQLException{
  304. String sql = "UPDATE TD_BACKBUSI_ORDER_REC SET VIPENDTIME = TO_DATE(?,'yyyymmddhh24miss') WHERE CHANNEL = 'TX20_twback' AND BUSITYPE = '3' AND USERID = ? AND VIPSTATUS NOT IN ('0','8') AND VIPENDTIME IS NOT NULL AND VIPENDTIME >= SYSDATE";
  305. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, endtime,userid);
  306. return ((Integer)obj)>0 ? true : false;
  307. }
  308. /**
  309. * 更新上海2元权益报文表
  310. * @param orderno
  311. * @param logid
  312. * @throws SQLException
  313. */
  314. public void updShInPaInfo(BackBusiOrderRec bean){
  315. try{
  316. this.getExecutor().updateWithDBName(DataSource.NET3G, "updShInPaInfo", new Object[] {bean.getId(),bean.getLogid()});
  317. }catch(Exception e){}
  318. }
  319. /**
  320. * 是否向省里推送订购关系
  321. * @param cpid
  322. * @param spid
  323. */
  324. public boolean orderPush(String cpid, String spid) throws SQLException {
  325. String sql="select ORDERPUSH from TB_BACKBUSI_CONF t where CPID=? AND SPID=?";
  326. String orderPush = SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, cpid, spid);
  327. return "0".equals(orderPush);
  328. }
  329. /**
  330. * 获取产品id
  331. * @param spid
  332. */
  333. public String getProduct( String spid) throws SQLException {
  334. String sql="select product_id from tb_sp_aop_config where sp_id=? ";
  335. String orderPush = SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, spid);
  336. return orderPush;
  337. }
  338. public static void main(String[] args) {
  339. try {
  340. BackBusiOrderDao dao = new BackBusiOrderDao();
  341. // System.out.println(dao.findByUserAndSpid("18673197465", "youtu", "1167"));
  342. //System.out.println(dao.findOrderRecByUserid("18673197465"));
  343. OrderInfo orderInfo = new OrderInfo();
  344. orderInfo.setUserid("18673197465");
  345. orderInfo.setProvince("湖南");
  346. orderInfo.setArea("长沙");
  347. orderInfo.setOrderid("123456789");
  348. orderInfo.setType(0);
  349. //dao.addOrderRec(orderInfo);
  350. //System.out.println(dao.endtime31Day("20190620235959"));
  351. //System.out.println(dao.findByUserAndSpid("18673197465", "youtu", "1167"));
  352. //System.out.println(dao.getCpSp("youtu", "140"));
  353. //System.out.println(dao.getActivityInfo("youtu", "1167", "湖南"));
  354. //System.out.println(dao.generateID());
  355. //String vipstatus = dao.getVipstatus("028b4f73-14bc-4450-afaa-81a323ef9d24");
  356. //System.out.println(vipstatus);
  357. //System.out.println(dao.getBackBusiConf("test_01", "youtu", "1168"));
  358. //dao.updOrderRec("3", "9002", "失败", "123456", "2");
  359. //CPDao cd = new CPDao();
  360. //System.out.println(cd.findById("youtu"));
  361. //String sql = "SELECT * FROM TB_CP_ACCOUNT_CONFIG a, tb_sp_info b where a.cpid=b.cpid and b.cpid= 'youtu' and b.spid= '141' ";
  362. //System.out.println(dao.getExecutor().queryObjectWithDBName(HashMap.class, "net3g", "sql", new Object[] { "youtu", "140" }));
  363. //System.out.println(SQLExecutor.queryListBeanWithDBName(List.class, "net3g", sql, null));
  364. //System.out.println(SQLExecutor.queryObjectWithDBName(HashMap.class, DataSource.NET3G, sql,new Object[] {}));
  365. //System.out.println(dao.endtimeParamDay("1","20190801235959"));
  366. System.out.println(dao.getStartTime("20191126235959","3"));
  367. } catch (Exception e) {
  368. // TODO Auto-generated catch block
  369. e.printStackTrace();
  370. }
  371. }
  372. }