package com.foreverwin.mesnac.dispatch.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.foreverwin.mesnac.common.util.StringUtil;
import com.foreverwin.mesnac.dispatch.model.ItemBatch;
import com.foreverwin.mesnac.dispatch.mapper.ItemBatchMapper;
import com.foreverwin.mesnac.dispatch.service.ItemBatchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 物料批次表 服务实现类
 * </p>
 *
 * @author Leon.L
 * @since 2021-06-18
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ItemBatchServiceImpl extends ServiceImpl<ItemBatchMapper, ItemBatch> implements ItemBatchService {


    @Autowired
    private ItemBatchMapper itemBatchMapper;


    @Override
    public List<ItemBatch> findItemBatch(String site, String item, String batch) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put(ItemBatch.SITE, site);
        queryMap.put(ItemBatch.ITEM, item);
        if (StringUtil.notBlank(batch)) {
            queryMap.put(ItemBatch.BATCH, batch);
        }

        return itemBatchMapper.selectByMap(queryMap);
    }

    @Override
    public List<ItemBatch> findItemLabel(String site, String item, String label) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put(ItemBatch.SITE, site);
        queryMap.put(ItemBatch.ITEM, item);
        if (StringUtil.notBlank(label)) {
            queryMap.put(ItemBatch.LABEL, label);
        }

        return itemBatchMapper.selectByMap(queryMap);
    }
}