'use strict';

/**
 * cld接口模型
 *
 * @author EllisRan.
 * @date 2020/12/4
 * @version
 */
const Request = require("request");

class CLDModel {

    CLDUrl = 'http://cld.smartcost.com.cn';

    /**
     * 获取cld所有员工信息
     *
     * @return {Promise}
     */
    async getAllStaff() {
        let postData = {
            url: this.CLDUrl + '/api/building/staff/list',
            encoding: 'utf8'
        };
        return new Promise(function (resolve, reject) {
            try {
                // 请求接口
                Request.post(postData, function (err, postResponse, body) {
                    if (err) {
                        throw '请求错误';
                    }
                    if (postResponse.statusCode !== 200) {
                        throw 'CLD通讯失败！';
                    }
                    resolve(body);
                });
            } catch (error) {
                reject([]);
            }
        });
    }
}

module.exports = CLDModel;
