package com.openhis.quartz.task;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.alibaba.fastjson2.JSONObject;
import com.core.common.core.domain.R;
import com.core.common.utils.DateUtils;
import com.openhis.web.inventorymanage.appservice.IProductStocktakingAppService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.core.common.utils.StringUtils;
import com.core.framework.config.TenantContext;
import com.openhis.administration.domain.Location;
import com.openhis.administration.service.ILocationService;

/**
 * 批量盘点定时任务
 * 
 * @author yuxj
 */
@Component("stocktakingBatchTask")
public class StocktakingBatchTask {

    Logger logger = LoggerFactory.getLogger(StocktakingBatchTask.class);
    @Resource
    IProductStocktakingAppService productStocktakingAppService;

    public void autoStocktakingBatch(Integer tenantId) {
        // 定时任务指定租户id,示例
        try {
            // 在控制台打印当前时间加执行的功能名
            System.out.println("执行自动批量盘点START：" + DateUtils.getNowDate());
            logger.info("执行自动批量盘点START：" + DateUtils.getNowDate());

            // 设置当前线程的租户ID
            TenantContext.setCurrentTenant(tenantId);
            //执行自动盘点
            productStocktakingAppService.autoStocktakingBatch();

            logger.info("执行自动批量盘点END：" + DateUtils.getNowDate());
            // 在控制台打印当前时间加执行的功能名
            System.out.println("执行自动批量盘点END：" + DateUtils.getNowDate());
        } finally {
            // 清除线程局部变量，防止内存泄漏
            TenantContext.clear();
        }

    }
}
