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 reviewScore = weightPdu.reviewWeight().add(staffPerformSummaryEntity.getReviewScore());  //评价分数默认20分扣完为止
        if(reviewScore.compareTo(BigDecimal.ZERO)< 0){
            reviewScore = BigDecimal.ZERO;
        }
        BigDecimal attendScore = weightPdu.attendWeight().add(staffPerformSummaryEntity.getAttendScore()); //考勤
        if(attendScore.compareTo(BigDecimal.ZERO)< 0){
            attendScore = BigDecimal.ZERO;
        }

        BigDecimal otherScore = staffPerformSummaryEntity.getOtherScore();  //其他绩效加分项

        BigDecimal goworkScore = weightPdu.goworkWeight().add(staffPerformSummaryEntity.getGoworkScore());  //办件
        if(goworkScore.compareTo(BigDecimal.ZERO)< 0){
            goworkScore = BigDecimal.ZERO;
        }

        BigDecimal effectScore = weightPdu.effectWeight().add(staffPerformSummaryEntity.getEffectScore());  //效能
        if(effectScore.compareTo(BigDecimal.ZERO)< 0){
            effectScore = BigDecimal.ZERO;
        }

        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);
    }
}
