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");
var moment = require('moment')
// const settings = require("../../../config/settings");
// const uiconfig = System.getUiConfig2(settings.wxconfig.appId);
class TestApi {
  constructor() {
    this.appSve = System.getObject("service.appSve");

    this.cacheManager = System.getObject("db.cacheManager");
    this.shopSve = System.getObject("service.shopSve");
    this.statisticalrateSve = System.getObject("service.statisticalrateSve");
    this.pagestatisticsSve = System.getObject("service.pagestatisticsSve");
    this.utilstmSve = System.getObject("service.utilstmSve");
    this.utilspaSve = System.getObject("service.utilspaSve");
    this.utilesignbaoSve = System.getObject("service.utilesignbaoSve");
    this.econtractSve = System.getObject("service.econtractSve");
    this.restClient = System.getObject("util.restClient");
    this.channelmanageallotSve = System.getObject("service.channelmanageallotSve");
    this.etemplateSve = System.getObject("service.etemplateSve");
    this.ecompanySve = System.getObject("service.ecompanySve");
    this.businessallotSve = System.getObject("service.businessallotSve");
    this.businesschanceSve = System.getObject("service.businesschanceSve");
    this.bytmmonitSve = System.getObject("service.bytmmonitSve");
    this.bytmmonit = System.getObject("api.bytmmonit");
    this.imghandleApi = System.getObject("api.imghandle");
    this.bytmdynamicsSve = System.getObject("service.bytmdynamicsSve");
    this.softwarecrsubmitSve = System.getObject("service.softwarecrsubmitSve");
    this.workcrsubmitSve = System.getObject("service.workcrsubmitSve");

    this.phonesearch = System.getObject("api.phonesearch");
    this.redisClient = System.getObject("util.redisClient");
    this.trademarkSve = System.getObject("service.trademarkSve");
  }
  async ddsend(obj) {
    var obj = {
      proxyCode: "201943117371910013432153", stateCode: "ROBOT", errorMsg: "错误测试----666----。。。。。。"
    }
    this.trademarkSve.ddSend(obj);
  }
  async getCrList(obj) {
    try {
      // var tmp = uiconfig.config.pdict.tm_submit_status;
      // console.log(typeof (tmp), "tmp...............>>>>>>>>>>>>>>>");
      // console.log(tmp, "?????????????????????????????????????");
      // var tmp1 = tmp["WAITARTIFICIALEXAMINE"];
      // return tmp1;
      // var tbDataList = await this.cacheManager["MsgqTestCache"].pushMqData("MSGQ",obj);
      // var tmpobj = { appKey: "a95ad36efc064343aff200d18be6637d", companyName: "汉唐信通(北京)咨询股份有限公司", currentPage: 1, pageSize: 10 }
      // var result= await this.phonesearch.phoneNameSearch(tmpobj);
      // console.log(result);
      // return result;


      // var tmpStr=await this.workcrsubmitSve.getBusUid("skxx");
      // console.log(tmpStr,"<<<<<<<tmpStr>>>>>>>>>>>>>>>>>>>>>>>");
      // var tmpStr1=await this.workcrsubmitSve.getBusUid("w");
      // console.log(tmpStr1,"<<<<<<<tmpStr1>>>>>>>>>>>>>>>>>>>>>>>");
      // var tmpStr2=await this.workcrsubmitSve.getBusUid();
      // console.log(tmpStr2,"<<<<<<<tmpStr2>>>>>>>>>>>>>>>>>>>>>>>");
      // return tmpStr;
      // var result = this.softwarecrsubmitSve.getAutoSubList();
      // var result = this.workcrsubmitSve.getAutoSubList();
      // return result;
    } catch (error) {
      console.log(error.stack, "error>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    }

  }
  async consumeMq() {
    var tbDataList = await this.cacheManager["MsgqTestCache"].consumeData("MSGQ");
    console.log("消耗完毕........................");

  }

  async getT() {
    var result = await this.bytmdynamicsSve.notifyWxTmDynamics();
    console.log(result, "result>>>>>>>>>>>>>>");

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

  async monit(qobj) {
    // console.log("qobj================================================");
    // console.log(qobj);
    try {
      var self = this;
      var item = await this.bytmmonitSve.dao.model.findOne({ where: { code: "th81548400031627" } });
      console.log("item.........................");
      console.log(item);
      if (item && item.queryBuilder) {
        var query = JSON.parse(item.queryBuilder);
        console.log("query..........................>>>>>>>>>>>>>>>>>>>>>>>");
        console.log(query);
        query.appKey = "wx76a324c5d201d1a4";
        query.apply_year = "-1";//": "2018",==申请日期,-1为全部否则为选择对应的年份
        query.status = "-1";//":"-1",==法律状态,-1为全部,1:申请中；2:已初审；3:已注册；4:已无效  5-其他
        query.ncl_one_codes = "-1";//":"01",	==申请日期,-1为全部否则为选择对应的大类
        query.total_type = "1";//":"-1",==统计类型,-1为全部，1为可无效、2为可撤三、3可续展、4可宽展、5可异议
        query.current_page = 1;//": 1,
        query.page_size = 10;//": 10,
        //构建新条件
        query.monit_name = item.name;
        var tmp = await this.bytmmonit.getTmMonitList(query);
        // console.log("tmp999999999999999999999999999999999999999999999999999999999");
        // console.log(tmp);
        return tmp;
      }




      // qobj.code="test001"
      // var tempObj={
      //   user_id:1,
      //   monitType:qobj.monit_type,
      //   name:self.getNameInfo(qobj),
      //   queryBuilder:JSON.stringify(qobj)
      // }
      // console.log("tttttttttttttttttttt-----------------add------------------------------");
      // console.log(tempObj);
      // return await this.bytmmonitSve.addMonit(tempObj);

      // var obj={
      //     search:{monitType:1},
      //     pageInfo:{
      //       pageSize:10,
      //       pageNo:1
      //     }
      // };
      // var attributesObj=["code","name","monitType","created_at"];
      // return await this.bytmmonitSve.getPageList(1,10,{monitType:1},[["created_at", 'desc']],attributesObj);

    } catch (e) {
      console.log("error..................................??????????????????");
      console.log(e.stack);
    }
  }

  async moni() {
    await this.bytmmonitSve.getMonitAll();
  }

  getNameInfo(params) {
    var nameStr = "";
    if (params.monit_type == 1) {
      if (!params.name && params.ncl_type.length == 0 && !params.tm_regist_num && !params.applicant_cn) {
        return nameStr;
      }
      var tName = [];
      var nameTypeStr = this.getNameTypeStr(params.name, params.name_type);
      if (nameTypeStr) {
        tName.push(nameTypeStr);
      }
      if (params.tm_regist_num) {
        tName.push(params.tm_regist_num);
      }
      if (params.applicant_cn) {
        tName.push(params.applicant_cn);
      }
      var nclStr = this.getNclStr(params.ncl_type);
      if (nclStr) {
        tName.push(nclStr);
      }
      nameStr = tName.join("，");
    } else if (params.monit_type == 2) {
      if (params.tm_agency == null) {
        return nameStr;
      }
      nameStr = params.tm_agency
    }
    return nameStr;
  }
  getNameTypeStr(name, name_type) {
    var nameType = "";
    if (name) {
      nameType = name;
      switch (name_type) {
        case 1:
          nameType = nameType + "（相同）";
          break;
        case 2:
          nameType = nameType + "（相似）";
          break;
        case 3:
          nameType = nameType + "（相同+相似）";
          break;
        default:
          break;
      }
    }
    return nameType;
  }
  getNclStr(ncl_type) {
    if (!ncl_type || ncl_type.length == 0) {
      return ""
    }
    var tNclList = [];
    for (var i = 0; i < ncl_type.length; i++) {
      var tNcl = ncl_type[i];
      if (tNcl && i < 3) {
        tNclList.push(tNcl);
      }
      if (i == 3) {
        break;
      }
    }
    return ncl_type.length > 3 ? tNclList.join("、类") + "等" + ncl_type.length + "个类别" : tNclList.join("类、") + "类";
  }

  async opCache(obj) {
    // var tbDataList = await this.cacheManager["ApplistCache"].getListByCache();
    var list = [];
    var key = "byc_" + obj.openId;
    var mark = obj.mark;
    var tbDataList = await this.cacheManager["BycCache"].getBycListByCache(key);
    if (tbDataList && tbDataList != null && tbDataList != "null") {
      list = JSON.parse(tbDataList);
    }
    return { code: 1, data: list };
  }
  async redisInsert(obj) {
    var list = [];
    var key = "byc_" + obj.openId;
    var mark = obj.mark;
    var tbDataList = await this.cacheManager["BycCache"].getBycListByCache(key);
    if (tbDataList && tbDataList != null && tbDataList != "null") {
      list = JSON.parse(tbDataList);
      if (mark != "" && mark != null) {
        if (list.length < 10) {
          var delIndex = list.findIndex(v => v.value === mark);
          if (delIndex < 0) {
            list.push({ value: mark });
          }
        } else {
          var delIndex = list.findIndex(v => v.value === mark);
          if (delIndex < 0) {
            //移除单个数据
            list.splice(0, 1);
            list.push({ value: mark });
          }
        }
      }
    } else {
      if (mark != "" && mark != null) {
        var m = {
          value: mark
        };
        list.push(m);
      }
    }
    var stringStr = JSON.stringify(list);
    this.cacheManager["BycCache"].setBycList(key, stringStr);
    return { code: 1 };
  }

  async contracturl(obj) {
    this.econtractSve.downloadCompleteUrl(obj.limit);
  }

  async getStr(obj) {
    // var reverse ="中国人民".split('').reverse().join('');
    // console.log(reverse,"reverse.....................>>>>>>>>>>>>>>>");
    var tmp = {
      reg_num: "12164800",
      nclone_code: 35

    }
    // var tmp=await this.utilstmSve.getGroupNclNumList(tmpt,"testApi");
    // var item= await this.businesschanceSve.getChannelBusinessList({channel_code:"wssyh5",chance_status:4,current_page:1,page_size:10});
    // this.businessallotSve.success(164,27,3000,"成功01","add");
    // this.businessallotSve.success(164,27,100,"put成功01","put");
    // var item= await this.businesschanceSve.getChannelTotal("hrjob360");
    console.log("tmp..............................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    console.log(tmp);
    return tmp;
    // var arry=["yzc","hhr"];
  }
  reverseStr(str) {
    return "中国人民".split('').reverse().join('');
  }
  async testWeight() {
    // return await this.channelmanageallotSve.incrAllotCount(obj.id, obj.weight);
  }

  async businessAllot() {
    try {
      var tmp = await this.channelmanageallotSve.businessOneAllot("http://boss.gongsibao.com")
      console.log("tmp===================>>>>>>>>>>>>>>>>>>>>>");
      console.log(tmp);
    } catch (e) {
      console.log("erro:=================");
      console.log(e.stack);
    } finally {

    }
  }

  async importECompany(obj) {
    console.log(obj, "===================>>>>>>>>>>>>>>>>>>>>>");
    var names = obj.companyNames;
    var nameA = obj.nameA || '智信云（天津）科技有限公司';
    var encryptkey = obj.encryptkey;
    var posturl = obj.posturl;
    var etemplate = await this.etemplateSve.findById(Number(obj.etemplateId || 0));
    if (!etemplate) {
      return 0;
    }

    for (var name of names) {
      try {
        console.log("========== import ecompany : " + name);
        let rs = await this.ecompanySve.importCompany(name, nameA, encryptkey, posturl, etemplate);
      } catch (e) {
        console.log(e);
      }
    }
    return 1;
  }

  async downloadFile() {
    var tt = await this.utilesignbaoSve.downfile("https://esignoss.oss-cn-hangzhou.aliyuncs.com/1111563786/28243226-d248-42b0-9e17-820d615ef201/b20baff5-b0c4-4676-a551-633ba642db5d.pdf?Expires=1544526333&OSSAccessKeyId=LTAIdvHfiVrzDKbE&Signature=ZsMABJKb3oyk8rrjH6txev6CRs0%3D", "testApi");
    console.log("tt-----------------------------");
    console.log(tt);
    return tt;
  }

  async downloadUserContractFile() {
    var tt = await this.utilesignbaoSve.downloadUserContractFile("c0f6212793ba4c79be699cab2424bdd8", "testApi");
    console.log("tt-----------------------------");
    console.log(tt);
    return tt;
  }
  async testPOst() {
    let rs = await this.restClient.execPost({ data: "" }, posturl);
    console.log(rs, "=========================================================");
    return rs;
  }

  async testPushContract() {
    var rs = await this.econtractSve.pushContract();
    return rs;
  }

  async testContractCallback() {
    var params = {
      signTime: "2018-12-11 23:55:22",
      signResult: "2",
      thirdOrderNo: "1"
    };
    var rs = await this.econtractSve.updateCallbackStatus(params);
    return rs;
  }

  async createEntTemplate() {  //创建合同模板
    // var fileUrl="https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_230111544249013072201881433372分包协议（个人经营者）.pdf";
    var fileUrl = "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_440015468554977022019718457702%E5%88%86%E5%8C%85%E5%8D%8F%E8%AE%AE%EF%BC%88%E4%B8%AA%E4%BA%BA%E7%BB%8F%E8%90%A5%E8%80%85%EF%BC%89---%E6%9C%80%E6%96%B0%E7%89%88.pdf";

    // var fileUrl="zc_230111544249013072201881433372分包协议（个人经营者）.pdf";
    var tt = await this.utilesignbaoSve.createEntTemplate(fileUrl, "汉唐信通（北京）咨询股份有限公司", "testApi");
    // 返回值
    //   { code: 1,
    // message: 'success',
    // data:
    //  { fileKey: '$75c7bf61-7059-4152-9f60-448b652f81ff$4276293485',
    //    templateId: '2c98d5446734acf5016791e8ed32001d' } }
    console.log(tt, "tt11-----------------------------");
    return tt;
  }

  async createAccountId() {   //创建个人帐户
    var params = {
      thirdId: "odnZ4t9j-kDDNZnboQFJY0tO1M89EE",//咱们的唯一码-onlycode 必填
      name: "高宇强",//姓名 必填
      idNo: "412702198211212755",//身份证 必填
      idType: 19,//默认 必填
      mobile: "15801599965",//手机号 必填
      email: "306411273@qq.com"//邮箱
    };
    var tt = await this.utilesignbaoSve.createAccountId(params, "testApi");
    console.log("tt-----------------------------");
    console.log(tt);
    return tt;
    //   { code: 1,
    // message: 'success',
    // data: { accountId: 'f21eb569efef4c22b688a85ca2975915' } }
    //

  }
  async updateAccountId() {   //创建个人帐户
    var params = {
      accountId: "f21eb569efef4c22b688a85ca2975915",//咱们的唯一码-onlycode 必填
      name: "王栋源",//姓名 必填
      mobile: "17610163852",//手机号
    };
    var tt = await this.utilesignbaoSve.updateAccountId(params, "testApi");
    console.log("tt-----------------------------");
    console.log(tt);
    return tt;
  }
  async creatCompanyAccountId() {   //创建企业账号
    var params = {
      thirdId: "owD7y5AqMWjDSru10gDacEeA9Q5g",    //企业用户在对接方的账号标识字段
      creatorId: "fc7d596a767b47a4874490966c7641c7",  //企业创建人在 e签宝的个人账号唯一标识(宋毅accountId)
      name: "汉唐信通（北京）咨询股份有限公司",   //企业名称
      organCode: "911101057889696760",   //企业证照号(企业统一社会信用代码)
      organType: 11,    //企业账号证照类型
      legalName: "宋毅",  //企业法人姓名
      legalIdNo: "341221198504218256",    //企业法人身份证号
      legalIdType: 19,   //个人账号证件类型
      email: "lisa@gongsibao.com"   //企业邮箱
    };
    var tt = await this.utilesignbaoSve.creatCompanyAccountId(params, "testApi");
    console.log(tt);
  }
  async grantAuthorization() {    //设置静默签署授权
    var params = {
      grantAccountId: "740b19e0799a4d7abacfa1a31fb72b1e"  //企业的accountId
    };
    var tt = await this.utilesignbaoSve.grantAuthorization(params, "testApi");
    console.log("tt-----------------------------");
    console.log(tt);   //成功调用下返回{ code: 1, message: 'success', data: null }
  }

  async bankthree() {   //三要素验证
    var params = {
      name: "宋",//姓名 必填
      idno: "341221198504218256",//身份证 必填  
      cardno: "6214850112377038"//银行卡 必填
    };
    var tt = await this.utilesignbaoSve.bankthree(params, "bankinfoAuth");
    console.log("tt-----------------------------");
    console.log(tt);
    return tt;
    // {"code":-110,"message":"手机号格式错误","data":{}}
    //1成功,-110提示验证信息有误，-120亲，提供的信息不正确，请验证后再试！
  }
  async bankfour() {   //四要素验证
    var params = {
      name: "宋毅",//姓名 必填
      idno: "341221198504218256",//身份证 必填
      mobile: "11010929366",//手机号 必填
      cardno: "6214850112377038"//银行卡 必填
    };
    var tt = await this.utilesignbaoSve.bankfour(params, "bankinfoAuth");
    console.log("tt-----------------------------");
    console.log(tt);
    return tt;
    // {"code":-110,"message":"手机号格式错误","data":{}}
    //1成功,-110提示验证信息有误，-120亲，提供的信息不正确，请验证后再试！

  }

  async userSignContractNoTemplate() {  //获取用合同,每次都创建********************************************************************************
    var params = {
      templateId: "2c98d5446734acf5016827d168a6013b",  //模板id，由创建模板接口调用返回的templateId 必填
      name: "汉唐信通（北京）咨询股份有限公司",  //合同模板名称 必填
      simpleFormFields: {
        nameA: "汉唐信通（北京）咨询股份有限公司",    //甲方 必填
        nameB: "高宇强",    //乙方 必填
        unit: "吉林省华生商贸有限公司公主岭华生百货商场-公主岭百货",     //合作单位（国美） 必填---------------------------超出长度风险---目前不知多少长度
        signDateA: "2018-12-09",  //甲方签约日期 必填
        signDateB: "2018-12-09"   //乙方签约日期 必填
      }
    };
    var ebaoAccountId = "9238f57f559b411eb9b4685bc1b903f7";//签署人账户id-- 必填
    var thirdOrderNo = "";//第三方流水号，通知回调使用---选填
    var eSignBaoRedirectBossUrl = "https://boss.gongsibao.com/";
    var tt = await this.utilesignbaoSve.userSignContractNoTemplate(params, ebaoAccountId, thirdOrderNo, eSignBaoRedirectBossUrl, "testApi");
    console.log(tt);
    return tt;
  }


  async createByTemplate() {    //合同模板创建合同
    var params = {
      templateId: "2c98d5446734acf50167927e57710026",  //模板id，由创建模板接口调用返回的templateId 必填
      name: "汉唐信通（北京）咨询股份有限公司",  //合同模板名称 必填
      simpleFormFields: {
        nameA: "汉唐信通（北京）咨询股份有限公司",    //甲方 必填
        nameB: "宋毅",    //乙方 必填
        unit: "国美",     //合作单位（国美） 必填
        signDateA: "2018-12-09",  //甲方签约日期 必填
        signDateB: "2018-12-09"   //乙方签约日期 必填
      }
    };
    var tt = await this.utilesignbaoSve.createByTemplate(params, "testApi");
    console.log(tt, "tt-----------------------------");
    return tt;
  }
  async addProcess() {   //创建合同签署流程
    var params = {
      businessScene: "买房子-张娇",     //业务场景名称-- 必填
      initiatorAccountId: "",     //发起方账户id，默认对接平台,--使用默认的，不用填写
      signValidity: "",     //签署截止时间戳毫秒值-- 选填
      payer: "",     //签署付费方，默认对接平台-- 选填
      signPlatform: "1",    //指定用户签署的平台,空值表示不限平台(1:H5签2:支付宝生活号签3:微信小程序签(后续版本支持))-- 选填
      noticeType: "1",     //用户接收签署任务通知的方式,空值不通知,1短信，2邮箱，格式"1,2"
      redirectUrl: "",     //页面签署完成后跳转地址-------??????TODO:
      docId: "8b2f4c4503c14e14bd1fa42a23281b8d",    //合同id
      docName: ""   //合同名称，默认使用创建合同时的名称-- 选填
    };
    var tt = await this.utilesignbaoSve.addProcess(params, "testApi");
    console.log(tt, "tt-----------------------------");
    return tt;
  }
  async platformSignTask() {         //发起对接平台自动签署
    var params = {
      flowId: "73facea1eadf4b98a8c11a204ac24c8e",   //流程id-- 必填
      posList: [{
        signType: 1,    //盖章位置定位方式,1关键字定位-- 必填
        key: "sealA"//-- 必填
      }]
    };
    var tt = await this.utilesignbaoSve.platformSignTask(params, "testApi");
    console.log(tt, "tt-----------------------------");
    return tt;
  }
  async handPersonSignTask() {   //发起个人手动签署
    var params = {
      flowId: "73facea1eadf4b98a8c11a204ac24c8e",    //流程id-- 必填
      accountId: "97ba4f47aa8248f28f01d07f649348a1",   //签署人账户id-- 必填
      sealType: "0",   //印章类型, 指定签署印章类型,0:手绘印章;1:模板印章-- 必填
      posList: [{
        signType: 1,    //盖章位置定位方式,1关键字定位-- 必填
        key: "sealB"//-- 必填
      }]
    };
    var tt = await this.utilesignbaoSve.handPersonSignTask(params, "testApi");
    console.log(tt, "tt-----------------------------");
    return tt;
  }


  async getContractDetails() {   //合同详情
    var params = {
      flowId: "73facea1eadf4b98a8c11a204ac24c8e"
    };
    var contractDetails = await this.utilesignbaoSve.getContractDetails(params, "testApi");
    console.log(contractDetails, "contractDetails--------------------------->>>>>>>-----------------");
    return contractDetails;

  }

  async archiveProcess() {   //合同归档
    var params = {
      flowId: "0e8688e7c67e4dbc9b178b25bd0bdda7"
    };
    var contractDetails = await this.utilesignbaoSve.getContractDetails(params, "testApi");
    console.log(contractDetails, "contractDetails--------------------------->>>>>>>-----------------");
    var archiveProcess = await this.utilesignbaoSve.archiveProcess(params, "testApi");
    console.log(archiveProcess, "archiveProcess--------------------------->>>>>>>---archiveProcess--------------");

  }

  async getnow() {

    var ttt = moment("2019-01-29").add(-2, "months").format("YYYY-MM-DD");
    console.log(ttt, "ttt..............................");
    var myDate = new Date();
    console.log(myDate, "now time");
    console.log(myDate.toLocaleString(), "......toLocaleString");
    console.log(myDate.toLocaleTimeString(), "......toLocaleTimeString");

    console.log(myDate.getTime(), ".......................num");
    console.log(parseInt(myDate.getTime() / 1000), ".......................num=??????????????????????????????????方案--ok");

    //添加月
    // var newData=await this.AddMouth(myDate.Format("yyyy-MM-dd"),-6);
    var newData = moment().add(-2, "months").format("YYYY-MM-DD")
    console.log(newData, "...........................newData");
    console.log(parseInt(new Date(newData).getTime() / 1000), ".............newData...........................num");



    myDate.setFullYear(myDate.getFullYear() + 1);
    console.log(myDate.toLocaleString(), "......toLocaleString===1");
    console.log(myDate.toLocaleTimeString(), "......toLocaleTimeString===1");
    var t = (new Date()).Format("yyyy-MM-dd")
    var myDateYY = new Date(t);
    console.log(myDateYY, "...............yyyy-MM-dd");
    console.log(myDateYY.getTime(), ".......................num===============1");


    // return Date.now();//---长度13
    // return this.pagestatisticsSve.getRankList("yddpfk",10);
    // var t=(new Date()).Format("yyyy-MM-dd hh:mm:ss");//string
    // console.log(typeof(t));
    // console.log(t);
    // var tt=(new Date()).getTime();//number
    // console.log(typeof(tt));
    // console.log(tt);

    // return Number((new Date()).Format("yyyyMMddHHmmss"));

    // var myDate = new Date();
    // return  myDate.toLocaleString(); //获取日期与时间==="2018-11-5 17:40:21"
    // return  myDate.toLocaleTimeString(); //获取当前时间
    // var year = myDate.getFullYear();
    // var month =myDate.getMonth() + 1;
    //
    // var day = myDate.getDate();
    // console.log("day......................");
    // console.log(day);
    // return new Date("2018-11-5");

    // var param={
    //   applicant_cn:"深圳市凤凰磐涅投资发展有限公司",
    //   page_size:10,
    //   current_page:1
    // }
    // return this.tmutilsSve.tmShortListByApplicantCn(param,"TestApi");
    //
    // var param={
    //   company_name:"发展有限公司",
    //   query_type:"like",
    //   page_size:10,
    //   current_page:1
    // }
    //     // return this.utilsicSve.icDetailsByCompanyName(param,"TestApi");
    // var tt={
    //   applicant_name:"tmp"
    // }
    //
    //     var paCountResult=await this.utilspaSve.paCountByApplicantName(tt);
    //     console.log("tttttttttttttttttttt");
    //     console.log(paCountResult);
    //     console.log(paCountResult.status==0?paCountResult.data[0].fm_count:0);
    //     console.log(paCountResult.status==0?paCountResult.data[0].wg_count:0);
    //     console.log(paCountResult.status==0?paCountResult.data[0].syxx_count:0);
    //     return paCountResult;
  }

  async AddMouth(date, num) {
    //date为格式化后的日期字符yyyy-MM-dd,num为增加的月份
    var monthnum = parseInt(num);
    var year = parseInt(date.substring(0, 4));
    var month = parseInt(date.substring(5, 7));
    var day = parseInt(date.substring(8, 10));
    if (monthnum == 0) {
      return date;
    }
    console.log("monthnum;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
    console.log(monthnum);
    console.log(month - monthnum);
    var newyear = year;
    var newmonth = month;
    var newday = day;
    if (monthnum > 0) {
      if (month + monthnum > 12) {
        newyear = year + 1;
        newmonth = month + monthnum - 12;
        newday = day;
      }
      else {
        newyear = year;
        newmonth = month + monthnum;
        newday = day;
      }
    }
    else {
      if (month + monthnum <= 0) {
        var newyear = year - 1;
        var newmonth = abs(month + monthnum);
        var newday = day;
      }
      else {
        var newyear = year;
        var newmonth = month + monthnum;
        var newday = day;
      }
    }

    var newdate = newyear + "-" + newmonth + "-" + newday;
    return newdate;
  }

  async getuuid() {
    var uuid = uuidv4();
    var u = uuid.replace(/\-/g, "");
    return u;
  }
  async sendMsg() {
    // this.smsClient=System.getObject("util.smsClient");
    // this.smsClient.sendMsg("15010929366","亲爱的知产合伙人，你的客户于"+(new Date()).Format("yyyy-MM-dd")+"发布了新的【商标】需求，亲，赶紧联系客户吧！")
    // this.smsClient.sendMsg("15010929366","亲爱的知产合伙人，你的客户于"+(new Date()).Format("yyyy-MM-dd")+"成功购买【国内商标注册申请】服务，亲，赶紧去自己店铺收钱吧！")
  }
  async getTm(obj) {
    console.log("obj.clientIp....................................");
    console.log(obj.clientIp);
    var tmp =
    // {
    //  "app_code": "31008699",
    //  "channel_order_num": "20181020001"
    //  }	;
    {
      app_code: "31008699",
      channel_user_name: "",
      channel_order_num: "20181020010",
      notify_url: "http://192.168.18.85:3000/api/testApi/test",
      service_item_code: "sbzc",
      tm_form_type: "3",
      ncl_one_codes: "09",
      tm_name: "测试01",
      pic_url: "https://gsb-zc.oss-cn-beijing.aliyuncs.com/zc_word2picbb03236223cf47e99337049a5035798d.jpg",
      tm_name_en: "",
      known: 0,
      tm_value: "2000",
      seal_authorize_stuff: "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_49153969261207820181620233278委托书111.jpg",
      voice_url: "",
      desc_url: "",
      colorized_pic_url: "",
      remark_info: "测试01-remark_info",
      customer_contact: "宋毅",
      customer_mobile: "15010929366",
      notes: "测试01-notes",
      applicants: {
        applicants_type: "ent",
        applicants_name: "汉唐信通(北京)科技有限公司-测试01",
        credit_code: "911101083066224948",
        addr: "北京市海淀区北清路164号17-27号院813号-测试01",
        identitycard_url: "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_49153969261207820181620233278委托书111.jpg",
        businessLicense_url: "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_49153969261207820181620233278委托书111.jpg",
        identitycard: ""
      },
      tm_contact_person: {
        contact_name: "张苗",
        contact_mobile: "18810930720",
        contact_fax: "",
        contact_zipCode: "100020",
        contact_email: ""
      },
      ncl_small_codes: {
        nclthree: [
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090658",
            name: "计算机程序（可下载软件）",
            pcode: "0901"
          },
          {
            code: "090589",
            name: "已录制的计算机操作程序",
            pcode: "0901"
          }
        ]
      }
    };
    let tmpKey = "a95ad36efc064343aff200d18be6637d";
    let appkey = "a7d9872f9c6e4480b8ea45edec660199";
    let keyHex = cryptoJS.enc.Utf8.parse(tmpKey);
    let ivHex = cryptoJS.enc.Utf8.parse(tmpKey.substring(0, 8));
    //data加密
    var cipherDataStr = JSON.stringify(tmp);
    console.log("cipherDataStr...........................................");
    console.log(cipherDataStr);
    var cipherData = cryptoJS.TripleDES.encrypt(cipherDataStr, keyHex, { iv: ivHex }).toString();
    var tmpMess = Math.round(Math.random() * 100000);
    var tmpTimestamp = parseInt(Date.now() / 1000);
    var tmp_sign_type = "sha256";

    var signContent = "data=" + cipherData + "&mess=" + tmpMess + "&timestamp=" + tmpTimestamp + "&key=" + appkey;
    var tmpSign = crypto.createHmac(tmp_sign_type, appkey).update(signContent).digest('hex');

    var reqData = {
      app_code: "31008699",
      data: cipherData,
      mess: tmpMess,
      timestamp: tmpTimestamp,
      sign: tmpSign,
      sign_type: tmp_sign_type
    }

    console.log("reqData------------------------->>>>>>>>>>>>>>>>");
    console.log(reqData);
    var ttReqData = querystring.stringify(reqData);
    console.log("ttReqData------------------------->>>>>>>>>>>>>>>>");
    console.log(ttReqData);
    return reqData;

  }
}
module.exports = TestApi;
