package com.cpp.web.controller.configManager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpp.common.core.domain.R;
import com.cpp.web.service.datafactory.ParsingLogService;
import com.cpp.web.service.station.ElectricFieldService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequiredArgsConstructor
@RequestMapping("/parsingLog")
public class ParsingLogController {

    private final ParsingLogService parsingLogService;

    private final ElectricFieldService electricFieldService;

    /**
     * 根据场站编号 解析时间 文件状态 分页查询
     *
     * @param currentPage
     * @param pageSize
     * @param stationCode
     * @param time
     * @param fileStatus
     * @return
     */
    @ApiOperation(value = "根据场站编号分页查询", notes = "分页查询")
    @PostMapping("/getByStationCodeAndCreateTimeAndFileStatusAndFileType")
    public R getByStationCodeAndCreateTimeAndFileStatusAndFileType(Long currentPage, Long pageSize, String stationCode, Long time, String fileStatus, String fileType) {
        Page page = new Page(currentPage, pageSize);
        page.setMaxLimit((long) -1);
        return R.ok(parsingLogService.page(page, parsingLogService.getByStationCodeAndCreateTimeAndFileStatusAndFileType(stationCode, new Date(time), new Date(time + 60 * 60 * 24 * 1000 - 1000), fileStatus, fileType)));
    }

    @ApiOperation(value = "根据场站编号分页查询", notes = "分页查询")
    @GetMapping("/getByStationCodeAndCreateTimeAndFileType")
    public R getByStationCodeAndCreateTimeAndFileType(Long page, Long size, String stationCode, Long startTime,Long endTime, String fileType,String dataSources,String parsingDescribe,String parsingFileStatus) {
        Map<String,Object> map = new HashMap<>();
        String electricFieldType = electricFieldService.findByStationCode(stationCode).getElectricFieldTypeEnum();

        Page pages = new Page(page, size);
        pages.setMaxLimit((long) -1);
        map.put("data",parsingLogService.page(pages, parsingLogService.getByStationCodeAndCreateTimeAndFileType(stationCode, new Date(startTime), new Date(endTime), fileType,dataSources,parsingDescribe,parsingFileStatus)));
        map.put("type",electricFieldType);
//        return R.ok(parsingLogService.page(pages, parsingLogService.getByStationCodeAndCreateTimeAndFileType(stationCode, new Date(startTime), new Date(endTime), fileType,dataSources,parsingDescribe,parsingFileStatus)));
        return R.ok(map);
    }
}
