5aeb390b983d24fff191192eb2770682df9c209f.svn-base 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package com.chinacreator.process.dao;
  2. import java.sql.SQLException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import org.apache.log4j.Logger;
  7. import org.springframework.cache.annotation.Cacheable;
  8. import org.springframework.stereotype.Component;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.chinacreator.process.bean.ContinueBean;
  11. import com.chinacreator.process.bean.KuaishouPushBean;
  12. import com.chinacreator.process.util.DataSource;
  13. import com.frameworkset.common.poolman.PreparedDBUtil;
  14. import com.frameworkset.common.poolman.SQLExecutor;
  15. @Component
  16. public class VipSmsSpidSendDao{
  17. /**
  18. * 添加推送数据
  19. * @param bean
  20. * @throws SQLException
  21. */
  22. public void addSendLog(HashMap<String, String> params) throws SQLException {
  23. String sql = " INSERT INTO TL_VIP_SMSSPID_SEND_LOG ( ID, USERID, CONFID, SENDMONTH, COLLECTID, INSERTTIME ) " +
  24. " VALUES ( TO_CHAR(SYSDATE,'YYYYMMDDHH24MISS')||SEQ_CHANNEL_ORG.NEXTVAL, " +
  25. " #[USERID], #[CONFID], #[SENDMONTH], #[COLLECTID], SYSDATE )";
  26. SQLExecutor.insertBean("net3g", sql, params);
  27. }
  28. /**
  29. * 获取TD_VIP_SMSSPID_REC表RESULTCODE为待处理和之前有处理过但发送时间不合法的数据数据
  30. * 每次取800条数据
  31. * @param partition 分区标识
  32. * @param rows 每次取多少条数据
  33. * @param currmonth 当前月份
  34. * @return
  35. * @throws SQLException
  36. */
  37. public List<HashMap> getDataByPart(String partition, int rows, String currmonth)throws SQLException {
  38. //SELECT * FROM (SELECT * FROM TD_VIP_SMSSPID_REC PARTITION(T_HASH_P50) WHERE RESULTCODE = '1') WHERE ROWNUM < 800
  39. //resultcocde: 1,待处理,9055,未到短信发送开始时间,9054,已过短信发送结束时间
  40. String sql = " SELECT * FROM ( SELECT * FROM TD_VIP_SMSSPID_REC PARTITION("+partition+") WHERE COLLECTMONTH = ? AND RESULTCODE IN ( '1','9055','9054' ) ) WHERE ROWNUM < ? ";
  41. PreparedDBUtil pdb = new PreparedDBUtil();
  42. pdb.preparedSelect(DataSource.NET3G, sql);
  43. pdb.setString(1, currmonth);
  44. pdb.setInt(2, rows);
  45. return pdb.executePreparedForList(HashMap.class);
  46. }
  47. /**
  48. * 根据ID更新TD_VIP_SMSSPID_REC表的处理状态
  49. * @param id
  50. * @param resultcode
  51. * @param errorinfo
  52. * @param realflag
  53. * @return
  54. * @throws SQLException
  55. */
  56. public boolean updExecRes(String id, String resultcode, String errorinfo) throws SQLException {
  57. boolean res = false;
  58. //更新数据状态为处理中
  59. String sql = "UPDATE TD_VIP_SMSSPID_REC SET RESULTCODE = ? , RESULTINFO = ? , UPDTIME = SYSDATE WHERE ID = ? AND RESULTCODE = '2' ";
  60. int rows = (Integer)SQLExecutor.updateWithDBName(DataSource.NET3G, sql, resultcode, errorinfo, id);
  61. if(rows > 0){
  62. return true;
  63. }
  64. return res;
  65. }
  66. /**
  67. * 更新状态为执行中
  68. * @param id
  69. * @return
  70. * @throws SQLException
  71. */
  72. public boolean updExecing(String id) throws SQLException {
  73. //更新数据状态为处理中
  74. String sql = "UPDATE TD_VIP_SMSSPID_REC SET RESULTCODE = '2' , UPDTIME = SYSDATE WHERE ID = ? ";
  75. int rows = (Integer)SQLExecutor.updateWithDBName(DataSource.NET3G, sql, id);
  76. if(rows > 0){
  77. return true;
  78. }else{
  79. return false;
  80. }
  81. }
  82. /**
  83. * 获取发送配置信息
  84. * @return
  85. * @throws SQLException
  86. */
  87. @Cacheable(value="vipsmsspidconf",key="#confid")
  88. public HashMap getVipsmsspidconf(String confid) throws SQLException {
  89. //System.out.println("查询数据库");
  90. String sql = "SELECT * FROM TB_VIP_SMSSPID_CONF WHERE STATUS = '0' AND ID = ? ";
  91. PreparedDBUtil pdb = new PreparedDBUtil();
  92. pdb.preparedSelect(DataSource.NET3G, sql);
  93. pdb.setString(1, confid);
  94. return (HashMap)pdb.executePreparedForObject(HashMap.class);
  95. }
  96. /**
  97. * 查询用户当月是否已发送过指定短信TL_VIP_SMSSPID_SEND_LOG
  98. * @param userid
  99. * @param sendmonth
  100. * @param confid
  101. * @return true是,false否
  102. * @throws SQLException
  103. */
  104. public boolean hasAlreadySend(String userid, String sendmonth, String confid) throws SQLException {
  105. String sql = "SELECT COUNT(1) CNT FROM TL_VIP_SMSSPID_SEND_LOG WHERE USERID = ? AND CONFID = ? AND SENDMONTH = ? ";
  106. int cnt = SQLExecutor.queryObjectWithDBName(Integer.class, DataSource.NET3G,sql, userid, confid, sendmonth);
  107. if(cnt > 0){
  108. return true;
  109. }else{
  110. return false;
  111. }
  112. }
  113. public static void main(String[] args) throws SQLException {
  114. VipSmsSpidSendDao dao = new VipSmsSpidSendDao();
  115. System.out.println(dao.getVipsmsspidconf("20220406101954000001"));
  116. System.out.println(dao.getVipsmsspidconf("20220406101954000001"));
  117. //System.out.println(dao.updatePush("202005091510455306373", "0", "ok"));
  118. //System.out.println(dao.findOrderRelaBySpid("18673197465", "1022"));
  119. //System.out.println(dao.getNo());
  120. //System.out.println(dao.queryPush("202005091510455306373"));
  121. //System.out.println(dao.getOrderPush());
  122. //System.out.println(dao.hasSync("18673197465", "190"));
  123. //System.out.println(dao.getSpidById("20201022095726288224"));
  124. }
  125. }