package com.engine.salary.wrapper;

import com.api.formmode.mybatis.util.SqlProxyHandle;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.component.WeaTableColumnGroup;
import com.engine.salary.entity.salaryacct.dto.SalaryComparisonResultListDTO;
import com.engine.salary.entity.salaryacct.param.SalaryComparisonResultQueryParam;
import com.engine.salary.mapper.sys.SalarySysConfMapper;
import com.engine.salary.service.SalaryAcctRecordService;
import com.engine.salary.service.SalaryComparisonResultService;
import com.engine.salary.service.SalarySobEmpFieldService;
import com.engine.salary.service.SalarySobItemService;
import com.engine.salary.service.impl.SalaryComparisonResultServiceImpl;
import com.engine.salary.sys.entity.po.SalarySysConfPO;
import com.engine.salary.util.page.PageInfo;

import org.apache.commons.lang3.math.NumberUtils;
import weaver.hrm.User;

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

import static com.engine.salary.sys.constant.SalarySysConstant.SALARY_ACCT_FIXED_COLUMNS;

/**
 * 薪资核算线下对比结果
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class SalaryComparisonResultWrapper extends Service {

    
    private SalaryComparisonResultService getSalaryComparisonResultService(User user) {
        return (SalaryComparisonResultService) ServiceUtil.getService(SalaryComparisonResultServiceImpl.class, user);
    }

    private SalarySysConfMapper getSalarySysConfMapper() {
        return SqlProxyHandle.getProxy(SalarySysConfMapper.class);
    }
    
    private SalaryAcctRecordService salaryAcctRecordService;
    
    private SalarySobEmpFieldService salarySobEmpFieldService;
    
    private SalarySobItemService salarySobItemService;

    /**
     * 薪资核算线下对比列表
     *
     * @param queryParam 列表查询条件
     * @return
     */
    public Map<String, Object> listPage(SalaryComparisonResultQueryParam queryParam) {
        // 查询薪资核算线下对比列表(不包含隐藏薪资项目)
        SalaryComparisonResultListDTO salaryComparisonResultListDTO = getSalaryComparisonResultService(user).listPageByParam(queryParam);

        PageInfo<Map<String, Object>> pageInfo = salaryComparisonResultListDTO.getData();

        List<WeaTableColumnGroup> weaTableColumns = salaryComparisonResultListDTO.getWeaTableColumns();
        // 获取固定列头数
        SalarySysConfPO salaryAcctFixedColumns = getSalarySysConfMapper().getOneByCode(SALARY_ACCT_FIXED_COLUMNS);
        if (salaryAcctFixedColumns != null) {
            int fixedNum = NumberUtils.isCreatable(salaryAcctFixedColumns.getConfValue()) ? Integer.valueOf(salaryAcctFixedColumns.getConfValue()) : 3;
            if (fixedNum == 0) {
                fixedNum = 3;
            }
            for (int i = 0; i < fixedNum && i < weaTableColumns.size(); i++) {
                weaTableColumns.get(i).setFixed("left");
            }
        }

        Map<String, Object> datas = new HashMap<>();
        datas.put("pageInfo", pageInfo);
        datas.put("columns", weaTableColumns);

        return datas;
    }
}
