package nckd.jxccl.hr.task;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.exception.KDException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.schedule.executor.AbstractTask;
import kd.sdk.plugin.Plugin;

import java.util.Map;

/**
 * 后台任务插件
 * @author Turborao
 * @Date : 2025/12/16 13:05
 */
public class HRDataCleanTask extends AbstractTask implements Plugin {

    private static final Log logger = LogFactory.getLog(HRDataCleanTask.class);

    private static final DBRoute QUEUE_DB_ROUTE = new DBRoute("hr");

    @Override
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {

        this.clearOpenQueueLog();

    }


    public void clearOpenQueueLog() {
        try {
            String strLog = ResManager.loadKDString("HRDataCleanTask-消息队列保留时长 - 状态成功", "HRDataClearLog_1", "bos-open-base", new Object[]{0});
            logger.info(strLog);
            String sql = "DELETE FROM tv_nckd_employee_12m_avgqty WHERE fyear*100+fmonth in (select fyear*100+fmonth  from v_nckd_12monthly_series)";
            DB.execute(QUEUE_DB_ROUTE, sql);
            String str = ResManager.loadKDString("HRDataCleanTask-队列清理任务执行成功。", "HRDataClearLog_2", "bos-open-base", new Object[0]);
            logger.info(str);
        } catch (Exception e) {
            String str = ResManager.loadKDString("HRDataCleanTask-队列清理定时任务执行失败:%s。", "HRDataClearLog_3", "bos-open-base", new Object[]{e.getMessage()});
            logger.error(str, e);
            throw e;
        }
    }
}