package com.dxhy.core.task;

import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.core.job.entity.ScheduleJobEntity;
import com.dxhy.core.job.service.ScheduleJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
* @Description 从大B定时获取基础配置信息
* @Author wangruwei
* @Date 2024/12/5 16:28
**/
@Component("groupConfigGetBigBTask")
@Slf4j
public class GroupConfigGetBigBTask {

    @Resource
    private ScheduleJobService scheduleJobService;

    @Resource
    private com.dxhy.core.service.erpBigb.ErpBigbService ErpBigbService;

    /**
    * @Description 从大B定时获取基础配置信息
    * @param
    * @Return void
    * @Author wangruwei
    * @Date 2024/12/5 16:29
    **/
    public void getGroupConfig() {
        log.info("-------------调大B获取基础配置信息-任务开始----------------");
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        ScheduleJobEntity scheduleJobEntity = scheduleJobService.queryByBeanName("groupConfigGetBigBTask", "getGroupConfig");
        if (scheduleJobEntity != null && "0".equals(scheduleJobEntity.getJobStatus())) {
            try {
                scheduleJobEntity.setJobStatus("1");
                scheduleJobService.updateById(scheduleJobEntity);

                ErpBigbService.getGroupConfig();
                log.info("---------------调大B获取基础配置信息任务结束--------------");
            } catch (Exception e) {
               log.info("业务处理异常：{}", e);
                log.error("---------------调大B获取基础配置信息任务异常,{}--------------", e.getMessage());
            } finally {
                log.info("---------------调大B获取基础配置信息任务重置--------------");
                scheduleJobEntity.setJobStatus("0");
                scheduleJobService.updateById(scheduleJobEntity);
            }
        }
    }
}
