c2b0a706df13a43ac87ba6cc715beea9b7446bf5.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. package com.chinacreator.process.dao;
  2. import com.chinacreator.process.bean.OrderLog;
  3. import com.chinacreator.process.bean.PointShopOrderBean;
  4. import com.chinacreator.process.util.DataSource;
  5. import com.frameworkset.common.poolman.PreparedDBUtil;
  6. import com.frameworkset.common.poolman.SQLExecutor;
  7. import org.apache.log4j.Logger;
  8. import org.springframework.stereotype.Component;
  9. import java.sql.SQLException;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. @Component
  13. public class PointShopDao {
  14. private Logger log = Logger.getLogger("pointshop");
  15. public List<HashMap> findSpInfo(String spid) throws SQLException {
  16. String sql = " select cpid, spid, spname, price, vacproductid, spcode, type, feetype, cancancelorder, canorder, " +
  17. " errorhandle,duration,canaccumulation,mutex,relationSp,paytype,needUnifiedAuthSync,spcodename,haslocal " +
  18. " from tb_sp_info where spid = ? ";
  19. return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, spid);
  20. }
  21. public List<HashMap> findOrderRelaAll(String userid) throws SQLException {
  22. String sql = " SELECT CPID,SPID,USERID, TO_CHAR(ORDERTIME, 'yyyymmddhh24miss') ORDERTIME, " +
  23. " TO_CHAR(endtime, 'yyyymmddhh24miss') endtime, TO_CHAR(CANCELTIME, 'yyyymmddhh24miss') CANCELTIME, " +
  24. " (case when endtime is null then '0' when endtime >= sysdate then '1' else '2' end) STATUS " +
  25. " FROM TD_ORDER_RELATIONS WHERE USERID = ? ";
  26. return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, userid);
  27. }
  28. /**
  29. * 更新callBack状态
  30. *
  31. * @param bcstatus
  32. * @param bcinfo
  33. * @param id
  34. * @return
  35. * @throws SQLException
  36. */
  37. public void updCallBack(String bcstatus, String bcinfo, String id) {
  38. try {
  39. String sql = "UPDATE TD_POINTS_ORDER_REC SET BCSTATUS = ?, BCINFO = ? WHERE ID = ?";
  40. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, bcstatus, bcinfo, id);
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. log.error("orderId: " + id + ", 更新callBack状态出现异常," + e.getMessage());
  44. }
  45. }
  46. public void updParamsByCb(String cbReqParams, String cbRspParams, String requestId) throws SQLException {
  47. String sql = "UPDATE TL_POINTS_INOUT_PARAMS SET CBREQPARAMS = ?, CBRESPARAMS = ?, CBTIME = SYSDATE WHERE REQUESTID = ?";
  48. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, cbReqParams, cbRspParams, requestId);
  49. }
  50. /**
  51. * 根据orderId和orderNo查询订购信息
  52. *
  53. * @param id
  54. * @return
  55. * @throws SQLException
  56. */
  57. public PointShopOrderBean getOrderRec(String id) throws SQLException {
  58. String sql = " SELECT " +
  59. " ID, USERID,PROVINCE,AREA,CPID,SPID,ORDERNO,GOODSCODE,RESULTCODE,RESULTINFO,BUSITYPE,SERVICECODE, " +
  60. " TO_CHAR(INSERTTIME,'YYYYMMDDHH24MISS') INSERTTIME,TO_CHAR(FINISHTIME,'YYYYMMDDHH24MISS') FINISHTIME, " +
  61. " TO_CHAR(ORDERTIME,'YYYYMMDDHH24MISS') ORDERTIME,REQUESTID,VIPSTATUS,APPID " +
  62. " FROM TD_POINTS_ORDER_REC WHERE ID = ? ";
  63. return SQLExecutor.queryObjectWithDBName(PointShopOrderBean.class, DataSource.NET3G, sql, id);
  64. }
  65. /**
  66. * 获取赠送会员状态
  67. * @param orderId
  68. * @return
  69. * @throws SQLException
  70. */
  71. // public String getVipstatus(String orderId) throws SQLException {
  72. // String sql = "SELECT VIPSTATUS FROM TD_POINTS_ORDER_REC WHERE ID = ? ";
  73. // return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G,sql,orderId);
  74. // }
  75. /**
  76. * 获取赠送会员状态
  77. *
  78. * @param orderId
  79. * @return
  80. * @throws SQLException
  81. */
  82. public String getBackVipstatus(String id) throws SQLException {
  83. String sql = "SELECT VIPSTATUS FROM TD_BACKBUSI_ORDER_REC WHERE ID = ? ";
  84. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, id);
  85. }
  86. /**
  87. * 获取赠送会员处理结果
  88. *
  89. * @param orderId
  90. * @return
  91. * @throws SQLException
  92. */
  93. public String getResultCode(String orderId) throws SQLException {
  94. String sql = "SELECT RESULTCODE FROM TD_POINTS_ORDER_REC WHERE ID = ? ";
  95. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, orderId);
  96. }
  97. /**
  98. * 更新会员状态
  99. * @param vipstatus
  100. * @param id
  101. * @param tabname 表名
  102. * @return
  103. * @throws SQLException
  104. */
  105. // public boolean updVipstatus(String vipstatus, String id, String tabname) throws SQLException {
  106. // //赠送会员状态,0成功,1未赠送,2赠送中,3失败,4不赠送
  107. // String sql = " UPDATE "+tabname+" SET VIPSTATUS = ? WHERE ID = ? ";
  108. // Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, vipstatus, id);
  109. // return ((Integer)obj)>0 ? true : false;
  110. // }
  111. /**
  112. * 更新业务状态信息
  113. *
  114. * @param resultCode
  115. * @param resultInfo
  116. * @param id
  117. * @param tabname
  118. * @return
  119. * @throws SQLException
  120. */
  121. public boolean updBusiStatus(String resultCode, String resultInfo, String id, String tabname) throws SQLException {
  122. //赠送会员状态,0成功,1未赠送,2赠送中,3失败,4不赠送
  123. String sql = " UPDATE " + tabname + " SET RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  124. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, resultCode, resultInfo, id);
  125. return ((Integer) obj) > 0 ? true : false;
  126. }
  127. /**
  128. * @param vipStatus
  129. * @param resultCode
  130. * @param resultInfo
  131. * @param id
  132. * @param tabname
  133. * @return
  134. * @throws SQLException
  135. */
  136. // public boolean updBusiStatus(String vipStatus, String resultCode, String resultInfo, String id, String tabname) throws SQLException {
  137. // //赠送会员状态,0成功,1未赠送,2赠送中,3失败,4不赠送
  138. // String sql = " UPDATE "+tabname+" SET VIPSTATUS = ? , RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  139. // Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, vipStatus, resultCode, resultInfo, id);
  140. // return ((Integer)obj)>0 ? true : false;
  141. // }
  142. public boolean updBusiStatus(PointShopOrderBean bean, String tabname) {
  143. try {
  144. //赠送会员状态,0成功,1未赠送,2赠送中,3失败,4不赠送
  145. String sql = " UPDATE " + tabname + " SET VIPSTATUS = ? , RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  146. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, bean.getVipstatus(), bean.getResultCode(), bean.getResultInfo(), bean.getId());
  147. return ((Integer) obj) > 0 ? true : false;
  148. } catch (SQLException e) {
  149. e.printStackTrace();
  150. log.error("orderId: " + bean.getId() + ", 更新订购信息表出现异常," + e.getMessage());
  151. }
  152. return false;
  153. }
  154. /**
  155. * 根据条件查询订购关系
  156. *
  157. * @param userid
  158. * @param cpid
  159. * @param spid
  160. * @return
  161. * @throws SQLException
  162. */
  163. public HashMap findByUserAndSpid(String userid, String cpid, String spid) throws SQLException {
  164. String sql = "SELECT CPID, SPID, USERID, TO_CHAR(ORDERTIME, 'yyyymmddhh24miss') ORDERTIME, " +
  165. " TO_CHAR(ENDTIME, 'yyyymmddhh24miss') ENDTIME, TO_CHAR(CANCELTIME, 'yyyymmddhh24miss') CANCELTIME " +
  166. " FROM TD_ORDER_RELATIONS WHERE USERID= ? and CPID= ? AND SPID= ? ";
  167. return SQLExecutor.queryObjectWithDBName(HashMap.class, DataSource.NET3G, sql, userid, cpid, spid);
  168. }
  169. /**
  170. * 获取赠送会员加密密码
  171. * @param goodsCode
  172. * @return
  173. * @throws SQLException
  174. */
  175. // public String getPwdByGoodsCode(String goodsCode)throws SQLException {
  176. // String sql = " SELECT PWD FROM TB_POINTS_GOODS_CONF WHERE GOODSCODE = ? ";
  177. // return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G,sql,goodsCode);
  178. // }
  179. //
  180. /**
  181. * 获取业务配置信息
  182. *
  183. * @param cpid
  184. * @param spid
  185. * @return
  186. * @throws SQLException
  187. */
  188. public List<HashMap> getBackBusiConf(String cpid, String spid) throws SQLException {
  189. String sql = "SELECT * FROM TB_BACKBUSI_CONF WHERE STATUS = '0' AND CPID = ? AND SPID = ? ";
  190. return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, cpid, spid);
  191. }
  192. /**
  193. * 获取当前时间
  194. *
  195. * @return
  196. * @throws SQLException
  197. */
  198. public String currTime() throws SQLException {
  199. String sql = "SELECT TO_CHAR(SYSDATE,'yyyymmddhh24miss') CURRTIME FROM DUAL";
  200. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, null);
  201. }
  202. public static void main(String[] args) throws SQLException {
  203. PointShopDao dao = new PointShopDao();
  204. //System.out.println(dao.findSpInfo("1167"));
  205. //System.out.println(dao.getPwdByGoodsCode("pointshop130"));
  206. //System.out.println(dao.getOrderRec("201906211723268662899","d4078706-2ff3-4f1b-9aad-80436a294b22"));
  207. System.out.println(dao.currParamDay("4"));
  208. }
  209. /**
  210. * 获取从当天算起31天
  211. *
  212. * @return
  213. * @throws SQLException
  214. */
  215. public String curr31Day() throws SQLException {
  216. String sql = "SELECT TO_CHAR(30+TRUNC(SYSDATE)+1-1/86400,'yyyymmddhh24miss') curr31Day FROM DUAL";
  217. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, null);
  218. }
  219. /**
  220. * 获取从指定时间开始起加31天
  221. *
  222. * @param endtime
  223. * @return
  224. * @throws SQLException
  225. */
  226. public String endtime31Day(String endtime) throws SQLException {
  227. String sql = "SELECT TO_CHAR(31+TO_DATE(?,'yyyymmddhh24miss'),'yyyymmddhh24miss') endtime31Day FROM DUAL";
  228. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, endtime);
  229. }
  230. /**
  231. * 更新订购信息表
  232. *
  233. * @param resultCode
  234. * @param resultInfo
  235. * @param orderId
  236. * @return
  237. * @throws SQLException
  238. */
  239. public void updOrderRec(PointShopOrderBean bean) {
  240. try {
  241. String sql = " UPDATE TD_POINTS_ORDER_REC SET FINISHTIME = SYSDATE, VIPSTATUS = ?, RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  242. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, bean.getVipstatus(), bean.getResultCode(), bean.getResultInfo(), bean.getId());
  243. } catch (SQLException e) {
  244. e.printStackTrace();
  245. log.error("Id: " + bean.getId() + ", 更新积分商城订购信息表出现异常," + e.getMessage());
  246. }
  247. }
  248. /**
  249. * 更新后向产品订购信息表
  250. *
  251. * @param resultCode
  252. * @param resultInfo
  253. * @param orderId
  254. * @return
  255. * @throws SQLException
  256. */
  257. public void updBackOrderRec(PointShopOrderBean bean) {
  258. try {
  259. String sql = " UPDATE TD_BACKBUSI_ORDER_REC SET VIPSTATUS = ?, RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  260. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, bean.getVipstatus(), bean.getResultCode(), bean.getResultInfo(), bean.getId());
  261. } catch (SQLException e) {
  262. e.printStackTrace();
  263. log.error("id: " + bean.getId() + ", 更新后向订购信息表出现异常," + e.getMessage());
  264. }
  265. }
  266. /**
  267. * 新增或更新订购关系
  268. *
  269. * @param bean
  270. * @throws SQLException
  271. */
  272. public void order(PointShopOrderBean bean) throws SQLException {
  273. String sql = " MERGE INTO TD_ORDER_RELATIONS a USING (SELECT #[cpid] cpid, #[spid] spid, #[userid] userid FROM DUAL) b " +
  274. " ON(a.cpid = b.cpid and a.spid = b.spid and a.userid = b.userid) " +
  275. " WHEN MATCHED THEN UPDATE " +
  276. " SET status = '0',ENDTIME=TO_DATE(#[endtime],'yyyymmddhh24miss'),ORDERTIME=SYSDATE, effecttime=SYSDATE, " +
  277. " CDNSUCCEED = '1', SYNCSUCCEED = '1',CDNCOUNT = '0', SYNCCOUNT = '0', CACHESUCCEED = '1', ORDERCHANNEL = #[orderchannel] " +
  278. " WHEN NOT MATCHED THEN INSERT(ID,CPID,SPID,USERID,ORDERTIME,EFFECTTIME,ENDTIME,STATUS,PROVINCE,AREA,ORDERCHANNEL,SYNCCOUNT,SYNCSUCCEED,TYPE,ORDERSTATUS,ORDERTYPE, " +
  279. " ISEXPERIENCE,CACHESUCCEED,CDNSUCCEED,CDNCOUNT) VALUES ( " +
  280. " TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval, " +
  281. " #[cpid],#[spid],#[userid],SYSDATE,SYSDATE, " +
  282. " TO_DATE(#[endtime], 'yyyymmddhh24miss'),'0',#[province],#[area],#[orderchannel],0,1,1,'3','1',0,1,'1','0') ";
  283. SQLExecutor.insertBean(DataSource.NET3G, sql, bean);
  284. }
  285. /**
  286. * 记录订购日志
  287. *
  288. * @param orderLog
  289. * @throws SQLException
  290. */
  291. public void addOrderLog(OrderLog orderLog) throws SQLException {
  292. String sql = "insert into tl_order_log (id, userid, province, area, apptype, useragent, origin, "
  293. + "channel, cpid, spid, errorcode, errorinfo, status, orderstatus, ordertype, inserttime, isexperience) values ( "
  294. + "to_char(sysdate, 'yyyymmddhh24miss') || SEQ_COMMON6.nextval,"
  295. + "#[userid], #[province], #[area], #[apptype], #[useragent], #[origin], #[channel], #[cpid],"
  296. + "#[spid], #[errorcode], #[errorinfo], #[status], #[orderstatus], #[ordertype],"
  297. + "sysdate, #[isexperience])";
  298. SQLExecutor.insertBean(DataSource.NET3G, sql, orderLog);
  299. }
  300. /**
  301. * 获取从当前天起加多少天的有效期
  302. *
  303. * @param days 加多少天
  304. * @return
  305. * @throws SQLException
  306. */
  307. public String currParamDay(String days) throws SQLException {
  308. String sql = "SELECT TO_CHAR(?+TRUNC(SYSDATE)-1/86400,'yyyymmddhh24miss') FROM DUAL";
  309. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, days);
  310. }
  311. /**
  312. * 获取从指定时间加多少天有效期
  313. *
  314. * @param days 加多少天
  315. * @param endtime 起始日期
  316. * @return
  317. * @throws SQLException
  318. */
  319. public String endtimeParamDay(String days, String endtime) throws SQLException {
  320. String sql = "SELECT TO_CHAR(?+TO_DATE(?,'yyyymmddhh24miss'),'yyyymmddhh24miss') FROM DUAL";
  321. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, days, endtime);
  322. }
  323. /**
  324. * 获取结束时间
  325. *
  326. * @param orderId
  327. * @return
  328. * @throws SQLException
  329. */
  330. public String getBackEndtime(String id) throws SQLException {
  331. String sql = " SELECT TO_CHAR(ENDTIME,'YYYYMMDDHH24MISS') FROM TD_BACKBUSI_ORDER_REC WHERE ID = ? ";
  332. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, id);
  333. }
  334. public String endtimeTheMonthLastDay() throws SQLException {
  335. String sql = "SELECT TO_CHAR(TRUNC(LAST_DAY(sysdate),'dd')+1-1/24/60/60,'yyyymmddhh24miss') FROM DUAL";
  336. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql);
  337. }
  338. public String endtimeNextMonthLastDay(String currEndtime) throws SQLException {
  339. String sql="select to_char(last_day(add_months(trunc(TO_DATE(?, 'yyyymmddhh24miss')),1)+1-1/24/60/60),'yyyymmddhh24miss') from dual";
  340. return SQLExecutor.queryObjectWithDBName(String.class, DataSource.NET3G, sql, currEndtime);
  341. }
  342. /*******************************20210118积分商城异步处理开始*****************************/
  343. /**
  344. * 查询要异步赠送会员的数据
  345. * @param trycount
  346. * @return
  347. */
  348. public List<HashMap> getVipAsynData(String trycount){
  349. //赠送会员状态,0成功,1待赠送,2赠送中,3失败,8已冻结
  350. String sql = " SELECT * FROM (SELECT ID, USERID, ORDERID,CHANNEL, CPID, SPID, VIPSTATUS, BUSITYPE, RETRYCOUNT, TO_CHAR(ENDTIME, 'YYYYMMDDHH24MISS') ENDTIME FROM TD_BACKBUSI_ORDER_REC WHERE INSERTTIME > SYSDATE - 10 "+
  351. " AND CHANNEL = 'CHSvideoD00' "+
  352. " AND RESULTCODE NOT IN ('0','2') "+
  353. " AND VIPSTATUS NOT IN ('0') "+
  354. " AND RETRYCOUNT < ? "+
  355. " AND (RETRYTIME IS NULL OR TO_NUMBER((SYSDATE - RETRYTIME)*24*60) >=2) "+
  356. " ORDER BY INSERTTIME) "+
  357. " WHERE ROWNUM < 1000 ";
  358. PreparedDBUtil pdb = new PreparedDBUtil();
  359. try {
  360. pdb.preparedSelect(DataSource.NET3G, sql);
  361. pdb.setInt(1, Integer.parseInt(trycount));
  362. return pdb.executePreparedForList(HashMap.class);
  363. } catch (Exception e) {
  364. e.printStackTrace();
  365. }
  366. return null;
  367. }
  368. /**
  369. * 更新业务处理状态
  370. * @param vipstatus
  371. * @param reesultCode
  372. * @param resultInfo
  373. * @param id
  374. * @param tabname
  375. * @param time
  376. * @throws SQLException
  377. */
  378. public void updSendVipRes(String vipstatus, String reesultCode, String resultInfo, String id, String tabname, String time) throws SQLException {
  379. if("TD_POINTS_ORDER_REC".equals(tabname)){
  380. String sql = " UPDATE TD_POINTS_ORDER_REC SET FINISHTIME = SYSDATE, VIPSTATUS = ?, RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  381. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, vipstatus, reesultCode,resultInfo, id);
  382. }else{
  383. String sql = " UPDATE TD_BACKBUSI_ORDER_REC SET VIPSTATUS = ?, RESULTCODE = ?, RESULTINFO = ?, RETRYCOUNT = RETRYCOUNT+1, RETRYTIME = SYSDATE, TIMES = ? WHERE ID = ? ";
  384. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, vipstatus, reesultCode,resultInfo, time, id);
  385. }
  386. }
  387. /**
  388. * 更新赠送会员状态
  389. * @param bean
  390. * @param tabname
  391. * @return
  392. * @throws SQLException
  393. */
  394. public boolean updSendVipStatus(PointShopOrderBean bean, String tabname) throws SQLException {
  395. //赠送会员状态,0成功,1未赠送,2赠送中,3失败,4不赠送
  396. String sql = " UPDATE "+tabname+" SET VIPSTATUS = ? , RESULTCODE = ?, RESULTINFO = ? WHERE ID = ? ";
  397. Object obj = SQLExecutor.updateWithDBName(DataSource.NET3G, sql, bean.getVipstatus(), bean.getResultCode(), bean.getResultInfo(), bean.getId());
  398. return ((Integer)obj)>0 ? true : false;
  399. }
  400. /*******************************20210118积分商城异步处理结束*****************************/
  401. }