"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const egg_1=require("egg"),moment=require("moment");class StatisticMonth extends egg_1.Subscription{static get schedule(){return{cron:"0 4 1 * *",type:"worker",immediate:!1}}async subscribe(){const{ctx:j,ctx:{service:k}}=this,a=moment().subtract(1,"month").format("YYYY-MM"),b=moment().format("YYYY-MM"),c=await k.evaluation.selectRange(a,b);if(0===c.length)return;const l={};c.forEach(f=>{const{stationId:a,excellent:b,good:c,ordinary:d,bad:e,abandoned:g}=f;l[a]||(l[a]={stationId:a,excellent:0,good:0,ordinary:0,bad:0,abandoned:0,sumTrade:0,updateTime:0,score:0}),l[a].excellent+=b,l[a].good+=c,l[a].ordinary+=d,l[a].bad+=e,l[a].abandoned+=g,l[a].sumTrade+=b+c+d+e+g,l[a].updateTime+=1});const d=Object.values(l),e=d.reduce((c,a)=>c+a.sumTrade,0),f=e/d.length;d.forEach(b=>{b.score=k.evaluation.calculateScore(b,b.updateTime,f)}),k.statistic.add(d,a),k.honor.setMonthScoreHonor(d,a),k.honor.setMonthParticipationHonor(d,a),k.honor.setMonthSatisfiedRateHonor(d,a),j.logger.info(`Monthly statistic at ${moment().format("YYYY-MM-DD HH:mm:ss")}`,d)}}module.exports=StatisticMonth;