package com.chinaweal.aiccs.aiccs.revoke.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaweal.aiccs.aiccs.abnormal.service.EBaseinfoService;
import com.chinaweal.aiccs.aiccs.revoke.entity.AnnouncementTaskListDetail;
import com.chinaweal.aiccs.aiccs.revoke.entity.dto.AnnouncementTaskListDetailImportDto;
import com.chinaweal.aiccs.aiccs.revoke.entity.dto.AnnouncementTaskListDetailQueryDto;
import com.chinaweal.aiccs.aiccs.revoke.excelListener.AnnouncementTaskListDetailExcelListener;
import com.chinaweal.aiccs.aiccs.revoke.mapper.AnnouncementTaskListDetailMapper;
import com.chinaweal.aiccs.aiccs.revoke.service.AnnouncementTaskListDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 * 公告任务名单详细名录表 服务实现类
 * </p>
 *
 * @author system
 * @since 2026-02-26
 */
@Service
@RequiredArgsConstructor
public class AnnouncementTaskListDetailServiceImpl extends ServiceImpl<AnnouncementTaskListDetailMapper, AnnouncementTaskListDetail> implements AnnouncementTaskListDetailService {

    private final EBaseinfoService eBaseinfoService;

    @Override
    public IPage<AnnouncementTaskListDetail> queryPageWithAbnormalAndSeriousIllegal(Page<AnnouncementTaskListDetail> page, AnnouncementTaskListDetailQueryDto queryDto) {
        return baseMapper.queryPageWithAbnormalAndSeriousIllegal(page, queryDto);
    }

    @Override
    public void importFromExcel(MultipartFile file, String taskListId, String createUserId) {
        try (InputStream inputStream = file.getInputStream()) {
            EasyExcel.read(inputStream, AnnouncementTaskListDetailImportDto.class,
                    new AnnouncementTaskListDetailExcelListener(this, eBaseinfoService, taskListId, createUserId)).sheet().doRead();
        } catch (Exception e) {
            throw new RuntimeException("Excel导入失败：" + e.getMessage(), e);
        }
    }
}