package nckd.jimin.jyyy.hr.wtc.wtabm.opplugin.web.vaapply;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.sdk.plugin.Plugin;

import java.util.Date;

/**
 * Tyx 2025-04-28
 * 请假单通用操作插件
 * 判断请假结束日期-开始日期是否超过30天，是的话表头是否长假字段[nckd_islongleave]为true
 */
public class VaApplyBillOpEx extends AbstractOperationServicePlugIn implements Plugin {

    private static final Log log = LogFactory.getLog(VaApplyBillOpEx.class);

    @Override
    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
        DynamicObject[] bills = e.getDataEntities();
        for (DynamicObject bill : bills) {
            Date startDate = bill.getDate("startdate");
            Date endDate = bill.getDate("enddate");
            //判断两个日期是不是相差30天
            //2025-05-06 判断是否哺乳假 是的话不算长假
            long dateDiff = Math.abs(endDate.getTime() - startDate.getTime());
            long day = dateDiff / ( 1000 * 60 * 60 * 24);
            log.info(" -------- 相差天数：" + day + " -------- ");
            if(day > 30) {
                bill.set("nckd_islongleave", true);
            }
        }
        
        super.beginOperationTransaction(e);
    }
}