package com.kcim.web;

import com.kcim.common.util.Result;
import com.kcim.service.KpiComputeImportService;
import com.kcim.vo.SheetImportResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @program: CostAccount
 * @description:
 * @author: Wang.YS
 * @create: 2024-06-03 13:57
 **/
@Slf4j
@Api(tags = "成本公用导入controller")
@RestController
@RequestMapping("import")
@AllArgsConstructor
public class PublicImportController {
    KpiComputeImportService service;

    @ApiOperation("查询导入列表")
    @GetMapping("list")
    public Result getList(@RequestParam(name = "current",defaultValue = "1",required = false) Integer current,
                          @RequestParam(name = "pageSize",defaultValue = "10",required = false) Integer pageSize,
                          @RequestParam(required = false) String computeDate,
                          @RequestParam(required = false) String tableName){
        return Result.ok(service.getList(current,pageSize,computeDate,tableName));
    }

    @ApiOperation("获取导入表名")
    @GetMapping("getTableList")
    public Result getTableList(){
        return Result.ok(service.getTableList());
    }

    @ApiOperation("导入数据")
    @PostMapping()
    public Result importData(@RequestPart("computeDate")String computeDate,
                             @RequestPart String tableName,
                             @RequestPart("file") MultipartFile file){
        service.importData(computeDate,tableName,file);
        return Result.ok();
    }


    @ApiOperation("撤销导入")
    @PostMapping("removeImport")
    public Result removeImport(@RequestParam Integer id){
        service.removeImport(id);
        return Result.ok();
    }

    @ApiOperation("复原导入")
    @PostMapping("recoverImport")
    public Result recoverImport(@RequestParam Integer id){
        service.recoverImport(id);
        return Result.ok();
    }

    @ApiOperation("批量导入数据")
    @PostMapping("importMultipleSheets")
    public Result importMultipleSheets(@RequestPart("computeDate")String computeDate,
                             @RequestPart("file") MultipartFile file){
        List<SheetImportResultVO> sheetImportResultVOS = service.importMultipleSheets(computeDate, file);
        return Result.ok(sheetImportResultVOS);
    }
}
