import com.alibaba.excel.EasyExcel;
import com.sysu.admin.MarkApplication;
import com.sysu.admin.api.base.BaseTest;
import com.sysu.admin.controller.crop.class_item.CropClassItemRepository;
import com.sysu.admin.controller.crop.class_item_period.CropClassItemPeriodRepository;
import com.sysu.admin.controller.crop.clazz.CropClassRepository;
import com.sysu.admin.controller.crop.period.CropPeriodRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MarkApplication.class)
public class CropClassPeriodTest extends BaseTest {

    @Autowired
    private CropClassItemPeriodRepository cropClassItemPeriodRepository;
    @Autowired
    private CropClassItemRepository cropClassItemRepository;
    @Autowired
    private CropClassRepository cropClassRepository;
    @Autowired
    private CropPeriodRepository cropPeriodRepository;


    @Test
    public void printToken(){
        System.out.println(getToken("381033297947398144","19874006220"));
    }

    @Test
    public void importCropClassPeriod(){
        FileInputStream file = null;
        try {
            file = new FileInputStream(new File("C:\\Users\\Administrator\\Documents\\WeChat Files\\wxid_0rs9qy7rezsh22\\FileStorage\\File\\2022-11",
                    "作物种类及生长期(1).xlsx"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        EasyExcel.read(file, CropClassPeriodExcel.class,
                new CropClassPeriodExcelListener(
                    cropClassItemPeriodRepository,cropClassItemRepository,cropClassRepository,cropPeriodRepository
                )
        ).doReadAllSync();
        System.out.println("导入完成");
    }

}
