package com.energy.manage.service.controller.datatransfer;

import com.energy.manage.common.base.Page;
import com.energy.manage.common.reponse.ResultResp;
import com.energy.manage.service.config.annotations.UserLoginToken;
import com.energy.manage.service.controller.base.BaseServiceController;
import com.energy.manage.service.domain.dto.datatransfer.DataTransferDto;
import com.energy.manage.service.domain.dto.datatransfer.EditDataTransferTypeDto;
import com.energy.manage.service.domain.vo.datatransfer.DataTransferBatchShortVo;
import com.energy.manage.service.domain.vo.datatransfer.DataTransferVo;
import com.energy.manage.service.service.datatransfer.DataTransferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 数据转换模块儿
 * @author chy
 * @date 2024/5/20 10:17
 * @desc
 */
@Slf4j
@Api(value = "DataTransferController",tags = "数据转换")
@RestController
@RequestMapping("/dataTransfer")
public class DataTransferController extends BaseServiceController {

    @Autowired
    private DataTransferService dataTransferService;


    @UserLoginToken
    @ApiOperation(value = "查询可以数据转换批次")
    @GetMapping("/fieldBatchListForDataTransfer")
    public ResultResp fieldBatchListForDataTransfer(){
        return success(dataTransferService.fieldBatchListForDataTransfer(getRoleId()));
    }

    @UserLoginToken
    @ApiOperation("查询转换数据组")
    @GetMapping("/queryDataTransferGroup")
    public ResultResp<Page<DataTransferBatchShortVo>> queryDataTransferGroup(DataTransferDto dataTransferDto){
        dataTransferDto.setRoleId(getRoleId());
        return pageResult(dataTransferService.queryDataTransferGroup(dataTransferDto),dataTransferDto);
    }

    @UserLoginToken
    @ApiOperation("查询批次下数据转换信息")
    @GetMapping("/queryDataTransferByBatchCode")
    public ResultResp queryDataTransferByBatchCode(@RequestParam("batchCode") String batchCode){
        return success(dataTransferService.queryDataTransferByBatchCode(batchCode));
    }


    @UserLoginToken
    @ApiOperation("新增数据转换")
    @PostMapping("/addDataTransferList")
    public ResultResp addDataTransferList(@RequestBody DataTransferDto dataTransferDto){
        dataTransferDto.setRoleId(getRoleId());
        dataTransferDto.setUserId(getUserId());
        return dataTransferService.addDataTransfer(dataTransferDto);
    }

    @UserLoginToken
    @ApiOperation("转换/重新转换")
    @PostMapping("/dataTransfer")
    public ResultResp dataTransfer(@RequestBody EditDataTransferTypeDto editDto){
        return dataTransferService.dataTransfer(editDto, getUserId());
    }

    @UserLoginToken
    @ApiOperation("时间粒度编辑")
    @PostMapping("/editTimeGranularity")
    public ResultResp editTimeGranularity(@RequestBody EditDataTransferTypeDto editDto){
        return dataTransferService.editTimeGranularity(editDto.getBatchCode(), editDto.getDataTransferType(), editDto.getTimeGranularity(),getUserId());
    }

    @UserLoginToken
    @ApiOperation("转换数据时间范围查询")
    @GetMapping("/queryDataTime")
    public ResultResp queryDataTime(@RequestParam("batchCode") String batchCode, @RequestParam("dataTransferType") String dataTransferType){
        return success(dataTransferService.queryDataTime(batchCode, dataTransferType));
    }
}
