99ccc44f76f6b66947ac83433a70e1f2697430fd.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package com.chinacreator.videoalliance.order.dao;
  2. import com.chinacreator.common.dao.ExecutorDao;
  3. import com.chinacreator.videoalliance.common.util.DataSource;
  4. import com.chinacreator.videoalliance.order.bean.*;
  5. import com.frameworkset.common.poolman.PreparedDBUtil;
  6. import com.frameworkset.common.poolman.SQLExecutor;
  7. import org.apache.commons.lang.math.NumberUtils;
  8. import org.springframework.stereotype.Component;
  9. import java.sql.SQLException;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. @Component
  14. public class OrderDao extends ExecutorDao {
  15. public void order(OrderInfo orderInfo) throws SQLException {
  16. getExecutor().insertBean("net3g", "order", orderInfo);
  17. }
  18. public void countOrder(OrderInfo orderInfo) throws SQLException {
  19. getExecutor().insertBean("net3g", "countOrder", orderInfo);
  20. }
  21. public void orderTiyan(OrderInfo orderInfo) throws SQLException {
  22. getExecutor().insertBean("net3g", "ordertiyan", orderInfo);
  23. }
  24. public void cancelOrder(OrderInfo orderInfo) throws SQLException {
  25. getExecutor().updateBean("net3g", "cancelOrder", orderInfo);
  26. }
  27. public OrderInfo findByUser(String userid, String cpid, String spid) throws SQLException {
  28. return (OrderInfo)getExecutor().queryObjectWithDBName(OrderInfo.class, "net3g", "findByUserAndSpid",
  29. new Object[] { userid, cpid, spid });
  30. }
  31. public List<OrderInfo> findByUser(String userid, String cpid) throws SQLException {
  32. return getExecutor().queryListWithDBName(OrderInfo.class, "net3g", "findByUserAndCpid",
  33. new Object[] { userid, cpid });
  34. }
  35. public List<OrderInfo> findByUser(String userid) throws SQLException {
  36. return getExecutor().queryListWithDBName(OrderInfo.class, "net3g", "findByUser", new Object[] { userid });
  37. }
  38. public boolean hasOrder(String userid, String cpid, String spid) throws SQLException {
  39. String sql = "select count(id) from TD_ORDER_RELATIONS where userid=? and cpid=? and spid=? and status=0 and (endtime is null or endtime > sysdate)";
  40. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, cpid, spid }),
  41. 0) > 0;
  42. }
  43. public boolean hasCancelOrder(String userid, String cpid, String spid) throws SQLException {
  44. String sql = "select count(id) from TD_ORDER_RELATIONS where userid=? and cpid=? and spid=? and status=1 and (endtime is null or endtime > sysdate)";
  45. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, cpid, spid }),
  46. 0) > 0;
  47. }
  48. public boolean hasValid(String userid, String cpid, String spid) throws SQLException {
  49. String sql = "select count(id) from TD_ORDER_RELATIONS where userid=? and cpid=? and spid=? and (endtime is null or endtime > sysdate)";
  50. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, cpid, spid }),
  51. 0) > 0;
  52. }
  53. public boolean hasTiyanValid(String userid, String cpid, String spid) throws SQLException {
  54. String sql = "select count(id) from TD_ORDER_RELATIONS where userid=? and cpid=? and spid=? and (endtime is null or endtime > sysdate) and orderstatus in (7,9) and spid not in (select spid from tb_sp_info where errorhandle = '0')";
  55. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, cpid, spid }),
  56. 0) > 0;
  57. }
  58. public String getValue(String key) throws SQLException {
  59. return getExecutor().queryFieldWithDBName("net3g", "findpassword", new Object[] { key });
  60. }
  61. public Boolean isOpen(String spid,String cpid,String province) throws Exception {
  62. String sql = "select count(1) from tb_changshi_province_control where spid= ? and cpid = ? and province = ? and status='2'";
  63. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql,spid,cpid,province))>=1 ? true:false;
  64. }
  65. public void insertToken(String token) throws SQLException {
  66. String sql="insert into td_token_date(token) VALUES(?)";
  67. SQLExecutor.insertWithDBName("net3g",sql,token);
  68. }
  69. public Boolean isToken(String spid,String cpid,String channel) throws Exception {
  70. String sql = " select count(1) from tb_istoken_conf where cpid in (?,'*') and spid in (?,'*') and channel in (?,'*') and status='0'";
  71. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, cpid, spid,channel)) > 0;
  72. }
  73. public Map channelProvince(OrderInfo orderInfo) throws Exception {
  74. String sql = "SELECT * FROM TB_PROVINCE_CHANNEL_CONF WHERE STATUS='0' AND PROVINCE = REPLACE(REPLACE(?, '省', ''), '市', '') and channel=? and spid=?";
  75. return SQLExecutor.queryObjectWithDBName(HashMap.class,DataSource.NET3G, sql,new Object[] {orderInfo.getProvince(),orderInfo.getChannel(),orderInfo.getSpid()});
  76. }
  77. public boolean isMangtvCancel(String userid, String spid, String startTime, String endTime) throws SQLException {
  78. String sql = " select count(1) from TD_ORDER_RELATIONS where userid=? and spid=? and ordertime>=to_date(?,'yyyyMMddHH24miss') and ORDERTIME<=to_date(?,'yyyyMMddHH24miss') and sysdate<to_date(TO_CHAR(ADD_MONTHS(ordertime,6),'yyyyMM'),'yyyyMM') ";
  79. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid,startTime,endTime)) > 0;
  80. }
  81. public boolean isMangtvOrder(String userid, String spid) throws SQLException {
  82. String sql = " select count(1) from TD_ORDER_RELATIONS where userid=? and spid=? ";
  83. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid)) > 0;
  84. }
  85. public boolean queryCancelConf(String spid) throws SQLException {
  86. String sql="select count(1) from TB_PRODUCT_CANCEL_CONF where spid= ? and status='0' ";
  87. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid))>0;
  88. }
  89. public Integer getCancelMonth(String spid) throws SQLException {
  90. String sql="select month from TB_PRODUCT_CANCEL_CONF where spid=? and status='0'";
  91. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid));
  92. }
  93. public boolean isCancel(String userid, String spid, Integer num) throws SQLException {
  94. String sql = " select count(1) from TD_ORDER_RELATIONS where userid= ? and spid= ? and sysdate>to_date(TO_CHAR(ADD_MONTHS(ordertime,?),'yyyyMM'),'yyyyMM')";
  95. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid,num)) > 0;
  96. }
  97. public boolean isSendsms(String spid) throws SQLException {
  98. String sql="select count(1) from tb_sp_info t where t.spid= ? and t.DIRECTYPE='1' and t.spid not in ('1027','1028','1022','1023') and not EXISTS (select * from TB_PRODUCT_CANCEL_CONF b where b.spid=? and b.status='0' )";
  99. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid,spid)) > 0;
  100. }
  101. public void addCoupon(OrderInfo orderInfo) throws SQLException {
  102. getExecutor().insertBean("net3g", "addcoupon", orderInfo);
  103. }
  104. public String getOrderid(String userid,String spid) throws SQLException {
  105. return getExecutor().queryFieldWithDBName("net3g", "getorderid", new Object[] { userid,spid });
  106. }
  107. public Map getActiveTime(String spid, String channel) throws Exception {
  108. String sql = "SELECT to_char(starttime,'yyyy-mm-dd hh24:mi:ss') starttime,to_char(endtime,'yyyy-mm-dd hh24:mi:ss') endtime from tb_acproduct_config where spid = ? and channel = ?";
  109. return SQLExecutor.queryObjectWithDBName(HashMap.class, DataSource.NET3G, sql,new Object[] { spid, channel});
  110. }
  111. public Boolean hasCoupon(String spid,String userid) throws Exception {
  112. String sql = " select count(1) from td_coupon_rec where userid =? and spid = ? and couponmonth = to_char(sysdate,'yyyymm')";
  113. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid)) > 0;
  114. }
  115. public boolean hasSendCouponSms(String userid, String spid) throws SQLException {
  116. String sql = "select count(1) from tl_order_log a" +
  117. " where spid = ? and userid =? and status = '0' and errorcode = '0' "+
  118. " and inserttime >= (select starttime from tb_acproduct_config where spid = ? " +
  119. " and coupontype = '0' and isunique = '2' and status = '0') " +
  120. " and inserttime <= (select endtime from tb_acproduct_config where spid = ? " +
  121. "and coupontype = '0' and isunique = '2' and status = '0')";
  122. int count = Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid,userid,spid,spid));
  123. if(count==1)
  124. return true;
  125. return false;
  126. }
  127. public List<String> querySendSmsProduct() throws SQLException {
  128. String sql = "select spid from tb_sendsms_product where status = '0'";
  129. return SQLExecutor.queryListWithDBName(String.class, DataSource.NET3G, sql);
  130. }
  131. //获得券码活动配置
  132. public HashMap getCouponConfig(String spid ){
  133. PreparedDBUtil pdb = new PreparedDBUtil();
  134. String sql = "SELECT ID, CPID,SPID,TO_CHAR(STARTTIME,'YYYYMMDDHH24MISS') STARTTIME, " +
  135. "TO_CHAR(ENDTIME,'YYYYMMDDHH24MISS') ENDTIME,ACTIVITYCODE,COUPONTYPE,REMARK,CHANNEL,EXTEND1 " +
  136. " from TB_ACPRODUCT_CONFIG where sysdate between STARTTIME and ENDTIME and status = '0' and activitycode = 'telecomActivity' and spid = ? ";
  137. try {
  138. pdb.preparedSelect(DataSource.NET3G, sql);
  139. pdb.setString(1,spid);
  140. //return pdb.executePreparedForList(HashMap.class)==null?null:pdb.executePreparedForList(HashMap.class).get(0);
  141. List<HashMap> list = pdb.executePreparedForList(HashMap.class);
  142. if (list != null && list.size() > 0) {
  143. HashMap map = list.get(0);
  144. return map;
  145. }
  146. } catch (SQLException e) {
  147. e.printStackTrace();
  148. }
  149. return null;
  150. }
  151. public String getHmdInfo(String callerhead){
  152. PreparedDBUtil pdb = new PreparedDBUtil();
  153. String sql="select PROVINCE from TB_CALLER_AREACODE where status = '0' and callerhead = ?";
  154. try {
  155. pdb.preparedSelect(DataSource.NET3G, sql);
  156. pdb.setString(1, callerhead);
  157. return (String) pdb.executePreparedForObject(String.class);
  158. } catch (SQLException e) {
  159. e.printStackTrace();
  160. }
  161. return null;
  162. }
  163. /**
  164. * 获取字典表里可以退订的合约包spid
  165. * @param name
  166. * @return
  167. * @throws SQLException
  168. */
  169. public String getDictionryValue(String name) throws SQLException {
  170. return getExecutor().queryFieldWithDBName("net3g", "getDictionryValue", new Object[]{name});
  171. }
  172. /**
  173. * 获取合约包绑定的违约包spid
  174. * @param spid
  175. * @return
  176. * @throws SQLException
  177. */
  178. public String getWYJSpid(String spid) throws SQLException {
  179. return getExecutor().queryFieldWithDBName("net3g", "getWYJSpid", new Object[]{spid});
  180. }
  181. public void addWYJLog(WyjLogBean bean) throws SQLException {
  182. getExecutor().insertBean("net3g", "addWYJLog", bean);
  183. }
  184. public String getSpname(String spid) throws SQLException {
  185. return this.getExecutor().queryFieldWithDBName("net3g", "getSpname", new Object[]{spid});
  186. }
  187. public void inserArrearageData(ReflowBean reflowBean) throws SQLException {
  188. getExecutor().insertBean("net3g", "inserArrearageData", reflowBean);
  189. }
  190. }