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


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.exception.BusinessException;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sw.mes.yb.pad.entity.RecutDetail;
import com.sw.mes.yb.pad.dao.RecutDetailDao;
import com.sw.mes.yb.pad.service.RecutDetailService;

import java.util.List;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class RecutDetailServiceImpl extends BaseServiceImpl<RecutDetail> implements RecutDetailService {
    RecutDetailDao dao;

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

    @Override
    public RecutDetail findBySectionNoFb(String sectionNoFb) {
        List<RecutDetail> recutDetails = dao.findBySectionNoFb(sectionNoFb);
        if (recutDetails.size() > 1) {
            throw new BusinessException(sectionNoFb + "该编号在方棒信息表中存在重复的数据，请处理");
        }
        if (recutDetails.size() == 1) {
            return recutDetails.get(0);
        }
        return null;
    }

    @Override
    public List<RecutDetail> getAllDataBySectionNoFb(String sectionNoFb) {
        List<RecutDetail> recutDetails = dao.findBySectionNoFb(sectionNoFb);
        if(CollectionUtils.isNotEmpty(recutDetails)){
            return recutDetails;
        }
        return null;
    }

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

    @Override
    public List<RecutDetail> findByPieceNo(String pieceNo) {
        return dao.findByPieceNoHeadOrPieceNoEnd(pieceNo);
    }

    @Override
    public List<RecutDetail> findBySectionNo(String sectionNo) {
        return dao.findBySectionNo(sectionNo);
    }

}
