package com.fizz.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.fizz.business.domain.PdoStripvalue;
import com.fizz.business.dto.ExitCoilInfoDTO;
import com.fizz.business.mapper.PdoStripvalueMapper;
import com.fizz.business.mapper.SegmentMapper;
import com.fizz.business.service.PdoStripValueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author chenhao
 * @date 2023/05/30
 */
@Slf4j
@Service
public class PdoStripValueServiceImpl implements PdoStripValueService {

    @Autowired
    PdoStripvalueMapper pdoStripvalueMapper;
    @Autowired
    SegmentMapper segmentMapper;

    /**
     * 打包segment
     * @param pdoExCoil
     */
    @Override
    public void treatStripValues(ExitCoilInfoDTO pdoExCoil) {
        PdoStripvalue stripvalue = segmentMapper.getStripValue(pdoExCoil.getEntryMatId(), pdoExCoil.getStartPos(), pdoExCoil.getEndPos());
        if (Objects.isNull(stripvalue)) {
            log.warn("W: strip value is null, {}", JSON.toJSONString(pdoExCoil));
            return;
        }
        stripvalue.setExitMatId(pdoExCoil.getExitMatId());
        pdoStripvalueMapper.insert(stripvalue);
    }
}
