package cn.axzo.msg.center.notices.client.task.compensation;

import cn.axzo.msg.center.notices.client.task.LoggerJobHandler;
import cn.azxo.framework.common.model.JobPageRequest;
import cn.azxo.framework.common.utils.LogUtil;
import com.alibaba.fastjson.JSON;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 实时批量消息请求拆分补偿任务
 *
 * @author zhaoyong
 * @see RealBatchMessageRequestSplitCompensation
 * @since 2021-08-24 12:59
 */
@Slf4j
@Component
public class RealBatchMessageRequestSplitCompensation extends LoggerJobHandler {

  @Override
  @XxlJob(value = "realBatchMessageRequestSplitCompensation")
  public ReturnT<String> execute(String param) {
    return jobLoggerTemplate.execute(() -> {
      log.info("RealBatchMessageRequestSplitCompensation.execute task Start ......");
      try {
        JobPageRequest request = jobParamResolver.resolver(param);
        log.info("RealBatchMessageRequestSplitCompensation.execute task request is {}", JSON.toJSONString(request));
        taskService.realBatchMessageRequestSplitCompensation(request);
      } catch (Exception e) {
        LogUtil.error("RealBatchMessageRequestSplitCompensation.execute is error", e);
        return ReturnT.FAIL;
      }
      log.info("RealBatchMessageRequestSplitCompensation.execute task End ......");
      return ReturnT.SUCCESS;
    });
  }

}
