package io.renren.modules.dataSet.upload;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import io.renren.common.exception.RRException;
import io.renren.common.utils.R;
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.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;

/**
 * web读写案例
 *
 * @author Jiaju Zhuang
 **/
@RestController
@RequestMapping("/dataset/staticup")
public class UpLoadController {


    /**
     * 文件上传
     * <p>
     * 1. 创建excel对应的实体对象 参照{@link }
     * <p>
     * 2. 由于默认一行行的读取excel，所以需要创建excel一行一行的回调监听器，参照{@link }
     * <p>
     * 3. 直接读即可
     */
    @Autowired
    private UpLoadService upLoadService;
    @PostMapping("upload")
    @ResponseBody
    public R uploadExcel(MultipartFile file) throws IOException {
//        EasyExcel.read(file.getInputStream(), UploadData.class, new UploadDataListener(uploadDAO)).sheet().doRead();

        Map map = upLoadService.upload(file);

//        System.out.println(map);
        return R.ok().put("data", map);

    }

    @RequestMapping("uploadcsv")
    public R uploadCSV(MultipartFile file) throws Exception {
        System.out.println(file);
        Map map = upLoadService.uploadCSV(file);
//        System.out.println(map);
        return R.ok().put("data",map);
    }
    @RequestMapping("getstapre")
    public R getstaticprecontent(@RequestBody Map map){

        final List getstaticprecontent = upLoadService.getstaticprecontent(map);
//        System.out.println(datas);

//        subeqpdemoService.getPrecontent(subeqpments);
        return R.ok().put("data",getstaticprecontent);
    }
}
