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 where ncl_one_code is not null and ncl_one_code<>'' limit 1000";
    var tminfos = await this.connectionigirl.query(sql);
    var sources = [];
    if (tminfos[0]) {
      for (var i = 0; i < tminfos[0].length; i++) {
        var tmg = tminfos[0][i].tm_group;
        var strlist = null;
        if (tmg) {
          strlist = tmg.replace(/"/g, "").replace(/\[/g, "").replace(/\]/g, "").split(",");
          if (!strlist) {
            strlist.shift();
          }
        }
        var des = tminfos[0][i].tm_ncl_third.replace(/\[/g, "").replace(/\]/g, "").replace(/\'/g, "");
        var source = {
          beginTime: 1574388139000,
          classificationCode: tminfos[0][i].ncl_one_code,
          description: des,
          endTime: 1668089537981,
          label: "商标标签",
          originalPrice: 10,
          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/20191125_2.json', jsonstr, function (err) {
          if (err) {
            console.error(err);
          }
          console.log('--------------------修改成功11111111111111');
          return resv({ status: 0, msg: "成功" })
        })
      }
      )

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

  }



}
module.exports = TmjsonfileService;
