package com.zjrs.zwnw.dbgl.blo.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.persistens.PageUtil;
import com.zjrs.zwnw.dbgl.blo.DbrwcxPLO;
import com.zjrs.zwnw.dbgl.blo.DbrwglCommPLO;
import com.zjrs.zwnw.dbgl.dto.DbrwglDbrwQueryDTO;
import com.zjrs.zwnw.dbgl.dto.DbrwglExportrwcxDTO;
import com.zjrs.zwnw.dbgl.entity.DbrwMapper;
import com.zjrs.zwnw.dbgl.entity.DbrwcxMapper;
import com.zjrs.zwnw.dbgl.entity.DbxmMapper;
import com.zjrs.zwnw.portal.blo.CommonBLO;
import com.zjrs.zwnw.portal.entity.VSSgOrgMapper;
import org.mohrss.leaf.core.framework.domain.blo.impl.BLOImpl;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;


/**
 * @Author chenzhibiao
 * @create 2022/6/30 8:43
 */
@Service
public class DbrwcximplPLO extends BLOImpl implements DbrwcxPLO {
    @Resource
    private DbrwcxMapper dbrwcxMapper;
    @Resource
    private DbrwMapper dbrwMapper;
    @Resource
    private CommonBLO commonBLO;
    @Resource
    private DbrwglCommPLO dbrwglCommPLO;
    @Resource
    private VSSgOrgMapper vSSgOrgMapper;
    @Resource
    private DbxmMapper dbxmMapper;


    @Override
    public PageResult getDbrwList(DbrwglDbrwQueryDTO dto, Integer pagenum, Integer pagesize) {
        Page<Map<String, Object>> page = new Page<>(dto.getPagenum(), dto.getPagesize());
        Page<Map<String, Object>> pageResult = (Page) dbrwcxMapper.getDbrwList(page,dto);

        PageResult result = PageUtil.PageResult(pageResult);
        return result;
    }

    @Override
    public void exportDbrwcxList(DbrwglDbrwQueryDTO dto, HttpServletResponse res) {
        List<DbrwglExportrwcxDTO> result = dbrwcxMapper.exportDbrwcxList(dto);
        InputStream inputStream = null;
        try {
            inputStream = DbrwcximplPLO.class.getClassLoader()
                    .getResourceAsStream("templates" + File.separator + "dbgl" + File.separator + "dbrwcx.xlsx");

            String fileName = "督办列表.xlsx";
            res.setContentType("application/vnd.ms-excel;charset=utf-8");
            res.setHeader("Content-disposition", "attachment;filename=" + fileName);
            res.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
