110102b1d6ac5f0e3602912f7238b26122f4b24e.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package com.chinacreator.process.dao;
  2. import com.chinacreator.process.bean.ChannelOrderBean;
  3. import com.chinacreator.process.util.DataSource;
  4. import com.frameworkset.common.poolman.PreparedDBUtil;
  5. import com.frameworkset.common.poolman.SQLExecutor;
  6. import org.apache.log4j.Logger;
  7. import org.springframework.stereotype.Component;
  8. import java.sql.SQLException;
  9. import java.text.SimpleDateFormat;
  10. import java.util.Date;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. @Component
  14. public class ChannelOrderDao
  15. {
  16. private static Logger logger = Logger.getLogger(ChannelOrderDao.class);
  17. @SuppressWarnings("unchecked")
  18. public List<ChannelOrderBean> queryNeedDo()
  19. {
  20. //String sql = "select id,userid,to_char(ordertime,'yyyymmddhh24miss') ordertime,a.type,updatetype,to_char(canceltime,'yyyymmddhh24miss') canceltime,productid from td_channel_ftp_order a,TB_CHANNELORDER_CONFIG b where a.status = '1' and a.inserttime between sysdate-1 and sysdate and a.productid = b.vacproductid order by id";
  21. String sql="select id,\n" +
  22. " userid,\n" +
  23. " to_char(ordertime, 'yyyymmddhh24miss') ordertime,\n" +
  24. " a.type,\n" +
  25. " updatetype,\n" +
  26. " to_char(canceltime, 'yyyymmddhh24miss') canceltime,\n" +
  27. " productid\n" +
  28. " from td_channel_ftp_order a, TB_CHANNELORDER_CONFIG b\n" +
  29. " where a.status = '1'\n" +
  30. " and a.inserttime between sysdate - 1 and sysdate\n" +
  31. " and a.productid = b.vacproductid\n" +
  32. " and a.productid != '99106371'\n" +
  33. "union all\n" +
  34. "select id,\n" +
  35. " userid,\n" +
  36. " to_char(ordertime, 'yyyymmddhh24miss') ordertime,\n" +
  37. " a.type,\n" +
  38. " updatetype,\n" +
  39. " to_char(canceltime, 'yyyymmddhh24miss') canceltime,\n" +
  40. " productid\n" +
  41. " from td_channel_ftp_order a, TB_CHANNELORDER_CONFIG b\n" +
  42. " where a.productid = '99106371'\n" +
  43. " and a.status = '1'\n" +
  44. " and a.productid = b.vacproductid\n" +
  45. " and a.inserttime >=to_date('2020/11/25 14:24:26', 'yyyy/MM/dd HH24:mi:ss')\n" +
  46. " and updatetype = '2'\n" +
  47. " order by id";
  48. PreparedDBUtil pdb = new PreparedDBUtil();
  49. try {
  50. return pdb.executeSelectForList("sdk", sql, 0L, 500, ChannelOrderBean.class);
  51. } catch (Exception e) {
  52. logger.error("查询td_channel_ftp_order失败", e);
  53. }
  54. return null;
  55. }
  56. @SuppressWarnings("unchecked")
  57. public List<ChannelOrderBean> queryNeedDotest()
  58. {
  59. String sql = "select id,userid,to_char(ordertime,'yyyymmddhh24miss') ordertime,type,updatetype,to_char(canceltime,'yyyymmddhh24miss') canceltime,istimeout from td_channel_ftp_order where userid ='13230445009'";
  60. PreparedDBUtil pdb = new PreparedDBUtil();
  61. try {
  62. return pdb.executeSelectForList("sdk", sql, 0L, 500, ChannelOrderBean.class);
  63. } catch (SQLException e) {
  64. logger.error("查询td_channel_ftp_order失败", e);
  65. }
  66. return null;
  67. }
  68. @SuppressWarnings("unchecked")
  69. public List<ChannelOrderBean> queryNeedDoForTimeout()
  70. {
  71. String sql = "select id,userid,to_char(ordertime,'yyyymmddhh24miss') ordertime,type from td_channel_ftp_order where status = 1 and istimeout = 1 order by id";
  72. PreparedDBUtil pdb = new PreparedDBUtil();
  73. try {
  74. return pdb.executeSelectForList("sdk", sql, 0L, 500, ChannelOrderBean.class);
  75. } catch (SQLException e) {
  76. logger.error("查询td_channel_ftp_order失败", e);
  77. }
  78. return null;
  79. }
  80. public void updatestatus(String id, String result) {
  81. String sql = "update TD_CHANNEL_FTP_ORDER set status = 0,synctime = sysdate, result = ? where id = ?";
  82. try {
  83. SQLExecutor.updateWithDBName("sdk", sql, new Object[] { result, id });
  84. } catch (SQLException e) {
  85. logger.error("更改td_channel_ftp_order失败", e);
  86. }
  87. }
  88. /**
  89. * 更新办理结果
  90. * @param id
  91. * @param result 结果编码
  92. * @param resultinfo 结果信息
  93. */
  94. public void updatestatus(String id, String result, String resultinfo) {
  95. String sql = "update TD_CHANNEL_FTP_ORDER set status = 0,synctime = sysdate, result = ?, RESULTINFO = ? where id = ?";
  96. try {
  97. SQLExecutor.updateWithDBName("sdk", sql, new Object[] { result, resultinfo, id});
  98. } catch (SQLException e) {
  99. logger.error("更改td_channel_ftp_order失败", e);
  100. }
  101. }
  102. public int isOrder(String cpid, String spid, String userid) {
  103. int isOrder = 1;
  104. PreparedDBUtil pdb = new PreparedDBUtil();
  105. String sql = "select count(*) from TD_ORDER_RELATIONS where cpid=? and spid=? and userid=? and status='0'";
  106. try {
  107. pdb.preparedSelect(DataSource.NET3G, sql);
  108. pdb.setString(1, cpid);
  109. pdb.setString(2, spid);
  110. pdb.setString(3, userid);
  111. pdb.executePrepared();
  112. if (pdb.getInt(0, 0) > 0)
  113. isOrder = 0;
  114. } catch (Exception e) {
  115. logger.error("查询用户是否已订购失败", e);
  116. }
  117. return isOrder;
  118. }
  119. /**
  120. * 特殊复合产品结束时间
  121. * @return
  122. */
  123. public Date getLastYearDay(){
  124. PreparedDBUtil pdb = new PreparedDBUtil();
  125. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  126. String sql = "select TO_DATE(TO_CHAR(trunc(add_months(sysdate,12),'MM') - 1/24/60/60,'yyyyMMddhh24miss'), 'yyyyMMddhh24miss') from dual";
  127. try {
  128. String endtime = (String)pdb.executeSelectForList(DataSource.NET3G, sql, 0L, 500, String.class).get(0);
  129. Date d = sdf.parse(endtime);
  130. return d;
  131. } catch (Exception e) {
  132. e.printStackTrace();
  133. }
  134. return null;
  135. }
  136. /**
  137. * 特殊复合产品结束时间
  138. * @return
  139. */
  140. public Date getLastYearDayFirst(Date time){
  141. PreparedDBUtil pdb = new PreparedDBUtil();
  142. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  143. String sql = "select TO_DATE(TO_CHAR(trunc(add_months(?,12),'MM') - 1/24/60/60,'yyyyMMddhh24miss'), 'yyyyMMddhh24miss') from dual";
  144. try {
  145. pdb.preparedSelect(DataSource.NET3G, sql);
  146. pdb.setDate(1,time);
  147. String endtime = pdb.executePreparedForList(String.class).get(0);
  148. Date d = sdf.parse(endtime);
  149. return d;
  150. } catch (Exception e) {
  151. e.printStackTrace();
  152. }
  153. return null;
  154. }
  155. /**
  156. * 特殊复合产品结束时间
  157. * @return
  158. */
  159. public Date getLastYearDay(Date time){
  160. PreparedDBUtil pdb = new PreparedDBUtil();
  161. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  162. String sql = "select TO_DATE(TO_CHAR(trunc(add_months(?,13),'MM') - 1/24/60/60,'yyyyMMddhh24miss'), 'yyyyMMddhh24miss') from dual";
  163. try {
  164. pdb.preparedSelect(DataSource.NET3G, sql);
  165. pdb.setDate(1,time);
  166. String endtime = pdb.executePreparedForList(String.class).get(0);
  167. Date d = sdf.parse(endtime);
  168. return d;
  169. } catch (Exception e) {
  170. e.printStackTrace();
  171. }
  172. return null;
  173. }
  174. public Date getFhcpEndtime(String userid,String cpid,String spid){
  175. PreparedDBUtil pdb = new PreparedDBUtil();
  176. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  177. String sql = "select endtime from TD_ORDER_RELATIONS where userid = ? and cpid = ? and spid = ?";
  178. try {
  179. String endtime = SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, new Object[] { userid, cpid, spid });
  180. Date d = sdf.parse(endtime);
  181. return d;
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. }
  185. return null;
  186. }
  187. //判断是否还需要发短信(查找活动时间范围内是否有订购的记录)
  188. public boolean hasSendCouponSms(String userid,String spid){
  189. PreparedDBUtil pdb = new PreparedDBUtil();
  190. String sql = "select count(1) from tl_order_log a " +
  191. " where spid = ? and userid =? and status = '0' and errorcode = '0' " +
  192. " and inserttime >= (select starttime from tb_acproduct_config where spid = ? " +
  193. " and coupontype = '0' and isunique = '2' and status = '0')" +
  194. " and inserttime <= (select endtime from tb_acproduct_config where spid = ? " +
  195. " and coupontype = '0' and isunique = '2' and status = '0')";
  196. try {
  197. pdb.preparedSelect(DataSource.NET3G, sql);
  198. pdb.setString(1,spid);
  199. pdb.setString(2,userid);
  200. pdb.setString(3,spid);
  201. pdb.setString(4,spid);
  202. pdb.executePrepared();
  203. if (pdb.getInt(0, 0) ==1)
  204. return true;
  205. } catch (SQLException e) {
  206. e.printStackTrace();
  207. }
  208. return false;
  209. }
  210. //采集需要订购后再下发其他短信的产品
  211. public List<String> querySendSmsProduct(){
  212. PreparedDBUtil pdb = new PreparedDBUtil();
  213. String sql = "select spid from tb_sendsms_product where status = '0' ";
  214. try {
  215. pdb.preparedSelect(DataSource.NET3G, sql);
  216. return pdb.executePreparedForList(String.class);
  217. } catch (SQLException e) {
  218. e.printStackTrace();
  219. }
  220. return null;
  221. }
  222. //获得券码活动配置
  223. public HashMap getCouponConfig(String spid ){
  224. PreparedDBUtil pdb = new PreparedDBUtil();
  225. String sql = "SELECT ID, CPID,SPID,TO_CHAR(STARTTIME,'YYYYMMDDHH24MISS') STARTTIME, " +
  226. "TO_CHAR(ENDTIME,'YYYYMMDDHH24MISS') ENDTIME,ACTIVITYCODE,COUPONTYPE,REMARK,CHANNEL,EXTEND1 " +
  227. " from TB_ACPRODUCT_CONFIG where sysdate between STARTTIME and ENDTIME and status = '0' and activitycode = 'telecomActivity' and spid = ? ";
  228. try {
  229. pdb.preparedSelect(DataSource.NET3G, sql);
  230. pdb.setString(1,spid);
  231. // return pdb.executePreparedForList(HashMap.class)==null?null:pdb.executePreparedForList(HashMap.class).get(0);
  232. List<HashMap> list = pdb.executePreparedForList(HashMap.class);
  233. if (list != null && list.size() > 0) {
  234. HashMap map = list.get(0);
  235. return map;
  236. }
  237. } catch (SQLException e) {
  238. e.printStackTrace();
  239. }
  240. return null;
  241. }
  242. }