package com.chaozhanggui.admin.system.controller;

import com.chaozhanggui.admin.system.service.PromotionService;
import com.chaozhanggui.common.system.config.RespBody;
import com.chaozhanggui.dao.system.dao.TbPlussCashMapper;
import com.chaozhanggui.dao.system.entity.TbPlussCash;
import com.chaozhanggui.system.entity.Promotion;
import com.chaozhanggui.system.util.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lyf
 */
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/promotion")
@Slf4j
public class PromotionController {
    @Resource
    private PromotionService promotionService;

    //接受文件上传
    @PostMapping("/uploadExecl")
    @ResponseBody
    public RespBody uploadFile(MultipartFile file){
        //调用工具类解析excel文件
        List<ArrayList<String>> row = ExcelUtil.analysis(file);
        //打印信息
        for (int i = 0;i<row.size();i++){
            List<String> cell = row.get(i);
            for (int j = 0;j<cell.size();j++){
                System.out.print(cell.get(j)+" ");
            }
            System.out.println();
        }
        //存入数据库
        return promotionService.uploadFile(row);
    }

}
