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");
const md5 = require("MD5");
const uuidv4 = require('uuid/v4');
const crypto = require('crypto');

var cacheBaseComp = null;
class TcompanytaxitemCtl extends CtlBase {
  constructor() {
    super("tax", CtlBase.getServiceName(TcompanytaxitemCtl));
    this.redisClient = system.getObject("util.redisClient");
  }

  async taxPage(pobj, pobj2, req, res) {
    let loginInfo = req.loginUser || {};
    let month = this.trim(pobj.month);
    if (month) {
      month = Number(month.replace("-", ""));
    }
    let condition = {
      currentPage: pobj.currentPage,
      pageSize: pobj.pageSize,
      month: month || 0,
      companyId: loginInfo.user.companyId,
      idName: pobj.idName,
      idNo: pobj.idNo,
    }

    try {
      var page = await this.service.pageByCondition(condition);
      return system.getResultSuccess(page);
    } catch (error) {
      console.log(error);
      return system.getResult(-1, `服务异常`);
    }
  }

  async taxUrl(pobj, pobj2, req, res) {
    let id = pobj.id;
    try {
      let item = await this.service.findById(id);
      if(!item) {
        return system.getResult(null, "税务信息不存在");
      }
      
      // TODO 请求张云飞
      item.last_at = new Date();
      item.save();
      return system.getResultSuccess({
        taxUrl: "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_7511582721898214202026205818214tfb_month_12.pdf"
      });
    } catch (error) {
      console.log(error);
      return system.getResult(-1, `服务异常`);
    }
  }
}
module.exports = TcompanytaxitemCtl;