package com.mortals.xhx.module.check.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.pdu.WeightPdu;
import com.mortals.xhx.common.utils.AuditUtil;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.check.dao.CheckEffectRecordDao;
import com.mortals.xhx.module.check.model.CheckComplainRecordEntity;
import com.mortals.xhx.module.check.model.CheckEffectRecordEntity;
import com.mortals.xhx.module.check.model.CheckGoworkRecordEntity;
import com.mortals.xhx.module.check.model.vo.StaffCheckSummaryQuery;
import com.mortals.xhx.module.check.model.vo.StaffCheckSummaryVo;
import com.mortals.xhx.module.check.service.CheckEffectRecordService;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptPerformStatEntity;
import com.mortals.xhx.module.dept.model.DeptPerformStatQuery;
import com.mortals.xhx.module.dept.service.DeptPerformStatService;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.dingding.CheckDingMsg;
import com.mortals.xhx.module.dingding.personal.service.IDingPersonService;
import com.mortals.xhx.module.perform.model.PerformComplainRecordEntity;
import com.mortals.xhx.module.perform.model.PerformEffectRecordEntity;
import com.mortals.xhx.module.perform.model.PerformRulesEntity;
import com.mortals.xhx.module.perform.service.PerformEffectRecordService;
import com.mortals.xhx.module.perform.service.PerformRulesService;
import com.mortals.xhx.module.staff.model.*;
import com.mortals.xhx.module.staff.service.StaffPerformStatService;
import com.mortals.xhx.module.staff.service.StaffPerformSummaryService;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import static com.mortals.xhx.common.key.ParamKey.SYS_PARAM_WEIGHT;
import static com.mortals.xhx.common.key.RedisKey.KEY_CHECK_SUMMARY_CACHE;

/**
* CheckEffectRecordService
* 效能绩效核查信息 service实现
*
* @author zxfei
* @date 2023-07-11
*/
@Service("checkEffectRecordService")
@Slf4j
public class CheckEffectRecordServiceImpl extends AbstractCRUDServiceImpl<CheckEffectRecordDao, CheckEffectRecordEntity, Long> implements CheckEffectRecordService {

    @Autowired
    private StaffPerformSummaryService staffPerformSummaryService;
    @Autowired
    private IDingPersonService dingPersonService;
    @Autowired
    private StaffService staffService;
    @Autowired
    private MessageService messageService;
    @Autowired
    private StaffPerformStatService staffPerformStatService;
    @Autowired
    private DeptPerformStatService deptPerformStatService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private PerformEffectRecordService recordService;

    @Autowired
    private PerformRulesService rulesService;
    @Autowired
    private ParamService paramService;
    @Autowired
    private ICacheService cacheService;

    @Override
    protected void saveBefore(CheckEffectRecordEntity entity, Context context) throws AppException {
        updateStaffRuleNames(entity);
    }

    @Override
    protected void updateBefore(CheckEffectRecordEntity entity, Context context) throws AppException {
        updateStaffRuleNames(entity);
    }


    private void updateStaffRuleNames(CheckEffectRecordEntity entity) {
        if (!ObjectUtils.isEmpty(entity.getRuleId())) {
            PerformRulesEntity rulesEntity = rulesService.getCache(entity.getRuleId().toString());
            entity.setRuleName(rulesEntity.getName());
        }
        if (!ObjectUtils.isEmpty(entity.getStaffId())) {
            StaffEntity staffCache = staffService.getCache(entity.getStaffId().toString());
            entity.setStaffName(staffCache == null ? "" : staffCache.getName());
            entity.setDeptName(staffCache == null ? "" : staffCache.getDeptName());
        }
    }


    @Override
    protected void saveAfter(CheckEffectRecordEntity entity, Context context) throws AppException {
        //发送钉钉通知信息
        try{
            StaffCheckSummaryQuery query = new StaffCheckSummaryQuery();
            query.setStaffId(entity.getStaffId());
            query.setCheckTimeStart(DateUtils.getStrDate(entity.getCheckTime()));
            query.setCheckTimeEnd(query.getCheckTimeStart());
            query.setCheckType(CheckTypeEnum.效能绩效.getValue());
            cacheService.lpush(KEY_CHECK_SUMMARY_CACHE, query);
            //summaryCheck(query);
        }catch (Exception e){
            log.error("汇总已审核的核查记录出错",e);
        }
    }


    private void sendCheckDingTalk(CheckEffectRecordEntity entity) {
        String ruleStr = String.format("%s/%s/%s", PerformTypeEnum.效能绩效.getDesc(), entity.getCategoryName(), entity.getRuleName());
        //绩效核查通知
        StaffEntity staffCache = staffService.getCache(entity.getStaffId().toString());
        if (!ObjectUtils.isEmpty(staffCache)) {
            Rest<String> personRest = dingPersonService.getPersonByMobile(staffCache.getPhoneNumber());
            if (YesNoEnum.YES.getValue() == personRest.getCode()) {
                CheckDingMsg checkDingMsg = new CheckDingMsg();
                checkDingMsg.setUserIds(personRest.getData());
                checkDingMsg.setDateTime(DateUtil.formatDateTime(entity.getHappenTime() == null ? new Date() : entity.getHappenTime()));
                checkDingMsg.setRuleStr(ruleStr);
                checkDingMsg.setPerformTypeStr(PerformTypeEnum.办件绩效.getDesc());
                checkDingMsg.setScore(entity.getScore().toString());
                checkDingMsg.setSubAddType(entity.getSubAddType());
               // checkDingMsg.setPath(String.format("/api/v1/perform/info?id=%s&&performType=effect", entity.getId()));
                checkDingMsg.setPath(String.format("#/appealinfo?id=%s&&performType=%s&subAddType=%s", entity.getId(),PerformTypeEnum.效能绩效.getValue(),entity.getSubAddType()));
              //  checkDingMsg.setPath(String.format("/api/v1/perform/info?id=%s&&performType=effect", entity.getId()));
                Rest<String> msgRest = messageService.sendDingTalkWorkMsg(checkDingMsg);
            } else {
                log.error("根据手机号码获取人员错误，msg:{}", personRest.getMsg());
            }
        } else {
            log.error("员工未找到,staffId:{}", entity.getStaffId());
        }
    }


    @Override
    public void examine(CheckEffectRecordEntity entity, Context context) throws AppException {
        if(entity.getId()==null){
            throw new AppException("核查记录ID不能为空");
        }
        CheckEffectRecordEntity temp = this.get(entity.getId());
        if (temp == null) {
            throw new AppException("核查记录ID不正确");
        }
        if (context != null && context.getUser()!=null) {
            IUser user = context.getUser();
            entity.setUpdateUserId(user.getId());
            entity.setCheckPerson(user.getRealName());
        }
        if(!ObjectUtils.isEmpty(entity.getSubAddType())&&!ObjectUtils.isEmpty(entity.getCheckResult())){
            AuditUtil.audit(entity);
        }
        entity.setCheckTime(temp.getHappenTime());
        entity.setUpdateTime(new Date());
        entity.setCheckStatus(CheckStatusEnum.已处理.getValue()); //处理状态(1.未处理,2.已处理)
        dao.update(entity);
        try{
            if(!ObjectUtils.isEmpty(temp.getRecordId())){
                PerformEffectRecordEntity recordEntity = recordService.get(temp.getRecordId());
                if(!ObjectUtils.isEmpty(recordEntity)){
                    recordEntity.setProcessStatus(ProcessStatusEnum.已处理.getValue());
                    recordEntity.setUpdateTime(new Date());
                    recordEntity.setUpdateUserId(this.getContextUserId(context));
                    recordService.update(recordEntity);
                }
            }

            sendCheckDingTalk(temp);
            StaffCheckSummaryQuery query = new StaffCheckSummaryQuery();
            query.setStaffId(temp.getStaffId());
            query.setCheckTimeStart(DateUtils.getStrDate(entity.getCheckTime()));
            query.setCheckTimeEnd(query.getCheckTimeStart());
            query.setCheckType(CheckTypeEnum.效能绩效.getValue());
            cacheService.lpush(KEY_CHECK_SUMMARY_CACHE, query);
            //summaryCheck(query);
        }catch (Exception e){
            log.error("汇总已审核的核查记录出错",e);
        }
    }

    @Override
    public List<StaffCheckSummaryVo> summaryCheck(StaffCheckSummaryQuery query) throws AppException {
        if(StringUtils.isEmpty(query.getCheckTimeStart())||StringUtils.isEmpty(query.getCheckTimeStart())){
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar=Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String startTime = format.format(calendar.getTime());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            String endTime = format.format(calendar.getTime());
            query.setCheckTimeStart(startTime);
            query.setCheckTimeEnd(endTime);
        }
        List<StaffCheckSummaryVo> summaryVoList = dao.summaryCheck(query);
        if(CollectionUtils.isNotEmpty(summaryVoList)){
            String value = paramService.getValueByKey(SYS_PARAM_WEIGHT);
            WeightPdu weightPdu;
            if (ObjectUtils.isEmpty(value)){
                weightPdu = new WeightPdu();
            }else {
                weightPdu = JSONObject.parseObject(value,WeightPdu.class);
            }
            for(StaffCheckSummaryVo vo:summaryVoList){
                StaffEntity staffEntity = staffService.get(vo.getStaffId());
                if(staffEntity.getStatus() == StaffSatusEnum.离职.getValue()) {
                    if(staffEntity.getLeaveDate()!=null){
                        String leaveDateStr = DateUtils.getStrDate(staffEntity.getLeaveDate());
                        String month = vo.getMonth()>9?String.valueOf(vo.getMonth()):"0"+vo.getMonth();
                        String summaryDate = vo.getYear()+"-"+month+"-01";
                        if(DateUtils.StrToDate(leaveDateStr).compareTo(DateUtils.StrToDate(summaryDate)) < 0){
                            //离职日期在统计日期之前不统计
                            continue;
                        }
                    }
                }
                if(staffEntity.getAttendCheck()==0 && staffEntity.getEffectCheck()==0 && staffEntity.getGoworkCheck()==0 && staffEntity.getComplainCheck()==0){
                    continue;
                }
                StaffPerformSummaryEntity staffPerformSummaryEntity = new StaffPerformSummaryEntity();
                staffPerformSummaryEntity.initAttrValue();
                BeanUtils.copyProperties(vo,staffPerformSummaryEntity, BeanUtil.getNullPropertyNames(vo));
                staffPerformSummaryEntity.setEffectScore(vo.getSumScore());
                StaffPerformSummaryQuery summaryQuery = new StaffPerformSummaryQuery();
                summaryQuery.setStaffId(vo.getStaffId());
                summaryQuery.setYear(vo.getYear());
                summaryQuery.setMonth(vo.getMonth());
                StaffPerformSummaryEntity temp = staffPerformSummaryService.selectOne(summaryQuery);
                if(temp!=null){
                    if(temp.getReviewScore()!=null){
                        staffPerformSummaryEntity.setReviewScore(temp.getReviewScore());
                    }
                    if(temp.getOtherScore()!=null){
                        staffPerformSummaryEntity.setOtherScore(temp.getOtherScore());
                    }
                    if(temp.getGoworkScore()!=null){
                        staffPerformSummaryEntity.setGoworkScore(temp.getGoworkScore());
                    }
                    if(temp.getAttendScore()!=null){
                        staffPerformSummaryEntity.setAttendScore(temp.getAttendScore());
                    }
                    if (temp.getComplainScore() != null) {
                        staffPerformSummaryEntity.setComplainScore(temp.getComplainScore());
                    }
                    BigDecimal erro = new BigDecimal(0);
                    erro = erro.add(staffPerformSummaryEntity.getReviewScore());
                    erro = erro.add(staffPerformSummaryEntity.getAttendScore());
                    if(staffPerformSummaryEntity.getOtherScore().compareTo(BigDecimal.ZERO)!=0){
                        BigDecimal Score100 = new BigDecimal(100);
                        BigDecimal otherScoreErro = Score100.subtract(staffPerformSummaryEntity.getOtherScore());
                        erro = erro.add(BigDecimal.ZERO.subtract(otherScoreErro));
                    }
                    erro = erro.add(staffPerformSummaryEntity.getGoworkScore());
                    erro = erro.add(staffPerformSummaryEntity.getEffectScore());
                    erro = erro.add(staffPerformSummaryEntity.getComplainScore());
                    staffPerformSummaryEntity.setErrorScore(erro);
//                    BigDecimal total = new BigDecimal(100);
//                    staffPerformSummaryEntity.setTotalScore(total.add(erro));
                    computeSummary(staffPerformSummaryEntity,weightPdu,staffEntity);
                    staffPerformSummaryEntity.setId(temp.getId());
                    staffPerformSummaryEntity.setUpdateTime(new Date());
                    staffPerformSummaryService.update(staffPerformSummaryEntity);
                }else {
                    staffPerformSummaryEntity.setAttendScore(new BigDecimal(0));
                    staffPerformSummaryEntity.setReviewScore(new BigDecimal(0));
                    staffPerformSummaryEntity.setOtherScore(new BigDecimal(0));
                    staffPerformSummaryEntity.setGoworkScore(new BigDecimal(0));
                    staffPerformSummaryEntity.setComplainScore(new BigDecimal(0));
                    staffPerformSummaryEntity.setErrorScore(vo.getSumScore());
//                    BigDecimal total = new BigDecimal(100);
//                    staffPerformSummaryEntity.setTotalScore(total.add(vo.getSumScore()));
                    computeSummary(staffPerformSummaryEntity,weightPdu,staffEntity);
                    staffPerformSummaryEntity.setCreateUserId(1l);
                    staffPerformSummaryEntity.setCreateTime(new Date());
                    staffPerformSummaryService.save(staffPerformSummaryEntity);
                }

            }
        }
        doSaveStaffPerformStat(query);
        doSaveDeptPerformStat(query);
        return summaryVoList;
    }

    @Override
    public void doSaveStaffPerformStat(StaffCheckSummaryQuery query) {
        if (StringUtils.isEmpty(query.getCheckTimeStart()) || StringUtils.isEmpty(query.getCheckTimeStart())) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String startTime = format.format(calendar.getTime());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            String endTime = format.format(calendar.getTime());
            query.setCheckTimeStart(startTime);
            query.setCheckTimeEnd(endTime);
        }
        List<StaffPerformStatEntity> performStatList = dao.getStaffPerformStat(query);
        if(CollectionUtils.isNotEmpty(performStatList)){
            for(StaffPerformStatEntity entity:performStatList) {
                StaffEntity staffEntity = staffService.get(entity.getStaffId());
                if(staffEntity.getAttendCheck()==0 && staffEntity.getEffectCheck()==0 && staffEntity.getGoworkCheck()==0 && staffEntity.getComplainCheck()==0){
                    continue;
                }
                StaffPerformStatQuery tempQuery = new StaffPerformStatQuery();
                tempQuery.setStaffId(entity.getStaffId());
                tempQuery.setYear(entity.getYear());
                tempQuery.setMonth(entity.getMonth());
                tempQuery.setDay(entity.getDay());
                StaffPerformStatEntity temp = staffPerformStatService.selectOne(tempQuery);
                if (temp != null) {
                    StaffPerformStatEntity statEntity = new StaffPerformStatEntity();
                    statEntity.initAttrValue();
                    BeanUtils.copyProperties(temp, statEntity, BeanUtil.getNullPropertyNames(temp));
                    statEntity.setId(temp.getId());
                    statEntity.setUpdateTime(new Date());
                    statEntity.setEffectScoreAdd(entity.getEffectScoreAdd());
                    statEntity.setEffectScoreSub(entity.getEffectScoreSub());
                    computeStaff(statEntity);
                    staffPerformStatService.update(statEntity);
                }else {
                    StaffPerformStatEntity statEntity = new StaffPerformStatEntity();
                    statEntity.initAttrValue();
                    BeanUtils.copyProperties(entity, statEntity, BeanUtil.getNullPropertyNames(entity));
                    statEntity.setId(null);
                    computeStaff(statEntity);
                    statEntity.setCreateUserId(1l);
                    statEntity.setCreateTime(new Date());
                    staffPerformStatService.save(statEntity);
                }
            }
        }
    }

    @Override
    public void doSaveDeptPerformStat(StaffCheckSummaryQuery query) {
        if (StringUtils.isEmpty(query.getCheckTimeStart()) || StringUtils.isEmpty(query.getCheckTimeStart())) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String startTime = format.format(calendar.getTime());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            String endTime = format.format(calendar.getTime());
            query.setCheckTimeStart(startTime);
            query.setCheckTimeEnd(endTime);
        }
        List<DeptPerformStatEntity> performStatList = dao.getDeptPerformStat(query);
        if(CollectionUtils.isNotEmpty(performStatList)){
            for(DeptPerformStatEntity entity:performStatList) {
                DeptPerformStatQuery tempQuery = new DeptPerformStatQuery();
                tempQuery.setDeptId(entity.getDeptId());
                tempQuery.setYear(entity.getYear());
                tempQuery.setMonth(entity.getMonth());
                tempQuery.setDay(entity.getDay());
                DeptPerformStatEntity temp = deptPerformStatService.selectOne(tempQuery);
                if (temp != null) {
                    DeptPerformStatEntity statEntity = new DeptPerformStatEntity();
                    statEntity.initAttrValue();
                    BeanUtils.copyProperties(temp, statEntity, BeanUtil.getNullPropertyNames(temp));
                    statEntity.setId(temp.getId());
                    statEntity.setUpdateTime(new Date());
                    statEntity.setEffectScoreAdd(entity.getEffectScoreAdd());
                    statEntity.setEffectScoreSub(entity.getEffectScoreSub());
                    computeDept(statEntity);
                    deptPerformStatService.update(statEntity);
                }else {
                    DeptPerformStatEntity statEntity = new DeptPerformStatEntity();
                    statEntity.initAttrValue();
                    BeanUtils.copyProperties(entity, statEntity, BeanUtil.getNullPropertyNames(entity));
                    statEntity.setId(null);
                    computeDept(statEntity);
                    statEntity.setCreateUserId(1l);
                    statEntity.setCreateTime(new Date());
                    deptPerformStatService.save(statEntity);
                }
            }
        }
    }

    private void computeStaff(StaffPerformStatEntity statEntity){
        BigDecimal totalAddScore = new BigDecimal(0);
        BigDecimal totalSubScore = new BigDecimal(0);
        BigDecimal totalScore = new BigDecimal(100);
        totalAddScore = totalAddScore.add(statEntity.getAttendScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getAttendScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getComplainScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getComplainScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getReviewScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getReviewScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getGoworkScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getGoworkScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getEffectScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getEffectScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getOtherScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getOtherScoreSub());
        statEntity.setTotalAddScore(totalAddScore);
        statEntity.setTotalSubScore(totalSubScore);
        totalScore = totalScore.add(totalAddScore);
        totalScore = totalScore.subtract(totalSubScore);
        statEntity.setTotalScore(totalScore);
    }

    private void computeDept(DeptPerformStatEntity statEntity){
        DeptEntity deptEntity = deptService.get(statEntity.getDeptId());
        BigDecimal totalAddScore = new BigDecimal(0);
        BigDecimal totalSubScore = new BigDecimal(0);
        BigDecimal totalScore = new BigDecimal(100);
        if(deptEntity!=null){
            totalScore = totalScore.multiply(new BigDecimal(deptEntity.getPersonNum()));
        }else {
            totalScore = totalScore.multiply(new BigDecimal(10));
        }
        totalAddScore = totalAddScore.add(statEntity.getAttendScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getAttendScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getComplainScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getComplainScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getReviewScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getReviewScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getGoworkScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getGoworkScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getEffectScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getEffectScoreSub());
        totalAddScore = totalAddScore.add(statEntity.getOtherScoreAdd());
        totalSubScore = totalSubScore.add(statEntity.getOtherScoreSub());
        statEntity.setTotalAddScore(totalAddScore);
        statEntity.setTotalSubScore(totalSubScore);
        totalScore = totalScore.add(totalAddScore);
        totalScore = totalScore.subtract(totalSubScore);
        statEntity.setTotalScore(totalScore);
    }

    private void computeSummary(StaffPerformSummaryEntity staffPerformSummaryEntity, WeightPdu weightPdu,StaffEntity staffEntity){
        BigDecimal total = new BigDecimal(100);
        BigDecimal reviewScore = total.add(staffPerformSummaryEntity.getReviewScore());  //评价
        reviewScore = reviewScore.multiply(weightPdu.reviewWeight());
        BigDecimal attendScore = total.add(staffPerformSummaryEntity.getAttendScore()); //考勤
        attendScore = attendScore.multiply(weightPdu.attendWeight());
        BigDecimal otherScore = staffPerformSummaryEntity.getOtherScore();  //自评不用加100
        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 = complainScore = total.add(staffPerformSummaryEntity.getComplainScore());  //投诉
        BigDecimal summary = new BigDecimal(0);
        if(staffEntity.getReviewCheck()==1) {
            summary = summary.add(reviewScore);
        }
        if(staffEntity.getAttendCheck()==1) {
            summary = summary.add(attendScore);
        }
        if(staffEntity.getOtherCheck()==1) {
            summary = summary.add(otherScore);
        }
        if(staffEntity.getEffectCheck()==1){
            summary = summary.add(effectScore);
        }
        if(staffEntity.getGoworkCheck()==1) {
            summary = summary.add(goworkScore);
        }
        staffPerformSummaryEntity.setTotalScore(summary);
    }
}