package com.njcn.device.pq.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.algorithm.pojo.dto.PqReasonableRangeDto;
import com.njcn.algorithm.pojo.param.DataCleanParam;
import com.njcn.algorithm.pojo.po.PqReasonableRange;
import com.njcn.device.pq.mapper.ReasonableRangeMapper;
import com.njcn.device.pq.service.ReasonableRangeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xy
 * @since 2025-02-13
 */
@Service
public class ReasonableRangeServiceImpl extends ServiceImpl<ReasonableRangeMapper, PqReasonableRange> implements ReasonableRangeService {

    @Override
    public List<PqReasonableRangeDto> getReasonableRangeList(DataCleanParam param) {
        List<PqReasonableRangeDto> result = new ArrayList<>();
        LambdaQueryWrapper<PqReasonableRange> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PqReasonableRange::getBelongingSystem,param.getSystemType());
        if(StrUtil.isNotBlank(param.getDataSource())){
            queryWrapper.eq(PqReasonableRange::getDataSource,param.getDataSource());
        }
        if(StrUtil.isNotBlank(param.getTableName())){
            queryWrapper.eq(PqReasonableRange::getInfluxdbTableName,param.getTableName());
        }
        queryWrapper.eq(PqReasonableRange::getState,1);
        List<PqReasonableRange> list = this.list(queryWrapper);
        if (CollUtil.isNotEmpty(list)) {
            list.forEach(item->{
                PqReasonableRangeDto dto = new PqReasonableRangeDto();
                BeanUtils.copyProperties(item,dto);
                result.add(dto);
            });
        }
        return result;
    }
}
