package jnpf.personnels.service;

import jnpf.base.vo.PageListVO;
import jnpf.model.personnels.dto.analysis.FtbPersonnlesAnalysisDTO;
import jnpf.model.personnels.vo.analysis.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * @Author: peng.hao
 * @create: 2025/4/11
 */
public interface FtbPersonnelsBrainDrainService {
    /**
     * 人事异动转正人数同比环比
     */
    FtbPersonnlesBrainDrainVO getBrainDrainCorrectRateComparison(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动新人率人数同比环比
     * @param dto
     * @return
     */
    FtbPersonnlesBrainDrainVO getBrainDrainCorrectRateNewcomerRate(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动入职岗位维度
     * @param dto
     * @return
     */

    List<FtbPersonnelsPeoplePostRatioVO> getOnboardingPostDimension(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动转正岗位维度
     * @param dto
     * @return
     */
    List<FtbPersonnelsPeoplePostRatioVO> getRegularPostDimension(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动离职岗位维度
     * @param dto
     * @return
     */
    List<FtbPersonnelsPeoplePostRatioVO> getTurnoverPostDimension(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动入职人数 门店维度，部门维度
     * @param dto
     * @return PageListVO<FtbPersonnelsPeopleInfoRatioVO>
     */
    List<FtbPersonnelsPeopleInfoRatioVO> getOnboardingStoreDimension(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动转正人数 门店维度，部门维度
     * @param dto
     * @return PageListVO<FtbPersonnelsPeopleInfoRatioVO>
     */
    List<FtbPersonnelsPeopleInfoRatioVO> getRegularizationStoreDimension(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动离职人数 门店维度，部门维度
     * @param dto
     * @return PageListVO<FtbPersonnelsPeopleInfoRatioVO>
     */
    List<FtbPersonnelsPeopleInfoRatioVO> getTurnoverStoreDimension(FtbPersonnlesAnalysisDTO dto);

    /**
     * 人事异动新人率 岗位维度、门店维度、部门维度 进行展示
     * @param dto
     * @return PageListVO<FtbPersonnelsPeopleInfoRatioVO>
     */
    List<FtbPersonnelsPeopleInfoRatioVO> getNewHireRateDimension(FtbPersonnlesAnalysisDTO dto);


    /**
     * 入职明细
     * @param dto
     * @return PageListVO<FtbPersonnelsOnboardingDetailVO>
     */
    PageListVO<FtbPersonnelsOnboardingDetailVO> getOnboardingDetail(FtbPersonnlesAnalysisDTO dto);

    /**
     * 转正明细
     * @param dto
     * @return PageListVO<FtbPersonnelsRegularizationDetailVO>
     */
    PageListVO<FtbPersonnelsRegularizationDetailVO> getRegularizationDetail(FtbPersonnlesAnalysisDTO dto);


    /**
     * 新人率占比明细
     * @param dto
     * @return PageListVO<FtbPersonnelsNewHireRateDetailVO>
     */
    PageListVO<FtbPersonnelsNewHireRateDetailVO> getNewHireRateDetail(FtbPersonnlesAnalysisDTO dto);

    /**
     * 新人率占比明细导出
     * @param dto
     * @param response
     */
    void getNewHireRateDetailExport(FtbPersonnlesAnalysisDTO dto, HttpServletResponse response);

    /**
     * 入职明细导出
     * @param dto
     * @param response
     */
    void getOnboardingDetailExport(FtbPersonnlesAnalysisDTO dto, HttpServletResponse response);

    /**
     * 转正明细导出
     * @param dto
     * @param response
     */
    void getRegularizationDetailExport(FtbPersonnlesAnalysisDTO dto, HttpServletResponse response);


    /**
     * 百分比计算（保留两位小数）
     *
     * @param a 分子
     * @param b 分母
     * @return {@link BigDecimal }
     */
    @SuppressWarnings("Duplicates")
    static BigDecimal computeDivision(Object a, Object b) {
        BigDecimal result = computeDivisionNo(a, b);
        return result.multiply(BigDecimal.valueOf(100));
    }
    /**
     * 非百分比计算
     */
    @SuppressWarnings("Duplicates")
    static BigDecimal computeDivisionNo(Object a, Object b) {
        if (a == null || b == null) {
            return BigDecimal.ZERO;
        }
        // a/b 除数为0
        if (b instanceof Integer) {
            Integer b0 = (Integer) b;
            if (b0 == 0) {
                return BigDecimal.ZERO;
            }
        }
        if (b instanceof Long) {
            Long b0 = (Long) b;
            if (b0 == 0) {
                return BigDecimal.ZERO;
            }
        }
        if (b instanceof BigDecimal) {
            if (((BigDecimal) b).compareTo(BigDecimal.ZERO) == 0) {
                return BigDecimal.ZERO;
            }
        }
        BigDecimal a0 = new BigDecimal(String.valueOf(a));
        BigDecimal b0 = new BigDecimal(String.valueOf(b));
        return a0.divide(b0, 2, RoundingMode.HALF_UP);
    }

}
