package com.sw.mes.yb.pad.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.utils.StringUtils;
import com.sw.mes.yb.pad.dao.SectionNoDetailDao;
import com.sw.mes.yb.pad.entity.SectionNoDetail;
import com.sw.mes.yb.pad.service.SectionNoDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class SectionNoDetailServiceImpl extends BaseServiceImpl<SectionNoDetail> implements SectionNoDetailService {
    SectionNoDetailDao dao;

    @Autowired
    public void setDao(SectionNoDetailDao dao) {
        super.setBaseDao(dao);
        this.dao = dao;
    }

    @Override
    public SectionNoDetail findBySectionNo(String sectionNo) {
        List<SectionNoDetail> sectionNoDetailList = dao.findBySectionNo(sectionNo);
        if (sectionNoDetailList.size() <= 0) {
            return null;
        }
        return sectionNoDetailList.get(0);
    }

    @Override
    public SectionNoDetail findByLikeSectionNo(String sectionNo) {
        List<SectionNoDetail> byLikeSectionNo = dao.findByLikeSectionNo(sectionNo);
        if(CollectionUtils.isEmpty(byLikeSectionNo)){
            return null;
        }
        return byLikeSectionNo.get(0);
    }

    @Override
    public Boolean sectionNoDetailIsExist(String sectionNo) {
        List<SectionNoDetail> sectionNoDetailList = dao.findBySectionNo(sectionNo);
        return sectionNoDetailList.size() > 0 ? true : false;
    }

    @Override
    public List<SectionNoDetail> findByCrystalIdAndParentId(Long goodsId, Long parentId) {
        return dao.findByCrystalIdAndParentIdOrderById(goodsId, parentId);
    }

    @Override
    public List<SectionNoDetail> findByParentId(Long goodsId) {
        return dao.findByParentId(goodsId);
    }

    @Override
    public Integer findSegmentNumByNo(String crystalNo) {
        return dao.findSegmentNumByNo(crystalNo);
    }

    @Override
    public List<SectionNoDetail> findByCrystalNoAndSectionPosiotion(String crystalNo, Integer sectionPosiotion) {
        if (StringUtils.isNotBlank(crystalNo) && null != sectionPosiotion){
            return dao.findInfoByCrystalNoAndSectionPosiotion(crystalNo,sectionPosiotion);
        }
        return null;
    }

    @Override
    public SectionNoDetail findByCrystalNoAndSegmentNumLessThan(String crystalNo, Integer segmentNum) {
        return dao.findByCrystalNoAndSegmentNumLessThan(crystalNo,segmentNum);
    }

    @Override
    public SectionNoDetail findByCrystalNoAndSegmentNumGreaterThan(String crystalNo, Integer segmentNum) {
        return dao.findByCrystalNoAndSegmentNumGreaterThan(crystalNo,segmentNum);
    }

    @Override
    public List<SectionNoDetail> findByCrystalNo(String crystalNo) {
        return dao.findByCrystalNo(crystalNo);
    }

    @Override
    public SectionNoDetail findByCrystalNoAndOxygenCarbonMark(String crystalNo, Integer oxygenCarbonMark) {

        if (StringUtils.isNotBlank(crystalNo) && null != oxygenCarbonMark){
            if (oxygenCarbonMark == 1){

                return dao.findHeadByCrystalNoAndOxygenCarbonMark(crystalNo,oxygenCarbonMark);
            }else if (oxygenCarbonMark == 2){
                return dao.findTailByCrystalNoAndOxygenCarbonMark(crystalNo,oxygenCarbonMark);
            }
        }
        return null;
    }

}
