package com.ensign.crm.module.crm.controller.crm;

import com.ensign.crm.framework.common.pojo.CommonResult;
import com.ensign.crm.module.crm.model.DealerRegistrationModel;
import com.ensign.crm.module.crm.service.ExcelTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description: 生成Excel模板，解析Excel
 * @Date: 29/11/2024 2:27 pm
 * @Created: by ZZSLL
 */

@RestController
@Tag(name = "CRM - excel")
@RequestMapping("/crm-api/proxy/excel")
public class ExcelTemplateController {

    @Autowired
    private ExcelTemplateService excelTemplateService;

    @GetMapping("/download-template")
    @Operation(summary = "下载经销商登记引出模板")
    public void generateTemplate(HttpServletResponse response) throws IOException {
        excelTemplateService.generateDealerRegistration(response);
    }

    @PostMapping("/upload/parsing")
    @Operation(summary = "解析经销商登记Excel数据")
    public CommonResult<List<DealerRegistrationModel>> parsing(MultipartFile file) throws IOException {
        return CommonResult.success(excelTemplateService.parsingExcel(file));
    }
}
