const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class AppdetailService{
  constructor(){
     this.cacheManager=system.getObject("db.cacheManager");
  }
//app调用次数
  async findAndCountAlldetail(obj){
     var details=[];
     var apicallAccu= await this.cacheManager["ApiAccuCache"].getApiCallAccu(obj);
     var result={rows:[],count:0};
     var keys=await this.cacheManager["MagCache"].keys("api_call_" + obj + "*");
     var detail=null;
     for(let j=0;j<keys.length;j++){
       var d=keys[j];
       var pathdetail=d.substr(d.lastIndexOf("_")+1,d.length);
       var apicalldetailAccu= await this.cacheManager["ApiCallCountCache"].getApiCallCount(obj,pathdetail);
       var detail={"detailPath":d,"detailCount":apicalldetailAccu.callcount,"detailAmount":apicalldetailAccu.amount};
       details.push(detail);
      }
    result.rows=details;
    result.count=details.length;
    return result;
}
  async delCache(obj){
    return this.cacheManager["MagCache"].del(obj.key);
  }
  async clearAllCache(obj){
    return this.cacheManager["MagCache"].clearAll();
  }
}
module.exports=AppdetailService;
