package com.hdkj.lt.job.task;

import com.alibaba.fastjson.JSON;
import com.hdkj.lt.job.service.IDistOSSSvgFileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Slf4j
@Component("distOSSSvgFile")
@RequiredArgsConstructor
public class DistOSSSvgFileProcessor {

    private final IDistOSSSvgFileService distOSSSvgFileService;

    public void params(String params) {
        log.info("OSSSvgFile定时任务 param：{}", JSON.toJSONString(params));
        long startTime = System.nanoTime();
        String fileDir = Optional.ofNullable(params)// 获取参数内容
                .map(JSON::parseObject)
                .filter(ObjectUtils::isNotEmpty) // 过滤参数不为为空的逻辑
                .map(e -> e.getString("fileDir"))
                .orElse("harmony"); // 默认值
        distOSSSvgFileService.saveBatchFileInfo(fileDir);
        long endTime = System.nanoTime();
        log.info("=====OSSSvgFile定时任务执行完成耗时：{}ms=====", (endTime - startTime) / 1_000_000);
    }
}
