package jnpf.model.cultivate.vo.position;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.stream.Collectors;

/**
 * @author fantaibao
 * @date 2024/03/22
 */
@Data
public class FtbCultivatePositionPersonStatisticesExportVO {
    /**
     * 员工姓名
     */
    @ExcelProperty("员工姓名")
    private String employeeName;
    /**
     * 员工ID(页面显示)
     */
    @ExcelProperty("员工ID")
    private String employeeCustomId;
    /**
     * 用户id，请求接口用
     */
    @ExcelIgnore
    private String userId;
    /**
     * 所属组织
     */
    @ExcelProperty("所属组织")
    private String organization;
    /**
     * 组织ID(页面显示)
     */
    @ExcelProperty("组织ID")
    private String organizationCustomId;
    /**
     * 本岗岗位_职等
     */
    @ExcelProperty("本岗岗位_职级")
    private String thisPosition;
    /**
     * 学习岗位_职等
     */
    @ExcelProperty("学习岗位")
    private String learningPosition;
    /**
     * 学习时长（h）
     */
    @ExcelProperty("学习时长（h）")
    private BigDecimal studyDuration;
    /**
     * 完课率（%）
     */
    @ExcelProperty("完课率（%）")
    private BigDecimal courseCompletionRate;
    /**
     * 学习地图课程总数
     */
    @ExcelProperty("学习地图课程总数")
    private Integer totalNumberOfLearningMapCourses;
    /**
     * 学习课程数
     */
    @ExcelProperty("学习课程数")
    private Integer numberOfStudyCourses;
    /**
     * 下属人数
     */
    @ExcelProperty("下属人数")
    private Integer numberOfSubordinates;
    /**
     * 下属参与学习人数
     */
    @ExcelProperty("下属参与学习人数")
    private Integer numberOfSubordinatesParticipatingInLearning;
    /**
     * 下属人均学习时长(h)
     */
    @ExcelProperty("下属人均学习时长(h)")
    private BigDecimal averageStudyHoursPerSubordinate;

    public static FtbCultivatePositionPersonStatisticesExportVO convert(FtbCultivatePositionPersonStatisticesVO vo) {
        if (vo == null) {
            return null;
        }
        FtbCultivatePositionPersonStatisticesExportVO ftbCultivatePositionPersonStatisticesExportVO = new FtbCultivatePositionPersonStatisticesExportVO();
        ftbCultivatePositionPersonStatisticesExportVO.setEmployeeName(vo.getEmployeeName());
        ftbCultivatePositionPersonStatisticesExportVO.setEmployeeCustomId(vo.getEmployeeCustomId());
        ftbCultivatePositionPersonStatisticesExportVO.setUserId(vo.getUserId());
        if (CollectionUtils.isNotEmpty(vo.getOrganization())) {
            ftbCultivatePositionPersonStatisticesExportVO.setOrganization(vo.getOrganization().stream().collect(Collectors.joining(",")));
        }
        if (CollectionUtils.isNotEmpty(vo.getOrganizationCustomId())) {
            ftbCultivatePositionPersonStatisticesExportVO.setOrganizationCustomId(vo.getOrganizationCustomId().stream().collect(Collectors.joining(",")));
        }
        if (CollectionUtils.isNotEmpty(vo.getThisPosition())) {
            ftbCultivatePositionPersonStatisticesExportVO.setThisPosition(vo.getThisPosition()
                    .stream().map(a -> a.getPositionName() + "_" + a.getPositionGradesName())
                    .collect(Collectors.joining(";")));
        }
        if (CollectionUtils.isNotEmpty(vo.getLearningPosition())) {
            ftbCultivatePositionPersonStatisticesExportVO.setLearningPosition(vo.getLearningPosition()
                    .stream().map(FtbCultivatePositionPersonStatisticesVO.PositionInfo::getPositionName)
                    .collect(Collectors.joining(";")));
        }
        ftbCultivatePositionPersonStatisticesExportVO.setStudyDuration(vo.getStudyDuration());
        ftbCultivatePositionPersonStatisticesExportVO.setCourseCompletionRate(vo.getCourseCompletionRate().multiply(BigDecimal.valueOf(100)));
        ftbCultivatePositionPersonStatisticesExportVO.setTotalNumberOfLearningMapCourses(vo.getTotalNumberOfLearningMapCourses());
        ftbCultivatePositionPersonStatisticesExportVO.setNumberOfStudyCourses(vo.getNumberOfStudyCourses());
        ftbCultivatePositionPersonStatisticesExportVO.setNumberOfSubordinates(vo.getNumberOfSubordinates());
        ftbCultivatePositionPersonStatisticesExportVO.setNumberOfSubordinatesParticipatingInLearning(vo.getNumberOfSubordinatesParticipatingInLearning());
        ftbCultivatePositionPersonStatisticesExportVO.setAverageStudyHoursPerSubordinate(vo.getAverageStudyHoursPerSubordinate());
        return ftbCultivatePositionPersonStatisticesExportVO;
    }

}
