package nckd.jxccl.hr.gzbb;

import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Date;

/**
 * 央国企人事云》国资报表ext》单据》数据采集模板
 * 表单插件
 * nckd_sjcjmb
 * duanyuqi
 */
public class SjcjmbCheckForm extends AbstractFormPlugin {
    private static final Log logger = LogFactory.getLog(SjcjmbCheckForm.class);

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String fieldKey = e.getProperty().getName();
        if ("nckd_ssny".equals(fieldKey)) {
            // 获取所在月份的最后一天填入截止日期
            Date nckd_ssny = (Date) this.getModel().getValue("nckd_ssny");
            // 1. 将 Date 转换为 LocalDate
            LocalDate localDate = nckd_ssny.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            // 2. 计算次月最后一天
            YearMonth nextMonth = YearMonth.from(localDate).plusMonths(1);
            LocalDate lastDay = nextMonth.atEndOfMonth();
            // 3. 将 LocalDate 转换回 Date
            Date resultDate = Date.from(lastDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
            this.getModel().setValue("nckd_tbjzsj", resultDate);
        }
        super.propertyChanged(e);
    }

}
