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.common.utils.StaffPerformUtil;
import com.mortals.xhx.module.check.dao.CheckGoworkRecordDao;
import com.mortals.xhx.module.check.model.CheckEffectRecordEntity;
import com.mortals.xhx.module.check.model.CheckGoworkRecordEntity;
import com.mortals.xhx.module.check.model.CheckOtherRecordEntity;
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.CheckGoworkRecordService;
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.*;
import com.mortals.xhx.module.perform.service.PerformErrorMessageService;
import com.mortals.xhx.module.perform.service.PerformGoworkRecordService;
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.Arrays;
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;

/**
* CheckGoworkRecordService
* 办件绩效核查信息 service实现
*
* @author zxfei
* @date 2023-07-11
*/
@Service("checkGoworkRecordService")
@Slf4j
public class CheckGoworkRecordServiceImpl extends AbstractCRUDServiceImpl<CheckGoworkRecordDao, CheckGoworkRecordEntity, Long> implements CheckGoworkRecordService {

    @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 PerformGoworkRecordService recordService;

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

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

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


    private void updateStaffRuleNames(CheckGoworkRecordEntity 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(CheckGoworkRecordEntity entity, Context context) throws AppException {
        //添加绩效异常信息
        try {
            if(entity.getRemark().indexOf("申诉成功") < 0) {
                PerformErrorMessageEntity errorMessageEntity = new PerformErrorMessageEntity();
                errorMessageEntity.initAttrValue();
                BeanUtils.copyProperties(entity, errorMessageEntity, BeanUtil.getNullPropertyNames(entity));
                errorMessageEntity.setCheckRecordId(entity.getId());
                errorMessageEntity.setErrorTime(entity.getGoworkTime());
                errorMessageEntity.setPerformType(PerformTypeEnum.办件绩效.getValue());
                performErrorMessageService.save(errorMessageEntity);
            }
        }catch (Exception e) {
            log.error("新增绩效异常信息核查状态出错", e);
        }
    }

    @Override
    protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
        try {
            PerformErrorMessageQuery query = new PerformErrorMessageQuery();
            query.setPerformType(PerformTypeEnum.办件绩效.getValue());
            query.setCheckRecordIdList(Arrays.asList(ids));
            List<PerformErrorMessageEntity> errorList = performErrorMessageService.find(query);
            if (CollectionUtils.isNotEmpty(errorList)) {
                Long[] deleteIds = errorList.stream().map(i -> i.getId()).toArray(Long[]::new);
                performErrorMessageService.remove(deleteIds, context);
            }
        }catch (Exception e){
            log.error("删除绩效异常信息核查状态出错", e);
        }
    }

    private void sendCheckDingTalk(CheckGoworkRecordEntity 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.getGoworkTime() == null ? new Date() : entity.getGoworkTime()));
                checkDingMsg.setRuleStr(ruleStr);
                checkDingMsg.setPerformTypeStr(PerformTypeEnum.办件绩效.getDesc());
                checkDingMsg.setScore(entity.getScore().toString());
                checkDingMsg.setSubAddType(entity.getSubAddType());
                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=gowork", entity.getId()));
                Rest<String> msgRest = messageService.sendDingTalkWorkMsg(checkDingMsg);
            } else {
                log.error("根据手机号码获取人员错误，msg:{}", personRest.getMsg());
            }
        } else {
            log.error("员工未找到,staffId:{}", entity.getStaffId());
        }
    }

    @Override
    public void examine(CheckGoworkRecordEntity entity, Context context) throws AppException {
        if(entity.getId()==null){
            throw new AppException("核查记录ID不能为空");
        }
        CheckGoworkRecordEntity 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.getGoworkTime());
        entity.setUpdateTime(new Date());
        entity.setCheckStatus(CheckStatusEnum.已处理.getValue()); //处理状态(1.未处理,2.已处理)
        dao.update(entity);
        //更新绩效异常信息核查状态
        try {
            PerformErrorMessageEntity errorMessageEntity = performErrorMessageService.selectOne(new PerformErrorMessageQuery().checkRecordId(entity.getId()).performType(PerformTypeEnum.办件绩效.getValue()));
            if(errorMessageEntity!=null){
                PerformErrorMessageEntity updateEntity = new PerformErrorMessageEntity();
                updateEntity.setId(errorMessageEntity.getId());
                updateEntity.setCheckStatus(CheckStatusEnum.已处理.getValue());
                updateEntity.setCheckTime(entity.getCheckTime());
                updateEntity.setUpdateTime(new Date());
                performErrorMessageService.update(updateEntity);
            }
        }catch (Exception e){
            log.error("更新绩效异常信息核查状态出错", e);
        }
        //发送钉钉通知信息
        try{
            if(!ObjectUtils.isEmpty(temp.getRecordId())){
                PerformGoworkRecordEntity 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.setGoworkScore(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){
                    staffPerformSummaryEntity.setRemarkAdd(temp.getRemarkAdd());
                    staffPerformSummaryEntity.setRemark(temp.getRemark());
                    staffPerformSummaryEntity.setAddTotalScore(temp.getAddTotalScore());
                    if(temp.getReviewScore()!=null){
                        staffPerformSummaryEntity.setReviewScore(temp.getReviewScore());
                    }
                    if(temp.getOtherScore()!=null){
                        staffPerformSummaryEntity.setOtherScore(temp.getOtherScore());
                    }
                    if(temp.getAttendScore()!=null){
                        staffPerformSummaryEntity.setAttendScore(temp.getAttendScore());
                    }
                    if(temp.getEffectScore()!=null){
                        staffPerformSummaryEntity.setEffectScore(temp.getEffectScore());
                    }
                    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.getComplainScore().compareTo(BigDecimal.ZERO)!=0){
                        BigDecimal complainScoreErro = StaffPerformUtil.SCORE100.subtract(staffPerformSummaryEntity.getComplainScore());
                        erro = erro.add(BigDecimal.ZERO.subtract(complainScoreErro));
                    }
                    erro = erro.add(staffPerformSummaryEntity.getGoworkScore());
                    erro = erro.add(staffPerformSummaryEntity.getEffectScore());
                    staffPerformSummaryEntity.setErrorScore(erro);
                    StaffPerformUtil.computeSummary(staffPerformSummaryEntity,weightPdu,staffEntity);
                    staffPerformSummaryEntity.setId(temp.getId());
                    staffPerformSummaryEntity.setUpdateTime(new Date());
                    staffPerformSummaryService.update(staffPerformSummaryEntity);
                }else {
                    staffPerformSummaryEntity.setAttendScore(BigDecimal.ZERO);
                    staffPerformSummaryEntity.setReviewScore(BigDecimal.ZERO);
                    staffPerformSummaryEntity.setOtherScore(BigDecimal.ZERO);
                    staffPerformSummaryEntity.setEffectScore(BigDecimal.ZERO);
                    staffPerformSummaryEntity.setComplainScore(BigDecimal.ZERO);
                    staffPerformSummaryEntity.setErrorScore(vo.getSumScore());
                    StaffPerformUtil.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.setGoworkScoreAdd(entity.getGoworkScoreAdd());
                    statEntity.setGoworkScoreSub(entity.getGoworkScoreSub());
                    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.setGoworkScoreAdd(entity.getGoworkScoreAdd());
                    statEntity.setGoworkScoreSub(entity.getGoworkScoreSub());
                    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);
    }


}