欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

表单生成器(Form Builder)之伪造表单数据mongodb篇

程序员文章站 2022-11-07 21:36:26
这篇文章终于回到了正轨:为mongodb伪造数据。之前的随机数、随机车牌照、随机时间还有这篇笔记中的获取指定长度的中文字符串,都是为这篇笔记做准备。看一下我们的准备(基础代码) 现在一切都准备好了,那我们就说说正事儿。为了让这些数据有点意义,我想了三个表单。分别是车辆信息表、车辆耗损表以及车辆营收表 ......

  这篇文章终于回到了正轨:为mongodb伪造数据。之前的随机数、随机车牌照、随机时间还有这篇笔记中的获取指定长度的中文字符串,都是为这篇笔记做准备。看一下我们的准备(基础代码)

//    1、获取指定范围随机数-包括最大值和最小值
var getrangerandomnumber = function(num1,num2){ 
    num1 = number.isinteger(num1) ? num1: 0;
    num2 = number.isinteger(num2) ? num2: 0;
    var minnum=math.min(num1,num2),maxnum=math.max(num1,num2);
    return math.round(math.random() * (maxnum - minnum)) + minnum;
}; 
//    2、格式化日期时间-参考:https://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
var dateextendformat = function(date, format) {
    var o = {
        "m+": date.getmonth() + 1, 
        "d+": date.getdate(), 
        "h+": date.gethours(), 
        "m+": date.getminutes(), 
        "s+": date.getseconds(), 
        "q+": math.floor((date.getmonth() + 3) / 3), 
        "s": date.getmilliseconds() 
    }
    if (/(y+)/.test(format)) format = format.replace(regexp.$1, (date.getfullyear() + "").substr(4 - regexp.$1.length));
    for (var k in o) {
        if (new regexp("(" + k + ")").test(format)) {
            format = format.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};
//    3、获取指定范围随机时间,依赖方法 getrangerandomnumber、dateextendformat
var getrangerandomdate=function(date1,date2,format){
    var date1valueof=new date(date1).valueof(),date2valueof=new date(date2).valueof();
    if(isnan(date1valueof)&&isnan(date2valueof)){
        date1valueof=0;
        date2valueof=new date().valueof();
    }
    else{
        if(isnan(date1valueof))date1valueof=0;
        if(isnan(date2valueof))date2valueof=0;
    }
    var retdate=new date(getrangerandomnumber(math.abs(date1valueof-date2valueof)) + math.min(date1valueof,date2valueof));
    if(format){
        retdate=dateextendformat(retdate,format);
    }
    return retdate;
};
//    4、获取随机车牌照
var getrandomlicenseplate=(function f(excludearr){
    if(!array.isarray(excludearr))excludearr=[];
    //    生成一个随机车联牌照
    var strprovinceshorter="京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川黔滇藏陕甘青宁新港澳台";
    var strnumberletter="0123456789abcdefghijklmnopqrstuvwxyz";
    var tempretlicenseplate=strprovinceshorter[getrangerandomnumber(strprovinceshorter.length-1)];
    for(var i=0;i<6;i++){
        tempretlicenseplate+=strnumberletter[getrangerandomnumber(strnumberletter.length-1)];
    }
    //    判断这个车联牌照是否存在
    if(excludearr.indexof(tempretlicenseplate)>=0){
        tempretlicenseplate = f(excludearr);
    } else {
        excludearr.push(tempretlicenseplate);
    }
    return tempretlicenseplate;
});
//    5.0、获取一个随机汉字
var getchinesecharacter=function(){
    return string.fromcharcode(getrangerandomnumber(parseint("4e00",16),parseint("9fa5",16)));
};
//    5.1、获取指定长度的中文字符串
var getcustomchinesecharacters=function(len){
    len=isnan(number(len))?1:math.abs(math.ceil(number(len)));
    var retstr="";
    for(var i=0;i<len;i++){
        retstr+=getchinesecharacter();
    }
    return retstr;
};

  现在一切都准备好了,那我们就说说正事儿。为了让这些数据有点意义,我想了三个表单。分别是车辆信息表、车辆耗损表以及车辆营收表,下面看一下三张表的结构

车辆信息表(formid: 507048044944691000, formversion: 507048044944691001

唯一标识

中文描述

控件类型

是否必填

表单项的其他配置(在表单设计时配置,文本框长度、时间格式等)

1572493551001

车辆品牌名称

单行文本框

1572493551002

车辆品牌型号

单行文本框

1572493551003

车辆牌照

单行文本框

1572493551004

车辆购买日期

日期时间

1572493551005

车辆购买价格

数值文本框

1572493551006

备注

多行文本框

 

车辆信息表(formid: 507048044944691000, formversion: 507048044944691002

唯一标识

中文描述

控件类型

是否必填

表单项的其他配置(在表单设计时配置,文本框长度、时间格式等)

1572493551001

车辆品牌名称

单行文本框

1572493551002

车辆品牌型号

单行文本框

1572493551003

车辆牌照

单行文本框

1572493551004

车辆购买日期

时间控件

1572493551005

车辆购买价格

数值文本框

1572493551006

备注

多行文本框

……业务需求,删除或者新增一个或者多个字段,生成一个新的版本号

 

车辆耗损表(formid: 507048044944692000, formversion: 507048044944692001

唯一标识

中文描述

控件类型

是否必填

表单项的其他配置(在表单设计时配置,文本框长度、时间格式等)

1572493552001

所属车辆

下拉搜索控件

1572493552002

耗损人员

选择人员控件

1572493552003

耗损时间

时间控件

1572493552004

耗损类别

单行文本框

1572493552005

耗损金额

数值文本框

1572493552006

备注

多行文本框

 

车辆营收表(formid: 507048044944693000, formversion: 507048044944693001

唯一标识

中文描述

控件类型

是否必填

表单项的其他配置(在表单设计时配置,文本框长度、时间格式等)

1572493553001

所属车辆

下拉搜索控件

1572493553002

营收人员

选择人员控件

1572493553003

营收时间

时间控件

1572493553004

营收类别

单行文本框

1572493553005

营收金额

数值文本框

1572493553006

里程

数值文本框

1572493553007

备注

多行文本框

   现在我们就按照表结构伪造数据,下面是全部的代码(可以在mongodb环境下执行)

//    1、获取指定范围随机数-包括最大值和最小值
var getrangerandomnumber = function(num1,num2){ 
    num1 = number.isinteger(num1) ? num1: 0;
    num2 = number.isinteger(num2) ? num2: 0;
    var minnum=math.min(num1,num2),maxnum=math.max(num1,num2);
    return math.round(math.random() * (maxnum - minnum)) + minnum;
}; 
//    2、格式化日期时间-参考:https://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
var dateextendformat = function(date, format) {
    var o = {
        "m+": date.getmonth() + 1, 
        "d+": date.getdate(), 
        "h+": date.gethours(), 
        "m+": date.getminutes(), 
        "s+": date.getseconds(), 
        "q+": math.floor((date.getmonth() + 3) / 3), 
        "s": date.getmilliseconds() 
    }
    if (/(y+)/.test(format)) format = format.replace(regexp.$1, (date.getfullyear() + "").substr(4 - regexp.$1.length));
    for (var k in o) {
        if (new regexp("(" + k + ")").test(format)) {
            format = format.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};
//    3、获取指定范围随机时间,依赖方法 getrangerandomnumber、dateextendformat
var getrangerandomdate=function(date1,date2,format){
    var date1valueof=new date(date1).valueof(),date2valueof=new date(date2).valueof();
    if(isnan(date1valueof)&&isnan(date2valueof)){
        date1valueof=0;
        date2valueof=new date().valueof();
    }
    else{
        if(isnan(date1valueof))date1valueof=0;
        if(isnan(date2valueof))date2valueof=0;
    }
    var retdate=new date(getrangerandomnumber(math.abs(date1valueof-date2valueof)) + math.min(date1valueof,date2valueof));
    if(format){
        retdate=dateextendformat(retdate,format);
    }
    return retdate;
};
//    4、获取随机车牌照
var getrandomlicenseplate=(function f(excludearr){
    if(!array.isarray(excludearr))excludearr=[];
    //    生成一个随机车联牌照
    var strprovinceshorter="京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川黔滇藏陕甘青宁新港澳台";
    var strnumberletter="0123456789abcdefghijklmnopqrstuvwxyz";
    var tempretlicenseplate=strprovinceshorter[getrangerandomnumber(strprovinceshorter.length-1)];
    for(var i=0;i<6;i++){
        tempretlicenseplate+=strnumberletter[getrangerandomnumber(strnumberletter.length-1)];
    }
    //    判断这个车联牌照是否存在
    if(excludearr.indexof(tempretlicenseplate)>=0){
        tempretlicenseplate = f(excludearr);
    } else {
        excludearr.push(tempretlicenseplate);
    }
    return tempretlicenseplate;
});
//    5.0、获取一个随机汉字
var getchinesecharacter=function(){
    return string.fromcharcode(getrangerandomnumber(parseint("4e00",16),parseint("9fa5",16)));
};
//    5.1、获取指定长度的中文字符串
var getcustomchinesecharacters=function(len){
    len=isnan(number(len))?1:math.abs(math.ceil(number(len)));
    var retstr="";
    for(var i=0;i<len;i++){
        retstr+=getchinesecharacter();
    }
    return retstr;
};

//    插入数据方法
var handlebatchinsertdata=function(initconfig){
    if(initconfig.formid&&initconfig.formversion&&array.isarray(initconfig.source)&&initconfig.source.length){
        var temptrs=[],
        tempcreatedate=isodate(),
        tempforminstacedatacounter=db.getcollection('forminstace').find({}).count();
        initconfig.source.foreach((formitemobj)=>{
            var tempcreateuseridindex = math.floor(math.random() * gv_createuserids.length);
            var temptr={
                _id:(++tempforminstacedatacounter).tostring(),
                formitems:[],
                extenddata:{},
                createuserid:gv_createuserids[tempcreateuseridindex],
                createusername:gv_createuserids[tempcreateuseridindex],
                createdate:tempcreatedate,
                lastmodifydate:tempcreatedate,
                formid:initconfig.formid,
                formversion:initconfig.formversion
            };
            for(var i in formitemobj){
                if (formitemobj.hasownproperty(i)){
                    temptr.formitems.push({key:i,value:formitemobj[i]});
                }
            }
            temptrs.push(temptr);
        });
        try{
            db.forminstace.insertmany(temptrs);
        }catch(e){
            print(e);
        }    
    }
};

//    创建用户集合
var gv_createuserids = ["user10000","user10001","user10002","user10003","user10004","user10005","user10006","user10007","user10008","user10009"];

//    车辆信息表插入数据配置
var gv_carinfoinitconfig = {
    formid:"507048044944691000",
    formversion:"507048044944691001",
    cartypes:[
        {    
            brandname:"红旗",
            models:[
                {name:"hs7",min:349800,max:459800},
                {name:"hs5",min:183800,max:249800},
                {name:"h7",min:252800,max:317800},
                {name:"h5",min:146800,max:190800},
                {name:"he-hs3",min:225800,max:317800}
            ]
        },
        {    
            brandname:"比亚迪",
            models:[
                {name:"元",min:65900,max:99900},
                {name:"宋",min:79800,max:119800},
                {name:"宋pro",min:89800,max:119800},
                {name:"唐",min:129900,max:169900},
                {name:"比亚迪f3",min:43900,max:65900},
                {name:"速锐",min:59900,max:69900},
                {name:"秦pro",min:79800,max:115900},
                {name:"宋max",min:79900,max:129900},
                {name:"元ev",min:89900,max:139900},
                {name:"比亚迪s2",min:89800,max:109800},
                {name:"宋dm",min:176900,max:206900},
                {name:"宋pro dm",min:169800,max:259900},
                {name:"宋ev",min:189900,max:219900},
                {name:"宋pro ev",min:179800,max:259900},
                {name:"唐dm",min:229900,max:329900},
                {name:"唐ev",min:259900,max:409900},
                {name:"比亚迪e1",min:59900,max:79900},
                {name:"比亚迪e2",min:89800,max:119800},
                {name:"比亚迪e3",min:103800,max:139800},
                {name:"秦dm",min:132900,max:209900},
                {name:"秦pro dm",min:136900,max:206900},
                {name:"秦ev",min:149900,max:169900},
                {name:"秦pro ev",min:149900,max:299900},
                {name:"宋max dm",min:149900,max:196900},
                {name:"宋max ev",min:179800,max:199800}
            ]
        },
        {    
            brandname:"奇瑞",
            models:[
                {name:"瑞虎3",min:59900,max:79900},
                {name:"瑞虎3x",min:49900,max:62900},
                {name:"瑞虎5x",min:59900,max:89900},
                {name:"瑞虎7",min:85900,max:150900},
                {name:"瑞虎8",min:88800,max:155900},
                {name:"艾瑞泽5",min:49900,max:84900},
                {name:"艾瑞泽gx",min:74900,max:113900},
                {name:"瑞虎3xe",min:175800,max:189800},
                {name:"瑞虎e",min:109900,max:143900},
                {name:"奇瑞eq1",min:59800,max:75800},
                {name:"艾瑞泽e",min:126800,max:143800},
                {name:"艾瑞泽5e",min:192300,max:212300}
            ]
        },
        {    
            brandname:"吉利",
            models:[
                {name:"远景x1",min:39900,max:57900},
                {name:"远景x3",min:45900,max:68900},
                {name:"缤越",min:78800,max:129800},
                {name:"远景s1",min:59900,max:94900},
                {name:"远景x6",min:68900,max:105900},
                {name:"帝豪gs",min:77800,max:116800},
                {name:"博越",min:88800,max:161800},
                {name:"星越",min:135800,max:195800},
                {name:"金刚",min:47900,max:65900},
                {name:"远景",min:47900,max:73900},
                {name:"帝豪",min:68900,max:98800},
                {name:"帝豪gl",min:78800,max:121800},
                {name:"缤瑞",min:75800,max:110800},
                {name:"博瑞",min:136800,max:179800},
                {name:"嘉际",min:99800,max:148800},
                {name:"缤越phev",min:149800,max:169800},
                {name:"帝豪gse",min:119800,max:159800},
                {name:"星越phev",min:188800,max:216800},
                {name:"帝豪ev",min:135800,max:238300},
                {name:"帝豪phev",min:165800,max:185800},
                {name:"帝豪gl phev",min:152800,max:164800},
                {name:"博瑞phev",min:176800,max:209800},
                {name:"嘉际phev",min:169800,max:192800}
            ]
        },
        {    
            brandname:"长安",
            models:[
                {name:"长安cs15",min:55900,max:80900},
                {name:"长安cs35",min:63900,max:87900},
                {name:"长安cs35 plus",min:69900,max:109900},
                {name:"长安cs55",min:82900,max:133900},
                {name:"长安cs75",min:79800,max:174800},
                {name:"长安cs75 plus",min:106900,max:154900},
                {name:"长安cs85 coupe",min:119900,max:169900},
                {name:"长安cs95",min:165900,max:213900},
                {name:"奔奔",min:40900,max:56900},
                {name:"悦翔",min:49900,max:67900},
                {name:"逸动dt",min:52900,max:80900},
                {name:"逸动xt",min:77900,max:111900},
                {name:"逸动",min:69900,max:103900},
                {name:"睿骋cc",min:84900,max:135900},
                {name:"锐程cc",min:94900,max:128900},
                {name:"睿骋",min:120800,max:150800},
                {name:"凌轩",min:67900,max:110900},
                {name:"长安cs15 ev",min:89800,max:98800},
                {name:"长安cs75 phev",min:175800,max:206800},
                {name:"奔奔ev",min:49800,max:81800},
                {name:"逸动et",min:132900,max:142900},
                {name:"逸动phev",min:160900,max:169900},
                {name:"逸动ev",min:129900,max:139900},
            ]
        },
        {    
            brandname:"长安欧尚",
            models:[
                {name:"长安欧尚科赛3",min:59900,max:76900},
                {name:"长安欧尚科赛5",min:69900,max:82900},
                {name:"长安欧尚x70a",min:49900,max:859500},
                {name:"长安欧尚cx70",min:59900,max:109900},
                {name:"长安欧尚科赛",min:86800,max:152800},
                {name:"欧尚s",min:39900,max:55900},
                {name:"欧尚长行",min:68900,max:82900},
                {name:"长安欧尚a600",min:49900,max:84900},
                {name:"长安欧尚a800",min:62900,max:100900},
                {name:"长安欧尚科尚",min:79800,max:160800},
                {name:"长安之星9",min:47800,max:48800},
                {name:"长安星卡",min:32900,max:47900},
                {name:"尼欧ⅱ",min:88800,max:100800},
                {name:"欧力威ev",min:105800,max:105800},
                {name:"欧诺s ev",min:175800,max:175800},
                {name:"欧尚长行ev",min:169800,max:169800},
                {name:"欧尚ev",min:169800,max:169800},
                {name:"欧尚a600 ev",min:149800,max:149800},
                {name:"长安之星9 ev",min:152800,max:156000},
                {name:"长安星卡ev",min:123800,max:125800},
            ]
        },
        {    
            brandname:"长安轻型车",
            models:[
                {name:"睿行s50",min:48900,max:77900},
                {name:"睿行s50t",min:61900,max:78900},
                {name:"睿行m60",min:51900,max:59900},
                {name:"睿行m70",min:60500,max:74000},
                {name:"睿行m80",min:58500,max:72000},
                {name:"睿行m90",min:68500,max:92500},
                {name:"神骐f30",min:47600,max:63800},
                {name:"神骐t10",min:39900,max:50900},
                {name:"神骐t20",min:33900,max:59700},
                {name:"凯程f70",min:92800,max:139800},
                {name:"长安星卡l系列",min:39900,max:47900},
                {name:"长安星卡c系列",min:30900,max:33600},
                {name:"睿行es30",min:66800,max:69800},
                {name:"睿行em60",min:122800,max:122800},
                {name:"睿行em80",min:96800,max:120000}
            ]
        },
        {    
            brandname:"长安跨越",
            models:[
                {name:"长安跨越v3",min:33500,max:34300},
                {name:"跨越王x1",min:39600,max:51800},
                {name:"跨越王x3",min:45700,max:58400},
                {name:"长安跨越王x5",min:47400,max:65600},
                {name:"长安新豹2",min:40700,max:58600},
                {name:"新豹3",min:46200,max:59900},
                {name:"新豹t3",min:41300,max:51800},
                {name:"长安新豹mini",min:32100,max:50500},
                {name:"跨越者d5",min:59300,max:67700},
                {name:"长安跨越新能源v3 ev",min:79200,max:79200},
                {name:"长安跨越新能源v5 ev",min:93800,max:93800}
            ]
        },
        {    
            brandname:"力帆",
            models:[
                {name:"迈威",min:56800,max:73800},
                {name:"力帆x80",min:109900,max:149900},
                {name:"力帆820",min:76800,max:119800},
                {name:"轩朗",min:69800,max:106800},
                {name:"乐途",min:35800,max:59800},
                {name:"力帆650ev",min:168900,max:175800},
                {name:"力帆820ev",min:256800,max:279800}
            ]
        },
        {    
            brandname:"长城",
            models:[
                {name:"风骏5",min:68800,max:112800},
                {name:"风骏6",min:86800,max:117800},
                {name:"风骏7",min:86800,max:138800},
                {name:"炮",min:97800,max:159800},
                {name:"长城c30 ev",min:150000,max:154000}
            ]
        },
        {    
            brandname:"哈弗",
            models:[
                {name:"哈弗h2",min:74900,max:95900},
                {name:"哈弗h2s",min:70000,max:85000},
                {name:"哈弗h4",min:73900,max:115000},
                {name:"哈弗f5",min:100000,max:130000},
                {name:"哈弗h5",min:107800,max:136800},
                {name:"哈弗m6",min:66000,max:82000},
                {name:"哈弗h6",min:102000,max:136000},
                {name:"哈弗h6 coupe",min:79900,max:119000},
                {name:"哈弗h7",min:142000,max:180000},
                {name:"哈弗f7",min:109000,max:153700},
                {name:"哈弗f7x",min:119900,max:154900},
                {name:"哈弗h9",min:209800,max:272800},
            ]
        },
        {    
            brandname:"江铃",
            models:[
                {name:"宝典",min:78800,max:105300},
                {name:"凯锐800",min:120800,max:129100},
                {name:"凯运强劲版",min:99500,max:117400},
                {name:"凯运升级版",min:94800,max:106800},
                {name:"顺达宽体",min:90800,max:100000},
                {name:"顺达窄体",min:84000,max:89000},
                {name:"特顺",min:101300,max:142700},
                {name:"域虎3",min:89800,max:122200},
                {name:"域虎5",min:96800,max:136300},
                {name:"域虎7",min:119800,max:176300},
                {name:"江铃e100b",min:73800,max:73800},
                {name:"江铃e160",min:95800,max:98800},
                {name:"江铃e200l",min:87800,max:90800},
                {name:"江铃e200n",min:90800,max:93800},
                {name:"易至ev3",min:66800,max:83800},
                {name:"易至ex5",min:89800,max:122800},
                {name:"特顺ev",min:206000,max:206000},
                {name:"骐铃t5",min:65800,max:86800},
                {name:"骐铃t7",min:72800,max:113800},
                {name:"骐铃t100",min:53800,max:71800},
                {name:"d-max房车",min:283000,max:396000},
                {name:"考斯特房车",min:318000,max:380000},
                {name:"旅居房车",min:536000,max:596000},
                {name:"罗莎房车租赁款",min:268000,max:288000},
                {name:"骐铃t7皮卡房车",min:258000,max:299800},
                {name:"全顺商旅房车",min:468000,max:518000},
                {name:"全顺t型房车",min:408000,max:448000},
                {name:"商旅房车",min:438000,max:488000},
                {name:"商旅房车经典款",min:388000,max:428000},
                {name:"途睿欧商务车",min:298000,max:398000}
            ]
        },
    ],
    source:[]
};

var gv_tempcarlicenseplates=[];
gv_carinfoinitconfig.cartypes.foreach((cartype)=>{
    if(array.isarray(cartype.models)&&cartype.models.length){
        cartype.models.foreach((model)=>{
            for(var i=0;i<getrangerandomnumber(10,100);i++){
                var tempplate = getrandomlicenseplate(gv_tempcarlicenseplates);
                gv_carinfoinitconfig.source.push({
                    "1572493551001":cartype.brandname,
                    "1572493551002":model.name,
                    "1572493551003":tempplate,
                    "1572493551004":getrangerandomdate("2010-01-01","2018-06-06","yyyy-mm-dd hh:mm:ss"),
                    "1572493551005":getrangerandomnumber(model.min,model.max),
                    "1572493551006":getcustomchinesecharacters(getrangerandomnumber(200))
                });
            }
        });
    }
});

//    车辆花费表插入数据配置
var gv_carwastageinitconfig = {
    formid:"507048044944692000",
    formversion:"507048044944692001",
    wastagetype:[
        {text:"违章",detailed:["信号灯","压线","单双号","规定方向行驶","避让特殊车辆","避让行人","时间道路禁行"]},
        {text:"洗车",detailed:["全套","外围"]},
        {text:"修车",detailed:["轮胎","前玻璃","后玻璃","坐垫","前大灯","后大灯","车窗","发动机","电瓶","变速箱"]},
        {text:"加油",detailed:["92","93","95","97"]},
        {text:"保险",detailed:["太平洋","平安","人保","泰康"]},
        {text:"肇事",detailed:["伤人","护栏","撞车","间接事故","其他"]}
    ],
    source:[]
};

//    车辆营收表插入数据配置
var gv_carrevenueinitconfig = {
    formid:"507048044944693000",
    formversion:"507048044944693001",
    revenuetypes:[
        {text:"租赁",detailed:["一天","一周","一月","一年"]},
        {text:"载客",detailed:["线下","滴滴","uber","快的","其他"]},
        {text:"送货",detailed:["手机","笔记本","照相机","微波炉","电磁率","其他"]},
        {text:"其他",detailed:["婚车","其他"]}
    ],
    source:[]
};

if(gv_carinfoinitconfig.source.length){
    gv_carinfoinitconfig.source.foreach((carinfo,carinfoindex)=>{
        for(var i=0;i<getrangerandomnumber(50,100);i++){
            var tempuseridindexwastagetype = getrangerandomnumber(gv_createuserids.length-1);
            var tempwastagetypeindex = getrangerandomnumber(gv_carwastageinitconfig.wastagetype.length-1);
            var tempwastagetypedetailindex = getrangerandomnumber(gv_carwastageinitconfig.wastagetype[tempwastagetypeindex].detailed.length-1);
            gv_carwastageinitconfig.source.push({
                "1572493552001": {
                    id: (carinfoindex+1).tostring(),
                    name: carinfo["1572493551003"],
                    value: ""
                },
                "1572493552002": [{id:gv_createuserids[tempuseridindexwastagetype],name:gv_createuserids[tempuseridindexwastagetype],face:""}],
                "1572493552003": getrangerandomdate(carinfo["1572493551004"],"2019-11-07","yyyy-mm-dd hh:mm:ss"),
                "1572493552004": gv_carwastageinitconfig.wastagetype[tempwastagetypeindex].text,
                "1572493552005": getrangerandomnumber(20,10000),
                "1572493552006": gv_carwastageinitconfig.wastagetype[tempwastagetypeindex].detailed[tempwastagetypedetailindex]
            });
        }
        
        for(var i=0;i<getrangerandomnumber(100,200);i++){
            var tempuseridindexrevenue = getrangerandomnumber(gv_createuserids.length-1);
            var temprevenueindex = getrangerandomnumber(gv_carrevenueinitconfig.revenuetypes.length-1);
            var temprevenuedetailindex = getrangerandomnumber(gv_carrevenueinitconfig.revenuetypes[temprevenueindex].detailed.length-1);
            gv_carrevenueinitconfig.source.push({
                "1572493553001": {
                    id: (carinfoindex+1).tostring(),
                    name: carinfo["1572493551003"],
                    value: ""
                },
                "1572493553002": [{id:gv_createuserids[tempuseridindexrevenue],name:gv_createuserids[tempuseridindexrevenue],face:""}],
                "1572493553003": getrangerandomdate(carinfo["1572493551004"],"2019-11-07","yyyy-mm-dd hh:mm:ss"),
                "1572493553004": gv_carrevenueinitconfig.revenuetypes[temprevenueindex].text,
                "1572493553005": getrangerandomnumber(20,10000),
                "1572493553006": getrangerandomnumber(50,3000),
                "1572493553007": gv_carrevenueinitconfig.revenuetypes[temprevenueindex].detailed[temprevenuedetailindex]
            });
        }
    });
}

handlebatchinsertdata(gv_carinfoinitconfig);
handlebatchinsertdata(gv_carwastageinitconfig);
handlebatchinsertdata(gv_carrevenueinitconfig);

  看一下数据库中的截图

表单生成器(Form Builder)之伪造表单数据mongodb篇

表单生成器(Form Builder)之伪造表单数据mongodb篇

表单生成器(Form Builder)之伪造表单数据mongodb篇

  一共生成了656084条数据,我觉得还是不错了,没白折腾……当然你可以将随机数调的大一些,便可以生成更多的数据,就到这里吧!