GetPowerData.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const API = require("../../lib/API.js")
  2. const { axiosWithQgOutbound } = require("../../lib/Lepao/qgOutboundAxios")
  3. const { BaseStdResponse } = require("../../BaseStdResponse.js")
  4. // 获取楼栋
  5. class GetDyList extends API {
  6. constructor() {
  7. super()
  8. this.setPath("/Power/GetPowerData")
  9. this.setMethod("POST")
  10. }
  11. async onRequest(req, res) {
  12. try {
  13. const { type, pid } = req.body
  14. if ([type].some(value => value === '' || value === null || value === undefined))
  15. return res.json({
  16. ...BaseStdResponse.MISSING_PARAMETER
  17. })
  18. if (type !== 'buildlist')
  19. if ([pid].some(value => value === '' || value === null || value === undefined))
  20. return res.json({
  21. ...BaseStdResponse.MISSING_PARAMETER
  22. })
  23. const url = `https://hqpay.ctbu.edu.cn/weixin/ashx/frmuser.ashx?test=${type}${type !== 'buildlist' ? '&pid=' + pid : ''}`
  24. const response = await axiosWithQgOutbound({
  25. method: 'get',
  26. url,
  27. timeout: 15000,
  28. logger: this.logger,
  29. scene: 'PowerGetData'
  30. })
  31. if (!response || !response.data)
  32. return res.json({
  33. ...BaseStdResponse.ERR,
  34. msg: "请稍后再试"
  35. })
  36. res.json({
  37. ...BaseStdResponse.OK,
  38. data: response.data ?? []
  39. })
  40. } catch (error) {
  41. this.logger?.error(`${error.stack}`)
  42. return res.json({
  43. ...BaseStdResponse.ERR,
  44. msg: `${error.message ?? "请稍后再试"}`
  45. })
  46. }
  47. }
  48. }
  49. module.exports.GetDyList = GetDyList