package com.dayou.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dayou.common.RestResponse;
import com.dayou.dto.MajorStatisticalSelectDTO;
import com.dayou.service.IMajorStatisticalStatementService;
import com.dayou.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("major/statisticalStatement")
public class MajorStatisticalStatementController extends BaseController{

    @Autowired
    private IMajorStatisticalStatementService majorStatisticalStatementService;

    /**
     * 查询大中型台账
     * @param page 分页
     * @param dto 查询条件
     * @return Page<MajorLedgerVO>
     */
    @GetMapping("/getMajorLedgerVO")
    public RestResponse<Page<MajorLedgerVO>> getMajorLedgerVO(Page page, MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorLedgerVO(page, dto));
    }

    /**
     * 导出大中型台账
     * @param dto 查询条件
     */
    @GetMapping("/getMajorLedgerVO/export")
    public void exportMajorLedgerVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorLedgerVO> result = majorStatisticalStatementService.exportMajorLedgerVO(dto);
        exportPlus(response,"房地产总台账列表",result, MajorLedgerVO.class);
    }

    /**
     * 评估部绩效扣分查询
     * @param dto 查询dto
     * @return RestResponse<List<MajorPerformanceDeductionVO>>
     */
    @GetMapping("/department/getMajorPerformanceDeductionVO")
    public RestResponse<List<MajorPerformanceDeductionVO>> getMajorPerformanceDeductionVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorPerformanceDeductionVO(dto));
    }

    /**
     * 评估部绩效扣分查询
     * @param dto 查询dto
     */
    @GetMapping("/department/getMajorPerformanceDeductionVO/export")
    public void exportMajorPerformanceDeductionVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorPerformanceDeductionVO> result = majorStatisticalStatementService.getMajorPerformanceDeductionVO(dto);
        exportPlus(response,"评估部绩效扣分表数据",result, MajorPerformanceDeductionVO.class);
    }

    /**
     * 评估人员绩效扣分查询
     * @param dto 查询dto
     * @return RestResponse<List<MajorPerformanceDeductionVO>>
     */
    @GetMapping("/evaluator/getMajorPerformanceDeductionVO")
    public RestResponse<List<MajorPerformanceDeductionVO>> getMajorPerformanceDeductionVOByEvaluator(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorPerformanceDeductionVOByEvaluator(dto));
    }

    /**
     * 评估人员绩效扣分查询
     * @param dto 查询dto
     */
    @GetMapping("/evaluator/getMajorPerformanceDeductionVO/export")
    public void exportMajorPerformanceDeductionVOByEvaluator(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorPerformanceDeductionVO> result = majorStatisticalStatementService.getMajorPerformanceDeductionVOByEvaluator(dto);
        exportPlus(response,"评估人员绩效扣分表数据",result, MajorPerformanceDeductionVO.class);
    }

    /**
     * 查询每种错误类型的数量
     * @param dto 查询dto
     * @return List<MajorErrorTypeCountVO>
     */
    @GetMapping("/errorType/getMajorErrorTypeCountVO")
    public RestResponse<List<MajorErrorTypeCountVO>> getMajorErrorTypeCountVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorErrorTypeCountVO(dto));
    }

    /**
     * 导出每种错误类型的数量
     * @param dto 查询dto
     */
    @GetMapping("/errorType/getMajorErrorTypeCountVO/export")
    public void exportMajorErrorTypeCountVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorErrorTypeCountVO> result = majorStatisticalStatementService.getMajorErrorTypeCountVO(dto);
        exportPlus(response,"错误类型统计数据",result, MajorErrorTypeCountVO.class);
    }

    /**
     * 查询错误类型详情列表
     * @param page 分页
     * @param dto 查询dto
     * @return Page<MajorPerformanceDeductionDetailVO>
     */
    @GetMapping("/errorType/getMajorErrorTypeCountVO/detail")
    public RestResponse<Page<MajorPerformanceDeductionDetailVO>> getMajorErrorTypeDetailVO(Page page, MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorErrorTypeDetailVO(page, dto));
    }

    /**
     * 导出错误类型详情列表
     * @param dto 查询dto
     */
    @GetMapping("/errorType/getMajorErrorTypeCountVO/detail/export")
    public void exportMajorErrorTypeDetailVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorPerformanceDeductionDetailVO> result = majorStatisticalStatementService.exportMajorErrorTypeDetailVO(dto);
        String name;
        if (dto.getCheckType().equals("com")) {
            name = "公司审核错误统计列表详情";
        }else {
            name = "部门内部错误统计列表详情";
        }
        exportPlus(response,name,result, MajorPerformanceDeductionDetailVO.class);
    }

    /**
     * 根据部门id获取部门绩效扣分
     * @param dto 查询dto
     * @return List<MajorPerformanceDeductionVO>
     */
    @GetMapping("/depId/getMajorPerformanceDeductionVO")
    public RestResponse<List<MajorPerformanceDeductionVO>> getMajorPerformanceDeductionVOByDepId(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorPerformanceDeductionVOByDepId(dto));
    }

    /**
     * 根据部门id导出部门绩效扣分
     * @param dto 查询dto
     */
    @GetMapping("/depId/getMajorPerformanceDeductionVO/export")
    public void exportMajorPerformanceDeductionVOByDepId(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorPerformanceDeductionVO> result = majorStatisticalStatementService.getMajorPerformanceDeductionVOByDepId(dto);
        exportPlus(response,"部门内部绩效扣分表数据",result, MajorPerformanceDeductionVO.class);
    }

    /**
     * 查询错误详情列表
     * @param page 分页
     * @param dto 查询dto
     * @return Page<MajorPerformanceDeductionDetailVO>
     */
    @GetMapping("/getMajorPerformanceDeductionDetailVO")
    public RestResponse<Page<MajorPerformanceDeductionDetailVO>> getMajorPerformanceDeductionDetailVO(Page page, MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorPerformanceDeductionDetailVO(page, dto));
    }

    /**
     * 导出错误详情列表
     * @param dto 查询dto
     */
    @GetMapping("/getMajorPerformanceDeductionDetailVO/export")
    public void exportMajorPerformanceDeductionDetailVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorPerformanceDeductionDetailVO> result = majorStatisticalStatementService.exportMajorPerformanceDeductionDetailVO(dto);
        String fileName = "资产评估部绩效扣分详情_" + dto.getCheckLoop();
        switch (dto.getMistakeType()) {
            case "normal":
                fileName += "_" + "一般错误";
                break;
            case "hard":
                fileName += "_" + "较大错误";
                break;
            case "fatal":
                fileName += "_" + "重大错误";
                break;
        }
        exportPlus(response, fileName, result, MajorPerformanceDeductionDetailVO.class);
    }

    /**
     * 评估部效率查询
     * @param dto 查询dto
     * @return List<MajorEvaluateEfficiencyVO>
     */
    @GetMapping("/evaluate/dep/getEfficiencyVO")
    public RestResponse<List<MajorEvaluateEfficiencyVO>> getMajorEvaluateDepEfficiencyVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorEvaluateDepEfficiencyVO(dto));
    }

    /**
     * 评估部效率导出
     * @param dto 查询dto
     */
    @GetMapping("/evaluate/dep/getEfficiencyVO/export")
    public void exportMajorEvaluateDepEfficiencyVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorEvaluateEfficiencyVO> result = majorStatisticalStatementService.getMajorEvaluateDepEfficiencyVO(dto);
        exportPlus(response, "评估部效率值表", result, MajorEvaluateEfficiencyVO.class);
    }

    /**
     * 评估人员效率查询
     * @param dto 查询dto
     * @return List<MajorEvaluateEfficiencyVO>
     */
    @GetMapping("/evaluate/per/getEfficiencyVO")
    public RestResponse<List<MajorEvaluateEfficiencyVO>> getMajorEvaluatePerEfficiencyVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorEvaluatePerEfficiencyVO(dto));
    }

    /**
     * 评估人员效率导出
     * @param dto 查询dto
     */
    @GetMapping("/evaluate/per/getEfficiencyVO/export")
    public void exportMajorEvaluatePerEfficiencyVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorEvaluateEfficiencyVO> result = majorStatisticalStatementService.getMajorEvaluatePerEfficiencyVO(dto);
        exportPlus(response, "评估人员效率值表", result, MajorEvaluateEfficiencyVO.class);
    }

    /**
     * 效率详情列表查询
     * @param page 分页
     * @param dto 查询dto
     * @return RestResponse<Page<MajorEfficiencyDetailVO>>
     */
    @GetMapping("/evaluate/getMajorEvaEffDetailVO")
    public RestResponse<Page<MajorEfficiencyDetailVO>> getMajorEfficiencyDetailVO(Page page, MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorEfficiencyDetailVO(page, dto));
    }

    /**
     * 效率详情列表导出
     * @param dto 查询dto
     */
    @GetMapping("/evaluate/getMajorEvaEffDetailVO/export")
    public void exportMajorEfficiencyDetailVO(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorEfficiencyDetailVO> result = majorStatisticalStatementService.exportMajorEfficiencyDetailVO(dto);
        exportPlus(response, "大中型订单列表", result, MajorEfficiencyDetailVO.class);
    }

    /**
     * 项目部绩效查询
     * @param dto 查询dto
     * @return List<MajorEvaluateEfficiencyVO>
     */
    @GetMapping("/department/getMajorDepPerformanceOverviewVO")
    public RestResponse<List<MajorDepPerformanceOverviewVO>> getMajorDepPerformanceOverviewVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorDepPerformanceOverviewVO(dto));
    }

    /**
     * 市场部效率查询
     * @param dto 查询dto
     * @return List<MajorMarketEfficiencyVO>
     */
    @GetMapping("/market/dep/getEfficiencyVO")
    public RestResponse<List<MajorMarketEfficiencyVO>> getMajorMarketDepEfficiencyVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorsMarketDepEfficiencyVO(dto));
    }

    /**
     * 市场部效率导出
     * @param dto 查询dto
     */
    @GetMapping("/market/dep/getEfficiencyVO/export")
    public void majorMarketDepEfficiencyVOExport(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorMarketEfficiencyVO> result = majorStatisticalStatementService.getMajorsMarketDepEfficiencyVO(dto);
        exportPlus(response, "市场部效率值表", result, MajorMarketEfficiencyVO.class);
    }

    /**
     * 客户经理效率查询
     * @param dto 查询dto
     * @return List<MajorMarketEfficiencyVO>
     */
    @GetMapping("/market/per/getEfficiencyVO")
    public RestResponse<List<MajorMarketEfficiencyVO>> getMajorMarketPerEfficiencyVO(MajorStatisticalSelectDTO dto) {
        return RestResponse.data(majorStatisticalStatementService.getMajorMarketPerEfficiencyVO(dto));
    }

    /**
     * 客户经理效率导出
     * @param dto 查询dto
     */
    @GetMapping("/market/per/getEfficiencyVO/export")
    public void majorMarketPerEfficiencyVOExport(MajorStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<MajorMarketEfficiencyVO> result = majorStatisticalStatementService.getMajorMarketPerEfficiencyVO(dto);
        exportPlus(response, "客户经理效率值表", result, MajorMarketEfficiencyVO.class);
    }

}
