const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
var RPCClient = require('@alicloud/pop-core').RPCClient;
var OSS = require('ali-oss');
const crypto = require('crypto');
var fs = require('fs');
class TmjsonfileService extends ServiceBase {
  constructor() {
    super("transfer", ServiceBase.getDaoName(TmjsonfileService));
    this.connectionigirl = system.getObject("db.common.connection").getConigirl();

  }

  async createjsonfile() {
    var sql = "select * from bi_trademarktransaction limit 1000";
    var tminfos = await this.connectionigirl.query(sql);
    var sources = [];
    if (tminfos[0]) {
      for (var i = 0; i < tminfos[0].length; i++) {
        var a = tminfos[0][i].tm_group;
        var strlist = null;
        if (a) {
          strlist = a.replace(/"/g, "").replace(/\[/g, "").replace(/\]/g, "").split(",");
          if (!strlist[0]) {
            strlist.shift();
          }
        }
        var source = {
          beginTime: 1558059537981,
          classificationCode: tminfos[0][i].ncl_one_code,
          description: "",
          endTime: 1558069537981,
          label: "商标标签",
          originalPrice: tminfos[0][i].platform_quoted_price,
          ownerEnName: "",
          ownerName: tminfos[0][i].tm_applier,
          partnerCode: "gong_si_bao",
          regAnnDate: tminfos[0][i].tm_regist_day * 1000,
          secondaryClassification: strlist,
          status: 1,
          thirdClassification: tminfos[0][i].tm_ncl_third,
          tmIcon: tminfos[0][i].pic_url,
          tmName: tminfos[0][i].name,
          tmNumber: tminfos[0][i].code
        }
        sources.push(source);
      }
      var jsonstr = JSON.stringify(sources, null, "\t");
      return new Promise(function (resv, rej) {
        fs.writeFile('/tmp/20191112_2.json', jsonstr, function (err) {
          if (err) {
            console.error(err);
          }
          console.log('--------------------修改成功11111111111111');
          return resv({ status: 0, msg: "成功" })
        })
      }
      )

      console.log('--------------------修改成功');
    }

  }



}
module.exports = TmjsonfileService;
