package com.tofly.xrtymis.custom.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.xrtymis.custom.dto.FinishingRateDto;
import com.tofly.xrtymis.custom.service.FinishingRateService;
import com.tofly.xrtymis.custom.service.export.ExportCommonCodeService;
import com.tofly.xrtymis.mapper.FinishingRateMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 工单完成率统计
 */
@Service
@AllArgsConstructor
public class FinishingRateServiceImpl implements FinishingRateService {

    private final FinishingRateMapper finishingRateMapper;

    private final ExportCommonCodeService exportCommonCodeService;



    @Override
    public List<Map> workOrderCount(HttpServletResponse response, FinishingRateDto dto) {
        List<Map> orderCount = finishingRateMapper.workOrderCount(dto);
        if (dto.getExport() == 1){
            exportCommonCodeService.exportCode(response,"frWorkOrderCountService",orderCount);
        }
        return orderCount;
    }

    @Override
    public Page<Map> workOrderInfo(HttpServletResponse response,Page page,FinishingRateDto dto) {
        Page<Map> orderInfo = finishingRateMapper.workOrderInfo(page, dto);
        if (dto.getExport() == 1){
            exportCommonCodeService.exportCode(response,"frWorkOrderInfoService",orderInfo.getRecords());
        }
        return orderInfo;
    }
}
