const system=require("../../../system");
const ServiceBase=require("../../sve.base")
const settings=require("../../../../config/settings")
class PmQuestionService extends ServiceBase{
  constructor(){
     super("pm",ServiceBase.getDaoName(PmQuestionService));
    }
  async fetchQuestionForDev(companyid){
    var result=await this.db.query('SELECT solvType ,count(*) as num FROM `pm_question` WHERE company_id =:status group by solvType',
      { replacements: {status:companyid}, type: this.db.QueryTypes.SELECT });
    var personQuestion=await this.db.query('SELECT `p_user`.nickName, GROUP_CONCAT(`pm_question`.solvType)  as name FROM `pm_question` left join `p_user` on `pm_question`.exector_id=`p_user`.id where `pm_question`.company_id=:status group by `pm_question`.exector_id',
      { replacements: {status:companyid}, type: this.db.QueryTypes.SELECT });
    console.log("------fetchQuestionForDev------");
    console.log(result);
    console.log(personQuestion);
    var params=[
      {name:"总计",value:0},
      {name:"待解决",value:0},
      {name:"解决中",value:0},
      {name:"已解决",value:0}
    ];
    var count=0;
    for(var i=0;i<result.length;i++){
      count=count+result[i].num;
      if(result[i].solvType=="waithandle"){
        params[1].value=result[i].num;
      }else if(result[i].solvType=="inmiddle"){
        params[2].value=result[i].num;
      }else if(result[i].solvType=="success"){
        params[3].value=result[i].num;
      }
    }
    params[0].value=count;
    var name=[];var waithandle=[];
    var inmiddle=[];var success=[];
    for(var i=0;i<personQuestion.length;i++){
      console.log(personQuestion[i]);
      name.push(personQuestion[i].nickName);
      var a=personQuestion[i].name.split(",");
      console.log("--------split--------");
      console.log(a);
      var num1=0;var num2=0;var num3=0;
      for(var j=0;j<a.length;j++){
        if(a[j]=="waithandle"){
          num1++;
        }else if(a[j]=="inmiddle"){
          num2++;
        }else if(a[j]=="success"){
          num3++;
        }
      }
      waithandle.push(num1);
      inmiddle.push(num2);
      success.push(num3);
    }
    console.log("----------------------");
    console.log(waithandle);
    console.log(inmiddle);
    console.log(success);
    return {obj1:params,obj2:name,obj3:waithandle,obj4:inmiddle,obj5:success};
  }
}
module.exports=PmQuestionService;
