144d01b82cbc04fa096fbfb2e81224048df9ccbd.svn-base 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package com.chinacreator.videoalliance.order.dao;
  2. import java.sql.SQLException;
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import org.apache.log4j.Logger;
  8. import org.springframework.cache.annotation.Cacheable;
  9. import org.springframework.stereotype.Component;
  10. import org.springframework.util.StringUtils;
  11. import com.chinacreator.common.exception.BusinessException;
  12. import com.chinacreator.common.support.cache.annotation.CacheName;
  13. import com.chinacreator.videoalliance.common.util.DataSource;
  14. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  15. import com.chinacreator.videoalliance.order.bean.SPInfo;
  16. import com.frameworkset.common.poolman.SQLExecutor;
  17. /**
  18. * 查询TB_SP_OPERLIMIT_CONF配置数据
  19. * @author xu.zhou
  20. * @date 20211230
  21. */
  22. @Component
  23. public class BusiOperlimitConfDao {
  24. private static Logger log = Logger.getLogger("orderError");
  25. /**
  26. * 获取IP白名单
  27. * @param invokeface
  28. * @return
  29. * @throws Exception
  30. */
  31. public List<HashMap> valiIpLimit(String invokeface) throws Exception {
  32. String sql = "SELECT PROJNAME, INVOKEFACE, IP FROM TB_PROJIPLIMIT_CONF WHERE STATUS = '0' AND INVOKEFACE = ? AND PROJNAME = 'videoif' ORDER BY INSERTTIME DESC ";
  33. return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, invokeface);
  34. }
  35. /**
  36. * 验证业务操作限制(是否能订购,是否能退订)
  37. * @param spid
  38. * @param status
  39. * @param datasrc
  40. * @param channel
  41. * @return
  42. * @throws Exception
  43. */
  44. public List<HashMap> valiOperLimit(String spid, String opertype) throws Exception {
  45. //System.out.println("查询数据库");
  46. String sql = "SELECT CPID,SPID,OPERTYPE,CHANNEL,DATASRC,IP FROM TB_SP_OPERLIMIT_CONF WHERE STATUS = '0' AND SPID = ? AND OPERTYPE = ? AND DATASRC = 'INTERFACE' ORDER BY CHANNEL ";
  47. return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, spid, opertype);
  48. }
  49. public boolean vali(String spid, String opertype, String ip, String channel) throws Exception {
  50. List<HashMap> dataList = this.valiOperLimit(spid, opertype);
  51. //是否限制办理
  52. boolean haslimit = false;
  53. if(dataList != null && dataList.size()>0){
  54. for(HashMap tm : dataList){
  55. System.out.println("tm=>"+tm);
  56. //能查到数据代表有限制,先设置为受限制
  57. haslimit = true;
  58. //配置了指定渠道不受限制,且渠道相同
  59. if(!StringUtils.isEmpty(channel) && channel.equals(tm.get("CHANNEL"))){
  60. //设置为不受限制
  61. haslimit = false;
  62. //配置了IP白名单,调用的IP必须在名单内
  63. if(!StringUtils.isEmpty((String)tm.get("IP"))){
  64. //先设置为受限制
  65. haslimit = true;
  66. //把IP转为LIST
  67. List<String> ipList = Arrays.asList(tm.get("IP").toString().split(","));
  68. //请求IP包含在白名单内
  69. if(ipList.contains(ip)){
  70. haslimit = false;
  71. }
  72. }
  73. }
  74. //如果不受限制,说明有匹配到了不受限制的配置数据
  75. if(!haslimit){
  76. break;
  77. }
  78. }
  79. //被限制抛异常
  80. if(haslimit){
  81. throw new BusinessException("7020", "该产品已下线,暂停办理");
  82. }
  83. }
  84. return haslimit;
  85. }
  86. /**
  87. * 前向产品订购失败添加数据到华胜前向推送表
  88. * 只有前向产品订购失败才添加,不包括违约金产品
  89. * @param orderInfo
  90. * @return
  91. */
  92. public boolean addHuashengSyncWait(OrderInfo orderInfo, String resultcode, String errorinfo){
  93. boolean res = false;
  94. String sqlspinfo = "select cpid, spid, spname, price, vacproductid, spcode, type, feetype, cancancelorder, canorder,errorhandle,duration,canaccumulation,mutex,relationSp,paytype,needUnifiedAuthSync,spcodename,haslocal,directype from tb_sp_info where spid=?";
  95. String sql = " INSERT INTO TD_HUASHENGSYNC_WAIT (ID, CPID, SPID, USERID, ORDERTIME, PROVINCE,AREA, ORDERCHANNEL, ORDERTYPE, HASSUCC, FAILCODE, FAILINFO, RESULTCODE ) "+
  96. " VALUES ( TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval, ?, ?, ?, SYSDATE, ?, ?, ?, '0', '1', ?, ?, '1' ) ";
  97. String userid = "";
  98. String spid = "";
  99. String cpid = "";
  100. try {
  101. userid = orderInfo.getUserid();
  102. spid = orderInfo.getSpid();
  103. cpid = orderInfo.getCpid();
  104. String directype = orderInfo.getDirectype(); //1,3为前向产品
  105. if("0".equals(resultcode)){//订购成功不处理
  106. return res;
  107. }
  108. //directype为空,查表获取
  109. if(StringUtils.isEmpty(directype)){
  110. SPInfo spinfo = (SPInfo)SQLExecutor.queryObjectWithDBName(SPInfo.class, "net3g", sqlspinfo, new Object[] { spid });
  111. if(spinfo != null) directype = spinfo.getDirectype();
  112. }
  113. if(!"1".equals(directype) && !"3".equals(directype)){//非前向产品不处理
  114. return res;
  115. }
  116. if(!StringUtils.isEmpty(errorinfo) && errorinfo.length() > 300){
  117. errorinfo = errorinfo.substring(0,300);
  118. }
  119. Object obj = SQLExecutor.insertWithDBName("net3g", sql,
  120. orderInfo.getCpid(),
  121. orderInfo.getSpid(),
  122. orderInfo.getUserid(),
  123. orderInfo.getProvince(),
  124. orderInfo.getArea(),
  125. orderInfo.getOrderchannel(),
  126. resultcode,
  127. errorinfo
  128. );
  129. res = ((Integer)obj) > 0;
  130. } catch (Exception e) {
  131. e.printStackTrace();
  132. log.error(userid+","+spid+",添加数据TD_HUASHENGSYNC_WAIT出现异常,"+e.getMessage());
  133. }
  134. return res;
  135. }
  136. /**
  137. * 查询省份限制配置
  138. * @param invokeface
  139. * @param province
  140. * @param type
  141. * @return
  142. * @throws SQLException
  143. */
  144. @Cacheable(value="ProvinceLimit", key="'ProvinceLimit-' + #invokeface + '-' + #province + '-' + #type")
  145. public List<HashMap> valiProvinceLimit(String invokeface, String province, String type) throws SQLException {
  146. boolean res = false;
  147. String sql = "SELECT INVOKEFACE, PROVINCE, CHANNEL, TYPE FROM TB_PROVINCE_INVOKELIMIT_CONF WHERE PROJNAME = 'videoif' AND STATUS = '0' AND INVOKEFACE = ? "+
  148. " AND ( TYPE = ? OR TYPE = '*' ) "+
  149. " AND ( PROVINCE = ? OR PROVINCE = '*' ) ";
  150. return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, invokeface, type, province);
  151. }
  152. public static void main(String[] args) {
  153. BusiOperlimitConfDao dao = new BusiOperlimitConfDao();
  154. try {
  155. //System.out.println(dao.valiOperLimit("99144186","0"));
  156. System.out.println(dao.vali("99144186","0","172.16.33.16",null));
  157. } catch (Exception e) {
  158. e.printStackTrace();
  159. }
  160. }
  161. }