package com.zcxk.rmcp.web.controller;

import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.rmcp.web.service.ImportFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@ResponseBody
@RequestMapping("import")
@Api(tags = "导入模块")
public class ImportController {

    @Autowired
    private ImportFileService importFileService;

    @ResponseBody
    @PostMapping("/importExcel")
    @ApiOperation(value = "导入Execl", notes = "Execl")
    public AjaxMessage<Void> importExcel(
            @ApiParam(value = "分类id", required = false) @RequestParam(required = false) Integer categoryId,
            @ApiParam(value = "导入类型 1：设备列表 2：装表 3：安装计划", required = true) @RequestParam(required = true) Integer importType,
            @ApiParam(value = "文件") @RequestParam MultipartFile file,
            HttpServletRequest request, HttpServletResponse response
    ) {
        importFileService.importExcel(categoryId, importType, file);
        return AjaxMessage.success();
    }

    @GetMapping("/downloadFailFile")
    @ApiOperation(value = "下载失败列表")
    public void downloadFailFile(
            @ApiParam(value = "id", required = true) @RequestParam(required = true) Integer objId,
            @ApiParam(value = "access_token", required = true) @RequestParam(required = true) String accessToken,
            HttpServletRequest request, HttpServletResponse response
    ) {
        importFileService.downloadFailFile(objId,response);
    }
}
