var System = require("../../system")
const uuidv4 = require('uuid/v4');
const crypto = require('crypto');
const cryptoJS = require("crypto-js");
const querystring = require('querystring');
const logCtl = System.getObject("web.oplogCtl");
const fs = require("fs");
const xlsx = require('node-xlsx')
var moment = require('moment')
class TestApi {
  constructor() {
    this.utilesignbaoSve = System.getObject("service.utilesignbaoSve");
    this.redisClient = System.getObject("util.redisClient");
    this.downcontractClient = System.getObject("util.downcontractClient");
    // this.publishClient = System.getObject("util.publishClient");
  }

  async testAddDL(obj) {
    let contracts = obj.contracts || [];
    for(let p of contracts) {
      await this.redisClient.rpushBCD(p);
    }
    return {msg: "success"}
  }

  async donloadContract(obj) {
    this.downcontractClient.donloadContract();
    return {msg: "start success"};
  }

  async genPosterQrcodeImg(obj) {
    return await this.imghandleApi.genPosterQrcodeImg(obj.qrcode, obj.bakImg);
  }


  async creatCompanyAccountId(obj) {   //创建企业账号
    var params = {
      thirdId: obj.thirdId || "owD7y5AqMWjDSru10gDacEeA9Q5g",    //企业用户在对接方的账号标识字段-该字段来唯一标识一个企业用户
      creatorId: obj.creatorId || "fc7d596a767b47a4874490966c7641c7",  //企业创建人在 e签宝的个人账号唯一标识(宋毅accountId)
      name: obj.name || "汉唐信通（北京）咨询股份有限公司",   //企业名称
      organCode: obj.organCode || "911101057889696760",   //企业证照号(企业统一社会信用代码)
      organType: obj.organType || 11,    //企业账号证照类型--11为企业统一社会信用代码
      legalName: obj.legalName || "宋毅",  //企业法人姓名
      legalIdNo: obj.legalIdNo || "341221198504218256",    //企业法人身份证号
      legalIdType: 19,   //个人账号证件类型--19为中国大陆居民身份证
      email: obj.email || "lisa@gongsibao.com"   //企业邮箱
    };
    var tt = await this.utilesignbaoSve.creatCompanyAccountId(params, "testApi");
    tt.aaa = "aaa";
    console.log(tt);
    return tt;
  }

  async importexcel() {
    var names = [];
    for (var i = 1; i <= 6; i++) {
      try {
        var filePath = "/tmp/banks" + i + ".xlsx";
        console.log("----------------------------- begin " + i + " -----------------------------");
        var sheets = xlsx.parse(filePath);
        if (!sheets || sheets.length == 0) {
          return result;
        }

        var sheet = sheets[0];
        if (!sheet || !sheet.data || sheet.data.length == 0) {
          return result;
        }

        var rows = sheet.data;

        for (var idx in rows) {
          var cells = rows[idx];
          if (!cells || cells.length < 3) {
            continue;
          }
          var obj = {
            number: cells[0],
            bankName: cells[1],
            bankCode: cells[2]
          }
          await this.ebankSve.create(obj);
        }
        console.log("----------------------------- end " + i + "-----------------------------");
      } catch (error) {
        console.log(error.stack);
      }
    }
  }

  async sssss(obj){
      if(obj.ss in {"12":"","13":""}) {
        console.log("ok")
      }else {
        console.log("no")
      }


  }




}
module.exports = TestApi;
