{"_id":"wanke-bff-share","_rev":"33-daa1a32ef103fda190249372bcd6d991","time":{"2.0.0":"2020-07-23T13:51:24.533Z","2.0.1":"2020-07-23T13:51:24.533Z","2.0.10":"2020-07-23T13:51:24.533Z","2.0.2":"2020-07-23T13:51:24.533Z","2.0.3":"2020-07-23T13:51:24.533Z","2.0.4":"2020-07-23T13:51:24.533Z","2.0.5":"2020-07-23T13:51:24.533Z","2.0.6":"2020-07-23T13:51:24.533Z","2.0.7":"2020-07-23T13:51:24.533Z","2.0.8":"2020-07-23T13:51:24.533Z","2.0.9":"2020-07-23T13:51:24.533Z","created":"2020-12-28T06:23:31.046Z","1.1.28":"2020-12-28T06:23:31.249Z","modified":"2022-05-24T01:11:20.567Z"},"name":"wanke-bff-share","dist-tags":{"latest":"1.1.28"},"versions":{"1.1.28":{"name":"wanke-bff-share","version":"1.1.28","description":"wanke bff public share","main":"dist/src/index.js","types":"dist/src/index.d.ts","scripts":{"build":"node ./util/build.js","start":"node ./dist/src/start.js","test":"echo \"Error: no test specified\" && exit 1","start-dev":"nodemon --config \"./util/nodemon.json\"","doc":"apidoc -i src/routes/ -o src/public/apidoc","release":"node ./util/build.js && npm publish"},"apidoc":{"name":"wanke-bff-share-doc","version":"0.0.0","description":"node api document","title":"wanke-bff-share-doc","sampleUrl":"http://localhost:8081","preview-url":"http://localhost:8081/apidoc","order":[]},"keywords":["wanke","bff","share"],"repository":{"type":"git","url":"git+https://github.com/shufengdong/wanke-bff-common.git"},"bugs":{"url":"https://github.com/shufengdong/wanke-bff-common/issues"},"homepage":"https://github.com/shufengdong/wanke-bff-common/README.md","devDependencies":{"@babel/core":"7.9.0","@types/dotenv":"6.1.1","@types/express":"4.17.1","@types/express-serve-static-core":"4.16.11","@types/find":"0.2.1","@types/graphql":"14.5.0","@types/http-errors":"1.6.3","@types/jsonfile":"5.0.0","@types/lodash":"4.14.157","@types/mocha":"5.2.7","@types/morgan":"1.9.0","@types/node":"12.12.30","@types/request":"2.48.4","@types/should":"13.0.0","@types/supertest":"2.0.8","@typescript-eslint/eslint-plugin":"2.24.0","@typescript-eslint/parser":"2.24.0","babel":"6.23.0","babel-core":"6.26.3","babel-loader":"8.0.6","babel-preset-stage-0":"6.24.1","eslint":"6.8.0","fs-extra":"9.0.1","http-errors":"1.8.0","jest":"25.5.0","nodemon":"1.19.4","pre-commit":"1.2.2","ts-node":"8.9.1","tsconfig-paths":"3.9.0","typescript":"3.8.3","webpack":"4.42.0","webpack-cli":"3.3.11"},"author":{"name":"zhenghan2018@gmail.com"},"license":"ISC","dependencies":{"connect-multiparty":"^2.2.0","eureka-js-client":"4.3.0","express":"^4.17.1","form-data":"^3.0.0","graphql":"^15.2.0","json2csv":"5.0.1","loadsh":"0.0.4","log4js":"^6.3.0","moment":"2.27.0","qr-image":"3.2.0","request":"2.88.2","svg-captcha":"^1.4.0","tslib":"^2.0.0","ws":"^7.3.1"},"gitHead":"e90c0fe946df352267b34186b365de5a37171bda","_id":"wanke-bff-share@1.1.28","_nodeVersion":"12.19.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-RezZL/dDD+FJIz7A93QuycqvguxonQAfvO35LUZFVcTk0rC/SdGrbemZ/LL6wQmsKoXoh6TraNNQZOqNRFkWEQ==","shasum":"b64902c951e5282d2adb732810b217f57787f1d2","tarball":"https://registry.npmjs.org/wanke-bff-share/-/wanke-bff-share-1.1.28.tgz","fileCount":508,"unpackedSize":1118408,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf6XnjCRA9TVsSAnZWagAA8FYP+wf/oGLBJ99P7pQsTJHF\n3k8Q/RkFi8VTSAd8ZnB42yn+UMlmvRYdEO9fwhs4eAx6lnVIONjcTWBpZG1l\nM9+RS2QA5MEgBP96Z9xmJFznzOt+T4duKWmd8XoEWFFT2c4MvnYwoC08tUdK\nbo+2nMKa39eE66guie0BYZZTyWJI6rRnWnp/zNuPadCyhoCNTU9yu6rvELHq\nE7DmZMi7RWshaN3QxbXYr5ToSgRGX6pzNrwax9FvyQJMN5hyH9v3XXNn2P5c\nXT92E7p2sCCPKW+XogMRzD+/aDk5dQ9uqtqq3NeKhXSLcSiPxPXTBFO0+Oik\ntovuU1e/1PpdCfpafiUJGY0c9ny6Cszsk5V88ICSLxccvWtn0SIcqj4/KzLA\n3bgS8xJASl998teya4kMr9y0pD7GcpyZoNQ2RtibszXDjFH936bpcdkmpVVD\n2wPMH+OrYmSxtqkbeiLhXF4gklb62OFNRCNssz4+3qxCo1ZYXKnfA0L8fR3o\nvMvqZqQou9PAyy0ThgcB5SxSwr/p5ExLJqY/f1ZmQi2HwdBbutGBKTBi3H2j\nsu4I9Id7XlqOP0bdmw+fHVP4vZ0EDkRw8hbUxbsIh6e5POJJAK5oFIpe7pmI\n94mGs6lOEJcnbS2AygiBJKDFU3OyvTPZlQct06KVSs0/wfeBqs32QtC6h8WN\nayF4\r\n=A8op\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZ7mm2q6q0CAgDH83g4v5k3K1W5BBEPubw3Rn08d0qQAIgG8JvxA2KWX0XZvQ4iqinSheldIf/ubw9aLrmEVQUWWQ="}]},"_npmUser":{"name":"wanke2022","email":"jiangyukun@wankeauto.com"},"directories":{},"maintainers":[{"name":"wanke2022","email":"jiangyukun@wankeauto.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wanke-bff-share_1.1.28_1609136611046_0.2013964173522267"},"_hasShrinkwrap":false}},"maintainers":[{"name":"wanke2022","email":"jiangyukun@wankeauto.com"}],"description":"wanke bff public share","homepage":"https://github.com/shufengdong/wanke-bff-common/README.md","keywords":["wanke","bff","share"],"repository":{"type":"git","url":"git+https://github.com/shufengdong/wanke-bff-common.git"},"author":{"name":"zhenghan2018@gmail.com"},"bugs":{"url":"https://github.com/shufengdong/wanke-bff-common/issues"},"license":"ISC","readme":"# wank-bff-share（万克中间层公用部分）\r\n\r\n* [wank-bff-share](#wank-bff-share（万克中间层公用部分）)\r\n  * [约定](#约定)\r\n  * [configs](#configs（通用配置项部分）)\r\n    * [configResource](#configResource.json（通用枚举查询配置项）)\r\n    * [configTranslationEN](#configTranslationEN（国际化-英文翻译配置项）)\r\n    * [configTranslationZH](#configTranslationZH（国际化-中文翻译配置项）)\r\n  * [handlers](#handlers（通用基础方法）)\r\n    * [baseHandler](#baseHandler（基础处理方法）)\r\n      * [cloneObj](#cloneObj)\r\n      * [flatTreeToArray](#flatTreeToArray)\r\n      * [fixDigits](#fixDigits)\r\n      * [filterTree](#filterTree)\r\n      * [streamToBuffer](#streamToBuffer)\r\n      * [judgeKeyIsExist](#judgeKeyIsExist)\r\n      * [getUniqueId](#getUniqueId)\r\n      * [judgeEmpty](#judgeEmpty)\r\n      * [judgeAbnormalResp](#judgeAbnormalResp)\r\n      * [jsonToCsv](#jsonToCsv)\r\n      * [getPropertyFromOrigin](#getPropertyFromOrigin)\r\n      * [__cutoutProperty](#__cutoutProperty)\r\n    * [frontHander](#frontHandler（前端处理方法）)\r\n      * [setPageToTarget](#setPageToTarget)\r\n      * [runMonthToStr](#runMonthToStr)\r\n      * [setUniqueId](#setUniqueId)\r\n      * [echartDataGenerator](#echartDataGenerator)\r\n      * [addNum](#addNum)\r\n      * [mixArrToObj](#mixArrToObj)\r\n      * [getParamLost](#getParamLost)\r\n      * [qrCodeGener](#qrCodeGener)\r\n      * [getCategoryType](#getCategoryType)\r\n      * [conversionUnit](#conversionUnit)\r\n      * [getBaseResp](#getBaseResp)\r\n      * [getScaleUnitAndPowerUnit](#getScaleUnitAndPowerUnit)\r\n    * [requestHandler](#requestHandler（请求处理方法）)\r\n      * [getApiBaseUrl](#getApiBaseUrl)\r\n      * [joinUrl](#joinUrl)\r\n      * [requestPromise](#requestPromise)\r\n      * [responseHandle](#responseHandle)\r\n      * [judgeAbnormalResp](#judgeAbnormalResp)\r\n    * [timeHandler](#timeHandler（时间处理方法）)\r\n      * [checkDateFormat](#checkDateFormat)\r\n      * [__existDate](#__existDate)\r\n      * [getFormatTimeObj](#getFormatTimeObj)\r\n      * [getDateAfterCalculate](#getDateAfterCalculate)\r\n      * [getCertainMonthDays](#getCertainMonthDays)\r\n      * [getDaysByArgs](#getDaysByArgs)\r\n      * [getTimePoint](#getTimePoint)\r\n      * [getMonthBetween](#getMonthBetween)\r\n      * [getTimePointInterval](#getTimePointInterval)\r\n      * [msToDate](#msToDate)\r\n      * [splicingDate](#splicingDate)\r\n      * [__timeToMoment](#__timeToMoment)\r\n      * [transfromTimeFormat](#transfromTimeFormat)\r\n      * [judgeIsBetween](#judgeIsBetween)\r\n      * [getTimeIntervalByMoment](#getTimeIntervalByMoment)\r\n      * [msToDisplay](#msToDisplay)\r\n  * [接口开发流程](#接口开发流程)\r\n\r\n---\r\n\r\n## 约定\r\n\r\n1. route层书写的graphQlQuery外层包装属性为results\r\n2. models层书写函数时，函数命名按照请求方式+资源名的形式，例：getUsers,postUser,patchUser,putUser,deleteUser,getUserById\r\n3. 参数中Array类型的参数后缀用List代表，例：idList，typeList等\r\n4. models中的参数类型命名规范，基础资源返回I + 资源名（IUser）,函数参数按I + 方法名定义（IPostUsers）\r\n5. 编写models中的graphTypeDefine文件时，如果类型为数组格式，区分数组格式还是对象格式，则命名中应加List，例：AlarmEventType, AlarmEventListType\r\n6. route层引入模块命名按模块文件名+模块功能+s（usersModels，baseHandlers）\r\n7. 常量命名全部大写，多单词按下划线间隔\r\n8. 查询某类资源详情，修改，删除，路由命名按:id的形式，例（/users/:id),查询该资源的某类关系也一样，例（users/:id/stations)\r\n9. 请求方式规范尽量参照RESTful风格\r\n10. routes文件命名采用脊柱风格\r\n11. 其他文件采用驼峰命名\r\n\r\n## configs（通用配置项部分）\r\n\r\n调用方式：share.configs.XXX\r\n\r\n### configResource.json（通用枚举查询配置项）\r\n\r\n 使用示例\r\n\r\n```\r\n{\r\n    \"负荷单元\": \"loadUnit\",\r\n    \"匹配参数\": {\r\n        \"stationId\": \"电站Id\"\r\n    }\r\n},\r\n```\r\n\r\n以上配置代表可以查询loadUnit的枚举值，可过滤的参数为stationId\r\n增加通用枚举只需在models里增加对应的方法和在该配置项里写出，让前端通过/enums?resource=XXX的格式即可\r\n\r\n### configTranslationEN（国际化-英文翻译配置项）\r\n\r\n### configTranslationZH（国际化-中文翻译配置项）\r\n\r\n---\r\n\r\n## handlers（通用基础方法）\r\n\r\n调用方式：share.handlers.XXX\r\n\r\n### baseHandler（基础方法）\r\n\r\n#### cloneObj\r\n\r\n**描述：**\r\ncloneObj()方法克隆传入的对象，并返回该对象的新的引用\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst origin = { a: 1 };\r\nconst new1 = origin;\r\nconst new2 = cloneObj(origin);\r\n\r\norigin.a = 2;\r\n\r\nconsole.log(new1);\r\n// { a: 2 }\r\nconsole.log(new2);\r\n// { a: 1 }\r\n```\r\n\r\n**语法：**\r\n`const newReference = baseHandler.cloneObj(origin)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| origin   | any  |  true   | 无 |\r\n\r\n**返回值：**\r\n入参对象的新引用\r\n\r\n---\r\n\r\n#### flatTreeToArray\r\n**描述：**\r\nflatTreeToArray()方法将传入的树型结构数据扁平化，并返回扁平化后的数组结构\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst children = {\r\n  a: 1,\r\n  children: [{\r\n    b: 2,\r\n    c: 3,\r\n    children: []\r\n  }, {\r\n    d: 4,\r\n    children: []\r\n  }],\r\n};\r\n\r\nconst child = {\r\n  a: 1,\r\n  child: [{\r\n    b: 2,\r\n    c: 3,\r\n    child: []\r\n  }, {\r\n    d: 4,\r\n    child: []\r\n  }],\r\n};\r\n\r\nconst childrenArr = flatTreeToArray(children);\r\nconsole.log(childrenArr);\r\n// [ { a: 1 }, { b: 2, c: 3 }, { d: 4 } ]\r\n\r\nconst childrenArr1 = flatTreeToArray(children, 'child');\r\nconsole.log(childrenArr1);\r\n// 返回children对象本身\r\n\r\nconst childArr = flatTreeToArray(child, 'child');\r\nconsole.log(childArr);\r\n// [ { a: 1 }, { b: 2, c: 3 }, { d: 4 } ]\r\n```\r\n\r\n**语法：**\r\n`const flatArr = baseHandler.flatTreeToArray(treeData, flatProperty)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| treeData | object  |  true   | 无 |\r\n| flatProperty | string | false | children |\r\n**返回值：**\r\n树形结构数据扁平化后的数组，每一项的值为树形结构每一层的对象\r\n\r\n---\r\n\r\n#### fixDigits\r\n**描述：**\r\nfixDigits()方法将传入的数据四舍五入后保留一定位数，并返回处理后的结果\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(fixDigits(100.124135));\r\n// 100.12\r\nconsole.log(fixDigits(0.1235425));\r\n// 0.12\r\nconsole.log(fixDigits(100.124135, 4));\r\n// 100.1241\r\nconsole.log(fixDigits(0));\r\n// 0\r\nconsole.log(fixDigits(0, 2, true));\r\n// 0.00\r\n```\r\n\r\n**语法：**\r\n`const valueStr = baseHandler.fixDigits(target, digits, isMandatoryDigits)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| target | Number  |  true   | 无 |\r\n| digits | Number | true | 2 |\r\n| isMandatoryDigits | Boolean | true | false |\r\n**返回值：**\r\n经过处理后的字符串\r\n\r\n---\r\n\r\n#### filterTree\r\n**描述：**\r\nfilterTree()方法根据传入的filter方法过滤根节点下的子树，并返回新树\r\n\r\nTips：根节点暂未进行过滤\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst tree = {\r\n  name: 'john',\r\n  age: 50,\r\n  children: [{\r\n    name: 'john-son1',\r\n    age: 18\r\n  }, {\r\n    name: 'john-son2',\r\n    age: 15\r\n  }, {\r\n    name: 'john-daughter1',\r\n    age: 18\r\n  }]\r\n};\r\n\r\nconst filter = node => node.age === 15;\r\nconst newTree = filterTree(tree.children, filter);\r\nconsole.log(newTree);\r\n// [{\r\n//   name: 'john-son1',\r\n//   age: 18\r\n// }, {\r\n//   name: 'john-daughter1',\r\n//   age: 18\r\n// }]\r\n```\r\n\r\n**语法：**\r\n`const newChildrenTree = baseHandler.filterTree(treeChildren, filter)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| treeChildren | any[]  |  true   | 无 |\r\n| filter | function | true | 无 |\r\n**返回值：**\r\n过滤后的新树\r\n\r\n---\r\n\r\n#### streamToBuffer\r\n**描述：**\r\nstreamToBuffer()方法将可读流对象转换，并返回一个Buffer对象\r\n\r\n**方法 demo:**\r\n\r\n```\r\n这个比较抽象，输出也看不出含义，大家按照功能描述使用即可\r\n```\r\n\r\n**语法：**\r\n`const buffer = baseHandler.streamToBuffer(stream)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| stream | any  |  true   | 无 |\r\n**返回值：**\r\n转换后的buffer对象\r\n\r\n---\r\n\r\n#### judgeKeyIsExist\r\n**描述：**\r\njudgeKeyIsExist()方法将遍历传入的对象，判断是否含有必要的键值，只要非undefined都认为存在，并返回一个缺失的属性数组，如果必要属性都存在，返回一个空数组\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst origin = {\r\n  a: 1,\r\n  b: 2,\r\n  c: 3\r\n};\r\n\r\nconsole.log(judgeKeyIsExist(origin, ['a', 'b']));\r\n// []\r\n\r\nconsole.log(judgeKeyIsExist(origin, ['a', 'b', 'd']));\r\n// [ 'd' ]\r\n```\r\n\r\n**语法：**\r\n`const losts = baseHandler.judgeKeyIsExist(origin, requestKey)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| origin | object  |  true   | 无 |\r\n| requestKey | string[] | true | 无 |\r\n**返回值：**\r\n缺失键值的数组\r\n\r\n---\r\n\r\n#### getUniqueId\r\n**描述：**\r\ngetUniqueId()方法获取uid，返回一个uid\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst uid = getUniqueId();\r\nconst uid2 = getUniqueId();\r\n\r\nconsole.log(uid);\r\n// js/4ed1_9d51\r\nconsole.log(uid2);\r\n// js/4c07_82a1\r\n```\r\n\r\n**语法：**\r\n`const uid = baseHandler.getUniqueId()`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n**返回值：**\r\nuid\r\n\r\n---\r\n\r\n#### judgeEmpty\r\n**描述：**\r\njudgeEmpty()方法判断字段是否为空，并返回一个布尔值\r\n空值包括undefined,null,空串，null的字符串\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst origin = {\r\n  b: null,\r\n  c: '',\r\n  d: 'null',\r\n  e: 0,\r\n};\r\n\r\nconsole.log(judgeEmpty(origin.a));\r\n// true\r\n\r\nconsole.log(judgeEmpty(origin.b));\r\n// true\r\n\r\nconsole.log(judgeEmpty(origin.c));\r\n// true\r\n\r\nconsole.log(judgeEmpty(origin.d));\r\n// true\r\n\r\nconsole.log(judgeEmpty(origin.e));\r\n// false\r\n```\r\n\r\n**语法：**\r\n`const isEmpty = baseHandler.judgeEmpty(property)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| property | any | true | 无 |\r\n**返回值：**\r\n根据是否为给定的假值返回一个布尔值\r\n\r\n---\r\n\r\n#### jsonToCsv\r\n**描述：**\r\njsonToCsv()方法是对第三方库json2csv的parseAsync函数的包装，将json文件转为csv格式数据\r\n\r\n**方法 demo:**\r\n\r\n```\r\n具体使用可查询第三方库json2csv，参数与第三方库一致\r\nGithub链接：https://github.com/zemirco/json2csv\r\n```\r\n\r\n**语法：**\r\n`const csvData = baseHandler.jsonToCsv(data, opts)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| data | array | true | 无 |\r\n| opts | object | true | 无 |\r\n\r\noptions参数：查看具体第三方库链接\r\n**返回值：**\r\n转换后的csv格式数据\r\n\r\n---\r\n\r\n#### getPropertyFromOrigin\r\n**描述：**\r\ngetPropertyFromOrigin()方法从传入的方法中获取对应的属性，如没有对应属性则只为null\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst objOrigin = {\r\n  id: 1,\r\n  name: 'hans',\r\n  title: 'HANS',\r\n};\r\n\r\nconst arrOrigin = [{\r\n  id: 1,\r\n  name: 'hans',\r\n  title: 'HANS',\r\n}, {\r\n  id: 2,\r\n  name: 'john',\r\n  title: 'JOHN'\r\n}];\r\n\r\nconst objData = getPropertyFromOrigin(objOrigin);\r\nconsole.log(objData);\r\n// { name: 'HANS', value: 1 }\r\n\r\nconst objData2 = getPropertyFromOrigin(objOrigin, { name: 'name', title: 'title', age: 'age' });\r\nconsole.log(objData2);\r\n// { name: 'hans', title: 'HANS', age: null }\r\n\r\nconst arrData = getPropertyFromOrigin(arrOrigin);\r\nconsole.log(arrData);\r\n// [ { name: 'HANS', value: 1 }, { name: 'JOHN', value: 2 } ]\r\n```\r\n\r\n**语法：**\r\n`const data = baseHandler.getPropertyFromOrigin(origin, propertyMap)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| origin | any | true | 无 |\r\n| propertyMap | object | true | { name: 'title', value: 'id' } |\r\n\r\n**返回值：**\r\n根据propertyMap中的对应关系转换后的数据\r\n\r\n---\r\n\r\n#### __cutoutProperty\r\n**描述：**\r\n__cutoutProperty()方法是对GraphQL的裁剪的封装，返回裁剪后的数据\r\n\r\n**方法 demo:**\r\n\r\n```\r\n具体见使用端\r\n```\r\n\r\n**语法：**\r\n`const results = baseHandler.__cutoutProperty(type, resolve, graphqlQuery, catchGraphQlError)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| type | GraphQLObjectType | true | 无 |\r\n| resolve | any | true | 无 |\r\n| graphqlQuery | string | true | 无 |\r\n| catchGraphQlError | function | true | (error: ReadonlyArray<GraphQLError>) => console.log(error) |\r\n\r\n**返回值：**\r\n截取后的数据\r\n\r\n---\r\n\r\n### frontHandler（前端处理方法）\r\n\r\n#### setPageToTarget\r\n**描述：**\r\nsetPageToTarget()方法将后端返回的分页属性赋值给中间层返回对象上,主要使用为中间层返回分页参数的层级和后台不一致，进行统一处理，会修改传入的target对象\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst origin = {\r\n  page: 1,\r\n  size: 20,\r\n  totalCount: 2,\r\n  totalPages: 1\r\n};\r\n\r\nconst target = {};\r\nsetPageToTarget(origin, target);\r\nconsole.log(target);\r\n// { page: 1, size: 20, totalCount: 2, totalPages: 1 }\r\n```\r\n\r\n**语法：**\r\n`baseHandler.setPageToTarget(origin, target)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| origin | object | true | 无 |\r\n| target | object | true | 无 |\r\n\r\n**返回值：**\r\n无返回值\r\n\r\n---\r\n\r\n#### runMonthToStr\r\n**描述：**\r\nrunMonthToStr()方法将后端返回的适用月份字符串改为前端适合的字符串显示,如果有连续数字则转换为start~end格式，具体见方法demo,并返回对象本身\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(runMonthToStr({ runMonth: '1,2,4,6' }));\r\n// { runMonth: '1,2,4,6', runMonthTitle: '1~2,4,6' }\r\n\r\nconsole.log(runMonthToStr({ runMonth: '1,2,3,4,5,6,7,8,9,10' }));\r\n// { runMonth: '1,2,3,4,5,6,7,8,9,10', runMonthTitle: '1~10' }\r\n```\r\n\r\n**语法：**\r\n`frontHandler.runMonthToStr(origin)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| origin | object | true | 无 |\r\n\r\n**返回值：**\r\n传入的对象本身，增加了runMonthTitle字段\r\n\r\n---\r\n\r\n#### setUniqueId\r\n**描述：**\r\nsetUniqueId()方法为后端返回树结构数据添加唯一标识，并返回添加后的树形数据,会修改原对象\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst origin = {\r\n  a: 1,\r\n  children: [{\r\n    b: 1,\r\n    children: [{\r\n      d: 1\r\n    }]\r\n  }, {\r\n    c: 1\r\n  }]\r\n};\r\n\r\nsetUniqueId(origin);\r\n\r\nconsole.log(origin);\r\n// {\r\n//   a: 1,\r\n//   key: '0',\r\n//   children: [{\r\n//     b: 1,\r\n//     key: '0-0'\r\n//     children: [{\r\n//       d: 1\r\n//       key: '0-0-0'\r\n//     }]\r\n//   }, {\r\n//     c: 1,\r\n//     key: '0-1'\r\n//   }]\r\n// }\r\n\r\nsetUniqueId(origin, '1');\r\n\r\nconsole.log(origin);\r\n// {\r\n//   a: 1,\r\n//   key: '1',\r\n//   children: [{\r\n//     b: 1,\r\n//     key: '1-0'\r\n//     children: [{\r\n//       d: 1\r\n//       key: '1-0-0'\r\n//     }]\r\n//   }, {\r\n//     c: 1,\r\n//     key: '1-1'\r\n//   }]\r\n// }\r\n```\r\n\r\n**语法：**\r\n`frontHandler.setUniqueId(tree, key)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| tree | object | true | 无 |\r\n| key | string | true | 空串 |\r\n\r\n**返回值：**\r\n增加标识后的树形结构\r\n\r\n---\r\n\r\n#### echartDataGenerator\r\n**描述：**\r\nechartDataGenerator()方法为了前端展示需要，将按传入的参数生成固定间隔的时间轴数据，后端数据传入时，相同时间的数据将对应到具体时间，并返回xData和yData\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst baseData = [{\r\n  dtime: '2020-06-29 00:00:00',\r\n  val: 1\r\n}, {\r\n  dtime: '2020-06-29 00:15:00',\r\n  val: 2\r\n}, {\r\n  dtime: '2020-06-29 00:30:00',\r\n  val: 3\r\n}];\r\n\r\n// 无数据生成x轴，默认参数\r\nconst echarts = echartDataGenerator([], '2020-06-29 00:00:00', '2020-06-29 00:30:00');\r\nconsole.log(echarts);\r\n// {\r\n//    xData:\r\n//      [ '2020-06-29 00:00:00',\r\n//      '2020-06-29 00:15:00',\r\n//      '2020-06-29 00:30:00' ],\r\n//    yData:\r\n//      [ null, null, null ]\r\n// }\r\n\r\n// 无数据生成x轴，按指定参数生成\r\nconst echarts2 = echartDataGenerator([], '2020-06-29 00:00:00', '2020-06-29 00:10:00', 'minute', 1);\r\nconsole.log(echarts2);\r\n// { xData:\r\n//     [ '2020-06-29 00:00:00',\r\n//       '2020-06-29 00:01:00',\r\n//       '2020-06-29 00:02:00',\r\n//       '2020-06-29 00:03:00',\r\n//       '2020-06-29 00:04:00',\r\n//       '2020-06-29 00:05:00',\r\n//       '2020-06-29 00:06:00',\r\n//       '2020-06-29 00:07:00',\r\n//       '2020-06-29 00:08:00',\r\n//       '2020-06-29 00:09:00',\r\n//       '2020-06-29 00:10:00' ],\r\n//  yData:\r\n//     [ null, null, null, null, null, null, null, null, null, null, null ]\r\n// }\r\n\r\n// 数据赋值\r\nconst echarts3 = echartDataGenerator(baseData, '2020-06-29 00:00:00', '2020-06-29 00:30:00');\r\nconsole.log(echarts3);\r\n// {\r\n//   xData:\r\n//     ['2020-06-29 00:00:00',\r\n//       '2020-06-29 00:15:00',\r\n//       '2020-06-29 00:30:00'],\r\n//   yData:\r\n//     ['1', '2', '3']\r\n// }\r\n```\r\n\r\n**语法：**\r\n`const echarts = frontHandler.echartDataGenerator(results, startTime, endTime, timeType, timeInterval, fix, withTime)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| results | { dtime: string, val: number }[] | true | 无 |\r\n| startDate | string | true | 无 |\r\n| endDate | string | true | 无 |\r\n| timeType | string | true | 'minute' |\r\n| timeInterval | number | true | 15 |\r\n| fix | number | true | 2 |\r\n| withTime | boolean | true | true |\r\n\r\n**返回值：**\r\n返回一个包含xData和yData属性的对象\r\n\r\n---\r\n\r\n#### addNum\r\n**描述：**\r\naddNum()方法为了前端展示需要，列表展示需要序号，统一添加序号，支持分页参数，并返回添加后的数据，会修改原数组,如果数据为空，则返回空数组\r\n\r\n**方法 demo:**\r\n\r\n```\r\nlet arr = [{\r\n  name: 'hans'\r\n}, {\r\n  name: 'john'\r\n}];\r\n\r\narr = addNum(arr);\r\nconsole.log(arr);\r\n// [ { name: 'hans', num: 1 }, { name: 'john', num: 2 } ]\r\n\r\narr = addNum(arr, 2, 10);\r\nconsole.log(arr);\r\n// [ { name: 'hans', num: 11 }, { name: 'john', num: 12 } ]\r\n```\r\n\r\n**语法：**\r\n`frontHandler.addNum(target, page, size)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| target | any[] | true | 无 |\r\n| page | number | false | 无 |\r\n| size | number | false | 无 |\r\n\r\n**返回值：**\r\n返回添加后的对象本身或空数组\r\n\r\n---\r\n\r\n#### mixArrToObj\r\n**描述：**\r\nmixArrToObj()方法为了将后端返回的多个数据数组拼接到一个对象数组中,dataArr,typeArr,unitArr数组的长度应保持一致，存在对应关系,startIndex为返回对象中num属性的起始数字，digits为dataArr中数据保留位数\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst dataArr = [\r\n  [{ dtime: '2020-06-30 00:00:00', val: 1.1345 }, { dtime: '2020-06-30 00:15:00', val: 4.1345 }],\r\n  [{ dtime: '2020-06-30 00:00:00', val: 2.1345 }, { dtime: '2020-06-30 00:15:00', val: 5.1345 }],\r\n  [{ dtime: '2020-06-30 00:00:00', val: 3.1345 }, { dtime: '2020-06-30 00:15:00', val: 6.1345 }],\r\n];\r\nconst typeArr = ['a', 'b', 'c'];\r\nconst unitArr = ['V', 'V', 'V'];\r\nconst fixArr = mixArrToObj(dataArr, typeArr, unitArr, 1, 3);\r\n\r\nconsole.log(fixArr);\r\n// [\r\n//   {\r\n//     num: 1,\r\n//     dtime: '2020-06-30 00:00:00',\r\n//     a: '1.135V',\r\n//     b: '2.135V',\r\n//     c: '3.135V'\r\n//   },\r\n//   {\r\n//     num: 2,\r\n//     dtime: '2020-06-30 00:15:00',\r\n//     a: '4.135V',\r\n//     b: '5.135V',\r\n//     c: '6.135V'\r\n//   }\r\n// ]\r\n```\r\n\r\n**语法：**\r\n`const fixArr = frontHandler.mixArrToObj(dataArr, typeArr, unitArr, startIndex, digits)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| dataArr | any[] | true | 无 |\r\n| typeArr | string[] | true | 无 |\r\n| unitArr | string[] | true | 无 |\r\n| startIndex | number | true | 1 |\r\n| digits | number | true | 2 |\r\n\r\n**返回值：**\r\ndataArr数据混合后的对象数组\r\n\r\n---\r\n\r\n#### getParamLost\r\n**描述：**\r\ngetParamLost()方法获取参数缺失，与baseHandler中的judgeKeyIsExist配套使用，用于检验请求参数的校验，并返回一个参数缺失对象，如果不存在缺失返回null\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst isNull = getParamLost([]);\r\nconsole.log(isNull);\r\n// null\r\n\r\nconst isLost = getParamLost(['a']);\r\nconsole.log(isLost);\r\n// { errorCode: 52, errorMsg: '参数缺失a' }\r\n```\r\n\r\n**语法：**\r\n`const isLost = frontHandler.getParamLost(losts)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| losts | string[] | true | 无 |\r\n\r\n**返回值：**\r\n参数缺失对象或者null\r\n\r\n---\r\n\r\n#### qrCodeGener\r\n**描述：**\r\nqrCodeGener()方法生成二维码，供APP扫码使用。\r\n采用第三方库[qr-image](#https://github.com/alexeyten/qr-image)生成，并返回一个buffer对象,\r\n使用参数语法可参考第三方库\r\n\r\n**方法 demo:**\r\n\r\n```\r\n这个比较抽象，输出也看不出含义，大家按照功能描述使用即可\r\n```\r\n\r\n**语法：**\r\n`const buffer = await frontHandler.qrCodeGener(content, type)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| content | string | true | 无 |\r\n| type | string | true | png |\r\n\r\n**返回值：**\r\n二维码buffer对象\r\n\r\n---\r\n\r\n#### getCategoryType\r\n**描述：**\r\nqrCodeGener()方法生成二维码，供APP扫码使用。\r\n采用第三方库[qr-image](#https://github.com/alexeyten/qr-image)生成，并返回一个buffer对象,\r\n使用参数语法可参考第三方库\r\n\r\n**方法 demo:**\r\n\r\n```\r\n这个比较抽象，输出也看不出含义，大家按照功能描述使用即可\r\n```\r\n\r\n**语法：**\r\n`const buffer = await frontHandler.qrCodeGener(content, type)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| content | string | true | 无 |\r\n| type | string | true | png |\r\n\r\n**返回值：**\r\n二维码buffer对象\r\n\r\n---\r\n\r\n#### conversionUnit\r\n**描述：**\r\nconversionUnit()方法用于单位转换，并返回单位转换后的对象。该方法中英文方法通用，转换逻辑不同。\r\n后台传回的单位都是基础单位\r\n如果是电量数据，达到10000才进行转换，改为万kWh\r\n\r\n中文情况下：1000进行转换，单位最高到G到就不再进行转换\r\n\r\n英文情况下：不转换单位\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst opts = {\r\n  target: 1000,\r\n  unit: 'kWh'\r\n}\r\n\r\nconst valueObj = conversionUnit(opts);\r\nconsole.log(valueObj);\r\n// { value: '1', unit: 'MWh' }\r\n\r\nconst opts2 = {\r\n  target: 1000,\r\n  unit: 'kWh',\r\n  threshold: 10000\r\n}\r\nconst valueObj2 = conversionUnit(opts2);\r\nconsole.log(valueObj2);\r\n// { value: '1000', unit: 'kWh' }\r\n\r\nconst opts3 = {\r\n  target: 1000.145,\r\n  unit: 'kWh'\r\n}\r\nconst valueObj3 = conversionUnit(opts3);\r\nconsole.log(valueObj3);\r\n// { value: '1', unit: 'MWh' }\r\n\r\nconst opts4 = {\r\n  target: 1000.145,\r\n  unit: 'kWh',\r\n  isEnglish: true\r\n}\r\nconst valueObj4 = conversionUnit(opts4);\r\nconsole.log(valueObj4);\r\n// { value: '1000.15', unit: 'kWh' }\r\n\r\nconst opts5 = {\r\n  target: 10000.145,\r\n  unit: 'kWh',\r\n  isElectricity: true\r\n}\r\nconst valueObj5 = conversionUnit(opts5);\r\nconsole.log(valueObj5);\r\n// { value: '1万', unit: 'kWh' }\r\n```\r\n\r\n**语法：**\r\n`const valueObj = frontHandler.conversionUnit(content, type)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| options | object | true | 无 |\r\n\r\n**options参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| target | number/null | true | 0 |\r\n| unit | string | true | 无 |\r\n| threshold | number | false | 1000 |\r\n| isEnglish | boolean | false | false |\r\n| digits | number | false | 2 |\r\n| isElectricity | boolean | false | false |\r\n\r\n**返回值：**\r\n单位转换后的对象，含有属性value，unit\r\n\r\n---\r\n\r\n#### getBaseResp\r\n**描述：**\r\ngetBaseResp()方法根据传入的基础数据类型，并返回基础的响应对象\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(getBaseResp())\r\n// { results: [], errorCode: 0, errorMsg: '' }\r\n\r\nconsole.log(getBaseResp({}));\r\n// { results: {}, errorCode: 0, errorMsg: '' }\r\n\r\nconsole.log(getBaseResp(''));\r\n// { results: '', errorCode: 0, errorMsg: '' }\r\n```\r\n\r\n**语法：**\r\n`const baseResp = frontHandler.getBaseResp(baseDataType)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| baseDataType | any  |  true   | [] |\r\n**返回值：**\r\n基础的响应对象\r\n\r\n---\r\n\r\n#### getScaleUnitAndPowerUnit\r\n**描述：**\r\ngetScaleUnitAndPowerUnit()方法传入后台获取的属性配置数组，如果存在scale和ratedPower配置则获取对应的单位，如果未找到，默认返回kW\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst propertyArr = [{\r\n  name: 'scale',\r\n  unit: {\r\n    name: 'kWh'\r\n  }\r\n}, {\r\n  name: 'ratedPower',\r\n  unit: {\r\n    name: 'kW'\r\n  }\r\n}];\r\n\r\nconst unitObj = getScaleUnitAndPowerUnit(propertyArr);\r\nconsole.log(unitObj);\r\n// { scaleUnit: 'kWh', powerUnit: 'kW' }\r\n\r\nconsole.log(getScaleUnitAndPowerUnit([]));\r\n// { scaleUnit: 'kW', powerUnit: 'kW' }\r\n```\r\n\r\n**语法：**\r\n`const unitObj = frontHandler.getScaleUnitAndPowerUnit(propertyArr)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| propertyArr | array | true | 无 |\r\n\r\n**返回值：**\r\n单位对象，含有属性scaleUnit，powerUnit\r\n\r\n---\r\n\r\n### requestHandler（请求处理方法）\r\n\r\n#### getApiBaseUrl\r\n**描述：**\r\ngetApiBaseUrl()方法获取后台基础IP端口，返回值已封装到req._apiBaseUrl,需要的时候直接获取即可\r\n\r\n**方法 demo:**\r\n\r\n```\r\n无\r\n```\r\n\r\n**语法：**\r\n`const baseUrl = await requestHandler.getApiBaseUrl()`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n\r\n**返回值：**\r\n获取后台接口的基础IP端口\r\n\r\n---\r\n\r\n#### joinUrl\r\n**描述：**\r\njoinUrl()方法根据传入的参数拼接URL,query中含有数组时转为字符串，逗号间隔\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst baseUrl = 'http://localhost:3000/';\r\nconst pathArr = ['api', 'login'];\r\nconst query = {\r\n  name: 'hans',\r\n  password: 'password'\r\n};\r\n\r\nconst url = joinUrl(baseUrl, pathArr, query);\r\nconsole.log(url);\r\n// http://localhost:3000/api/login?name=hans&password=password\r\n```\r\n\r\n**语法：**\r\n`const baseUrl = await requestHandler.joinUrl(baseUrl, path, query)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| baseUrl | string | true | 无 |\r\n| path | string[] | true | 无 |\r\n| query | object | true | {} |\r\n\r\n**返回值：**\r\n拼接后的url\r\n\r\n---\r\n\r\n#### requestPromise\r\n**描述：**\r\nrequestPromise()方法是第三方请求库[request](#https://github.com/request/request)的封装\r\n\r\n**方法 demo:**\r\n\r\n```\r\n具体使用\r\n```\r\n\r\n**语法：**\r\n`const baseUrl = await requestHandler.requestPromise(req, httpMethod, url, postBody)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| req | any | true | 无 |\r\n| httpMethod | string | true | 无 |\r\n| url | string | true | 无 |\r\n| postBody | object | true | {} |\r\n\r\n**返回值：**\r\nurl请求返回的Promise\r\n\r\n---\r\n\r\n#### responseHandle\r\n**描述：**\r\nresponseHandle()方法是对返回对象的处理，主要为logger打印返回内容服务，express原生的res对象里没有返回的具体数据内容，所以自己封装处理，如果未传具体返回，则默认为frontHandler.getBaseResp({})的默认返回\r\n\r\n**方法 demo:**\r\n\r\n```\r\n具体使用\r\n```\r\n\r\n**语法：**\r\nrequestHandler.responseHandle(res, results)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| res | any | true | 无 |\r\n| results | any | false | 无 |\r\n\r\n**返回值：**\r\nurl请求返回的Promise\r\n\r\n---\r\n\r\n#### judgeAbnormalResp\r\n**描述：**\r\njudgeAbnormalResp()方法判断后台返回是否出现跟约定数据格式不同，如不同则认为异常返回\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst objResp = {};\r\nconst arrayResp = [];\r\n\r\nconsole.log(judgeAbnormalResp({ origin: objResp, promiseDataType: 'array' }));\r\n// true\r\n\r\nconsole.log(judgeAbnormalResp({ origin: objResp, promiseDataType: 'object' }));\r\n// false\r\n\r\nconsole.log(judgeAbnormalResp({ origin: arrayResp, promiseDataType: 'array' }));\r\n// false\r\n\r\nconsole.log(judgeAbnormalResp({ origin: arrayResp, promiseDataType: 'object' }));\r\n// true\r\n```\r\n\r\n**语法：**\r\n`const isAbnormal = requestHandler.judgeAbnormalResp(options)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| options | object | true | 无 |\r\n\r\noptions参数：\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| origin | any | true | 无 |\r\n| promiseDataType | string | true | 无 |\r\n**返回值：**\r\n判断与约定的数据类型是否一致返回一个布尔值，判断是否出现异常返回\r\n\r\n---\r\n\r\n### timeHandler（时间处理方法）\r\n\r\n#### checkDateFormat\r\n**描述：**\r\ncheckDateFormat()方法判断传入的日期格式是否符合需要的日期格式，并返回布尔值区分是否符合\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst dateStr = '2020-07-01';\r\nconsole.log(checkDateFormat(dateStr));\r\n// false\r\n\r\nconsole.log(checkDateFormat(dateStr, 'YYYY-MM-DD'));\r\n// true\r\n```\r\n\r\n**语法：**\r\n`const isTrue = timeHandler.checkDateFormat(dateStr, format)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| dateStr | string | true | 无 |\r\n| format | string | true | 'YYYY-MM-DD HH:mm:ss' |\r\n\r\n**返回值：**\r\n如格式符合返回true，格式不符返回false\r\n\r\n---\r\n\r\n#### __existDate\r\n**描述：**\r\n__existDate()方法判断传入的日期是否存在，并返回一个布尔值表示是否存在该日期\r\n\r\nTips: 只是配合其他基础方法使用，外部不会调取到该方法，所以方法名前加了__表示私有\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(__existDate('2020-02-29'));\r\n// true\r\n\r\nconsole.log(__existDate('2020-07-01'));\r\n// true\r\n\r\nconsole.log(__existDate('2029-02-29'));\r\n// false\r\n```\r\n\r\n**语法：**\r\n`const isExist = timeHandler.__existDate(dateStr)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| dateStr | string | true | 无 |\r\n\r\n**返回值：**\r\n如存在返回true，不存在false\r\n\r\n---\r\n\r\n#### getFormatTimeObj\r\n**描述：**\r\ngetFormatTimeObj()方法获取当前时间的格式化对象，小于10的数字会进行补零，并返回一个对象\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst timeObj = getFormatTimeObj();\r\nconsole.log(timeObj);\r\n// {\r\n//   year: '2020',\r\n//   month: '07',\r\n//   day: '01',\r\n//   hour: '11',\r\n//   minute: '47',\r\n//   second: '14',\r\n//   curTime: '2020-07-01 11:47:14',\r\n//   curMonth: '2020-07',\r\n//   curDate: '2020-07-01'\r\n// }\r\n```\r\n\r\n**语法：**\r\n`const timeObj = timeHandler.getFormatTimeObj()`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| date | string | true | 当前时间 |\r\n\r\n**返回值：**\r\n年月日时分秒和常用当前月份，当前日期，当前时间的对象\r\n\r\n---\r\n\r\n#### getDateAfterCalculate\r\n**描述：**\r\ngetDateAfterCalculate()方法对于moment.add()方法的封装，并返回一个时间间隔后的日期\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst timeObj = getFormatTimeObj();\r\nconsole.log(timeObj);\r\n// {\r\n//   year: '2020',\r\n//   month: '07',\r\n//   day: '01',\r\n//   hour: '11',\r\n//   minute: '47',\r\n//   second: '14',\r\n//   curTime: '2020-07-01 11:47:14',\r\n//   curMonth: '2020-07',\r\n//   curDate: '2020-07-01'\r\n// }\r\n```\r\n\r\n**语法：**\r\n`const timeObj = timeHandler.getDateAfterCalculate()`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n\r\n**返回值：**\r\n年月日时分秒和常用当前月份，当前日期，当前时间的对象\r\n\r\n---\r\n\r\n#### getCertainMonthDays\r\n**描述：**\r\ngetCertainMonthDays()方法获得传入月份的日期数组，长度为当月时间长度\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst certainMonth = '2020-02';\r\nconst monthDays = getCertainMonthDays(certainMonth);\r\nconsole.log(monthDays);\r\n// ['2020-02-01', '2020-02-02', ... '2020-02-29'];\r\n```\r\n\r\n**语法：**\r\n`const monthDays = timeHandler.getCertainMonthDays(certainMonth)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| certainMonth | string | true | 无 |\r\n\r\n**返回值：**\r\n返回一个数组，包含该月的日期\r\n\r\n---\r\n\r\n#### getDaysByArgs\r\n**描述：**\r\ngetDaysByArgs()方法根据传入的起止时间，获取该时间段内的日期,包含传入的日期\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst days = getDaysByArgs('2020-01-29', '2020-02-05');\r\nconsole.log(days);\r\n// ['2020-01-29', '2020-02-02', ... '2020-02-05'];\r\n```\r\n\r\n**语法：**\r\n`const days = timeHandler.getDaysByArgs(startDate, endDate)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| startDate | string | true | 无 |\r\n| endDate | string | true | 无 |\r\n\r\n**返回值：**\r\n返回一个数组，包含起止时间段内的日期\r\n\r\n---\r\n\r\n#### getTimePoint\r\n**描述：**\r\ngetTimePoint()方法根据传入的起止时间和时间间隔，返回该时间段内的年月日时分秒的数组\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst times = getTimePoint('2020-02-05', '2020-02-05', 60);\r\nconsole.log(times);\r\n// [\r\n//   '2020-02-05 00:00:00',\r\n//   '2020-02-05 01:00:00',\r\n//   '2020-02-05 02:00:00',\r\n//   '2020-02-05 03:00:00',\r\n//   '2020-02-05 04:00:00',\r\n//   '2020-02-05 05:00:00',\r\n//   '2020-02-05 06:00:00',\r\n//   '2020-02-05 07:00:00',\r\n//   '2020-02-05 08:00:00',\r\n//   '2020-02-05 09:00:00',\r\n//   '2020-02-05 10:00:00',\r\n//   '2020-02-05 11:00:00',\r\n//   '2020-02-05 12:00:00',\r\n//   '2020-02-05 13:00:00',\r\n//   '2020-02-05 14:00:00',\r\n//   '2020-02-05 15:00:00',\r\n//   '2020-02-05 16:00:00',\r\n//   '2020-02-05 17:00:00',\r\n//   '2020-02-05 18:00:00',\r\n//   '2020-02-05 19:00:00',\r\n//   '2020-02-05 20:00:00',\r\n//   '2020-02-05 21:00:00',\r\n//   '2020-02-05 22:00:00',\r\n//   '2020-02-05 23:00:00'\r\n// ]\r\n```\r\n\r\n**语法：**\r\n`const times = timeHandler.getTimePoint(startDate, endDate, timeInterval)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| startDate | string | true | 无 |\r\n| endDate | string | true | 无 |\r\n| timeInterval | number | true | 15 |\r\n\r\n**返回值：**\r\n返回该时间段内的年月日时分秒的数组\r\n\r\n---\r\n\r\n#### getMonthBetween\r\n**描述：**\r\ngetMonthBetween()方法根据传入的起止时间和时间间隔，返回该时间段内的年月日时分秒的数组\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst months = getMonthBetween('2019-12-05', '2020-03-05');\r\nconsole.log(months);\r\n// [ '2019-12', '2020-01', '2020-02', '2020-03' ]\r\n```\r\n\r\n**语法：**\r\n`const months = timeHandler.getMonthBetween(startDate, endDate)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| startDate | string | true | 无 |\r\n| endDate | string | true | 无 |\r\n\r\n**返回值：**\r\n返回该时间段内的月份数组\r\n\r\n---\r\n\r\n#### getTimePointInterval\r\n**描述：**\r\ngetTimePointInterval()方法根据参数返回两个时间点的差值，差值的纬度可选minute/second\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst time1 = '2020-07-01 00:00:00';\r\nconst time2 = '2020-07-01 00:01:30';\r\n\r\nconsole.log(getTimePointInterval(time1, time2));\r\n// 1.5\r\n\r\nconsole.log(getTimePointInterval(time1, time2, 'second'));\r\n// 90\r\n\r\nconsole.log(getTimePointInterval('00:00:00', '00:30:00'));\r\n// 30\r\n```\r\n\r\n**语法：**\r\n`const timeInterval = timeHandler.getTimePointInterval(time1, time2, resultTimeType)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| time1 | string | true | 无 |\r\n| time2 | string | true | 无 |\r\n| resultTimeType | string | true | 'minute' |\r\n\r\n**返回值：**\r\n返回该时间段内的月份数组\r\n\r\n---\r\n\r\n#### msToDate\r\n**描述：**\r\nmsToDate()方法将输入的ms值转化为前端页面所需的显示格式，最长时间为30天，超过30天则只按秒为单位显示，如果不传则按0s处理\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconst oneSecond = 1000;\r\nconsole.log(msToDate(oneSecond));\r\n// 1s\r\n\r\nconsole.log(msToDate(oneSecond * 37));\r\n// 37s\r\n\r\nconsole.log(msToDate(oneSecond * 3760))\r\n// 1h2min40s\r\n\r\nconsole.log(msToDate(oneSecond * 3600 * 25))\r\n// 1d1h\r\n\r\nconsole.log(msToDate(oneSecond * 3600 * 24 * 31))\r\n// 2678400s\r\n\r\nconsole.log(msToDate());\r\n// 0s\r\n```\r\n\r\n**语法：**\r\n`const display = timeHandler.msToDate(msd)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| msd | string/number | true | 无 |\r\n\r\n**返回值：**\r\nms转换后的显示值\r\n\r\n---\r\n\r\n#### splicingDate\r\n**描述：**\r\nsplicingDate()方法将把传入的参数拼接成年月日时分秒的字符串，具体见下面示例\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(splicingDate('2020-07-01', '2020-07-02'));\r\n// 2020-07-01 00:00:00,2020-07-02 23:59:59\r\n\r\nconsole.log(splicingDate('2020-07', '2020-08'));\r\n// 2020-07-01 00:00:00,2020-08-31 23:59:59\r\n\r\nconsole.log(splicingDate('2019', '2020'));\r\n// 2019-01-01 00:00:00,2020-01-01 00:00:00\r\n```\r\n\r\n**语法：**\r\n`const times = timeHandler.splicingDate(startDate, endDate)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| startDate | string | true | 无 |\r\n| endDate | string | true | 无 |\r\n\r\n**返回值：**\r\n拼接后的字符串\r\n\r\n---\r\n\r\n#### __timeToMoment\r\n**描述：**\r\n__timeToMoment()方法获取传入的时间内最近的时刻点（0，15，30，45），并返回时间对象，包含属性hour,minute\r\n\r\nTips: 传入的格式为HH:mm\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(__timeToMoment('12:14'));\r\n// { hour: 12, minute: 15 }\r\n\r\nconsole.log(__timeToMoment('12:01'));\r\n// { hour: 12, minute: 0 }\r\n\r\nconsole.log(__timeToMoment('12:59'));\r\n// { hour: 13, minute: 0 }\r\n```\r\n\r\n**语法：**\r\n`const timeObj = timeHandler.__timeToMoment(time)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| time | string | true | 无 |\r\n\r\n**返回值：**\r\n时间对象，包含属性hour,minute\r\n\r\n---\r\n\r\n#### transfromTimeFormat\r\n**描述：**\r\ntransfromTimeFormat()方法是moment().format()方法的封装，用来转化时间格式\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(transfromTimeFormat('2020-01-01'));\r\n// 2020-01-01 00:00\r\n\r\nconsole.log(transfromTimeFormat('2020-01-01 00:00:00', ETimeFormatType.DAY));\r\n// 2020-01-01\r\n```\r\n\r\n**语法：**\r\n`const timeObj = timeHandler.transfromTimeFormat(time, format)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| time | string | true | 无 |\r\n| format | string | true | 'YYYY-MM-DD HH:mm' |\r\n\r\n**返回值：**\r\n转换后的时间字符串\r\n\r\n---\r\n\r\n#### judgeIsBetween\r\n**描述：**\r\njudgeIsBetween()方法判断一个时间是否在两个时间点之间，并返回一个字符串表示关系，返回结果before/between/after\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(judgeIsBetween('2020-07-01', '2020-07-01', '2020-07-01'));\r\n// between\r\n\r\nconsole.log(judgeIsBetween('2020-07-01', '2020-06-01', '2020-06-01'));\r\n// after\r\n\r\nconsole.log(judgeIsBetween('2020-07-01', '2020-08-01', '2020-08-01'));\r\n// before\r\n```\r\n\r\n**语法：**\r\n`const relation = timeHandler.judgeIsBetween(cur, start, end)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| cur | string | true | 无 |\r\n| start | string | true | 无 |\r\n| end | string | true | 无 |\r\n\r\n**返回值：**\r\n转换后的时间字符串\r\n\r\n---\r\n\r\n#### getTimeIntervalByMoment\r\n**描述：**\r\ngetTimeIntervalByMoment()方法是moment.diff()方法的封装，获取两个时间点的具体时间间隔\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(ms);\r\n// 180000\r\n\r\nconsole.log(day);\r\n// 1\r\n```\r\n\r\n**语法：**\r\n`const relation = timeHandler.getTimeIntervalByMoment(originTime, targetTime, timeType)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| originTime | string | true | 无 |\r\n| targetTime | string | true | 无 |\r\n| timeType | string | true | days |\r\n\r\n**返回值：**\r\n两个时间点的具体时间间隔\r\n\r\n---\r\n\r\n#### msToDisplay\r\n**描述：**\r\nmsToDisplay()方法是针对前端页面显示需求，将ms值转换为所需格式\r\n\r\n**方法 demo:**\r\n\r\n```\r\nconsole.log(msToDisplay(1000 * 60 * 15, 'HH:mm'));\r\n// { H: '0', m: '15' }\r\n\r\nconsole.log(msToDisplay(1000 * 60 * 75, 'HH:mm'));\r\n// { H: '1', m: '15' }\r\n\r\nconsole.log(msToDisplay(1000 * 60 * 70, 'HH'));\r\n// { H: '1.17' }\r\n```\r\n\r\n**语法：**\r\n`const display = timeHandler.msToDisplay(ms, format, digits)`\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| ms | number | true | 无 |\r\n| format | string | true | 'HH' |\r\n| digits | number | true | 2 |\r\n\r\n**返回值：**\r\n转换后的时间对象\r\n\r\n---\r\n\r\n## models（后台路由封装）\r\n\r\n调用方式：share.models.XXX\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| req | object | true | 无 |\r\n| params | object | true | 无 |\r\n| graphqlQuery | string | false | 无 |\r\n\r\nTips：这里的参数为model的通用参数，以下具体方法中的参数都为params中的参数\r\n\r\n### abnormalAlarmConfigs(告警配置)\r\n\r\n**总览：**\r\nabnormalAlarmConfigs模块对应后台告警配置模块，存在以下函数\r\n\r\n| function | remark |\r\n| ---------- | ------ |\r\n| getAbnormalAlarmConfigs | 获取告警配置列表 |\r\n| postAbnormalAlarmConfigs | 新增告警配置 |\r\n| patchAbnormalAlarmConfigs | 变量修改告警配置 |\r\n| deleteAbnormalAlarmConfigs | 删除告警配置 |\r\n\r\n#### getAbnormalAlarmConfigs\r\n**描述：**\r\n后台对应URL：GET /ems-abnormal/alarmStatuses\r\n根据传入的参数获取告警配置列表\r\n\r\n**参数：**\r\n| property | type | require | default |\r\n|----------|------| ------- | ------- |\r\n| stationId | number | false | 无 |\r\n| page | number | false | 无 |\r\n| size | number | false | 无 |\r\n| queryStr | string | false | 无 |\r\n\r\n---\r\n\r\n## 接口开发流程\r\n\r\n![image](https://github.com/shufengdong/wanke-bff-common/blob/master/docs/img/develop-process.png)\r\n\r\n#### 接口测试流程暂时跳过，等待hq-test包二期开发支持接口测试后实行","readmeFilename":"README.md"}