• 6.0 生成txt、doc文件


    1、生成doc 

    file/generate_doc.js

    1. /**
    2. *
    3. * @description 拼接mysql字段的值,从中随机取值后,生成doc文件
    4. */
    5. const fs = require('fs')
    6. const mysql_config = require('../config/mysql_config')
    7. const {connect, read} = require('../mysql/mysql');
    8. (async () => {
    9. const Mock = require('mockjs')
    10. let Random = Mock.Random
    11. let c = await connect(mysql_config.options)
    12. for (let j = 0; j < 1000; j++) {
    13. let start = j * 1000
    14. let end = (j + 1) * 1000
    15. let sql = `select * from test_data limit ${start},${end}`
    16. let arr = await read(c, sql)
    17. let name = Random.csentence(5, 15).replaceAll('。', '')
    18. for (let i in arr) {
    19. if (arr.hasOwnProperty(i)) {
    20. if (parseInt(i) / 100 % 1 === 0 && parseInt(i) !== 0) {
    21. break
    22. } else {
    23. fs.writeFile(`${name}.doc`, JSON.stringify(arr[i]), {flag: 'a', encoding: 'utf8'}, err => {
    24. if (err) throw err;
    25. console.log('The file has been saved!');
    26. })
    27. }
    28. }
    29. }
    30. }
    31. })()

    2、生成较大的doc

    file/generate_larger_doc.js

    1. /**
    2. *
    3. * @description 拼接mysql字段的值,从中随机取值后,生成size比较大的doc文件
    4. */
    5. const fs = require('fs')
    6. const mysql_config = require('../config/mysql_config')
    7. const {connect, read} = require('../mysql/mysql');
    8. (async () => {
    9. const Mock = require('mockjs')
    10. let Random = Mock.Random
    11. let c = await connect(mysql_config.options)
    12. for (let j = 0; j < 1000; j++) {
    13. let start = j * 1000
    14. let end = (j + 1) * 1000
    15. let sql = `select * from test limit ${start},${end}`
    16. let arr = await read(c, sql)
    17. let name = Random.csentence(5, 15).replaceAll('。', '')
    18. for (let i in arr) {
    19. if (arr.hasOwnProperty(i)) {
    20. if (parseInt(i) / 1000 % 1 === 0 && parseInt(i) !== 0) {
    21. break
    22. } else {
    23. console.log(1)
    24. fs.writeFile(`${name}.doc`, JSON.stringify(arr[i]), {flag: 'a', encoding: 'utf8'}, err => {
    25. if (err) throw err;
    26. console.log('The file has been saved!');
    27. })
    28. }
    29. }
    30. }
    31. }
    32. })()

    3、生成txt

    file/generate_txt.js

    1. /**
    2. *
    3. * @description 拼接mysql字段的值,从中随机取值后,生成txt文件
    4. */
    5. const fs = require('fs')
    6. const mysql_config = require('../config/mysql_config')
    7. const {connect, read} = require('../mysql/mysql');
    8. (async () => {
    9. const Mock = require('mockjs')
    10. let Random = Mock.Random
    11. let c = await connect(mysql_config.options)
    12. for (let j = 0; j < 1000; j++) {
    13. let start = j * 1000
    14. let end = (j + 1) * 1000
    15. let sql = `select * from test limit ${start},${end}`
    16. let arr = await read(c, sql)
    17. let name = Random.csentence(5, 15).replaceAll('。', '')
    18. for (let i in arr) {
    19. if (arr.hasOwnProperty(i)) {
    20. if (parseInt(i) / 100 % 1 === 0 && parseInt(i) !== 0) {
    21. break
    22. } else {
    23. fs.writeFile(`${name}.txt`, JSON.stringify(arr[i]), {flag: 'a'}, err => {
    24. if (err) throw err;
    25. console.log('The file has been saved!');
    26. })
    27. }
    28. }
    29. }
    30. }
    31. })()

    4、config/mysql_config.js

    1. module.exports = {
    2. options: {
    3. host: 'vm-mysql57.lan',
    4. user: 'root',
    5. password: 'wlh123456',
    6. database: 'data_jimi',
    7. insert_file: {
    8. table: 'file',
    9. path: 'D:\\target',
    10. field1: 'content',
    11. field2: 'filename'
    12. }
    13. },
    14. sql_group: {
    15. es_sql: 'select * from test limit 50000,50600',
    16. hbase_sql: '',
    17. mongo_sql: '',
    18. neo4j_sql: '',
    19. redis_sql: ''
    20. }
    21. }

  • 相关阅读:
    HTML+CSS+JS网页设计期末课程大作业____(航天月球响应式 3页)
    PaddleSeg (2) 模型训练
    202. 快乐数
    0基础可以转行编程行业么
    智慧水利数字孪生案例分享:数字孪生水利,助力三峡科学防洪防汛
    MySQL 5.7 安装教程(全步骤、保姆级教程)
    Unsatisfied dependency expressed through bean property ‘sqlSessionTemplate‘;
    Python日期和时间库datetime
    结合行人检测与单应性变换的安全社交距离估计
    [hive] 窗口函数 ROW_NUMBER()
  • 原文地址:https://blog.csdn.net/LetsStudy/article/details/127773030