var system=require("../../system")
var settings=require("../../../config/settings");
const CtlBase = require("../ctl.base");
const uuidv4 = require('uuid/v4');
class AppCtl extends CtlBase{
   constructor(){
     super(CtlBase.getServiceName(AppCtl));
     //this.appS=system.getObject("service.appSve");
     this.newschanneS=system.getObject("service.newschannelSve");
     this.servicesitem=system.getObject("service.servicesitemSve");
     this.loopplayS=system.getObject("service.loopplaySve");
   }

   async initNewInstance(queryobj,qobj){
     var u=uuidv4();
     var aid=u.replace(/\-/g,"");
     var rd={name:"",appid:aid}
     return system.getResult2(rd,null);
   }
   async findHomeInitData(queryobj,qobj){
     var newschannels=await this.newschanneS.findPrev5();
     //var servicesitems=await this.servicesitem.findService5();
     var onlines=await this.cacheManager["VisitCountCache"].findOnlines();
     qobj.appid=settings.wxconfig.appId;
     //var loopplays=await this.loopplayS.findAndCountAll(qobj);
     //var app=await this.cacheManager["AppCache"].cacheApp(settings.wxconfig.appId);
     var app=await this.service.findOne(settings.wxconfig.appId);
     var rtn={};
     rtn.logoUrl=app.logoUrl;
     rtn.appimgUrl=app.appimgUrl;
     rtn.news=newschannels;
     //rtn.servicesitem=servicesitems;
     rtn.onlines=onlines;
     //rtn.loopplays=loopplays;
     return system.getResult2(rtn,null);
   }
}
module.exports=AppCtl;
