var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");

class TmjsonfileCtl extends CtlBase {
  constructor() {
    super("transfer", CtlBase.getServiceName(TmjsonfileCtl));
  }
  async createjsonfile(p, o, q) {
    var rtn = await this.service.createjsonfile();
    console.log(rtn);
    if (rtn.status > -1) {
      var oss = system.getObject("util.ossClient");
      var newdate = new Date();
      var m = newdate.getMonth() + 1;
      var d = newdate.getDate();
      var strdate = ""
      if (newdate.getHours() > 12) {
        strdate = newdate.getFullYear() + "" + m + d + "_2.json";
      } else {
        strdate = newdate.getFullYear() + "" + m + d + "_1.json";
      }
      var result = await oss.upfile(strdate, "/tmp/20191112_2.json");
      if (result.res.status > -1) {
        var obj = { zc_url: result.url };
        var s = await this.service.create(obj);
        if (s) {
          return { status: 0, msg: "成功" };
        }
      }else{
        return { status:-201, msg: "创建失败" };
      }
    }else{
      return { status:-200, msg: "json文件生成失败" };
    }
  }

}
module.exports = TmjsonfileCtl;
