package nckd.jxccl.swc.hcdm.mservice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import kd.sdk.swc.hcdm.business.helper.HCDMAdjFileServiceHelper;
import kd.sdk.swc.hcdm.business.helper.HCDMApplyBillServiceHelper;
import kd.sdk.swc.hcdm.business.helper.HCDMSalaryStdServiceHelper;
import kd.sdk.swc.hcdm.common.dto.stdtab.match.StdTableDataMatchParam;
import kd.sdk.swc.hcdm.common.dto.stdtab.match.StdTableDataMatchResult;
import nckd.jxccl.swc.hcdm.mservice.api.ISwcService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 定调薪档案服务
 * @author W.Y.C
 * @date 2026/1/7 21:37
 * @version 1.0
 */
public class SwcService implements ISwcService {
    @Override
    public Map<String, Object> getLastDecAdjRecords(Map<String, Object> param) {
        return HCDMAdjFileServiceHelper.getLastDecAdjRecords(param);
    }

    @Override
    public List<Map<String,Object>> matchStdTableData(List<Map<String,Object>> params) {
        List<StdTableDataMatchParam> stdTableDataMatchParams = params.stream()
                .map(m -> JSON.toJavaObject((JSONObject) JSON.toJSON(m), StdTableDataMatchParam.class))
                .collect(Collectors.toList());
        List<StdTableDataMatchResult> stdTableDataMatchResults = HCDMSalaryStdServiceHelper.matchStdTableData(stdTableDataMatchParams);
        List<Map<String,Object>> result = new ArrayList<>();
        return stdTableDataMatchResults.stream()
                .filter(Objects::nonNull)
                .map(r -> (Map<String, Object>) JSON.toJSON(r)) // 返回 JSONObject，兼容 Map
                .collect(Collectors.toList());
    }

    @Override
    public Map<String, Object> saveDraftApplyBill(Map<String, Object> param) {
        return HCDMApplyBillServiceHelper.saveDraftApplyBill(param);
    }
}