package com.mortals.xhx.common.utils;

import com.mortals.xhx.common.pdu.WeightPdu;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffPerformSummaryEntity;

import java.math.BigDecimal;

/**
 * 员工绩效分数计算
 */
public class StaffPerformUtil {

    /** 群众评议总分 **/
    public static BigDecimal REVIEW_SCORE = new BigDecimal(20);

    public static BigDecimal SCORE100 = new BigDecimal(100);

    public static void computeSummary(StaffPerformSummaryEntity staffPerformSummaryEntity, WeightPdu weightPdu, StaffEntity staffEntity){
        BigDecimal total = new BigDecimal(100);
        BigDecimal reviewScore = REVIEW_SCORE.add(staffPerformSummaryEntity.getReviewScore());  //评价分数默认20分扣完为止
        if(reviewScore.compareTo(BigDecimal.ZERO)< 0){
            reviewScore = BigDecimal.ZERO;
        }
        BigDecimal attendScore = total.add(staffPerformSummaryEntity.getAttendScore()); //考勤
        attendScore = attendScore.multiply(weightPdu.attendWeight());
        BigDecimal otherScore = staffPerformSummaryEntity.getOtherScore();  //其他绩效加分项
//        if(otherScore.compareTo(BigDecimal.ZERO)==0){
//            otherScore = new BigDecimal(100);
//        }
//        otherScore = otherScore.multiply(weightPdu.selfWeight());
        BigDecimal goworkScore = total.add(staffPerformSummaryEntity.getGoworkScore());  //办件
        goworkScore = goworkScore.multiply(weightPdu.goworkWeight());
        BigDecimal effectScore = total.add(staffPerformSummaryEntity.getEffectScore());  //效能
        effectScore = effectScore.multiply(weightPdu.effectWeight());
        BigDecimal complainScore = staffPerformSummaryEntity.getComplainScore();  //自评不用加100
        if(complainScore.compareTo(BigDecimal.ZERO)==0){
            complainScore = SCORE100;
        }
        complainScore = complainScore.multiply(weightPdu.selfWeight());
        BigDecimal summary = new BigDecimal(0);
        if(staffEntity.getReviewCheck()==1) {
            summary = summary.add(reviewScore);
        }
        if(staffEntity.getAttendCheck()==1) {
            summary = summary.add(attendScore);
        }

        summary = summary.add(otherScore);

        if(staffEntity.getEffectCheck()==1){
            summary = summary.add(effectScore);
        }
        if(staffEntity.getGoworkCheck()==1) {
            summary = summary.add(goworkScore);
        }
        if(staffEntity.getComplainCheck()==1){
            summary = summary.add(complainScore);
        }
        staffPerformSummaryEntity.setTotalScore(summary);
    }
}
