1bfbba9058198e45d023d124473e18efc6daf4fe.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 hasOrder(String userid, String spid) throws SQLException {
  44. String sql = "select count(id) from TD_ORDER_RELATIONS where userid=? and spid=? and status=0 and (endtime is null or endtime > sysdate)";
  45. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, spid }),
  46. 0) > 0;
  47. }
  48. public boolean hasCancelOrder(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 status=1 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 hasValid(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)";
  55. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, cpid, spid }),
  56. 0) > 0;
  57. }
  58. public boolean hasTiyanValid(String userid, String cpid, String spid) throws SQLException {
  59. 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')";
  60. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, cpid, spid }),
  61. 0) > 0;
  62. }
  63. public String getValue(String key) throws SQLException {
  64. return getExecutor().queryFieldWithDBName("net3g", "findpassword", new Object[] { key });
  65. }
  66. public Boolean isOpen(String spid,String cpid,String province) throws Exception {
  67. String sql = "select count(1) from tb_changshi_province_control where spid= ? and cpid = ? and province = ? and status='2'";
  68. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql,spid,cpid,province))>=1 ? true:false;
  69. }
  70. public void insertToken(String token) throws SQLException {
  71. String sql="insert into td_token_date(token) VALUES(?)";
  72. SQLExecutor.insertWithDBName("net3g",sql,token);
  73. }
  74. public Boolean isToken(String spid,String cpid,String channel) throws Exception {
  75. String sql = " select count(1) from tb_istoken_conf where cpid in (?,'*') and spid in (?,'*') and channel in (?,'*') and status='0'";
  76. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, cpid, spid,channel)) > 0;
  77. }
  78. public Map channelProvince(OrderInfo orderInfo) throws Exception {
  79. String sql = "SELECT * FROM TB_PROVINCE_CHANNEL_CONF WHERE STATUS='0' AND PROVINCE = REPLACE(REPLACE(?, '省', ''), '市', '') and channel=? and spid=?";
  80. return SQLExecutor.queryObjectWithDBName(HashMap.class,DataSource.NET3G, sql,new Object[] {orderInfo.getProvince(),orderInfo.getChannel(),orderInfo.getSpid()});
  81. }
  82. public boolean isMangtvCancel(String userid, String spid, String startTime, String endTime) throws SQLException {
  83. 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') ";
  84. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid,startTime,endTime)) > 0;
  85. }
  86. public boolean isMangtvOrder(String userid, String spid) throws SQLException {
  87. String sql = " select count(1) from TD_ORDER_RELATIONS where userid=? and spid=? ";
  88. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid)) > 0;
  89. }
  90. public boolean queryCancelConf(String spid) throws SQLException {
  91. String sql="select count(1) from TB_PRODUCT_CANCEL_CONF where spid= ? and status='0' ";
  92. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid))>0;
  93. }
  94. public Integer getCancelMonth(String spid) throws SQLException {
  95. String sql="select month from TB_PRODUCT_CANCEL_CONF where spid=? and status='0'";
  96. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid));
  97. }
  98. public boolean isCancel(String userid, String spid, Integer num) throws SQLException {
  99. String sql = " select count(1) from TD_ORDER_RELATIONS where userid= ? and spid= ? and sysdate>to_date(TO_CHAR(ADD_MONTHS(ordertime,?),'yyyyMM'),'yyyyMM')";
  100. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid,num)) > 0;
  101. }
  102. public boolean isSendsms(String spid) throws SQLException {
  103. 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' )";
  104. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid,spid)) > 0;
  105. }
  106. public void addCoupon(OrderInfo orderInfo) throws SQLException {
  107. getExecutor().insertBean("net3g", "addcoupon", orderInfo);
  108. }
  109. public String getOrderid(String userid,String spid) throws SQLException {
  110. return getExecutor().queryFieldWithDBName("net3g", "getorderid", new Object[] { userid,spid });
  111. }
  112. public Map getActiveTime(String spid, String channel) throws Exception {
  113. 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 = ?";
  114. return SQLExecutor.queryObjectWithDBName(HashMap.class, DataSource.NET3G, sql,new Object[] { spid, channel});
  115. }
  116. public Boolean hasCoupon(String spid,String userid) throws Exception {
  117. String sql = " select count(1) from td_coupon_rec where userid =? and spid = ? and couponmonth = to_char(sysdate,'yyyymm')";
  118. return Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, userid, spid)) > 0;
  119. }
  120. public boolean hasSendCouponSms(String userid, String spid) throws SQLException {
  121. String sql = "select count(1) from tl_order_log a" +
  122. " where spid = ? and userid =? and status = '0' and errorcode = '0' "+
  123. " and inserttime >= (select starttime from tb_acproduct_config where spid = ? " +
  124. " and coupontype = '0' and isunique = '2' and status = '0') " +
  125. " and inserttime <= (select endtime from tb_acproduct_config where spid = ? " +
  126. "and coupontype = '0' and isunique = '2' and status = '0')";
  127. int count = Integer.parseInt(SQLExecutor.queryFieldWithDBName(DataSource.NET3G, sql, spid,userid,spid,spid));
  128. if(count==1)
  129. return true;
  130. return false;
  131. }
  132. public List<String> querySendSmsProduct() throws SQLException {
  133. String sql = "select spid from tb_sendsms_product where status = '0'";
  134. return SQLExecutor.queryListWithDBName(String.class, DataSource.NET3G, sql);
  135. }
  136. //获得券码活动配置
  137. public HashMap getCouponConfig(String spid ){
  138. PreparedDBUtil pdb = new PreparedDBUtil();
  139. String sql = "SELECT ID, CPID,SPID,TO_CHAR(STARTTIME,'YYYYMMDDHH24MISS') STARTTIME, " +
  140. "TO_CHAR(ENDTIME,'YYYYMMDDHH24MISS') ENDTIME,ACTIVITYCODE,COUPONTYPE,REMARK,CHANNEL,EXTEND1 " +
  141. " from TB_ACPRODUCT_CONFIG where sysdate between STARTTIME and ENDTIME and status = '0' and activitycode = 'telecomActivity' and spid = ? ";
  142. try {
  143. pdb.preparedSelect(DataSource.NET3G, sql);
  144. pdb.setString(1,spid);
  145. //return pdb.executePreparedForList(HashMap.class)==null?null:pdb.executePreparedForList(HashMap.class).get(0);
  146. List<HashMap> list = pdb.executePreparedForList(HashMap.class);
  147. if (list != null && list.size() > 0) {
  148. HashMap map = list.get(0);
  149. return map;
  150. }
  151. } catch (SQLException e) {
  152. e.printStackTrace();
  153. }
  154. return null;
  155. }
  156. public String getHmdInfo(String callerhead){
  157. PreparedDBUtil pdb = new PreparedDBUtil();
  158. String sql="select PROVINCE from TB_CALLER_AREACODE where status = '0' and callerhead = ?";
  159. try {
  160. pdb.preparedSelect(DataSource.NET3G, sql);
  161. pdb.setString(1, callerhead);
  162. return (String) pdb.executePreparedForObject(String.class);
  163. } catch (SQLException e) {
  164. e.printStackTrace();
  165. }
  166. return null;
  167. }
  168. /**
  169. * 获取字典表里可以退订的合约包spid
  170. * @param name
  171. * @return
  172. * @throws SQLException
  173. */
  174. public String getDictionryValue(String name) throws SQLException {
  175. return getExecutor().queryFieldWithDBName("net3g", "getDictionryValue", new Object[]{name});
  176. }
  177. /**
  178. * 获取合约包绑定的违约包spid
  179. * @param spid
  180. * @return
  181. * @throws SQLException
  182. */
  183. public String getWYJSpid(String spid) throws SQLException {
  184. return getExecutor().queryFieldWithDBName("net3g", "getWYJSpid", new Object[]{spid});
  185. }
  186. public void addWYJLog(WyjLogBean bean) throws SQLException {
  187. getExecutor().insertBean("net3g", "addWYJLog", bean);
  188. }
  189. public String getSpname(String spid) throws SQLException {
  190. return this.getExecutor().queryFieldWithDBName("net3g", "getSpname", new Object[]{spid});
  191. }
  192. public void inserArrearageData(ReflowBean reflowBean) throws SQLException {
  193. getExecutor().insertBean("net3g", "inserArrearageData", reflowBean);
  194. }
  195. public List<String> queryAopProduct() throws SQLException {
  196. String sql = "select t1.spid from (select sp_id spid from tb_sp_aop_config group by sp_id) t1 " +
  197. ",(select * from tb_sp_info where vacproductid is not null and paytype = '4') t2 " +
  198. "where t1.spid = t2.spid ";
  199. return SQLExecutor.queryListWithDBName(String.class, DataSource.NET3G, sql);
  200. }
  201. public boolean getRelation(String userid,String spid) throws SQLException {
  202. String sql = "select count(id) from TD_ORDER_RELATIONS where userid=? and spid=? ";
  203. return NumberUtils.toInt(SQLExecutor.queryFieldWithDBName("net3g", sql, new Object[] { userid, spid }),
  204. 0) > 0;
  205. }
  206. }