123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package com.chinacreator.videoalliance.order.dao;
- import java.sql.SQLException;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.log4j.Logger;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.stereotype.Component;
- import org.springframework.util.StringUtils;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.support.cache.annotation.CacheName;
- import com.chinacreator.videoalliance.common.util.DataSource;
- import com.chinacreator.videoalliance.order.bean.OrderInfo;
- import com.chinacreator.videoalliance.order.bean.SPInfo;
- import com.frameworkset.common.poolman.SQLExecutor;
- /**
- * 查询TB_SP_OPERLIMIT_CONF配置数据
- * @author xu.zhou
- * @date 20211230
- */
- @Component
- public class BusiOperlimitConfDao {
-
- private static Logger log = Logger.getLogger("orderError");
-
- /**
- * 获取IP白名单
- * @param invokeface
- * @return
- * @throws Exception
- */
- public List<HashMap> valiIpLimit(String invokeface) throws Exception {
- String sql = "SELECT PROJNAME, INVOKEFACE, IP FROM TB_PROJIPLIMIT_CONF WHERE STATUS = '0' AND INVOKEFACE = ? AND PROJNAME = 'videoif' ORDER BY INSERTTIME DESC ";
- return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, invokeface);
- }
-
- /**
- * 验证业务操作限制(是否能订购,是否能退订)
- * @param spid
- * @param status
- * @param datasrc
- * @param channel
- * @return
- * @throws Exception
- */
- public List<HashMap> valiOperLimit(String spid, String opertype) throws Exception {
- //System.out.println("查询数据库");
- 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 ";
- return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, spid, opertype);
- }
-
- public boolean vali(String spid, String opertype, String ip, String channel) throws Exception {
- List<HashMap> dataList = this.valiOperLimit(spid, opertype);
- //是否限制办理
- boolean haslimit = false;
- if(dataList != null && dataList.size()>0){
- for(HashMap tm : dataList){
- System.out.println("tm=>"+tm);
- //能查到数据代表有限制,先设置为受限制
- haslimit = true;
- //配置了指定渠道不受限制,且渠道相同
- if(!StringUtils.isEmpty(channel) && channel.equals(tm.get("CHANNEL"))){
- //设置为不受限制
- haslimit = false;
- //配置了IP白名单,调用的IP必须在名单内
- if(!StringUtils.isEmpty((String)tm.get("IP"))){
- //先设置为受限制
- haslimit = true;
- //把IP转为LIST
- List<String> ipList = Arrays.asList(tm.get("IP").toString().split(","));
- //请求IP包含在白名单内
- if(ipList.contains(ip)){
- haslimit = false;
- }
- }
- }
- //如果不受限制,说明有匹配到了不受限制的配置数据
- if(!haslimit){
- break;
- }
- }
-
- //被限制抛异常
- if(haslimit){
- throw new BusinessException("7020", "该产品已下线,暂停办理");
- }
- }
-
- return haslimit;
- }
-
- /**
- * 前向产品订购失败添加数据到华胜前向推送表
- * 只有前向产品订购失败才添加,不包括违约金产品
- * @param orderInfo
- * @return
- */
- public boolean addHuashengSyncWait(OrderInfo orderInfo, String resultcode, String errorinfo){
- boolean res = false;
- 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=?";
- String sql = " INSERT INTO TD_HUASHENGSYNC_WAIT (ID, CPID, SPID, USERID, ORDERTIME, PROVINCE,AREA, ORDERCHANNEL, ORDERTYPE, HASSUCC, FAILCODE, FAILINFO, RESULTCODE ) "+
- " VALUES ( TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval, ?, ?, ?, SYSDATE, ?, ?, ?, '0', '1', ?, ?, '1' ) ";
- String userid = "";
- String spid = "";
- String cpid = "";
- try {
- userid = orderInfo.getUserid();
- spid = orderInfo.getSpid();
- cpid = orderInfo.getCpid();
- String directype = orderInfo.getDirectype(); //1,3为前向产品
- if("0".equals(resultcode)){//订购成功不处理
- return res;
- }
- //directype为空,查表获取
- if(StringUtils.isEmpty(directype)){
- SPInfo spinfo = (SPInfo)SQLExecutor.queryObjectWithDBName(SPInfo.class, "net3g", sqlspinfo, new Object[] { spid });
- if(spinfo != null) directype = spinfo.getDirectype();
- }
- if(!"1".equals(directype) && !"3".equals(directype)){//非前向产品不处理
- return res;
- }
- if(!StringUtils.isEmpty(errorinfo) && errorinfo.length() > 300){
- errorinfo = errorinfo.substring(0,300);
- }
- Object obj = SQLExecutor.insertWithDBName("net3g", sql,
- orderInfo.getCpid(),
- orderInfo.getSpid(),
- orderInfo.getUserid(),
- orderInfo.getProvince(),
- orderInfo.getArea(),
- orderInfo.getOrderchannel(),
- resultcode,
- errorinfo
- );
- res = ((Integer)obj) > 0;
- } catch (Exception e) {
- e.printStackTrace();
- log.error(userid+","+spid+",添加数据TD_HUASHENGSYNC_WAIT出现异常,"+e.getMessage());
- }
-
- return res;
- }
-
- /**
- * 查询省份限制配置
- * @param invokeface
- * @param province
- * @param type
- * @return
- * @throws SQLException
- */
- @Cacheable(value="ProvinceLimit", key="'ProvinceLimit-' + #invokeface + '-' + #province + '-' + #type")
- public List<HashMap> valiProvinceLimit(String invokeface, String province, String type) throws SQLException {
- boolean res = false;
- String sql = "SELECT INVOKEFACE, PROVINCE, CHANNEL, TYPE FROM TB_PROVINCE_INVOKELIMIT_CONF WHERE PROJNAME = 'videoif' AND STATUS = '0' AND INVOKEFACE = ? "+
- " AND ( TYPE = ? OR TYPE = '*' ) "+
- " AND ( PROVINCE = ? OR PROVINCE = '*' ) ";
- return SQLExecutor.queryListWithDBName(HashMap.class, DataSource.NET3G, sql, invokeface, type, province);
- }
-
- public static void main(String[] args) {
- BusiOperlimitConfDao dao = new BusiOperlimitConfDao();
- try {
- //System.out.println(dao.valiOperLimit("99144186","0"));
- System.out.println(dao.vali("99144186","0","172.16.33.16",null));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|