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

  1. // 1、获取指定范围随机数-包括最大值和最小值
  2. var getRangeRandomNumber = function(num1,num2){
  3. num1 = Number.isInteger(num1) ? num1: 0;
  4. num2 = Number.isInteger(num2) ? num2: 0;
  5. var minNum=Math.min(num1,num2),maxNum=Math.max(num1,num2);
  6. return Math.round(Math.random() * (maxNum - minNum)) + minNum;
  7. };
  8. // 2、格式化日期时间-参考:https://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
  9. var dateExtendFormat = function(date, format) {
  10. var o = {
  11. "M+": date.getMonth() + 1,
  12. "d+": date.getDate(),
  13. "H+": date.getHours(),
  14. "m+": date.getMinutes(),
  15. "s+": date.getSeconds(),
  16. "q+": Math.floor((date.getMonth() + 3) / 3),
  17. "S": date.getMilliseconds()
  18. }
  19. if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  20. for (var k in o) {
  21. if (new RegExp("(" + k + ")").test(format)) {
  22. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  23. }
  24. }
  25. return format;
  26. };
  27. // 3、获取指定范围随机时间,依赖方法 getRangeRandomNumber、dateExtendFormat
  28. var getRangeRandomDate=function(date1,date2,format){
  29. var date1ValueOf=new Date(date1).valueOf(),date2ValueOf=new Date(date2).valueOf();
  30. if(isNaN(date1ValueOf)&&isNaN(date2ValueOf)){
  31. date1ValueOf=0;
  32. date2ValueOf=new Date().valueOf();
  33. }
  34. else{
  35. if(isNaN(date1ValueOf))date1ValueOf=0;
  36. if(isNaN(date2ValueOf))date2ValueOf=0;
  37. }
  38. var retDate=new Date(getRangeRandomNumber(Math.abs(date1ValueOf-date2ValueOf)) + Math.min(date1ValueOf,date2ValueOf));
  39. if(format){
  40. retDate=dateExtendFormat(retDate,format);
  41. }
  42. return retDate;
  43. };
  44. // 4、获取随机车牌照
  45. var getRandomLicensePlate=(function f(excludeArr){
  46. if(!Array.isArray(excludeArr))excludeArr=[];
  47. // 生成一个随机车联牌照
  48. var strProvinceShorter="京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川黔滇藏陕甘青宁新港澳台";
  49. var strNumberLetter="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  50. var tempRetLicensePlate=strProvinceShorter[getRangeRandomNumber(strProvinceShorter.length-1)];
  51. for(var i=0;i<6;i++){
  52. tempRetLicensePlate+=strNumberLetter[getRangeRandomNumber(strNumberLetter.length-1)];
  53. }
  54. // 判断这个车联牌照是否存在
  55. if(excludeArr.indexOf(tempRetLicensePlate)>=0){
  56. tempRetLicensePlate = f(excludeArr);
  57. } else {
  58. excludeArr.push(tempRetLicensePlate);
  59. }
  60. return tempRetLicensePlate;
  61. });
  62. // 5.0、获取一个随机汉字
  63. var getChineseCharacter=function(){
  64. return String.fromCharCode(getRangeRandomNumber(parseInt("4E00",16),parseInt("9FA5",16)));
  65. };
  66. // 5.1、获取指定长度的中文字符串
  67. var getCustomChineseCharacters=function(len){
  68. len=isNaN(Number(len))?1:Math.abs(Math.ceil(Number(len)));
  69. var retStr="";
  70. for(var i=0;i<len;i++){
  71. retStr+=getChineseCharacter();
  72. }
  73. return retStr;
  74. };

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

车辆信息表(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. // 1、获取指定范围随机数-包括最大值和最小值
  2. var getRangeRandomNumber = function(num1,num2){
  3. num1 = Number.isInteger(num1) ? num1: 0;
  4. num2 = Number.isInteger(num2) ? num2: 0;
  5. var minNum=Math.min(num1,num2),maxNum=Math.max(num1,num2);
  6. return Math.round(Math.random() * (maxNum - minNum)) + minNum;
  7. };
  8. // 2、格式化日期时间-参考:https://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
  9. var dateExtendFormat = function(date, format) {
  10. var o = {
  11. "M+": date.getMonth() + 1,
  12. "d+": date.getDate(),
  13. "H+": date.getHours(),
  14. "m+": date.getMinutes(),
  15. "s+": date.getSeconds(),
  16. "q+": Math.floor((date.getMonth() + 3) / 3),
  17. "S": date.getMilliseconds()
  18. }
  19. if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  20. for (var k in o) {
  21. if (new RegExp("(" + k + ")").test(format)) {
  22. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  23. }
  24. }
  25. return format;
  26. };
  27. // 3、获取指定范围随机时间,依赖方法 getRangeRandomNumber、dateExtendFormat
  28. var getRangeRandomDate=function(date1,date2,format){
  29. var date1ValueOf=new Date(date1).valueOf(),date2ValueOf=new Date(date2).valueOf();
  30. if(isNaN(date1ValueOf)&&isNaN(date2ValueOf)){
  31. date1ValueOf=0;
  32. date2ValueOf=new Date().valueOf();
  33. }
  34. else{
  35. if(isNaN(date1ValueOf))date1ValueOf=0;
  36. if(isNaN(date2ValueOf))date2ValueOf=0;
  37. }
  38. var retDate=new Date(getRangeRandomNumber(Math.abs(date1ValueOf-date2ValueOf)) + Math.min(date1ValueOf,date2ValueOf));
  39. if(format){
  40. retDate=dateExtendFormat(retDate,format);
  41. }
  42. return retDate;
  43. };
  44. // 4、获取随机车牌照
  45. var getRandomLicensePlate=(function f(excludeArr){
  46. if(!Array.isArray(excludeArr))excludeArr=[];
  47. // 生成一个随机车联牌照
  48. var strProvinceShorter="京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川黔滇藏陕甘青宁新港澳台";
  49. var strNumberLetter="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  50. var tempRetLicensePlate=strProvinceShorter[getRangeRandomNumber(strProvinceShorter.length-1)];
  51. for(var i=0;i<6;i++){
  52. tempRetLicensePlate+=strNumberLetter[getRangeRandomNumber(strNumberLetter.length-1)];
  53. }
  54. // 判断这个车联牌照是否存在
  55. if(excludeArr.indexOf(tempRetLicensePlate)>=0){
  56. tempRetLicensePlate = f(excludeArr);
  57. } else {
  58. excludeArr.push(tempRetLicensePlate);
  59. }
  60. return tempRetLicensePlate;
  61. });
  62. // 5.0、获取一个随机汉字
  63. var getChineseCharacter=function(){
  64. return String.fromCharCode(getRangeRandomNumber(parseInt("4E00",16),parseInt("9FA5",16)));
  65. };
  66. // 5.1、获取指定长度的中文字符串
  67. var getCustomChineseCharacters=function(len){
  68. len=isNaN(Number(len))?1:Math.abs(Math.ceil(Number(len)));
  69. var retStr="";
  70. for(var i=0;i<len;i++){
  71. retStr+=getChineseCharacter();
  72. }
  73. return retStr;
  74. };
  75.  
  76. // 插入数据方法
  77. var handleBatchInsertData=function(initConfig){
  78. if(initConfig.formId&&initConfig.formVersion&&Array.isArray(initConfig.source)&&initConfig.source.length){
  79. var tempTrs=[],
  80. tempCreateDate=ISODate(),
  81. tempFormInstaceDataCounter=db.getCollection('FormInstace').find({}).count();
  82. initConfig.source.forEach((formItemObj)=>{
  83. var tempCreateUserIdIndex = Math.floor(Math.random() * GV_CreateUserIds.length);
  84. var tempTr={
  85. _id:(++tempFormInstaceDataCounter).toString(),
  86. FormItems:[],
  87. ExtendData:{},
  88. CreateUserId:GV_CreateUserIds[tempCreateUserIdIndex],
  89. CreateUserName:GV_CreateUserIds[tempCreateUserIdIndex],
  90. CreateDate:tempCreateDate,
  91. LastModifyDate:tempCreateDate,
  92. FormId:initConfig.formId,
  93. FormVersion:initConfig.formVersion
  94. };
  95. for(var i in formItemObj){
  96. if (formItemObj.hasOwnProperty(i)){
  97. tempTr.FormItems.push({key:i,value:formItemObj[i]});
  98. }
  99. }
  100. tempTrs.push(tempTr);
  101. });
  102. try{
  103. db.FormInstace.insertMany(tempTrs);
  104. }catch(e){
  105. print(e);
  106. }
  107. }
  108. };
  109.  
  110. // 创建用户集合
  111. var GV_CreateUserIds = ["user10000","user10001","user10002","user10003","user10004","user10005","user10006","user10007","user10008","user10009"];
  112.  
  113. // 车辆信息表插入数据配置
  114. var GV_CarInfoInitConfig = {
  115. formId:"507048044944691000",
  116. formVersion:"507048044944691001",
  117. carTypes:[
  118. {
  119. brandName:"红旗",
  120. models:[
  121. {name:"HS7",min:349800,max:459800},
  122. {name:"HS5",min:183800,max:249800},
  123. {name:"H7",min:252800,max:317800},
  124. {name:"H5",min:146800,max:190800},
  125. {name:"HE-HS3",min:225800,max:317800}
  126. ]
  127. },
  128. {
  129. brandName:"比亚迪",
  130. models:[
  131. {name:"元",min:65900,max:99900},
  132. {name:"宋",min:79800,max:119800},
  133. {name:"宋Pro",min:89800,max:119800},
  134. {name:"唐",min:129900,max:169900},
  135. {name:"比亚迪F3",min:43900,max:65900},
  136. {name:"速锐",min:59900,max:69900},
  137. {name:"秦Pro",min:79800,max:115900},
  138. {name:"宋MAX",min:79900,max:129900},
  139. {name:"元EV",min:89900,max:139900},
  140. {name:"比亚迪S2",min:89800,max:109800},
  141. {name:"宋DM",min:176900,max:206900},
  142. {name:"宋Pro DM",min:169800,max:259900},
  143. {name:"宋EV",min:189900,max:219900},
  144. {name:"宋Pro EV",min:179800,max:259900},
  145. {name:"唐DM",min:229900,max:329900},
  146. {name:"唐EV",min:259900,max:409900},
  147. {name:"比亚迪e1",min:59900,max:79900},
  148. {name:"比亚迪e2",min:89800,max:119800},
  149. {name:"比亚迪e3",min:103800,max:139800},
  150. {name:"秦DM",min:132900,max:209900},
  151. {name:"秦Pro DM",min:136900,max:206900},
  152. {name:"秦EV",min:149900,max:169900},
  153. {name:"秦Pro EV",min:149900,max:299900},
  154. {name:"宋MAX DM",min:149900,max:196900},
  155. {name:"宋MAX EV",min:179800,max:199800}
  156. ]
  157. },
  158. {
  159. brandName:"奇瑞",
  160. models:[
  161. {name:"瑞虎3",min:59900,max:79900},
  162. {name:"瑞虎3x",min:49900,max:62900},
  163. {name:"瑞虎5x",min:59900,max:89900},
  164. {name:"瑞虎7",min:85900,max:150900},
  165. {name:"瑞虎8",min:88800,max:155900},
  166. {name:"艾瑞泽5",min:49900,max:84900},
  167. {name:"艾瑞泽GX",min:74900,max:113900},
  168. {name:"瑞虎3xe",min:175800,max:189800},
  169. {name:"瑞虎e",min:109900,max:143900},
  170. {name:"奇瑞eQ1",min:59800,max:75800},
  171. {name:"艾瑞泽e",min:126800,max:143800},
  172. {name:"艾瑞泽5e",min:192300,max:212300}
  173. ]
  174. },
  175. {
  176. brandName:"吉利",
  177. models:[
  178. {name:"远景X1",min:39900,max:57900},
  179. {name:"远景X3",min:45900,max:68900},
  180. {name:"缤越",min:78800,max:129800},
  181. {name:"远景S1",min:59900,max:94900},
  182. {name:"远景X6",min:68900,max:105900},
  183. {name:"帝豪GS",min:77800,max:116800},
  184. {name:"博越",min:88800,max:161800},
  185. {name:"星越",min:135800,max:195800},
  186. {name:"金刚",min:47900,max:65900},
  187. {name:"远景",min:47900,max:73900},
  188. {name:"帝豪",min:68900,max:98800},
  189. {name:"帝豪GL",min:78800,max:121800},
  190. {name:"缤瑞",min:75800,max:110800},
  191. {name:"博瑞",min:136800,max:179800},
  192. {name:"嘉际",min:99800,max:148800},
  193. {name:"缤越PHEV",min:149800,max:169800},
  194. {name:"帝豪GSe",min:119800,max:159800},
  195. {name:"星越PHEV",min:188800,max:216800},
  196. {name:"帝豪EV",min:135800,max:238300},
  197. {name:"帝豪PHEV",min:165800,max:185800},
  198. {name:"帝豪GL PHEV",min:152800,max:164800},
  199. {name:"博瑞PHEV",min:176800,max:209800},
  200. {name:"嘉际PHEV",min:169800,max:192800}
  201. ]
  202. },
  203. {
  204. brandName:"长安",
  205. models:[
  206. {name:"长安CS15",min:55900,max:80900},
  207. {name:"长安CS35",min:63900,max:87900},
  208. {name:"长安CS35 PLUS",min:69900,max:109900},
  209. {name:"长安CS55",min:82900,max:133900},
  210. {name:"长安CS75",min:79800,max:174800},
  211. {name:"长安CS75 PLUS",min:106900,max:154900},
  212. {name:"长安CS85 COUPE",min:119900,max:169900},
  213. {name:"长安CS95",min:165900,max:213900},
  214. {name:"奔奔",min:40900,max:56900},
  215. {name:"悦翔",min:49900,max:67900},
  216. {name:"逸动DT",min:52900,max:80900},
  217. {name:"逸动XT",min:77900,max:111900},
  218. {name:"逸动",min:69900,max:103900},
  219. {name:"睿骋CC",min:84900,max:135900},
  220. {name:"锐程CC",min:94900,max:128900},
  221. {name:"睿骋",min:120800,max:150800},
  222. {name:"凌轩",min:67900,max:110900},
  223. {name:"长安CS15 EV",min:89800,max:98800},
  224. {name:"长安CS75 PHEV",min:175800,max:206800},
  225. {name:"奔奔EV",min:49800,max:81800},
  226. {name:"逸动ET",min:132900,max:142900},
  227. {name:"逸动PHEV",min:160900,max:169900},
  228. {name:"逸动EV",min:129900,max:139900},
  229. ]
  230. },
  231. {
  232. brandName:"长安欧尚",
  233. models:[
  234. {name:"长安欧尚科赛3",min:59900,max:76900},
  235. {name:"长安欧尚科赛5",min:69900,max:82900},
  236. {name:"长安欧尚X70A",min:49900,max:859500},
  237. {name:"长安欧尚CX70",min:59900,max:109900},
  238. {name:"长安欧尚科赛",min:86800,max:152800},
  239. {name:"欧尚S",min:39900,max:55900},
  240. {name:"欧尚长行",min:68900,max:82900},
  241. {name:"长安欧尚A600",min:49900,max:84900},
  242. {name:"长安欧尚A800",min:62900,max:100900},
  243. {name:"长安欧尚科尚",min:79800,max:160800},
  244. {name:"长安之星9",min:47800,max:48800},
  245. {name:"长安星卡",min:32900,max:47900},
  246. {name:"尼欧Ⅱ",min:88800,max:100800},
  247. {name:"欧力威EV",min:105800,max:105800},
  248. {name:"欧诺S EV",min:175800,max:175800},
  249. {name:"欧尚长行EV",min:169800,max:169800},
  250. {name:"欧尚EV",min:169800,max:169800},
  251. {name:"欧尚A600 EV",min:149800,max:149800},
  252. {name:"长安之星9 EV",min:152800,max:156000},
  253. {name:"长安星卡EV",min:123800,max:125800},
  254. ]
  255. },
  256. {
  257. brandName:"长安轻型车",
  258. models:[
  259. {name:"睿行S50",min:48900,max:77900},
  260. {name:"睿行S50T",min:61900,max:78900},
  261. {name:"睿行M60",min:51900,max:59900},
  262. {name:"睿行M70",min:60500,max:74000},
  263. {name:"睿行M80",min:58500,max:72000},
  264. {name:"睿行M90",min:68500,max:92500},
  265. {name:"神骐F30",min:47600,max:63800},
  266. {name:"神骐T10",min:39900,max:50900},
  267. {name:"神骐T20",min:33900,max:59700},
  268. {name:"凯程F70",min:92800,max:139800},
  269. {name:"长安星卡L系列",min:39900,max:47900},
  270. {name:"长安星卡C系列",min:30900,max:33600},
  271. {name:"睿行ES30",min:66800,max:69800},
  272. {name:"睿行EM60",min:122800,max:122800},
  273. {name:"睿行EM80",min:96800,max:120000}
  274. ]
  275. },
  276. {
  277. brandName:"长安跨越",
  278. models:[
  279. {name:"长安跨越V3",min:33500,max:34300},
  280. {name:"跨越王X1",min:39600,max:51800},
  281. {name:"跨越王X3",min:45700,max:58400},
  282. {name:"长安跨越王X5",min:47400,max:65600},
  283. {name:"长安新豹2",min:40700,max:58600},
  284. {name:"新豹3",min:46200,max:59900},
  285. {name:"新豹T3",min:41300,max:51800},
  286. {name:"长安新豹MINI",min:32100,max:50500},
  287. {name:"跨越者D5",min:59300,max:67700},
  288. {name:"长安跨越新能源V3 EV",min:79200,max:79200},
  289. {name:"长安跨越新能源V5 EV",min:93800,max:93800}
  290. ]
  291. },
  292. {
  293. brandName:"力帆",
  294. models:[
  295. {name:"迈威",min:56800,max:73800},
  296. {name:"力帆X80",min:109900,max:149900},
  297. {name:"力帆820",min:76800,max:119800},
  298. {name:"轩朗",min:69800,max:106800},
  299. {name:"乐途",min:35800,max:59800},
  300. {name:"力帆650EV",min:168900,max:175800},
  301. {name:"力帆820EV",min:256800,max:279800}
  302. ]
  303. },
  304. {
  305. brandName:"长城",
  306. models:[
  307. {name:"风骏5",min:68800,max:112800},
  308. {name:"风骏6",min:86800,max:117800},
  309. {name:"风骏7",min:86800,max:138800},
  310. {name:"炮",min:97800,max:159800},
  311. {name:"长城C30 EV",min:150000,max:154000}
  312. ]
  313. },
  314. {
  315. brandName:"哈弗",
  316. models:[
  317. {name:"哈弗H2",min:74900,max:95900},
  318. {name:"哈弗H2s",min:70000,max:85000},
  319. {name:"哈弗H4",min:73900,max:115000},
  320. {name:"哈弗F5",min:100000,max:130000},
  321. {name:"哈弗H5",min:107800,max:136800},
  322. {name:"哈弗M6",min:66000,max:82000},
  323. {name:"哈弗H6",min:102000,max:136000},
  324. {name:"哈弗H6 Coupe",min:79900,max:119000},
  325. {name:"哈弗H7",min:142000,max:180000},
  326. {name:"哈弗F7",min:109000,max:153700},
  327. {name:"哈弗F7x",min:119900,max:154900},
  328. {name:"哈弗H9",min:209800,max:272800},
  329. ]
  330. },
  331. {
  332. brandName:"江铃",
  333. models:[
  334. {name:"宝典",min:78800,max:105300},
  335. {name:"凯锐800",min:120800,max:129100},
  336. {name:"凯运强劲版",min:99500,max:117400},
  337. {name:"凯运升级版",min:94800,max:106800},
  338. {name:"顺达宽体",min:90800,max:100000},
  339. {name:"顺达窄体",min:84000,max:89000},
  340. {name:"特顺",min:101300,max:142700},
  341. {name:"域虎3",min:89800,max:122200},
  342. {name:"域虎5",min:96800,max:136300},
  343. {name:"域虎7",min:119800,max:176300},
  344. {name:"江铃E100B",min:73800,max:73800},
  345. {name:"江铃E160",min:95800,max:98800},
  346. {name:"江铃E200L",min:87800,max:90800},
  347. {name:"江铃E200N",min:90800,max:93800},
  348. {name:"易至EV3",min:66800,max:83800},
  349. {name:"易至EX5",min:89800,max:122800},
  350. {name:"特顺EV",min:206000,max:206000},
  351. {name:"骐铃T5",min:65800,max:86800},
  352. {name:"骐铃T7",min:72800,max:113800},
  353. {name:"骐铃T100",min:53800,max:71800},
  354. {name:"D-MAX房车",min:283000,max:396000},
  355. {name:"考斯特房车",min:318000,max:380000},
  356. {name:"旅居房车",min:536000,max:596000},
  357. {name:"罗莎房车租赁款",min:268000,max:288000},
  358. {name:"骐铃T7皮卡房车",min:258000,max:299800},
  359. {name:"全顺商旅房车",min:468000,max:518000},
  360. {name:"全顺T型房车",min:408000,max:448000},
  361. {name:"商旅房车",min:438000,max:488000},
  362. {name:"商旅房车经典款",min:388000,max:428000},
  363. {name:"途睿欧商务车",min:298000,max:398000}
  364. ]
  365. },
  366. ],
  367. source:[]
  368. };
  369.  
  370. var GV_TempCarLicensePlates=[];
  371. GV_CarInfoInitConfig.carTypes.forEach((carType)=>{
  372. if(Array.isArray(carType.models)&&carType.models.length){
  373. carType.models.forEach((model)=>{
  374. for(var i=0;i<getRangeRandomNumber(10,100);i++){
  375. var tempPlate = getRandomLicensePlate(GV_TempCarLicensePlates);
  376. GV_CarInfoInitConfig.source.push({
  377. "1572493551001":carType.brandName,
  378. "1572493551002":model.name,
  379. "1572493551003":tempPlate,
  380. "1572493551004":getRangeRandomDate("2010-01-01","2018-06-06","yyyy-MM-dd HH:mm:ss"),
  381. "1572493551005":getRangeRandomNumber(model.min,model.max),
  382. "1572493551006":getCustomChineseCharacters(getRangeRandomNumber(200))
  383. });
  384. }
  385. });
  386. }
  387. });
  388.  
  389. // 车辆花费表插入数据配置
  390. var GV_CarWastageInitConfig = {
  391. formId:"507048044944692000",
  392. formVersion:"507048044944692001",
  393. wastageType:[
  394. {text:"违章",detailed:["信号灯","压线","单双号","规定方向行驶","避让特殊车辆","避让行人","时间道路禁行"]},
  395. {text:"洗车",detailed:["全套","外围"]},
  396. {text:"修车",detailed:["轮胎","前玻璃","后玻璃","坐垫","前大灯","后大灯","车窗","发动机","电瓶","变速箱"]},
  397. {text:"加油",detailed:["92","93","95","97"]},
  398. {text:"保险",detailed:["太平洋","平安","人保","泰康"]},
  399. {text:"肇事",detailed:["伤人","护栏","撞车","间接事故","其他"]}
  400. ],
  401. source:[]
  402. };
  403.  
  404. // 车辆营收表插入数据配置
  405. var GV_CarRevenueInitConfig = {
  406. formId:"507048044944693000",
  407. formVersion:"507048044944693001",
  408. revenueTypes:[
  409. {text:"租赁",detailed:["一天","一周","一月","一年"]},
  410. {text:"载客",detailed:["线下","滴滴","Uber","快的","其他"]},
  411. {text:"送货",detailed:["手机","笔记本","照相机","微波炉","电磁率","其他"]},
  412. {text:"其他",detailed:["婚车","其他"]}
  413. ],
  414. source:[]
  415. };
  416.  
  417. if(GV_CarInfoInitConfig.source.length){
  418. GV_CarInfoInitConfig.source.forEach((carInfo,carInfoIndex)=>{
  419. for(var i=0;i<getRangeRandomNumber(50,100);i++){
  420. var tempUserIdIndexWastageType = getRangeRandomNumber(GV_CreateUserIds.length-1);
  421. var tempWastageTypeIndex = getRangeRandomNumber(GV_CarWastageInitConfig.wastageType.length-1);
  422. var tempWastageTypeDetailIndex = getRangeRandomNumber(GV_CarWastageInitConfig.wastageType[tempWastageTypeIndex].detailed.length-1);
  423. GV_CarWastageInitConfig.source.push({
  424. "1572493552001": {
  425. id: (carInfoIndex+1).toString(),
  426. name: carInfo["1572493551003"],
  427. value: ""
  428. },
  429. "1572493552002": [{id:GV_CreateUserIds[tempUserIdIndexWastageType],name:GV_CreateUserIds[tempUserIdIndexWastageType],face:""}],
  430. "1572493552003": getRangeRandomDate(carInfo["1572493551004"],"2019-11-07","yyyy-MM-dd HH:mm:ss"),
  431. "1572493552004": GV_CarWastageInitConfig.wastageType[tempWastageTypeIndex].text,
  432. "1572493552005": getRangeRandomNumber(20,10000),
  433. "1572493552006": GV_CarWastageInitConfig.wastageType[tempWastageTypeIndex].detailed[tempWastageTypeDetailIndex]
  434. });
  435. }
  436.  
  437. for(var i=0;i<getRangeRandomNumber(100,200);i++){
  438. var tempUserIdIndexRevenue = getRangeRandomNumber(GV_CreateUserIds.length-1);
  439. var tempRevenueIndex = getRangeRandomNumber(GV_CarRevenueInitConfig.revenueTypes.length-1);
  440. var tempRevenueDetailIndex = getRangeRandomNumber(GV_CarRevenueInitConfig.revenueTypes[tempRevenueIndex].detailed.length-1);
  441. GV_CarRevenueInitConfig.source.push({
  442. "1572493553001": {
  443. id: (carInfoIndex+1).toString(),
  444. name: carInfo["1572493551003"],
  445. value: ""
  446. },
  447. "1572493553002": [{id:GV_CreateUserIds[tempUserIdIndexRevenue],name:GV_CreateUserIds[tempUserIdIndexRevenue],face:""}],
  448. "1572493553003": getRangeRandomDate(carInfo["1572493551004"],"2019-11-07","yyyy-MM-dd HH:mm:ss"),
  449. "1572493553004": GV_CarRevenueInitConfig.revenueTypes[tempRevenueIndex].text,
  450. "1572493553005": getRangeRandomNumber(20,10000),
  451. "1572493553006": getRangeRandomNumber(50,3000),
  452. "1572493553007": GV_CarRevenueInitConfig.revenueTypes[tempRevenueIndex].detailed[tempRevenueDetailIndex]
  453. });
  454. }
  455. });
  456. }
  457.  
  458. handleBatchInsertData(GV_CarInfoInitConfig);
  459. handleBatchInsertData(GV_CarWastageInitConfig);
  460. handleBatchInsertData(GV_CarRevenueInitConfig);

  看一下数据库中的截图

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

表单生成器(Form Builder)之伪造表单数据mongodb篇的更多相关文章

  1. 表单生成器(Form Builder)之伪造表单数据番外篇——随机车辆牌照

    前几天记录了一下表单生成器(Form Builder)之表单数据存储结构mongodb篇,之后便想着伪造一些数据.为什么要伪造数据呢?说来惭愧,因为拖拉拽设计表单以及表单对应的列表的PC端和移动端该显 ...

  2. 表单生成器(Form Builder)之伪造表单数据番外篇——指定范围随机时间

    为了伪造一些尽量真实的假数据,也真是够费劲的.上一篇笔记记录了一下获取一个随机车辆牌照,这篇笔记记录一下怎么获取一个随机时间.这篇就不说那么多废话了,直接上代码 // 获取指定范围的随机数 var g ...

  3. 表单生成器(Form Builder)之表单数据存储结构mongodb篇

    从这篇笔记开始,记录一下表单生成器(Form Builder)相关的一些东西,网上关于他的介绍有很多,这里就不解释了. 开篇说一下如何存储Form Builder生成的数据.

  4. 表单生成器(Form Builder)之mongodb表单数据查询——统计查询求和

    上一篇笔记仅是记录了一下简单的关联查询,根据笔记中的场景:将某一车辆关联的耗损记录全部放在了一个字段当中.不知道现在中有没有这种场景,我们的应用中没有类似的场景,可能我们更关注的是某车辆的总耗损金额和 ...

  5. 表单生成器(Form Builder)之mongodb表单数据查询——关联查询

    这一篇接着记录一下查询相关的操作.想象一下,如果想要在一张表格中展示某些车辆的耗损和营收情况,我们该怎么处理.车辆.耗损.营收各自存储在一张表中,耗损和营收中冗余了车辆信息……我们便想到了关联查询.m ...

  6. 表单生成器(Form Builder)之mongodb表单数据查询——返回分页数据和总条数

    上一篇笔记将开始定义的存储结构处理了一下,将FormItems数组中的表单项都拿到mongodb document的最外层,和以前的关系型数据类似,之不过好多列都是动态的,不固定,不过这并没有什么影响 ...

  7. 表单生成器(Form Builder)之mongodb表单数据——整理数据

    在上篇笔记中,为车辆信息表.车辆耗损表以及车辆营收表插入了一些数据.之后便是查询了,重点也在查询……按照之前定好的数据结构,如果查询mongodb document的最外层比较简单,但是我们的重点应该 ...

  8. Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法

    Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法 昨天在开发的时候遇到个小问题,就是如何将Grid的内容与Form一起发送到服务器端.默认情况下,表单(F ...

  9. 表单组件 form fastadmin(生成表单元素)

    Form组件 定义文件位置: /extend/fast/Formphp 通用参数 $name 通常为我们组件的名称(name属性值),我们在后台接收时可以通过这个名称来获取到它所对应的值 $value ...

随机推荐

  1. C# Pkcs8 1024位 加密 解密 签名 解签

    部分代码来至 https://www.cnblogs.com/dj258/p/6049786.html using System; using System.Collections.Generic; ...

  2. nginx部署基于http负载均衡器

    nginx跨多个应用程序实例的负载平衡是一种用于优化资源利用率,最大化吞吐量,减少延迟和确保容错配置的常用技术. 环境介绍 配置nginx负载均衡器因会用到多台服务器来进行,所以下面我会用到docke ...

  3. 详谈springboot启动类的@SpringBootApplication注解

    前几天我们学会了如何创建springboot项目今天我们说一下他是怎么运行的为什么不需要我们再去编写繁重的配置文件的 @SpringBootApplication 首先我们看一下这个注解,他是用来标注 ...

  4. 【hibernate】存储图片

    [hibernate]存储图片 转载: package cn.ycx.study.hibernate.entity; import javax.persistence.Entity; import j ...

  5. 【Java Web开发学习】Spring环境profile

    [Java Web开发学习]Spring 环境profile 转载:http://www.cnblogs.com/yangchongxing/p/8890702.html 开发.测试.生产环境往往是不 ...

  6. Selenium使用方法整理

    我采用的是Python来使用selenium库,同时java也可以使用,但不如python操作起来方便.下文都会以python的操作为例子,整理我学习selenium过程中收集到的方法. 一:安装 首 ...

  7. 这几种JavaScript语法不要轻易使用,容易出事

    文章目录 12种不宜使用的JavaScript语法 1. == 2. with 3. eval 4. continue 5. switch 贯穿 6. 单行的块结构 7. ++和-- 8. 位运算符 ...

  8. 如何编写一个TS程序?

    第一步:我们首先需要个代码编辑器-VSCode  点击此处下载(你会下载到rar文件) 第二步:我们还需要下载NodeJS,因为这里有npm,npm是包管理工具,可以下载TypeScript. 注意: ...

  9. 【原】MAC安装Flutter

    系统环境要求 Flutter因为是新出的框架,所以对系统还是有一定的要求的. MacOS(64-bit) 磁盘空间:大于700M,如果算上Android Studio等编辑工具,尽量大于3G. 命令号 ...

  10. 每天进步一点点----JS之比较运算符易错点

    1.字符串的比较 字符串也是可以比较的,字符串比较的asc码顺序:asc有128位,由7位二进制数表示,每个数对应的是一个字符.ASC码有ASC码1,由7位二进制1数表示:ASC2码又8位二进制数表示 ...