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 id=175342";
    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(",");
          for(var n=0;n<strlist.length;n++){
            if (!strlist[n]) {
              strlist.shift();
            }
          }
        }
        var des = "";
        if(tminfos[0][i].tm_ncl_third){
          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:  parseInt(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 strdate = ""
      if (newdate.getHours() > 12) {
        strdate = newdate.getFullYear() + "" + m + d + "_2.json";
      } else {
        strdate = newdate.getFullYear() + "" + m + d + "_1.json";
      }
      var jsonstr = JSON.stringify(sources, null, "\t");
      return new Promise(function (resv, rej) {
        fs.writeFile('/tmp/'+strdate, jsonstr, function (err) {
          if (err) {
            console.error(err);
          }
          console.log('--------------------修改成功11111111111111');
          return resv({ status: 0, msg: "成功" })
        })
      }
      )

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

  }



}
module.exports = TmjsonfileService;
