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


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sw.mes.core.dto.store.WarehouseInputBillDetailBo;
import com.sw.mes.core.dto.store.WarehouseOutputBillDetailBo;
import com.sw.mes.store.entity.WarehouseInputBillDetail;
import com.sw.mes.store.mapper.WarehouseInputBillDetailMapper;
import com.sw.mes.store.service.WarehouseInputBillDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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


/**
 * @Author wupeng
 * @Description 入库单详情
 * @Date 18:58 2023/7/27
 * @Param
 * @return
 **/
@Service
@Transactional
public class WarehouseInputBillDetailServiceImpl extends ServiceImpl<WarehouseInputBillDetailMapper, WarehouseInputBillDetail> implements WarehouseInputBillDetailService {

    @Autowired
    private WarehouseInputBillDetailMapper inputBillDetailMapper;

    /**
     * 根据入库单号查询入库明细
     **/
    @Override
    public List<WarehouseInputBillDetail> getByBillNo(String billNo) {
        return inputBillDetailMapper.getByBillNo(billNo);
    }

    @Override
    public List<WarehouseInputBillDetail> getByBillId(Long billId) {
        return inputBillDetailMapper.getByBillId(billId);
    }
    @Override
    public List<WarehouseInputBillDetail> getByBillIds(List<Long> billIds) {
        return inputBillDetailMapper.getByBillIds(billIds);
    }

    @Override
    public WarehouseInputBillDetail getByUniqueCode(String uniqueCode) {
        return inputBillDetailMapper.getByUniqueCode(uniqueCode);
    }

    @Override
    public List<WarehouseInputBillDetail> getByBatchNo(String batchNo) {
        return inputBillDetailMapper.getByBatchNo(batchNo);
    }

    @Override
    public List<WarehouseInputBillDetail> findWarehouseInputBillDetailsBySerialNoOrTraceIdOrBatchNo(String code) {
        return inputBillDetailMapper.findWarehouseInputBillDetailsBySerialNoOrTraceIdOrBatchNo(code);
    }

    @Override
    public List<WarehouseInputBillDetail> findBatchNoBySerialNoOrTraceId(String serialNo, String traceId) {
        return inputBillDetailMapper.findBatchNoBySerialNoOrTraceId(serialNo, traceId);
    }

    @Override
    public List<WarehouseInputBillDetailBo> findWarehouseInputBillDetailsByMaterialCode(String materialCode) {
        List<WarehouseInputBillDetailBo> warehouseInputBillDetailBos = new ArrayList<>();
        List<WarehouseInputBillDetail> warehouseInputBillDetailsByMaterialCode = inputBillDetailMapper.findWarehouseInputBillDetailsByMaterialCode(materialCode);
        warehouseInputBillDetailsByMaterialCode.forEach(entity -> {
            WarehouseInputBillDetailBo warehouseInputBillDetailBo = new WarehouseInputBillDetailBo();
            BeanUtils.copyProperties(entity, warehouseInputBillDetailBo);
            warehouseInputBillDetailBos.add(warehouseInputBillDetailBo);
        });
        return warehouseInputBillDetailBos;
    }

    @Override
    public Set<String> getDistinctMaterialCode(int page, int PageSize) {
        return inputBillDetailMapper.getDistinctMaterialCode();
    }

//    @Override
//    public String findDetailsByMaterialBatchNoWarehouseType(String materialCode, String batchNo, String warehouseCode, String type) {
//        return inputBillDetailMapper.findDetailsByMaterialBatchNoWarehouseType(materialCode,batchNo,warehouseCode,type);
//    }
}