package com.mtcarpenter.mall.controller;


import com.mtcarpenter.mall.excelEntity.UmsCompanyInfoExcel;
import com.mtcarpenter.mall.model.UmsCompanyInfo;
import com.mtcarpenter.mall.util.EasyExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.models.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@Api(tags = "UmsCompanyController", description = "供应商信息")
@RequestMapping("/umsCompany")
public class UmsCompanyController {
    //导入excel
    @RequestMapping(value = "excelImport", method = {RequestMethod.GET, RequestMethod.POST })
    public String excelImport(HttpServletRequest request, Model model, @RequestParam("uploadFile") MultipartFile[] files) throws Exception {
        if(files != null && files.length > 0){
            MultipartFile file = files[0];
            List<Object> list = EasyExcelUtil.readExcel(file, new UmsCompanyInfoExcel(),1,1);
            if(list != null && list.size() > 0){
                for(Object o : list){
                    UmsCompanyInfoExcel umsCompanyInfoExcel = (UmsCompanyInfoExcel) o;
                    System.out.println(umsCompanyInfoExcel.getCompIntroduction()+"/"+umsCompanyInfoExcel.getCompConPerson()+"/"+umsCompanyInfoExcel.getCityId());
                }
            }
        }
        return "index";
    }

}
