package com.sw.mes.production.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.production.dao.FormulaSchemeDetailDao;
import com.sw.mes.production.entity.FormulaSchemeDetail;
import com.sw.mes.production.service.FormulaSchemeDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class FormulaSchemeDetailServiceImpl extends BaseServiceImpl<FormulaSchemeDetail> implements FormulaSchemeDetailService {
    FormulaSchemeDetailDao dao;

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

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

    @Override
    public List<FormulaSchemeDetail> findByFormulaSchemeIdAndMaterialTypeAndMaterialClassName(Long formulaSchemeId, String materialType, String materialClassName) {
        return findByFormulaSchemeId(formulaSchemeId).stream().filter(item -> (item.getMaterialType() != null && item.getMaterialType().equals(materialType)) && (item.getMaterialClassName() != null && item.getMaterialClassName().equals(materialClassName))).collect(java.util.stream.Collectors.toList());
    }

    @Override
    public FormulaSchemeDetail findByTaskAndMaterialCode(Long taskId, Integer againNum, String materialCode) {
        return dao.findByTaskAndMaterialCode(taskId, againNum, materialCode);
    }

}
