const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class UserCache extends CacheBase{
  constructor(){
    super();
    this.userDao=system.getObject("db.auth.userDao");
  }
  isdebug(){
   return settings.env=="dev";
 }
  desc(){
    return "缓存本地应用对象";
 }
 prefix(){
    return "g_userlocal_"
 }
 async buildCacheVal(cachekey,inputkey, val, ex, ...items) {
   const configValue = await this.userDao.model.findAll({
    where: { userName: inputkey, app_id: settings.pmappid },
    attributes: ['id','userName', 'nickName','headUrl','jwtkey','jwtsecret','created_at','isSuper','isAdmin','mail'],
    include: [
      { model: this.db.models.company,raw:true},
      {model:this.db.models.role,as:"Roles",attributes:["id","code"],}
    ],
  });
   
   if (configValue && configValue[0]) {
     return JSON.stringify(configValue[0]);
   }
   return null;
 }
}
module.exports=UserCache;