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/9/1 15:00
 * @Version 1.0
 */
@Slf4j
@Component("segmentPsrDevice")
@RequiredArgsConstructor
public class SegmentPsrDeviceProcessor {

    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.saveSegmentPsrDeviceInfo(cityShort);
        long endTime = System.nanoTime();
        log.info("=====导线、电缆段台账信息接入定时任务执行完成耗时：{}ms=====", (endTime - startTime) / 1_000_000);
    }
}
