package com.hdkj.lt.job.task;

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

import java.util.Optional;

/**
 * @Description 中压接入点和接入点变压器关联台账信息
 * @Author wcx
 * @Date 2025/7/30 15:07
 * @Version 1.0
 */
@Slf4j
@Component("joinEcTransformer")
@RequiredArgsConstructor
public class JoinEcTransformerProcessor {

    private final IDealPsrDeviceService dealPsrDeviceService;

    public void params(String params) {
        log.info("=====中压接入点和接入点变压器关联台账信息定时任务开始=====");
        long startTime = System.nanoTime();
        String cityShort = Optional.ofNullable(params)// 获取参数内容,多个简称，隔开
                .map(JSON::parseObject)
                .filter(ObjectUtils::isNotEmpty) // 过滤参数不为为空的逻辑
                .map(e -> e.getString("cityShort"))
                .orElse("-"); // 默认值
        dealPsrDeviceService.saveJoinEcTransformerInfo(cityShort);
        long endTime = System.nanoTime();
        log.info("=====中压接入点和接入点变压器关联台账信息定时任务开始执行完成耗时：{}ms=====", (endTime - startTime) / 1_000_000);
    }
}
