package com.dayou.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dayou.common.RestResponse;
import com.dayou.dto.AssetsStatisticalSelectDTO;
import com.dayou.service.IAssetsStatisticalStatementService;
import com.dayou.vo.*;
import lombok.extern.slf4j.Slf4j;
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("assets/statisticalStatement")
@Slf4j
public class AssetsStatisticalStatementController extends BaseController{

    @Autowired
    private IAssetsStatisticalStatementService assetsStatisticalStatementService;

    /**
     * 获取资产台账
     * @param dto 查询dto
     * @return Page<AssetsLedgerVO>
     */
    @GetMapping("/getAssetsLedgerVO")
    public RestResponse<Page<AssetsLedgerVO>> getAssetsLedgerVO(AssetsStatisticalSelectDTO dto, Page page) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsLedgerVO(dto,page));
    }

    /**
     * 资产台账导出
     * @param dto 查询dto
     */
    @GetMapping("/getAssetsLedgerVO/export")
    public void assetsLedgerVOExport(AssetsStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<AssetsLedgerVO> result = assetsStatisticalStatementService.assetsLedgerVOExport(dto);
        exportPlus(response,"资产台账列表",result, AssetsLedgerVO.class);
    }

    /**
     * 评估部绩效扣分查询
     * @param dto 查询dto
     * @return List<AssetsPerformanceDeductionVO>
     */
    @GetMapping("/department/getAssetsPerformanceDeductionVO")
    public RestResponse<List<AssetsPerformanceDeductionVO>> getAssetsPerformanceDeductionVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsPerformanceDeductionVO(dto));
    }

    /**
     * 评估部绩效扣分导出
     * @param dto 查询dto
     */
    @GetMapping("/department/getAssetsPerformanceDeductionVO/export")
    public void assetsPerformanceDeductionVOExport(AssetsStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<AssetsPerformanceDeductionVO> result = assetsStatisticalStatementService.assetsPerformanceDeductionVOExport(dto);
        exportPlus(response, "资产评估部绩效扣分", result, AssetsPerformanceDeductionVO.class);
    }

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

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

    /**
     * 评估人员绩效扣分查询
     * @param dto 查询dto
     * @return List<AssetsPerformanceDeductionVO>
     */
    @GetMapping("/evaluator/getAssetsPerformanceDeductionVO")
    public RestResponse<List<AssetsPerformanceDeductionVO>> getAssetsPerformanceDeductionVOByEvaluator(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsPerformanceDeductionVOByEvaluator(dto));
    }

    /**
     * 评估人员绩效扣分导出
     * @param dto 查询dto
     */
    @GetMapping("/evaluator/getAssetsPerformanceDeductionVO/export")
    public void assetsPerformanceDeductionVOByEvaluatorExport(AssetsStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<AssetsPerformanceDeductionVO> result = assetsStatisticalStatementService.assetsPerformanceDeductionVOByEvaluatorExport(dto);
        exportPlus(response, "评估人员绩效扣分", result, AssetsPerformanceDeductionVO.class);
    }

    /**
     * 评估部效率查询
     * @param dto 查询dto
     * @return List<AssetsEvaluateDepEfficiencyVO>
     */
    @GetMapping("/evaluate/dep/getEfficiencyVO")
    public RestResponse<List<AssetsEvaluateEfficiencyVO>> getAssetsEvaluateDepEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsEvaluateDepEfficiencyVO(dto));
    }

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

    /**
     * 评估人员效率查询
     * @param dto 查询dto
     * @return List<AssetsEvaluateDepEfficiencyVO>
     */
    @GetMapping("/evaluate/per/getEfficiencyVO")
    public RestResponse<List<AssetsEvaluateEfficiencyVO>> getAssetsEvaluatePerEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsEvaluatePerEfficiencyVO(dto));
    }

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

    /**
     * 效率详情列表查询
     * @param page 分页
     * @param dto 查询dto
     * @return Page<AssetsEvaluateEfficiencyDetailVO>
     */
    @GetMapping("/evaluate/getAssetsEvaEffDetailVO")
    public RestResponse<Page<AssetsEfficiencyDetailVO>> getAssetsEvaEffDetailVO(Page page, AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsEvaEffDetailVO(page, dto));
    }

    /**
     * 效率详情列表导出
     * @param dto 查询dto
     */
    @GetMapping("/evaluate/getAssetsEvaEffDetailVO/export")
    public void assetsEvaEffDetailVOExport(AssetsStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<AssetsEfficiencyDetailVO> result = assetsStatisticalStatementService.assetsEvaEffDetailVOExport(dto);
        exportPlus(response, "资产订单列表", result, AssetsEfficiencyDetailVO.class);
    }

    /**
     * 市场部效率查询
     * @param dto 查询dto
     * @return List<AssetsMarketEfficiencyVO>
     */
    @GetMapping("/market/dep/getEfficiencyVO")
    public RestResponse<List<AssetsMarketEfficiencyVO>> getAssetsMarketDepEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsMarketDepEfficiencyVO(dto));
    }

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

    /**
     * 客户经理效率查询
     * @param dto 查询dto
     * @return List<AssetsMarketEfficiencyVO>
     */
    @GetMapping("/market/per/getEfficiencyVO")
    public RestResponse<List<AssetsMarketEfficiencyVO>> getAssetsMarketPerEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsMarketPerEfficiencyVO(dto));
    }

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

    /**
     * 资产客户效率值(总)查询
     * @param dto 查询dto
     * @return List<AssetsCustomerEfficiencyVO>
     */
    @GetMapping("/customer/total/getEfficiencyVO")
    public RestResponse<List<AssetsCustomerEfficiencyVO>> getAssetsCustomerTotalEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsCustomerTotalEfficiencyVO(dto));
    }

    /**
     * 资产客户效率值(总)导出
     * @param dto 查询dto
     */
    @GetMapping("/customer/total/getEfficiencyVO/export")
    public void assetsCustomerTotalEfficiencyVOExport(AssetsStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<AssetsCustomerEfficiencyVO> result = assetsStatisticalStatementService.getAssetsCustomerTotalEfficiencyVO(dto);
        exportPlus(response, "资产客户效率值(总)", result, AssetsCustomerEfficiencyVO.class);
    }

    /**
     * 资产客户效率值(客户经理)查询
     * @param dto 查询dto
     * @return List<AssetsCustomerEfficiencyVO>
     */
    @GetMapping("/customer/manager/getEfficiencyVO")
    public RestResponse<List<AssetsCustomerEfficiencyVO>> getAssetsCustomerManagerEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        return RestResponse.data(assetsStatisticalStatementService.getAssetsCustomerManagerEfficiencyVO(dto));
    }

    /**
     * 资产客户效率值(客户经理)导出
     * @param dto 查询dto
     */
    @GetMapping("/customer/manager/getEfficiencyVO/export")
    public void assetsCustomerManagerEfficiencyVOExport(AssetsStatisticalSelectDTO dto, HttpServletResponse response) throws IOException {
        List<AssetsCustomerEfficiencyVO> result = assetsStatisticalStatementService.getAssetsCustomerManagerEfficiencyVO(dto);
        exportPlus(response, "资产客户效率值(客户经理)", result, AssetsCustomerEfficiencyVO.class);
    }

}
