package com.zcxk.evaluation.service.impl;

import com.zcxk.client.UserCenterClient;
import com.zcxk.evaluation.dao.EvaluationResultTaskMapper;
import com.zcxk.evaluation.service.EvaluationResultTaskDetailsService;
import com.zcxk.evaluation.vo.EvaluationResultTaskDetailsVo;
import com.zcxk.utils.EvaluationUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @ClassName EvaluationResultServiceImpl
 * @Description: 考评结果业务处理
 * @Author lihui
 * @Date 2021/5/7
 * @Version V1.0
 **/
@Slf4j
@Service
public class EvaluationResultTaskDetailsServiceImpl implements EvaluationResultTaskDetailsService {

    @Autowired
    private UserCenterClient userCenterClient;

    @Autowired
    private EvaluationResultTaskMapper evaluationResultTaskMapper;

    @Override
    public EvaluationResultTaskDetailsVo findResultTaskDetail(Integer evaluationResultId) {
        EvaluationResultTaskDetailsVo vo =  evaluationResultTaskMapper.findResultTaskDetail(evaluationResultId);
        if (vo == null) {
            return vo;
        }
        if (StringUtils.isNotEmpty(vo.getEvaluationGrade())) {
            Map<String,String> gradMap  = userCenterClient.selectListByPCodes("SC_EVALUATION_GRADE");
            vo.setEvaluationGrade(gradMap.get(vo.getEvaluationGrade()));
        }
        vo.setCycle(EvaluationUtil.formatCycle(Integer.parseInt(vo.getCycle()),vo.getYear(), vo.getMonth()));
        return vo;
    }
}
