package com.engine.salary.wrapper;

import com.cloudstore.eccom.pc.table.WeaTable;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.siaccount.param.QueryAccountDetailParam;
import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO;
import com.engine.salary.service.ColumnBuildService;
import com.engine.salary.service.RecordsBuildService;
import com.engine.salary.service.SIReportService;
import com.engine.salary.service.impl.ColumnBuildServiceImpl;
import com.engine.salary.service.impl.RecordsBuildServiceImpl;
import com.engine.salary.service.impl.SIReportServiceImpl;
import com.engine.salary.util.page.PageInfo;
import weaver.hrm.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class SIReportWrapper extends Service {

    private SIReportService getSIReportService(User user) {
        return (SIReportService) ServiceUtil.getService(SIReportServiceImpl.class, user);
    }

    private RecordsBuildService getRecordsBuildService(User user) {
        return (RecordsBuildService) ServiceUtil.getService(RecordsBuildServiceImpl.class, user);
    }


    private ColumnBuildService getColumnBuildService(User user) {
        return (ColumnBuildService) ServiceUtil.getService(ColumnBuildServiceImpl.class, user);
    }


    public  Map<String,Object> welfareList(QueryAccountDetailParam param) {
        PageInfo<InsuranceAccountDetailPO> page = getSIReportService(user).welfareList(param);
        List<InsuranceAccountDetailPO>  list = page.getList();
        List<Map<String, Object>> records = getRecordsBuildService(user).buildCommonRecordsWithStyle(list, param.getEmployeeId());


        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(records);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(page.getPageNum());
        pageInfo.setPageSize(page.getPageSize());


        List<WeaTableColumn> columns = getColumnBuildService(user).buildCommonColumns(list);

        WeaTable table = new WeaTable();
        table.setColumns(columns);


        WeaResultMsg result = new WeaResultMsg(false);
        result.putAll(table.makeDataResult());
        result.success();

        Map<String,Object> datas = new HashMap<>();
        datas.put("pageInfo", pageInfo);
        datas.put("dataKey",result.getResultMap());


        return datas;
    }
}
