package nckd.jxccl.hr.sdm.business;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
import nckd.jxccl.base.common.utils.QueryFieldBuilder;
import nckd.jxccl.hr.sdm.common.SanDingConstant;

/**
 * 三定管理业务服务
 * @author: jtd
 * @date: 2025/12/19 17:44
 */
public class SdmBusinessService {

    private static final HRBaseServiceHelper sanDingPlanServiceHelper = HRBaseServiceHelper.create(SanDingConstant.NCKD_SANDINGPLAN_ENTITY);

    public static DynamicObject getLastSanDingPlanDyo(Long id) {
        // 排序 年度降序、适用批次人力资源需求批次.编码降序
        String orderBys = QueryFieldBuilder.create().addDesc(SanDingConstant.NCKD_SANDINGYEAR_KEY).addDesc(SanDingConstant.NCKD_SANDINGTIME_KEY, SanDingConstant.NUMBER_KEY).buildOrder();
        // 获取最近一个三定计划
        DynamicObject[] lastSanDingPlanDyos = sanDingPlanServiceHelper.queryOriginalArray(SanDingConstant.ID_KEY, new QFilter[]{new QFilter(SanDingConstant.ID_KEY, QCP.not_equals, id)}, orderBys);
        if (lastSanDingPlanDyos.length > 0) {
            return sanDingPlanServiceHelper.loadSingle(lastSanDingPlanDyos[0].getLong(SanDingConstant.ID_KEY));
        }
        return sanDingPlanServiceHelper.generateEmptyDynamicObject();
    }

}
