package com.gz;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.gz.dto.archive.ArchiveDTO;
import com.gz.mapper.archive.ArchiveMapper;
import com.gz.rvo.archive.ArchiveRVO;
import com.gz.service.archive.ArchiveService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import tk.mybatis.mapper.entity.Example;

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

@SpringBootTest
public class HandleSource {

    @Resource
    private ArchiveService archiveService;

    @Resource
    private ArchiveMapper archiveMapper;

    @Test
    public void run() {
        ExcelReader reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\ljw\\Desktop\\a.xlsx"));
        List<Map<String, Object>> maps = reader.readAll();

        for (Map<String, Object> map : maps) {
            String dh = MapUtil.getStr(map, "a");
            String ly = MapUtil.getStr(map, "b");
            String xzqh = MapUtil.getStr(map, "c");
            String bq = MapUtil.getStr(map, "d");

            if (StrUtil.isNotBlank(bq)) {
                System.out.println(bq);
            }

            ArchiveDTO archiveDTO = new ArchiveDTO();
            archiveDTO.setDh(dh);
            archiveDTO.setLy(ly);
            archiveDTO.setXzqh(xzqh);
            archiveDTO.setBq(bq);

            Example dhParam = new Example(ArchiveDTO.class);
            dhParam.createCriteria().andEqualTo("dh", dh);
            archiveMapper.updateByExampleSelective(archiveDTO, dhParam);
        }
    }
}
