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

import com.njcn.device.pq.pojo.dto.CvtHarmonicCorrectionFactorsDTO;
import com.njcn.device.pq.pojo.param.CvtLineRelationParam;
import com.njcn.device.pq.pojo.po.CvtHarmonicCorrectionFactors;
import com.njcn.device.pq.service.CvtHarmonicCorrectionFactorsService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.device.pq.pojo.po.CvtLineRelation;
import com.njcn.device.pq.mapper.CvtLineRelationMapper;
import com.njcn.device.pq.service.CvtLineRelationService;
/**
 * 
 * Description:
 * Date: 2025/02/11  上午 9:22【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
@AllArgsConstructor
public class CvtLineRelationServiceImpl extends ServiceImpl<CvtLineRelationMapper, CvtLineRelation> implements CvtLineRelationService{

    private final CvtHarmonicCorrectionFactorsService cvtHarmonicCorrectionFactorsService;


    @Override
    public boolean add(CvtLineRelationParam cvtLineRelationParam) {
        CvtLineRelation one = this.lambdaQuery().eq(CvtLineRelation::getLineId, cvtLineRelationParam.getLineId()).one();
        if(Objects.isNull(one)){
            CvtLineRelation cvtLineRelation = new CvtLineRelation();
            BeanUtils.copyProperties(cvtLineRelationParam,cvtLineRelation);

            this.save(cvtLineRelation);
        }else {
            one.setCvtId(cvtLineRelationParam.getCvtId());
            this.updateById(one);
        }
        return true;
    }

    @Override
    public CvtHarmonicCorrectionFactorsDTO queryByLineId(String lineId) {
        CvtHarmonicCorrectionFactorsDTO cvtHarmonicCorrectionFactorsDTO = new CvtHarmonicCorrectionFactorsDTO();
        CvtLineRelation one = this.lambdaQuery().eq(CvtLineRelation::getLineId, lineId).one();
        if(Objects.nonNull(one)&& StringUtils.isNotEmpty(one.getCvtId())){
            CvtHarmonicCorrectionFactors byId = cvtHarmonicCorrectionFactorsService.getById(one.getCvtId());
            BeanUtils.copyProperties(byId,cvtHarmonicCorrectionFactorsDTO);
        }
        return cvtHarmonicCorrectionFactorsDTO;
    }
}
