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 OrgCtl extends CtlBase{
   constructor(){
     super("auth",CtlBase.getServiceName(OrgCtl));
     this.compSvr=system.getObject("service.common.companySve");
   }
   //检查是否已经存在主要岗位
   async checkMainPosition(p,q,req){
    return this.service.checkMainPosition(p,q,req);
   }
   async  changePos(p,q,req){
     var toorgid=p.orgid;
     var uid=p.uid;
     var rtn= await this.service.changePos(toorgid,uid);
     return system.getResult(rtn);
   }
   async create(p,q,req){
  
       return super.create(p,q,req);
   }
   async delete(p,q,req){
    return super.delete(p,q,req);
  }
   async update(p,q,req){
    return super.update(p,q,req);
   }
   async initOrgs(p,q,req){
    var tocompany=req.session.tocompany;
    var cmkey=p.comkey;
    if(cmkey){
      tocompany =await this.compSvr.findOne({companykey:cmkey});
    }
     //按照公司名称查询，是否存在节点，不存在，就创建根节点
     //如果存在就按照名称查询出当前和她的字节点
     var rtn=await this.service.initOrgs(tocompany,req.appid);
     return system.getResult(rtn);
   }
   async findOrgById(p,q,req){
    var rtn=await this.service.findOrgById(p.id);
    return system.getResult(rtn);
   }
}
module.exports=OrgCtl;
