var system = require("../../../system");
const CtlBase = require("../../ctl.base");
const CryptoJS = require("crypto-js");
var crypto = require('crypto');
const settings = require("./../../../../config/settings");

/**
 *  @module agriculture
 *  @class servicelistCtl
 *  服务单ctl
 */

class messageCtl extends CtlBase {
    constructor() {
        super("agriculture", CtlBase.getServiceName(messageCtl));
        this.servicebillCtl = system.getObject("service.agriculture.servicebillCtl");
    }

    async message(meg) {
        console.log('-----------------------------message--------------------');
        console.log(meg)
        const res = {};
        switch (meg.type) {
            case "CREATE_ACCOUNTING":
                res = await this.servicebillCtl.create(meg);
                break;
            case "APP_TICKET":
                res = await this.service.ticketProcessing(meg);
                break;
        }
        return { "result": "success" };
    }
    zeropad(inputData, length = 8) {
        inputData = Buffer.from(inputData, "utf8").toString("hex");
        const bitLength = inputData.length * length;
        if (bitLength < 256) {
            for (i = bitLength; i < 256; i += length) {
                inputData += 0;
            }
        } else if (bitLength > 256) {
            while ((inputData.length * length) % 256 != 0) {
                inputData += 0;
            }
        }
        return Buffer.from(inputData, "hex").toString("utf8");
    }
}
module.exports = messageCtl;