package com.yinlihupo.enlish.service.service.exam;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.yinlihupo.enlish.service.domain.dataobject.ExamWordsDO;
import com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO;
import com.yinlihupo.enlish.service.domain.mapper.ExamWordsJudgeResultDOMapper;
import com.yinlihupo.enlish.service.model.bo.Word;
import com.yinlihupo.enlish.service.service.ExamWordsService;
import com.yinlihupo.enlish.service.service.VocabularyService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileOutputStream;
import java.util.*;

@SpringBootTest
@Slf4j
public class ExamTest {

    @Resource
    private ExamWordsService examWordsService;
    @Resource
    private VocabularyService vocabularyService;
    @Resource
    private ExamWordsJudgeResultDOMapper examWordsJudgeResultDOMapper;
    @Test
    public void test() {
//        ExamWordsDO examWordsDO = examWordsService.generateExamWords(5, 0);
//        log.info("{}", examWordsDO);
//        List<VocabularyBankDO> vocabularyBankDOS = vocabularyService.findVocabularyBankDOListById(examWordsDO.getWordIds());
//        List<Word> assessmentWords = vocabularyBankDOS.stream().map(vocabularyBankDO -> Word.builder()
//                .id(vocabularyBankDO.getId())
//                .title(vocabularyBankDO.getWord())
//                .definition(vocabularyBankDO.getDefinition())
//                .build()).toList();
//
//
//        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//        Configure config = Configure.builder()
//                .bind("words", policy)
//                .build();
//
//        Map<String, Object> data = new HashMap<>();
//        data.put("examId", examWordsDO.getId());
//        data.put("studentId", 1);
//        data.put("studentStr","小明三班一年级");
//        data.put("examStr", examWordsDO.getTitle());
//        data.put("words", assessmentWords);
//        data.put("answer", assessmentWords);
//
//        // 4. 渲染并输出
//        try (XWPFTemplate template = XWPFTemplate.compile("C:\\project\\java\\enlish_edu\\enlish\\enlish-service\\src\\main\\resources\\templates\\assessment_v5.docx", config)) {
//            template.render(data);
//            template.write(new FileOutputStream("学生单词测试卷.docx"));
//            System.out.println("文档生成成功！");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }
}
