package jnpf.personnels.controller.web.analysis;

import com.fantaibao.permission.annotation.FtbCheckPermission;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.personnels.dto.analysis.FtbPersonnlesAnalysisDTO;
import jnpf.model.personnels.vo.analysis.*;
import jnpf.personnels.service.FtbPersonnelsTurnoverAnalysisService;
import jnpf.personnels.utils.PersonnelDataAnalysisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * web 人才流失分析
 * @Author: peng.hao
 * @create: 2024/10/14
 */
@RestController
@Slf4j
@RequestMapping("/web/turnover-analysis")
public class FtbPersonnelsTurnoverAnalysisController {

    @Resource
    FtbPersonnelsTurnoverAnalysisService ftbPersonnelsTurnoverAnalysisService;

    /**
     * 离职人数（月）
     * 同比
     * 环比
     */
    @PostMapping("get-leave-people-month")
    @FtbCheckPermission("leaveManage")
    public ActionResult<FtbPersonnelsTurnoverWithAnalysisInfoVO> getLeavePeopleMonth(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeavePeopleMonth(dto));
    }
    /**
     * 离职性别分布（月）
     */
    @PostMapping("get-leave-people-sex-month")
    public ActionResult<FtbPersonnelsTurnoverPeopleSexVO> getLeavePeopleSexMonth(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeavePeopleSexMonth(dto));
    }
    /**
     * 首月离职率
     * 同比
     * 环比
     */
    @PostMapping("get-first-month-leave-rate")
    public ActionResult<FtbPersonnelsTurnoverFirstMonthLeaveRateVO> getFirstMonthLeaveRate(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getFirstMonthLeaveRate(dto));
    }
    /**
     * 首周离职率
     * 同比
     * 环比
     */
    @PostMapping("get-first-week-leave-rate")
    public ActionResult<FtbPersonnelsTurnoverFirstWeekLeaveRateVO> getFirstWeekLeaveRate(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getFirstWeekLeaveRate(dto));
    }
    /**
     * 首年离职率
     * 同比
     * 环比
     */
    @PostMapping("get-first-year-leave-rate")
    @FtbCheckPermission("leaveManage")
    public ActionResult<FtbPersonnelsTurnoverFirstYearLeaveRateVO> getFirstYearLeaveRate(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getFirstYearLeaveRate(dto));
    }

    /**
     * 新员工离职比例
     */
    @PostMapping("get-new-employee-leave-rate")
    public ActionResult<FtbPersonnelsTurnoverLeaveRateVO> getNewEmployeeLeaveRate(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getNewEmployeeLeaveRate(dto));
    }
    /**
     * 离职原因分布
     */
    @PostMapping("get-leave-reason-distribution")
    public ActionResult<List<FtbPersonnelsTurnoverLeaveReasonDistributionVO>> getLeaveReasonDistribution(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeaveReasonDistribution(dto));
    }

    /**
     * 离职各岗位人数占比
     */
    @PostMapping("get-leave-people-post-ratio")
    public ActionResult<List<FtbPersonnelsTurnoverLeavePeoplePostRatioVO>> getLeavePeoplePostRatio(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatio(dto));
    }
    /**
     * 离职人员司龄分布
     */
    @PostMapping("get-leave-people-age-distribution")
    public ActionResult<List<FtbPersonnelsTurnoverLeavePeopleAgeDistributionVO>> getLeavePeopleAgeDistribution(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeavePeopleAgeDistribution(dto));
    }
    /**
     * 离职人员年龄分布占比
     */
    @PostMapping("get-leave-people-age-ratio")
    public ActionResult<List<FtbPersonnelsTurnoverLeavePeopleAgeRatioVO>> getLeavePeopleAgeRatio(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeavePeopleAgeRatio(dto));
    }
    /**
     * 离职率对比
     */
    @PostMapping("get-leave-rate-comparison")
    public ActionResult<FtbPersonnelsTurnoverRateComparisonVO> getLeaveRateComparison(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        return ActionResult.success(ftbPersonnelsTurnoverAnalysisService.getLeaveRateComparison(dto));
    }

    /**
     * 新员工离职比例明细
     */
    @PostMapping("get-new-employee-leave-rate-detail")
    public ActionResult<PersonnelDataAnalysisListVO> getNewEmployeeLeaveRateDetail(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverNewEmployeeDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getNewEmployeeLeaveRateDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverNewEmployeeDetailVO.class));
    }

    /**
     * 新员工离职比例明细导出
     */
    @PostMapping("get-new-employee-leave-rate-detail-export")
    public void getNewEmployeeLeaveRateDetailExprot(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        ftbPersonnelsTurnoverAnalysisService.getNewEmployeeLeaveRateDetailExport(dto, response);
    }

    /**
     * 离职原因分布明细
     */
    @PostMapping("get-leave-reason-distribution-detail")
    public ActionResult<PersonnelDataAnalysisListVO> getLeaveReasonDistributionDetail(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverLeaveReasonDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getLeaveReasonDistributionDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverLeaveReasonDetailVO.class));
    }

    /**
     * 离职原因分布明细导出
     */
    @PostMapping("get-leave-reason-distribution-detail-export")
    public void getLeaveReasonDistributionDetailExprot(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        ftbPersonnelsTurnoverAnalysisService.getLeaveReasonDistributionDetailExport(dto, response);
    }

    /**
     * 各岗位人数占比明细
     */
    @PostMapping("get-leave-people-post-ratio-detail")
    public ActionResult<PersonnelDataAnalysisListVO> getLeavePeoplePostRatioDetail(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverPostRatioDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatioDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverPostRatioDetailVO.class));
    }

    /**
     * 各岗位人数占比明细导出
     */
    @PostMapping("get-leave-people-post-ratio-detail-export")
    public void getLeavePeoplePostRatioDetailExprot(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatioDetailExport(dto, response);
    }


    /**
     * 各部门人数占比明细
     */
    @PostMapping("/get-details-of-department-PeopleInEachStore")
    public ActionResult<PersonnelDataAnalysisListVO> getDetailsOfDepartmentOfPeopleInEachStore(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverPostRatioDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatioDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverPostRatioDetailVO.class));
    }

    /**
     * 各部门人数占比明细导出
     */
    @PostMapping("/get-details-of-department-PeopleInEachStore-export")
    public void getDetailsOfDepartmentOfPeopleInEachStoreExport(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        // 暂时调用岗位占比明细导出方法
        ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatioDetailExport(dto, response);
    }


    /**
     * 各门店人数占比明细
     */
    @PostMapping("/get-details-of-proportion-PeopleInEachStore")
    public ActionResult<PersonnelDataAnalysisListVO> getDetailsOfTheProportionOfPeopleInEachStore(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverPostRatioDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatioDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverPostRatioDetailVO.class));
    }

    /**
     * 各门店人数占比明细导出
     */
    @PostMapping("/get-details-of-proportion-PeopleInEachStore-export")
    public void getDetailsOfTheProportionOfPeopleInEachStoreExport(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        // 暂时调用岗位占比明细导出方法
        ftbPersonnelsTurnoverAnalysisService.getLeavePeoplePostRatioDetailExport(dto, response);
    }

    /**
     * 离职人员年龄分布占比明细
     */
    @PostMapping("get-leave-people-age-ratio-detail")
    public ActionResult<PersonnelDataAnalysisListVO> getLeavePeopleAgeRatioDetail(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverAgeDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getLeavePeopleAgeRatioDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverAgeDetailVO.class));
    }

    /**
     * 离职人员年龄分布占比明细导出
     */
    @PostMapping("get-leave-people-age-ratio-detail-export")
    public void getLeavePeopleAgeRatioDetailExprot(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        ftbPersonnelsTurnoverAnalysisService.getLeavePeopleAgeRatioDetailExport(dto, response);
    }
    /**
     * 离职人员司龄分布明细
     */
    @PostMapping("get-leave-people-age-distribution-detail")
    public ActionResult<PersonnelDataAnalysisListVO> getLeavePeopleAgeDistributionDetail(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverSeniorityDetailVO> result = ftbPersonnelsTurnoverAnalysisService.getLeavePeopleAgeDistributionDetail(dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverSeniorityDetailVO.class));
    }

    /**
     * 离职人员司龄分布明细导出
     */
    @PostMapping("get-leave-people-age-distribution-detail-export")
    public void getLeavePeopleAgeDistributionDetailExprot(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        ftbPersonnelsTurnoverAnalysisService.getLeavePeopleAgeDistributionDetailExport(dto, response);
    }
    /**
     * 离职性别分布明细
     */
    @PostMapping("get-break-down-gender-detail")
    public ActionResult<PersonnelDataAnalysisListVO> breakdownOfGenderDistributionOfResignation(@RequestBody FtbPersonnlesAnalysisDTO dto) {
        PageListVO<FtbPersonnelsTurnoverGenderDetailVO> result = ftbPersonnelsTurnoverAnalysisService.breakdownOfGenderDistributionOfResignation
                (dto);
        return ActionResult.success(PersonnelDataAnalysisUtil.encapsulatePageData(result, FtbPersonnelsTurnoverGenderDetailVO.class));
    }

    /**
     * 离职性别分布明细导出
     */
    @PostMapping("get-break-down-gender-detail-export")
    public void breakdownOfGenderDistributionOfResignationExprot(@RequestBody FtbPersonnlesAnalysisDTO dto, HttpServletResponse response) {
        ftbPersonnelsTurnoverAnalysisService.breakdownOfGenderDistributionOfResignationExprot(dto, response);
    }

}
