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


import com.sw.mes.core.annotation.Jinko;
import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.yb.accessory.dao.AccessoryMaterialDao;
import com.sw.mes.yb.accessory.entity.AccessoryMaterial;
import com.sw.mes.yb.accessory.service.AccessoryMaterialService;
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 AccessoryMaterialServiceImpl extends BaseServiceImpl<AccessoryMaterial> implements AccessoryMaterialService {
    AccessoryMaterialDao dao;
	@Autowired
    public void setDao(AccessoryMaterialDao dao) {
        super.setBaseDao(dao);
        this.dao=dao;
    }

    @Override
    public AccessoryMaterial findByCodes(String productNo) {
        List<AccessoryMaterial> list = dao.findByCodesOrderByCreateDateDesc(productNo);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    @Jinko(value = "根据物料主数据ID获取辅料信息", author = "wupeng")
    public AccessoryMaterial findMaterialId(Long materialModelId) {
        List<AccessoryMaterial> list = dao.findMaterialId(materialModelId);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public AccessoryMaterial getByMaterialCode(String materialCode) {
        List<AccessoryMaterial> list = dao.getByMaterialCode(materialCode);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
