基于mongodb的临时手机池生成方案(后面补充方案图)

2018-06-08  本文已影响0人  小雪的笔记

print('=========WECOME==========');
//方法
function getMobileV3() {
var getNum = function(start, end) {
var number = (Math.random() * (end - start + 1) + start);
return parseInt(number);
};
var telFirst = "133,153,177,180,181,189,134,135,136,137,138,139,150,151,152,157,158,159,178,182,183,184,187,188,147,130,131,132,155,156,176,185,186,145,170,171"
.split(",");
var index = getNum(0, telFirst.length - 1);
var first = telFirst[index];
var second = (getNum(1, 888) + 10000).toString().substr(1);
var thrid = (getNum(1, 9100) + 10000).toString().substr(1);
return first + second + thrid;
}

function getMobile() {
var getNum = function(start, end) {
var number = (Math.random() * (end - start + 1) + start);
return parseInt(number);
};

var telFirst = "133,153,177,180,181,189,134,135,136,137,138,139,150,151,152,157,158,159,178,182,183,184,187,188,147,130,131,132,155,156,176,185,186,145,170,171"
        .split(",");
var mobile_testNum = "mobile_testNum3";
var mobile = "";
var index = getNum(0, telFirst.length - 1);
var first = telFirst[index];

var mobieend = 0;
var currentNum = 0;
var timestamp =0;
while (true) {
 // var value = Integer.valueOf(ucRedisDao.get(mobile_testNum));
  var partitionNum = db.config.findOne({name:"partitionNum"}).value;
  timestamp = ((new Date()).valueOf()).toString(); 
  var partionIndex = (timestamp%100024);
  var redisKeyMax = "mobile_test3_max:" + (partionIndex).toString();
  var start = db.config.findOne({name:redisKeyMax}).value;
 
  if (start == 0) {
    currentNum = parseInt((100000000 / 100024) * (partionIndex - 1));
    if(partionIndex==0){
        currentNum = 5421;
    }
  } else {
    currentNum = parseInt(start);
  }
  if (currentNum >= ((100000000 / 100024) * partionIndex) || currentNum >= 99999999) {
    db.config.update( {name:"partitionNum" } , { $set : { value : (partitionNum-1)} } );
    print('=========partitionNum=========='+(partitionNum-1));
    continue;
  }

  ++currentNum;
  mobieend = currentNum;
  db.config.update( {name:redisKeyMax } , { $set : { value :currentNum} } );
  mobile = first + (parseInt(mobieend) + 100000000).toString().substr(1);;
  break;
}
print('=========mobile=========='+mobile+'++++++++++++++++++++partionIndex:'+partionIndex+'_____________start:'+start+'   timestamp:'+timestamp);

return mobile;

}

//调用
var index =0;
var startStamp =((new Date()).valueOf());
while(true){
var mobile = getMobile();
var count = db.prdmobile.count({"mobile":parseInt(mobile)});
if(count==0){
db.prdavailablemobile.insert({"mobile":mobile});
++index;
if(index>=20000000){
break;
}else{
print('mobile:'+mobile);
}
}
}

var endStamp =((new Date()).valueOf());
print('=========end=========='+(endStamp-startStamp));

上一篇下一篇

猜你喜欢

热点阅读