"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChargingPileDal = void 0;
var nslib_1 = require("../refs/nslib");
var mslib_1 = require("mslib");
/**
 *获取规则配置
 * @date 2022-08-16 10:16:41
 * @author 侯洪莉
 */
var ChargingPileDal = /** @class */ (function () {
    function ChargingPileDal() {
    }
    /**
    * 获取使用规则配置信息
    * @param {*} parkId
    * @param {string} pileId 充电桩appID
    * @param {*} opsConfig 统一平台配置
    */
    ChargingPileDal.prototype.getPileRule = function (parkId, pileId) {
        return __awaiter(this, void 0, void 0, function () {
            var sql, sqlApiClient, res, info;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        sql = "\n            select  \n                id,\n                name  as pileName,      -- \u5145\u7535\u6869\u540D\u79F0\n                pileId,                 -- \u5145\u7535\u6869ID\n                isEnable,               -- \u662F\u5426\u542F\u7528 0-\u7981\u7528 1-\u542F\u7528\n                discountSource,         -- \u62B5\u6263\u6765\u6E90\n                discountType,           -- \u62B5\u6263\u7C7B\u578B\n                discountMethod,         -- \u62B5\u6263\u65B9\u6CD5\n                discountNumber,         -- \u62B5\u6263\u6570\u91CF\n                chargeTime,             -- \u4F7F\u7528\u62B5\u6263\u7684\u6700\u5C0F\u5145\u7535\u65F6\u95F4\u8981\u6C42\n                onceMaxNum,             -- \u5355\u6B21\u505C\u8F66\u62B5\u6263\u6B21\u6570\u4E0A\u9650\n                dayMaxNum,              -- \u5355\u65E5\u505C\u8F66\u62B5\u6263\u6B21\u6570\u4E0A\u9650\n                onceMaxTime,            -- \u5355\u6B21\u505C\u8F66\u62B5\u6263\u65F6\u957F\u4E0A\u9650\n                onceMaxMoney,           -- \u5355\u6B21\u505C\u8F66\u62B5\u6263\u91D1\u989D\u4E0A\u9650\n                dayMaxTime,             -- \u6BCF\u65E5\u62B5\u6263\u65F6\u957F\u4E0A\u9650\n                dayMaxMoney,            -- \u6BCF\u65E5\u62B5\u6263\u91D1\u989D\u4E0A\u9650\n                isSpecialFeeRule,       -- \u662F\u5426\u4F7F\u7528\u7279\u6B8A\u89C4\u5219\n                carStyle                   -- \u5145\u7535\u8F66\u8F86\u7C7B\u578B\n            from \n                t_" + parkId + "_ns_pile \n            where \n                isDelete  = 0 and isEnable = 1 and pileId='" + pileId + "'\n            limit 1\n        ";
                        sqlApiClient = nslib_1.generateTySqlApiClient(parkId);
                        return [4 /*yield*/, sqlApiClient.selectOne(sql)];
                    case 1:
                        res = _a.sent();
                        info = res || null;
                        mslib_1.logger.info('规则配置', JSON.stringify(info));
                        return [2 /*return*/, info];
                }
            });
        });
    };
    /**
     * 获取全局配置信息
     *
     * @param {string}
     * @param {*} opsConfig 统一平台配置
     */
    ChargingPileDal.prototype.getPileConfig = function (parkId) {
        return __awaiter(this, void 0, void 0, function () {
            var session, sql, sqlApiClient, result, info, configInfo, _i, info_1, item;
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        session = '1103860';
                        sql = "\n            select\n            name, \n            value \n            from t_" + parkId + "_ns_pile_config where session='" + session + "';\n        ";
                        sqlApiClient = nslib_1.generateTySqlApiClient(parkId);
                        return [4 /*yield*/, sqlApiClient.list(sql)];
                    case 1:
                        result = _b.sent();
                        info = result || [];
                        mslib_1.logger.info('全局配置', JSON.stringify(info));
                        configInfo = {};
                        if (info && info.length > 0) {
                            for (_i = 0, info_1 = info; _i < info_1.length; _i++) {
                                item = info_1[_i];
                                Object.assign(configInfo, (_a = {},
                                    _a[item.name] = item['value'],
                                    _a));
                            }
                        }
                        return [2 /*return*/, configInfo];
                }
            });
        });
    };
    return ChargingPileDal;
}());
exports.ChargingPileDal = ChargingPileDal;
//# sourceMappingURL=ChargingPileDal.js.map