cld_model.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. /**
  3. * cld接口模型
  4. *
  5. * @author EllisRan.
  6. * @date 2020/12/4
  7. * @version
  8. */
  9. const Request = require("request");
  10. class CLDModel {
  11. CLDUrl = 'http://cld.smartcost.com.cn';
  12. /**
  13. * 获取cld所有员工信息
  14. *
  15. * @return {Promise}
  16. */
  17. async getAllStaff() {
  18. let postData = {
  19. url: this.CLDUrl + '/api/building/staff/list',
  20. encoding: 'utf8'
  21. };
  22. return new Promise(function (resolve, reject) {
  23. try {
  24. // 请求接口
  25. Request.post(postData, function (err, postResponse, body) {
  26. if (err) {
  27. throw '请求错误';
  28. }
  29. if (postResponse.statusCode !== 200) {
  30. throw 'CLD通讯失败!';
  31. }
  32. resolve(body);
  33. });
  34. } catch (error) {
  35. reject([]);
  36. }
  37. });
  38. }
  39. /**
  40. * 获取办事处人员信息
  41. *
  42. * @param cid
  43. * @return {Promise}
  44. */
  45. async getCategoryStaff(cid) {
  46. let postData = {
  47. url: this.CLDUrl + '/api/building/category/staff/' + cid,
  48. encoding: 'utf8'
  49. };
  50. return new Promise(function (resolve, reject) {
  51. try {
  52. // 请求接口
  53. Request.post(postData, function (err, postResponse, body) {
  54. if (err) {
  55. throw '请求错误';
  56. }
  57. if (postResponse.statusCode !== 200) {
  58. throw 'CLD通讯失败!';
  59. }
  60. resolve(body);
  61. });
  62. } catch (error) {
  63. reject([]);
  64. }
  65. });
  66. }
  67. }
  68. module.exports = CLDModel;