package com.engine.organization.service.impl;

import com.engine.core.impl.Service;
import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam;
import com.engine.organization.entity.hrmresource.vo.HrmResourceVO;
import com.engine.organization.mapper.resource.ResourceMapper;
import com.engine.organization.service.ExportCommonService;
import com.engine.organization.util.HrmI18nUtil;
import com.engine.organization.util.db.MapperProxyFactory;
import com.engine.organization.util.excel.ExcelUtil;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.util.*;

/**
 * @Author weaver_cl
 * @Description:
 * @Date 2022/6/28
 * @Version V1.0
 **/
public class ExportCommonServiceImpl extends Service implements ExportCommonService {

    @Override
    public XSSFWorkbook resourceExport(List<Long> ids) {

        List<HrmResourceVO> hrmResourceVOS = MapperProxyFactory.getProxy(ResourceMapper.class).listAll(ids);
        if (hrmResourceVOS == null) {
            hrmResourceVOS = new ArrayList<>();
        }
        // 1.工作簿名称
        String sheetName = HrmI18nUtil.getI18nLabel(85368, "人员档案数据");
        // 2.表头(后面动态获取)
        List<List<Object>> excelSheetData = new ArrayList<>();

        String[] header = {
                HrmI18nUtil.getI18nLabel( 93270, "姓名"),
                HrmI18nUtil.getI18nLabel( 93272, "部门"),
                HrmI18nUtil.getI18nLabel( 93274, "分部"),
                HrmI18nUtil.getI18nLabel( 93275, "移动电话"),
                HrmI18nUtil.getI18nLabel( 93278, "办公室电话"),
                HrmI18nUtil.getI18nLabel( 93279, "直接上级")};
        excelSheetData.add(Arrays.asList(header));

        //数据
        List<List<Object>> rows = new LinkedList<>();
        for (HrmResourceVO vo : hrmResourceVOS) {
            List<Object> row = new LinkedList<>();
            row.add(vo.getLastName());
            row.add(vo.getDepartmentName());
            row.add(vo.getCompanyName());
            row.add(vo.getMobile());
            row.add(vo.getTelephone());
            row.add(vo.getManagerName());
            rows.add(row);
        }
        excelSheetData.addAll(rows);
        return ExcelUtil.genWorkbookV2(excelSheetData, sheetName);
    }


}
