package jnpf.model.cultivate.vo.position;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

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

/**
 * @author fantaibao
 * @date 2024/03/22
 */
@Data
public class FtbCultivatePersonStatisticesExportVO {

    @JsonIgnore
    @JSONField(serialize = false)
    @ExcelIgnore
    private String postLearnId;

    /**
     * 岗位主键id
     */
    @ExcelIgnore
    private String positionId;
    /**
     * 岗位名称
     */
    @ExcelProperty(value = "岗位名称", index = 2)
    private String positionTitle;
    /**
     * 岗位ID(页面显示)
     */
    @ExcelProperty(value = "岗位ID", index = 3)
    private String positionCustomId;
    /**
     * 所属组织
     */
    @ExcelProperty(value = "所属组织", index = 0)
    private String organization;
    /**
     * 组织ID(页面显示)
     */
    @ExcelProperty(value = "组织ID", index = 1)
    private String organizationCustomId;
    /**
     * 岗位人数
     */
    @ExcelProperty(value = "岗位人数", index = 4)
    private Integer numberOfPositions;
    /**
     * 岗位学习人数
     */
    @ExcelProperty(value = "岗位学习人数", index = 5)
    private Integer numberOfPeopleStudyingOnTheJob;
    /**
     * 学习时长（h）
     */
    @ExcelProperty(value = "学习时长（h）", index = 6)
    private BigDecimal studyDuration;
    /**
     * 岗位学习完课率（%）
     */
    @ExcelProperty(value = "岗位学习完课率（%）", index = 8)
    private BigDecimal courseCompletionRate;
    /**
     * 人均学习时长（h）
     */
    @ExcelProperty(value = "人均学习时长（h）", index = 7)
    private BigDecimal averageStudyTimePerPerson;
    /**
     * 已学习课程数
     */
    @ExcelProperty(value = "已学习课程数", index = 10)
    private Integer numberOfCoursesTaken;
    /**
     * 岗位学习课程总数
     */
    @ExcelProperty(value = "岗位学习课程总数", index = 9)
    private Integer totalNumberOfOnTheJobLearningCourses;
    /**
     * 岗位学习考试合格率（%)
     */
    @ExcelProperty(value = "岗位学习考试合格率（%)", index = 11)
    private BigDecimal averageStudyHoursPerSubordinate;

    public static FtbCultivatePersonStatisticesExportVO convert(FtbCultivatePersonStatisticesVO ftbCultivatePersonStatisticesVO) {
        if (ftbCultivatePersonStatisticesVO == null) {
            return null;
        }
        FtbCultivatePersonStatisticesExportVO ftbCultivatePersonStatisticesExportVO = new FtbCultivatePersonStatisticesExportVO();
        ftbCultivatePersonStatisticesExportVO.setPostLearnId(ftbCultivatePersonStatisticesVO.getPostLearnId());
        ftbCultivatePersonStatisticesExportVO.setPositionId(ftbCultivatePersonStatisticesVO.getPositionId());
        ftbCultivatePersonStatisticesExportVO.setPositionTitle(ftbCultivatePersonStatisticesVO.getPositionTitle());
        ftbCultivatePersonStatisticesExportVO.setPositionCustomId(ftbCultivatePersonStatisticesVO.getPositionCustomId());
        if (CollectionUtils.isNotEmpty(ftbCultivatePersonStatisticesVO.getOrganization())) {
            ftbCultivatePersonStatisticesExportVO.setOrganization(ftbCultivatePersonStatisticesVO.getOrganization().stream().collect(Collectors.joining(",")));
        }
        if (CollectionUtils.isNotEmpty(ftbCultivatePersonStatisticesVO.getOrganizationCustomId())) {
            ftbCultivatePersonStatisticesExportVO.setOrganizationCustomId(ftbCultivatePersonStatisticesVO.getOrganizationCustomId().stream().collect(Collectors.joining(",")));
        }
        ftbCultivatePersonStatisticesExportVO.setNumberOfPositions(ftbCultivatePersonStatisticesVO.getNumberOfPositions());
        ftbCultivatePersonStatisticesExportVO.setNumberOfPeopleStudyingOnTheJob(ftbCultivatePersonStatisticesVO.getNumberOfPeopleStudyingOnTheJob());
        ftbCultivatePersonStatisticesExportVO.setStudyDuration(ftbCultivatePersonStatisticesVO.getStudyDuration());
        ftbCultivatePersonStatisticesExportVO.setCourseCompletionRate(ftbCultivatePersonStatisticesVO.getCourseCompletionRate().multiply(BigDecimal.valueOf(100)));
        ftbCultivatePersonStatisticesExportVO.setAverageStudyTimePerPerson(ftbCultivatePersonStatisticesVO.getAverageStudyTimePerPerson());
        ftbCultivatePersonStatisticesExportVO.setNumberOfCoursesTaken(ftbCultivatePersonStatisticesVO.getNumberOfCoursesTaken());
        ftbCultivatePersonStatisticesExportVO.setTotalNumberOfOnTheJobLearningCourses(ftbCultivatePersonStatisticesVO.getTotalNumberOfOnTheJobLearningCourses());
        ftbCultivatePersonStatisticesExportVO.setAverageStudyHoursPerSubordinate(ftbCultivatePersonStatisticesVO.getAverageStudyHoursPerSubordinate());
        return ftbCultivatePersonStatisticesExportVO;
    }
}
