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


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sw.mes.core.dto.store.WarehouseOutputBillDetailBo;
import com.sw.mes.store.entity.WarehouseOutputBillDetail;
import com.sw.mes.store.mapper.WarehouseOutputBillDetailMapper;
import com.sw.mes.store.service.WarehouseOutputBillDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


/**
 * @Author wupeng
 * @Description 出库明细
 * @Date 20:38 2023/8/2
 * @Param
 * @return
 **/
@Service
@Transactional
public class WarehouseOutputBillDetailServiceImpl extends ServiceImpl<WarehouseOutputBillDetailMapper, WarehouseOutputBillDetail> implements WarehouseOutputBillDetailService {

    @Autowired
    private WarehouseOutputBillDetailMapper detailMapper;

    @Override
    public List<WarehouseOutputBillDetail> getByBillId(Long id) {
        return detailMapper.getByBillId(id);
    }

    @Override
    public List<WarehouseOutputBillDetail> getByBillNo(String billNo) {
        return detailMapper.getByBillNo(billNo);
    }

    @Override
    public WarehouseOutputBillDetail getByBillMaterialCode(String billNo, String materialCode) {
        return detailMapper.getByBillMaterialCode(billNo,materialCode);
    }

    @Override
    public List<WarehouseOutputBillDetailBo> findWarehouseOutputBillDetailByMaterialCode(String materialCode) {
        List<WarehouseOutputBillDetailBo> warehouseOutputBillDetailBos = new ArrayList<>();
        List<WarehouseOutputBillDetail> warehouseOutputBillDetailByMaterialCode = detailMapper.findWarehouseOutputBillDetailByMaterialCode(materialCode);
        warehouseOutputBillDetailByMaterialCode.forEach(entity->{
            WarehouseOutputBillDetailBo warehouseOutputBillDetailBo = new WarehouseOutputBillDetailBo();
            BeanUtils.copyProperties(entity,warehouseOutputBillDetailBo);
            warehouseOutputBillDetailBos.add(warehouseOutputBillDetailBo);
        });
        return warehouseOutputBillDetailBos;
    }
}